Skip to content

config ROM_START_OFFSET not linked to dependencies #91160

@JordanYates

Description

@JordanYates

Summary

The default values for CONFIG_ROM_START_OFFSET are arbitrarily defined as a value that works for "most" devices, and are not linked to other values that actually drive the required values.

zephyr/Kconfig.zephyr

Lines 130 to 134 in ed7f2e0

config ROM_START_OFFSET
hex
prompt "ROM start offset" if !BOOTLOADER_MCUBOOT
default 0x200 if BOOTLOADER_MCUBOOT
default 0

To provide a concrete example CONFIG_ROM_START_OFFSET is used with MCUboot to place the application with some offset, with the expectation that this offset is where the vector table lives.

However, the linker scripts which actually control the location of the vector table have nothing to do with CONFIG_ROM_START_OFFSET. This is instead controlled (at least for ARM) by CONFIG_NUM_IRQS.

/* When setting TBLOFF in VTOR we must align the offset to the number of
* exception entries in the vector table. The minimum alignment of 32 words
* is sufficient for the 16 ARM Core exceptions and up to 16 HW interrupts.
* For more than 16 HW interrupts, we adjust the alignment by rounding up
* to the next power of two; this restriction guarantees a functional VTOR
* setting in any Cortex-M implementation (might not be required in every
* Cortex-M processor).
*/
. = ALIGN( 1 << LOG2CEIL(4 * (16 + CONFIG_NUM_IRQS)) );

The result of this is that for any SoC where 4 * (16 + CONFIG_NUM_IRQS) is greater than 0x200, the board needs to override ROM_START_OFFSET to work properly with MCUboot. e.g.

config ROM_START_OFFSET
default 0x800 if BOOTLOADER_MCUBOOT

Describe the solution you'd like

The required value for CONFIG_ROM_START_OFFSET is (at least for ARM) dependent solely on NUM_IRQS, which in turn only depends on the SoC. Individual boards should not be required to override this value to get MCUboot working.

Something like the following?

config VTOR_ALIGNMENT
      default 0x200 if ARM && NUM_IRQS < X
      default 0x400 if ARM && NUM_IRQS < Y
      default 0x800 if ARM && NUM_IRQS < Z
      default 0x200

config ROM_START_OFFSET
        default VTOR_ALIGNMENT if BOOTLOADER_MCUBOOT 
 	default 0 

Alternatives

Do nothing, all praise Ctrl-C & Ctrl-V

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions