Infineon: Add cyw20829 platform, shared slot feature, json memory map, psoc6 xip
Based in 1.8.0 release of MCUBoot library
This commit adds CYW20829 Infineon platform support with following capabilities:
1. Overwrite and swap upgrade mode support
2. Multi-image with up to 4 images
3. Hardware security counter is supported for CYW20829 platform
Add XIP support for PSOC6 platform - place BOOT slot in external memory and execute it in place using SMIF in XIP mode
and some new features for Infineon devices.
1. Shared upgrade slot feature - use one shared area for upgrade slots of multiple images
2. Memory map defined using JSON file - define memory regions for bootloader and user app in conventional way using JSON file
diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt
index 49b0fa0..b9bf517 100644
--- a/boot/zephyr/CMakeLists.txt
+++ b/boot/zephyr/CMakeLists.txt
@@ -94,6 +94,12 @@
keys.c
)
+if(DEFINED CONFIG_ENABLE_MGMT_PERUSER)
+ zephyr_library_sources(
+ boot_serial_extensions.c
+ )
+endif()
+
if(NOT DEFINED CONFIG_FLASH_PAGE_LAYOUT)
zephyr_library_sources(
flash_map_legacy.c
@@ -239,6 +245,8 @@
zephyr_sources(${BOOT_DIR}/boot_serial/src/boot_serial.c)
zephyr_sources(${BOOT_DIR}/boot_serial/src/serial_recovery_cbor.c)
zephyr_sources(${BOOT_DIR}/boot_serial/src/cbor_decode.c)
+ zephyr_sources(${BOOT_DIR}/boot_serial/src/cbor_encode.c)
+ zephyr_sources(${BOOT_DIR}/boot_serial/src/cbor_common.c)
zephyr_include_directories(${BOOT_DIR}/bootutil/include)
zephyr_include_directories(${BOOT_DIR}/boot_serial/include)
@@ -250,20 +258,20 @@
)
endif()
-# CONF_FILE points to the KConfig configuration files of the bootloader.
-foreach (filepath ${CONF_FILE})
- file(READ ${filepath} temp_text)
- string(FIND "${temp_text}" ${CONFIG_BOOT_SIGNATURE_KEY_FILE} match)
- if (${match} GREATER_EQUAL 0)
- if (NOT DEFINED CONF_DIR)
- get_filename_component(CONF_DIR ${filepath} DIRECTORY)
- else()
- message(FATAL_ERROR "Signature key file defined in multiple conf files")
- endif()
- endif()
-endforeach()
-
if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "")
+ # CONF_FILE points to the KConfig configuration files of the bootloader.
+ foreach (filepath ${CONF_FILE})
+ file(READ ${filepath} temp_text)
+ string(FIND "${temp_text}" ${CONFIG_BOOT_SIGNATURE_KEY_FILE} match)
+ if (${match} GREATER_EQUAL 0)
+ if (NOT DEFINED CONF_DIR)
+ get_filename_component(CONF_DIR ${filepath} DIRECTORY)
+ else()
+ message(FATAL_ERROR "Signature key file defined in multiple conf files")
+ endif()
+ endif()
+ endforeach()
+
if(IS_ABSOLUTE ${CONFIG_BOOT_SIGNATURE_KEY_FILE})
set(KEY_FILE ${CONFIG_BOOT_SIGNATURE_KEY_FILE})
elseif((DEFINED CONF_DIR) AND
diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig
index 2e7ac39..5d71cd2 100644
--- a/boot/zephyr/Kconfig
+++ b/boot/zephyr/Kconfig
@@ -30,7 +30,6 @@
# When building for ECDSA, we use our own copy of mbedTLS, so the
# Zephyr one must not be enabled or the MBEDTLS_CONFIG_FILE macros
# will collide.
- depends on ! MBEDTLS
help
Use TinyCrypt for crypto primitives.
@@ -41,7 +40,6 @@
# When building for ECDSA, we use our own copy of mbedTLS, so the
# Zephyr one must not be enabled or the MBEDTLS_CONFIG_FILE macros
# will collide.
- depends on ! MBEDTLS
help
Use cc310 for crypto primitives.
@@ -298,15 +296,6 @@
memory usage; larger values allow it to support larger images.
If unsure, leave at the default value.
-config BOOT_ERASE_PROGRESSIVELY
- bool "Erase flash progressively when receiving new firmware"
- default y if SOC_FAMILY_NRF
- help
- If enabled, flash is erased as necessary when receiving new firmware,
- instead of erasing the whole image slot at once. This is necessary
- on some hardware that has long erase times, to prevent long wait
- times at the beginning of the DFU process.
-
config MEASURED_BOOT
bool "Store the boot state/measurements in shared memory"
default n
@@ -364,7 +353,7 @@
config BOOT_USB_DFU_WAIT
bool "Wait for a prescribed duration to see if USB DFU is invoked"
- select USB
+ select USB_DEVICE_STACK
select USB_DFU_CLASS
select IMG_MANAGER
help
@@ -374,7 +363,7 @@
config BOOT_USB_DFU_GPIO
bool "Use GPIO to detect whether to trigger DFU mode"
- select USB
+ select USB_DEVICE_STACK
select USB_DFU_CLASS
select IMG_MANAGER
help
@@ -403,7 +392,8 @@
default 6 if BOARD_NRF9160DK_NRF9160
default 11 if BOARD_NRF52840DK_NRF52840
default 13 if BOARD_NRF52DK_NRF52832
- default 23 if BOARD_NRF5340_DK_NRF5340_CPUAPP || BOARD_NRF5340_DK_NRF5340_CPUAPPNS
+ default 23 if BOARD_NRF5340_DK_NRF5340_CPUAPP || BOARD_NRF5340_DK_NRF5340_CPUAPP_NS
+ default 43 if BOARD_BL5340_DVK_CPUAPP || BOARD_BL5340_DVK_CPUAPP_NS
help
Pin on the DFU detect port that triggers DFU mode.
@@ -468,7 +458,6 @@
select SERIAL
select UART_INTERRUPT_DRIVEN
select BASE64
- select TINYCBOR
help
If y, enables a serial-port based update mode. This allows
MCUboot itself to load update images into flash over a UART.
@@ -487,12 +476,25 @@
config BOOT_SERIAL_CDC_ACM
bool "CDC ACM"
- select USB
select USB_DEVICE_STACK
- select USB_CDC_ACM
endchoice
+config MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD
+ bool "Allow to select image number for DFU"
+ help
+ With the option enabled, the mcuboot serial recovery will
+ respect the "image" field in mcumgr image update frame
+ header.
+ The mapping of image number to partition is as follows:
+ 0 -> default behaviour, same as 1;
+ 1 -> image-0 (primary slot of the first image);
+ 2 -> image-1 (secondary slot of the first image);
+ 3 -> image-2;
+ 4 -> image-3.
+ Note that 0 is default upload target when no explicit
+ selection is done.
+
config MCUBOOT_INDICATION_LED
bool "Turns on LED indication when device is in DFU"
default n
@@ -518,9 +520,9 @@
int "Pin to trigger serial recovery mode"
default 6 if BOARD_NRF9160DK_NRF9160
default 11 if BOARD_NRF52840DK_NRF52840
- default 13 if BOARD_NRF52DK_NRF52832
- default 23 if BOARD_NRF5340PDK_NRF5340_CPUAPP || BOARD_NRF5340PDK_NRF5340_CPUAPPNS || \
- BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_NRF5340DK_NRF5340_CPUAPPNS
+ default 13 if BOARD_NRF52DK_NRF52832 || BOARD_NRF52833DK_NRF52833
+ default 23 if BOARD_NRF5340PDK_NRF5340_CPUAPP || BOARD_NRF5340PDK_NRF5340_CPUAPP_NS || \
+ BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_NRF5340DK_NRF5340_CPUAPP_NS
help
Pin on the serial detect port that triggers serial recovery mode.
@@ -540,18 +542,40 @@
Useful for powering on when using the same button as
the one used to place the device in bootloader mode.
-# Workaround for not being able to have commas in macro arguments
-DT_CHOSEN_Z_CONSOLE := zephyr,console
-
-config RECOVERY_UART_DEV_NAME
- string "UART Device Name for Recovery UART"
- default "$(dt_chosen_label,$(DT_CHOSEN_Z_CONSOLE))" if HAS_DTS
- default "UART_0"
- depends on BOOT_SERIAL_UART
+config BOOT_ERASE_PROGRESSIVELY
+ bool "Erase flash progressively when receiving new firmware"
+ default y if SOC_FAMILY_NRF
help
- This option specifies the name of UART device to be used for
- serial recovery.
+ If enabled, flash is erased as necessary when receiving new firmware,
+ instead of erasing the whole image slot at once. This is necessary
+ on some hardware that has long erase times, to prevent long wait
+ times at the beginning of the DFU process.
+menuconfig ENABLE_MGMT_PERUSER
+ bool "Enable system specific mcumgr commands"
+ help
+ The option enables processing of system specific mcumgr commands;
+ system specific commands are within group MGMT_GROUP_ID_PERUSER (64)
+ and above, as defined within mcumgr library.
+ These are system specific command and system specific implementation
+ function is required to process these commands.
+
+if ENABLE_MGMT_PERUSER
+config BOOT_MGMT_CUSTOM_STORAGE_ERASE
+ bool "Enable storage erase command"
+ help
+ The option enables mcumgr command that allows to erase storage
+ partition.
+ Note that the storage partition needs to be defined, in DTS, otherwise
+ enabling the option will cause a compilation to fail.
+
+config BOOT_MGMT_CUSTOM_IMG_LIST
+ bool "Enable custom image list command"
+ help
+ The option enables command which returns versions and installation
+ statuses (custom property) for all images.
+
+endif # ENABLE_MGMT_PERUSER
endif # MCUBOOT_SERIAL
config BOOT_INTR_VEC_RELOC
@@ -604,6 +628,24 @@
Enables implementation of MCUBOOT_WATCHDOG_FEED() macro which is
used to feed watchdog while doing time consuming operations.
+config BOOT_IMAGE_ACCESS_HOOKS
+ bool "Enable hooks for overriding MCUboot's native routines"
+ help
+ Allow to provide procedures for override or extend native
+ MCUboot's routines required for access the image data and the image
+ update.
+
+config BOOT_IMAGE_ACCESS_HOOKS_FILE
+ string "Hooks implementation file path"
+ depends on BOOT_IMAGE_ACCESS_HOOKS
+ help
+ Path to the file which implements hooks.
+ You can use either absolute or relative path.
+ In case relative path is used, the build system assumes that it starts
+ from the directory where the MCUBoot KConfig configuration file is
+ located. If the key file is not there, the build system uses relative
+ path that starts from the zephyr port cmake directory (boot/zephyr/).
+
endmenu
config MCUBOOT_DEVICE_SETTINGS
@@ -638,10 +680,6 @@
default n if SOC_FAMILY_NRF
default y
-config LOG_IMMEDIATE
- default n if MULTITHREADING
- default y
-
config LOG_PROCESS_THREAD
default n # mcuboot has its own log processing thread
diff --git a/boot/zephyr/boards/flash_sim_driver.conf b/boot/zephyr/boards/flash_sim_driver.conf
new file mode 100644
index 0000000..7e5e58e
--- /dev/null
+++ b/boot/zephyr/boards/flash_sim_driver.conf
@@ -0,0 +1,2 @@
+CONFIG_FLASH_SIMULATOR=y
+CONFIG_FLASH_SIMULATOR_UNALIGNED_READ=y
diff --git a/boot/zephyr/boards/mimxrt1020_evk.conf b/boot/zephyr/boards/mimxrt1020_evk.conf
new file mode 100644
index 0000000..37ed5f8
--- /dev/null
+++ b/boot/zephyr/boards/mimxrt1020_evk.conf
@@ -0,0 +1,4 @@
+# Copyright 2021 NXP
+# SPDX-License-Identifier: Apache-2.0
+
+CONFIG_BOOT_MAX_IMG_SECTORS=1024
diff --git a/boot/zephyr/boards/mimxrt1050_evk_qspi.conf b/boot/zephyr/boards/mimxrt1050_evk_qspi.conf
new file mode 100644
index 0000000..37ed5f8
--- /dev/null
+++ b/boot/zephyr/boards/mimxrt1050_evk_qspi.conf
@@ -0,0 +1,4 @@
+# Copyright 2021 NXP
+# SPDX-License-Identifier: Apache-2.0
+
+CONFIG_BOOT_MAX_IMG_SECTORS=1024
diff --git a/boot/zephyr/boards/mimxrt1060_evk.conf b/boot/zephyr/boards/mimxrt1060_evk.conf
new file mode 100644
index 0000000..37ed5f8
--- /dev/null
+++ b/boot/zephyr/boards/mimxrt1060_evk.conf
@@ -0,0 +1,4 @@
+# Copyright 2021 NXP
+# SPDX-License-Identifier: Apache-2.0
+
+CONFIG_BOOT_MAX_IMG_SECTORS=1024
diff --git a/boot/zephyr/boards/mimxrt1064_evk.conf b/boot/zephyr/boards/mimxrt1064_evk.conf
new file mode 100644
index 0000000..1c50bc9
--- /dev/null
+++ b/boot/zephyr/boards/mimxrt1064_evk.conf
@@ -0,0 +1,4 @@
+# Copyright 2021 NXP
+# SPDX-License-Identifier: Apache-2.0
+
+CONFIG_BOOT_MAX_IMG_SECTORS=512
diff --git a/boot/zephyr/boards/nrf52840_big.overlay b/boot/zephyr/boards/nrf52840_big.overlay
index 094a7a4..778a1ed 100644
--- a/boot/zephyr/boards/nrf52840_big.overlay
+++ b/boot/zephyr/boards/nrf52840_big.overlay
@@ -28,3 +28,10 @@
};
};
};
+
+&zephyr_udc0 {
+ cdc_acm_uart0 {
+ compatible = "zephyr,cdc-acm-uart";
+ label = "CDC_ACM_0";
+ };
+};
diff --git a/boot/zephyr/boards/nrf52840dk_hooks_sample_overlay.conf b/boot/zephyr/boards/nrf52840dk_hooks_sample_overlay.conf
new file mode 100644
index 0000000..5c13cd2
--- /dev/null
+++ b/boot/zephyr/boards/nrf52840dk_hooks_sample_overlay.conf
@@ -0,0 +1,7 @@
+CONFIG_UPDATEABLE_IMAGE_NUMBER=2
+
+CONFIG_FLASH_SIMULATOR=y
+CONFIG_FLASH_SIMULATOR_UNALIGNED_READ=y
+
+CONFIG_BOOT_IMAGE_ACCESS_HOOKS=y
+CONFIG_BOOT_IMAGE_ACCESS_HOOKS_FILE="hooks_sample.c"
diff --git a/boot/zephyr/boards/nrf52840dk_ram.overlay b/boot/zephyr/boards/nrf52840dk_ram.overlay
new file mode 100644
index 0000000..a1f9f38
--- /dev/null
+++ b/boot/zephyr/boards/nrf52840dk_ram.overlay
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2021 Nordic Semiconductor ASA
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/delete-node/ &slot1_partition;
+/delete-node/ &slot0_partition;
+/delete-node/ &boot_partition;
+
+&flash0 {
+ partitions {
+ boot_partition: partition@0 {
+ label = "mcuboot";
+ reg = <0x000000000 0x00010000>;
+ };
+ slot0_partition: partition@10000 {
+ label = "image-0";
+ reg = <0x000010000 0x00000A000>;
+ };
+ };
+};
+
+/ {
+ soc {
+ flash_controller2: flash-controller@2 {
+ compatible = "zephyr,sim-flash";
+ reg = <0x00000000 DT_SIZE_K(40)>;
+
+ #address-cells = <1>;
+ #size-cells = <1>;
+ erase-value = <0xff>;
+
+ label = "flash_ctrl";
+
+ flash_sim0: flash_sim@0 {
+ status = "okay";
+ compatible = "soc-nv-flash";
+ label = "simulated_flash";
+ erase-block-size = <4096>;
+ write-block-size = <1>;
+ reg = <0x00000000 DT_SIZE_K(40)>;
+
+ partitions {
+ compatible = "fixed-partitions";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ slot1_partition: partition@0 {
+ label = "image-1";
+ reg = <0x00000000 0x00000A000>;
+ };
+ };
+ };
+ };
+ };
+};
diff --git a/boot/zephyr/boards/nrf52840dk_ram_multi.overlay b/boot/zephyr/boards/nrf52840dk_ram_multi.overlay
new file mode 100644
index 0000000..7befec9
--- /dev/null
+++ b/boot/zephyr/boards/nrf52840dk_ram_multi.overlay
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2021 Nordic Semiconductor ASA
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/delete-node/ &slot1_partition;
+/delete-node/ &slot0_partition;
+/delete-node/ &boot_partition;
+
+&flash0 {
+ partitions {
+ boot_partition: partition@0 {
+ label = "mcuboot";
+ reg = <0x000000000 0x00010000>;
+ };
+ slot0_partition: partition@10000 {
+ label = "image-0";
+ reg = <0x000010000 0x00000A000>;
+ };
+ slot1_partition: partition@1A000 {
+ label = "image-1";
+ reg = <0x00001A000 0x00000A000>;
+ };
+ slot3_partition: partition@24000 {
+ label = "image-3";
+ reg = <0x000024000 0x00000A000>;
+ };
+ };
+};
+
+/ {
+ soc {
+ flash_controller2: flash-controller@2 {
+ compatible = "zephyr,sim-flash";
+ reg = <0x00000000 DT_SIZE_K(40)>;
+
+ #address-cells = <1>;
+ #size-cells = <1>;
+ erase-value = <0xff>;
+
+ label = "flash_ctrl";
+
+ flash_sim0: flash_sim@0 {
+ status = "okay";
+ compatible = "soc-nv-flash";
+ label = "simulated_flash";
+ erase-block-size = <4096>;
+ write-block-size = <1>;
+ reg = <0x00000000 DT_SIZE_K(40)>;
+
+ partitions {
+ compatible = "fixed-partitions";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ slot2_partition: partition@0 {
+ label = "image-2";
+ reg = <0x00000000 0x00000A000>;
+ };
+ };
+ };
+ };
+ };
+};
diff --git a/boot/zephyr/boards/nrf52840dongle_nrf52840.conf b/boot/zephyr/boards/nrf52840dongle_nrf52840.conf
index ba333d9..f4fbb39 100644
--- a/boot/zephyr/boards/nrf52840dongle_nrf52840.conf
+++ b/boot/zephyr/boards/nrf52840dongle_nrf52840.conf
@@ -24,9 +24,7 @@
CONFIG_MULTITHREADING=y
# USB
-CONFIG_USB=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="MCUBOOT"
-CONFIG_USB_CDC_ACM=y
CONFIG_USB_COMPOSITE_DEVICE=n
CONFIG_USB_MASS_STORAGE=n
diff --git a/boot/zephyr/boards/nrf52_minimal_footprint.conf b/boot/zephyr/boards/nrf52_minimal_footprint.conf
index afe8c9b..81c0845 100644
--- a/boot/zephyr/boards/nrf52_minimal_footprint.conf
+++ b/boot/zephyr/boards/nrf52_minimal_footprint.conf
@@ -44,7 +44,7 @@
CONFIG_SERIAL=n
# Power management
-CONFIG_SYS_POWER_MANAGEMENT=n
+CONFIG_PM=n
# Interrupts
CONFIG_DYNAMIC_INTERRUPTS=n
diff --git a/boot/zephyr/boards/thingy53_nrf5340_cpuapp.conf b/boot/zephyr/boards/thingy53_nrf5340_cpuapp.conf
new file mode 100644
index 0000000..754bf7b
--- /dev/null
+++ b/boot/zephyr/boards/thingy53_nrf5340_cpuapp.conf
@@ -0,0 +1,81 @@
+CONFIG_SIZE_OPTIMIZATIONS=y
+
+CONFIG_SYSTEM_CLOCK_DISABLE=y
+CONFIG_SYSTEM_CLOCK_NO_WAIT=y
+CONFIG_PM=n
+
+CONFIG_MAIN_STACK_SIZE=10240
+CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h"
+
+CONFIG_BOOT_MAX_IMG_SECTORS=2048
+CONFIG_BOOT_SIGNATURE_TYPE_RSA=y
+
+# Flash
+CONFIG_FLASH=y
+CONFIG_BOOT_ERASE_PROGRESSIVELY=y
+CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y
+CONFIG_FPROTECT=y
+
+# Serial
+CONFIG_SERIAL=y
+CONFIG_UART_LINE_CTRL=y
+
+# MCUBoot serial
+CONFIG_GPIO=y
+CONFIG_MCUBOOT_SERIAL=y
+CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD=y
+CONFIG_BOOT_SERIAL_CDC_ACM=y
+CONFIG_BOOT_SERIAL_DETECT_PORT="GPIO_1"
+CONFIG_BOOT_SERIAL_DETECT_PIN=13
+
+# Required by QSPI
+CONFIG_NORDIC_QSPI_NOR=y
+CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
+CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE=16
+
+CONFIG_PM_EXTERNAL_FLASH_SUPPORT_LEGACY=y
+CONFIG_PM_EXTERNAL_FLASH=y
+CONFIG_PM_EXTERNAL_FLASH_DEV_NAME="MX25R64"
+CONFIG_PM_EXTERNAL_FLASH_BASE=0x0
+CONFIG_PM_EXTERNAL_FLASH_SIZE=0x800000
+
+# Required by USB and QSPI
+CONFIG_MULTITHREADING=y
+
+# USB
+CONFIG_USB=y
+CONFIG_USB_DEVICE_MANUFACTURER="Nordic Semiconductor ASA"
+CONFIG_USB_DEVICE_PRODUCT="Bootloader Thingy:53"
+CONFIG_USB_DEVICE_VID=0x1915
+CONFIG_USB_DEVICE_PID=0x5300
+CONFIG_USB_CDC_ACM=y
+
+# Decrease memory footprint
+CONFIG_CBPRINTF_NANO=y
+CONFIG_TIMESLICING=n
+CONFIG_BOOT_BANNER=n
+CONFIG_CONSOLE=n
+CONFIG_CONSOLE_HANDLER=n
+CONFIG_UART_CONSOLE=n
+CONFIG_USE_SEGGER_RTT=n
+CONFIG_LOG=n
+CONFIG_ERRNO=n
+CONFIG_PRINTK=n
+CONFIG_RESET_ON_FATAL_ERROR=n
+CONFIG_SPI=n
+CONFIG_I2C=n
+CONFIG_UART_NRFX=n
+
+# The following configurations are required to support simultaneous multi image update
+CONFIG_PCD_APP=y
+CONFIG_UPDATEABLE_IMAGE_NUMBER=2
+CONFIG_BOOT_UPGRADE_ONLY=y
+# The network core cannot access external flash directly. The flash simulator must be used to
+# provide a memory region that is used to forward the new firmware to the network core.
+CONFIG_FLASH_SIMULATOR=y
+CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
+CONFIG_FLASH_SIMULATOR_STATS=n
+
+# Enable custom command to erase settings partition.
+CONFIG_ENABLE_MGMT_PERUSER=y
+CONFIG_BOOT_MGMT_CUSTOM_STORAGE_ERASE=y
diff --git a/boot/zephyr/boot_serial_extensions.c b/boot/zephyr/boot_serial_extensions.c
new file mode 100644
index 0000000..49bb4ea
--- /dev/null
+++ b/boot/zephyr/boot_serial_extensions.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2021 Nordic Semiconductor ASA
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr.h>
+#include <drivers/flash.h>
+#include <mgmt/mcumgr/zephyr_groups.h>
+
+#include <flash_map_backend/flash_map_backend.h>
+#include <sysflash/sysflash.h>
+
+#include "bootutil/bootutil_log.h"
+#include "../boot_serial/src/boot_serial_priv.h"
+#include "../boot_serial/src/cbor_encode.h"
+
+#include "bootutil/image.h"
+#include "bootutil/bootutil_public.h"
+#include "bootutil/boot_hooks.h"
+
+MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+
+#ifdef CONFIG_BOOT_MGMT_CUSTOM_STORAGE_ERASE
+static int bs_custom_storage_erase(cbor_state_t *cs)
+{
+ int rc;
+
+ const struct flash_area *fa;
+
+ rc = flash_area_open(FLASH_AREA_ID(storage), &fa);
+
+ if (rc < 0) {
+ LOG_ERR("failed to open flash area");
+ } else {
+ rc = flash_area_erase(fa, 0, FLASH_AREA_SIZE(storage));
+ if (rc < 0) {
+ LOG_ERR("failed to erase flash area");
+ }
+ flash_area_close(fa);
+ }
+ if (rc == 0) {
+ rc = MGMT_ERR_OK;
+ } else {
+ rc = MGMT_ERR_EUNKNOWN;
+ }
+
+ map_start_encode(cs, 10);
+ tstrx_put(cs, "rc");
+ uintx32_put(cs, rc);
+ map_end_encode(cs, 10);
+
+ return rc;
+}
+#endif
+
+#ifdef MCUBOOT_MGMT_CUSTOM_IMG_LIST
+static int custom_img_status(int image_index, uint32_t slot,char *buffer,
+ ssize_t len)
+{
+ uint32_t area_id;
+ struct flash_area const *fap;
+ struct image_header hdr;
+ int rc;
+ int img_install_stat;
+
+ rc = BOOT_HOOK_CALL(boot_img_install_stat_hook, BOOT_HOOK_REGULAR,
+ image_index, slot, &img_install_stat);
+ if (rc == BOOT_HOOK_REGULAR)
+ {
+ img_install_stat = 0;
+ }
+
+ rc = BOOT_HOOK_CALL(boot_read_image_header_hook, BOOT_HOOK_REGULAR,
+ image_index, slot, &hdr);
+ if (rc == BOOT_HOOK_REGULAR)
+ {
+ area_id = flash_area_id_from_multi_image_slot(image_index, slot);
+
+ rc = flash_area_open(area_id, &fap);
+ if (rc) {
+ return rc;
+ }
+
+ rc = flash_area_read(fap, 0, &hdr, sizeof(hdr));
+
+ flash_area_close(fap);
+ }
+
+ if (rc == 0) {
+ if (hdr.ih_magic == IMAGE_MAGIC) {
+ snprintf(buffer, len, "ver=%d.%d.%d.%d,install_stat=%d",
+ hdr.ih_ver.iv_major,
+ hdr.ih_ver.iv_minor,
+ hdr.ih_ver.iv_revision,
+ hdr.ih_ver.iv_build_num,
+ img_install_stat);
+ } else {
+ rc = 1;
+ }
+ }
+
+ return rc;
+}
+
+static int bs_custom_img_list(cbor_state_t *cs)
+{
+ int rc = 0;
+ char tmpbuf[64]; /* Buffer should fit version and flags */
+
+ map_start_encode(cs, 10);
+
+ for (int img = 0; img < MCUBOOT_IMAGE_NUMBER; img++) {
+ for (int slot = 0; slot < 2; slot++) {
+ rc = custom_img_status(img, slot, tmpbuf, sizeof(tmpbuf));
+
+ intx32_put(cs, img * 2 + slot + 1);
+ if (rc == 0) {
+ tstrx_put_term(cs, tmpbuf);
+ } else {
+ tstrx_put_term(cs, "");
+ }
+ }
+ }
+
+ tstrx_put(cs, "rc");
+ uintx32_put(cs, MGMT_ERR_OK);
+ map_end_encode(cs, 10);
+
+ return rc;
+}
+
+#ifndef ZEPHYR_MGMT_GRP_BASIC_CMD_IMAGE_LIST
+ #define ZEPHYR_MGMT_GRP_BASIC_CMD_IMAGE_LIST 1
+#endif
+#endif /*MCUBOOT_MGMT_CUSTOM_IMG_LIST*/
+
+int bs_peruser_system_specific(const struct nmgr_hdr *hdr, const char *buffer,
+ int len, cbor_state_t *cs)
+{
+ int mgmt_rc = MGMT_ERR_ENOTSUP;
+
+ if (hdr->nh_group == ZEPHYR_MGMT_GRP_BASE) {
+ if (hdr->nh_op == NMGR_OP_WRITE) {
+#ifdef CONFIG_BOOT_MGMT_CUSTOM_STORAGE_ERASE
+ if (hdr->nh_id == ZEPHYR_MGMT_GRP_BASIC_CMD_ERASE_STORAGE) {
+ mgmt_rc = bs_custom_storage_erase(cs);
+ }
+#endif
+ } else if (hdr->nh_op == NMGR_OP_READ) {
+#ifdef MCUBOOT_MGMT_CUSTOM_IMG_LIST
+ if (hdr->nh_id == ZEPHYR_MGMT_GRP_BASIC_CMD_IMAGE_LIST) {
+ mgmt_rc = bs_custom_img_list(cs);
+ }
+#endif
+ }
+ }
+
+ if (mgmt_rc == MGMT_ERR_ENOTSUP) {
+ map_start_encode(cs, 10);
+ tstrx_put(cs, "rc");
+ uintx32_put(cs, mgmt_rc);
+ map_end_encode(cs, 10);
+ }
+
+ return MGMT_ERR_OK;
+}
diff --git a/boot/zephyr/flash_map_extended.c b/boot/zephyr/flash_map_extended.c
index 7b6ae63..a52d58f 100644
--- a/boot/zephyr/flash_map_extended.c
+++ b/boot/zephyr/flash_map_extended.c
@@ -15,7 +15,7 @@
#include "bootutil/bootutil_log.h"
-MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+BOOT_LOG_MODULE_DECLARE(mcuboot);
#if (!defined(CONFIG_XTENSA) && defined(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL))
#define FLASH_DEVICE_ID SOC_FLASH_0_ID
@@ -59,9 +59,9 @@
case 0: return FLASH_AREA_IMAGE_PRIMARY(image_index);
#if !defined(CONFIG_SINGLE_APPLICATION_SLOT)
case 1: return FLASH_AREA_IMAGE_SECONDARY(image_index);
-#if !defined(CONFIG_BOOT_SWAP_USING_MOVE)
- case 2: return FLASH_AREA_IMAGE_SCRATCH;
#endif
+#if defined(CONFIG_BOOT_SWAP_USING_SCRATCH)
+ case 2: return FLASH_AREA_IMAGE_SCRATCH;
#endif
}
@@ -93,6 +93,30 @@
return flash_area_id_to_multi_image_slot(0, area_id);
}
+#if defined(CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD)
+int flash_area_id_from_direct_image(int image_id)
+{
+ switch (image_id) {
+ case 0:
+ case 1:
+ return FLASH_AREA_ID(image_0);
+#if DT_HAS_FIXED_PARTITION_LABEL(image_1)
+ case 2:
+ return FLASH_AREA_ID(image_1);
+#endif
+#if DT_HAS_FIXED_PARTITION_LABEL(image_2)
+ case 3:
+ return FLASH_AREA_ID(image_2);
+#endif
+#if DT_HAS_FIXED_PARTITION_LABEL(image_3)
+ case 4:
+ return FLASH_AREA_ID(image_3);
+#endif
+ }
+ return -EINVAL;
+}
+#endif
+
int flash_area_sector_from_off(off_t off, struct flash_sector *sector)
{
int rc;
@@ -109,6 +133,12 @@
return rc;
}
+uint8_t flash_area_get_device_id(const struct flash_area *fa)
+{
+ (void)fa;
+ return FLASH_DEVICE_ID;
+}
+
#define ERASED_VAL 0xff
__weak uint8_t flash_area_erased_val(const struct flash_area *fap)
{
diff --git a/boot/zephyr/flash_map_legacy.c b/boot/zephyr/flash_map_legacy.c
index b217947..6a8e7ae 100644
--- a/boot/zephyr/flash_map_legacy.c
+++ b/boot/zephyr/flash_map_legacy.c
@@ -49,7 +49,7 @@
#define FLASH_AREA_IMAGE_SECTOR_SIZE FLASH_AREA_IMAGE_SCRATCH_SIZE
#endif
-MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+BOOT_LOG_MODULE_DECLARE(mcuboot);
/*
* Lookup the sector map for a given flash area. This should fill in
diff --git a/boot/zephyr/hooks_sample.c b/boot/zephyr/hooks_sample.c
new file mode 100644
index 0000000..a4dbfb5
--- /dev/null
+++ b/boot/zephyr/hooks_sample.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2021 Nordic Semiconductor ASA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <assert.h>
+#include <zephyr.h>
+#include "bootutil/image.h"
+#include "bootutil/bootutil.h"
+#include "bootutil/fault_injection_hardening.h"
+#include "flash_map_backend/flash_map_backend.h"
+
+/* @retval 0: header was read/populated
+ * FIH_FAILURE: image is invalid,
+ * BOOT_HOOK_REGULAR if hook not implemented for the image-slot,
+ * othervise an error-code value.
+ */
+int boot_read_image_header_hook(int img_index, int slot,
+ struct image_header *img_hed)
+{
+ if (img_index == 1 && slot == 0) {
+ img_hed->ih_magic = IMAGE_MAGIC;
+ return 0;
+ }
+
+ return BOOT_HOOK_REGULAR;
+}
+
+/* @retval FIH_SUCCESS: image is valid,
+ * FIH_FAILURE: image is invalid,
+ * fih encoded BOOT_HOOK_REGULAR if hook not implemented for
+ * the image-slot.
+ */
+fih_int boot_image_check_hook(int img_index, int slot)
+{
+ if (img_index == 1 && slot == 0) {
+ FIH_RET(FIH_SUCCESS);
+ }
+
+ FIH_RET(fih_int_encode(BOOT_HOOK_REGULAR));
+}
+
+int boot_perform_update_hook(int img_index, struct image_header *img_head,
+ const struct flash_area *area)
+{
+ if (img_index == 1) {
+ return 0;
+ }
+
+ return BOOT_HOOK_REGULAR;
+}
+
+int boot_read_swap_state_primary_slot_hook(int image_index,
+ struct boot_swap_state *state)
+{
+ if (image_index == 1) {
+ state->magic = BOOT_MAGIC_UNSET;
+ state->swap_type = BOOT_SWAP_TYPE_NONE;
+ state->image_num = image_index ; // ?
+ state->copy_done = BOOT_FLAG_UNSET;
+ state->image_ok = BOOT_FLAG_UNSET;
+
+ return 0;
+ }
+
+ return BOOT_HOOK_REGULAR;
+}
+
+int boot_copy_region_post_hook(int img_index, const struct flash_area *area,
+ size_t size)
+{
+ return 0;
+}
+
+int boot_serial_uploaded_hook(int img_index, const struct flash_area *area,
+ size_t size)
+{
+ return 0;
+}
+
+int boot_img_install_stat_hook(int image_index, int slot, int *img_install_stat)
+{
+ return BOOT_HOOK_REGULAR;
+}
diff --git a/boot/zephyr/include/config-ecdsa.h b/boot/zephyr/include/config-ec.h
similarity index 93%
rename from boot/zephyr/include/config-ecdsa.h
rename to boot/zephyr/include/config-ec.h
index 6ae1ada..3b11295 100644
--- a/boot/zephyr/include/config-ecdsa.h
+++ b/boot/zephyr/include/config-ec.h
@@ -1,7 +1,7 @@
/*
* Minimal configuration for using TLS in the bootloader
*
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * Copyright (C) 2006-2021, ARM Limited, All Rights Reserved
* Copyright (C) 2016, Linaro Ltd
* SPDX-License-Identifier: Apache-2.0
*
@@ -53,6 +53,7 @@
#endif
#define MBEDTLS_ECDSA_C
+#define MBEDTLS_ECDH_C
/* mbed TLS modules */
#define MBEDTLS_ASN1_PARSE_C
@@ -64,6 +65,7 @@
#define MBEDTLS_MD_C
#define MBEDTLS_OID_C
#define MBEDTLS_SHA256_C
+#define MBEDTLS_SHA224_C
#define MBEDTLS_AES_C
/* Bring in support for x509. */
@@ -77,7 +79,7 @@
#define MBEDTLS_MPI_MAX_SIZE 32
-#define MBEDTLS_SSL_MAX_CONTENT_LEN 1024
+#define MBEDTLS_SSL_MAX_CONTENT_LEN 1024
/* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
diff --git a/boot/zephyr/include/config-ed25519.h b/boot/zephyr/include/config-ed25519.h
index 3efb7bd..7e43708 100644
--- a/boot/zephyr/include/config-ed25519.h
+++ b/boot/zephyr/include/config-ed25519.h
@@ -1,7 +1,7 @@
/*
* Configuration of mbedTLS containing only the ASN.1 parser.
*
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * Copyright (C) 2006-2021, ARM Limited, All Rights Reserved
* Copyright (C) 2016, Linaro Ltd
* SPDX-License-Identifier: Apache-2.0
*
@@ -60,6 +60,7 @@
#define MBEDTLS_MD_C
#define MBEDTLS_OID_C
#define MBEDTLS_SHA256_C
+#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA512_C
#define MBEDTLS_AES_C
diff --git a/boot/zephyr/include/config-kw.h b/boot/zephyr/include/config-kw.h
index 0ed94d1..168e56e 100644
--- a/boot/zephyr/include/config-kw.h
+++ b/boot/zephyr/include/config-kw.h
@@ -1,7 +1,7 @@
/*
* Minimal configuration for using TLS in the bootloader
*
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * Copyright (C) 2006-2021, ARM Limited, All Rights Reserved
* Copyright (C) 2016, Linaro Ltd
* SPDX-License-Identifier: Apache-2.0
*
@@ -57,6 +57,7 @@
#define MBEDTLS_CIPHER_MODE_CTR
#define MBEDTLS_SHA256_C
+#define MBEDTLS_SHA224_C
#define MBEDTLS_AES_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_NIST_KW_C
diff --git a/boot/zephyr/include/config-rsa-kw.h b/boot/zephyr/include/config-rsa-kw.h
index 99c9957..bc3da7d 100644
--- a/boot/zephyr/include/config-rsa-kw.h
+++ b/boot/zephyr/include/config-rsa-kw.h
@@ -1,7 +1,7 @@
/*
* Minimal configuration for using TLS in the bootloader
*
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * Copyright (C) 2006-2021, ARM Limited, All Rights Reserved
* Copyright (C) 2016, Linaro Ltd
* SPDX-License-Identifier: Apache-2.0
*
@@ -63,6 +63,7 @@
#define MBEDTLS_MD_C
#define MBEDTLS_OID_C
#define MBEDTLS_SHA256_C
+#define MBEDTLS_SHA224_C
#define MBEDTLS_AES_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_NIST_KW_C
diff --git a/boot/zephyr/include/config-rsa.h b/boot/zephyr/include/config-rsa.h
index 265b290..0552420 100644
--- a/boot/zephyr/include/config-rsa.h
+++ b/boot/zephyr/include/config-rsa.h
@@ -1,7 +1,7 @@
/*
* Minimal configuration for using TLS in the bootloader
*
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * Copyright (C) 2006-2021, ARM Limited, All Rights Reserved
* Copyright (C) 2016, Linaro Ltd
* SPDX-License-Identifier: Apache-2.0
*
@@ -64,6 +64,7 @@
#define MBEDTLS_MD_C
#define MBEDTLS_OID_C
#define MBEDTLS_SHA256_C
+#define MBEDTLS_SHA224_C
#define MBEDTLS_AES_C
/* Save RAM by adjusting to our exact needs */
diff --git a/boot/zephyr/include/flash_map_backend/flash_map_backend.h b/boot/zephyr/include/flash_map_backend/flash_map_backend.h
index 958cdcb..ae95217 100644
--- a/boot/zephyr/include/flash_map_backend/flash_map_backend.h
+++ b/boot/zephyr/include/flash_map_backend/flash_map_backend.h
@@ -76,19 +76,38 @@
*/
int flash_area_sector_from_off(off_t off, struct flash_sector *sector);
+static inline uint32_t flash_area_get_off(const struct flash_area *fa)
+{
+ return (uint32_t)fa->fa_off;
+}
+
+static inline uint32_t flash_area_get_size(const struct flash_area *fa)
+{
+ return (uint32_t)fa->fa_size;
+}
+
+static inline uint8_t flash_area_get_id(const struct flash_area *fa)
+{
+ return fa->fa_id;
+}
+
+uint8_t flash_area_get_device_id(const struct flash_area *fa);
+
/*
* Returns the value expected to be read when accessing any erased
* flash byte.
*/
uint8_t flash_area_erased_val(const struct flash_area *fap);
-/*
- * Reads len bytes from off, and checks if the read data is erased.
- *
- * Returns 1 if erased, 0 if non-erased, and -1 on failure.
- */
-int flash_area_read_is_empty(const struct flash_area *fa, uint32_t off,
- void *dst, uint32_t len);
+static inline uint32_t flash_sector_get_off(const struct flash_sector *fs)
+{
+ return fs->fs_off;
+}
+
+static inline uint32_t flash_sector_get_size(const struct flash_sector *fs)
+{
+ return fs->fs_size;
+}
#ifdef __cplusplus
}
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
index 8f2b157..7061fc1 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
@@ -34,6 +34,14 @@
#define MCUBOOT_SIGN_ED25519
#endif
+#if defined(CONFIG_BOOT_USE_TINYCRYPT)
+# if defined(CONFIG_MBEDTLS) || defined(CONFIG_BOOT_USE_CC310)
+# error "One crypto library implementation allowed at a time."
+# endif
+#elif defined(CONFIG_MBEDTLS) && defined(CONFIG_BOOT_USE_CC310)
+# error "One crypto library implementation allowed at a time."
+#endif
+
#ifdef CONFIG_BOOT_USE_MBEDTLS
#define MCUBOOT_USE_MBED_TLS
#elif defined(CONFIG_BOOT_USE_TINYCRYPT)
@@ -60,6 +68,7 @@
#ifdef CONFIG_SINGLE_APPLICATION_SLOT
#define MCUBOOT_SINGLE_APPLICATION_SLOT 1
+#define MCUBOOT_IMAGE_NUMBER 1
#else
#ifdef CONFIG_BOOT_SWAP_USING_MOVE
@@ -145,6 +154,40 @@
#define MCUBOOT_FIH_PROFILE_HIGH
#endif
+#ifdef CONFIG_ENABLE_MGMT_PERUSER
+#define MCUBOOT_PERUSER_MGMT_GROUP_ENABLED 1
+#else
+#define MCUBOOT_PERUSER_MGMT_GROUP_ENABLED 0
+#endif
+
+#ifdef CONFIG_BOOT_MGMT_CUSTOM_IMG_LIST
+#define MCUBOOT_MGMT_CUSTOM_IMG_LIST
+#endif
+
+#ifdef CONFIG_BOOT_IMAGE_ACCESS_HOOKS
+#define MCUBOOT_IMAGE_ACCESS_HOOKS
+#endif
+
+/*
+ * The configuration option enables direct image upload with the
+ * serial recovery.
+ */
+#ifdef CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD
+#define MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD
+#endif
+
+/*
+ * The option enables code, currently in boot_serial, that attempts
+ * to erase flash progressively, as update fragments are received,
+ * instead of erasing whole image size of flash area after receiving
+ * first frame.
+ * Enabling this options prevents stalling the beginning of transfer
+ * for the time needed to erase large chunk of flash.
+ */
+#ifdef CONFIG_BOOT_ERASE_PROGRESSIVELY
+#define MCBOOT_ERASE_PROGRESSIVELY
+#endif
+
/*
* Enabling this option uses newer flash map APIs. This saves RAM and
* avoids deprecated API usage.
@@ -154,6 +197,13 @@
*/
#define MCUBOOT_USE_FLASH_AREA_GET_SECTORS
+#if (defined(CONFIG_BOOT_USB_DFU_WAIT) || \
+ defined(CONFIG_BOOT_USB_DFU_GPIO))
+# ifndef CONFIG_MULTITHREADING
+# error "USB DFU Requires MULTITHREADING"
+# endif
+#endif
+
#ifdef CONFIG_BOOT_MAX_IMG_SECTORS
#define MCUBOOT_MAX_IMG_SECTORS CONFIG_BOOT_MAX_IMG_SECTORS
@@ -205,4 +255,9 @@
#endif /* CONFIG_BOOT_WATCHDOG_FEED */
+#define MCUBOOT_CPU_IDLE() \
+ if (!IS_ENABLED(CONFIG_MULTITHREADING)) { \
+ k_cpu_idle(); \
+ }
+
#endif /* __MCUBOOT_CONFIG_H__ */
diff --git a/boot/zephyr/include/platform-bench.h b/boot/zephyr/include/platform-bench.h
index ed74612..d0cb963 100644
--- a/boot/zephyr/include/platform-bench.h
+++ b/boot/zephyr/include/platform-bench.h
@@ -23,7 +23,7 @@
#include "bootutil/bootutil_log.h"
/* TODO: Unclear if this can be here (redundantly). */
-MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+BOOT_LOG_MODULE_DECLARE(mcuboot);
typedef uint32_t bench_state_t;
diff --git a/boot/zephyr/include/target.h b/boot/zephyr/include/target.h
index 1b0c8f5..5f60daa 100644
--- a/boot/zephyr/include/target.h
+++ b/boot/zephyr/include/target.h
@@ -38,7 +38,7 @@
!defined(FLASH_ALIGN) || \
!(FLASH_AREA_LABEL_EXISTS(image_0)) || \
!(FLASH_AREA_LABEL_EXISTS(image_1) || CONFIG_SINGLE_APPLICATION_SLOT) || \
- (!defined(CONFIG_BOOT_SWAP_USING_MOVE) && !FLASH_AREA_LABEL_EXISTS(image_scratch) && !defined(CONFIG_SINGLE_APPLICATION_SLOT))
+ (defined(CONFIG_BOOT_SWAP_USING_SCRATCH) && !FLASH_AREA_LABEL_EXISTS(image_scratch))
#error "Target support is incomplete; cannot build mcuboot."
#endif
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index b375656..ab3b262 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -105,7 +105,7 @@
}
#endif
-MCUBOOT_LOG_MODULE_REGISTER(mcuboot);
+BOOT_LOG_MODULE_REGISTER(mcuboot);
#ifdef CONFIG_MCUBOOT_INDICATION_LED
/*
@@ -183,11 +183,10 @@
rsp->br_image_off +
rsp->br_hdr->ih_hdr_size);
- irq_lock();
#ifdef CONFIG_SYS_CLOCK_EXISTS
sys_clock_disable();
#endif
-#ifdef CONFIG_USB
+#ifdef CONFIG_USB_DEVICE_STACK
/* Disable the USB to prevent it from firing interrupts */
usb_disable();
#endif
@@ -213,6 +212,8 @@
__set_MSPLIM(0);
#endif
+#else
+ irq_lock();
#endif /* CONFIG_MCUBOOT_CLEANUP_ARM_CORE */
#ifdef CONFIG_BOOT_INTR_VEC_RELOC
@@ -390,7 +391,11 @@
if (detect_value == expected) {
if (delay > 0) {
+#ifdef CONFIG_MULTITHREADING
k_sleep(K_MSEC(50));
+#else
+ k_busy_wait(50000);
+#endif
/* Get the uptime for debounce purposes. */
int64_t timestamp = k_uptime_get();
@@ -409,7 +414,11 @@
}
/* Delay 1 ms */
+#ifdef CONFIG_MULTITHREADING
k_sleep(K_MSEC(1));
+#else
+ k_busy_wait(1000);
+#endif
}
}
}
diff --git a/boot/zephyr/prj.conf b/boot/zephyr/prj.conf
index 7df1254..a9de580 100644
--- a/boot/zephyr/prj.conf
+++ b/boot/zephyr/prj.conf
@@ -1,7 +1,7 @@
CONFIG_CONSOLE_HANDLER=y
CONFIG_DEBUG=y
CONFIG_SYSTEM_CLOCK_DISABLE=y
-CONFIG_SYS_POWER_MANAGEMENT=n
+CONFIG_PM=n
CONFIG_MAIN_STACK_SIZE=10240
CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h"
diff --git a/boot/zephyr/sample.yaml b/boot/zephyr/sample.yaml
index a685159..6a42312 100644
--- a/boot/zephyr/sample.yaml
+++ b/boot/zephyr/sample.yaml
@@ -6,25 +6,45 @@
sample.bootloader.mcuboot:
tags: bootloader_mcuboot
platform_allow: nrf52840dk_nrf52840 frdm_k64f
+ integration_platforms:
+ - nrf52840dk_nrf52840
sample.bootloader.mcuboot.serial_recovery:
extra_args: OVERLAY_CONFIG=serial_recovery.conf
platform_allow: nrf52840dk_nrf52840
+ integration_platforms:
+ - nrf52840dk_nrf52840
tags: bootloader_mcuboot
sample.bootloader.mcuboot.usb_cdc_acm_recovery:
tags: bootloader_mcuboot
platform_allow: nrf52840dongle_nrf52840
+ extra_args: DTC_OVERLAY_FILE=./usb_cdc_acm.overlay
+ integration_platforms:
+ - nrf52840dongle_nrf52840
sample.bootloader.mcuboot.usb_cdc_acm_recovery_log:
extra_args: OVERLAY_CONFIG=./usb_cdc_acm_log_recovery.conf
DTC_OVERLAY_FILE=./boards/nrf52840_big.overlay
platform_allow: nrf52840dk_nrf52840
+ integration_platforms:
+ - nrf52840dk_nrf52840
tags: bootloader_mcuboot
sample.bootloader.mcuboot.single_slot:
extra_args: OVERLAY_CONFIG=./single_slot.conf
DTC_OVERLAY_FILE=./boards/nrf52840_single_slot.overlay
platform_allow: nrf52840dk_nrf52840
+ integration_platforms:
+ - nrf52840dk_nrf52840
tags: bootloader_mcuboot
sample.bootloader.mcuboot.qspi_nor_slot:
extra_args: DTC_OVERLAY_FILE=./boards/nrf52840dk_qspi_nor_secondary.overlay
OVERLAY_CONFIG="./boards/nrf52840dk_qspi_nor.conf;./boards/nrf52840dk_qspi_secondary_boot.conf"
platform_allow: nrf52840dk_nrf52840
+ integration_platforms:
+ - nrf52840dk_nrf52840
+ tags: bootloader_mcuboot
+ sample.bootloader.mcuboot.hooks_multi:
+ extra_args: DTC_OVERLAY_FILE=./boards/nrf52840dk_ram_multi.overlay
+ OVERLAY_CONFIG=./boards/nrf52840dk_hooks_sample_overlay.conf
+ platform_allow: nrf52840dk_nrf52840
+ integration_platforms:
+ - nrf52840dk_nrf52840
tags: bootloader_mcuboot
diff --git a/boot/zephyr/serial_adapter.c b/boot/zephyr/serial_adapter.c
index 8297522..18fab9b 100644
--- a/boot/zephyr/serial_adapter.c
+++ b/boot/zephyr/serial_adapter.c
@@ -26,7 +26,7 @@
#error Zephyr UART console must been disabled if serial_adapter module is used.
#endif
-MCUBOOT_LOG_MODULE_REGISTER(serial_adapter);
+BOOT_LOG_MODULE_REGISTER(serial_adapter);
/** @brief Console input representation
*
@@ -192,27 +192,28 @@
boot_uart_fifo_init(void)
{
#ifdef CONFIG_BOOT_SERIAL_UART
- uart_dev = device_get_binding(CONFIG_RECOVERY_UART_DEV_NAME);
+ uart_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
#elif CONFIG_BOOT_SERIAL_CDC_ACM
- uart_dev = device_get_binding(CONFIG_USB_CDC_ACM_DEVICE_NAME "_0");
- if (uart_dev) {
- int rc;
- rc = usb_enable(NULL);
- if (rc) {
- return (-1);
- }
- }
+ uart_dev = DEVICE_DT_GET_ONE(zephyr_cdc_acm_uart);
#endif
- uint8_t c;
- if (!uart_dev) {
+ if (!device_is_ready(uart_dev)) {
return (-1);
}
+#if CONFIG_BOOT_SERIAL_CDC_ACM
+ int rc = usb_enable(NULL);
+ if (rc) {
+ return (-1);
+ }
+#endif
+
uart_irq_callback_set(uart_dev, boot_uart_fifo_callback);
/* Drain the fifo */
if (uart_irq_rx_ready(uart_dev)) {
+ uint8_t c;
+
while (uart_fifo_read(uart_dev, &c, 1)) {
;
}
@@ -222,11 +223,5 @@
uart_irq_rx_enable(uart_dev);
- /* Enable all interrupts unconditionally. Note that this is due
- * to Zephyr issue #8393. This should be removed once the
- * issue is fixed in upstream Zephyr.
- */
- irq_unlock(0);
-
return 0;
}
diff --git a/boot/zephyr/single_loader.c b/boot/zephyr/single_loader.c
index c16a0b7..af2d398 100644
--- a/boot/zephyr/single_loader.c
+++ b/boot/zephyr/single_loader.c
@@ -13,7 +13,7 @@
#include "mcuboot_config/mcuboot_config.h"
-MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+BOOT_LOG_MODULE_DECLARE(mcuboot);
/* Variables passed outside of unit via poiters. */
static const struct flash_area *_fa_p;
@@ -83,7 +83,7 @@
}
if (!boot_u32_safe_add(&size, hdr->ih_img_size, hdr->ih_hdr_size) ||
- size >= fa_p->fa_size) {
+ size >= flash_area_get_size(fa_p)) {
return BOOT_EBADIMAGE;
}
@@ -120,8 +120,8 @@
fih_rc = FIH_SUCCESS;
#endif /* MCUBOOT_VALIDATE_PRIMARY_SLOT */
- rsp->br_flash_dev_id = _fa_p->fa_device_id;
- rsp->br_image_off = _fa_p->fa_off;
+ rsp->br_flash_dev_id = flash_area_get_device_id(_fa_p);
+ rsp->br_image_off = flash_area_get_off(_fa_p);
rsp->br_hdr = &_hdr;
out:
diff --git a/boot/zephyr/usb_cdc_acm.overlay b/boot/zephyr/usb_cdc_acm.overlay
new file mode 100644
index 0000000..09eb8cf
--- /dev/null
+++ b/boot/zephyr/usb_cdc_acm.overlay
@@ -0,0 +1,6 @@
+&zephyr_udc0 {
+ cdc_acm_uart0 {
+ compatible = "zephyr,cdc-acm-uart";
+ label = "CDC_ACM_0";
+ };
+};