Skip to content

Commit

Permalink
Nuvoton: Migrate to new memory bankc information (#382)
Browse files Browse the repository at this point in the history
* Nuvoton: Remove unsupported armclang and iar toolchains

Armclang and IAR toolchains are not supported in Mbed CE. Remove them
for clean.

* 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
  • Loading branch information
ccli8 authored Nov 22, 2024
1 parent ab43414 commit 99fcb5b
Show file tree
Hide file tree
Showing 37 changed files with 371 additions and 1,719 deletions.
1 change: 1 addition & 0 deletions targets/TARGET_NUVOTON/TARGET_M2354/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target_sources(mbed-m2354
analogin_api.c
analogout_api.c

device/partition_M2354_mem.c
device/startup_M2354.c
device/system_M2354.c
device/StdDriver/src/m2354_acmp.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ Below summarize the copy paths from TF-M into Mbed:
**NOTE**: `trusted-firmware-m/cmake_build/install/image_signing/keys/root-RSA-3072.pem` can be missing due to TF-M build tool issue.
Try to get it from `trusted-firmware-m/bl2/ext/mcuboot/root-RSA-3072.pem` instead if it is just the original source.

Open `targets.json5` (for built-in target) or `custom_targets.json5` (for custom target),
, locate the `memory_banks` section for this mbed target,
and update the below symbols per above TF-M exported `region_defs.h`.

```json5
"memory_banks": {
"NS_CODE": {
"size": /*<NS_CODE_SIZE>*/,
"start": /*<NS_CODE_START>*/,
},
"NS_DATA": {
"size": /*<NS_DATA_SIZE>*/,
"start": /*<NS_DATA_START>*/,
},
},
```

## PSA Firmware Update

### Requirement
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ StackSize = MBED_CONF_TARGET_BOOT_STACK_SIZE;

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

/**
Expand Down
33 changes: 33 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_M2354/device/partition_M2354_mem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020, Nuvoton Technology Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <assert.h>
#include "partition_M2354_mem.h"

/* Check MBED_ROM_BANK_NS_CODE_START and friends
*
* These symbols must be resolved by TF-M exported region_defs.h.
*/
static_assert(MBED_ROM_BANK_NS_CODE_START == NS_CODE_START,
"MBED_ROM_BANK_NS_CODE_START not equal TF-M imported NS_CODE_START");
static_assert(MBED_ROM_BANK_NS_CODE_SIZE == NS_CODE_SIZE,
"MBED_ROM_BANK_NS_CODE_SIZE not equal TF-M imported NS_CODE_SIZE");
static_assert(MBED_RAM_BANK_NS_DATA_START == NS_DATA_START,
"MBED_RAM_BANK_NS_DATA_START not equal TF-M imported NS_DATA_START");
static_assert(MBED_RAM_BANK_NS_DATA_SIZE == NS_DATA_SIZE,
"MBED_RAM_BANK_NS_DATA_SIZE not equal TF-M imported NS_DATA_SIZE");
116 changes: 24 additions & 92 deletions targets/TARGET_NUVOTON/TARGET_M2354/device/partition_M2354_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,113 +19,45 @@
#ifndef __PARTITION_M2354_MEM_H__
#define __PARTITION_M2354_MEM_H__

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

#include "nu_tfm_import_define.h"
#include NU_TFM_S_REGION_DEFS_H_PATH
#include "nu_tfm_import_undefine.h"

/* Resolve MBED_ROM_START and friends
/* Resolve MBED_ROM_BANK_NS_CODE_START and friends
*
* TF-M exported region_defs.h essentially resolves MBED_ROM_START and friends.
* target.mbed_rom_start and friends get unnecessary.
* TF-M exported region_defs.h essentially resolves MBED_ROM_BANK_NS_CODE_START and friends.
*/
/* Resolve non-secure ROM start */
#undef MBED_ROM_START
#define MBED_ROM_START NS_CODE_START

/* Resolve non-secure ROM size */
#undef MBED_ROM_SIZE
#define MBED_ROM_SIZE NS_CODE_SIZE

/* Resolve non-secure RAM start */
#undef MBED_RAM_START
#define MBED_RAM_START NS_DATA_START

/* Resolve non-secure RAM size */
#undef MBED_RAM_SIZE
#define MBED_RAM_SIZE NS_DATA_SIZE

/* Mbed build tool passes just APPLICATION_xxx macros to C/C++ files and just
* MBED_APP_xxx macros to linker files even though they mean the same thing.
* Because this file is to include by both C/C++ files and linker files, we add
* these macros according to the others for consistency when they are missing
* in compile or link stage. */

#ifndef APPLICATION_ADDR
#ifdef MBED_APP_START
#define APPLICATION_ADDR MBED_APP_START
#else
#define APPLICATION_ADDR MBED_ROM_START
#endif
#endif

#ifndef APPLICATION_SIZE
#ifdef MBED_APP_SIZE
#define APPLICATION_SIZE MBED_APP_SIZE
#else
#define APPLICATION_SIZE MBED_ROM_SIZE
#endif
/* Physical NS_CODE start/size */
#if !defined(MBED_ROM_BANK_NS_CODE_START)
#define MBED_ROM_BANK_NS_CODE_START NS_CODE_START
#endif
#if !defined(MBED_ROM_BANK_NS_CODE_SIZE)
#define MBED_ROM_BANK_NS_CODE_SIZE NS_CODE_SIZE
#endif

#ifndef APPLICATION_RAM_ADDR
#ifdef MBED_RAM_APP_START
#define APPLICATION_RAM_ADDR MBED_RAM_APP_START
#else
#define APPLICATION_RAM_ADDR MBED_RAM_START
/* Physical NS_DATA start/size */
#if !defined(MBED_RAM_BANK_NS_DATA_START)
#define MBED_RAM_BANK_NS_DATA_START NS_DATA_START
#endif
#if !defined(MBED_RAM_BANK_NS_DATA_SIZE)
#define MBED_RAM_BANK_NS_DATA_SIZE NS_DATA_SIZE
#endif

#ifndef APPLICATION_RAM_SIZE
#ifdef MBED_RAM_APP_SIZE
#define APPLICATION_RAM_SIZE MBED_RAM_APP_SIZE
#else
#define APPLICATION_RAM_SIZE MBED_RAM_SIZE
#endif
/* Configured NS_CODE start/size */
#if !defined(MBED_CONFIGURED_ROM_BANK_NS_CODE_START)
#define MBED_CONFIGURED_ROM_BANK_NS_CODE_START MBED_ROM_BANK_NS_CODE_START
#endif
#if !defined(MBED_CONFIGURED_ROM_BANK_NS_CODE_SIZE)
#define MBED_CONFIGURED_ROM_BANK_NS_CODE_SIZE MBED_ROM_BANK_NS_CODE_SIZE
#endif

#ifndef MBED_APP_START
#define MBED_APP_START APPLICATION_ADDR
/* Configured NS_DATA start/size */
#if !defined(MBED_CONFIGURED_RAM_BANK_NS_DATA_START)
#define MBED_CONFIGURED_RAM_BANK_NS_DATA_START MBED_RAM_BANK_NS_DATA_START
#endif

#ifndef MBED_APP_SIZE
#define MBED_APP_SIZE APPLICATION_SIZE
#endif

#ifndef MBED_RAM_APP_START
#define MBED_RAM_APP_START APPLICATION_RAM_ADDR
#endif

#ifndef MBED_RAM_APP_SIZE
#define MBED_RAM_APP_SIZE APPLICATION_RAM_SIZE
#endif

#if (APPLICATION_ADDR != MBED_APP_START)
#error("APPLICATION_ADDR and MBED_APP_START are not the same!!!")
#endif

#if (APPLICATION_SIZE != MBED_APP_SIZE)
#error("APPLICATION_SIZE and MBED_APP_SIZE are not the same!!!")
#endif

#if (APPLICATION_RAM_ADDR != MBED_RAM_APP_START)
#error("APPLICATION_RAM_ADDR and MBED_RAM_APP_START are not the same!!!")
#endif

#if (APPLICATION_RAM_SIZE != MBED_RAM_APP_SIZE)
#error("APPLICATION_RAM_SIZE and MBED_RAM_APP_SIZE are not the same!!!")
#if !defined(MBED_CONFIGURED_RAM_BANK_NS_DATA_SIZE)
#define MBED_CONFIGURED_RAM_BANK_NS_DATA_SIZE MBED_RAM_BANK_NS_DATA_SIZE
#endif

#endif /* __PARTITION_M2354_MEM_H__ */
112 changes: 0 additions & 112 deletions targets/TARGET_NUVOTON/TARGET_M2354/device/partition_M2354_mem.icf.h

This file was deleted.

Loading

0 comments on commit 99fcb5b

Please sign in to comment.