diff --git a/arch/common/CMakeLists.txt b/arch/common/CMakeLists.txt index 48685151ab1bd..b01b57df0b1eb 100644 --- a/arch/common/CMakeLists.txt +++ b/arch/common/CMakeLists.txt @@ -76,9 +76,8 @@ zephyr_linker_sources_ifdef(CONFIG_NOCACHE_MEMORY nocache.ld ) -# Only ARM, X86 and OPENISA_RV32M1_RISCV32 use ROM_START_OFFSET. -if (DEFINED CONFIG_ARM OR DEFINED CONFIG_X86 OR DEFINED CONFIG_ARM64 - OR DEFINED CONFIG_SOC_OPENISA_RV32M1) +# Only ARM, X86 and RISCV use ROM_START_OFFSET. +if (DEFINED CONFIG_ARM OR DEFINED CONFIG_X86 OR DEFINED CONFIG_ARM64 OR DEFINED CONFIG_RISCV) # Exclamation mark is printable character with lowest number in ASCII table. # We are sure that this file will be included as a first. zephyr_linker_sources(ROM_START SORT_KEY ! rom_start_address.ld) diff --git a/include/zephyr/dfu/flash_img.h b/include/zephyr/dfu/flash_img.h index 004468526093d..8ae5fe52e477f 100644 --- a/include/zephyr/dfu/flash_img.h +++ b/include/zephyr/dfu/flash_img.h @@ -111,6 +111,13 @@ int flash_img_check(struct flash_img_context *ctx, const struct flash_img_check *fic, uint8_t area_id); +/** + * @brief Get the flash area id for the image upload slot. + * + * @return flash area id for the image upload slot + */ +uint8_t flash_img_get_upload_slot(void); + #ifdef __cplusplus } #endif diff --git a/include/zephyr/dfu/mcuboot.h b/include/zephyr/dfu/mcuboot.h index fe15f769f98ee..8788ec4657eb9 100644 --- a/include/zephyr/dfu/mcuboot.h +++ b/include/zephyr/dfu/mcuboot.h @@ -159,6 +159,13 @@ int boot_read_bank_header(uint8_t area_id, struct mcuboot_img_header *header, size_t header_size); +/** + * @brief Get the flash area id for the active image slot. + * + * @return flash area id for the active image slot + */ +uint8_t boot_fetch_active_slot(void); + /** * @brief Check if the currently running image is confirmed as OK. * diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index 2706ad6583c98..41d24edcf6ab9 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -12,7 +12,7 @@ config MCUBOOT config BOOTLOADER_MCUBOOT bool "MCUboot bootloader support" - select USE_DT_CODE_PARTITION + select USE_DT_CODE_PARTITION if !MCUBOOT_BOOTLOADER_MODE_RAM_LOAD imply INIT_ARCH_HW_AT_BOOT if ARCH_SUPPORTS_ARCH_HW_INIT depends on !MCUBOOT help diff --git a/soc/lowrisc/opentitan/Kconfig.defconfig b/soc/lowrisc/opentitan/Kconfig.defconfig index 7cbedf1f60bf4..59c13c4ba8174 100644 --- a/soc/lowrisc/opentitan/Kconfig.defconfig +++ b/soc/lowrisc/opentitan/Kconfig.defconfig @@ -18,4 +18,9 @@ config 2ND_LVL_INTR_00_OFFSET config NUM_IRQS default 256 +# The OpenTitan SoC requires a manifest in front of the +# application binary. +config ROM_START_OFFSET + default 0x404 + endif # SOC_OPENTITAN diff --git a/subsys/dfu/boot/mcuboot.c b/subsys/dfu/boot/mcuboot.c index 93d58cb5b6cd0..a23c82dce75a0 100644 --- a/subsys/dfu/boot/mcuboot.c +++ b/subsys/dfu/boot/mcuboot.c @@ -44,7 +44,6 @@ LOG_MODULE_REGISTER(mcuboot_dfu, LOG_LEVEL_DBG); #if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD) /* For RAM LOAD mode, the active image must be fetched from the bootloader */ -static uint8_t boot_fetch_active_slot(void); #define ACTIVE_SLOT_FLASH_AREA_ID boot_fetch_active_slot() #define INVALID_SLOT_ID 255 #else @@ -76,7 +75,7 @@ struct mcuboot_v1_raw_header { */ #if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD) -static uint8_t boot_fetch_active_slot(void) +uint8_t boot_fetch_active_slot(void) { int rc; uint8_t slot; @@ -93,7 +92,12 @@ static uint8_t boot_fetch_active_slot(void) return slot; } -#endif +#else /* CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD */ +uint8_t boot_fetch_active_slot(void) +{ + return ACTIVE_SLOT_FLASH_AREA_ID; +} +#endif /* CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD */ static int boot_read_v1_header(uint8_t area_id, struct mcuboot_v1_raw_header *v1_raw) diff --git a/subsys/dfu/img_util/flash_img.c b/subsys/dfu/img_util/flash_img.c index 69fa559f0e39d..31e65c4e30c05 100644 --- a/subsys/dfu/img_util/flash_img.c +++ b/subsys/dfu/img_util/flash_img.c @@ -10,12 +10,12 @@ #include #include #include +#include #include #include #ifdef CONFIG_IMG_ERASE_PROGRESSIVELY #include -#include #endif #include @@ -29,8 +29,13 @@ #endif #endif +#ifdef CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD +/* For RAM LOAD mode, the active image must be fetched from the bootloader */ +#define UPLOAD_FLASH_AREA_ID flash_img_get_upload_slot() +#else /* FIXED_PARTITION_ID() values used below are auto-generated by DT */ #define UPLOAD_FLASH_AREA_ID FIXED_PARTITION_ID(UPLOAD_FLASH_AREA_LABEL) +#endif /* CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD */ #define UPLOAD_FLASH_AREA_CONTROLLER \ DT_GPARENT(DT_NODELABEL(UPLOAD_FLASH_AREA_LABEL)) @@ -145,6 +150,25 @@ int flash_img_init_id(struct flash_img_context *ctx, uint8_t area_id) ctx->flash_area->fa_size, NULL); } +#ifdef CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD +uint8_t flash_img_get_upload_slot(void) +{ + uint8_t slot; + + slot = boot_fetch_active_slot(); + + if (slot == FIXED_PARTITION_ID(slot0_partition)) { + return FIXED_PARTITION_ID(slot1_partition); + } + return FIXED_PARTITION_ID(slot0_partition); +} +#else /* CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD */ +uint8_t flash_img_get_upload_slot(void) +{ + return UPLOAD_FLASH_AREA_ID; +} +#endif /* CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD */ + int flash_img_init(struct flash_img_context *ctx) { return flash_img_init_id(ctx, UPLOAD_FLASH_AREA_ID); diff --git a/subsys/mgmt/hawkbit/hawkbit.c b/subsys/mgmt/hawkbit/hawkbit.c index 2e833a2b078f7..0bea86a791902 100644 --- a/subsys/mgmt/hawkbit/hawkbit.c +++ b/subsys/mgmt/hawkbit/hawkbit.c @@ -853,7 +853,7 @@ int hawkbit_init(void) } LOG_DBG("Marked current image as OK"); - ret = boot_erase_img_bank(FIXED_PARTITION_ID(SLOT1_LABEL)); + ret = boot_erase_img_bank(flash_img_get_upload_slot()); if (ret < 0) { LOG_ERR("Failed to erase second slot: %d", ret); return ret; diff --git a/tests/kernel/smp/testcase.yaml b/tests/kernel/smp/testcase.yaml index 650ed72c2088a..725a972ff043f 100644 --- a/tests/kernel/smp/testcase.yaml +++ b/tests/kernel/smp/testcase.yaml @@ -31,6 +31,9 @@ tests: - smp ignore_faults: true filter: (CONFIG_MP_MAX_NUM_CPUS > 1) + platform_exclude: + - qemu_riscv64/qemu_virt_riscv64/smp # qemu_riscv64 doesn't support custom ROM offset + - qemu_riscv32/qemu_virt_riscv32/smp # qemu_riscv32 doesn't support custom ROM offset extra_configs: - CONFIG_SCHED_CPU_MASK=y - CONFIG_ROM_START_OFFSET=0x80