Skip to contentSkip to conversation

tools/env: fix cross-compilation

PATCH New Grant Erickson 2 participants 4 messages Dec 22, 2011 – Jan 8, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/env: fix cross-compilation

This patch fixes the make infrastructure for the fw_printenv tool such that it is built, by default, as a cross-compilation for the target board when so requested with TOOLSUBDIRS on the U-Boot make command line.

---
 tools/env/Makefile |   18 +++++++++---------
 tools/env/README   |   19 ++++++++++++++-----
 2 files changed, 23 insertions(+), 14 deletions(-)
tools/env/Makefile +9 -9
index 28b73da..705d5e8 100644
@@ -23,24 +23,24 @@
 
 include $(TOPDIR)/config.mk
 
-HOSTSRCS := $(SRCTREE)/lib/crc32.c  fw_env.c  fw_env_main.c
+SRCS := $(SRCTREE)/lib/crc32.c  fw_env.c  fw_env_main.c
 HEADERS	:= fw_env.h
 
 # Compile for a hosted environment on the target
-HOSTCPPFLAGS  = -idirafter $(SRCTREE)/include \
-		-idirafter $(OBJTREE)/include2 \
-		-idirafter $(OBJTREE)/include \
-		-DUSE_HOSTCC
+CPPFLAGS = -Wall \
+	   -idirafter $(SRCTREE)/include \
+	   -idirafter $(OBJTREE)/include2 \
+	   -idirafter $(OBJTREE)/include \
+	   -DUSE_HOSTCC
 
 ifeq ($(MTD_VERSION),old)
-HOSTCPPFLAGS += -DMTD_OLD
+CPPFLAGS += -DMTD_OLD
 endif
 
 all:	$(obj)fw_printenv
 
-# Some files complain if compiled with -pedantic, use HOSTCFLAGS_NOPED
-$(obj)fw_printenv:	$(HOSTSRCS) $(HEADERS)
-	$(HOSTCC) $(HOSTCFLAGS_NOPED) $(HOSTLDFLAGS) -o $@ $(HOSTSRCS)
+$(obj)fw_printenv:	$(SRCS) $(HEADERS)
+	$(CROSS_COMPILE)gcc $(CPPFLAGS) $(SRCS) -o $@
 
 clean:
 	rm -f $(obj)fw_printenv
tools/env/README +14 -5
index 3f0d77e..5b02f7d 100644
@@ -2,11 +2,20 @@
 This is a demo implementation of a Linux command line tool to access
 the U-Boot's environment variables.
 
-In the current version, there is an issue in cross-compilation.
-In order to cross-compile fw_printenv, run
-    make HOSTCC=<your CC cross-compiler> env
-in the root directory of the U-Boot distribution. For example,
-    make HOSTCC=arm-linux-gcc env
+To build it for your target board along with U-Boot itself, simply add:
+
+    TOOLSUBDIRS=env
+
+to your make invocation such as:
+
+    make -C u-boot/source \
+    O=$(CURDIR)/u-boot/build \
+    TOOLSUBDIRS=env \
+    all
+
+and you will find, for example:
+
+    $(CURDIR)/u-boot/build/tools/env/fw_printenv
 
 For the run-time utiltity configuration uncomment the line
 #define CONFIG_FILE  "/etc/fw_env.config"
Signature · 1 line
1.7.7.3
#1 lore raw

PATCH 1/1 tools/env: fix cross-compilation

Quoted 4 lines · On Thursday 22 December 2011 13:39:35 Grant Erickson wrote:

This patch fixes the make infrastructure for the fw_printenv tool such that it is built, by default, as a cross-compilation for the target board when so requested with TOOLSUBDIRS on the U-Boot make command line.

how is this any simpler than the existing method ?
make tools HOSTCC=some-random-target-gcc

the current tools/ subdir is consistent in its handling. this patch would break that.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120105/75abcd3b/attachment.pgp>

#2 lore raw

PATCH 1/1 tools/env: fix cross-compilation

Quoted 11 lines · Mike Frysinger
Quoted 4 lines · On Thursday 22 December 2011 13:39:35 Grant Erickson wrote:

This patch fixes the make infrastructure for the fw_printenv tool such that it is built, by default, as a cross-compilation for the target board when so requested with TOOLSUBDIRS on the U-Boot make command line.

how is this any simpler than the existing method ?
make tools HOSTCC=some-random-target-gcc

the current tools/ subdir is consistent in its handling. this patch would break that.

Mike,

Because it's broken with respect to how the rest of U-Boot is built. I already specify the cross-compiler via CROSS_COMPILE when I build u-boot.bin and u-boot.img, that I need to specify the same compiler in two different ways to build executables for the same target platform is broken and, it sounds like, as are the rest of the tools subdirectories.

If fw_setenv were a build host-based tool or if it made sense as a build host-based tool, then using HOSTCC would be sensible.

Best,

Grant

#3 lore raw

PATCH 1/1 tools/env: fix cross-compilation

Quoted 11 lines · On Thursday 05 January 2012 18:25:52 Grant Erickson wrote:
Quoted 10 lines · Mike Frysinger
Quoted 4 lines · On Thursday 22 December 2011 13:39:35 Grant Erickson wrote:

This patch fixes the make infrastructure for the fw_printenv tool such that it is built, by default, as a cross-compilation for the target board when so requested with TOOLSUBDIRS on the U-Boot make command line.

how is this any simpler than the existing method ?

make tools HOSTCC=some-random-target-gcc

Quoted 8 lines
Quoted 2 lines

the current tools/ subdir is consistent in its handling. this patch would break that.

Because it's broken with respect to how the rest of U-Boot is built. I already specify the cross-compiler via CROSS_COMPILE when I build u-boot.bin and u-boot.img, that I need to specify the same compiler in two different ways to build executables for the same target platform is broken and, it sounds like, as are the rest of the tools subdirectories.

no, you specified the toolchain that is appropriate for building bare metal code. it is often times not the same as the toolchain used to build userspace applications for running under Linux. this is not broken behavior.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120108/ac613bb7/attachment.pgp>