1

I am trying to extract a FIT image created by mkimage on an ARM board.

Usually when we build u-boot, mkimage and dumpimage are built for the host.

I would instead like to cross-compile and install in a ramfs. Is there any method to do this?

Rewrite Makefile :

I have modified the make file such a that it take arm cross tool as HOSTCC, I can see .o files are created for arm arch(file *.o). **Sample Makefile is given as below ** (just i want dumpimage to be compiled for arm, so I have commented out all other sections)=>

# git diff 0b94ce5ed4a6c2cd0fec7b8337e776b03e387347
diff --git a/Makefile b/Makefile
index 88128ec..8ed7a33 100755
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,7 @@ PATCHLEVEL = 07
 SUBLEVEL =
 EXTRAVERSION =
 NAME =
+CC=arm-linux-gnueabihf-gcc

 # *DOCUMENTATION*
 # To see a list of typical targets execute "make help"
@@ -224,7 +225,7 @@ unexport CDPATH

 #########################################################################

-HOSTARCH := $(shell uname -m | \
+#HOSTARCH := $(shell uname -m | \
    sed -e s/i.86/x86/ \
        -e s/sun4u/sparc64/ \
        -e s/arm.*/arm/ \
@@ -233,6 +234,7 @@ HOSTARCH := $(shell uname -m | \
        -e s/ppc/powerpc/ \
        -e s/macppc/powerpc/\
        -e s/sh.*/sh/)
+HOSTARCH := arm

 HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
        sed -e 's/\(cygwin\).*/cygwin/')
@@ -254,8 +256,8 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
      else if [ -x /bin/bash ]; then echo /bin/bash; \
      else echo sh; fi ; fi)

-HOSTCC       = cc
-HOSTCXX      = c++
+HOSTCC       = arm-linux-gnueabihf-gcc
+HOSTCXX      = arm-linux-gnueabihf-g++
 HOSTCFLAGS   = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
 HOSTCXXFLAGS = -O2

@@ -283,7 +285,7 @@ os_x_before = $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
    $(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)

 # Snow Leopards build environment has no longer restrictions as described above
-HOSTCC       = $(call os_x_before, 10, 5, "cc", "gcc")
+HOSTCC       = $(call os_x_before, 10, 5, "arm-linux-gnueabihf-gcc", "arm-linux-gnueabihf-gcc")
 HOSTCFLAGS  += $(call os_x_before, 10, 4, "-traditional-cpp")
 HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")

@@ -392,13 +394,13 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
 # Rules shared between *config targets and build targets

 # Basic helpers built in scripts/
-PHONY += scripts_basic
-scripts_basic:
-       $(Q)$(MAKE) $(build)=scripts/basic
-       $(Q)rm -f .tmp_quiet_recordmcount
+#PHONY += scripts_basic
+#scripts_basic:
+#      $(Q)$(MAKE) $(build)=scripts/basic
+#      $(Q)rm -f .tmp_quiet_recordmcount

 # To avoid any implicit rule to kick in, define an empty command.
-scripts/basic/%: scripts_basic ;
+#scripts/basic/%: scripts_basic ;

 PHONY += outputmakefile
 # outputmakefile generates a Makefile in the output directory, if using a
@@ -470,11 +472,11 @@ ifeq ($(config-targets),1)
 KBUILD_DEFCONFIG := sandbox_defconfig
 export KBUILD_DEFCONFIG KBUILD_KCONFIG

-config: scripts_basic outputmakefile FORCE
-       $(Q)$(MAKE) $(build)=scripts/kconfig $@
+#config: scripts_basic outputmakefile FORCE
+#      $(Q)$(MAKE) $(build)=scripts/kconfig $@

-%config: scripts_basic outputmakefile FORCE
-       $(Q)$(MAKE) $(build)=scripts/kconfig $@
+#%config: scripts_basic outputmakefile FORCE
+#      $(Q)$(MAKE) $(build)=scripts/kconfig $@

 else
 # ===========================================================================
@@ -670,7 +672,7 @@ libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)

 libs-y := $(sort $(libs-y))

-u-boot-dirs    := $(patsubst %/,%,$(filter %/, $(libs-y))) tools examples
+u-boot-dirs    := tools

 u-boot-alldirs := $(sort $(u-boot-dirs) $(patsubst %/,%,$(filter %/, $(libs-))))

@@ -1197,7 +1199,7 @@ u-boot.sym: u-boot FORCE

 # The actual objects are generated when descending,
 # make sure no implicit rule kicks in
