Skip to content

Commit 80e20b7

Browse files
sigvartmhnordicjm
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> Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no> (cherry picked from commit a8cb6e2)
1 parent 55ea8a5 commit 80e20b7

13 files changed

Lines changed: 181 additions & 2 deletions

File tree

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/mpu/arm_mpu_mem_cfg.h>
11+
#if USE_PARTITION_MANAGER
12+
#include <pm_config.h>
13+
#endif
1114

1215
#ifdef CONFIG_ARM_MPU_SRAM_WRITE_THROUGH
1316
#define ARM_MPU_SRAM_REGION_ATTR REGION_RAM_WT_ATTR
@@ -38,13 +41,23 @@ static const struct arm_mpu_region mpu_regions[] = {
3841

3942
/* Region 1 */
4043
MPU_REGION_ENTRY("SRAM_0",
44+
#if USE_PARTITION_MANAGER
45+
PM_SRAM_ADDRESS,
46+
#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE)
47+
REGION_RAM_ATTR(PM_SRAM_ADDRESS, PM_SRAM_SIZE)),
48+
#else
49+
REGION_RAM_ATTR(REGION_SRAM_SIZE)),
50+
#endif
51+
#else
4152
RAM_BASE,
4253
#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE)
4354
ARM_MPU_SRAM_REGION_ATTR(RAM_BASE,
4455
RAM_SIZE)),
4556
#else
4657
ARM_MPU_SRAM_REGION_ATTR(REGION_SRAM_SIZE)),
4758
#endif
59+
60+
#endif /* USE_PARTITION_MANAGER */
4861
};
4962

5063
const struct arm_mpu_config mpu_config = {

cmake/linker/ld/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
8080
${current_includes}
8181
${soc_linker_script_includes}
8282
${template_script_defines}
83+
-DUSE_PARTITION_MANAGER=$<BOOL:${CONFIG_PARTITION_MANAGER_ENABLED}>
8384
-E ${LINKER_SCRIPT}
8485
-P # Prevent generation of debug `#line' directives.
8586
-o ${linker_script_gen}

cmake/linker/lld/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
5252
-imacros ${AUTOCONF_H}
5353
${current_includes}
5454
${template_script_defines}
55+
-DUSE_PARTITION_MANAGER=$<BOOL:${CONFIG_PARTITION_MANAGER_ENABLED}>
5556
-E ${LINKER_SCRIPT}
5657
-P # Prevent generation of debug `#line' directives.
5758
-o ${linker_script_gen}

cmake/modules/kernel.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,7 @@ if("${CMAKE_EXTRA_GENERATOR}" STREQUAL "Eclipse CDT4")
257257
include(${ZEPHYR_BASE}/cmake/ide/eclipse_cdt4_generator_amendment.cmake)
258258
eclipse_cdt4_generator_amendment(1)
259259
endif()
260+
261+
if(ZEPHYR_NRF_MODULE_DIR)
262+
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/partition_manager.cmake)
263+
endif()

drivers/flash/soc_flash_nrf.c

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

3737
#define SOC_NV_FLASH_NODE DT_INST(0, soc_nv_flash)
3838

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

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

170181
return 0;

drivers/flash/soc_flash_nrf_rram.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ LOG_MODULE_REGISTER(flash_nrf_rram, CONFIG_FLASH_LOG_LEVEL);
5454
#define WRITE_BLOCK_SIZE_FROM_DT DT_PROP(RRAM, write_block_size)
5555
#define ERASE_VALUE 0xFF
5656

57+
#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER
58+
#include <soc_secure.h>
59+
#include <pm_config.h>
60+
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER */
61+
5762
#ifdef CONFIG_MULTITHREADING
5863
static struct k_sem sem_lock;
5964
#define SYNC_INIT() k_sem_init(&sem_lock, 1, 1)
@@ -292,6 +297,12 @@ static int nrf_rram_read(const struct device *dev, off_t addr, void *data, size_
292297
}
293298
addr += RRAM_START;
294299

300+
#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER && PM_APP_ADDRESS
301+
if (addr < PM_APP_ADDRESS) {
302+
return soc_secure_mem_read(data, (void *)addr, len);
303+
}
304+
#endif
305+
295306
memcpy(data, (void *)addr, len);
296307

297308
return 0;

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,39 @@
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+
#if defined(CONFIG_PM_USE_CONFIG_SRAM_SIZE)
62+
#define RAM_SIZE CONFIG_PM_SRAM_SIZE
63+
#else
64+
#define RAM_SIZE PM_SRAM_SIZE
65+
#endif
66+
#define RAM_ADDR PM_SRAM_ADDRESS
67+
68+
#else /* ! USE_PARTITION_MANAGER */
69+
3770
#if defined(CONFIG_ROM_END_OFFSET)
3871
#define ROM_END_OFFSET CONFIG_ROM_END_OFFSET
3972
#else
@@ -65,6 +98,23 @@
6598
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
6699
#endif /* !defined(CONFIG_SRAM_DEPRECATED_KCONFIG_SET) */
67100

101+
#endif /* USE_PARTITION_MANAGER */
102+
103+
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay)
104+
#define CCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ccm))
105+
#define CCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ccm))
106+
#endif
107+
108+
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
109+
#define ITCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_itcm))
110+
#define ITCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_itcm))
111+
#endif
112+
113+
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay)
114+
#define DTCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_dtcm))
115+
#define DTCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_dtcm))
116+
#endif
117+
68118
#if defined(CONFIG_CUSTOM_SECTION_ALIGN)
69119
_region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE;
70120
#else

include/zephyr/storage/flash_map.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ const char *flash_area_label(const struct flash_area *fa);
351351
*/
352352
uint8_t flash_area_erased_val(const struct flash_area *fa);
353353

354+
#if USE_PARTITION_MANAGER
355+
#include <flash_map_pm.h>
356+
#else
357+
354358
/**
355359
* Returns non-0 value if partition of given DTS node label exists.
356360
*
@@ -620,6 +624,8 @@ DT_FOREACH_STATUS_OKAY(fixed_subpartitions, FOR_EACH_SUBPARTITION_TABLE)
620624
#undef FOR_EACH_SUBPARTITION_TABLE
621625
/** @endcond */
622626

627+
#endif /* USE_PARTITION_MANAGER */
628+
623629
#ifdef __cplusplus
624630
}
625631
#endif

lib/heap/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ choice
164164
prompt "Supported heap sizes"
165165
depends on !64BIT
166166
default SYS_HEAP_SMALL_ONLY if ((SRAM_DEPRECATED_KCONFIG_SET && SRAM_SIZE <= 256) || \
167-
(!SRAM_DEPRECATED_KCONFIG_SET && DT_SRAM_SIZE <= 256))
167+
(!SRAM_DEPRECATED_KCONFIG_SET && DT_SRAM_SIZE <= 256)) !PARTITION_MANAGER_ENABLED
168168
default SYS_HEAP_AUTO
169169
help
170170
Heaps using reduced-size chunk headers can accommodate so called

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
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 */
2836
#ifdef CONFIG_SRAM_DEPRECATED_KCONFIG_SET
2937
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
3038
#define RAM_SIZE KB(CONFIG_SRAM_SIZE)
@@ -33,6 +41,8 @@ LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
3341
#define RAM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_sram))
3442
#endif
3543

44+
#endif /* USE_PARTITION_MANAGER */
45+
3646
#ifdef CONFIG_COMMON_LIBC_MALLOC
3747

3848
#if (CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE != 0)

0 commit comments

Comments
 (0)