Torsten Robitzki
Torsten Robitzki

Reputation: 2555

How to write the start address of a section to a dedicated location in ROM

In a bare metal project, I need to write the start address of the ROM section to a dedicated address. What I've found so far is something like this definition in the linker script:

MEMORY{
    ROM  (rx)  : ORIGIN = 0x00018000, LENGTH = 0x8000
    UICR (r)   : ORIGIN = 0x10001000, LENGTH = 0x400
}

SECTIONS {
    .bootloader_addr 0x10001014 :
    {
        KEEP(*(.bootloader_addr))
    } > UICR
}

and to define the value that is to be placed at 0x10001014 I could add this somewhere in a C++ file:

std::uint32_t uicr_bootloader_start_address 
    __attribute__((section(".bootloader_addr"),used)) = 
        0x18000;

Does someone have an idea how I could avoid having to declare the constant integer and to use the linker to directly write the startadress of the code section to 0x10001014?

Upvotes: 0

Views: 911

Answers (1)

hcs
hcs

Reputation: 1534

I haven't used this myself, but ld supports a LONG(expr) command that should insert a 4-byte literal into the binary.

Upvotes: 1

Related Questions