Extract u-boot default environment from u-boot source code

I tried to extract the u-boot default environment variables from the u-boot source code (/include/configs/apalis-tk1.h and alike) in my image which is based on the Apalis TK1 Linux Image v2.7b+.

After building u-boot with the instruction in the Toradex instructions (see hyperlink below) I executed

./scripts/get_default_envs.sh

to print the default environment variables on the console but I got the following error message

objcopy: Unable to recognise the format of the input file `copy_env_common.o'

(The shell script moves enc_common.o to copy_env_common.o.)

My host environment variables are set like suggested in Toradex instructions http://developer.toradex.com/knowledge-base/build-u-boot-and-linux-kernel-from-source-code#UBoot

printenv ARCH
  arm
printenv PATH
  ... :/home/kromer/gcc-linaro/bin/ ... :/home/kromer/u-boot-toradex/tools
printenv CROSS_COMPILE
  arm-linux-gnueabihf-

How to get around this problem?

It looks like this script does not honour CROSS_COMPILE variable. Try this patch

diff --git a/scripts/get_default_envs.sh b/scripts/get_default_envs.sh
index 7955db6..844ff6e 100755
--- a/scripts/get_default_envs.sh
+++ b/scripts/get_default_envs.sh
@@ -24,7 +24,7 @@ cp ${env_obj_file_path} ${ENV_OBJ_FILE_COPY}
 
 # NOTE: objcopy saves its output to file passed in
 # (copy_env_common.o in this case)
-objcopy -O binary -j ".rodata.default_environment" ${ENV_OBJ_FILE_COPY}
+${CROSS_COMPILE}objcopy -O binary -j ".rodata.default_environment" ${ENV_OBJ_FILE_COPY}
 
 # Replace default '\0' with '\n' and sort entries
 tr '\0' '\n' < ${ENV_OBJ_FILE_COPY} | sort -u

By the way: Thanks a lot.

One thing to note: Do not wonder about that the extracted uboot-env.txt (with ./scripts/get_default_envs.sh > uboot-env.txt) does not contain the U-Boot version ver=.... When booting into u-boot which has been flashed together with an u-boot environment image sourced from this .txt file the version is included there as e.g. ver=U-Boot 2016.11-00074-g48127d1-dirty (Jun 22 2017 - 14:17:15 +0200). This means when ./tools/mkenvimage is executed to generate the u-boot environment image e.g. uboot-env.bin the version of u-boot is added to the binary automatically (to avoid that an invalid u-boot version is pasted into the u-boot environment image source file).

However when booting into u-boot and reseting to the u-boot default environment (which is located separate from the u-boot environments image persistent storage location) with env default -a; saveenv; printenv; the version is not accessible anymore. This is due to the reason that just the u-boot environment image file contains the version variable but not the default environment (from the u-boot source code).