Patchwork [U-Boot] tools/env: fix cross-compilation

login
register
mail settings
Submitter Grant Erickson
Date Dec. 22, 2011, 6:39 p.m.
Message ID <1324579175-26503-1-git-send-email-marathon96@gmail.com>
Download mbox | patch
Permalink /patch/132888/
State Rejected
Headers show

Comments

Grant Erickson - Dec. 22, 2011, 6:39 p.m.
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.

Signed-off-by: Grant Erickson <marathon96@gmail.com>
---
 tools/env/Makefile |   18 +++++++++---------
 tools/env/README   |   19 ++++++++++++++-----
 2 files changed, 23 insertions(+), 14 deletions(-)
Mike Frysinger - Jan. 5, 2012, 11:18 p.m.
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
Grant Erickson - Jan. 5, 2012, 11:25 p.m.
On Jan 5, 2012, at 3:18 PM, Mike Frysinger wrote:
> 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
Mike Frysinger - Jan. 8, 2012, 6:54 a.m.
On Thursday 05 January 2012 18:25:52 Grant Erickson wrote:
> On Jan 5, 2012, at 3:18 PM, Mike Frysinger wrote:
> > 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.
> 
> 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

Patch

diff --git a/tools/env/Makefile b/tools/env/Makefile
index 28b73da..705d5e8 100644
--- a/tools/env/Makefile
+++ b/tools/env/Makefile
@@ -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
diff --git a/tools/env/README b/tools/env/README
index 3f0d77e..5b02f7d 100644
--- a/tools/env/README
+++ b/tools/env/README
@@ -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"