add ota algorithm for device
1. effective "Differential Upgrade" patch algorithm with high compression rate 2. effective recovery algorithm support recovery firmware in blocks which has low memory consumption and wear-leveling strategies, especially suitable for embeded devices with low RAM. 3. add sample ota bootloader project, see: board\TencentOS_tiny_EVB_MX_Plus\KEIL\ota\ota_bootloader_recovery 4. add sample application project for download firmware through http, see: board\TencentOS_tiny_EVB_MX_Plus\KEIL\ota\ota_application_download_through_http 5. add sample application project for download firmware through qcloud explorer console, see: board\TencentOS_tiny_EVB_MX_Plus\KEIL\ota\ota_application_download_through_qcloud_iot_explorer 6. an OTA markdown document is pending
This commit is contained in:
85
components/ota/common/flash/ota_flash.h
Normal file
85
components/ota/common/flash/ota_flash.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* 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_FLASH_H_
|
||||
#define _OTA_FLASH_H_
|
||||
|
||||
#include "stdint.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
|
||||
#define OTA_FLASH_SECTOR_SIZE_LOG2 (flash_ctl.sector_size_log2)
|
||||
#define OTA_FLASH_SECTOR_SIZE (1 << OTA_FLASH_SECTOR_SIZE_LOG2)
|
||||
#define OTA_FLASH_WRITE_ALIGN (flash_ctl.flash_write_align)
|
||||
|
||||
#define OTA_FLASH_WRITE ((ota_flash_write_t)(flash_ctl.flash_drv.write))
|
||||
#define OTA_FLASH_READ ((ota_flash_read_t)(flash_ctl.flash_drv.read))
|
||||
#define OTA_FLASH_ERASE ((ota_flash_erase_t)(flash_ctl.flash_drv.erase))
|
||||
|
||||
#define OTA_ALIGN_UP(v, align) (((v) + ((align) - 1)) & ~((align) - 1))
|
||||
#define OTA_IS_ALINGED(v, align) ((v) % (align) == 0)
|
||||
|
||||
typedef uint8_t ota_byte_t; // byte
|
||||
typedef uint16_t ota_hword_t; // half word
|
||||
typedef uint32_t ota_word_t; // word
|
||||
typedef uint64_t ota_dword_t; // double word
|
||||
|
||||
typedef enum ota_flash_program_type_en {
|
||||
OTA_FLASH_PROGRAM_TYPE_BYTE, /*!< Program byte (8-bit) at a specified address */
|
||||
OTA_FLASH_PROGRAM_TYPE_HALFWORD, /*!< Program a half-word (16-bit) at a specified address */
|
||||
OTA_FLASH_PROGRAM_TYPE_WORD, /*!< Program a word (32-bit) at a specified address */
|
||||
OTA_FLASH_PROGRAM_TYPE_DOUBLEWORD, /*!< Program a double word (64-bit) at a specified address */
|
||||
} ota_flash_pgm_type_t;
|
||||
|
||||
typedef int (*ota_flash_write_t)(uint32_t addr, const void *buf, size_t len);
|
||||
typedef int (*ota_flash_read_t)(uint32_t addr, void *buf, size_t len);
|
||||
typedef int (*ota_flash_erase_t)(uint32_t addr, size_t len);
|
||||
|
||||
typedef struct ota_flash_drv_st {
|
||||
ota_flash_write_t write;
|
||||
ota_flash_read_t read;
|
||||
ota_flash_erase_t erase;
|
||||
} ota_flash_drv_t;
|
||||
|
||||
typedef struct ota_flash_property_st {
|
||||
uint8_t sector_size_log2;
|
||||
ota_flash_pgm_type_t pgm_type;
|
||||
} ota_flash_prop_t;
|
||||
|
||||
typedef struct ota_flash_control_st {
|
||||
uint8_t sector_size_log2;
|
||||
uint8_t flash_write_align;
|
||||
|
||||
ota_flash_drv_t flash_drv;
|
||||
} ota_flash_ctl_t;
|
||||
|
||||
int ota_flash_init(ota_flash_drv_t *flash_drv, ota_flash_prop_t *flash_prop);
|
||||
|
||||
int ota_flash_read(uint32_t addr, void *buf, size_t buf_size);
|
||||
|
||||
int ota_flash_write(uint32_t addr, void *buf, size_t buf_size);
|
||||
|
||||
int ota_flash_erase(uint32_t start, size_t len);
|
||||
|
||||
int ota_flash_erase_blocks(uint32_t start, size_t len);
|
||||
|
||||
size_t ota_flash_write_size_aligned_get(size_t len);
|
||||
|
||||
int ota_flash_size_is_aligned(size_t len);
|
||||
|
||||
#endif /* _OTA_FLASH_H_ */
|
||||
|
Reference in New Issue
Block a user