Skip to content

Commit

Permalink
[nrf noup] zephyr: introduce partition manager
Browse files Browse the repository at this point in the history
Partition Manager is a component which uses yaml files to
resolve flash placement with a wholistic view of the
device

Signed-off-by: Håkon Øye Amundsen <[email protected]>
  • Loading branch information
hakonfam authored and SebastianBoe committed Apr 12, 2019
1 parent d62e189 commit b6d3687
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 8 deletions.
31 changes: 31 additions & 0 deletions boot/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@ config MCUBOOT
select MPU_ALLOW_FLASH_WRITE if ARM_MPU
select USE_CODE_PARTITION if HAS_FLASH_LOAD_OFFSET

# Define used by partition_manager.py to deduce size of partition
config PM_PARTITION_SIZE_MCUBOOT
hex "Flash space reserved for bootloader."
default 0xc000
help
Flash space set aside for the MCUBoot. Note, the name
of this configuration needs to match the requirements set by the
script 'partition_manager.py'. See pm.yaml.


# Define used by partition_manager.py to deduce size of partition
config PM_PARTITION_SIZE_MCUBOOT_SCRATCH
hex "Flash space reserved for scratch."
default 0x1e000
help
Flash space set aside for the scratch area.

# Define used by partition_manager.py to deduce size of partition
config PM_PARTITION_SIZE_MCUBOOT_STORAGE
hex "Flash space reserved for storage."
default 0x4000
help
Flash space set aside for the storage area.

# Define used by partition_manager.py to deduce size of partition
config PM_PARTITION_SIZE_MCUBOOT_PAD
hex "Flash space reserved for padding area."
default 0x200
help
Flash space set aside for the padding area.

config BOOT_USE_MBEDTLS
bool
# Hidden option
Expand Down
11 changes: 11 additions & 0 deletions boot/zephyr/include/sysflash/sysflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
#ifndef __SYSFLASH_H__
#define __SYSFLASH_H__

#if USE_PARTITION_MANAGER
#include <pm_config.h>

#define FLASH_AREA_IMAGE_PRIMARY PM_MCUBOOT_PARTITIONS_PRIMARY_ID
#define FLASH_AREA_IMAGE_SECONDARY PM_MCUBOOT_PARTITIONS_SECONDARY_ID
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID

#else

#include <generated_dts_board.h>

#define FLASH_AREA_IMAGE_PRIMARY DT_FLASH_AREA_IMAGE_0_ID
#define FLASH_AREA_IMAGE_SECONDARY DT_FLASH_AREA_IMAGE_1_ID
#define FLASH_AREA_IMAGE_SCRATCH DT_FLASH_AREA_IMAGE_SCRATCH_ID
#endif /* USE_PARTITION_MANAGER */


#endif /* __SYSFLASH_H__ */
33 changes: 33 additions & 0 deletions boot/zephyr/pm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# The size of this partition is defined by the kconfig symbol
# CONFIG_PM_PARTITION_SIZE_MCUBOOT
mcuboot:
placement:
# MCUboot must be placed in front of 'mcuboot_pad'.
before: [mcuboot_pad]

mcuboot_partitions:
# Define a set of sub-partitions which spans over 'mcuboot_pad', 'spm' and
# 'app' if both are present. If only 'app' is present, then these partitions
# will only span across that partition.
# The sub partitions share the size of the parent partition(s) equally.
sub_partitions: [primary, secondary]
span: [mcuboot_pad, spm, app]

# The size of this partition is defined by the kconfig symbol
# CONFIG_PM_PARTITION_SIZE_MCUBOOT_SCRATCH
mcuboot_scratch:
placement:
after: [app]

# The size of this partition is defined by the kconfig symbol
# CONFIG_PM_PARTITION_SIZE_MCUBOOT_STORAGE
mcuboot_storage:
placement:
after: [mcuboot_scratch]

# Padding placed before image to boot
mcuboot_pad:
# MCUboot pad must be placed before the 'spm' partition if that is present.
# If 'spm' partition is not present, it must be placed before the 'app'.
placement:
before: [spm, app]
77 changes: 69 additions & 8 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,93 @@ if(CONFIG_BOOTLOADER_MCUBOOT)
if (${require_build})
add_subdirectory(${MCUBOOT_BASE}/boot/zephyr ${CMAKE_BINARY_DIR}/mcuboot)

set(to_sign ${KERNEL_HEX_NAME})

# TODO: Assert that the bootloader and image use the same key.

set(SIGNED_IMAGE signed.hex)
set(signed_image_hex ${PROJECT_BINARY_DIR}/signed.hex)
set(signed_image_bin ${PROJECT_BINARY_DIR}/signed.bin)
set(to_sign_bin ${PROJECT_BINARY_DIR}/to_sign.bin)
set(update_hex ${PROJECT_BINARY_DIR}/update.hex)
set(update_bin ${PROJECT_BINARY_DIR}/update.bin)

set_property(GLOBAL APPEND PROPERTY
extra_post_build_commands
set(merged_hex_file
$<TARGET_PROPERTY:partition_manager,MCUBOOT_TO_SIGN>)
set(merged_hex_file_depends
$<TARGET_PROPERTY:partition_manager,MCUBOOT_TO_SIGN_DEPENDS>)
set(sign_merged
$<BOOL:$<TARGET_PROPERTY:partition_manager,MCUBOOT_TO_SIGN>>)
set(to_sign
$<IF:${sign_merged},${merged_hex_file},${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}>)
set(sign_depends
$<IF:${sign_merged},${merged_hex_file_depends},kernel_elf>)
add_custom_command(
OUTPUT
${signed_image_hex}
${update_hex}
${update_bin}
COMMAND
${PYTHON_EXECUTABLE}
${MCUBOOT_BASE}/scripts/imgtool.py
sign
--key ${MCUBOOT_BASE}/${CONFIG_BOOT_SIGNATURE_KEY_FILE}
--header-size ${CONFIG_TEXT_SECTION_OFFSET}
--header-size $<TARGET_PROPERTY:partition_manager,MCUBOOT_HEADER_SIZE>
--align ${DT_FLASH_WRITE_BLOCK_SIZE}
--version 0.1 # TODO: Configurable?
--slot-size 0x32000 # TODO: Configurable?
${KERNEL_HEX_NAME} # TODO: Enforce that this will be present through Kconfig
${SIGNED_IMAGE}
--slot-size $<TARGET_PROPERTY:partition_manager,MCUBOOT_SLOT_SIZE>
--pad-header
${to_sign}
${signed_image_hex}
COMMAND
${CMAKE_OBJCOPY}
--input-target=ihex
--output-target=binary
${to_sign}
${to_sign_bin}
COMMAND
${PYTHON_EXECUTABLE}
${MCUBOOT_BASE}/scripts/imgtool.py
sign
--key ${MCUBOOT_BASE}/${CONFIG_BOOT_SIGNATURE_KEY_FILE}
--header-size $<TARGET_PROPERTY:partition_manager,MCUBOOT_HEADER_SIZE>
--align ${DT_FLASH_WRITE_BLOCK_SIZE}
--version 0.1 # TODO: Configurable?
--slot-size $<TARGET_PROPERTY:partition_manager,MCUBOOT_SLOT_SIZE>
--pad-header
${to_sign_bin}
${update_bin}
COMMAND
${CMAKE_OBJCOPY}
--input-target=binary
--output-target=ihex
${update_bin}
${update_hex}
COMMAND
${CMAKE_OBJCOPY}
--input-target=binary
--output-target=ihex
${update_bin}
${update_hex}
COMMAND
${CMAKE_OBJCOPY}
--input-target=ihex
--output-target=ihex
--change-address $<TARGET_PROPERTY:partition_manager,MCUBOOT_SECONDARY_ADDRESS>
${update_hex}
${PROJECT_BINARY_DIR}/moved_update.hex
DEPENDS
${sign_depends}
)
add_custom_target(mcuboot_sign_target DEPENDS ${signed_image_hex})

set_property(GLOBAL APPEND PROPERTY
HEX_FILES_TO_MERGE
${SIGNED_IMAGE}
${signed_image_hex}
)
set_property(GLOBAL APPEND PROPERTY
HEX_FILES_TO_MERGE_TARGET
${logical_target_for_zephyr_elf}
mcuboot_sign_target
)
endif() # ${require_build}
endif()

0 comments on commit b6d3687

Please sign in to comment.