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);
|
||||
|
||||
|
38
components/ota/recovery/include/ota_err.h
Normal file
38
components/ota/recovery/include/ota_err.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* Tencent is pleased to support the open source community by making TencentOS
|
||||
* available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||
*
|
||||
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||
* License, except for the third-party components listed below which are
|
||||
* subject to different license terms. Your integration of TencentOS into your
|
||||
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||
* as the other licenses applicable to the third-party components included
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _OTA_ERR_H_
|
||||
#define _OTA_ERR_H_
|
||||
|
||||
typedef enum ota_err_en {
|
||||
OTA_ERR_NONE = 0u,
|
||||
|
||||
OTA_ERR_FLASH_INIT_FAIL = 1u,
|
||||
|
||||
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_KV_FAIL
|
||||
} ota_err_t;
|
||||
|
||||
#endif /* _OTA_ERR_H_ */
|
||||
|
Reference in New Issue
Block a user