diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/ota/ota_bootloader_recovery/MDK-ARM/TencentOS_tiny.uvoptx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/ota/ota_bootloader_recovery/MDK-ARM/TencentOS_tiny.uvoptx index 649f287d..cfe53ca9 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/ota/ota_bootloader_recovery/MDK-ARM/TencentOS_tiny.uvoptx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/ota/ota_bootloader_recovery/MDK-ARM/TencentOS_tiny.uvoptx @@ -1172,7 +1172,7 @@ ota_recovery - 0 + 1 0 0 0 diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/ota/ota_bootloader_recovery/Src/main.c b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/ota/ota_bootloader_recovery/Src/main.c index 645f6e67..f9a4d790 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/ota/ota_bootloader_recovery/Src/main.c +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/ota/ota_bootloader_recovery/Src/main.c @@ -55,17 +55,17 @@ int main(void) return -1; } -#if 1 - if (ota_recovery_xip() != 0) { - printf("recovery failed!\n"); +#if 0 + if ((ret = ota_recovery_xip()) != OTA_ERR_NONE) { + printf("recovery failed, OTA errcode = %d!\r\n", ret); } else { - printf("recovery successfully!\n"); + printf("recovery successfully!\r\n"); } #else - if (ota_recovery() != 0) { - printf("recovery failed!\n"); + if ((ret = ota_recovery()) != OTA_ERR_NONE) { + printf("recovery failed, OTA errcode = %d!\r\n", ret); } else { - printf("recovery successfully!\n"); + printf("recovery successfully!\r\n"); } #endif diff --git a/components/ota/common/env/ota_env.c b/components/ota/common/env/ota_env.c index 666e6617..54126742 100644 --- a/components/ota/common/env/ota_env.c +++ b/components/ota/common/env/ota_env.c @@ -35,7 +35,7 @@ ota_err_t ota_env_init(ota_updt_type_t updt_type, uint32_t partition_addr, ota_f ota_partition_end(OTA_PARTITION_KV), (kv_flash_drv_t *)flash_drv, (kv_flash_prop_t *)flash_prop) != KV_ERR_NONE) { - return OTA_ERR_KV_FAIL; + return OTA_ERR_KV_INIT_FAIL; } return OTA_ERR_NONE; diff --git a/components/ota/common/info/ota_info.c b/components/ota/common/info/ota_info.c index 0a1414b3..03cc0823 100644 --- a/components/ota/common/info/ota_info.c +++ b/components/ota/common/info/ota_info.c @@ -16,7 +16,6 @@ *---------------------------------------------------------------------------*/ #include "tos_kv.h" -#include "ota_image.h" #include "ota_info.h" #include "ota_partition.h" @@ -35,19 +34,19 @@ ota_img_vs_t ota_info_curr_version(void) return version; } -int ota_info_update(ota_img_vs_t new_version) +ota_err_t ota_info_update(ota_img_vs_t new_version) { kv_err_t err; err = tos_kv_del("new_version"); if (err != KV_ERR_NONE && err != KV_ERR_NOT_EXIST) { - return -1; + return OTA_ERR_KV_DEL_FAIL; } if (tos_kv_set("cur_version", &new_version, sizeof(ota_img_vs_t)) != KV_ERR_NONE) { - return -1; + return OTA_ERR_KV_SET_FAIL; } - return 0; + return OTA_ERR_NONE; } diff --git a/components/ota/common/info/ota_info.h b/components/ota/common/info/ota_info.h index 0320e916..041e96c7 100644 --- a/components/ota/common/info/ota_info.h +++ b/components/ota/common/info/ota_info.h @@ -18,9 +18,12 @@ #ifndef _OTA_INFO_H_ #define _OTA_INFO_H_ +#include "ota_err.h" +#include "ota_image.h" + ota_img_vs_t ota_info_curr_version(void); -int ota_info_update(ota_img_vs_t new_version); +ota_err_t ota_info_update(ota_img_vs_t new_version); #endif /* _OTA_INFO_H_ */ diff --git a/components/ota/common/partition/ota_partition.c b/components/ota/common/partition/ota_partition.c index 61a4def5..1b30b1b3 100644 --- a/components/ota/common/partition/ota_partition.c +++ b/components/ota/common/partition/ota_partition.c @@ -20,7 +20,7 @@ static ota_pt_ctrl_t ctrl; -static int partitions_verify(ota_pt_t *pts, int n) +static ota_err_t partitions_verify(ota_pt_t *pts, int n) { int i = 0; @@ -34,7 +34,7 @@ static int partitions_verify(ota_pt_t *pts, int n) } } - return 0; + return OTA_ERR_NONE; } ota_err_t ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr) diff --git a/components/ota/recovery/include/ota_err.h b/components/ota/recovery/include/ota_err.h index 572ddabe..939f9c7f 100644 --- a/components/ota/recovery/include/ota_err.h +++ b/components/ota/recovery/include/ota_err.h @@ -23,15 +23,33 @@ typedef enum ota_err_en { OTA_ERR_FLASH_INIT_FAIL = 1u, - OTA_ERR_PARTITION_READ_FAIL = 2u, + OTA_ERR_PARTITION_READ_FAIL= 2u, OTA_ERR_PARTITION_MAGIC_NOT_SAME, OTA_ERR_PARTITION_ADDR_FAIL, OTA_ERR_PARTITION_NOT_ALIGN, OTA_ERR_PARTITION_CRC_FAIL, - OTA_ERR_UPDT_TYPE_UNKOWN, + OTA_ERR_UPDT_TYPE_UNKOWN = 7u, + + OTA_ERR_KV_INIT_FAIL = 8u, + OTA_ERR_KV_GET_FAIL, + OTA_ERR_KV_SET_FAIL, + OTA_ERR_KV_DEL_FAIL, + + + OTA_ERR_PATCH_READ_FAIL = 12u, + OTA_ERR_PATCH_MAGIC_NOT_SAME, + OTA_ERR_PATCH_CRC_FAIL, + + OTA_ERR_ACTIVE_APP_READ_FAIL = 15u, + OTA_ERR_ACTIVE_APP_CRC_FAIL, + + OTA_ERR_NEW_VERSION_NOT_SAME = 17u, + OTA_ERR_OLD_VERSION_NOT_SAME, + + OTA_ERR_BACK_UP_FAIL = 19u, + OTA_ERR_RECOVERRY_FAIL, - OTA_ERR_KV_FAIL } ota_err_t; #endif /* _OTA_ERR_H_ */ diff --git a/components/ota/recovery/include/ota_recovery.h b/components/ota/recovery/include/ota_recovery.h index eaba4788..1d494b9c 100644 --- a/components/ota/recovery/include/ota_recovery.h +++ b/components/ota/recovery/include/ota_recovery.h @@ -23,8 +23,9 @@ #include "ota_flash.h" #include "ota_image.h" #include "ota_patch.h" +#include "ota_err.h" -int ota_recovery(void); +ota_err_t ota_recovery(void); int ota_recovery_xip(void); diff --git a/components/ota/recovery/ota_recovery.c b/components/ota/recovery/ota_recovery.c index d74bf7c7..33abb8ec 100644 --- a/components/ota/recovery/ota_recovery.c +++ b/components/ota/recovery/ota_recovery.c @@ -29,7 +29,7 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) -static int patch_verify(ota_img_hdr_t *img_hdr) +static ota_err_t patch_verify(ota_img_hdr_t *img_hdr) { #define BUF_SIZE 128 static uint8_t buf[BUF_SIZE]; @@ -42,29 +42,29 @@ static int patch_verify(ota_img_hdr_t *img_hdr) /* drag the ota_img_hdr out of the flash */ if (ota_flash_read(patch_start, img_hdr, sizeof(ota_img_hdr_t)) < 0) { - return -1; + return OTA_ERR_PATCH_READ_FAIL; } /* 1. check whether new version patch downloaded */ if (tos_kv_get("new_version", &new_version, sizeof(ota_img_vs_t), &version_len) != KV_ERR_NONE) { - return -1; + return OTA_ERR_KV_GET_FAIL; } if (new_version.major != img_hdr->new_version.major || new_version.minor != img_hdr->new_version.minor) { - return -1; + return OTA_ERR_NEW_VERSION_NOT_SAME; } /* 2. verify magic */ if (img_hdr->magic != OTA_IMAGE_MAGIC) { - return -1; + return OTA_ERR_PATCH_MAGIC_NOT_SAME; } /* 3. is this patch for current version? */ cur_version = ota_info_curr_version(); if (cur_version.major != img_hdr->old_version.major || cur_version.minor != img_hdr->old_version.minor) { - return -1; + return OTA_ERR_OLD_VERSION_NOT_SAME; } /* 4. verify the patch crc checksum */ @@ -75,7 +75,7 @@ static int patch_verify(ota_img_hdr_t *img_hdr) while (remain_len > 0) { read_len = MIN(sizeof(buf), remain_len); if (ota_flash_read(patch_start, buf, read_len) < 0) { - return -1; + return OTA_ERR_PATCH_READ_FAIL; } crc = crc8(crc, buf, read_len); @@ -85,7 +85,7 @@ static int patch_verify(ota_img_hdr_t *img_hdr) } if (crc != img_hdr->patch_crc) { - return -1; + return OTA_ERR_PATCH_CRC_FAIL; } /* 5. verify the old crc checksum */ @@ -95,7 +95,7 @@ static int patch_verify(ota_img_hdr_t *img_hdr) while (remain_len > 0) { read_len = MIN(sizeof(buf), remain_len); if (ota_flash_read(active_app_start, buf, read_len) < 0) { - return -1; + return OTA_ERR_ACTIVE_APP_READ_FAIL; } crc = crc8(crc, buf, read_len); @@ -105,10 +105,10 @@ static int patch_verify(ota_img_hdr_t *img_hdr) } if (crc != img_hdr->old_crc) { - return -1; + return OTA_ERR_ACTIVE_APP_CRC_FAIL; } - return 0; + return OTA_ERR_NONE; } static int do_recovery(ota_img_hdr_t *hdr) @@ -154,12 +154,13 @@ static int app_copy(uint32_t dst, uint32_t dst_size, uint32_t src, uint32_t src_ return 0; } -int ota_recovery(void) +ota_err_t ota_recovery(void) { + ota_err_t ret; ota_img_hdr_t img_hdr; - if (patch_verify(&img_hdr)) { - return -1; + if ((ret = patch_verify(&img_hdr)) != OTA_ERR_NONE) { + return ret; } /* backup */ @@ -168,11 +169,10 @@ int ota_recovery(void) ota_partition_size(OTA_PARTITION_BACKUP_APP), ota_partition_start(OTA_PARTITION_ACTIVE_APP), ota_partition_size(OTA_PARTITION_ACTIVE_APP)) < 0) { - return -1; + return OTA_ERR_BACK_UP_FAIL; } if (do_recovery(&img_hdr) != 0) { - printf("recovery failed\n"); /* restore */ if (ota_partition_is_pingpong()) { @@ -181,13 +181,13 @@ int ota_recovery(void) ota_partition_start(OTA_PARTITION_BACKUP_APP), ota_partition_size(OTA_PARTITION_BACKUP_APP)); } - return -1; + return OTA_ERR_RECOVERRY_FAIL; } - if (ota_info_update(img_hdr.new_version) != 0) { - return -1; + if ((ret = ota_info_update(img_hdr.new_version)) != OTA_ERR_NONE) { + return ret; } - return 0; + return OTA_ERR_NONE; }