From 61636f1248501761fbe6bf0d8ee50f5379bd4aed Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 13 Jun 2021 14:02:42 +0200 Subject: [PATCH 1/2] soc/integration/builder: Allow linking in external software packages. --- litex/soc/integration/builder.py | 20 ++++++++++++++++---- litex/soc/software/bios/Makefile | 25 +++++++------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/litex/soc/integration/builder.py b/litex/soc/integration/builder.py index 643893283..afa4b2801 100644 --- a/litex/soc/integration/builder.py +++ b/litex/soc/integration/builder.py @@ -46,9 +46,6 @@ soc_software_packages = [ "libliteeth", "liblitesdcard", "liblitesata", - - # BIOS. - "bios" ] # Builder ------------------------------------------------------------------------------------------ @@ -105,16 +102,25 @@ class Builder: # Documentation self.generate_doc = generate_doc - # List software packages. + # List software packages and libraries. self.software_packages = [] + self.software_libraries = [] + for name in soc_software_packages: self.add_software_package(name) + if name == "libbase": + name += "-nofloat" + self.add_software_library(name) + def add_software_package(self, name, src_dir=None): if src_dir is None: src_dir = os.path.join(soc_directory, "software", name) self.software_packages.append((name, src_dir)) + def add_software_library(self, name): + self.software_libraries.append(name) + def _generate_includes(self): # Generate Include/Generated directories. _create_dir(self.include_dir) @@ -123,12 +129,18 @@ class Builder: # Generate BIOS files when the SoC uses it. with_bios = self.soc.cpu_type not in [None, "zynq7000"] if with_bios: + self.add_software_package("bios") # Generate Variables to variables.mak. variables_contents = [] def define(k, v): variables_contents.append("{}={}".format(k, _makefile_escape(v))) + # Define packages and libraries. + define("PACKAGES", " ".join(name for name, src_dir in self.software_packages)) + define("PACKAGE_DIRS", " ".join(src_dir for name, src_dir in self.software_packages)) + define("LIBS", " ".join(self.software_libraries)) + # Define the CPU variables. for k, v in export.get_cpu_mak(self.soc.cpu, self.compile_software): define(k, v) diff --git a/litex/soc/software/bios/Makefile b/litex/soc/software/bios/Makefile index ea1b00b26..6c0a6aac8 100755 --- a/litex/soc/software/bios/Makefile +++ b/litex/soc/software/bios/Makefile @@ -54,28 +54,17 @@ endif bios.elf: $(BIOS_DIRECTORY)/linker.ld $(OBJECTS) +vpath %.a $(PACKAGES:%=../%) -%.elf: ../libbase/crt0.o \ - ../libcompiler_rt/libcompiler_rt.a \ - ../libbase/libbase-nofloat.a \ - ../liblitedram/liblitedram.a \ - ../libliteeth/libliteeth.a \ - ../liblitespi/liblitespi.a \ - ../libfatfs/libfatfs.a \ - ../liblitesdcard/liblitesdcard.a \ - ../liblitesata/liblitesata.a +%.elf: ../libbase/crt0.o $(LIBS:%=%.a) $(CC) $(LDFLAGS) -T $(BIOS_DIRECTORY)/linker.ld -N -o $@ \ ../libbase/crt0.o \ $(OBJECTS) \ - -L../libcompiler_rt \ - -L../libbase \ - -L../liblitedram \ - -L../libliteeth \ - -L../liblitespi \ - -L../libfatfs \ - -L../liblitesdcard \ - -L../liblitesata \ - -llitedram -lliteeth -llitespi -lfatfs -llitesdcard -llitesata -lbase-nofloat -lcompiler_rt + $(PACKAGES:%=-L../%) \ + -Wl,--whole-archive \ + -Wl,--gc-sections \ + $(LIBS:lib%=-l%) \ + ifneq ($(OS),Windows_NT) chmod -x $@ From 8d527a1f3fd9d03417bb4cc57556f420ab038764 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 13 Jun 2021 14:03:43 +0200 Subject: [PATCH 2/2] soc/software/bios: Allow registering init functions. --- litex/soc/software/bios/helpers.c | 8 ++++++++ litex/soc/software/bios/helpers.h | 1 + litex/soc/software/bios/init.h | 10 ++++++++++ litex/soc/software/bios/linker.ld | 7 +++++++ litex/soc/software/bios/main.c | 2 ++ 5 files changed, 28 insertions(+) create mode 100644 litex/soc/software/bios/init.h diff --git a/litex/soc/software/bios/helpers.c b/litex/soc/software/bios/helpers.c index 746a792c3..5c1686759 100644 --- a/litex/soc/software/bios/helpers.c +++ b/litex/soc/software/bios/helpers.c @@ -10,6 +10,7 @@ #include "readline.h" #include "helpers.h" #include "command.h" +#include "init.h" extern unsigned int _ftext, _edata_rom; @@ -126,3 +127,10 @@ struct command_struct *command_dispatcher(char *command, int nb_params, char **p return NULL; } + +void init_dispatcher(void) +{ + for (const init_func* fp = __bios_init_start; fp != __bios_init_end; fp++) { + (*fp)(); + } +} diff --git a/litex/soc/software/bios/helpers.h b/litex/soc/software/bios/helpers.h index 6f1f2deeb..23853afce 100644 --- a/litex/soc/software/bios/helpers.h +++ b/litex/soc/software/bios/helpers.h @@ -5,5 +5,6 @@ void dump_bytes(unsigned int *ptr, int count, unsigned long addr); void crcbios(void); int get_param(char *buf, char **cmd, char **params); struct command_struct *command_dispatcher(char *command, int nb_params, char **params); +void init_dispatcher(void); #endif diff --git a/litex/soc/software/bios/init.h b/litex/soc/software/bios/init.h new file mode 100644 index 000000000..17720f3a8 --- /dev/null +++ b/litex/soc/software/bios/init.h @@ -0,0 +1,10 @@ +#pragma once + +typedef void (*init_func)(void); + +extern init_func const __bios_init_start[]; +extern init_func const __bios_init_end[]; + +#define define_init_func(f) \ + const init_func __bios_init_##f __attribute__((__used__)) \ + __attribute__((__section__(".bios_init"))) = f diff --git a/litex/soc/software/bios/linker.ld b/litex/soc/software/bios/linker.ld index 6ebd50cdd..af6c43be2 100644 --- a/litex/soc/software/bios/linker.ld +++ b/litex/soc/software/bios/linker.ld @@ -41,6 +41,13 @@ SECTIONS PROVIDE_HIDDEN (__bios_cmd_end = .); } > rom + .init : + { + PROVIDE_HIDDEN (__bios_init_start = .); + KEEP(*(.bios_init)) + PROVIDE_HIDDEN (__bios_init_end = .); + } > rom + .data : { . = ALIGN(8); diff --git a/litex/soc/software/bios/main.c b/litex/soc/software/bios/main.c index 5997118f9..4494387af 100644 --- a/litex/soc/software/bios/main.c +++ b/litex/soc/software/bios/main.c @@ -173,6 +173,8 @@ int main(int i, char **c) video_framebuffer_dma_enable_write(1); #endif + init_dispatcher(); + if(sdr_ok) { printf("--============== \e[1mBoot\e[0m ==================--\n"); boot_sequence();