1 /* *@defgroup ota_updater_api
2  * @{
3  *
4  * This is an include file of OTA updater to install new Firmware.
5  *
6  * Copyright (C) 2015-2021 Alibaba Group Holding Limited
7  */
8 #ifndef OTA_UPDATE_H
9 #define OTA_UPDATE_H
10 #include "ota_agent.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /**
17  *  ENUM: OTA Updater ERRNO.
18  */
19 typedef enum {
20      OTA_UPDATER_OK         = 0,
21      OTA_NB_INVALID_PARAM   = -1,  /* ota patch invalid parameter */
22      OTA_NB_HEADER_FAIL     = -2,  /* ota patch header fail */
23      OTA_NB_MEMORY_FAIL     = -3,  /* ota patch memory fail */
24      OTA_NB_READ_CTRL_FAIL  = -4,  /* ota patch read control fail */
25      OTA_NB_READ_DIFF_FAIL  = -5,  /* ota patch read diff fail */
26      OTA_NB_READ_OLD_FAIL   = -6,  /* ota patch read old fail */
27      OTA_NB_READ_EXTRA_FAIL = -7,  /* ota patch read extra fail */
28      OTA_NB_WRITE_DATA_FAIL = -8,  /* ota patch write data fail */
29      OTA_NB_CRC_COMP_FAIL   = -9,  /* ota patch crc fail */
30      OTA_XZ_PARAM_FAIL      = -10, /* ota XZ parameter fail */
31      OTA_XZ_CRC_FAIL        = -11, /* ota XZ crc fail */
32      OTA_XZ_UNCOMP_FAIL     = -12, /* ota XZ uncompress fail */
33      OTA_XZ_VERIFY_FAIL     = -13, /* ota XZ verify fail */
34      OTA_XZ_MEM_FAIL        = -14, /* ota XZ memory fail */
35      OTA_YMODEM_UP_FAIL     = -15, /* ota Ymodem upgrade fail */
36      OTA_USB_UP_FAIL        = -16, /* ota USB upgrade fail */
37      OTA_IMAGE_CRC_FAIL     = -17, /* ota image crc fail */
38      OTA_IMAGE_COPY_FAIL    = -18, /* ota image copy fail */
39 } OTA_UPDATER_E;
40 
41 /**
42  * ota_nbpatch_main  ota nbpatch main.
43  *
44  * @return OTA_SUCCESS            OTA success.
45  * @return OTA_NB_INVALID_PARAM   OTA patch invalid parameter.
46  * @return OTA_NB_HEADER_FAIL     OTA patch header fail.
47  * @return OTA_NB_MEMORY_FAIL     OTA patch memory fail.
48  * @return OTA_NB_READ_CTRL_FAIL  OTA patch read control fail.
49  * @return OTA_NB_READ_DIFF_FAIL  OTA patch read diff fail.
50  * @return OTA_NB_READ_OLD_FAIL   OTA patch read old fail.
51  * @return OTA_NB_READ_EXTRA_FAIL OTA patch read extra fail.
52  * @return OTA_NB_WRITE_DATA_FAIL OTA patch write data fail.
53  * @return OTA_NB_CRC_COMP_FAIL   OTA patch crc fail.
54  */
55 int ota_nbpatch_main(void);
56 
57 /**
58  * ota_xz_main   ota xz uncompress main.
59  *
60  * @return OTA_SUCCESS              OTA success.
61  * @return OTA_XZ_PARAM_FAIL        OTA XZ parameter fail.
62  * @return OTA_XZ_CRC_FAIL          OTA XZ crc fail.
63  * @return OTA_XZ_UNCOMP_FAIL       OTA XZ uncompress fail.
64  * @return OTA_XZ_VERIFY_FAIL       OTA XZ verify fail.
65  * @return OTA_XZ_MEM_FAIL          OTA XZ memory fail.
66  */
67 int ota_xz_main(void);
68 
69 /**
70  * ota_image_check   ota image crc check.
71  *
72  * @param[in] unsigned int addr     OTA check addr.
73  * @param[in] unsigned int size     OTA image size.
74  * @param[in] unsigned int crc      OTA image crc.
75  *
76  * @return OTA_SUCCESS              OTA success.
77  * @return OTA_IMAGE_CRC_FAIL       OTA image crc fail.
78  * @return OTA_IMAGE_COPY_FAIL      OTA image copy fail.
79  */
80 int ota_image_check(unsigned int addr, unsigned int size, unsigned int crc);
81 
82 /**
83  * ota_image_copy   ota image copy.
84  *
85  * @param[in] unsigned int addr     OTA image des addr.
86  * @param[in] unsigned int src      OTA image src addr.
87  * @param[in] unsigned int size     OTA image size.
88  *
89  * @return OTA_SUCCESS              OTA success.
90  * @return OTA_IMAGE_CRC_FAIL       OTA image crc fail.
91  * @return OTA_IMAGE_COPY_FAIL      OTA image copy fail.
92  */
93 int ota_image_copy(unsigned int dst, unsigned int src, unsigned int size);
94 
95 /**
96  * ota_read_parameter   ota read parameter from flash.
97  *
98  * @param[in] ota_boot_param_t *param ota parameter
99  *
100  * @return OTA_SUCCESS              OTA success.
101  * @return OTA_UPGRADE_WRITE_FAIL   OTA upgrade write fail.
102  * @return OTA_UPGRADE_PARAM_FAIL   OTA upgrade parameter fail.
103  * @return OTA_UPGRADE_FW_SIZE_FAIL OTA upgrade FW too big.
104  * @return OTA_UPGRADE_SET_BOOT_FAIL OTA upgrade set boot fail.
105  */
106 int ota_patch_read_param(ota_boot_param_t *param);
107 
108 /**
109  * ota_update_parameter  ota update parameter to flash.
110  *
111  * @param[in] ota_boot_param_t *param ota parameter
112  *
113  * @return OTA_SUCCESS              OTA success.
114  * @return OTA_UPGRADE_WRITE_FAIL   OTA upgrade write fail.
115  * @return OTA_UPGRADE_PARAM_FAIL   OTA upgrade parameter fail.
116  * @return OTA_UPGRADE_FW_SIZE_FAIL OTA upgrade FW too big.
117  * @return OTA_UPGRADE_SET_BOOT_FAIL OTA upgrade set boot fail.
118  */
119 int ota_patch_write_param(ota_boot_param_t *param);
120 
121 /**
122  * @}
123  */
124 #ifdef __cplusplus
125 }
126 #endif
127 #endif
128