Skip to content

Commit fbfb4df

Browse files
sigvartmhrlubos
authored andcommitted
[nrf noup] tree-wide: support NCS Partition Manager (PM) definitions
Partition Manager (PM) is a component of the nRF Connect SDK (NCS) which uses yaml files to resolve flash partition placement with a holistic view of the entire device, including each firmware image present on the flash device, and various subsystems, such as settings and NFFS. When this NCS extension is used, various source files which would use partition information from devicetree in "vanilla" zephyr instead use defines generated by PM instead. This commit removes support for HEX_FILES_TO_MERGE, as it conflicts with PM. The settings subsystem pm.yml defines a partition 'settings_storage'. The nffs subsystem pm.yml defines 'nffs_storage'. Leverage label translation to avoid patching partition names. Refer to the NCS documentation page for this feature for more details. This is a long-running out of tree patch which has been worked on by several people. The following sign-offs are in alphabetical order by first name. Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no> Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no> Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no> Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no> Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no> Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no> Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no> Signed-off-by: Ole Sæther <ole.saether@nordicsemi.no> Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no> Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no> Signed-off-by: Sigvart Hovland <sigvart.hovland@nordicsemi.no> Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no> Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no> Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no> Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no> Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no> Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no> Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no> (cherry picked from commit a7fb268) (cherry picked from commit ea83f6c) (cherry picked from commit 91b6032)
1 parent 2654453 commit fbfb4df

File tree

9 files changed

+130
-4
lines changed

9 files changed

+130
-4
lines changed

arch/arm/core/mpu/arm_mpu_regions.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <zephyr/arch/arm/mpu/arm_mpu.h>
99

1010
#include <zephyr/arch/arm/cortex_m/arm_mpu_mem_cfg.h>
11+
#if USE_PARTITION_MANAGER
12+
#include <pm_config.h>
13+
#endif
1114

1215
static const struct arm_mpu_region mpu_regions[] = {
1316
/* Region 0 */
@@ -21,13 +24,23 @@ static const struct arm_mpu_region mpu_regions[] = {
2124
#endif
2225
/* Region 1 */
2326
MPU_REGION_ENTRY("SRAM_0",
27+
#if USE_PARTITION_MANAGER
28+
PM_SRAM_ADDRESS,
29+
#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE)
30+
REGION_RAM_ATTR(PM_SRAM_ADDRESS, PM_SRAM_SIZE)),
31+
#else
32+
REGION_RAM_ATTR(REGION_SRAM_SIZE)),
33+
#endif
34+
#else
2435
CONFIG_SRAM_BASE_ADDRESS,
2536
#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE)
2637
REGION_RAM_ATTR(CONFIG_SRAM_BASE_ADDRESS, \
2738
CONFIG_SRAM_SIZE * 1024)),
2839
#else
2940
REGION_RAM_ATTR(REGION_SRAM_SIZE)),
3041
#endif
42+
43+
#endif /* USE_PARTITION_MANAGER */
3144
};
3245

3346
const struct arm_mpu_config mpu_config = {

cmake/modules/kernel.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,7 @@ if("${CMAKE_EXTRA_GENERATOR}" STREQUAL "Eclipse CDT4")
248248
include(${ZEPHYR_BASE}/cmake/ide/eclipse_cdt4_generator_amendment.cmake)
249249
eclipse_cdt4_generator_amendment(1)
250250
endif()
251+
252+
if(ZEPHYR_NRF_MODULE_DIR)
253+
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/partition_manager.cmake)
254+
endif()

drivers/flash/soc_flash_nrf.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ LOG_MODULE_REGISTER(flash_nrf);
3737

3838
#define SOC_NV_FLASH_NODE DT_INST(0, soc_nv_flash)
3939

40+
#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER
41+
#include <soc_secure.h>
42+
#include <pm_config.h>
43+
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER */
44+
4045
#ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE
4146
#define FLASH_SLOT_WRITE 7500
4247
#if defined(CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE)
@@ -166,6 +171,12 @@ static int flash_nrf_read(const struct device *dev, off_t addr,
166171
}
167172
#endif
168173

