From 253370cc8b15cd9aeb443aa35be42b9717f43556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=B8=85?= Date: Sat, 18 Sep 2021 03:50:45 +0000 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20add=20liteos=20patch=20ability=20Si?= =?UTF-8?q?gned-off-by:=20=E9=A9=AC=E5=B8=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/hisilicon/hi3516dv300/hi3516dv300.c | 128 +++++++++++++++++- .../product/hiupdate/auto_update_adaptation.c | 7 +- .../product/hiupdate/ota_update/ota_update.c | 2 +- 3 files changed, 132 insertions(+), 5 deletions(-) diff --git a/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c b/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c index 24c4776112..ad645a12d6 100755 --- a/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c +++ b/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c @@ -444,7 +444,7 @@ static int g_isRecovery = 0; char g_bootArgsStr[ARG_SZ]; -static void ChangeBootArgs() // get bootargs from emmc +static void ChangeBootArgs(void) // get bootargs from emmc { char *emmcBootArgs = env_get("bootargs"); if (!emmcBootArgs) { @@ -465,7 +465,7 @@ static void ChangeBootArgs() // get bootargs from emmc } } -static int EmmcInitParam() // get "boot_updater" string in misc,then set env +static int EmmcInitParam(void) // get "boot_updater" string in misc,then set env { const char rebootHead[] = "mem=640M console=ttyAMA0,115200 mmz=anonymous,0,0xA8000000,384M " "clk_ignore_unused androidboot.selinux=permissive skip_initramfs rootdelay=10 init=/init " @@ -517,6 +517,128 @@ static int EmmcInitParam() // get "boot_updater" string in misc,the return g_isRecovery; } +/* where to load files into memory */ +#define LOAD_ADDR ((unsigned char *)0x83000000) + +#define OTA_MAX_COMPONENT_NUM 8 +#define READ_BUF_LEN 4096 +#define OTA_PATH_LEN 64 +#define OTA_IMG_PATH "/update/version" +#define OTA_USE_PATH "/update" + + +const char *g_imgList[OTA_MAX_COMPONENT_NUM] = { "OTA.tag", "config", "u-boot.bin", "kernel.bin", + "rootfs.img", "rootfs_ext4.img", "patch.img", "infocomp.bin" }; + +int get_img_path(int idx, int verIdx, char *path, unsigned int len) +{ + if (path == NULL) { + return -1; + } + + char tmpPath[OTA_PATH_LEN] = {0}; + if (sprintf(tmpPath, "%s%d/%s", OTA_IMG_PATH, verIdx, g_imgList[idx]) <= 0) { + printf("sprintf ver:%d imgPath:%s fail!\r\n", verIdx, g_imgList[idx]); + return -1; + } + if (!strcpy(path, tmpPath)) { + printf("strcpy ver:%d imgPath:%s fail!\r\n", verIdx, g_imgList[idx]); + return -1; + } + + return 0; +} + +int get_write_path(int idx, char *path, unsigned int len) +{ + if (path == NULL) { + return -1; + } + + char tmpPath[OTA_PATH_LEN] = {0}; + if (sprintf(tmpPath, "%s/%s", OTA_USE_PATH, g_imgList[idx]) <= 0) { + printf("sprintf use path %s fail!\r\n", g_imgList[idx]); + return -1; + } + if (!strcpy(path, tmpPath)) { + printf("strcpy use path %s fail!\r\n", g_imgList[idx]); + return -1; + } + + return 0; +} + +int move_to_ota_path(int verIdx) +{ + unsigned long aufile_size = 0; + for (int idx = 0; idx < OTA_MAX_COMPONENT_NUM; idx++) { + char imgPath[OTA_PATH_LEN] = {0}; + int ret = get_img_path(idx, verIdx, imgPath, sizeof(imgPath)); + if (ret != 0 || (!fat_exists(imgPath))) { + continue; + } + + long long imgSize = 0; + if (!fat_size(imgPath, &imgSize)) { + aufile_size = ALIGN((unsigned long)imgSize, CONFIG_SYS_CACHELINE_SIZE); + memset(LOAD_ADDR, 0xff, aufile_size); + } else { + printf("get %s fat_size error\n", imgPath); + return -1; + } + + char writePath[OTA_PATH_LEN] = {0}; + ret = get_write_path(idx, writePath, sizeof(writePath)); + if (ret != 0) { + printf("get write path error, verIdx:%d, imgIdx:%d\n", verIdx, idx); + return -1; + } + + long long sz = file_fat_read(imgPath, LOAD_ADDR, (unsigned long)imgSize); + if (sz <= 0) { + printf("%s fat_read error\n", imgPath); + return -1; + } + + long long writeLen = 0; + ret = file_fat_write(writePath, (void *)LOAD_ADDR, 0, sz, &writeLen); + if (ret < 0) { + printf("write data to %s error\n", writePath); + return -1; + } + + (void)fat_unlink(imgPath); + } + return 0; +} + +int do_ota_auto_update(void) +{ + int updateFlag = -1; + int verIdx = 1; + int tagIdx = 0; + while (1) { + // Check whether OTA.tag is valid. + char tagPath[OTA_PATH_LEN] = {0}; + int ret = get_img_path(tagIdx, verIdx, tagPath, sizeof(tagPath)); + if (ret != 0 || (!fat_exists(tagPath))) { + printf("get verIdx:%d OTA.tag path fail, or file not exist.\r\n", verIdx); + break; + } + + ret = move_to_ota_path(verIdx); + if (ret != 0) { + printf("move_to_ota_path version:%d faild\n", verIdx); + return ret; + } + updateFlag = do_auto_update(); + printf("version:%d update ret %d\n", verIdx, updateFlag); + + verIdx++; + } + return updateFlag; +} + int misc_init_r(void) { const char cmdBuf[] = "mmc read 0x0 0x80000000 0x800 0x4800; bootm 0x80000000"; @@ -560,7 +682,7 @@ int misc_init_r(void) #if (CONFIG_AUTO_UPDATE == 1) int update_flag = -1; if (auto_update_flag) - update_flag = do_auto_update(); + update_flag = do_ota_auto_update(); if (bare_chip_program && !auto_update_flag) save_bootdata_to_flash(); if (update_flag == 0) diff --git a/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c b/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c index f5b11ed9b9..8a9ad85046 100644 --- a/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c +++ b/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c @@ -1044,6 +1044,8 @@ static void set_update_status(int status) } #endif +int g_update_status = -1; + /* * If none of the update file(u-boot, kernel or rootfs) was found * in the medium, return -1; @@ -1059,7 +1061,6 @@ static int update_to_flash(void) int cnt; int uboot_updated = 0; char buf[NAME_MAX_LEN] = {0}; - int update_status = 1; #ifdef CONFIG_AUTO_OTA_UPDATE if (g_is_ota) { @@ -1131,6 +1132,9 @@ static int update_to_flash(void) /* customer wants. */ cnt = 0; do { + if (g_update_status != 0) { + g_update_status = 1; + } res = au_do_update(i, (unsigned long)sz); if (!res) { printf("%s write success!\n", aufile[i]); @@ -1154,6 +1158,7 @@ static int update_to_flash(void) } while (res < 0); } + int update_status = (g_update_status == 1) ? 1 : 0; set_update_status(update_status); if (uboot_updated == 1) { diff --git a/u-boot-2020.01/product/hiupdate/ota_update/ota_update.c b/u-boot-2020.01/product/hiupdate/ota_update/ota_update.c index a9305c692e..2985f950c2 100644 --- a/u-boot-2020.01/product/hiupdate/ota_update/ota_update.c +++ b/u-boot-2020.01/product/hiupdate/ota_update/ota_update.c @@ -197,7 +197,7 @@ void clear_ota_files(void) char path[OTA_PATH_LEN] = {0}; unsigned int i; - printf("\nupdate: clear unused file:"); + printf("\nupdate: clear unused file:\n"); for (i = 0; i < g_component_num; i++) { if (get_ota_file_path( (char *)g_component_infos.table[i].addr, -- Gitee From c50fa8720eb4176653ee817fa60e7c35ab52fe8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=B8=85?= Date: Sat, 18 Sep 2021 03:58:20 +0000 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20add=20liteos=20patch=20ability=20Si?= =?UTF-8?q?gned-off-by:=20=E9=A9=AC=E5=B8=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- u-boot-2020.01/product/hiupdate/auto_update_adaptation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c b/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c index 8a9ad85046..9249b689e4 100644 --- a/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c +++ b/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c @@ -1142,7 +1142,7 @@ static int update_to_flash(void) #ifdef CONFIG_AUTO_OTA_UPDATE if (res) { // record update status as failed - update_status = 0; + g_update_status = 0; } if (g_is_ota) break; -- Gitee