soc/integration/builder: Allow linking in external software packages.

This commit is contained in:
Vegard Storheil Eriksen 2021-06-13 14:02:42 +02:00
parent 6b8a35a2f8
commit 61636f1248
2 changed files with 23 additions and 22 deletions

View File

@ -46,9 +46,6 @@ soc_software_packages = [
"libliteeth", "libliteeth",
"liblitesdcard", "liblitesdcard",
"liblitesata", "liblitesata",
# BIOS.
"bios"
] ]
# Builder ------------------------------------------------------------------------------------------ # Builder ------------------------------------------------------------------------------------------
@ -105,16 +102,25 @@ class Builder:
# Documentation # Documentation
self.generate_doc = generate_doc self.generate_doc = generate_doc
# List software packages. # List software packages and libraries.
self.software_packages = [] self.software_packages = []
self.software_libraries = []
for name in soc_software_packages: for name in soc_software_packages:
self.add_software_package(name) self.add_software_package(name)
if name == "libbase":
name += "-nofloat"
self.add_software_library(name)
def add_software_package(self, name, src_dir=None): def add_software_package(self, name, src_dir=None):
if src_dir is None: if src_dir is None:
src_dir = os.path.join(soc_directory, "software", name) src_dir = os.path.join(soc_directory, "software", name)
self.software_packages.append((name, src_dir)) self.software_packages.append((name, src_dir))
def add_software_library(self, name):
self.software_libraries.append(name)
def _generate_includes(self): def _generate_includes(self):
# Generate Include/Generated directories. # Generate Include/Generated directories.
_create_dir(self.include_dir) _create_dir(self.include_dir)
@ -123,12 +129,18 @@ class Builder:
# Generate BIOS files when the SoC uses it. # Generate BIOS files when the SoC uses it.
with_bios = self.soc.cpu_type not in [None, "zynq7000"] with_bios = self.soc.cpu_type not in [None, "zynq7000"]
if with_bios: if with_bios:
self.add_software_package("bios")
# Generate Variables to variables.mak. # Generate Variables to variables.mak.
variables_contents = [] variables_contents = []
def define(k, v): def define(k, v):
variables_contents.append("{}={}".format(k, _makefile_escape(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. # Define the CPU variables.
for k, v in export.get_cpu_mak(self.soc.cpu, self.compile_software): for k, v in export.get_cpu_mak(self.soc.cpu, self.compile_software):
define(k, v) define(k, v)

View File

@ -54,28 +54,17 @@ endif
bios.elf: $(BIOS_DIRECTORY)/linker.ld $(OBJECTS) bios.elf: $(BIOS_DIRECTORY)/linker.ld $(OBJECTS)
vpath %.a $(PACKAGES:%=../%)
%.elf: ../libbase/crt0.o \ %.elf: ../libbase/crt0.o $(LIBS:%=%.a)
../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
$(CC) $(LDFLAGS) -T $(BIOS_DIRECTORY)/linker.ld -N -o $@ \ $(CC) $(LDFLAGS) -T $(BIOS_DIRECTORY)/linker.ld -N -o $@ \
../libbase/crt0.o \ ../libbase/crt0.o \
$(OBJECTS) \ $(OBJECTS) \
-L../libcompiler_rt \ $(PACKAGES:%=-L../%) \
-L../libbase \ -Wl,--whole-archive \
-L../liblitedram \ -Wl,--gc-sections \
-L../libliteeth \ $(LIBS:lib%=-l%) \
-L../liblitespi \
-L../libfatfs \
-L../liblitesdcard \
-L../liblitesata \
-llitedram -lliteeth -llitespi -lfatfs -llitesdcard -llitesata -lbase-nofloat -lcompiler_rt
ifneq ($(OS),Windows_NT) ifneq ($(OS),Windows_NT)
chmod -x $@ chmod -x $@