174+
#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER && PM_APP_ADDRESS
175+
if (addr < PM_APP_ADDRESS) {
176+
return soc_secure_mem_read(data, (void *)addr, len);
177+
}
178+
#endif
179+
169180
nrf_nvmc_buffer_read(data, (uint32_t)addr, len);
170181

171182
return 0;

include/zephyr/arch/arm/cortex_m/scripts/linker.ld

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@
3434
#define ROMSTART_REGION ROMABLE_REGION
3535
#endif
3636

37+
#if USE_PARTITION_MANAGER
38+
39+
#include <pm_config.h>
40+
41+
#if CONFIG_NCS_IS_VARIANT_IMAGE && defined(PM_S0_ID)
42+
/* We are linking against S1, create symbol containing the flash ID of S0.
43+
* This is used when writing code operating on the "other" slot.
44+
*/
45+
_image_1_primary_slot_id = PM_S0_ID;
46+
47+
#else /* ! CONFIG_NCS_IS_VARIANT_IMAGE */
48+
49+
#ifdef PM_S1_ID
50+
/* We are linking against S0, create symbol containing the flash ID of S1.
51+
* This is used when writing code operating on the "other" slot.
52+
*/
53+
_image_1_primary_slot_id = PM_S1_ID;
54+
#endif /* PM_S1_ID */
55+
56+
#endif /* CONFIG_NCS_IS_VARIANT_IMAGE */
57+
58+
#define ROM_ADDR PM_ADDRESS
59+
#define ROM_SIZE PM_SIZE
60+
61+
#define RAM_SIZE PM_SRAM_SIZE
62+
#define RAM_ADDR PM_SRAM_ADDRESS
63+
64+
#else /* ! USE_PARTITION_MANAGER */
65+
3766
#if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0)
3867
#define ROM_ADDR RAM_ADDR
3968
#else
@@ -66,6 +95,23 @@
6695
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
6796
#endif
6897

98+
#endif /* USE_PARTITION_MANAGER */
99+
100+
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay)
101+
#define CCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ccm))
102+
#define CCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ccm))
103+
#endif
104+
105+
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
106+
#define ITCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_itcm))
107+
#define ITCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_itcm))
108+
#endif
109+
110+
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay)
111+
#define DTCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_dtcm))
112+
#define DTCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_dtcm))
113+
#endif
114+
69115
#if defined(CONFIG_CUSTOM_SECTION_ALIGN)
70116
_region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE;
71117
#else

include/zephyr/storage/flash_map.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ const char *flash_area_label(const struct flash_area *fa);
273273
*/
274274
uint8_t flash_area_erased_val(const struct flash_area *fa);
275275

276+
#if USE_PARTITION_MANAGER
277+
#include <flash_map_pm.h>
278+
#else
279+
276280
/**
277281
* Returns non-0 value if fixed-partition of given DTS node label exists.
278282
*
@@ -358,6 +362,8 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
358362
#define FIXED_PARTITION_NODE_DEVICE(node) \
359363
DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(node))
360364

365+
#endif /* USE_PARTITION_MANAGER */
366+
361367
#ifdef __cplusplus
362368
}
363369
#endif

lib/heap/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ config HEAP_LISTENER
6868
choice
6969
prompt "Supported heap sizes"
7070
depends on !64BIT
71-
default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256)
71+
default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256) && !PARTITION_MANAGER_ENABLED
7272
default SYS_HEAP_AUTO
7373
help
7474
Heaps using reduced-size chunk headers can accommodate so called

lib/libc/common/source/stdlib/malloc.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525
#include <zephyr/logging/log.h>
2626
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
2727

28+
#if USE_PARTITION_MANAGER
29+
30+
#include <pm_config.h>
31+
32+
#define RAM_SIZE PM_SRAM_SIZE
33+
#define RAM_ADDR PM_SRAM_ADDRESS
34+
35+
#else /* ! USE_PARTITION_MANAGER */
36+
37+
#define RAM_SIZE (KB((size_t) CONFIG_SRAM_SIZE))
38+
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
39+
40+
#endif /* USE_PARTITION_MANAGER */
41+
2842
#ifdef CONFIG_COMMON_LIBC_MALLOC
2943

3044
#if (CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE != 0)
@@ -106,8 +120,8 @@ static POOL_SECTION unsigned char __aligned(HEAP_ALIGN) malloc_arena[HEAP_SIZE];
106120
extern char _heap_sentry[];
107121
# define HEAP_SIZE ROUND_DOWN((POINTER_TO_UINT(_heap_sentry) - HEAP_BASE), HEAP_ALIGN)
108122
# else
109-
# define HEAP_SIZE ROUND_DOWN((KB((size_t) CONFIG_SRAM_SIZE) - \
110-
((size_t) HEAP_BASE - (size_t) CONFIG_SRAM_BASE_ADDRESS)), HEAP_ALIGN)
123+
# define HEAP_SIZE ROUND_DOWN((RAM_SIZE - \
124+
((size_t) HEAP_BASE - (size_t) RAM_ADDR)), HEAP_ALIGN)
111125
# endif /* else CONFIG_XTENSA */
112126

113127
# endif /* else CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE > 0 */

subsys/fs/littlefs_fs.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,12 @@ struct fs_mount_t FS_FSTAB_ENTRY(DT_DRV_INST(inst)) = { \
10541054
.type = FS_LITTLEFS, \
10551055
.mnt_point = DT_INST_PROP(inst, mount_point), \
10561056
.fs_data = &fs_data_##inst, \
1057-
.storage_dev = (void *)DT_FIXED_PARTITION_ID(FS_PARTITION(inst)), \
1057+
.storage_dev = (void *) \
1058+
COND_CODE_1(USE_PARTITION_MANAGER, \
1059+
(COND_CODE_1(FIXED_PARTITION_EXISTS(littlefs_storage), \
1060+
(FIXED_PARTITION_ID(littlefs_storage)), \
1061+
(FIXED_PARTITION_ID(storage)))), \
1062+
(DT_FIXED_PARTITION_ID(FS_PARTITION(inst)))), \
10581063
.flags = FSTAB_ENTRY_DT_MOUNT_FLAGS(DT_DRV_INST(inst)), \
10591064
};
10601065

subsys/ipc/rpmsg_service/rpmsg_backend.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,35 @@
1313
extern "C" {
1414
#endif
1515

16+
#if CONFIG_PARTITION_MANAGER_ENABLED
17+
18+
#include "pm_config.h"
19+
20+
#if defined(PM_RPMSG_NRF53_SRAM_ADDRESS) || defined(PM__RPMSG_NRF53_SRAM_ADDRESS)
21+
22+
#if defined(PM_RPMSG_NRF53_SRAM_ADDRESS)
23+
#define VDEV_START_ADDR PM_RPMSG_NRF53_SRAM_ADDRESS
24+
#define VDEV_SIZE PM_RPMSG_NRF53_SRAM_SIZE
25+
#else
26+
/* The current image is a child image in a different domain than the image
27+
* which defined the required values. To reach the values of the parent domain
28+
* we use the 'PM__' variant of the define.
29+
*/
30+
#define VDEV_START_ADDR PM__RPMSG_NRF53_SRAM_ADDRESS
31+
#define VDEV_SIZE PM__RPMSG_NRF53_SRAM_SIZE
32+
#endif /* defined(PM_RPMSG_NRF53_SRAM_ADDRESS) */
33+
34+
#else
1635
#define VDEV_START_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ipc_shm))
1736
#define VDEV_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ipc_shm))
37+
#endif /* defined(PM_RPMSG_NRF53_SRAM_ADDRESS) || defined(PM__RPMSG_NRF53_SRAM_ADDRESS) */
38+
39+
#else
40+
41+
#define VDEV_START_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ipc_shm))
42+
#define VDEV_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ipc_shm))
43+
44+
#endif /* CONFIG_PARTITION_MANAGER_ENABLED */
1845

1946
#define VDEV_STATUS_ADDR VDEV_START_ADDR
2047
#define VDEV_STATUS_SIZE 0x400

0 commit comments

Comments
 (0)