Skip to content

Commit 5485a44

Browse files
sigvartmhmbolivar-nordic
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'. Refer to the NCS documentation page for this feature for more details. Signed-off-by: Håkon Øye Amundsen <[email protected]> Signed-off-by: Øyvind Rønningstad <[email protected]> Signed-off-by: Sigvart Hovland <[email protected]> Signed-off-by: Sebastian Bøe <[email protected]> Signed-off-by: Andrzej Puzdrowski <[email protected]> Signed-off-by: Robert Lubos <[email protected]> Signed-off-by: Dominik Ermel <[email protected]> Signed-off-by: Torsten Rasmussen <[email protected]> Signed-off-by: Martí Bolívar <[email protected]> Signed-off-by: Thomas Stenersen <[email protected]> Signed-off-by: Andrzej Głąbek <[email protected]> Signed-off-by: Joakim Andersson <[email protected]> (cherry picked from commit 1fb3734, with conflicts resolved in Kconfig.zephyr to account for the TEXT_SECTION_OFFSET rename) (cherry picked from commit f4aa2ea)
1 parent 6e10efa commit 5485a44

File tree

9 files changed

+109
-5
lines changed

9 files changed

+109
-5
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,10 @@ set(logical_target_for_zephyr_elf ${logical_target_for_zephyr_elf} PARENT_SCOPE)
10991099
# 2. it can be defined in Kconfig
11001100
set_target_properties(${logical_target_for_zephyr_elf} PROPERTIES OUTPUT_NAME ${KERNEL_NAME})
11011101

1102+
if (ZEPHYR_NRF_MODULE_DIR)
1103+
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/s1.cmake)
1104+
endif()
1105+
11021106
set(post_build_commands "")
11031107
set(post_build_byproducts "")
11041108

Kconfig.zephyr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ config FLASH_LOAD_SIZE
119119
endif # HAS_FLASH_LOAD_OFFSET
120120

121121
config ROM_START_OFFSET
122-
hex
123-
prompt "ROM start offset" if !BOOTLOADER_MCUBOOT
124-
default 0x200 if BOOTLOADER_MCUBOOT
122+
hex "ROM start offset"
125123
default 0
126124
help
127125
If the application is built for chain-loading by a bootloader this

cmake/app/boilerplate.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@ set_property(TARGET app PROPERTY ARCHIVE_OUTPUT_DIRECTORY app)
595595

596596
add_subdirectory(${ZEPHYR_BASE} ${__build_dir})
597597

598+
if(ZEPHYR_NRF_MODULE_DIR)
599+
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/partition_manager.cmake)
600+
endif()
601+
598602
# Link 'app' with the Zephyr interface libraries.
599603
#
600604
# NB: This must be done in boilerplate.cmake because 'app' can only be

drivers/flash/soc_flash_nrf.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030

3131
#define SOC_NV_FLASH_NODE DT_INST(0, soc_nv_flash)
3232

33+
#if CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM
34+
#include <secure_services.h>
35+
#if USE_PARTITION_MANAGER
36+
#include <pm_config.h>
37+
#endif /* USE_PARTITION_MANAGER */
38+
#endif /* CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM */
39+
3340
#if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC)
3441
#include <sys/__assert.h>
3542
#include <bluetooth/hci.h>
@@ -185,6 +192,12 @@ static int flash_nrf_read(struct device *dev, off_t addr,
185192
return 0;
186193
}
187194

195+
#if CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM && USE_PARTITION_MANAGER
196+
if (addr < PM_APP_ADDRESS) {
197+
return spm_request_read(data, addr, len);
198+
}
199+
#endif
200+
188201
memcpy(data, (void *)addr, len);
189202

190203
return 0;

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@
3333
#define _DATA_IN_ROM
3434
#endif
3535

36+
#if USE_PARTITION_MANAGER
37+
#include <pm_config.h>
38+
39+
#ifdef LINK_INTO_s1
40+
/* We are linking against S1, create symbol containing the flash ID of S0.
41+
* This is used when writing code operating on the "other" slot.
42+
*/
43+
_image_1_primary_slot_id = PM_S0_ID;
44+
45+
#define ROM_ADDR PM_ADDRESS + PM_S1_ADDRESS - PM_S0_ADDRESS
46+
47+
#else /* ! LINK_INTO_s1 */
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+
#define ROM_ADDR PM_ADDRESS
57+
#endif /* LINK_MCUBOOT_INTO_s1 */
58+
#define ROM_SIZE PM_SIZE
59+
#else
60+
3661
#if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0)
3762
#define ROM_ADDR RAM_ADDR
3863
#else
@@ -49,8 +74,9 @@
4974
#define ROM_SIZE CONFIG_FLASH_LOAD_SIZE
5075
#else
5176
#define ROM_SIZE (CONFIG_FLASH_SIZE*1K - CONFIG_FLASH_LOAD_OFFSET)
52-
#endif
53-
#endif
77+
#endif /* CONFIG_FLASH_LOAD_SIZE > 0 */
78+
#endif /* CONFIG_HAS_TI_CCFG */
79+
#endif /* USE_PARTITION_MANAGER */
5480

5581
#if defined(CONFIG_XIP)
5682
#if defined(CONFIG_IS_BOOTLOADER)

