1 /** 2 * Copyright (C) 2019 Alibaba.inc, All rights reserved. 3 * 4 * @file: ota_port.h 5 * @brief: vendor ota interface 6 * @author: 7 * @date: 2019/12/16 8 * @version: 1.0 9 */ 10 #ifndef _TG_VENDOR_OTA_H_ 11 #define _TG_VENDOR_OTA_H_ 12 13 #include "aos/hal/flash.h" 14 #include "aos/mtd.h" 15 #include <vfsdev/flash_dev.h> 16 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #define OTA_BOOT_INFO_SIZE 0x1000 23 #define OTA_BOOT_INFO_HEAD_LEN 4 24 #define OTA_BOOT_INFO_BODY_LEN 44 25 26 #define OTA_LINK_NOTUSED 0 27 #define OTA_LINK_USED 1 28 29 #define OTA_OK 0 30 #define OTA_FAILE 1 31 32 typedef struct 33 { 34 char *bin_name; 35 hal_partition_t partition; 36 } ota_bin_partition; 37 38 enum bootinfo_zone { 39 OTA_BOOTINFO_ZONEA, 40 OTA_BOOTINFO_ZONEB, 41 OTA_BOOTINFO_ZONEMAX 42 }; 43 44 typedef enum { 45 ALI_C2H, 46 ALI_C4H, 47 ALI_C5A01, 48 ALI_C1H, 49 ALI_ODM_MAX 50 }ODM_TYPE; 51 52 enum ota_link { 53 OTA_LINK_ERR = -1, 54 OTA_LINK_A, 55 OTA_LINK_B, 56 OTA_LINK_MAX 57 }; 58 59 struct ota_boot_info { 60 uint32_t crc32; 61 uint16_t info_len; 62 uint8_t odm_type; 63 uint8_t reserved; 64 uint16_t linkA_used_flag; 65 uint16_t linkB_used_flag; 66 uint16_t update_link; 67 uint8_t crash_reboot_count; 68 uint8_t secureERR_reboot_count; 69 uint16_t reboot_count_max; 70 uint16_t reboot_reason; 71 uint16_t fallback_disable; 72 73 uint16_t reserved1; //Tool request struct four byte align 74 uint32_t boot2a_addr; 75 uint32_t boot2b_addr; 76 uint32_t rtosa_addr; 77 uint32_t rtosb_addr; 78 uint32_t boot2_len; 79 uint32_t rtos_len; 80 }; 81 82 int tg_flash_read(const uint32_t addr, uint8_t *dst, const uint32_t size); 83 84 int ota_adapt_flash_write(const hal_partition_t partition, const uint32_t addr, const uint8_t *src, const uint32_t size); 85 86 int ota_set_bootinfo_to_zoneAB(struct ota_boot_info *info); 87 88 enum bootinfo_zone ota_get_valid_bootinfo_zone(void); 89 90 int ota_get_bootinfo(struct ota_boot_info *info, enum bootinfo_zone zone); 91 92 ODM_TYPE ota_adapt_get_odm_type(void); 93 94 int ota_adapt_set_odm_type(ODM_TYPE type); 95 96 int ota_upgrade_link(void); 97 int ota_set_user_bootinfo(void *param); 98 99 int ota_clear_reboot_count(void); 100 101 /** 102 * @brief Get current active A/B slot 103 * 104 * @returns "a" if current slot is A, or "b" if current slot is B. 105 */ 106 const char* tg_ota_get_current_ab(void); 107 108 /** 109 * @brief To mark that the non-active slot is upgraded successfully. 110 * It's time to set A/B related flag to let system switch to new system until next reboot. 111 * It MAY do two actions: 112 * 1. To set flag to indicate system boot from non-active slot next time. 113 * 2. To enable A/B fallback to old system if new system boot failed 114 * @return: - 0: success; - -1: fail 115 */ 116 int tg_ota_upgrade_end(void); 117 118 /** 119 * @brief To mark the ota process is finished and present slot is workable, 120 * It called by genie sdk after main boot flow done 121 * @param[in] ab_fallback: 1: enable ab fallback, if it is not enabled; 0, disable ab_fallback. 122 */ 123 void tg_ota_finish(int ab_fallback); 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif /* _TG_VENDOR_OTA_H_ */ 130