[U-Boot] [PATCH] kbuild/makefile: allow building host tools separately

Sometimes it is required to build only host U-Boot tools without building U-Boot itself for either board.
For example: * In "buildroot" "uboot-tools" could be built for host just to have an ability to create uImage. * Linux distributions ship "mkimage" utility as a separate substance.
This patch allows building host U-Boot tools separately from U-Boot itself and what is more important user only needs to have host compiler (gcc).
To build host tools just execute: ===== make tools HOST_TOOLS_ONLY=yes =====
Without this patch to generate tools user needs: 1. Configure any existing board with "make XXX_config" 2. Execute tools building but still cross-compiler will be invoked and if there's no proper cross-compiler in PATH compilation will fail.
Signed-off-by: Alexey Brodkin abrodkin@synopsys.com
Cc: Masahiro Yamada yamada.m@jp.panasonic.com Cc: Tom Rini trini@ti.com Cc: Simon Glass sjg@chromium.org --- Kbuild | 5 +++++ Makefile | 7 +++++++ 2 files changed, 12 insertions(+)
diff --git a/Kbuild b/Kbuild index 1d89761..b5e348d 100644 --- a/Kbuild +++ b/Kbuild @@ -4,6 +4,9 @@ # 1) Generate generic-asm-offsets.h # 2) Generate asm-offsets.h
+# Don't execute target below if building host tools only +ifneq ($(HOST_TOOLS_ONLY),yes) + ##### # 1) Generate generic-asm-offsets.h
@@ -85,3 +88,5 @@ $(CPUDIR)/$(SOC)/asm-offsets.s: $(CPUDIR)/$(SOC)/asm-offsets.c FORCE
$(obj)/$(offsets-file): $(CPUDIR)/$(SOC)/asm-offsets.s $(call cmd,offsets) + +endif diff --git a/Makefile b/Makefile index b795338..2fb8ea1 100644 --- a/Makefile +++ b/Makefile @@ -481,9 +481,12 @@ ifeq ($(dot-config),1) # load other configuration include $(srctree)/config.mk
+# Don't check for config.mk presence if building host tools only +ifneq ($(HOST_TOOLS_ONLY),yes) ifeq ($(wildcard include/config.mk),) $(error "System not configured - see README") endif +endif
# If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use # that (or fail if absent). Otherwise, search for a linker script in a @@ -994,10 +997,14 @@ ifeq ($(CONFIG_SYS_GENERIC_BOARD),y) @/bin/false endif endif + +# Don't check for ldscript presence if building host tools only +ifneq ($(HOST_TOOLS_ONLY),yes) ifeq ($(wildcard $(LDSCRIPT)),) @echo >&2 " Could not find linker script." @/bin/false endif +endif
archprepare: prepare1 scripts_basic

Hi Alexey,
Sometimes it is required to build only host U-Boot tools without building U-Boot itself for either board.
For example:
- In "buildroot" "uboot-tools" could be built for host just to have an ability to create uImage.
- Linux distributions ship "mkimage" utility as a separate substance.
This patch allows building host U-Boot tools separately from U-Boot itself and what is more important user only needs to have host compiler (gcc).
To build host tools just execute:
make tools HOST_TOOLS_ONLY=yes
This may be the similar discussion to http://u-boot.10912.n7.nabble.com/U-Boot-could-not-cross-compile-u-boot-tool... Providing a separate make target seems preferable.
Maybe like this?
To build host tools just execute: ===== make tools-only =====
And I am not happy about adding ifdef to everywhere.
So, how about a patch like this?
diff --git a/Makefile b/Makefile index c744718..12e1075 100644 --- a/Makefile +++ b/Makefile @@ -409,7 +409,7 @@ timestamp_h := include/generated/timestamp_autogenerated.h
no-dot-config-targets := clean clobber mrproper distclean \ help %docs check% coccicheck \ - ubootversion backup + ubootversion backup tools-only
config-targets := 0 mixed-targets := 0 @@ -1128,6 +1128,9 @@ checkarmreloc: u-boot env: scripts_basic $(Q)$(MAKE) $(build)=tools/$@
+tools-only: scripts_basic + $(Q)$(MAKE) $(build)=tools + tools-all: export HOST_TOOLS_ALL=y tools-all: env tools ;
Best Regards Masahiro Yamada

Hi Masahiro-san,
On Fri, 2014-03-28 at 15:36 +0900, Masahiro Yamada wrote:
Hi Alexey,
This may be the similar discussion to http://u-boot.10912.n7.nabble.com/U-Boot-could-not-cross-compile-u-boot-tool...
It looks not that relevant to me. For example even before switching U-Boot to Kbuild it was not possible to build host tools simply without patching sources/headers or configuring real target. Or I might be missing something here.
Providing a separate make target seems preferable.
Maybe like this?
To build host tools just execute:
make tools-only
Fully agree. I thought about it right after I sent you initial patch.
And I am not happy about adding ifdef to everywhere.
So do I. But I don't see other way around unfortunately.
So, how about a patch like this?
diff --git a/Makefile b/Makefile index c744718..12e1075 100644 --- a/Makefile +++ b/Makefile @@ -409,7 +409,7 @@ timestamp_h := include/generated/timestamp_autogenerated.h
no-dot-config-targets := clean clobber mrproper distclean \ help %docs check% coccicheck \
ubootversion backup
ubootversion backup tools-only
config-targets := 0 mixed-targets := 0 @@ -1128,6 +1128,9 @@ checkarmreloc: u-boot env: scripts_basic $(Q)$(MAKE) $(build)=tools/$@
+tools-only: scripts_basic
$(Q)$(MAKE) $(build)=tools
tools-all: export HOST_TOOLS_ALL=y tools-all: env tools ;
Doesn't work for me: ======== $ make tools-only HOSTCC scripts/basic/fixdep HOSTCC tools/aisimage.o HOSTCC tools/crc32.o HOSTCC tools/default_image.o HOSTCC tools/dumpimage.o In file included from include/version.h:11:0, from tools/dumpimage.c:11: include/timestamp.h:11:47: fatal error: generated/timestamp_autogenerated.h: No such file or directory #include "generated/timestamp_autogenerated.h" ^ compilation terminated. make[1]: *** [tools/dumpimage.o] Error 1 make: *** [tools-only] Error 2 ========
-Alexey

Hi Alexey,
This may be the similar discussion to http://u-boot.10912.n7.nabble.com/U-Boot-could-not-cross-compile-u-boot-tool...
It looks not that relevant to me. For example even before switching U-Boot to Kbuild it was not possible to build host tools simply without patching sources/headers or configuring real target. Or I might be missing something here.
Sorry, I should have explained it more exactly.
What I wanted you to refer is Wolfgang's comment in that thread.
This part: Wolfgang wrote:
I'm not really hapy with the additional CROSS_BUILD_TOOLS paramert - but this may be a matter of taste, so the following is just a thought and a question:
Would it make more sense to provide a sparate make target instead?
Say, something like this:
Build tools for host make CROSS_COMPILE=<your_gcc_prefix tools Build tools for target make CROSS_COMPILE=<your_gcc_prefix cross_tools
?
And then we chose a new make target "cross_tools" rather than a new option "CROSS_BUILD_TOOLS=1".
That is similar to what is happening here.
I wanted to show retionale why a make target "tools-only" is better than "HOST_TOOLS_ONLY=yes".
Doesn't work for me:
$ make tools-only HOSTCC scripts/basic/fixdep HOSTCC tools/aisimage.o HOSTCC tools/crc32.o HOSTCC tools/default_image.o HOSTCC tools/dumpimage.o In file included from include/version.h:11:0, from tools/dumpimage.c:11: include/timestamp.h:11:47: fatal error: generated/timestamp_autogenerated.h: No such file or directory #include "generated/timestamp_autogenerated.h" ^ compilation terminated. make[1]: *** [tools/dumpimage.o] Error 1 make: *** [tools-only] Error 2 ========
Oops - My bad. I was disabling timestamp.
Could you fix like this?
tools-only: scripts_basic $(version_h) $(timestamp_h) $(Q)$(MAKE) $(build)=tools
It worked for me.
$ make tools-only HOSTCC scripts/basic/fixdep CHK include/config/uboot.release UPD include/config/uboot.release CHK include/generated/version_autogenerated.h UPD include/generated/version_autogenerated.h CHK include/generated/timestamp_autogenerated.h UPD include/generated/timestamp_autogenerated.h HOSTCC tools/aisimage.o HOSTCC tools/crc32.o HOSTCC tools/default_image.o HOSTCC tools/dumpimage.o HOSTCC tools/fdt.o HOSTCC tools/fdt_ro.o HOSTCC tools/fdt_rw.o HOSTCC tools/fdt_strerror.o HOSTCC tools/fdt_wip.o HOSTCC tools/fit_image.o HOSTCC tools/image-fit.o HOSTCC tools/image-host.o HOSTCC tools/image.o HOSTCC tools/imagetool.o HOSTCC tools/imximage.o HOSTCC tools/kwbimage.o HOSTCC tools/md5.o HOSTCC tools/mkenvimage.o HOSTCC tools/mkimage.o HOSTCC tools/mxsimage.o HOSTCC tools/omapimage.o HOSTCC tools/os_support.o HOSTCC tools/pblimage.o HOSTCC tools/sha1.o HOSTCC tools/ublimage.o HOSTLD tools/mkenvimage HOSTLD tools/dumpimage HOSTLD tools/mkimage HOSTCC tools/proftool
Best Regards Masahiro Yamada

Hi Masahiro-san,
On Mon, 2014-03-31 at 10:43 +0900, Masahiro Yamada wrote:
I wanted to show retionale why a make target "tools-only" is better than "HOST_TOOLS_ONLY=yes".
Completely agree. I should have think a bit more before sending initial patch because right after the email was sent I thought why didn't I use a new target? :)
New target looks much better than some random variable. It's shorter and easier to use.
Doesn't work for me:
$ make tools-only HOSTCC scripts/basic/fixdep HOSTCC tools/aisimage.o HOSTCC tools/crc32.o HOSTCC tools/default_image.o HOSTCC tools/dumpimage.o In file included from include/version.h:11:0, from tools/dumpimage.c:11: include/timestamp.h:11:47: fatal error: generated/timestamp_autogenerated.h: No such file or directory #include "generated/timestamp_autogenerated.h" ^ compilation terminated. make[1]: *** [tools/dumpimage.o] Error 1 make: *** [tools-only] Error 2 ========
Oops - My bad. I was disabling timestamp.
Could you fix like this?
tools-only: scripts_basic $(version_h) $(timestamp_h) $(Q)$(MAKE) $(build)=tools
Works as a charm for me as well. Do you mind to submit your changes (because it was you who implemented it properly and I don't want to "steal" your credits)?
Or I do it still on your behalf putting you in as an author?
-Alexey

Hi Alexey,
Works as a charm for me as well. Do you mind to submit your changes (because it was you who implemented it properly and I don't want to "steal" your credits)?
Or I do it still on your behalf putting you in as an author?
-Alexey
OK. I will post it with your Suggested-by credit. Thanks for your kindness!
Best Regards Masahiro Yamada
participants (2)
-
Alexey Brodkin
-
Masahiro Yamada