From 567320ec33338be20c0a19d8607d88d89f63f5fb Mon Sep 17 00:00:00 2001 From: maltose214 Date: Tue, 17 Aug 2021 20:17:12 +0800 Subject: [PATCH 1/7] add update status to metadata Signed-off-by: maltose214 --- .../board/hisilicon/hi3516dv300/hi3516dv300.c | 24 ++++++++- .../product/hiupdate/auto_update_adaptation.c | 53 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c b/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c index c7db76dbec..0171d2775c 100755 --- a/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c +++ b/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c @@ -260,6 +260,9 @@ int save_bootdata_to_flash(void) return 0; } +int auto_update_flag = 0; +int bare_chip_program = 0; + #define REG_BASE_GPIO0 0x120d0000 #define GPIO0_0_DATA_OFST 0x4 #define GPIO_DIR_OFST 0x400 @@ -516,7 +519,7 @@ static int EmmcInitParam() // get "boot_updater" string in misc,the int misc_init_r(void) { - const char cmdBuf[] = "mmc read 0x0 0x80000000 0x800 0x4800; bootm 0x80000000"; + const char cmdBuf[] = "mmc read 0x0 0x80000000 0x800 0x4800; go 0x80000000"; #ifdef CONFIG_RANDOM_ETHADDR random_init_r(); @@ -532,6 +535,18 @@ int misc_init_r(void) env_set("bootargs", g_bootArgsStr); env_set("bootcmd", cmdBuf); + /* auto update flag */ + if (is_auto_update()) + auto_update_flag = 1; + else + auto_update_flag = 0; + + /* bare chip program flag */ + if (is_bare_program()) + bare_chip_program = 1; + else + bare_chip_program = 0; + #ifdef CFG_MMU_HANDLEOK dcache_stop(); #endif @@ -543,6 +558,13 @@ int misc_init_r(void) #endif #if (CONFIG_AUTO_UPDATE == 1) + int update_flag = -1; + if (auto_update_flag) + update_flag = do_auto_update(); + if (bare_chip_program && !auto_update_flag) + save_bootdata_to_flash(); + if (update_flag == 0) + do_reset(NULL, 0, 0, NULL); #endif return 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 306d320dcc..16c686ac0d 100644 --- a/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c +++ b/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c @@ -1006,6 +1006,52 @@ write_op: bool g_is_ota; #endif /* CONFIG_AUTO_OTA_UPDATE */ +#ifdef CONFIG_AUTO_OTA_UPDATE +typedef struct { + unsigned char update_mode; + unsigned char running_partition; + unsigned char update_partiton; + unsigned char running_status; + unsigned char ota_status; + unsigned char reboot_status; + unsigned char update_status; +} UpdateMetaData; + +static void set_update_status(int status) +{ + printf("\nset_update_status status:%d\n",status); + const char *path = "/update/metadata"; + UpdateMetaData data = {0}; + int len = sizeof(data); + loff_t sz = file_fat_read(path, (void *)&data, len); + if (sz <= 0) { + printf("len is %d, sz is %lld invalid\n", len, sz); + return; + } + printf("pre - data.update_status %d\n", data.update_status); + data.updata_status = status; + loff_t size; + int ret = file_fat_write(path, (void *)&data, 0, len, &size); + if (ret < 0) { + printf("write data to /update/metadata error\n"); + return; + } + printf("%llu bytes written\n", size); + sz = file_fat_read(path, (void *)&data, len); + if (sz <= 0) { + printf("len is %d, sz is %lld invalid\n", len, sz); + return; + } + printf("new - data.update_status %d\n", data.update_status); + return; +} +#else +static void set_update_status(int status) +{ + return; +} +#endif + /* * If none of the update file(u-boot, kernel or rootfs) was found * in the medium, return -1; @@ -1021,6 +1067,7 @@ 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) { @@ -1097,6 +1144,10 @@ static int update_to_flash(void) printf("%s write success!\n", aufile[i]); } #ifdef CONFIG_AUTO_OTA_UPDATE + if (res) { + // record update status as failed + update_status = 0; + } if (g_is_ota) break; #endif /* CONFIG_AUTO_OTA_UPDATE */ @@ -1110,6 +1161,8 @@ static int update_to_flash(void) cnt++; } while (res < 0); } + + set_update_status(update_status); if (uboot_updated == 1) { printf("update success!\n"); -- Gitee From 67a2e8a884890b736e29587a98b21e5dbd9ac0ed Mon Sep 17 00:00:00 2001 From: maltose214 Date: Tue, 17 Aug 2021 20:27:28 +0800 Subject: [PATCH 2/7] add update status to metadata Signed-off-by: maltose214 --- 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 16c686ac0d..caabbadca4 100644 --- a/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c +++ b/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c @@ -1029,7 +1029,7 @@ static void set_update_status(int status) return; } printf("pre - data.update_status %d\n", data.update_status); - data.updata_status = status; + data.update_status = status; loff_t size; int ret = file_fat_write(path, (void *)&data, 0, len, &size); if (ret < 0) { -- Gitee From ffa7bfb82d2e8a4c153e0b31c9cbb44dda8eecf4 Mon Sep 17 00:00:00 2001 From: maltose214 Date: Wed, 18 Aug 2021 12:57:16 +0800 Subject: [PATCH 3/7] add update status to metadata Signed-off-by: maltose214 --- u-boot-2020.01/product/hiupdate/auto_update_adaptation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 caabbadca4..df2ef69d34 100644 --- a/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c +++ b/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c @@ -1019,7 +1019,7 @@ typedef struct { static void set_update_status(int status) { - printf("\nset_update_status status:%d\n",status); + printf("\nset update status:%d\n", status); const char *path = "/update/metadata"; UpdateMetaData data = {0}; int len = sizeof(data); @@ -1067,7 +1067,7 @@ static int update_to_flash(void) int cnt; int uboot_updated = 0; char buf[NAME_MAX_LEN] = {0}; - int update_status = 1; + int update_status = 1; #ifdef CONFIG_AUTO_OTA_UPDATE if (g_is_ota) { @@ -1162,7 +1162,7 @@ static int update_to_flash(void) } while (res < 0); } - set_update_status(update_status); + set_update_status(update_status); if (uboot_updated == 1) { printf("update success!\n"); -- Gitee From 4f09718a72daad0a98449102acf95742b791a91f Mon Sep 17 00:00:00 2001 From: maltose214 Date: Wed, 18 Aug 2021 14:34:05 +0800 Subject: [PATCH 4/7] add update status to metadata Signed-off-by: maltose214 --- u-boot-2020.01/product/hiupdate/auto_update_adaptation.c | 8 -------- 1 file changed, 8 deletions(-) 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 df2ef69d34..c010d52be3 100644 --- a/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c +++ b/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c @@ -1028,7 +1028,6 @@ static void set_update_status(int status) printf("len is %d, sz is %lld invalid\n", len, sz); return; } - printf("pre - data.update_status %d\n", data.update_status); data.update_status = status; loff_t size; int ret = file_fat_write(path, (void *)&data, 0, len, &size); @@ -1036,13 +1035,6 @@ static void set_update_status(int status) printf("write data to /update/metadata error\n"); return; } - printf("%llu bytes written\n", size); - sz = file_fat_read(path, (void *)&data, len); - if (sz <= 0) { - printf("len is %d, sz is %lld invalid\n", len, sz); - return; - } - printf("new - data.update_status %d\n", data.update_status); return; } #else -- Gitee From d0d0a9bd891600d455ea4e4f8c476edc46bd815b Mon Sep 17 00:00:00 2001 From: maltose214 Date: Thu, 26 Aug 2021 16:48:32 +0800 Subject: [PATCH 5/7] add update status to metadata Signed-off-by: maltose214 --- u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c b/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c index 0171d2775c..24c4776112 100755 --- a/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c +++ b/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c @@ -519,7 +519,7 @@ static int EmmcInitParam() // get "boot_updater" string in misc,the int misc_init_r(void) { - const char cmdBuf[] = "mmc read 0x0 0x80000000 0x800 0x4800; go 0x80000000"; + const char cmdBuf[] = "mmc read 0x0 0x80000000 0x800 0x4800; bootm 0x80000000"; #ifdef CONFIG_RANDOM_ETHADDR random_init_r(); -- Gitee From 889f82e9412c511c6db75d01b1c3b0c4a3d29c10 Mon Sep 17 00:00:00 2001 From: maltose214 Date: Thu, 9 Sep 2021 21:19:24 +0800 Subject: [PATCH 6/7] add patch info Signed-off-by: maltose214 --- u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.c | 1 + u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.c b/u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.c index 215547598f..c4df8253b6 100644 --- a/u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.c +++ b/u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.c @@ -82,6 +82,7 @@ static const char *get_ota_file_name(const char *addr) {"kernel_A", "kernel.bin"}, {"rootfs", "rootfs.img"}, {"rootfs_ext4", "rootfs_ext4.img"}, + {"patch", "patch.img"}, {"reserved", " "}, }; int i; diff --git a/u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.h b/u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.h index df0bb5a170..b277cc8bde 100644 --- a/u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.h +++ b/u-boot-2020.01/product/hiupdate/ota_update/ota_package_info.h @@ -22,7 +22,7 @@ #define OTA_ROOT_DIR "/update" #define OTA_TAG_FILE "OTA.tag" #define OTA_PATH_LEN 32 -#define OTA_MAX_COMPONENT_NUM 7 +#define OTA_MAX_COMPONENT_NUM 8 int change_to_ota_path(const char *src, char *ota_path, unsigned int len); int get_ota_file_path(const char *addr, char *path, unsigned int len); -- Gitee From a9b1f83353daf2e5ec2db8f27328365cd3e0a1ef Mon Sep 17 00:00:00 2001 From: maltose214 Date: Fri, 10 Sep 2021 20:40:35 +0800 Subject: [PATCH 7/7] add update status to metadata Signed-off-by: maltose214 --- u-boot-2020.01/product/hiupdate/auto_update_adaptation.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 c010d52be3..f5b11ed9b9 100644 --- a/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c +++ b/u-boot-2020.01/product/hiupdate/auto_update_adaptation.c @@ -1059,7 +1059,7 @@ static int update_to_flash(void) int cnt; int uboot_updated = 0; char buf[NAME_MAX_LEN] = {0}; - int update_status = 1; + int update_status = 1; #ifdef CONFIG_AUTO_OTA_UPDATE if (g_is_ota) { @@ -1154,7 +1154,7 @@ static int update_to_flash(void) } while (res < 0); } - set_update_status(update_status); + set_update_status(update_status); if (uboot_updated == 1) { printf("update success!\n"); -- Gitee