From 32399901f03a1901371363080de5a0c10abd8802 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Tue, 1 Sep 2020 10:08:59 +0200 Subject: [PATCH] fe310: Unify linker scripts Similar to the cortex-m common linker scripts, the RISC-V linker scripts can be unified easily, requiring only the memory addresses and lengths. This simplifies adding new RISC-V CPU's later --- cpu/fe310/Makefile.include | 31 +++++++++++++++++++ .../ldscripts/{fe310_g002.ld => fe310.ld} | 10 +++--- cpu/fe310/ldscripts/fe310_g000.ld | 28 ----------------- cpu/fe310/ldscripts/fe310_vars.ld | 23 ++++++++++++++ 4 files changed, 60 insertions(+), 32 deletions(-) rename cpu/fe310/ldscripts/{fe310_g002.ld => fe310.ld} (51%) delete mode 100644 cpu/fe310/ldscripts/fe310_g000.ld create mode 100644 cpu/fe310/ldscripts/fe310_vars.ld diff --git a/cpu/fe310/Makefile.include b/cpu/fe310/Makefile.include index 0b93159caa..55d1ac9ab5 100644 --- a/cpu/fe310/Makefile.include +++ b/cpu/fe310/Makefile.include @@ -1,3 +1,34 @@ CFLAGS += -Wno-pedantic +RAM_START_ADDR ?= 0x80000000 +RAM_LEN ?= 16K + +ifeq ($(CPU_MODEL), fe310_g000) + ROM_START_ADDR ?= 0x20400000 + ROM_LEN ?= 0x1fc00000 +else ifeq ($(CPU_MODEL), fe310_g002) + ROM_START_ADDR ?= 0x20010000 + ROM_LEN ?= 0x0006a120 +endif + +# All variables must be defined in the CPU configuration when using the common +# `ldscripts/fe310.ld` +ifneq (,$(ROM_START_ADDR)$(RAM_START_ADDR)$(ROM_LEN)$(RAM_LEN)) + $(if $(ROM_START_ADDR),,$(error ROM_START_ADDR is not defined)) + $(if $(RAM_START_ADDR),,$(error RAM_START_ADDR is not defined)) + $(if $(ROM_LEN),,$(error ROM_LEN is not defined)) + $(if $(RAM_LEN),,$(error RAM_LEN is not defined)) + LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_start_addr=$(ROM_START_ADDR) + LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_start_addr=$(RAM_START_ADDR) + LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_length=$(ROM_LEN) + LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_length=$(RAM_LEN) +endif + +ifneq (,$(ITIM_START_ADDR)) + LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_itim_start_addr=$(ITIM_START_ADDR) + LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_itim_length=$(ITIM_LEN) +endif + +LINKER_SCRIPT ?= fe310.ld + include $(RIOTMAKE)/arch/riscv.inc.mk diff --git a/cpu/fe310/ldscripts/fe310_g002.ld b/cpu/fe310/ldscripts/fe310.ld similarity index 51% rename from cpu/fe310/ldscripts/fe310_g002.ld rename to cpu/fe310/ldscripts/fe310.ld index 980be111c0..c37ec4c519 100644 --- a/cpu/fe310/ldscripts/fe310_g002.ld +++ b/cpu/fe310/ldscripts/fe310.ld @@ -11,18 +11,20 @@ * @{ * * @file - * @brief Memory definitions for the SiFive FE310_G002 + * @brief Memory definitions for the SiFive FE310 * * @author Ken Rabold + * @author Koen Zandberg * * @} */ +INCLUDE fe310_vars.ld MEMORY { - flash (rxai!w) : ORIGIN = 0x20010000, LENGTH = 0x0006a120 - ram (wxa!ri) : ORIGIN = 0x80000000, LENGTH = 0x00004000 - itim (wxa!ri) : ORIGIN = 0x08000000, LENGTH = 0x00002000 + flash (rxai!w) : ORIGIN = _rom_start_addr , LENGTH = _rom_length + ram (wxa!ri) : ORIGIN = _ram_start_addr, LENGTH = _ram_length + itim (wxa!ri) : ORIGIN = _itim_start_addr, LENGTH = _itim_length } INCLUDE fe310_base.ld diff --git a/cpu/fe310/ldscripts/fe310_g000.ld b/cpu/fe310/ldscripts/fe310_g000.ld deleted file mode 100644 index 0886577103..0000000000 --- a/cpu/fe310/ldscripts/fe310_g000.ld +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2017, 2019 Ken Rabold - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @addtogroup cpu_fe310 - * @{ - * - * @file - * @brief Memory definitions for the SiFive FE310_G000 - * - * @author Ken Rabold - * - * @} - */ - -MEMORY -{ - flash (rxai!w) : ORIGIN = 0x20400000, LENGTH = 0x1fc00000 - ram (wxa!ri) : ORIGIN = 0x80000000, LENGTH = 0x00004000 - itim (wxa!ri) : ORIGIN = 0x08000000, LENGTH = 0x00002000 -} - -INCLUDE fe310_base.ld \ No newline at end of file diff --git a/cpu/fe310/ldscripts/fe310_vars.ld b/cpu/fe310/ldscripts/fe310_vars.ld new file mode 100644 index 0000000000..e975736ae1 --- /dev/null +++ b/cpu/fe310/ldscripts/fe310_vars.ld @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2020 Inria + * 2020 Koen Zandberg + * + * @} + */ + +_itim_start_addr = DEFINED( _itim_start_addr ) ? _itim_start_addr : 0x0; +_itim_length = DEFINED( _itim_length ) ? _itim_length : 0x0;