modify=>auto_update.c (新增 do_recover)
modify=>gm8139.h (定義 nand or nor flash)
modify=>fw_env.h (修改 config 路徑 "/mnt/mtd/fw_env.config")
modify=>fw_env.config (修改 device offset 路徑")
modify=>fw_env_main.c (修改 lockname = "/var/locks/ ")
[command line]
workspace/uboot#./make_8136 =====>看哪個平台可以切換
workspace/uboot#cp u-boot.bin => 燒錄目錄
workspace/uboot#cat /proc/mtd => 看 parition
** command line 下 make 出可設定 uboot 的 tool
- 在/uboot/tools/env 底下
- fw_env.config
../gm8139.h 下定義
(SPI NOR)
#define CONFIG_ENV_OFFSET 0x50000
#define CONFIG_ENV_SIZE 0x10000
(SPI NAND)
#define CONFIG_ENV_OFFSET 0x220000
#define CONFIG_ENV_SIZE 0x20000
fw_env.config => SPI NOR
/dev/mtd0 A
0x10000
0x10000
1
如果燒錄的uboot位址是 0x10000
A = 0x50000-0x10000=0x40000
fw_env.h => 修改 config 路徑
#define CONFIG_FILE "/mnt/mtd/fw_env.config"
workspace/uboot#export PATH=/usr/src/arm-linux-3.3/toolchain_gnueabi-4.4.0_ARMv5TE/usr/bin:$PATH
workspace/uboot#make HOSTCC=arm-unknown-linux-uclibcgnueabi-gcc HOSTSTRIP=arm-unknown-linux-uclibcgnueabi-strip env
workspace/uboot#cd tools/env
int do_recover(void)
{
char cmd_load_image[128];
unsigned int offset,partsz;
unsigned int *mem_tmp;
int flag = H_HIDE_DOT;
/* get u-boot environment */
ENTRY e, *ep;
flag &= ~H_HIDE_DOT;
e.key = "recover_check";
e.data = NULL;
hsearch_r(e, FIND, &ep, &env_htab, flag);
/* It must need to burn in the empty partition at the end of all */
/* first-time check after burn-in image */
if (ep == NULL)
{
printf("there is no recover_check and insert !! \n");
e.key = "recover_check"; // pattern name in u-boot environment
e.data = "0xaaaaaaaa"; // pattern value in u-boot environment
hsearch_r(e, ENTER, &ep, &env_htab, flag);
if (!ep) {
printf("error inserting for u-boot variable !!\n");
return -1;
}
saveenv();
return 1;
}
//printf("%s=%s\n", ep->key, ep->data);
/* check checksum */
if(strcmp(ep->data,"0xaaaaaaaa")==0)
{
printf("burned-in image: no problem ! \n");
return 1;
}
else
{
printf("burned-in image: error ! \n\n");
printf("start recover mode >>>>> \n");
printf("recover mode: copy image ...... \n");
/* recovered partition */
#ifdef CONFIG_SPI_NAND_GM
offset = nand_sys_hdr->image[4].addr;
partsz = nand_sys_hdr->image[4].size+nand_sys_hdr->image[5].size+nand_sys_hdr->image[6].size;
#else
offset = spi_sys_hdr->image[4].addr;
partsz = spi_sys_hdr->image[4].size+spi_sys_hdr->image[5].size+spi_sys_hdr->image[6].size;
#endif
printf("recover mode: offset = 0x%x size = 0x%x \n",offset , partsz);
/* clear the memory tmp */
mem_tmp = (unsigned int *)malloc(partsz);
memset(mem_tmp, 0x00, partsz);
#ifdef CONFIG_SPI_NAND_GM
sprintf(cmd_load_image, "nand read 0x%x 0x%x 0x%x", (unsigned int)mem_tmp ,offset , partsz);
offset = nand_sys_hdr->image[1].addr;
#else
sprintf(cmd_load_image, "sf probe 0:0;sf read 0x%x 0x%x 0x%x", (unsigned int)mem_tmp ,offset , partsz);
offset = spi_sys_hdr->image[1].addr;
#endif
/* start read from spi flash to memory */
if (run_command(cmd_load_image, 0) != 0) {
printf("copy image fail \n");
return -1;
}
printf("recover mode: recover image ...... \n");
printf("recover mode: offset = 0x%x size = 0x%x \n",offset , partsz);
/* start write from memory to spi flash */
#ifdef CONFIG_SPI_NAND_GM
sprintf(cmd_load_image, "nand erase 0x%x 0x%x", offset, partsz);
if (run_command(cmd_load_image, 0) != 0) {
printf("erase partition fail \n");
return -1;
}
/* update partition */
sprintf(cmd_load_image, "nand write 0x%x 0x%x 0x%x", (unsigned int)mem_tmp , offset ,partsz);
if (run_command(cmd_load_image, 0) != 0) {
printf("write partition fail \n");
return -1;
}
offset = nand_sys_hdr->image[6].size+nand_sys_hdr->image[6].addr;
#else
sprintf(cmd_load_image, "sf probe 0:0;sf update 0x%x 0x%x 0x%x", (unsigned int)mem_tmp , offset ,partsz);
if (run_command(cmd_load_image, 0) != 0) {
printf("update image fail \n");
return -1;
}
offset = spi_sys_hdr->image[6].size+spi_sys_hdr->image[6].addr;
#endif
printf("recover mode: recover finish ...... \n");
/* set checksum after recovering */
e.key = "recover_check";
e.data = "0xaaaaaaaa";
hsearch_r(e, ENTER, &ep, &env_htab, flag);
if (!ep) {
printf("Error inserting for u-boot variable !!\n");
return -1;
}
saveenv();
}
printf("\n");
do_reset(NULL, 0, 0, NULL); // reset the system after recover-mode
return 1;
}
沒有留言:
張貼留言