Uboot support used ota upgrade command upgrade system

This commit is contained in:
HuangXin 2018-08-23 11:39:09 +08:00
parent fff8e32ab3
commit 9b9ace1e6d
3 changed files with 98 additions and 11 deletions

View File

@ -194,7 +194,7 @@ static int ota_read_boot_image(void)
{
int read_bytes = 0;
if (fs_set_blk_dev("sunxi_flash", "boot", FS_TYPE_EXT))
if (fs_set_blk_dev("sunxi_flash", "0", FS_TYPE_EXT))
{
return -1;
}
@ -210,7 +210,7 @@ static int ota_read_rootfs_image(void)
{
int read_bytes = 0;
if (fs_set_blk_dev("sunxi_flash", "rootfs", FS_TYPE_EXT))
if (fs_set_blk_dev("sunxi_flash", "0", FS_TYPE_EXT))
{
return -1;
}
@ -221,6 +221,40 @@ static int ota_read_rootfs_image(void)
return read_bytes;
}
static int ota_calc_image_chksum(unsigned char* addr, int iSize, char* pChksm)
{
unsigned char md5sum[MD5_CHKSUM_LEN];
md5(addr, iSize, md5sum);
__bin2hex(pChksm, md5sum, MD5_CHKSUM_LEN);
return 0;
}
static int ota_upgrade_boot_image(void)
{
char cmdBuf[128];
memset(cmdBuf, 0, 128);
sprintf(cmdBuf, "sunxi_flash write 0x%x boot", READ_BOOT_ADDR);
run_command(cmdBuf, 0);
return 0;
}
static int ota_upgrade_rootfs_image(void)
{
char cmdBuf[128];
memset(cmdBuf, 0, 128);
sprintf(cmdBuf, "sunxi_flash write 0x%x rootfs", READ_ROOTFS_ADDR);
run_command(cmdBuf, 0);
return 0;
}
#if 0
static int ota_read_file(const char* pDev, const char* pPart, const char* pFile)
{
@ -246,6 +280,7 @@ int do_ota(cmd_tbl_t *cmdtp, int flag, int argc,
static int read_boot_size = 0, read_rootfs_size = 0;
printf("ota cmd: argc = %d\n", argc);
if (argc < 2)
return CMD_RET_USAGE;
@ -298,15 +333,20 @@ int do_ota(cmd_tbl_t *cmdtp, int flag, int argc,
}
else if(strncmp(argv[1], "upgrade", strlen("upgrade")) == 0)
{
int flag = 0;
int force = 0, flag = 0;
OTA_PARAMS otaInfo, upgInfo;
if(argc == 2)
{
flag = (1 << 0) | (1 << 1);
}
}
else
{
if(argc == 4)
{
force = simple_strtoul(argv[3], NULL, 16);
}
if(strncmp(argv[2], "boot", strlen("boot")) == 0)
{
flag |= 1;
@ -324,14 +364,61 @@ int do_ota(cmd_tbl_t *cmdtp, int flag, int argc,
}
if(flag == 0)
{
return CMD_RET_USAGE;
}
ota_read_params(&otaInfo);
memset(&upgInfo, 0, sizeof(OTA_PARAMS));
if(flag & (1 << 0))
{
printf("%s(%d)\n", __FUNCTION__, __LINE__);
upgInfo.bootfileSize = ota_read_boot_image();
printf("%s(%d)\n", __FUNCTION__, __LINE__);
ota_calc_image_chksum((unsigned char*)READ_BOOT_ADDR,
upgInfo.bootfileSize, upgInfo.bootChksum);
printf("%s(%d)\n", __FUNCTION__, __LINE__);
if(strcmp(upgInfo.bootChksum, otaInfo.bootChksum) != 0
|| upgInfo.bootfileSize != otaInfo.bootfileSize)
{
printf("Upgrade boot image maybe error:\n\t%s --> %s\n\t%u-%u\n",
upgInfo.bootChksum, otaInfo.bootChksum,
upgInfo.bootfileSize, otaInfo.bootfileSize);
if(force == 0)
{
return CMD_RET_FAILURE;
}
}
printf("%s(%d)\n", __FUNCTION__, __LINE__);
ota_upgrade_boot_image();
printf("%s(%d)\n", __FUNCTION__, __LINE__);
}
if(flag & (1 << 1))
{
printf("%s(%d)\n", __FUNCTION__, __LINE__);
upgInfo.rootfsfileSize = ota_read_rootfs_image();
printf("%s(%d)\n", __FUNCTION__, __LINE__);
ota_calc_image_chksum((unsigned char*)READ_ROOTFS_ADDR,
upgInfo.rootfsfileSize, upgInfo.rootfsChksum);
printf("%s(%d)\n", __FUNCTION__, __LINE__);
if(strcmp(upgInfo.rootfsChksum, otaInfo.rootfsChksum) != 0
|| upgInfo.rootfsfileSize != otaInfo.rootfsfileSize)
{
printf("Upgrade rootfs image maybe error:\n\t%s --> %s\n\t%u-%u\n",
upgInfo.rootfsChksum, otaInfo.rootfsChksum,
upgInfo.rootfsfileSize, otaInfo.rootfsfileSize);
if(force == 0)
{
return CMD_RET_FAILURE;
}
}
ota_upgrade_rootfs_image();
}
}
else
@ -344,15 +431,15 @@ int do_ota(cmd_tbl_t *cmdtp, int flag, int argc,
}
U_BOOT_CMD(ota, 4, 0, do_ota,
U_BOOT_CMD(ota, 5, 0, do_ota,
"netease OTA command:",
"<command> <parmeters>\n"
" erase <partiton name>\n"
" - erase mtd partiton\n"
" read <boot/rootfs>\n"
" - read ota image form UDISK file system\n"
" upgrade <boot/rootfs/all>\n"
" upgrade <boot/rootfs/all> [0/1(skip verify chksum)]\n"
" - read ota image form UDISK file system and upgrade nand partiton\n"
" show_params\n"
" - show ota params information"
" - show ota params information\n"
" - *********************************************");

View File

@ -76,10 +76,10 @@ size = 512
; downloadfile="recovery.fex"
; user_type = 0x8000
;[partition]
; name = misc
; size = 1024
; user_type = 0x8000
[partition]
name = misc
size = 1024
user_type = 0x8000
[partition]
name = UDISK