diff --git a/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c b/u-boot-2020.01/board/hisilicon/hi3516dv300/hi3516dv300.c index c7db76dbec6faa1ea27bf2c761c2223c5f28e7c6..24c4776112542c9255c54c5035cab3f874d0c451 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 @@ -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 306d320dcc5ad0da58a90f67dc9ab23dbf8aa2b4..f5b11ed9b99792a80a1c2c9d634d8405e2181086 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,44 @@ 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:%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; + } + data.update_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; + } + 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 +1059,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 +1136,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 +1153,8 @@ static int update_to_flash(void) cnt++; } while (res < 0); } + + set_update_status(update_status); if (uboot_updated == 1) { printf("update success!\n"); 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 215547598f9bc7d03d61da990453da24efe0e675..c4df8253b60030df7f4751fe6aa11036b7ae3bac 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 df0bb5a1708a4ebcdeb2ec9b19474714846748f1..b277cc8bdef5e78047ebb1dbcc6dad749ee5537e 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);