Skip to content

Commit edefd60

Browse files
sigvartmhjukkar
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 <[email protected]> Signed-off-by: Andrzej Puzdrowski <[email protected]> Signed-off-by: Håkon Øye Amundsen <[email protected]> Signed-off-by: Ioannis Glaropoulos <[email protected]> Signed-off-by: Joakim Andersson <[email protected]> Signed-off-by: Johann Fischer <[email protected]> Signed-off-by: Martí Bolívar <[email protected]> Signed-off-by: Ole Sæther <[email protected]> Signed-off-by: Robert Lubos <[email protected]> Signed-off-by: Sebastian Bøe <[email protected]> Signed-off-by: Sigvart Hovland <[email protected]> Signed-off-by: Thomas Stenersen <[email protected]> Signed-off-by: Torsten Rasmussen <[email protected]> Signed-off-by: Øyvind Rønningstad <[email protected]> Signed-off-by: Trond Einar Snekvik <[email protected]> Signed-off-by: Gerard Marull-Paretas <[email protected]> Signed-off-by: Tomasz Moń <[email protected]> Signed-off-by: Dominik Ermel <[email protected]> Signed-off-by: Jamie McCrae <[email protected]> (cherry picked from commit 5c2eecf)
1 parent 3ffc2b9 commit edefd60

File tree

13 files changed

+187
-4
lines changed

13 files changed

+187
-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
#ifdef CONFIG_XIP
@@ -24,13 +27,23 @@ static const struct arm_mpu_region mpu_regions[] = {
2427

2528
/* Region 1 */
2629
MPU_REGION_ENTRY("SRAM_0",
30+
#if USE_PARTITION_MANAGER
31+
PM_SRAM_ADDRESS,
32+
#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE)
33+
REGION_RAM_ATTR(PM_SRAM_ADDRESS, PM_SRAM_SIZE)),
34+
#else
35+
REGION_RAM_ATTR(REGION_SRAM_SIZE)),
36+
#endif
37+
#else
2738
CONFIG_SRAM_BASE_ADDRESS,
2839
#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE)
2940
REGION_RAM_ATTR(CONFIG_SRAM_BASE_ADDRESS, \
3041
CONFIG_SRAM_SIZE * 1024)),
3142
#else
3243
REGION_RAM_ATTR(REGION_SRAM_SIZE)),
3344
#endif
45+
46+
#endif /* USE_PARTITION_MANAGER */
3447
};
3548

3649
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
@@ -256,3 +256,7 @@ if("${CMAKE_EXTRA_GENERATOR}" STREQUAL "Eclipse CDT4")
256256
include(${ZEPHYR_BASE}/cmake/ide/eclipse_cdt4_generator_amendment.cmake)
257257
eclipse_cdt4_generator_amendment(1)
258258
endif()
259+
260+
if(ZEPHYR_NRF_MODULE_DIR)
261+
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/partition_manager.cmake)
262+
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;

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)
@@ -279,6 +284,12 @@ static int nrf_rram_read(const struct device *dev, off_t addr, void *data, size_
279284
}
280285
addr += RRAM_START;
281286

287+
#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER && PM_APP_ADDRESS
288+
if (addr < PM_APP_ADDRESS) {
289+
return soc_secure_mem_read(data, (void *)addr, len);
290+
}
291+
#endif
292+
282293
memcpy(data, (void *)addr, len);
283294

284295
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_XIP) && (CONFIG_FLASH_SIZE == 0)
3871
#define ROM_ADDR RAM_ADDR
3972
#else
@@ -55,6 +88,23 @@
5588
#define RAM_SIZE (CONFIG_SRAM_SIZE * 1K)
5689
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
5790

91+
#endif /* USE_PARTITION_MANAGER */
92+
93+
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay)
94+
#define CCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ccm))
95+
#define CCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ccm))
96+
#endif
97+
98+
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
99+
#define ITCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_itcm))
100+
#define ITCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_itcm))
101+
#endif
102+
103+
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay)
104+
#define DTCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_dtcm))
105+
#define DTCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_dtcm))
106+
#endif
107+
58108
#if defined(CONFIG_CUSTOM_SECTION_ALIGN)
59109
_region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE;
60110
#else

include/zephyr/storage/flash_map.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ const char *flash_area_label(const struct flash_area *fa);
348348
*/
349349
uint8_t flash_area_erased_val(const struct flash_area *fa);
350350

351+
#if USE_PARTITION_MANAGER
352+
#include <flash_map_pm.h>
353+
#else
354+
351355
/**
352356
* Returns non-0 value if fixed-partition of given DTS node label exists.
353357
*
@@ -469,6 +473,8 @@ DT_FOREACH_STATUS_OKAY(fixed_partitions, FOR_EACH_PARTITION_TABLE)
469473
#undef FOR_EACH_PARTITION_TABLE
470474
/** @endcond */
471475

476+
#endif /* USE_PARTITION_MANAGER */
477+
472478
#ifdef __cplusplus
473479
}
474480
#endif

lib/heap/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ config HEAP_LISTENER
8181
choice
8282
prompt "Supported heap sizes"
8383
depends on !64BIT
84-
default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256)
84+
default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256) && !PARTITION_MANAGER_ENABLED
8585
default SYS_HEAP_AUTO
8686
help
8787
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 */

0 commit comments

Comments
 (0)