Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions arch/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions include/zephyr/dfu/flash_img.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions include/zephyr/dfu/mcuboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion modules/Kconfig.mcuboot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions soc/lowrisc/opentitan/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions subsys/dfu/boot/mcuboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion subsys/dfu/img_util/flash_img.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#include <stdio.h>
#include <string.h>
#include <zephyr/dfu/flash_img.h>
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/storage/flash_map.h>
#include <zephyr/storage/stream_flash.h>

#ifdef CONFIG_IMG_ERASE_PROGRESSIVELY
#include <bootutil/bootutil_public.h>
#include <zephyr/dfu/mcuboot.h>
#endif

#include <zephyr/devicetree.h>
Expand All @@ -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))

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion subsys/mgmt/hawkbit/hawkbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions tests/kernel/smp/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading