Skip to content

Commit 728c4b3

Browse files
committed
M2351: Polish memory partition code
1. Refine memory partition files to support different toolchains 2. Exclude NSC region from flash IAP range
1 parent b0c767a commit 728c4b3

File tree

6 files changed

+401
-148
lines changed

6 files changed

+401
-148
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/device/cmsis.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "partition_M2351.h"
2424

2525
/* Check relevant macro has been defined */
26-
#if (! defined(NU_TZ_SECURE_FLASH_SIZE))
27-
#error("NU_TZ_SECURE_FLASH_SIZE not defined")
26+
#if (! defined(NU_ROM_SIZE_S))
27+
#error("NU_ROM_SIZE_S not defined")
2828
#endif
2929

3030
// Support linker-generated symbol as start of relocated vector table.
@@ -38,7 +38,7 @@ extern uint32_t __start_vector_table__;
3838

3939
/* TZ_START_NS: Start address of non-secure application */
4040
#ifndef TZ_START_NS
41-
#define TZ_START_NS (NS_OFFSET + NU_TZ_SECURE_FLASH_SIZE)
41+
#define TZ_START_NS (NS_OFFSET + NU_ROM_SIZE_S)
4242
#endif
4343

4444
#endif

targets/TARGET_NUVOTON/TARGET_M2351/device/partition_M2351.h

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,31 @@
2121

2222
#include "partition_M2351_mem.h"
2323

24-
#define NU_TZ_SECURE_FLASH_SIZE NU_ROM_SIZE_S
25-
#define NU_TZ_SECURE_SRAM_SIZE NU_RAM_SIZE_S
26-
27-
#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
24+
#ifdef __cplusplus
25+
extern "C"
26+
{
27+
#endif
2828

29-
extern int Load$$LR$$LR_IROM_NSC$$Base;
30-
extern int Load$$LR$$LR_IROM_NSC$$Length;
29+
#if defined(__ARMCC_VERSION)
3130

32-
#define NU_TZ_NSC_REGION_START ((uint32_t) &Load$$LR$$LR_IROM_NSC$$Base)
33-
#define NU_TZ_NSC_REGION_SIZE ((uint32_t) &Load$$LR$$LR_IROM_NSC$$Length)
31+
extern int Image$$ER_IROM_NSC$$Base;
32+
#define NU_TZ_NSC_REGION_START ((uint32_t) &Image$$ER_IROM_NSC$$Base)
33+
#define NU_TZ_NSC_REGION_SIZE (NU_TZ_NSC_SIZE)
3434

3535
#elif defined(__ICCARM__)
3636

37-
extern int __NU_TZ_NSC_start__;
38-
extern int __NU_TZ_NSC_size__;
39-
40-
#define NU_TZ_NSC_REGION_START ((uint32_t) &__NU_TZ_NSC_start__)
41-
#define NU_TZ_NSC_REGION_SIZE ((uint32_t) &__NU_TZ_NSC_size__)
37+
extern int Image$$ER_IROM_NSC$$Base;
38+
#define NU_TZ_NSC_REGION_START ((uint32_t) &Image$$ER_IROM_NSC$$Base)
39+
#define NU_TZ_NSC_REGION_SIZE (NU_TZ_NSC_SIZE)
4240

4341
#elif defined(__GNUC__)
4442

45-
extern int __nu_tz_nsc_start;
46-
extern int __nu_tz_nsc_size;
47-
48-
#define NU_TZ_NSC_REGION_START ((uint32_t) &__nu_tz_nsc_start)
49-
#define NU_TZ_NSC_REGION_SIZE ((uint32_t) &__nu_tz_nsc_size)
43+
extern int Image$$ER_IROM_NSC$$Base;
44+
#define NU_TZ_NSC_REGION_START ((uint32_t) &Image$$ER_IROM_NSC$$Base)
45+
#define NU_TZ_NSC_REGION_SIZE (NU_TZ_NSC_SIZE)
5046

5147
#endif
5248

53-
/* Check relevant macros have been defined */
54-
#if (! defined(NU_TZ_SECURE_FLASH_SIZE))
55-
#error("NU_TZ_SECURE_FLASH_SIZE not defined")
56-
#endif
57-
#if (! defined(NU_TZ_SECURE_SRAM_SIZE))
58-
#error("NU_TZ_SECURE_SRAM_SIZE not defined")
59-
#endif
60-
#if (! defined(NU_TZ_NSC_REGION_START))
61-
#error("NU_TZ_NSC_REGION_START not defined")
62-
#endif
63-
#if (! defined(NU_TZ_NSC_REGION_SIZE))
64-
#error("NU_TZ_NSC_REGION_SIZE not defined")
65-
#endif
6649

6750
/*
6851
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
@@ -88,7 +71,7 @@ extern int __nu_tz_nsc_size;
8871
// <0x16000=> 88KB
8972
// <0x18000=> 96KB
9073
*/
91-
#define SCU_SECURE_SRAM_SIZE NU_TZ_SECURE_SRAM_SIZE
74+
#define SCU_SECURE_SRAM_SIZE NU_RAM_SIZE_S
9275
#define NON_SECURE_SRAM_BASE (0x30000000 + SCU_SECURE_SRAM_SIZE)
9376

9477

@@ -103,7 +86,7 @@ extern int __nu_tz_nsc_size;
10386
// <o>Secure Flash ROM Size <0x800-0x7FFFF:0x800>
10487
*/
10588

106-
#define FMC_SECURE_ROM_SIZE NU_TZ_SECURE_FLASH_SIZE
89+
#define FMC_SECURE_ROM_SIZE NU_ROM_SIZE_S
10790

10891
#define FMC_NON_SECURE_BASE (0x10000000 + FMC_SECURE_ROM_SIZE)
10992

@@ -867,5 +850,9 @@ __STATIC_INLINE void TZ_SAU_Setup(void)
867850

868851
#endif /* #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
869852

853+
#ifdef __cplusplus
854+
}
855+
#endif
856+
870857
#endif /* PARTITION_M2351 */
871858