-$(sort $(u-boot-init) $(u-boot-main)): $(u-boot-dirs) ;
+#$(sort $(u-boot-init) $(u-boot-main)): $(u-boot-dirs) ;

 # Handle descending into subdirectories listed in $(vmlinux-dirs)
 # Preset locale variables to speed up the build process. Limit locale
@@ -1205,24 +1207,30 @@ $(sort $(u-boot-init) $(u-boot-main)): $(u-boot-dirs) ;
 # make menuconfig etc.
 # Error messages still appears in the original language

-PHONY += $(u-boot-dirs)
-$(u-boot-dirs): prepare scripts
-       $(Q)$(MAKE) $(build)=$@
+PHONY += tools
+#-Xlinker -rpath-link=/home/phate/rpi/chroot-raspbian-armhf/usr/lib/arm-linux-gnueabihf
+LDFLAGS += -L./lib_sample/ -lcrypto
+LDFLAGS += -L/home/pritam/documents/workspace/codebase/linux/u-boot/codebase/openssl/openssl/ -lcrypto

-tools: prepare
+LD_LIBRARY_PATH=./lib_sample/
+export LD_LIBRARY_PATH
+tools: #prepare scripts
+       make $(build)=$@
+
+#tools: #prepare
 # The "tools" are needed early
-$(filter-out tools, $(u-boot-dirs)): tools
+#$(u-boot-dirs)):
 # The "examples" conditionally depend on U-Boot (say, when USE_PRIVATE_LIBGCC
 # is "yes"), so compile examples after U-Boot is compiled.
-examples: $(filter-out examples, $(u-boot-dirs))
+#examples: $(filter-out examples, $(u-boot-dirs))

 define filechk_uboot.release
-       echo "$(UBOOTVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
+#      echo "$(UBOOTVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
 endef

 # Store (new) UBOOTRELEASE string in include/config/uboot.release
-include/config/uboot.release: include/config/auto.conf FORCE
-       $(call filechk,uboot.release)
+#include/config/uboot.release: include/config/auto.conf FORCE
+#      $(call filechk,uboot.release)


 # Things we need to do before we recursively start building the kernel
@@ -1232,7 +1240,7 @@ include/config/uboot.release: include/config/auto.conf FORCE
 # version.h and scripts_basic is processed / created.

 # Listed in dependency order
-PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
+#PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3

 # prepare3 is used to check if we are building in a separate output directory,
 # and if so do:
@@ -1257,7 +1265,7 @@ ifeq ($(wildcard $(LDSCRIPT)),)
    @/bin/false
 endif

-archprepare: prepare1 scripts_basic
+#archprepare: prepare1 scripts_basic

 prepare0: archprepare FORCE
    $(Q)$(MAKE) $(build)=.
@@ -1377,11 +1385,11 @@ checkarmreloc: u-boot
            false; \
    fi

-env: scripts_basic
-       $(Q)$(MAKE) $(build)=tools/$@
+#env: scripts_basic
+#      $(Q)$(MAKE) $(build)=tools/$@

-tools-only: scripts_basic $(version_h) $(timestamp_h)
-       $(Q)$(MAKE) $(build)=tools
+#tools-only: scripts_basic $(version_h) $(timestamp_h)
+#      $(Q)$(MAKE) $(build)=tools

 tools-all: export HOST_TOOLS_ALL=y
 tools-all: env tools ;
diff --git a/common/image-sig.c b/common/image-sig.c
index eda5e13..c6df99f 100644
--- a/common/image-sig.c
+++ b/common/image-sig.c
@@ -3,6 +3,7 @@
  *
  * SPDX-License-Identifier:    GPL-2.0+
  */
+//#undef USE_HOSTCC

 #ifdef USE_HOSTCC
 #include "mkimage.h"
diff --git a/scripts/Makefile b/scripts/Makefile
index 2f081f7..345a272 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -16,4 +16,4 @@ build_docproc: $(obj)/docproc
    @:

 # Let clean descend into subdirs
-subdir-        += basic kconfig
+#subdir-       += basic kconfig
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 06e5c20..9056412 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -269,8 +269,8 @@ define rule_cc_o_c
    $(cmd_modversions)                                                \
    $(call echo-cmd,record_mcount)                                    \
    $(cmd_record_mcount)                                              \
-       scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' >    \
-                                                     $(dot-target).tmp;  \
+#scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' >    \
+#                                                    $(dot-target).tmp;  \
    rm -f $(depfile);                                                 \
    mv -f $(dot-target).tmp $(dot-target).cmd
 endef
diff --git a/scripts/basic/Makefile b/scripts/basic/Makefile
index f883857..b281340 100644
--- a/scripts/basic/Makefile
+++ b/scripts/basic/Makefile
@@ -11,8 +11,8 @@
 # SPDX-License-Identifier:     GPL-2.0
 #

-hostprogs-y    := fixdep
-always         := $(hostprogs-y)
+#hostprogs-y   := fixdep
+#always                := $(hostprogs-y)

-# fixdep is needed to compile other host programs
-$(addprefix $(obj)/,$(filter-out fixdep,$(always))): $(obj)/fixdep
+## fixdep is needed to compile other host programs
+#$(addprefix $(obj)/,$(filter-out fixdep,$(always))): $(obj)/fixdep
diff --git a/tools/Makefile b/tools/Makefile
index f72294a..be9b221 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -225,6 +225,7 @@ HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \
            $(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
            -I$(srctree)/lib/libfdt \
            -I$(srctree)/tools \
+               -I/home/pritam/documents/workspace/codebase/linux/u-boot/codebase/openssl/openssl/include \
            -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) \
            -DUSE_HOSTCC \
            -D__KERNEL_STRICT_NAMES \

OUTPUT is =>

make -f ./scripts/Makefile.build obj=tools
HOSTLD  tools/dumpimage
/home/pritam/documents/workspace/tools/sdks/bolide/petalinux/tools/linux-i386/gcc-arm-linux-gnueabi/bin/../lib/gcc/arm-linux-gnueabihf/5.2.1/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lssl
/home/pritam/documents/workspace/tools/sdks/bolide/petalinux/tools/linux-i386/gcc-arm-linux-gnueabi/bin/../lib/gcc/arm-linux-gnueabihf/5.2.1/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
scripts/Makefile.host:103: recipe for target 'tools/dumpimage' failed
make[1]: *** [tools/dumpimage] Error 1
Makefile:1217: recipe for target 'tools' failed
make: *** [tools] Error 2

NOTE I have downloaded and compile openssl for arm and path is assigned to LDFLAGS as we can see in Makefile patch

How can I link Libraries that are built separately for arm ?

Kindly correct me if I go wrong.

pritam
  • 65
  • 2
  • 11
  • You need an environment to run the cross compiled tools in. Normally, with a `ramfs`, there is a limited **LIBC**; such as [klibc](https://en.wikipedia.org/wiki/Klibc), [dietlibc](https://en.wikipedia.org/wiki/Dietlibc), [etc](https://en.wikipedia.org/wiki/C_standard_library#Implementations), or busybox. You need to cross compile with that 'rootfs' headers, tools, etc to make a working `dumpimage`. Maybe some u-boot configure out of the box exists, but those are the requirements to do what you want. You didn't give enough info on the 'ramfs'. – artless noise Apr 11 '18 at 16:38
  • In a short, I would like to have a dumpimage compiled for the arm board, so that I can manually installed in ramfs with shared library dependencies(somewhat using ldd, buildroot for dependancies). I am trying to compile u-boot tools for arm (make tools). In top level Makefile, I have replaced HOSTCC=cc and HOSTCXX=c++ with the crosstool(arm-linux-gnueabihf-gcc and g++ resply). But it's failing with "scripts/basic/fixdep: cannot execute binary file: Exec format error". So is there any method to this ? – pritam Apr 12 '18 at 04:16
  • How did you build the executables that are in the rootfs? – sawdust Apr 12 '18 at 04:39
  • rootfs is created by yocto. And I exported same cross tool (from yocto build sys) to cross compile the u-boot (which is intended to build dumpimage). – pritam Apr 12 '18 at 06:37
  • You probably have to write a new makefile to cross-compile this program for your target. There are too many HOST* variables besides the two that you tried to "fix". – sawdust Apr 12 '18 at 08:08
  • I have modified the Makefile for arm and details are given in tag. But now I am facing issues for linking libraries. – pritam Apr 16 '18 at 04:16

3 Answers3

1

I faced this problem where I only needed dumpimage tool on linux x86/64. The following worked for me.

1) wget ftp://ftp.denx.de/pub/u-boot/u-boot-latest.tar.bz2
2) cd u-boot-2017.09
3) make qemu-x86_defconfig
4) make tools

Host tools are now ready.

sunil
  • 491
  • 4
  • 10
0

Along with changes in Makefiles as mentioned above, on crypto and ssl link issue, I have compiled openssl for arm and linked *.a in a u-boot top level Makefile using HOSTLDFLAGS.

pritam
  • 65
  • 2
  • 11
0

You could build U-boot tools Cross compiled. Example: make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- CROSS_BUILD_TOOLS=1 tools

This will give you cross compiled tools generated in your tools directory.

  • I think, cross tolls must be having ssl and crypto support . But in my case these supports were not present (xilinx cross tools). Kindly correct me if I go wrong. – pritam Aug 17 '18 at 10:31