Skip to content

Commit c56d551

Browse files
committed
[M252KG] Use virtual sector instead of (physical) sector for Mbed OS flash algo
In Mbed OS/KV Store, the last two sectors of flash is used for internal flash tests. However, (physical) sector is just 512-bytes on M251 series and we can meet MBED_ERROR_MEDIA_FULL in mbed-os-features-storage-tests-kvstore-static_tests. To get around the failure, we adopt virtual sector instead for Mbed OS flash algo. A virtual sector is defined to be a group of (physical) sectors. Its start address and size both must be on the boundary of (physical) sector size multiplied by 2 to the power of n.
1 parent ce64112 commit c56d551

File tree

1 file changed

+61
-47
lines changed

1 file changed

+61
-47
lines changed

targets/TARGET_NUVOTON/TARGET_M251/flash_api.c

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
#include "flash_data.h"
2424
#include "mbed_critical.h"
2525

26+
/* Use virtual sector instead of (physical) sector for Mbed OS flash algo
27+
*
28+
* In Mbed OS/KV Store, the last two sectors of flash is used for internal flash
29+
* tests. However, (physical) sector is just 512-bytes on M251 series and we can
30+
* meet MBED_ERROR_MEDIA_FULL in mbed-os-features-storage-tests-kvstore-static_tests.
31+
* To get around the failure, we adopt virtual sector instead for Mbed OS flash
32+
* algo. A virtual sector is defined to be a group of (physical) sectors. Its start
33+
* address and size both must be on the boundary of (physical) sector size multiplied
34+
* by 2 to the power of n.
35+
*/
36+
2637
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
2738
// NOTE: On ARMv7-M/ARMv8-M, instruction fetches are always little-endian.
2839
static uint32_t FLASH_ALGO[] = {
@@ -41,62 +52,65 @@ static uint32_t FLASH_ALGO[] = {
4152
0x0000f2c4, 0x22406801, 0x60014311, 0x90022001, 0x2000e002, 0xe7ff9002, 0xb0039802, 0xb5804770,
4253
0x460ab088, 0x90064603, 0x20009105, 0x92029004, 0xe7ff9301, 0x99059804, 0xd2104288, 0x9806e7ff,
4354
0x1c4a9904, 0x00899204, 0xf7ff5840, 0x9003ff96, 0xd0032800, 0x9803e7ff, 0xe0039007, 0x2000e7ea,
44-
0xe7ff9007, 0xb0089807, 0xb5b0bd80, 0x4613b08a, 0x4605460c, 0x91079008, 0x20009206, 0x90039004,
45-
0x94019302, 0xe7ff9500, 0x0010f24c, 0x0000f2c4, 0x21016800, 0xd0014208, 0xe7f5e7ff, 0x0000f24c,
46-
0x0000f2c4, 0x22406801, 0x60014311, 0x1cc09807, 0x43882103, 0xe7ff9007, 0x28009807, 0xe7ffd04c,
47-
0x7800a808, 0x28000640, 0xe7ffd10f, 0x28809807, 0xe7ffd30b, 0x90052080, 0x99059808, 0x9b049a06,
48-
0xf00018d2, 0x9003f83f, 0xa808e022, 0x06407800, 0xd1112800, 0x9807e7ff, 0xd30d2810, 0x9807e7ff,
49-
0x4388210f, 0x98089005, 0x9a069905, 0x18d29b04, 0xf828f000, 0xe00a9003, 0x90059807, 0x99059808,
50-
0x9b049a06, 0xf00018d2, 0x9003f8de, 0xe7ffe7ff, 0x99089805, 0x90081808, 0x99049805, 0x90041808,
51-
0x99079805, 0x90071a08, 0x28009803, 0xe7ffd003, 0x90092001, 0xe7afe003, 0x90092000, 0x9809e7ff,
52-
0xbdb0b00a, 0xb088b5b0, 0x460c4613, 0x90074605, 0x92059106, 0x90049805, 0x300f9806, 0x4388210f,
53-
0x93039006, 0x95019402, 0xf24ce7ff, 0xf2c40010, 0x68000000, 0x42082101, 0xe7ffd001, 0xf24ce7f5,
54-
0xf2c40000, 0x68010000, 0x43112240, 0x98076001, 0x4388210f, 0x0104f24c, 0x0100f2c4, 0xf24c6008,
55-
0xf2c4000c, 0x21270000, 0x98046001, 0xf984f000, 0x0180f24c, 0x0100f2c4, 0x98046008, 0x90041d00,
56-
0xf0009804, 0xf24cf979, 0xf2c40184, 0x60080100, 0x1d009804, 0x98049004, 0xf96ef000, 0x0188f24c,
57-
0x0100f2c4, 0x98046008, 0x90041d00, 0xf0009804, 0xf24cf963, 0xf2c4018c, 0x60080100, 0x1d009804,
58-
0xf24c9004, 0xf2c40010, 0x21010000, 0x98066001, 0x90063810, 0x9806e7ff, 0xd0462800, 0xe7ffe7ff,
59-
0x00c0f24c, 0x0000f2c4, 0x21306800, 0xd0014208, 0xe7f5e7ff, 0xf0009804, 0xf24cf93f, 0xf2c40180,
60-
0x60080100, 0x1d009804, 0x98049004, 0xf934f000, 0x0184f24c, 0x0100f2c4, 0x98046008, 0x90041d00,
61-
0xf24ce7ff, 0xf2c400c0, 0x68000000, 0x420821c0, 0xe7ffd001, 0x9804e7f5, 0xf91ef000, 0x0188f24c,
62-
0x0100f2c4, 0x98046008, 0x90041d00, 0xf0009804, 0xf24cf913, 0xf2c4018c, 0x60080100, 0x1d009804,
63-
0x98069004, 0x90063810, 0xe7ffe7b5, 0x0010f24c, 0x0000f2c4, 0x21016800, 0xd0014208, 0xe7f5e7ff,
64-
0xb0082000, 0xb5b0bdb0, 0x4613b088, 0x4605460c, 0x91059006, 0x98059204, 0x21031cc0, 0x90054388,
65-
0x94029303, 0xe7ff9501, 0x0010f24c, 0x0000f2c4, 0x21016800, 0xd0014208, 0xe7f5e7ff, 0x0000f24c,
66-
0x0000f2c4, 0x22406801, 0x60014311, 0x000cf24c, 0x0000f2c4, 0x60012121, 0x9805e7ff, 0xd0412800,
67-
0x9806e7ff, 0x43882103, 0x0104f24c, 0x0100f2c4, 0x98046008, 0xf8c0f000, 0x0108f24c, 0x0100f2c4,
68-
0xf24c6008, 0xf2c40010, 0x21010000, 0xf3bf6001, 0xe7ff8f6f, 0x0010f24c, 0x0000f2c4, 0x21016800,
69-
0xd0014208, 0xe7f5e7ff, 0x0000f24c, 0x0000f2c4, 0x21406800, 0xd00b4208, 0xf24ce7ff, 0xf2c40000,
70-
0x68010000, 0x43112240, 0x20016001, 0xe00c9007, 0x1d009806, 0x98049006, 0x90041d00, 0x1f009805,
71-
0xe7ba9005, 0x90072000, 0x9807e7ff, 0xbdb0b008, 0xb088b5b0, 0x460c4613, 0x90064605, 0x92049105,
72-
0x1cc09805, 0x43882103, 0x93039005, 0x95019402, 0xf24ce7ff, 0xf2c40010, 0x68000000, 0x42082101,
73-
0xe7ffd001, 0xf24ce7f5, 0xf2c40000, 0x68010000, 0x43112240, 0xf24c6001, 0xf2c4000c, 0x21000000,
74-
0xe7ff6001, 0x28009805, 0xe7ffd050, 0x21039806, 0xf24c4388, 0xf2c40104, 0x60080100, 0x0008f24c,
75-
0x0000f2c4, 0x60012100, 0x0010f24c, 0x0000f2c4, 0x60012101, 0x8f6ff3bf, 0xf24ce7ff, 0xf2c40010,
76-
0x68000000, 0x42082101, 0xe7ffd001, 0xf24ce7f5, 0xf2c40000, 0x68000000, 0x42082140, 0xe7ffd00b,
77-
0x0000f24c, 0x0000f2c4, 0x22406801, 0x60014311, 0x90079806, 0xf24ce01d, 0xf2c40008, 0x68000000,
78-
0x90009904, 0xf0004608, 0x9900f817, 0xd0034281, 0x9806e7ff, 0xe00c9007, 0x1d009806, 0x98049006,
79-
0x90041d00, 0x1f009805, 0xe7ab9005, 0x90079806, 0x9807e7ff, 0xbdb0b008, 0x4601b083, 0x98029002,
80-
0x92021c42, 0x90017800, 0x1c429802, 0x78009202, 0x9a010200, 0x90011810, 0x1c429802, 0x78009202,
81-
0x9a010400, 0x90011810, 0x1c429802, 0x78009202, 0x9a010600, 0x90011810, 0x91009801, 0x4770b003,
82-
0x00000000,
55+
0xe7ff9007, 0xb0089807, 0xb580bd80, 0x4601b086, 0x20009004, 0x98049003, 0x72fff240, 0x40134603,
56+
0x90021ac0, 0xf6409802, 0x18800200, 0x91009001, 0x9802e7ff, 0x42889901, 0xe7ffd212, 0xf7ff9802,
57+
0x9003ff6c, 0x28009803, 0xe7ffd003, 0x90059803, 0xe7ffe009, 0xf2409802, 0x18402100, 0xe7e89002,
58+
0x90059803, 0x9805e7ff, 0xbd80b006, 0xb08ab5b0, 0x460c4613, 0x90084605, 0x92069107, 0x90042000,
59+
0x93029003, 0x95009401, 0xf24ce7ff, 0xf2c40010, 0x68000000, 0x42082101, 0xe7ffd001, 0xf24ce7f5,
60+
0xf2c40000, 0x68010000, 0x43112240, 0x98076001, 0x21031cc0, 0x90074388, 0x9807e7ff, 0xd04c2800,
61+
0xa808e7ff, 0x06407800, 0xd10f2800, 0x9807e7ff, 0xd30b2880, 0x2080e7ff, 0x98089005, 0x9a069905,
62+
0x18d29b04, 0xf83ff000, 0xe0229003, 0x7800a808, 0x28000640, 0xe7ffd111, 0x28109807, 0xe7ffd30d,
63+
0x210f9807, 0x90054388, 0x99059808, 0x9b049a06, 0xf00018d2, 0x9003f828, 0x9807e00a, 0x98089005,
64+
0x9a069905, 0x18d29b04, 0xf8def000, 0xe7ff9003, 0x9805e7ff, 0x18089908, 0x98059008, 0x18089904,
65+
0x98059004, 0x1a089907, 0x98039007, 0xd0032800, 0x2001e7ff, 0xe0039009, 0x2000e7af, 0xe7ff9009,
66+
0xb00a9809, 0xb5b0bdb0, 0x4613b088, 0x4605460c, 0x91069007, 0x98059205, 0x98069004, 0x210f300f,
67+
0x90064388, 0x94029303, 0xe7ff9501, 0x0010f24c, 0x0000f2c4, 0x21016800, 0xd0014208, 0xe7f5e7ff,
68+
0x0000f24c, 0x0000f2c4, 0x22406801, 0x60014311, 0x210f9807, 0xf24c4388, 0xf2c40104, 0x60080100,
69+
0x000cf24c, 0x0000f2c4, 0x60012127, 0xf0009804, 0xf24cf984, 0xf2c40180, 0x60080100, 0x1d009804,
70+
0x98049004, 0xf979f000, 0x0184f24c, 0x0100f2c4, 0x98046008, 0x90041d00, 0xf0009804, 0xf24cf96e,
71+
0xf2c40188, 0x60080100, 0x1d009804, 0x98049004, 0xf963f000, 0x018cf24c, 0x0100f2c4, 0x98046008,
72+
0x90041d00, 0x0010f24c, 0x0000f2c4, 0x60012101, 0x38109806, 0xe7ff9006, 0x28009806, 0xe7ffd046,
73+
0xf24ce7ff, 0xf2c400c0, 0x68000000, 0x42082130, 0xe7ffd001, 0x9804e7f5, 0xf93ff000, 0x0180f24c,
74+
0x0100f2c4, 0x98046008, 0x90041d00, 0xf0009804, 0xf24cf934, 0xf2c40184, 0x60080100, 0x1d009804,
75+
0xe7ff9004, 0x00c0f24c, 0x0000f2c4, 0x21c06800, 0xd0014208, 0xe7f5e7ff, 0xf0009804, 0xf24cf91e,
76+
0xf2c40188, 0x60080100, 0x1d009804, 0x98049004, 0xf913f000, 0x018cf24c, 0x0100f2c4, 0x98046008,
77+
0x90041d00, 0x38109806, 0xe7b59006, 0xf24ce7ff, 0xf2c40010, 0x68000000, 0x42082101, 0xe7ffd001,
78+
0x2000e7f5, 0xbdb0b008, 0xb088b5b0, 0x460c4613, 0x90064605, 0x92049105, 0x1cc09805, 0x43882103,
79+
0x93039005, 0x95019402, 0xf24ce7ff, 0xf2c40010, 0x68000000, 0x42082101, 0xe7ffd001, 0xf24ce7f5,
80+
0xf2c40000, 0x68010000, 0x43112240, 0xf24c6001, 0xf2c4000c, 0x21210000, 0xe7ff6001, 0x28009805,
81+
0xe7ffd041, 0x21039806, 0xf24c4388, 0xf2c40104, 0x60080100, 0xf0009804, 0xf24cf8c0, 0xf2c40108,
82+
0x60080100, 0x0010f24c, 0x0000f2c4, 0x60012101, 0x8f6ff3bf, 0xf24ce7ff, 0xf2c40010, 0x68000000,
83+
0x42082101, 0xe7ffd001, 0xf24ce7f5, 0xf2c40000, 0x68000000, 0x42082140, 0xe7ffd00b, 0x0000f24c,
84+
0x0000f2c4, 0x22406801, 0x60014311, 0x90072001, 0x9806e00c, 0x90061d00, 0x1d009804, 0x98059004,
85+
0x90051f00, 0x2000e7ba, 0xe7ff9007, 0xb0089807, 0xb5b0bdb0, 0x4613b088, 0x4605460c, 0x91059006,
86+
0x98059204, 0x21031cc0, 0x90054388, 0x94029303, 0xe7ff9501, 0x0010f24c, 0x0000f2c4, 0x21016800,
87+
0xd0014208, 0xe7f5e7ff, 0x0000f24c, 0x0000f2c4, 0x22406801, 0x60014311, 0x000cf24c, 0x0000f2c4,
88+
0x60012100, 0x9805e7ff, 0xd0502800, 0x9806e7ff, 0x43882103, 0x0104f24c, 0x0100f2c4, 0xf24c6008,
89+
0xf2c40008, 0x21000000, 0xf24c6001, 0xf2c40010, 0x21010000, 0xf3bf6001, 0xe7ff8f6f, 0x0010f24c,
90+
0x0000f2c4, 0x21016800, 0xd0014208, 0xe7f5e7ff, 0x0000f24c, 0x0000f2c4, 0x21406800, 0xd00b4208,
91+
0xf24ce7ff, 0xf2c40000, 0x68010000, 0x43112240, 0x98066001, 0xe01d9007, 0x0008f24c, 0x0000f2c4,
92+
0x99046800, 0x46089000, 0xf817f000, 0x42819900, 0xe7ffd003, 0x90079806, 0x9806e00c, 0x90061d00,
93+
0x1d009804, 0x98059004, 0x90051f00, 0x9806e7ab, 0xe7ff9007, 0xb0089807, 0xb083bdb0, 0x90024601,
94+
0x1c429802, 0x78009202, 0x98029001, 0x92021c42, 0x02007800, 0x18109a01, 0x98029001, 0x92021c42,
95+
0x04007800, 0x18109a01, 0x98029001, 0x92021c42, 0x06007800, 0x18109a01, 0x98019001, 0xb0039100,
96+
0x00004770, 0x00000000,
8397
};
8498

8599
static const flash_algo_t flash_algo_config = {
86-
.init = 0x00000001,
87-
.uninit = 0x000000b7,
88-
.erase_sector = 0x000000fb,
89-
.program_page = 0x000001eb,
90-
.static_base = 0x000006a0,
100+
.init = 0x00000001, // Init(...)
101+
.uninit = 0x000000b7, // UnInit(...)
102+
.erase_sector = 0x000001eb, // EraseVirtualSector(...) instead of EraseSector(...)
103+
.program_page = 0x0000024d, // ProgramPage(...)
104+
.static_base = 0x00000704, // PrgData
91105
.algo_blob = FLASH_ALGO
92106
};
93107

94-
/* Secure flash */
95108
static const sector_info_t sectors_info[] = {
96-
{0x0, 0x200}, // (start, sector size)
109+
{0x0, 0x800}, // (start, sector size)
110+
// Size of virtual sector (0x800) instead
111+
// of (physical) sector (0x200)
97112
};
98113

99-
/* Secure flash */
100114
static const flash_target_config_t flash_target_config = {
101115
.page_size = 4, // 4 bytes
102116
// Here page_size is program unit, which is different

0 commit comments

Comments
 (0)