targets/TARGET_NUVOTON/TARGET_M2351/device/partition_M2351_mem.h

Lines changed: 120 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919
#ifndef __PARTITION_M2351_MEM_H__
2020
#define __PARTITION_M2351_MEM_H__
2121

22-
/* About partition_M2351_mem.h/partition_M2351_mem.icf
22+
/* About partition_M2351_mem.h/partition_M2351_mem.icf.h
2323
*
2424
* 1. partition_M2351_mem.h is created for centralizing memory partition configuration. It will be
2525
* included by C/C++ files and linker files (except IAR linker file).
26-
* 2. IAR linker doesn't support preprocessor, so partition_M2351_mem.icf, duplicate of partition_M2351_mem.h
26+
* 2. IAR linker doesn't support preprocessor, so partition_M2351_mem.icf.h, duplicate of partition_M2351_mem.h
2727
* is created for IAR linker file.
28+
* 3. To continue above, we name partition_M2351_mem.icf.h instead of partition_M2351_mem.icf because:
29+
* (1) Mbed OS build tool may mis-regard partition_M2351_mem.icf as the main linker configuration file.
30+
* (2) *.icf files may not be present in search directories for "include" directive. Per observation,
31+
* the search directories are inconsistent among normal example build and test code build. To address
32+
* it, we name partition_M2351_mem.icf.h instead because *.h files are always present in these builds
33+
* (already there or via copy).
2834
*/
2935

3036
/* Default flash/SRAM partition
@@ -39,34 +45,38 @@
3945
*/
4046
#if defined(DOMAIN_NS) && DOMAIN_NS
4147

42-
/* Default non-secure ROM layout */
48+
/* Resolve non-secure ROM start */
4349
#ifndef MBED_ROM_START
4450
#define MBED_ROM_START (0x10040000)
4551
#endif
52+
/* Resolve non-secure ROM size */
4653
#ifndef MBED_ROM_SIZE
4754
#define MBED_ROM_SIZE (0x40000)
4855
#endif
49-
/* Default non-secure RAM layout */
56+
/* Resolve non-secure RAM start */
5057
#ifndef MBED_RAM_START
5158
#define MBED_RAM_START (0x30008000)
5259
#endif
60+
/* Resolve non-secure RAM size */
5361
#ifndef MBED_RAM_SIZE
5462
#define MBED_RAM_SIZE (0x10000)
5563
#endif
5664

5765
#else
5866

59-
/* Default secure ROM layout */
67+
/* Resolve secure ROM start */
6068
#ifndef MBED_ROM_START
6169
#define MBED_ROM_START (0x0)
6270
#endif
71+
/* Resolve secure ROM size */
6372
#ifndef MBED_ROM_SIZE
6473
#define MBED_ROM_SIZE (0x40000)
6574
#endif
66-
/* Default secure RAM layout */
75+
/* Resolve secure RAM start */
6776
#ifndef MBED_RAM_START
6877
#define MBED_RAM_START (0x20000000)
6978
#endif
79+
/* Resolve secure RAM size */
7080
#ifndef MBED_RAM_SIZE
7181
#define MBED_RAM_SIZE (0x8000)
7282
#endif
@@ -108,4 +118,108 @@
108118

109119
#endif
110120

