add errcode support for ota
This commit is contained in:
14
components/ota/common/env/ota_env.c
vendored
14
components/ota/common/env/ota_env.c
vendored
@@ -19,23 +19,25 @@
|
||||
#include "ota_env.h"
|
||||
#include "ota_partition.h"
|
||||
|
||||
int ota_env_init(ota_updt_type_t updt_type, uint32_t partition_addr, ota_flash_drv_t *flash_drv, ota_flash_prop_t *flash_prop)
|
||||
ota_err_t ota_env_init(ota_updt_type_t updt_type, uint32_t partition_addr, ota_flash_drv_t *flash_drv, ota_flash_prop_t *flash_prop)
|
||||
{
|
||||
ota_err_t ret;
|
||||
|
||||
if (ota_flash_init(flash_drv, flash_prop) < 0) {
|
||||
return -1;
|
||||
return OTA_ERR_FLASH_INIT_FAIL;
|
||||
}
|
||||
|
||||
if (ota_partition_load(updt_type, partition_addr) < 0) {
|
||||
return -1;
|
||||
if ((ret = ota_partition_load(updt_type, partition_addr)) != OTA_ERR_NONE) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (tos_kv_init(ota_partition_start(OTA_PARTITION_KV),
|
||||
ota_partition_end(OTA_PARTITION_KV),
|
||||
(kv_flash_drv_t *)flash_drv,
|
||||
(kv_flash_prop_t *)flash_prop) != KV_ERR_NONE) {
|
||||
return -1;
|
||||
return OTA_ERR_KV_FAIL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return OTA_ERR_NONE;
|
||||
}
|
||||
|
||||
|
3
components/ota/common/env/ota_env.h
vendored
3
components/ota/common/env/ota_env.h
vendored
@@ -21,8 +21,9 @@
|
||||
#include "stdint.h"
|
||||
#include "ota_flash.h"
|
||||
#include "ota_partition.h"
|
||||
#include "ota_err.h"
|
||||
|
||||
int ota_env_init(ota_updt_type_t updt_type, uint32_t partition_addr, ota_flash_drv_t *flash_drv, ota_flash_prop_t *flash_prop);
|
||||
ota_err_t ota_env_init(ota_updt_type_t updt_type, uint32_t partition_addr, ota_flash_drv_t *flash_drv, ota_flash_prop_t *flash_prop);
|
||||
|
||||
#endif /* _OTA_ENV_H_ */
|
||||
|
||||
|
@@ -26,30 +26,31 @@ static int partitions_verify(ota_pt_t *pts, int n)
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (pts[i].start >= pts[i].end) {
|
||||
return -1;
|
||||
return OTA_ERR_PARTITION_ADDR_FAIL;
|
||||
}
|
||||
|
||||
if (!ota_flash_size_is_aligned(pts[i].end - pts[i].start)) {
|
||||
return -1;
|
||||
return OTA_ERR_PARTITION_NOT_ALIGN;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr)
|
||||
ota_err_t ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr)
|
||||
{
|
||||
uint8_t crc = 0;
|
||||
ota_pt_hdr_t hdr;
|
||||
ota_err_t ret;
|
||||
|
||||
memset(&ctrl, 0, sizeof(ota_pt_ctrl_t));
|
||||
|
||||
if (ota_flash_read(partition_addr, &hdr, sizeof(ota_pt_hdr_t)) != 0) {
|
||||
return -1;
|
||||
return OTA_ERR_PARTITION_READ_FAIL;
|
||||
}
|
||||
|
||||
if (hdr.magic != OTA_PARTITION_MAGIC) {
|
||||
return -1;
|
||||
return OTA_ERR_PARTITION_MAGIC_NOT_SAME;
|
||||
}
|
||||
|
||||
ctrl.updt_type = updt_type;
|
||||
@@ -59,33 +60,33 @@ int ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr)
|
||||
|
||||
if (updt_type == OTA_UPDATE_IN_POSITION) {
|
||||
if (ota_flash_read(partition_addr + sizeof(ota_pt_hdr_t), &IP_PTS, sizeof(ota_ip_pts_t)) != 0) {
|
||||
return -1;
|
||||
return OTA_ERR_PARTITION_READ_FAIL;
|
||||
}
|
||||
|
||||
if (partitions_verify(IP_PTS_ARRAY, sizeof(IP_PTS) / sizeof(ota_pt_t)) != 0) {
|
||||
return -1;
|
||||
if ((ret = partitions_verify(IP_PTS_ARRAY, sizeof(IP_PTS) / sizeof(ota_pt_t))) != OTA_ERR_NONE) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
crc = partitions_crc(crc, IP_PTS_ARRAY, sizeof(IP_PTS) / sizeof(ota_pt_t));
|
||||
} else if (updt_type == OTA_UPDATE_PING_PONG) {
|
||||
if (ota_flash_read(partition_addr + sizeof(ota_pt_hdr_t), &PP_PTS, sizeof(ota_pp_pts_t)) != 0) {
|
||||
return -1;
|
||||
return OTA_ERR_PARTITION_READ_FAIL;
|
||||
}
|
||||
|
||||
if (partitions_verify(PP_PTS_ARRAY, sizeof(PP_PTS) / sizeof(ota_pt_t)) != 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
crc = partitions_crc(crc, PP_PTS_ARRAY, sizeof(PP_PTS) / sizeof(ota_pt_t));
|
||||
} else {
|
||||
return -1;
|
||||
return OTA_ERR_UPDT_TYPE_UNKOWN;
|
||||
}
|
||||
|
||||
if (crc != hdr.crc) {
|
||||
return -1;
|
||||
return OTA_ERR_PARTITION_CRC_FAIL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return OTA_ERR_NONE;
|
||||
}
|
||||
|
||||
uint32_t ota_partition_start(ota_pt_type_t pt_type)
|
||||
|
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "crc8.h"
|
||||
#include "ota_image.h"
|
||||
#include "ota_err.h"
|
||||
|
||||
#define OTA_PARTITION_INVALID (uint32_t)-1
|
||||
|
||||
@@ -128,7 +129,7 @@ typedef struct ota_partition_control_st {
|
||||
ota_pts_t pts;
|
||||
} ota_pt_ctrl_t;
|
||||
|
||||
int ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr);
|
||||
ota_err_t ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr);
|
||||
|
||||
uint32_t ota_partition_start(ota_pt_type_t pt_type);
|
||||
|
||||
|
Reference in New Issue
Block a user