Merge pull request #5858 from yangkunming99/relocate-image-header

RTL8195AM - move region headers to 0xb000 and 0xc000
pull/5910/head
Cruz Monrreal 2018-01-18 11:32:49 -06:00 committed by GitHub
commit 1a3dae763c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 18 deletions

View File

@ -23,24 +23,24 @@
static flash_t flash_obj;
void OTA_ReadHeader(uint32_t base, imginfo_t *img)
void OTA_ReadHeader(uint32_t addr, imginfo_t *img)
{
uint32_t epoch_hi, epoch_lo;
if (base != OTA_REGION1_BASE || base != OTA_REGION2_BASE) {
if (addr != OTA_REGION1_HEADER || addr != OTA_REGION2_HEADER) {
return;
}
flash_ext_read_word(&flash_obj, base + OTA_TAG_OFS, &img->tag);
flash_ext_read_word(&flash_obj, base + OTA_VER_OFS, &img->ver);
flash_ext_read_word(&flash_obj, base + OTA_EPOCH_OFS, &epoch_hi);
flash_ext_read_word(&flash_obj, base + OTA_EPOCH_OFS + 4, &epoch_lo);
flash_ext_read_word(&flash_obj, addr + OTA_TAG_OFS, &img->tag);
flash_ext_read_word(&flash_obj, addr + OTA_VER_OFS, &img->ver);
flash_ext_read_word(&flash_obj, addr + OTA_EPOCH_OFS, &epoch_hi);
flash_ext_read_word(&flash_obj, addr + OTA_EPOCH_OFS + 4, &epoch_lo);
img->timestamp = ((uint64_t)epoch_hi << 32) | (uint64_t) epoch_lo;
flash_ext_read_word(&flash_obj, base + OTA_SIZE_OFS, &img->size);
flash_ext_stream_read(&flash_obj, base + OTA_HASH_OFS, 32, img->hash);
flash_ext_stream_read(&flash_obj, base + OTA_CAMPAIGN_OFS, 16, img->campaign);
flash_ext_read_word(&flash_obj, base + OTA_CRC32_OFS, &img->crc32);
flash_ext_read_word(&flash_obj, addr + OTA_SIZE_OFS, &img->size);
flash_ext_stream_read(&flash_obj, addr + OTA_HASH_OFS, 32, img->hash);
flash_ext_stream_read(&flash_obj, addr + OTA_CAMPAIGN_OFS, 16, img->campaign);
flash_ext_read_word(&flash_obj, addr + OTA_CRC32_OFS, &img->crc32);
}
bool OTA_CheckHeader(imginfo_t *img)
@ -61,9 +61,9 @@ bool OTA_CheckHeader(imginfo_t *img)
return true;
}
void OTA_GetImageInfo(uint32_t base, imginfo_t *img)
void OTA_GetImageInfo(uint32_t header, imginfo_t *img)
{
OTA_ReadHeader(base, img);
OTA_ReadHeader(header, img);
if (!OTA_CheckHeader(img)) {
img->timestamp = 0;
@ -77,8 +77,8 @@ uint32_t OTA_GetUpdateBase(void)
{
imginfo_t img1, img2;
OTA_GetImageInfo(OTA_REGION1_BASE, &img1);
OTA_GetImageInfo(OTA_REGION2_BASE, &img2);
OTA_GetImageInfo(OTA_REGION1_HEADER, &img1);
OTA_GetImageInfo(OTA_REGION2_HEADER, &img2);
if (img1.valid && img2.valid) {
if (img1.timestamp < img2.timestamp) {

View File

@ -22,17 +22,19 @@
#define FLASH_SECTOR_SIZE 0x1000
#define FLASH_SECTOR_MASK ~(FLASH_SECTOR_SIZE - 1)
#define OTA_REGION1_HEADER 0x0b000
#define OTA_REGION2_HEADER 0x0c000
#define OTA_REGION1_BASE 0x40000
#define OTA_REGION2_BASE 0x120000
#define OTA_REGION1_SIZE 0xe0000
#define OTA_REGION2_SIZE 0xe0000
#define OTA_REGION_SIZE 0xe0000
#define OTA_MBED_FS_BASE 0xb000
#define OTA_MBED_FS_BASE 0x10000
#define OTA_MBED_FS_SIZE 0x30000
#define OTA_CRC32_LEN 0x44
#define OTA_HEADER_LEN 0x48
#define OTA_HEADER_OFS 0x0
#define OTA_TAG_OFS 0x0
#define OTA_VER_OFS 0x4
#define OTA_EPOCH_OFS 0x8
@ -57,6 +59,8 @@ typedef struct imginfo_s {
uint8_t campaign[16];
uint32_t crc32;
bool valid;
uint32_t header_addr;
uint32_t image_addr;
} imginfo_t;
#ifdef __cplusplus
@ -64,7 +68,7 @@ extern "C" {
#endif
extern void OTA_GetImageInfo(uint32_t base, imginfo_t *info);
extern uint32_t OTA_GetUpdateBase(void);
extern uint32_t OTA_GetUpdateRegion(void);
extern uint32_t OTA_UpdateHeader(uint32_t base, imginfo_t *img);
extern uint32_t OTA_UpdateImage(uint32_t base, uint32_t offset, uint32_t len, uint8_t *data);

View File

@ -255,7 +255,9 @@ def create_daplink(image_bin, ram1_bin, ram2_bin):
output = open(image_bin, "wb")
append_image_file(ram1_bin, output)
append_image_file(ram2_bin, output)
output.seek(0xb000)
line = ""
for key in ['tag', 'ver', 'timestamp', 'size', 'hash', 'campaign']:
line += RAM2_HEADER[key]
@ -264,7 +266,6 @@ def create_daplink(image_bin, ram1_bin, ram2_bin):
RAM2_HEADER['crc32'] = format_number(crc32_checksum(line), 8)
output.write(RAM2_HEADER['crc32'])
append_image_file(ram2_bin, output)
output.close()
# ----------------------------