Skip to content

Commit 405dd88

Browse files
chrisyangcmonr
authored andcommitted
rtl8195am - move region headers to 0xb000 and 0xc000
The new layout is as follows: 0x000000 - 0x008000 => bootloader 0x008000 - 0x00b000 => system sectors 0x00b000 - 0x00c000 => region1 header 0x00c000 - 0x00d000 => region2 header 0x00d000 - 0x010000 => reserved 0x010000 - 0x040000 => mbed file system 0x040000 - 0x120000 => region1 image 0x120000 - 0x200000 => region2 image This is to ensure when daplink erases sections, both regions' headers are erased properly.
1 parent c8062d5 commit 405dd88

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/ota_api.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@
2323

2424
static flash_t flash_obj;
2525

26-
void OTA_ReadHeader(uint32_t base, imginfo_t *img)
26+
void OTA_ReadHeader(uint32_t addr, imginfo_t *img)
2727
{
2828
uint32_t epoch_hi, epoch_lo;
2929

30-
if (base != OTA_REGION1_BASE || base != OTA_REGION2_BASE) {
30+
if (addr != OTA_REGION1_HEADER || addr != OTA_REGION2_HEADER) {
3131
return;
3232
}
3333

34-
flash_ext_read_word(&flash_obj, base + OTA_TAG_OFS, &img->tag);
35-
flash_ext_read_word(&flash_obj, base + OTA_VER_OFS, &img->ver);
36-
flash_ext_read_word(&flash_obj, base + OTA_EPOCH_OFS, &epoch_hi);
37-
flash_ext_read_word(&flash_obj, base + OTA_EPOCH_OFS + 4, &epoch_lo);
34+
flash_ext_read_word(&flash_obj, addr + OTA_TAG_OFS, &img->tag);
35+
flash_ext_read_word(&flash_obj, addr + OTA_VER_OFS, &img->ver);
36+
flash_ext_read_word(&flash_obj, addr + OTA_EPOCH_OFS, &epoch_hi);
37+
flash_ext_read_word(&flash_obj, addr + OTA_EPOCH_OFS + 4, &epoch_lo);
3838
img->timestamp = ((uint64_t)epoch_hi << 32) | (uint64_t) epoch_lo;
3939

40-
flash_ext_read_word(&flash_obj, base + OTA_SIZE_OFS, &img->size);
41-
flash_ext_stream_read(&flash_obj, base + OTA_HASH_OFS, 32, img->hash);
42-
flash_ext_stream_read(&flash_obj, base + OTA_CAMPAIGN_OFS, 16, img->campaign);
43-
flash_ext_read_word(&flash_obj, base + OTA_CRC32_OFS, &img->crc32);
40+
flash_ext_read_word(&flash_obj, addr + OTA_SIZE_OFS, &img->size);
41+
flash_ext_stream_read(&flash_obj, addr + OTA_HASH_OFS, 32, img->hash);
42+
flash_ext_stream_read(&flash_obj, addr + OTA_CAMPAIGN_OFS, 16, img->campaign);
43+
flash_ext_read_word(&flash_obj, addr + OTA_CRC32_OFS, &img->crc32);
4444
}
4545

4646
bool OTA_CheckHeader(imginfo_t *img)
@@ -61,9 +61,9 @@ bool OTA_CheckHeader(imginfo_t *img)
6161
return true;
6262
}
6363

64-
void OTA_GetImageInfo(uint32_t base, imginfo_t *img)
64+
void OTA_GetImageInfo(uint32_t header, imginfo_t *img)
6565
{
66-
OTA_ReadHeader(base, img);
66+
OTA_ReadHeader(header, img);
6767

6868
if (!OTA_CheckHeader(img)) {
6969
img->timestamp = 0;
@@ -77,8 +77,8 @@ uint32_t OTA_GetUpdateBase(void)
7777
{
7878
imginfo_t img1, img2;
7979

80-
OTA_GetImageInfo(OTA_REGION1_BASE, &img1);
81-
OTA_GetImageInfo(OTA_REGION2_BASE, &img2);
80+
OTA_GetImageInfo(OTA_REGION1_HEADER, &img1);
81+
OTA_GetImageInfo(OTA_REGION2_HEADER, &img2);
8282

8383
if (img1.valid && img2.valid) {
8484
if (img1.timestamp < img2.timestamp) {

targets/TARGET_Realtek/TARGET_AMEBA/ota_api.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@
2222
#define FLASH_SECTOR_SIZE 0x1000
2323
#define FLASH_SECTOR_MASK ~(FLASH_SECTOR_SIZE - 1)
2424

25+
#define OTA_REGION1_HEADER 0x0b000
26+
#define OTA_REGION2_HEADER 0x0c000
27+
#define OTA_REGION2_BASE 0x120000
2528
#define OTA_REGION1_BASE 0x40000
2629
#define OTA_REGION2_BASE 0x120000
2730
#define OTA_REGION1_SIZE 0xe0000
2831
#define OTA_REGION2_SIZE 0xe0000
2932
#define OTA_REGION_SIZE 0xe0000
30-
#define OTA_MBED_FS_BASE 0xb000
33+
#define OTA_MBED_FS_BASE 0x10000
34+
#define OTA_MBED_FS_SIZE 0x30000
3135

3236
#define OTA_CRC32_LEN 0x44
3337
#define OTA_HEADER_LEN 0x48
3438

35-
#define OTA_HEADER_OFS 0x0
3639
#define OTA_TAG_OFS 0x0
3740
#define OTA_VER_OFS 0x4
3841
#define OTA_EPOCH_OFS 0x8
@@ -57,14 +60,16 @@ typedef struct imginfo_s {
5760
uint8_t campaign[16];
5861
uint32_t crc32;
5962
bool valid;
63+
uint32_t header_addr;
64+
uint32_t image_addr;
6065
} imginfo_t;
6166

6267
#ifdef __cplusplus
6368
extern "C" {
6469
#endif
6570

6671
extern void OTA_GetImageInfo(uint32_t base, imginfo_t *info);
67-
extern uint32_t OTA_GetUpdateBase(void);
72+
extern uint32_t OTA_GetUpdateRegion(void);
6873

6974
extern uint32_t OTA_UpdateHeader(uint32_t base, imginfo_t *img);
7075
extern uint32_t OTA_UpdateImage(uint32_t base, uint32_t offset, uint32_t len, uint8_t *data);
0 Bytes
Binary file not shown.

tools/targets/REALTEK_RTL8195AM.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ def create_daplink(image_bin, ram1_bin, ram2_bin):
255255

256256
output = open(image_bin, "wb")
257257
append_image_file(ram1_bin, output)
258+
append_image_file(ram2_bin, output)
258259

260+
output.seek(0xb000)
259261
line = ""
260262
for key in ['tag', 'ver', 'timestamp', 'size', 'hash', 'campaign']:
261263
line += RAM2_HEADER[key]
@@ -264,7 +266,6 @@ def create_daplink(image_bin, ram1_bin, ram2_bin):
264266
RAM2_HEADER['crc32'] = format_number(crc32_checksum(line), 8)
265267

266268
output.write(RAM2_HEADER['crc32'])
267-
append_image_file(ram2_bin, output)
268269
output.close()
269270

270271
# ----------------------------

0 commit comments

Comments
 (0)