include/storage/flash_map.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ int flash_area_has_driver(const struct flash_area *fa);
209209
*/
210210
struct device *flash_area_get_device(const struct flash_area *fa);
211211

212+
#if USE_PARTITION_MANAGER
213+
#include <flash_map_pm.h>
214+
#else
215+
212216
#define FLASH_AREA_LABEL_EXISTS(label) \
213217
DT_HAS_FIXED_PARTITION_LABEL(label)
214218

@@ -221,6 +225,8 @@ struct device *flash_area_get_device(const struct flash_area *fa);
221225
#define FLASH_AREA_SIZE(label) \
222226
DT_REG_SIZE(DT_NODE_BY_FIXED_PARTITION_LABEL(label))
223227

228+
#endif /* USE_PARTITION_MANAGER */
229+
224230
#ifdef __cplusplus
225231
}
226232
#endif

subsys/dfu/boot/mcuboot.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ struct mcuboot_v1_raw_header {
7272
#define FLASH_MIN_WRITE_SIZE \
7373
DT_PROP(DT_CHOSEN(zephyr_flash), write_block_size)
7474

75+
#if USE_PARTITION_MANAGER
76+
#include <pm_config.h>
77+
78+
#define FLASH_AREA_IMAGE_PRIMARY PM_MCUBOOT_PRIMARY_ID
79+
#define FLASH_AREA_IMAGE_SECONDARY PM_MCUBOOT_SECONDARY_ID
80+
#ifdef PM_MCUBOOT_SCRATCH_ID
81+
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID
82+
#endif
83+
84+
#else
85+
7586
/* FLASH_AREA_ID() values used below are auto-generated by DT */
7687
#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE
7788
#define FLASH_AREA_IMAGE_PRIMARY FLASH_AREA_ID(image_0_nonsecure)
@@ -85,6 +96,8 @@ struct mcuboot_v1_raw_header {
8596
#define FLASH_AREA_IMAGE_SCRATCH FLASH_AREA_ID(image_scratch)
8697
#endif
8798

99+
#endif /* USE_PARTITION_MANAGER */
100+
88101
#ifdef CONFIG_MCUBOOT_TRAILER_SWAP_TYPE
89102
#define SWAP_TYPE_OFFS(bank_area) ((bank_area)->fa_size -\
90103
BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 3)

subsys/dfu/img_util/flash_img.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@
1717
#endif
1818

1919
#include <devicetree.h>
20+
21+
#if USE_PARTITION_MANAGER
22+
23+
#include <pm_config.h>
24+
#define FLASH_AREA_IMAGE_SECONDARY PM_MCUBOOT_SECONDARY_ID
25+
#else
26+
2027
/* FLASH_AREA_ID() values used below are auto-generated by DT */
2128
#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE
2229
#define FLASH_AREA_IMAGE_SECONDARY FLASH_AREA_ID(image_1_nonsecure)
2330
#else
2431
#define FLASH_AREA_IMAGE_SECONDARY FLASH_AREA_ID(image_1)
2532
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE */
2633

34+
#endif /* USE_PARTITION_MANAGER */
35+
2736
#define FLASH_WRITE_BLOCK_SIZE \
2837
DT_PROP(DT_CHOSEN(zephyr_flash), write_block_size)
2938

subsys/storage/flash_map/flash_map_default.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@
1010
#include <zephyr.h>
1111
#include <storage/flash_map.h>
1212

13+
#if USE_PARTITION_MANAGER
14+
15+
/**
16+
* Have flash_map_default use Partition Manager information instead of
17+
* DeviceTree information when we are using the Partition Manager.
18+
*/
19+
20+
#include <pm_config.h>
21+
#include <sys/util.h>
22+
23+
#define FLASH_MAP_OFFSET(i) UTIL_CAT(PM_, UTIL_CAT(PM_##i##_LABEL, _ADDRESS))
24+
#define FLASH_MAP_DEV(i) UTIL_CAT(PM_, UTIL_CAT(PM_##i##_LABEL, _DEV_NAME))
25+
#define FLASH_MAP_SIZE(i) UTIL_CAT(PM_, UTIL_CAT(PM_##i##_LABEL, _SIZE))
26+
#define FLASH_MAP_NUM PM_NUM
27+
28+
#define FLASH_AREA_FOO(i, _) \
29+
{ \
30+
.fa_id = i, \
31+
.fa_off = FLASH_MAP_OFFSET(i), \
32+
.fa_dev_name = FLASH_MAP_DEV(i), \
33+
.fa_size = FLASH_MAP_SIZE(i) \
34+
},
35+
36+
const struct flash_area default_flash_map[] = {
37+
UTIL_LISTIFY(FLASH_MAP_NUM, FLASH_AREA_FOO, ~)
38+
};
39+
40+
#else
41+
1342
/* Get the grand parent of a node */
1443
#define GPARENT(node_id) DT_PARENT(DT_PARENT(node_id))
1544

@@ -50,5 +79,7 @@ const struct flash_area default_flash_map[] = {
5079
DT_INST_FOREACH_STATUS_OKAY(FOREACH_PARTION)
5180
};
5281

82+
#endif /* USE_PARTITION_MANAGER */
83+
5384
const int flash_map_entries = ARRAY_SIZE(default_flash_map);
5485
const struct flash_area *flash_map = default_flash_map;

0 commit comments

Comments
 (0)