121+
/* Mbed build tool passes just APPLICATION_xxx macros to C/C++ files and just
122+
* MBED_APP_xxx macros to linker files even though they mean the same thing.
123+
* Because this file is to include by both C/C++ files and linker files, we add
124+
* these macros according to the others for consistency when they are missing
125+
* in compile or link stage. */
126+
127+
#ifndef APPLICATION_ADDR
128+
#ifdef MBED_APP_START
129+
#define APPLICATION_ADDR MBED_APP_START
130+
#else
131+
#define APPLICATION_ADDR MBED_ROM_START
132+
#endif
133+
#endif
134+
135+
#ifndef APPLICATION_SIZE
136+
#ifdef MBED_APP_SIZE
137+
#define APPLICATION_SIZE MBED_APP_SIZE
138+
#else
139+
#define APPLICATION_SIZE MBED_ROM_SIZE
140+
#endif
141+
#endif
142+
143+
#ifndef APPLICATION_RAM_ADDR
144+
#ifdef MBED_RAM_APP_START
145+
#define APPLICATION_RAM_ADDR MBED_RAM_APP_START
146+
#else
147+
#define APPLICATION_RAM_ADDR MBED_RAM_START
148+
#endif
149+
#endif
150+
151+
#ifndef APPLICATION_RAM_SIZE
152+
#ifdef MBED_RAM_APP_SIZE
153+
#define APPLICATION_RAM_SIZE MBED_RAM_APP_SIZE
154+
#else
155+
#define APPLICATION_RAM_SIZE MBED_RAM_SIZE
156+
#endif
157+
#endif
158+
159+
#ifndef MBED_APP_START
160+
#define MBED_APP_START APPLICATION_ADDR
161+
#endif
162+
163+
#ifndef MBED_APP_SIZE
164+
#define MBED_APP_SIZE APPLICATION_SIZE
165+
#endif
166+
167+
#ifndef MBED_RAM_APP_START
168+
#define MBED_RAM_APP_START APPLICATION_RAM_ADDR
169+
#endif
170+
171+
#ifndef MBED_RAM_APP_SIZE
172+
#define MBED_RAM_APP_SIZE APPLICATION_RAM_SIZE
173+
#endif
174+
175+
#if (APPLICATION_ADDR != MBED_APP_START)
176+
#error("APPLICATION_ADDR and MBED_APP_START are not the same!!!")
177+
#endif
178+
179+
#if (APPLICATION_SIZE != MBED_APP_SIZE)
180+
#error("APPLICATION_SIZE and MBED_APP_SIZE are not the same!!!")
181+
#endif
182+
183+
#if (APPLICATION_RAM_ADDR != MBED_RAM_APP_START)
184+
#error("APPLICATION_RAM_ADDR and MBED_RAM_APP_START are not the same!!!")
185+
#endif
186+
187+
#if (APPLICATION_RAM_SIZE != MBED_RAM_APP_SIZE)
188+
#error("APPLICATION_RAM_SIZE and MBED_RAM_APP_SIZE are not the same!!!")
189+
#endif
190+
191+
/* Determine NSC area
192+
*
193+
* Requirements for NSC area:
194+
* 1. Requested by SAU, NSC area must start at 32 byte-aligned boundary.
195+
* 2. By IDAU, 0~0x4000 is secure. NSC can only locate in 0x4000~0x10000000.
196+
* 3. Greentea flash IAP uses last 2 sectors for its test. Avoid this range.
197+
* 4. Greentea NVSTORE uses last 2 sectors or 4 KiB x 2 for its test. Avoid this range.
198+
* 5. KVStore uses last a few KiB. Avoid this range.
199+
* 6. Due to TFM build process, TFM and its tests must generate the same cmse_lib.o.
200+
* To this end, TZ NSC location must fix at a well-known location and cannot place
201+
* arbitrarily.
202+
*
203+
* Configurable for NSC area:
204+
* We cannot configure NSC location via configuration parameter because the generated
205+
* configuration macros are just passed to C/C++ files but not to linker files. So
206+
* we can only hardcode NSC location here as constants (to be included by linker file).
207+
*
208+
* Locate NSC area at end of secure flash:
209+
* We decide to locate NSC area at end of secure flash. To avoid this area
210+
* accidentally erased by flash IAP operation, flash IAP must configure to exclude
211+
* this area.
212+
*/
213+
/* TZ NSC area defaults to from secure ROM end */
214+
#define NU_TZ_NSC_START (NU_ROM_START_S + NU_ROM_SIZE_S - NU_TZ_NSC_SIZE)
215+
/* TZ NSC area defaults to 4KiB. */
216+
#define NU_TZ_NSC_SIZE 0x1000
217+
218+
/* Configuration of flash IAP area */
219+
#define NU_FLASHIAP_SECURE_START NU_ROM_START_S
220+
/* Exclude NSC area to avoid accidentally erased */
221+
#define NU_FLASHIAP_SECURE_SIZE (NU_ROM_SIZE_S - NU_TZ_NSC_SIZE)
222+
#define NU_FLASHIAP_NONSECURE_START NU_ROM_START_NS
223+
#define NU_FLASHIAP_NONSECURE_SIZE NU_ROM_SIZE_NS
224+
111225
#endif /* __PARTITION_M2351_MEM_H__ */

targets/TARGET_NUVOTON/TARGET_M2351/device/partition_M2351_mem.icf

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)