Commit 5ba16d22 authored by Federico Vaga's avatar Federico Vaga

sw:fw: builing system needs linker script MEMORY command from users

Mock Turtle CPUs' memory size and share memory size are configurable
at synthesis time. For this reason it is not possible to provide an
universal linker script that works for any Mock Turtle instance.

The firmware developer must provide a MEMORY command that describes
the memories on which the firmware will run.
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent ac69fe98
/* This is a generic configuration that should work on
the SPEC/SVEC demos FPGA */
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
/* This is a generic configuration that should work on
the SPEC/SVEC demos FPGA */
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
/* This is a generic configuration that should work on
the SPEC/SVEC demos FPGA */
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
/* This is a generic configuration that should work on
the SPEC/SVEC demos FPGA */
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
/* This is a generic configuration that should work on
the SPEC/SVEC demos FPGA */
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
/* This is a generic configuration that should work on
the SPEC/SVEC demos FPGA */
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
/* This is a generic configuration that should work on
the SPEC/SVEC demos FPGA */
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
/* This is a generic configuration that should work on
the SPEC/SVEC demos FPGA */
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
......@@ -56,7 +56,8 @@ you have to specify what to build, for example::
# Optional (prefer default when possible)
EXTRA_CFLAGS :=
MOCKTURTLE_LDSCRIPT := myfirmware.ld
TRTL_LD_SCRIPT := myfirmware.ld
TRTL_LD_DIR := path/to/linker-script/directory
Here the list of supported TBuild variables
......@@ -71,10 +72,38 @@ OUTPUT
EXTRA_CFLAGS
(Optional) Additional compiler options.
MOCKTURTLE_LDSCRIPT
TRTL_LD_SCRIPT
(Optional) Local path to the linker script.
The default is the standard Mock Turtle linker script.
TRTL_LD_DIR
(Optional) Path to the directory containing the ``trtl-memory.ld`` file.
By default this is set to the source's directory
Another requirement for a successful build is a linker script file containing
the ``MEMORY`` command. This linker script file must be named
``trtl-memory.ld`` and its content should look like this::
MEMORY
{
ram : ORIGIN = 0x00000000, LENGTH = 32768 - 2048
stack : ORIGIN = 32768 - 2048, LENGTH = 2048
smem : ORIGIN = 0x40200000, LENGTH = 65536
}
Unless you are modifying the Mock Turtle core itself, the following values are
fixed: ``ORIGIN = 0x00000000`` for the *ram*, ``ORIGIN = 0x40200000`` for
the *smem*. The ``LENGTH`` value for *ram* depends on the CPU memory size on
which the firmware will run; the ``LENGTH`` value for *smem* depends on the
Mock Turtle shared memory size; both these values depend on the FPGA synthesis
configuration.
.. note::
It is possible to add more linker script commands to ``trtl-memory.ld`` but
then the behavior is undefined. If you need more linker script commands,
please write your own linker script file and pass it to the build system
by using ``TRTL_LD_SCRIPT``.
You can build such firmware application by calling ``make`` from the
application directory (where the ``TBuild`` file is) like this::
......
......@@ -37,6 +37,9 @@ CROSS_COMPILE_TARGET ?= riscv32-elf-
CFLAGS += -D__TRTL_FIRMWARE__
CFLAGS += -mabi=ilp32 -march=rv32im -ffunction-sections -fdata-sections
LDFLAGS += -lgcc -lc -Wl,--gc-sections
TRTL_LD_DIR ?= $(src)
LDFLAGS += -L$(TRTL_FW)/urv/
LDFLAGS += -L$(TRTL_LD_DIR)
# provide search patch for sources
vpath %.c $(TRTL_FW)
......@@ -98,7 +101,9 @@ OBJS_BUILD = $(addprefix $(BUILDDIR)/, $(OBJS))
OBJDIR_BUILD = $(addprefix $(BUILDDIR)/, $(OBJDIR))
OBJDIR_BUILD += $(BUILDDIR)
MOCKTURTLE_LDSCRIPT ?= $(TRTL_FW)/urv/mockturtle.ld
TRTL_LD_SCRIPT ?= $(TRTL_FW)/urv/mockturtle.ld
.PHONY: all clean cleanall
......@@ -127,9 +132,9 @@ $(OBJDIR_BUILD):
$(OBJS_BUILD): | $(AUTOCONF)
$(OBJS_BUILD): | $(OBJDIR_BUILD)
$(build_output).elf: $(addprefix $(TRTL_SW)/include/mockturtle/hw/,$(WBGEN_HEADERS)) $(MOCKTURTLE_LDSCRIPT) $(OBJS_BUILD)
$(build_output).elf: $(addprefix $(TRTL_SW)/include/mockturtle/hw/,$(WBGEN_HEADERS)) $(TRTL_LD_SCRIPT) $(OBJS_BUILD)
$(warning $(OBJS_BUILD))
${CC} $(CFLAGS) $(LDFLAGS) -o $(build_output).elf -nostartfiles $(OBJS_BUILD) -T $(MOCKTURTLE_LDSCRIPT)
${CC} $(CFLAGS) $(LDFLAGS) -o $(build_output).elf -nostartfiles $(OBJS_BUILD) -T $(TRTL_LD_SCRIPT)
$(build_output).bin: $(build_output).elf
${OBJCOPY} --remove-section .smem -O binary $(build_output).elf $(build_output).bin
......
OUTPUT_FORMAT("elf32-littleriscv")
ENTRY(_start)
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
SECTIONS
{
/*--------------------------------------------------------------------*/
/* Code and read-only segment */
/*--------------------------------------------------------------------*/
/* Begining of code and text segment */
. = 0x00000000;
_ftext = .;
PROVIDE( eprol = . );
/* text: Program code section */
.text :
{
*(.boot)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
} > ram
/* init: Code to execute before main (called by crt0.S) */
.init :
{
KEEP( *(.init) )
} > ram
/* fini: Code to execute after main (called by crt0.S) */
.fini :
{
KEEP( *(.fini) )
} > ram
/* rodata: Read-only data */
.rodata :
{
*(.rdata)
*(.rodata)
*(.rodata.*)
*(.gnu.linkonce.r.*)
} > ram
/* End of code and read-only segment */
PROVIDE( etext = . );
_etext = .;
/*--------------------------------------------------------------------*/
/* Global constructor/destructor segement */
/*--------------------------------------------------------------------*/
/* The .ctors/.dtors sections are special sections which contain a
list of constructor/destructor function pointers. crtbegin.o
includes code in a .init section which goes through the .ctors list
and calls each constuctor. crtend.o includes code in a .fini
section which goes through the .dtors list and calls each
destructor. crtbegin.o includes a special null pointer in its own
.ctors/.dtors sections which acts as a start indicator for those
lists. crtend.o also includes a special null pointer in its own
.ctors/.dtors sections which acts as an end indictor. The linker
commands below are setup so that crtbegin.o's .ctors/.dtors
sections are always first and crtend.o's .ctors/.dtors sections are
always last. This is the only way the list of functions will have
the begin and end indicators in the right place. */
/* ctors : Array of global constructor function pointers */
/*--------------------------------------------------------------------*/
/* Initialized data segment */
/*--------------------------------------------------------------------*/
/* Start of initialized data segment */
. = ALIGN(16);
_fdata = .;
/* data: Writable data */
.data :
{
*(.data)
*(.data.*)
*(.gnu.linkonce.d.*)
} > ram
/* End of initialized data segment */
PROVIDE( edata = . );
_edata = .;
/* Have _gp point to middle of sdata/sbss to maximize displacement range */
. = ALIGN(16);
_gp = . + 0x800;
/* Writable small data segment */
.sdata :
{
*(.sdata)
*(.sdata.*)
*(.srodata.*)
*(.gnu.linkonce.s.*)
} > ram
/*--------------------------------------------------------------------*/
/* Uninitialized data segment */
/*--------------------------------------------------------------------*/
/* Start of uninitialized data segment */
. = ALIGN(8);
_fbss = .;
/* Writable uninitialized small data segment */
.sbss :
{
*(.sbss)
*(.sbss.*)
*(.gnu.linkonce.sb.*)
} > ram
/* bss: Uninitialized writeable data section */
. = .;
_bss_start = .;
.bss :
{
*(.bss)
*(.bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
} > ram
/* End of uninitialized data segment (used by syscalls.c for heap) */
PROVIDE( end = . );
_end = ALIGN(8);
.smem : { *(.smem) } > smem
PROVIDE(_endram = ORIGIN(stack));
PROVIDE(_fexception_stack = ORIGIN(stack) + LENGTH(stack) - 4);
PROVIDE(_fstack = ORIGIN(stack) + LENGTH(stack) - 4 - 0x400 );
}
INCLUDE trtl-memory.ld
INCLUDE trtl-sections.ld
SECTIONS
{
/*--------------------------------------------------------------------*/
/* Code and read-only segment */
/*--------------------------------------------------------------------*/
/* Begining of code and text segment */
. = 0x00000000;
_ftext = .;
PROVIDE( eprol = . );
/* text: Program code section */
.text :
{
*(.boot)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
} > ram
/* init: Code to execute before main (called by crt0.S) */
.init :
{
KEEP( *(.init) )
} > ram
/* fini: Code to execute after main (called by crt0.S) */
.fini :
{
KEEP( *(.fini) )
} > ram
/* rodata: Read-only data */
.rodata :
{
*(.rdata)
*(.rodata)
*(.rodata.*)
*(.gnu.linkonce.r.*)
} > ram
/* End of code and read-only segment */
PROVIDE( etext = . );
_etext = .;
/*--------------------------------------------------------------------*/
/* Global constructor/destructor segement */
/*--------------------------------------------------------------------*/
/* The .ctors/.dtors sections are special sections which contain a
list of constructor/destructor function pointers. crtbegin.o
includes code in a .init section which goes through the .ctors list
and calls each constuctor. crtend.o includes code in a .fini
section which goes through the .dtors list and calls each
destructor. crtbegin.o includes a special null pointer in its own
.ctors/.dtors sections which acts as a start indicator for those
lists. crtend.o also includes a special null pointer in its own
.ctors/.dtors sections which acts as an end indictor. The linker
commands below are setup so that crtbegin.o's .ctors/.dtors
sections are always first and crtend.o's .ctors/.dtors sections are
always last. This is the only way the list of functions will have
the begin and end indicators in the right place. */
/* ctors : Array of global constructor function pointers */
/*--------------------------------------------------------------------*/
/* Initialized data segment */
/*--------------------------------------------------------------------*/
/* Start of initialized data segment */
. = ALIGN(16);
_fdata = .;
/* data: Writable data */
.data :
{
*(.data)
*(.data.*)
*(.gnu.linkonce.d.*)
} > ram
/* End of initialized data segment */
PROVIDE( edata = . );
_edata = .;
/* Have _gp point to middle of sdata/sbss to maximize displacement range */
. = ALIGN(16);
_gp = . + 0x800;
/* Writable small data segment */
.sdata :
{
*(.sdata)
*(.sdata.*)
*(.srodata.*)
*(.gnu.linkonce.s.*)
} > ram
/*--------------------------------------------------------------------*/
/* Uninitialized data segment */
/*--------------------------------------------------------------------*/
/* Start of uninitialized data segment */
. = ALIGN(8);
_fbss = .;
/* Writable uninitialized small data segment */
.sbss :
{
*(.sbss)
*(.sbss.*)
*(.gnu.linkonce.sb.*)
} > ram
/* bss: Uninitialized writeable data section */
. = .;
_bss_start = .;
.bss :
{
*(.bss)
*(.bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
} > ram
/* End of uninitialized data segment (used by syscalls.c for heap) */
PROVIDE( end = . );
_end = ALIGN(8);
.smem : { *(.smem) } > smem
PROVIDE(_endram = ORIGIN(stack));
PROVIDE(_fexception_stack = ORIGIN(stack) + LENGTH(stack) - 4);
PROVIDE(_fstack = ORIGIN(stack) + LENGTH(stack) - 4 - 0x400 );
}
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
../trtl-memory.ld
\ No newline at end of file
/* This is a generic configuration that should work on
the SPEC/SVEC demos FPGA */
MEMORY
{
ram :
ORIGIN = 0x00000000,
LENGTH = 32768 - 2048
stack :
ORIGIN = 32768 - 2048,
LENGTH = 2048
smem :
ORIGIN = 0x40200000,
LENGTH = 65536
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment