Skip to content

Commit c434ea2

Browse files
committed
Nuvoton: Migrate to new style memory bank information
Change memory bank symbols: 1. MBED_APP_START/SIZE -> MBED_CONFIGURED_ROM_BANK_IROM1_START/SIZE NOTE: IROM2 for M2354 2. MBED_RAM_APP_START/SIZE -> MBED_CONFIGURED_RAM_BANK_IRAM1_START/SIZE NOTE: IRAM2 for M2354 3. APPLICATION_ADDR/SIZE -> MBED_CONFIGURED_ROM_BANK_IROM1_START/SIZE 4. APPLICATION_RAM_ADDR/SIZE -> MBED_CONFIGURED_RAM_BANK_IRAM1_START/SIZE 5. -> MBED_CONFIGURED_RAM_BANK_XRAM1_START/SIZE NOTE: Specific to NUC472 6. NU_HYPERRAM_START/SIZE -> MBED_CONFIGURED_RAM_BANK_HYPERRAM1_START/SIZE NOTE: Specific to M467
1 parent 67a1942 commit c434ea2

File tree

27 files changed

+371
-725
lines changed

27 files changed

+371
-725
lines changed

targets/TARGET_NUVOTON/TARGET_M2354/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ target_sources(mbed-m2354
1414
analogin_api.c
1515
analogout_api.c
1616

17+
device/partition_M2354_mem.c
1718
device/startup_M2354.c
1819
device/system_M2354.c
1920
device/StdDriver/src/m2354_acmp.c

targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ Below summarize the copy paths from TF-M into Mbed:
152152
**NOTE**: `trusted-firmware-m/cmake_build/install/image_signing/keys/root-RSA-3072.pem` can be missing due to TF-M build tool issue.
153153
Try to get it from `trusted-firmware-m/bl2/ext/mcuboot/root-RSA-3072.pem` instead if it is just the original source.
154154

155+
Open `targets.json5` (for built-in target) or `custom_targets.json5` (for custom target),
156+
, locate the `memory_banks` section for this mbed target,
157+
and update the below symbols per above TF-M exported `region_defs.h`.
158+
159+
```json5
160+
"memory_banks": {
161+
"NS_CODE": {
162+
"size": /*<NS_CODE_SIZE>*/,
163+
"start": /*<NS_CODE_START>*/,
164+
},
165+
"NS_DATA": {
166+
"size": /*<NS_DATA_SIZE>*/,
167+
"start": /*<NS_DATA_START>*/,
168+
},
169+
},
170+
```
171+
155172
## PSA Firmware Update
156173

157174
### Requirement

targets/TARGET_NUVOTON/TARGET_M2354/device/TOOLCHAIN_GCC_ARM/M2354.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ StackSize = MBED_CONF_TARGET_BOOT_STACK_SIZE;
3434

3535
MEMORY
3636
{
37-
VECTORS (rx) : ORIGIN = MBED_APP_START, LENGTH = 0x00000400
38-
FLASH (rx) : ORIGIN = MBED_APP_START + 0x400, LENGTH = MBED_APP_SIZE - 0x400
39-
RAM_INTERN (rwx) : ORIGIN = MBED_RAM_APP_START, LENGTH = MBED_RAM_APP_SIZE
37+
VECTORS (rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_NS_CODE_START, LENGTH = 0x00000400
38+
FLASH (rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_NS_CODE_START + 0x400, LENGTH = MBED_CONFIGURED_ROM_BANK_NS_CODE_SIZE - 0x400
39+
RAM_INTERN (rwx) : ORIGIN = MBED_CONFIGURED_RAM_BANK_NS_DATA_START, LENGTH = MBED_CONFIGURED_RAM_BANK_NS_DATA_SIZE
4040
}
4141

4242
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2020, Nuvoton Technology Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <assert.h>
20+
#include "partition_M2354_mem.h"
21+
22+
/* Check MBED_ROM_BANK_NS_CODE_START and friends
23+
*
24+
* These symbols must be resolved by TF-M exported region_defs.h.
25+
*/
26+
static_assert(MBED_ROM_BANK_NS_CODE_START == NS_CODE_START,
27+
"MBED_ROM_BANK_NS_CODE_START not equal TF-M imported NS_CODE_START");
28+
static_assert(MBED_ROM_BANK_NS_CODE_SIZE == NS_CODE_SIZE,
29+
"MBED_ROM_BANK_NS_CODE_SIZE not equal TF-M imported NS_CODE_SIZE");
30+
static_assert(MBED_RAM_BANK_NS_DATA_START == NS_DATA_START,
31+
"MBED_RAM_BANK_NS_DATA_START not equal TF-M imported NS_DATA_START");
32+
static_assert(MBED_RAM_BANK_NS_DATA_SIZE == NS_DATA_SIZE,
33+
"MBED_RAM_BANK_NS_DATA_SIZE not equal TF-M imported NS_DATA_SIZE");

targets/TARGET_NUVOTON/TARGET_M2354/device/partition_M2354_mem.h

Lines changed: 24 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -19,113 +19,45 @@
1919
#ifndef __PARTITION_M2354_MEM_H__
2020
#define __PARTITION_M2354_MEM_H__
2121

22-
/* About partition_M2354_mem.h/partition_M2354_mem.icf.h
23-
*
24-
* 1. partition_M2354_mem.h is created for centralizing memory partition configuration. It will be
25-
* included by C/C++ files and linker files (except IAR linker file).
26-
* 2. IAR linker doesn't support preprocessor, so partition_M2354_mem.icf.h, duplicate of partition_M2354_mem.h
27-
* is created for IAR linker file.
28-
* 3. To continue above, we name partition_M2354_mem.icf.h instead of partition_M2354_mem.icf because:
29-
* (1) Mbed OS build tool may mis-regard partition_M2354_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_M2354_mem.icf.h instead because *.h files are always present in these builds
33-
* (already there or via copy).
34-
*/
35-
3622
#include "nu_tfm_import_define.h"
3723
#include NU_TFM_S_REGION_DEFS_H_PATH
3824
#include "nu_tfm_import_undefine.h"
3925

40-
/* Resolve MBED_ROM_START and friends
26+
/* Resolve MBED_ROM_BANK_NS_CODE_START and friends
4127
*
42-
* TF-M exported region_defs.h essentially resolves MBED_ROM_START and friends.
43-
* target.mbed_rom_start and friends get unnecessary.
28+
* TF-M exported region_defs.h essentially resolves MBED_ROM_BANK_NS_CODE_START and friends.
4429
*/
45-
/* Resolve non-secure ROM start */
46-
#undef MBED_ROM_START
47-
#define MBED_ROM_START NS_CODE_START
48-
49-
/* Resolve non-secure ROM size */
50-
#undef MBED_ROM_SIZE
51-
#define MBED_ROM_SIZE NS_CODE_SIZE
52-
53-
/* Resolve non-secure RAM start */
54-
#undef MBED_RAM_START
55-
#define MBED_RAM_START NS_DATA_START
56-
57-
/* Resolve non-secure RAM size */
58-
#undef MBED_RAM_SIZE
59-
#define MBED_RAM_SIZE NS_DATA_SIZE
60-
61-
/* Mbed build tool passes just APPLICATION_xxx macros to C/C++ files and just
62-
* MBED_APP_xxx macros to linker files even though they mean the same thing.
63-
* Because this file is to include by both C/C++ files and linker files, we add
64-
* these macros according to the others for consistency when they are missing
65-
* in compile or link stage. */
6630

67-
#ifndef APPLICATION_ADDR
68-
#ifdef MBED_APP_START
69-
#define APPLICATION_ADDR MBED_APP_START
70-
#else
71-
#define APPLICATION_ADDR MBED_ROM_START
72-
#endif
73-
#endif
74-
75-
#ifndef APPLICATION_SIZE
76-
#ifdef MBED_APP_SIZE
77-
#define APPLICATION_SIZE MBED_APP_SIZE
78-
#else
79-
#define APPLICATION_SIZE MBED_ROM_SIZE
80-
#endif
31+
/* Physical NS_CODE start/size */
32+
#if !defined(MBED_ROM_BANK_NS_CODE_START)
33+
#define MBED_ROM_BANK_NS_CODE_START NS_CODE_START
8134
#endif
35+
#if !defined(MBED_ROM_BANK_NS_CODE_SIZE)
36+
#define MBED_ROM_BANK_NS_CODE_SIZE NS_CODE_SIZE
37+
#endif
8238

83-
#ifndef APPLICATION_RAM_ADDR
84-
#ifdef MBED_RAM_APP_START
85-
#define APPLICATION_RAM_ADDR MBED_RAM_APP_START
86-
#else
87-
#define APPLICATION_RAM_ADDR MBED_RAM_START
39+
/* Physical NS_DATA start/size */
40+
#if !defined(MBED_RAM_BANK_NS_DATA_START)
41+
#define MBED_RAM_BANK_NS_DATA_START NS_DATA_START
8842
#endif
43+
#if !defined(MBED_RAM_BANK_NS_DATA_SIZE)
44+
#define MBED_RAM_BANK_NS_DATA_SIZE NS_DATA_SIZE
8945
#endif
9046

91-
#ifndef APPLICATION_RAM_SIZE
92-
#ifdef MBED_RAM_APP_SIZE
93-
#define APPLICATION_RAM_SIZE MBED_RAM_APP_SIZE
94-
#else
95-
#define APPLICATION_RAM_SIZE MBED_RAM_SIZE
96-
#endif
47+
/* Configured NS_CODE start/size */
48+
#if !defined(MBED_CONFIGURED_ROM_BANK_NS_CODE_START)
49+
#define MBED_CONFIGURED_ROM_BANK_NS_CODE_START MBED_ROM_BANK_NS_CODE_START
9750
#endif
51+
#if !defined(MBED_CONFIGURED_ROM_BANK_NS_CODE_SIZE)
52+
#define MBED_CONFIGURED_ROM_BANK_NS_CODE_SIZE MBED_ROM_BANK_NS_CODE_SIZE
53+
#endif
9854

99-
#ifndef MBED_APP_START
100-
#define MBED_APP_START APPLICATION_ADDR
55+
/* Configured NS_DATA start/size */
56+
#if !defined(MBED_CONFIGURED_RAM_BANK_NS_DATA_START)
57+
#define MBED_CONFIGURED_RAM_BANK_NS_DATA_START MBED_RAM_BANK_NS_DATA_START
10158
#endif
102-
103-
#ifndef MBED_APP_SIZE
104-
#define MBED_APP_SIZE APPLICATION_SIZE
105-
#endif
106-
107-
#ifndef MBED_RAM_APP_START
108-
#define MBED_RAM_APP_START APPLICATION_RAM_ADDR
109-
#endif
110-
111-
#ifndef MBED_RAM_APP_SIZE
112-
#define MBED_RAM_APP_SIZE APPLICATION_RAM_SIZE
113-
#endif
114-
115-
#if (APPLICATION_ADDR != MBED_APP_START)
116-
#error("APPLICATION_ADDR and MBED_APP_START are not the same!!!")
117-
#endif
118-
119-
#if (APPLICATION_SIZE != MBED_APP_SIZE)
120-
#error("APPLICATION_SIZE and MBED_APP_SIZE are not the same!!!")
121-
#endif
122-
123-
#if (APPLICATION_RAM_ADDR != MBED_RAM_APP_START)
124-
#error("APPLICATION_RAM_ADDR and MBED_RAM_APP_START are not the same!!!")
125-
#endif
126-
127-
#if (APPLICATION_RAM_SIZE != MBED_RAM_APP_SIZE)
128-
#error("APPLICATION_RAM_SIZE and MBED_RAM_APP_SIZE are not the same!!!")
59+
#if !defined(MBED_CONFIGURED_RAM_BANK_NS_DATA_SIZE)
60+
#define MBED_CONFIGURED_RAM_BANK_NS_DATA_SIZE MBED_RAM_BANK_NS_DATA_SIZE
12961
#endif
13062

13163
#endif /* __PARTITION_M2354_MEM_H__ */

targets/TARGET_NUVOTON/TARGET_M251/device/M251_mem.h

Lines changed: 22 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -19,115 +19,42 @@
1919
#ifndef __M251_MEM_H__
2020
#define __M251_MEM_H__
2121

22-
/* About M251_mem.h/M251_mem.icf.h
23-
*
24-
* 1. M251_mem.h is created for centralizing memory configuration. It will be included by C/C++ files
25-
* and linker files (except IAR linker file).
26-
* 2. IAR linker doesn't support preprocessor, so M251_mem.icf.h, duplicate of M251_mem.h
27-
* is created for IAR linker file.
28-
* 3. To continue above, we name M251_mem.icf.h instead of M251_mem.icf because:
29-
* (1) Mbed OS build tool may mis-regard M251_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 M251_mem.icf.h instead because *.h files are always present in these builds
33-
* (already there or via copy).
34-
*/
35-
3622
/* Default memory specification
3723
*
3824
* Flash size: 256KiB
3925
* SRAM size: 32KiB
4026
*/
4127

42-
/* Resolve ROM start */
43-
#ifndef MBED_ROM_START
44-
#define MBED_ROM_START (0x0)
45-
#endif
46-
47-
/* Resolve ROM size */
48-
#ifndef MBED_ROM_SIZE
49-
#define MBED_ROM_SIZE (0x40000)
50-
#endif
51-
52-
/* Resolve RAM start */
53-
#ifndef MBED_RAM_START
54-
#define MBED_RAM_START (0x20000000)
55-
#endif
56-
57-
/* Resolve RAM size */
58-
#ifndef MBED_RAM_SIZE
59-
#define MBED_RAM_SIZE (0x8000)
60-
#endif
61-
62-
63-
/* Mbed build tool passes just APPLICATION_xxx macros to C/C++ files and just
64-
* MBED_APP_xxx macros to linker files even though they mean the same thing.
65-
* Because this file is to include by both C/C++ files and linker files, we add
66-
* these macros according to the others for consistency when they are missing
67-
* in compile or link stage. */
68-
69-
#ifndef APPLICATION_ADDR
70-
#ifdef MBED_APP_START
71-
#define APPLICATION_ADDR MBED_APP_START
72-
#else
73-
#define APPLICATION_ADDR MBED_ROM_START
74-
#endif
28+
/* Physical IROM1 start/size */
29+
#if !defined(MBED_ROM_BANK_IROM1_START)
30+
#define MBED_ROM_BANK_IROM1_START 0x0
7531
#endif
32+
#if !defined(MBED_ROM_BANK_IROM1_SIZE)
33+
#define MBED_ROM_BANK_IROM1_SIZE 0x40000
34+
#endif
7635

77-
#ifndef APPLICATION_SIZE
78-
#ifdef MBED_APP_SIZE
79-
#define APPLICATION_SIZE MBED_APP_SIZE
80-
#else
81-
#define APPLICATION_SIZE MBED_ROM_SIZE
36+
/* Physical IRAM1 start/size */
37+
#if !defined(MBED_RAM_BANK_IRAM1_START)
38+
#define MBED_RAM_BANK_IRAM1_START 0x20000000
8239
#endif
40+
#if !defined(MBED_RAM_BANK_IRAM1_SIZE)
41+
#define MBED_RAM_BANK_IRAM1_SIZE 0x8000
8342
#endif
8443

85-
#ifndef APPLICATION_RAM_ADDR
86-
#ifdef MBED_RAM_APP_START
87-
#define APPLICATION_RAM_ADDR MBED_RAM_APP_START
88-
#else
89-
#define APPLICATION_RAM_ADDR MBED_RAM_START
90-
#endif
44+
/* Configured IROM1 start/size */
45+
#if !defined(MBED_CONFIGURED_ROM_BANK_IROM1_START)
46+
#define MBED_CONFIGURED_ROM_BANK_IROM1_START MBED_ROM_BANK_IROM1_START
9147
#endif
48+
#if !defined(MBED_CONFIGURED_ROM_BANK_IROM1_SIZE)
49+
#define MBED_CONFIGURED_ROM_BANK_IROM1_SIZE MBED_ROM_BANK_IROM1_SIZE
50+
#endif
9251

93-
#ifndef APPLICATION_RAM_SIZE
94-
#ifdef MBED_RAM_APP_SIZE
95-
#define APPLICATION_RAM_SIZE MBED_RAM_APP_SIZE
96-
#else
97-
#define APPLICATION_RAM_SIZE MBED_RAM_SIZE
98-
#endif
52+
/* Configured IRAM1 start/size */
53+
#if !defined(MBED_CONFIGURED_RAM_BANK_IRAM1_START)
54+
#define MBED_CONFIGURED_RAM_BANK_IRAM1_START MBED_RAM_BANK_IRAM1_START
9955
#endif
100-
101-
#ifndef MBED_APP_START
102-
#define MBED_APP_START APPLICATION_ADDR
103-
#endif
104-
105-
#ifndef MBED_APP_SIZE
106-
#define MBED_APP_SIZE APPLICATION_SIZE
107-
#endif
108-
109-
#ifndef MBED_RAM_APP_START
110-
#define MBED_RAM_APP_START APPLICATION_RAM_ADDR
111-
#endif
112-
113-
#ifndef MBED_RAM_APP_SIZE
114-
#define MBED_RAM_APP_SIZE APPLICATION_RAM_SIZE
115-
#endif
116-
117-
#if (APPLICATION_ADDR != MBED_APP_START)
118-
#error("APPLICATION_ADDR and MBED_APP_START are not the same!!!")
119-
#endif
120-
121-
#if (APPLICATION_SIZE != MBED_APP_SIZE)
122-
#error("APPLICATION_SIZE and MBED_APP_SIZE are not the same!!!")
123-
#endif
124-
125-
#if (APPLICATION_RAM_ADDR != MBED_RAM_APP_START)
126-
#error("APPLICATION_RAM_ADDR and MBED_RAM_APP_START are not the same!!!")
127-
#endif
128-
129-
#if (APPLICATION_RAM_SIZE != MBED_RAM_APP_SIZE)
130-
#error("APPLICATION_RAM_SIZE and MBED_RAM_APP_SIZE are not the same!!!")
56+
#if !defined(MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE)
57+
#define MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE MBED_RAM_BANK_IRAM1_SIZE
13158
#endif
13259

13360
#endif /* __M251_MEM_H__ */

targets/TARGET_NUVOTON/TARGET_M251/device/TOOLCHAIN_GCC_ARM/M251.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ StackSize = MBED_CONF_TARGET_BOOT_STACK_SIZE;
3232

3333
MEMORY
3434
{
35-
VECTORS (rx) : ORIGIN = MBED_APP_START, LENGTH = 0x00000400
36-
FLASH (rx) : ORIGIN = MBED_APP_START + 0x400, LENGTH = MBED_APP_SIZE - 0x400
37-
RAM_INTERN (rwx) : ORIGIN = MBED_RAM_APP_START, LENGTH = MBED_RAM_APP_SIZE
35+
VECTORS (rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_IROM1_START, LENGTH = 0x00000400
36+
FLASH (rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_IROM1_START + 0x400, LENGTH = MBED_CONFIGURED_ROM_BANK_IROM1_SIZE - 0x400
37+
RAM_INTERN (rwx) : ORIGIN = MBED_CONFIGURED_RAM_BANK_IRAM1_START, LENGTH = MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE
3838
}
3939

4040
/* Must match cmsis_nvic.h */

targets/TARGET_NUVOTON/TARGET_M251/flash_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ static const flash_algo_t flash_algo_config = {
9494

9595
/* Secure flash */
9696
static const sector_info_t sectors_info[] = {
97-
{MBED_ROM_START, 0x200}, // (start, sector size)
97+
{MBED_ROM_BANK_IROM1_START, 0x200}, // (start, sector size)
9898
};
9999

100100
/* Secure flash */
101101
static const flash_target_config_t flash_target_config = {
102102
.page_size = 4, // 4 bytes
103103
// Here page_size is program unit, which is different
104104
// than FMC definition.
105-
.flash_start = MBED_ROM_START,
106-
.flash_size = MBED_ROM_SIZE,
105+
.flash_start = MBED_ROM_BANK_IROM1_START,
106+
.flash_size = MBED_ROM_BANK_IROM1_SIZE,
107107
.sectors = sectors_info,
108108
.sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t)
109109
};

0 commit comments

Comments
 (0)