Close

SparkFun RED-V board linker file

A project log for Sparkfun RED-V bare metal

I wanted to learn RISC-V, not on an emulator, but on a real bare metal RISC-V processor. Even though Sparkfun RED-V is no longer produced.

olaf-baeyensOlaf Baeyens 10/21/2024 at 15:580 Comments

Not a lot of documentation was found for the SparkFun RED-V board about a good working linker file but this one works great.

Took a lot of trial and error to get it functioning,

/* Specify the architecture */
OUTPUT_ARCH("riscv")

/* Define memory regions */
MEMORY
{
    FLASH (rx) : ORIGIN = 0x20010000, LENGTH = 16K
    RAM  (rwx) : ORIGIN = 0x80000000, LENGTH = 16K
}

/* Entry point of the program */
ENTRY(_start)

/* Define sections */
SECTIONS
{
    /* Code and read-only data goes into FLASH */
    .text : {
        _stext = .;
        KEEP(*(.text))
        KEEP(*(.text.*))
        KEEP(*(.rodata))
        KEEP(*(.rodata.*))
        _etext = .;
    } > FLASH

	.gnu_build_id : { 
		*(.note.gnu.build-id) 
	} > FLASH

    /* Read-write data goes into RAM */
    .data : {
        _sdata = .;
	_data_flash = LOADADDR(.data);
        KEEP(*(.data))
        KEEP(*(.data.*))
        _edata = .;
    } > RAM AT> FLASH

    /* Uninitialized data goes into RAM */
    .bss : {
        _sbss = .;
        KEEP(*(.bss))
        KEEP(*(.bss.*))
        KEEP(*(.noinit))
        _ebss = .;
    } > RAM

    /* The stack also goes into RAM */
    .stack ORIGIN(RAM) + LENGTH(RAM) - 0x1000 : {
        . = . + 0x1000;
        _estack = .;
    } > RAM

    /* Define symbols for the memory boundaries */
    _sflash = ORIGIN(FLASH);
    _eflash = ORIGIN(FLASH) + LENGTH(FLASH);
    _sram = ORIGIN(RAM);
    _eram = ORIGIN(RAM) + LENGTH(RAM);
}

Discussions