[U-Boot] [PATCH 21/21] RFC: Makefile: Build U-Boot as a library
Simon Glass
sjg at chromium.org
Sat Nov 24 04:29:44 UTC 2018
As an experiment, build U-Boot as a library, u-boot.o, so it can be used
by other open-source software. Update the sandbox build rules to suit.
This has not been tested in any meaningful way. It breaks sandbox_spl and
all x86 boards.
I am interested in feedback as to how useful this might be.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Makefile | 9 ++++++++-
arch/sandbox/config.mk | 10 ++++------
scripts/Makefile.spl | 17 +++++++++++++++--
3 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/Makefile b/Makefile
index d82772e7786..c8236de1463 100644
--- a/Makefile
+++ b/Makefile
@@ -1379,7 +1379,14 @@ cmd_smap = \
$(CC) $(c_flags) -DSYSTEM_MAP="\"$${smap}\"" \
-c $(srctree)/common/system_map.c -o common/system_map.o
-u-boot: $(u-boot-init) $(u-boot-main) u-boot.lds FORCE
+quiet_cmd_u-boot-lib ?= LIB $@
+ cmd_u-boot-lib ?= $(LD) -r --exclude-libs ALL \
+ --start-group $(u-boot-main) --end-group -o $@
+
+u-boot.o: $(u-boot-init) $(u-boot-main) u-boot.lds FORCE
+ +$(call if_changed,u-boot-lib)
+
+u-boot: u-boot.o FORCE
+$(call if_changed,u-boot__)
ifeq ($(CONFIG_KALLSYMS),y)
$(call cmd,smap)
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 7226b7be428..0f30f9db0b2 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -17,14 +17,12 @@ PLATFORM_CPPFLAGS += $(shell sdl-config --cflags)
endif
endif
-cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
- -Wl,--start-group $(u-boot-main) -Wl,--end-group \
- $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map
+cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds \
+ u-boot.o $(u-boot-init) \
+ $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map \
cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
- $(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
- -Wl,--start-group $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
- $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) -Wl,--end-group \
+ u-boot-spl.o $(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot-spl.map -Wl,--gc-sections)
CONFIG_ARCH_DEVICE_TREE := sandbox
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 7416abec62e..17c44424ceb 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -349,6 +349,20 @@ cmd_sunxi_spl_image_builder = $(objtree)/tools/sunxi-spl-image-builder \
$(obj)/sunxi-spl-with-ecc.bin: $(obj)/sunxi-spl.bin
$(call if_changed,sunxi_spl_image_builder)
+quiet_cmd_u-boot-spl-lib ?= LIB $@
+ cmd_u-boot-spl-lib ?= $(LD) -r --start-group $(u-boot-spl-main) \
+ --end-group -o $@
+
+$(obj)/u-boot-spl.o: $(u-boot-spl-platdata) $(u-boot-spl-init) \
+ $(u-boot-spl-main) FORCE
+ (cd $(obj) && $(LD) -r $(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
+ --start-group \
+ $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
+ $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
+ --end-group \
+ -o $(patsubst $(obj)/%,%,$@))
+ +$(call if_changed,u-boot-spl-lib)
+
# Rule to link u-boot-spl
# May be overridden by arch/$(ARCH)/config.mk
quiet_cmd_u-boot-spl ?= LD $@
@@ -359,8 +373,7 @@ quiet_cmd_u-boot-spl ?= LD $@
--end-group \
$(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN))
-$(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \
- $(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE
+$(obj)/$(SPL_BIN): $(obj)/u-boot-spl.o $(obj)/u-boot-spl.lds FORCE
$(call if_changed,u-boot-spl)
$(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
--
2.20.0.rc0.387.gc7a69e6b6c-goog
More information about the U-Boot
mailing list