Skip to content

struct devices should be allocated in ROM, not RAM #36035

@mbolivar-nordic

Description

@mbolivar-nordic

Somebody please prove me wrong by showing me I'm missing something obvious...

Pull request #24873 marked all devices const as a fix for issue #27399. The problem description says:

At this point all device instance could be made constant to save RAM.

However, despite being const, devices are still linked into RAM, at least on Arm Cortex-M:

$ west build -b nrf52840dk_nrf52840 samples/hello_world/ 

$ arm-none-eabi-gdb build/zephyr/zephyr.elf -q -ex 'x __device_start' -ex q
Reading symbols from build/zephyr/zephyr.elf...
0x20000040 <__device_dts_ord_26>:	0x0000406a

Note 0x20000000 is the base address of SRAM in the SoC memory map.

It seems that #24873 did not actually save any RAM for devices.

Since the device related linker section is in include/linker/common-ram.h:

SECTION_DATA_PROLOGUE(devices,,)

I'm guessing this bug applies to most if not all targets.

Describe the solution you'd like

I'm not sure if this is just an oversight or if there's something else blocking the fix, but I moved the linker section to ROM and it seems to work in basic testing, and produces the RAM savings I expected: #36032.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: Device ModelbugThe issue is a bug, or the PR is fixing a bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions