Skip to content

Commit 3dacf91

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]> (cherry picked from commit 6bff2a9) Signed-off-by: Andrzej Głąbek <[email protected]> (cherry picked from commit 2ce2dd9) Signed-off-by: Robert Lubos <[email protected]> (cherry picked from commit 4ac07a9) (cherry picked from commit 48475c6) (cherry picked from commit 155cf11) (cherry picked from commit 634d8d6) (cherry picked from commit 5282bae)
1 parent 474388f commit 3dacf91

File tree

22 files changed

+194
-63
lines changed

22 files changed

+194
-63
lines changed

CMakeLists.txt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,30 +1470,6 @@ add_custom_command(
14701470
# NB: COMMENT only works for some CMake-Generators
14711471
)
14721472

1473-
# To populate with hex files to merge, do the following:
1474-
# set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE ${my_local_list})
1475-
# Note that the zephyr.hex file will not be included automatically.
1476-
get_property(HEX_FILES_TO_MERGE GLOBAL PROPERTY HEX_FILES_TO_MERGE)
1477-
if(HEX_FILES_TO_MERGE)
1478-
# Merge in out-of-tree hex files.
1479-
set(MERGED_HEX_NAME merged.hex)
1480-
1481-
add_custom_command(
1482-
OUTPUT ${MERGED_HEX_NAME}
1483-
COMMAND
1484-
${PYTHON_EXECUTABLE}
1485-
${ZEPHYR_BASE}/scripts/mergehex.py
1486-
-o ${MERGED_HEX_NAME}
1487-
${HEX_FILES_TO_MERGE}
1488-
DEPENDS ${HEX_FILES_TO_MERGE} ${logical_target_for_zephyr_elf}
1489-
)
1490-
1491-
add_custom_target(mergehex ALL DEPENDS ${MERGED_HEX_NAME})
1492-
list(APPEND FLASH_DEPS mergehex)
1493-
1494-
message(VERBOSE "Merging hex files: ${HEX_FILES_TO_MERGE}")
1495-
endif()
1496-
14971473
if(EMU_PLATFORM)
14981474
include(${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake)
14991475
else()

Kconfig.zephyr

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

133133
config TEXT_SECTION_OFFSET
134-
hex
135-
prompt "TEXT section offset" if !BOOTLOADER_MCUBOOT
136-
default 0x200 if BOOTLOADER_MCUBOOT
134+
hex "TEXT section offset"
137135
default 0
138136
help
139137
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
@@ -540,6 +540,10 @@ set_property(TARGET app PROPERTY ARCHIVE_OUTPUT_DIRECTORY app)
540540

541541
add_subdirectory(${ZEPHYR_BASE} ${__build_dir})
542542

543+
include(${ZEPHYR_BASE}/../nrf/cmake/partition_manager.cmake
544+
OPTIONAL
545+
)
546+
543547
# Link 'app' with the Zephyr interface libraries.
544548
#
545549
# NB: This must be done in boilerplate.cmake because 'app' can only be

cmake/extensions.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,3 +1578,17 @@ function(generate_unique_target_name_from_filename filename target_name)
15781578

15791579
set(${target_name} gen_${x}_${unique_chars} PARENT_SCOPE)
15801580
endfunction()
1581+
1582+
# Usage:
1583+
# add_partition_manager_config(pm.yml)
1584+
#
1585+
# Will add all configurations defined in pm.yml to the global list of partition
1586+
# manager configurations.
1587+
function(add_partition_manager_config config_file)
1588+
get_filename_component(pm_path ${config_file} REALPATH)
1589+
set_property(
1590+
GLOBAL APPEND PROPERTY
1591+
PM_SUBSYS
1592+
${pm_path}
1593+
)
1594+
endfunction()

cmake/flash/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,8 @@ if(RUNNERS)
2828
CACHE STRING "Board definition directory" FORCE)
2929
set(ZEPHYR_RUNNER_CONFIG_KERNEL_ELF "${PROJECT_BINARY_DIR}/${KERNEL_ELF_NAME}"
3030
CACHE STRING "Path to kernel image in ELF format" FORCE)
31-
get_property(HEX_FILES_TO_MERGE GLOBAL PROPERTY HEX_FILES_TO_MERGE)
32-
if(HEX_FILES_TO_MERGE)
33-
set(ZEPHYR_RUNNER_CONFIG_KERNEL_HEX "${PROJECT_BINARY_DIR}/${MERGED_HEX_NAME}"
34-
CACHE STRING "Path to merged image in Intel Hex format" FORCE)
35-
else()
36-
set(ZEPHYR_RUNNER_CONFIG_KERNEL_HEX "${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}"
37-
CACHE STRING "Path to kernel image in Intel Hex format" FORCE)
38-
endif()
31+
set(ZEPHYR_RUNNER_CONFIG_KERNEL_HEX "${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}"
32+
CACHE STRING "Path to kernel image in Intel Hex format" FORCE)
3933
set(ZEPHYR_RUNNER_CONFIG_KERNEL_BIN "${PROJECT_BINARY_DIR}/${KERNEL_BIN_NAME}"
4034
CACHE STRING "Path to kernel image as raw binary" FORCE)
4135
# Not always applicable, but so often needed that they're provided

cmake/reports/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ foreach(report ram_report rom_report)
1717
$<TARGET_PROPERTY:zephyr_property_target,${report}_DEPENDENCIES>
1818
)
1919
endforeach()
20+
21+
add_custom_command(
22+
TARGET rom_report
23+
POST_BUILD
24+
COMMAND
25+
${PYTHON_EXECUTABLE}
26+
${ZEPHYR_BASE}/../nrf/scripts/partition_manager_report.py
27+
--input ${CMAKE_BINARY_DIR}/partitions.yml
28+
"$<$<NOT:$<TARGET_EXISTS:partition_manager>>:--quiet>"
29+
)

doc/application/index.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,19 +1150,6 @@ Below is a simple example :file:`CMakeList.txt`:
11501150
11511151
target_sources(app PRIVATE src/main.c)
11521152
1153-
The Cmake property ``HEX_FILES_TO_MERGE``
1154-
leverages the application configuration provided by
1155-
Kconfig and CMake to let you merge externally built hex files
1156-
with the hex file generated when building the Zephyr application.
1157-
For example:
1158-
1159-
.. code-block:: cmake
1160-
1161-
set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE
1162-
${app_bootloader_hex}
1163-
${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}
1164-
${app_provision_hex})
1165-
11661153
CMakeCache.txt
11671154
==============
11681155

drivers/flash/soc_flash_nrf.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
#include <string.h>
1717
#include <nrfx_nvmc.h>
1818

19+
#if CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM
20+
#include <secure_services.h>
21+
#if USE_PARTITION_MANAGER
22+
#include <pm_config.h>
23+
#endif /* USE_PARTITION_MANAGER */
24+
#endif /* CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM */
25+
1926
#if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC)
2027
#include <sys/__assert.h>
2128
#include <bluetooth/hci.h>
@@ -137,6 +144,12 @@ static int flash_nrf_read(struct device *dev, off_t addr,
137144
return 0;
138145
}
139146

147+
#if CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM && USE_PARTITION_MANAGER
148+
if (addr < PM_APP_ADDRESS) {
149+
return spm_request_read(data, addr, len);
150+
}
151+
#endif
152+
140153
memcpy(data, (void *)addr, len);
141154

142155
return 0;

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

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

36+
#if USE_PARTITION_MANAGER
37+
#include <pm_config.h>
38+
#define ROM_ADDR PM_ADDRESS
39+
#define ROM_SIZE PM_SIZE
40+
#else
41+
3642
#if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0)
3743
#define ROM_ADDR RAM_ADDR
3844
#else
@@ -49,8 +55,9 @@
4955
#define ROM_SIZE CONFIG_FLASH_LOAD_SIZE
5056
#else
5157
#define ROM_SIZE (CONFIG_FLASH_SIZE*1K - CONFIG_FLASH_LOAD_OFFSET)
52-
#endif
53-
#endif
58+
#endif /* CONFIG_FLASH_LOAD_SIZE > 0 */
59+
#endif /* CONFIG_HAS_TI_CCFG */
60+
#endif /* USE_PARTITION_MANAGER */
5461

5562
#if defined(CONFIG_XIP)
5663
#if defined(CONFIG_IS_BOOTLOADER)

samples/subsys/mgmt/mcumgr/smp_svr/src/main.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
#include <mgmt/smp_bt.h>
3535
#endif
3636

37+
#if USE_PARTITION_MANAGER
38+
39+
#include <pm_config.h>
40+
#define FLASH_AREA_STORAGE_ID PM_LITTLEFS_STORAGE_ID
41+
42+
#else
43+
44+
#include <devicetree.h>
45+
#define FLASH_AREA_STORAGE_ID DT_FLASH_AREA_STORAGE_ID
46+
47+
#endif /* USE_PARTITION_MANAGER */
48+
3749
/* Define an example stats group; approximates seconds since boot. */
3850
STATS_SECT_START(smp_svr_stats)
3951
STATS_SECT_ENTRY(ticks)
@@ -52,7 +64,7 @@ FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);
5264
static struct fs_mount_t littlefs_mnt = {
5365
.type = FS_LITTLEFS,
5466
.fs_data = &cstorage,
55-
.storage_dev = (void *)DT_FLASH_AREA_STORAGE_ID,
67+
.storage_dev = (void *)FLASH_AREA_STORAGE_ID,
5668
.mnt_point = "/lfs"
5769
};
5870
#endif

subsys/dfu/boot/mcuboot.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ struct mcuboot_v1_raw_header {
7171

7272
#define FLASH_MIN_WRITE_SIZE DT_FLASH_WRITE_BLOCK_SIZE
7373

74+
#if USE_PARTITION_MANAGER
75+
#include <pm_config.h>
76+
77+
#define FLASH_AREA_IMAGE_PRIMARY PM_MCUBOOT_PRIMARY_ID
78+
#define FLASH_AREA_IMAGE_SECONDARY PM_MCUBOOT_SECONDARY_ID
79+
#ifdef PM_MCUBOOT_SCRATCH_ID
80+
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID
81+
#endif
82+
83+
#else
84+
85+
#include <devicetree.h>
86+
7487
/* DT_FLASH_AREA_IMAGE_XX_YY values used below are auto-generated by DT */
7588
#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE
7689
#define FLASH_AREA_IMAGE_PRIMARY DT_FLASH_AREA_IMAGE_0_NONSECURE_ID
@@ -83,6 +96,7 @@ struct mcuboot_v1_raw_header {
8396
#ifdef DT_FLASH_AREA_IMAGE_SCRATCH_ID
8497
#define FLASH_AREA_IMAGE_SCRATCH DT_FLASH_AREA_IMAGE_SCRATCH_ID
8598
#endif
99+
#endif /* USE_PARTITION_MANAGER */
86100

87101
#ifdef CONFIG_MCUBOOT_TRAILER_SWAP_TYPE
88102
#define SWAP_TYPE_OFFS(bank_area) ((bank_area)->fa_size -\

subsys/dfu/img_util/flash_img.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
2424
#endif
2525

2626
#include <devicetree.h>
27+
28+
#if USE_PARTITION_MANAGER
29+
#include <pm_config.h>
30+
#define FLASH_AREA_IMAGE_SECONDARY PM_MCUBOOT_SECONDARY_ID
31+
#else
2732
/* DT_FLASH_AREA_IMAGE_XX_YY values used below are auto-generated by DT */
2833
#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE
2934
#define FLASH_AREA_IMAGE_SECONDARY DT_FLASH_AREA_IMAGE_1_NONSECURE_ID
3035
#else
3136
#define FLASH_AREA_IMAGE_SECONDARY DT_FLASH_AREA_IMAGE_1_ID
3237
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE */
38+
#endif /* USE_PARTITION_MANAGER */
3339

3440
BUILD_ASSERT_MSG((CONFIG_IMG_BLOCK_BUF_SIZE % DT_FLASH_WRITE_BLOCK_SIZE == 0),
3541
"CONFIG_IMG_BLOCK_BUF_SIZE is not a multiple of "

subsys/fs/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ if(CONFIG_FILE_SYSTEM)
1414

1515
target_link_libraries_ifdef(CONFIG_FAT_FILESYSTEM_ELM FS INTERFACE ELMFAT)
1616
target_link_libraries_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS FS INTERFACE LITTLEFS)
17+
18+
add_partition_manager_config(pm.yml)
1719
endif()
1820

1921
add_subdirectory_ifdef(CONFIG_FCB ./fcb)

subsys/fs/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ config FILE_SYSTEM_LITTLEFS
3535
help
3636
Enables LittleFS file system support.
3737

38+
# This config must be compatible with
39+
# nrf/subsys/partition_manager/Kconfig.template.partition_size
40+
config PM_PARTITION_SIZE_LITTLEFS
41+
hex "Flash space reserved for LittleFS storage partition"
42+
default 0x6000
43+
help
44+
Flash space set aside for the LittleFS storage partition.
45+
3846
config FILE_SYSTEM_SHELL
3947
bool "Enable file system shell"
4048
depends on SHELL

subsys/fs/pm.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <autoconf.h>
2+
3+
#ifdef CONFIG_FILE_SYSTEM_LITTLEFS
4+
littlefs_storage:
5+
placement: {after: [mcuboot_storage, app]}
6+
size: CONFIG_PM_PARTITION_SIZE_LITTLEFS
7+
#endif

subsys/settings/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ add_subdirectory(src)
44
zephyr_include_directories(
55
include
66
)
7+
8+
if (CONFIG_SETTINGS_FCB OR CONFIG_SETTINGS_NVS)
9+
# These settings backends require a partition in flash
10+
add_partition_manager_config(pm.yml)
11+
endif()

subsys/settings/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ if SETTINGS
1313
module = SETTINGS
1414
module-str = settings
1515
source "subsys/logging/Kconfig.template.log_config"
16+
17+
# This config must be compatible with
18+
# nrf/subsys/partition_manager/Kconfig.template.partition_size
19+
config PM_PARTITION_SIZE_SETTINGS_STORAGE
20+
hex "Flash space reserved for settings storage partition"
21+
default 0x2000
22+
help
23+
Flash space set aside for the settings storage partition.
1624
endif
1725

1826
config SETTINGS_RUNTIME

subsys/settings/pm.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <autoconf.h>
2+
3+
settings_storage:
4+
placement: {after: [mcuboot_storage, app]}
5+
size: CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE

subsys/settings/src/settings_fcb.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
#include "settings/settings_fcb.h"
1616
#include "settings_priv.h"
1717

18+
#if USE_PARTITION_MANAGER
19+
20+
#include <pm_config.h>
21+
#define FLASH_AREA_STORAGE_ID PM_SETTINGS_STORAGE_ID
22+
23+
#else
24+
25+
#include <devicetree.h>
26+
#define FLASH_AREA_STORAGE_ID DT_FLASH_AREA_STORAGE_ID
27+
28+
#endif /* USE_PARTITION_MANAGER */
29+
1830
#include <logging/log.h>
1931
LOG_MODULE_DECLARE(settings, CONFIG_SETTINGS_LOG_LEVEL);
2032

@@ -41,7 +53,7 @@ int settings_fcb_src(struct settings_fcb *cf)
4153
cf->cf_fcb.f_scratch_cnt = 1;
4254

4355
while (1) {
44-
rc = fcb_init(DT_FLASH_AREA_STORAGE_ID, &cf->cf_fcb);
56+
rc = fcb_init(FLASH_AREA_STORAGE_ID, &cf->cf_fcb);
4557
if (rc) {
4658
return -EINVAL;
4759
}
@@ -386,7 +398,7 @@ int settings_backend_init(void)
386398
int rc;
387399
const struct flash_area *fap;
388400

389-
rc = flash_area_get_sectors(DT_FLASH_AREA_STORAGE_ID, &cnt,
401+
rc = flash_area_get_sectors(FLASH_AREA_STORAGE_ID, &cnt,
390402
settings_fcb_area);
391403
if (rc == -ENODEV) {
392404
return rc;
@@ -399,7 +411,7 @@ int settings_backend_init(void)
399411
rc = settings_fcb_src(&config_init_settings_fcb);
400412

401413
if (rc != 0) {
402-
rc = flash_area_open(DT_FLASH_AREA_STORAGE_ID, &fap);
414+
rc = flash_area_open(FLASH_AREA_STORAGE_ID, &fap);
403415

404416
if (rc == 0) {
405417
rc = flash_area_erase(fap, 0, fap->fa_size);

subsys/settings/src/settings_nvs.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
#include "settings_priv.h"
1414
#include <storage/flash_map.h>
1515

16+
#if USE_PARTITION_MANAGER
17+
18+
#include <pm_config.h>
19+
#define FLASH_AREA_STORAGE_ID PM_SETTINGS_STORAGE_ID
20+
21+
#else
22+
23+
#include <devicetree.h>
24+
#define FLASH_AREA_STORAGE_ID DT_FLASH_AREA_STORAGE_ID
25+
26+
#endif /* USE_PARTITION_MANAGER */
27+
1628
#include <logging/log.h>
1729
LOG_MODULE_DECLARE(settings, CONFIG_SETTINGS_LOG_LEVEL);
1830

@@ -269,12 +281,12 @@ int settings_backend_init(void)
269281
struct flash_sector hw_flash_sector;
270282
u32_t sector_cnt = 1;
271283

272-
rc = flash_area_open(DT_FLASH_AREA_STORAGE_ID, &fa);
284+
rc = flash_area_open(FLASH_AREA_STORAGE_ID, &fa);
273285
if (rc) {
274286
return rc;
275287
}
276288

277-
rc = flash_area_get_sectors(DT_FLASH_AREA_STORAGE_ID, &sector_cnt,
289+
rc = flash_area_get_sectors(FLASH_AREA_STORAGE_ID, &sector_cnt,
278290
&hw_flash_sector);
279291
if (rc == -ENODEV) {
280292
return rc;

0 commit comments

Comments
 (0)