Rather than copying from Yocto, it may make sense to just clone from https://github.com/digidotcom/yocto-uboot and follow these instructions from a similar question: How does one compile u-boot using the yocto toolchain/sdk?.
This uses the toolchain generated by Yocto, but it should be possible to use another toolchain if the right flags are set.
How does one compile u-boot using the yocto toolchain/sdk?
On a project (a few in fact), I will be required to make changes to u-boot. I can make these within Yocto, but that is less than ideal. I would like to be able to make and test changes outside of Yocto as I can do with the kernel.
What I have working currently is to the do the following:
1. Build an sdk from Yocto using 'bitbake -c populate_sdk`
2. Install that SDK on my development machine
3. Checkout U-Boot (I am working off the tag dey-1.6.2.2-2009.08 currently.
4. Source the environment setup script for my SDK
5. As with the kernel. unset LDFLAGS
6. Apply the patch below.
7. make ccimx53js_config && make all
The patch (step 6) is the only part I am not happy with having to perform. Without this, U-Boot cannot link against libs (the first one I hit is libgcc.a) that are in the sysroot. The environment setup script sets up LD as the following (LD=arm-dey-linux-gnueabi-ld --sysroot=/home/posborne/Projects/WDNU-II/sdk/sysroots/armv7a-vfp-neon-dey-linux-gnueabi).
Patch (will use environment defined CC/LD/etc.):
diff --git a/config.mk b/config.mk
index 02d204a..a8682c5 100644
--- a/config.mk
+++ b/config.mk
@@ -65,17 +65,17 @@ cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
#
# Include the make variables (CC, etc...)
#
-AS = $(CROSS_COMPILE)as
-LD = $(CROSS_COMPILE)ld
-CC = $(CROSS_COMPILE)gcc
-CPP = $(CC) -E
-AR = $(CROSS_COMPILE)ar
-NM = $(CROSS_COMPILE)nm
-LDR = $(CROSS_COMPILE)ldr
-STRIP = $(CROSS_COMPILE)strip
-OBJCOPY = $(CROSS_COMPILE)objcopy
-OBJDUMP = $(CROSS_COMPILE)objdump
-RANLIB = $(CROSS_COMPILE)RANLIB
+AS ?= $(CROSS_COMPILE)as
+LD ?= $(CROSS_COMPILE)ld
+CC ?= $(CROSS_COMPILE)gcc
+CPP ?= $(CC) -E
+AR ?= $(CROSS_COMPILE)ar
+NM ?= $(CROSS_COMPILE)nm
+LDR ?= $(CROSS_COMPILE)ldr
+STRIP ?= $(CROSS_COMPILE)strip
+OBJCOPY ?= $(CROSS_COMPILE)objcopy
+OBJDUMP ?= $(CROSS_COMPILE)objdump
+RANLIB ?= $(CROSS_COMPILE)RANLIB
#########################################################################
So, has anyone gotten this to work without patching U-Boot?
• Comment
The Yocto SDK is designed to build applications, and u-boot and Linux need special treatment. For example, the SDK environment preparation script sets up CFLAGS and LDFLAGS which do not work with neither u-boot or Linux.
To compile externally I have been using my own script for u-boot which does something like:
CROSS_COMPILE=arm-dey-linux-gnueabi-
TOOLCHAIN_PATH=${SDK_INSTALL_PATH}/sysroots/x86_64-pokysdk-linux/usr/bin/arm-dey-linux-gnueabi
export PATH=${TOOLCHAIN_PATH}:${PATH}
make ${PRODUCT}_config
make -j4 CROSS_COMPILE=${CROSS_COMPILE} u-boot.imx
This is similar to what I did to use the DEL toolchain.
With the current Yocto SDK however, it breaks with:
arm-dey-linux-gnueabi-ld.bfd: cannot find -lgcc
This is an SDK problem which was fixed in u-boot by the following commit:
commit 52b1bf2c5cd2f8af880dab503d0039b35570665b
Author: Wolfgang Denk <wd@denx.de>
Date: Thu Jul 23 13:15:59 2009 +0200
Make linking against libgcc configurable
Many (especially ARM) tool chains seem to come with broken or
otherwise unusable (for the purposes of builing U-Boot) run-time
support libraries `libgcc.a'. By using the "USE_PRIVATE_LIBGCC"
setting we allow to use alternative libraries instead.
"USE_PRIVATE_LIBGCC" can either be set as an environment variable in
the shell, or as a command line argument when running "make", i. e.
$ make USE_PRIVATE_LIBGCC=yes
or
$ USE_PRIVATE_LIBGCC=yes
$ export USE_PRIVATE_LIBGCC
$ make
The value of "USE_PRIVATE_LIBGCC" is the name of the directory which
contains the alternative run-time support library `libgcc.a'. The
special value "yes" selects the directory $(OBJTREE)/lib_$(ARCH) .
Note that not all architectures provide an alternative `libgcc.a' in
their lib_$(ARCH) directories - so far, only ARM does.
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
cc: Stefan Roese <sr@denx.de>
So, the final way tobuild u-boot externally with the current Yocto SDK is:
CROSS_COMPILE=arm-dey-linux-gnueabi-
TOOLCHAIN_PATH=${SDK_INSTALL_PATH}/sysroots/x86_64-pokysdk-linux/usr/bin/arm-dey-linux-gnueabi
export PATH=${TOOLCHAIN_PATH}:${PATH}
make ${PRODUCT}_config
USE_PRIVATE_LIBGCC="yes" make -j4 CROSS_COMPILE=${CROSS_COMPILE} u-boot.imx