1 /** @defgroup ota_agent_api
2  * @{
3  *
4  * This is an include file of OTA agent transporting with clould.
5  *
6  * Copyright (C) 2015-2021 Alibaba Group Holding Limited
7  */
8 
9 #ifndef OTA_AGENT_H
10 #define OTA_AGENT_H
11 
12 /*******************************************************************
13 ***********                OTA Agent                  **************
14 ***********                   |                       **************
15 ***********                   V                       **************
16 ***********             Service manager               **************
17 ***********  device ----- inform version -----> cloud **************
18 ***********  device ---- subcribe upgrade ----> cloud **************
19 ***********                   |                       **************
20 ***********                   V                       **************
21 ***********             Transport module              **************
22 ***********  device <---- transport message --- cloud **************
23 ***********  device <-- new version:url,sign -- cloud **************
24 ***********                   |                       **************
25 ***********                   V                       **************
26 ***********             Download module               **************
27 ***********  device <---- download firmware --- cloud **************
28 ***********                   |                       **************
29 ***********                   V                       **************
30 ***********             Common hal module             **************
31 ***********  device ---- update image ----> ota part  **************
32 ***********                   |                       **************
33 ***********                   V                       **************
34 ***********             Verify module                 **************
35 ***********  device ---- verfiy firmware ----- verify **************
36 ***********  device ----- report status -----  reboot **************
37 ***********                   |                       **************
38 ***********                   V                       **************
39 ***********                MCU module                 **************
40 ***********  device ----- send FW ------> MCU         **************
41 ********************************************************************/
42 
43 #define OTA_VERSION      "3.3.0"
44 #define OTA_TRANSTYPE    "1"
45 #define OTA_OS_TYPE      "0"
46 #define OTA_BOARD_TYPE   "0"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /** @addtogroup aos_ota OTA
53  *  OTA upgrade service.
54  *
55  *  @{
56  */
57 
58 /* OTA upgrade flag */
59 #define OTA_UPGRADE_CUST   0x8778 /* upgrade user customize image */
60 #define OTA_UPGRADE_ALL    0x9669 /* upgrade all image: kernel+framework+app */
61 #define OTA_UPGRADE_XZ     0xA55A /* upgrade xz compressed image */
62 #define OTA_UPGRADE_DIFF   0xB44B /* upgrade diff compressed image */
63 #define OTA_UPGRADE_KERNEL 0xC33C /* upgrade kernel image only */
64 #define OTA_UPGRADE_APP    0xD22D /* upgrade app image only */
65 #define OTA_UPGRADE_FS     0x7083 /* upgrade fs image only */
66 #define OTA_BIN_MAGIC_APP     0xabababab
67 #define OTA_BIN_MAGIC_KERNEL  0xcdcdcdcd
68 #define OTA_BIN_MAGIC_ALL     0xefefefef
69 #define OTA_BIN_MAGIC_MCU     0xefcdefcd
70 #define OTA_BIN_MAGIC_FS      0xabcdabcd
71 
72 /**
73  *  ENUM: OTA Agent ERRNO.
74  */
75 typedef enum {
76         OTA_FINISH                = 4,   /*OTA finish status*/
77         OTA_DOWNLOAD              = 3,   /*OTA download status*/
78         OTA_TRANSPORT             = 2,   /*OTA transport status*/
79         OTA_INIT                  = 1,   /*OTA init status*/
80         OTA_SUCCESS               = 0,
81         OTA_INIT_FAIL             = -1,  /*OTA init failed.*/
82         OTA_TRANSPORT_INT_FAIL    = -2,  /*OTA transport init failed.*/
83         OTA_TRANSPORT_PAR_FAIL    = -3,  /*OTA transport parse failed.*/
84         OTA_TRANSPORT_VER_FAIL    = -4,  /*OTA transport verion is too old.*/
85         OTA_DOWNLOAD_INIT_FAIL    = -5,  /*OTA download init failed.*/
86         OTA_DOWNLOAD_HEAD_FAIL    = -6,  /*OTA download header failed.*/
87         OTA_DOWNLOAD_CON_FAIL     = -7,  /*OTA download connect failed.*/
88         OTA_DOWNLOAD_REQ_FAIL     = -8,  /*OTA download request failed.*/
89         OTA_DOWNLOAD_RECV_FAIL    = -9,  /*OTA download receive failed.*/
90         OTA_VERIFY_MD5_FAIL       = -10, /*OTA verfiy MD5 failed.*/
91         OTA_VERIFY_SHA2_FAIL      = -11, /*OTA verfiy SH256 failed.*/
92         OTA_VERIFY_RSA_FAIL       = -12, /*OTA verfiy RSA failed.*/
93         OTA_VERIFY_IMAGE_FAIL     = -13, /*OTA verfiy image failed.*/
94         OTA_UPGRADE_WRITE_FAIL    = -14, /*OTA upgrade write failed.*/
95         OTA_UPGRADE_PARAM_FAIL    = -15, /*OTA upgrade parameter failed.*/
96         OTA_UPGRADE_FW_SIZE_FAIL  = -16, /*OTA upgrade FW too big.*/
97         OTA_UPGRADE_SET_BOOT_FAIL = -17, /*OTA upgrade set boot failed.*/
98         OTA_CUSTOM_CALLBAK_FAIL   = -18, /*OTA custom callback failed.*/
99         OTA_MCU_INIT_FAIL         = -19, /*OTA MCU init failed.*/
100         OTA_MCU_VERSION_FAIL      = -20, /*OTA MCU version failed.*/
101         OTA_MCU_NOT_READY         = -21, /*OTA MCU not ready.*/
102         OTA_MCU_REBOOT_FAIL       = -22, /*OTA MCU fail to reboot.*/
103         OTA_MCU_HEADER_FAIL       = -23, /*OTA MCU header error.*/
104         OTA_MCU_UPGRADE_FAIL      = -24, /*OTA MCU upgrade fail.*/
105         OTA_INVALID_PARAMETER     = -25, /*OTA INVALID PARAMETER.*/
106 } OTA_ERRNO_E;
107 
108 typedef enum {
109     OTA_REPORT_UPGRADE_ERR  = -1, /* ota report upgrading failed to cloud*/
110     OTA_REPORT_DOWNLOAD_ERR = -2, /* ota report downloading failed to cloud*/
111     OTA_REPORT_VERIFY_ERR   = -3, /* ota report image verified err to cloud*/
112     OTA_REPORT_BURN_ERR     = -4, /* ota report image burning failed to cloud*/
113 } OTA_REPORT_CLOUD_ERRNO_E;
114 
115 #define OTA_URL_LEN  256 /*OTA download url max len*/
116 #define OTA_HASH_LEN 66  /*OTA download file hash len*/
117 #define OTA_SIGN_LEN 256 /*OTA download file sign len*/
118 #define OTA_VER_LEN  64  /*OTA version string max len*/
119 
120 typedef enum {
121   OTA_EVENT_UPGRADE_TRIGGER,
122   OTA_EVENT_DOWNLOAD,
123   OTA_EVENT_INSTALL,
124   OTA_EVENT_LOAD,
125   OTA_EVENT_REPORT_VER,
126 } OTA_EVENT_ID;
127 /**
128  *  Struct: OTA boot parameter.
129  */
130 typedef struct  {
131     unsigned int   dst_adr;    /*Single Bank: Destination Address: APP partition.*/
132     unsigned int   src_adr;    /*Single Bank: Copy from Source Address: OTA partition.*/
133     unsigned int   len;        /*Single Bank: Download file len */
134     unsigned short crc;        /*Single Bank: Download file CRC */
135     unsigned short upg_flag;   /*Upgrade flag: OTA_UPGRADE_ALL OTA_UPGRADE_XZ OTA_UPGRADE_DIFF*/
136     unsigned char  boot_count; /*Boot count: When >=3 Rollback to old version in BL for dual-banker boot*/
137              int   upg_status; /*OTA upgrade status*/
138     unsigned char  hash_type;  /*OTA download hash type*/
139 
140     char  url[OTA_URL_LEN];    /*OTA download url*/
141     char  sign[OTA_SIGN_LEN];  /*OTA download file sign*/
142     char  hash[OTA_HASH_LEN];  /*OTA download file hash*/
143     char  ver[OTA_VER_LEN];    /*OTA get version*/
144 
145     unsigned int   old_size;     /*Diff upgrade: patch old data size*/
146     unsigned short patch_num;    /*Diff upgrade: patch num*/
147     unsigned short patch_status; /*Diff upgrade: patch status*/
148     unsigned int   patch_off;    /*Diff upgrade: patch offset*/
149     unsigned int   new_off;      /*Diff upgrade: patch new data offset*/
150     unsigned int   new_size;     /*Diff upgrade: patch new data size*/
151     unsigned int   upg_magic;    /*OTA upgrade image magic*/
152     unsigned char  boot_type;    /*OS boot type:Single boot(0x00), dual boot(0x01)*/
153     unsigned char  reserved[13]; /*OTA Reserved*/
154     unsigned short param_crc;    /*OTA Parameter crc*/
155 } ota_boot_param_t;
156 
157 /**
158  *  Struct:  OTA sign info.
159  */
160 typedef struct {
161     unsigned int encrypto_magic; /*encrypto type: RSA:0xAABBCCDD or ECC:0xDDCCBBAA*/
162     char padding_mode;           /*sign padding mode:PKCS1 or OAEP*/
163     char sign_hash_type;         /*sign hash type*/
164     char abstract_hash_type;     /*calculate image hash type*/
165     char reserved[97];           /*reserved buf*/
166     char hash[32];               /*image hash value(sha256)*/
167     char signature[256];         /*image digest signature*/
168 } ota_sign_info_t;
169 
170 /**
171  *  Struct:  OTA image info.
172  */
173 typedef struct {
174     unsigned int   image_magic;   /* image magic */
175     unsigned int   image_size;    /* image size */
176     unsigned char  image_md5[16]; /* image md5 info */
177     unsigned char  image_num;     /* image number */
178     unsigned char  image_res;     /* image resouce */
179     unsigned short image_crc16;   /* image crc16 */
180 } ota_image_info_t;
181 
182 typedef struct {
183     ota_sign_info_t *sign_info;   /* Image sign info */
184     ota_image_info_t *image_info; /* Package Image info */
185 } ota_image_header_t;
186 
187 typedef struct {
188     void (*on_user_event_cb)(int event, int errnumb, void *param);
189     void *param; /* users paramter */
190 } ota_feedback_msg_func_t;
191 
192 typedef int (*report_func)(void *, uint32_t);
193 
194 typedef int (*triggered_func)(void *, char *, char *, void *);
195 
196 typedef struct {
197     report_func report_status_cb;
198     void *param; /* users paramter */
199 } ota_report_status_func_t;
200 
201 typedef struct {
202     triggered_func triggered_ota_cb;
203     void *param; /* users paramter */
204 } ota_triggered_func_t;
205 
206 typedef struct {
207     char module_name[33];
208     char store_path[77];
209     int module_type;
210 } ota_store_module_info_t;
211 
212 /* OTA service manager */
213 typedef struct ota_service_s {
214     char pk[20+1];                /* Product Key */
215     char ps[64+1];                /* Product secret */
216     char dn[32+1];                /* Device name */
217     char ds[64+1];                /* Device secret */
218     unsigned char dev_type;       /* device type: 0-->main dev 1-->sub dev*/
219     char module_name[33];         /* module name*/
220     unsigned char ota_process;
221     int module_numb;
222     ota_store_module_info_t *module_queue_ptr;
223     ota_feedback_msg_func_t feedback_func;
224     ota_report_status_func_t report_func;               /* report percentage to clould */
225     ota_triggered_func_t ota_triggered_func;            /* new version ready, if OTA upgrade or not by User */
226     int (*on_boot)(ota_boot_param_t *ota_param);        /* Upgrade complete to reboot to the new version */
227     ota_image_header_t header;                          /* OTA Image header */
228     void *mqtt_client;                                  /* mqtt client */                      /* OTA Upgrade parameters */
229 } ota_service_t;
230 
231 /* OTA service APIs */
232 /**
233  * ota_service_init  ota service init .
234  *
235  * @param[in] ota_service_t *ctx   ota service context
236  *
237  * @return OTA_SUCCESS             OTA success.
238  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
239  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
240  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
241  */
242 int ota_service_init(ota_service_t *ctx);
243 
244 /**
245  * ota_service_start                ota service start and file store in flash
246  *
247  * @param[in] ota_service_t *ctx   ota service context
248  *
249  * @return OTA_SUCCESS             OTA success.
250  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
251  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
252  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
253  */
254 int ota_service_start(ota_service_t *ctx);
255 
256 /**
257  * ota_download_to_fs_service  ota service submodule start.
258  *
259  * @param[in] void *ctx            ota service context
260  *
261  * @return OTA_SUCCESS             OTA success.
262  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
263  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
264  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
265  */
266  int ota_download_to_fs_service(void *ota_ctx , char *file_path);
267 
268 /**
269  * ota_install_jsapp  ota service submodule start.
270  *
271  * @param[in] void *ota_ctx        ota service context
272  *
273  * @return OTA_SUCCESS             OTA success.
274  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
275  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
276  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
277  */
278 int ota_install_jsapp(void *ota_ctx, char *store_file, int store_file_len, char *install_path);
279 
280 /**
281  * ota_report_module_version      ota report module version.
282  *
283  * @param[in]         void *ctx   ota service context
284  * @param[in] char *module_name   want tp report module name
285  * @param[in]     char *version   module file version
286  *
287  * @return OTA_SUCCESS             OTA success.
288  * @return -1                      OTA transport init fail.
289  */
290 int ota_report_module_version(void *ota_ctx, char *module_name, char *version);
291 
292 /**
293  * ota_service_param_reset;
294  *
295  * @param[in] ota_service_t *ctx   ota service context
296  *
297  * @return NULL
298  */
299 void ota_service_param_reset(ota_service_t *ctx);
300 
301 /**
302  * ota_sevice_parse_msg  ota service parse message.
303  *
304  * @param[in] ota_service_t *ctx   ota service context
305  *
306  * @return OTA_SUCCESS             OTA success.
307  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
308  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
309  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
310  */
311 int ota_sevice_parse_msg(ota_service_t *ctx, const char *json);
312 
313 /**
314  * ota_register_module_store ota register store moudle information buf to ctx;
315  *
316  *
317  * @param[in] ota_service_t             *ctx ota service context
318  * @param[in] ota_store_module_info_t *queue store moudle information buf ptr
319  * @param[in] int                  queue_len module buf size
320  *
321  * @return OTA_SUCCESS             OTA success.
322  * @return OTA_TRANSPORT_INT_FAIL  Get information failed.
323  */
324 int ota_register_module_store(ota_service_t *ctx, ota_store_module_info_t *queue, int queue_len);
325 /**
326  * ota_set_module_information      ota set module information to DB, include:
327  *                                 module name, store path, module type.
328  *
329  * @param[in] ota_service_t *ctx ota service context
330  * @param[in] char  *module_name ota module name
331  * @param[in] char   *store_path want to store module file path
332  * @param[in] int    module_type upgrade type: OTA_UPGRADE_ALL.etc.
333  *
334  * @return OTA_SUCCESS             OTA success.
335  * @return OTA_TRANSPORT_INT_FAIL  Get information failed.
336  */
337 int ota_set_module_information(ota_service_t *ctx, char *module_name,
338                                char *store_path, int module_type);
339 /**
340  * ota_get_module_information      ota get module information,include:
341  *                                 module name, store path, module type.
342  *
343  * @param[in] ota_service_t *ctx   ota service context
344  * @param[in]  char *module_name   ota module name
345  * @param[in] ota_store_module_info_t *module_info want to store module information var
346  *
347  * @return OTA_SUCCESS             OTA success.
348  * @return OTA_TRANSPORT_INT_FAIL  Get information failed.
349  */
350 int ota_get_module_information(ota_service_t *ctx, char *module_name, ota_store_module_info_t *module_info);
351 /**
352  * ota_register_boot_cb            ota register boot callback.
353  *
354  * @param[in] ota_service_t *ctx   ota service context
355  *
356  * @return OTA_SUCCESS             OTA success.
357  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
358  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
359  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
360  */
361 int ota_register_boot_cb(ota_service_t *ctx, void *cb, void *param);
362 /**
363  * ota_register_trigger_msg_cb     ota register trigger ota callback.
364  *
365  * @param[in] ota_service_t *ctx   ota service context
366  *
367  * @return OTA_SUCCESS             OTA success.
368  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
369  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
370  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
371  */
372 int ota_register_trigger_msg_cb(ota_service_t *ctx, void *cb, void *param);
373 /**
374  * ota_register_report_percent_cb  ota register file download process callback.
375  *
376  * @param[in] ota_service_t *ctx   ota service context
377  *
378  * @return OTA_SUCCESS             OTA success.
379  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
380  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
381  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
382  */
383 int ota_register_report_percent_cb(ota_service_t *ctx, void *cb, void *param);
384 /**
385  * ota_register_feedback_msg_cb  ota service register callback.
386  *
387  * @param[in] ota_service_t *ctx   ota service context
388  *
389  * @return OTA_SUCCESS             OTA success.
390  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
391  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
392  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
393  */
394 int ota_register_feedback_msg_cb(ota_service_t *ctx, void *cb, void *param);
395 /***************************************************************
396 *** OTA transport module:transport message with MQTT or CoAP ***
397 ****************************************************************/
398 /**
399  * ota_transport_inform  OTA inform version to cloud.
400  *
401  * @param[in]   void *mqttclient   mqtt client ptr
402  * @param[in]           char *pk   product key value
403  * @param[in]           char *dn   device name
404  * @param[in]  char *module_name   want to report module name, when module_name == NULL, report default module ver
405  * @param[in]          char *ver   version string
406  *
407  * @return OTA_SUCCESS             OTA success.
408  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
409  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
410  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
411  */
412 int ota_transport_inform(void *mqttclient, char *pk, char *dn, char *module_name, char *ver);
413 
414 /**
415  * ota_transport_upgrade  subscribe OTA upgrade to clould.
416  *
417  * @param[in] ota_service_t *ctx   ota service context
418  *
419  * @return OTA_SUCCESS             OTA success.
420  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
421  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
422  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
423  */
424 int ota_transport_upgrade(ota_service_t *ctx);
425 
426 /**
427  * ota_transport_upgrade  report status to cloud.
428  *
429  * @param[in] void *param  ota service context
430  * @param[in] int   status ota upgrade status
431  *
432  * @return OTA_SUCCESS             OTA success.
433  * @return OTA_TRANSPORT_INT_FAIL  OTA transport init fail.
434  * @return OTA_TRANSPORT_PAR_FAIL  OTA transport parse fail.
435  * @return OTA_TRANSPORT_VER_FAIL  OTA transport verion is too old.
436  */
437 int ota_transport_status(void *param, int status);
438 
439 /***************************************************************
440 *** OTA download module: download image with HTTP or CoaP    ***
441 ****************************************************************/
442 /**
443  * ota_download_start    OTA download start
444  *
445  * @param[in]              char *url  download url
446  * @param[in]   unsigned int url_len  download url length
447  * @param[in] report_func repot_func  report http downloading status function
448  * @param[in]       void *user_param  user's param for repot_func
449  *
450  * @return OTA_SUCCESS             OTA success.
451  * @return OTA_DOWNLOAD_INIT_FAIL  OTA download init failed.
452  * @return OTA_DOWNLOAD_CON_FAIL   OTA download connect failed.
453  * @return OTA_DOWNLOAD_REQ_FAIL   OTA download request failed.
454  * @return OTA_DOWNLOAD_RECV_FAIL  OTA download receive failed.
455  */
456 int ota_download_start(char *url, unsigned int url_len, report_func repot_func, void *user_param);
457 
458 /**
459  * ota_download_store_fs_start    OTA download file start and store in fs
460  *
461  * @param[in]              char *url  download url
462  * @param[in]   unsigned int url_len  download url length
463  * @param[in]       char *store_path  store file path and name eg:/root/test.bin
464  * @param[in] report_func report_func report http downloading status function
465  * @param[in]       void *user_param  user's param for repot_func
466  *
467  * @return OTA_SUCCESS             OTA success.
468  * @return OTA_DOWNLOAD_INIT_FAIL  OTA download init failed.
469  * @return OTA_DOWNLOAD_CON_FAIL   OTA download connect failed.
470  * @return OTA_DOWNLOAD_REQ_FAIL   OTA download request failed.
471  * @return OTA_DOWNLOAD_RECV_FAIL  OTA download receive failed.
472  */
473 int ota_download_store_fs_start(char *url, unsigned int url_len, char *store_path,
474                                 report_func report_func, void *user_param);
475 /**
476  * ota_download_image_header        ota download image header.
477  *
478  * @param[in]   ota_service_t *ctx    ota service context
479  * @param[in]            char *url    download url
480  * @param[in] unsigned int url_len    download url length
481  * @param[in]    unsigned int size    ota image size
482  *
483  * @return OTA_SUCCESS             OTA success.
484  * @return OTA_DOWNLOAD_INIT_FAIL  OTA download init fail.
485  * @return OTA_DOWNLOAD_HEAD_FAIL  OTA download header fail.
486  * @return OTA_DOWNLOAD_CON_FAIL   OTA download connect fail.
487  * @return OTA_DOWNLOAD_REQ_FAIL   OTA download request fail.
488  * @return OTA_DOWNLOAD_RECV_FAIL  OTA download receive fail.
489  */
490 int ota_download_image_header(ota_service_t *ctx, char *url, unsigned int url_len, unsigned int size);
491 
492 /***************************************************************
493 *** OTA hal module: update image to OTA partition:ota_hal.h  ***
494 ****************************************************************/
495 /**
496  * ota_read_parameter   ota read parameter from flash.
497  *
498  * @param[in] ota_boot_param_t *param ota parameter
499  *
500  * @return OTA_SUCCESS              OTA success.
501  * @return OTA_UPGRADE_WRITE_FAIL   OTA upgrade write fail.
502  * @return OTA_UPGRADE_PARAM_FAIL   OTA upgrade parameter fail.
503  * @return OTA_UPGRADE_FW_SIZE_FAIL OTA upgrade FW too big.
504  * @return OTA_UPGRADE_SET_BOOT_FAIL OTA upgrade set boot fail.
505  */
506 int ota_read_parameter(ota_boot_param_t *param);
507 
508 /**
509  * ota_update_parameter  ota update parameter to flash.
510  *
511  * @param[in] ota_boot_param_t *param ota parameter
512  *
513  * @return OTA_SUCCESS              OTA success.
514  * @return OTA_UPGRADE_WRITE_FAIL   OTA upgrade write fail.
515  * @return OTA_UPGRADE_PARAM_FAIL   OTA upgrade parameter fail.
516  * @return OTA_UPGRADE_FW_SIZE_FAIL OTA upgrade FW too big.
517  * @return OTA_UPGRADE_SET_BOOT_FAIL OTA upgrade set boot fail.
518  */
519 int ota_update_parameter(ota_boot_param_t *param);
520 
521 /**
522  * ota_get_fs_version  ota get fs image version.
523  *
524  * @param[in] char *ver_buf         store version buffer
525  * @param[in] cint ver_buf_len      store version buffer len
526  *
527  * @return 0                        get version success.
528  * @return -1                       get version fail.
529  */
530 int ota_get_fs_version(char *ver_buf, int ver_buf_len);
531 
532 /**
533  * ota_check_image  OTA check image.
534  *
535  * @param[in]  unsigned int size    OTA image size.
536  *
537  * @return OTA_SUCCESS              OTA success.
538  * @return OTA_VERIFY_MD5_FAIL      OTA verfiy MD5 fail.
539  * @return OTA_VERIFY_SHA2_FAIL     OTA verfiy SH256 fail.
540  * @return OTA_VERIFY_RSA_FAIL      OTA verfiy RSA fail.
541  * @return OTA_VERIFY_IMAGE_FAIL    OTA verfiy image fail.
542  */
543 int ota_check_image(unsigned int size);
544 
545 /**
546  * ota_jsapp_version_get            OTA parase js script version
547  *
548  * @param[in]  char *version        store version buf.
549  * @param[in]  char *file_path      js.app json file store path.
550  *
551  * @return 0                        get version success.
552  * @return -1                       get version failed.
553  */
554 int ota_jsapp_version_get(char *version, char *file_path);
555 /**
556  * @}
557  */
558 #ifdef __cplusplus
559 }
560 #endif
561 #endif /* OTA_AGNET_H */