Cannot build Hikey Fw from source

Are you using the latest for all repos, except uefi-tools.git?
Did you make sure to git clean the repo first? I had the same issue too until I did that.
If yes to both, then some logs might help.

@vchong, i tried the instructions from https://github.com/Linaro/documentation/blob/master/Reference-Platform/RPOfficial/ConsumerEdition/HiKey/BuildSourceBL.md from scratch and made the change you suggested for uefi-tools. I still see the same issue.
Is that what you mean by latest for all repos ? Im assuming ill get the latest if i clone the repositories as mentioned in the instructions now. note that the link uses the hikey-aosp branch and not master or any other branch.

[Edit] Yes, you will get the latest if you start a clone from scratch now.

I also tested again from scratch using the script below which basically contains instructions copy and pasted from https://github.com/Linaro/documentation/blob/master/Reference-Platform/RPOfficial/ConsumerEdition/HiKey/BuildSourceBL.md, plus the changes suggested for uefi-tools, minus the ‘git clean’ since these are new/clean repos. Note that I also added ‘–depth=1’ to speed up the test. The build is ok. Not sure what the problem is on your end.


#!/bin/bash

git clone --depth=1 -b hikey-aosp https://github.com/96boards-hikey/edk2.git
git clone --depth=1 -b hikey-aosp https://github.com/96boards-hikey/OpenPlatformPkg.git
git clone --depth=1 https://github.com/OP-TEE/optee_os.git
git clone --depth=1 -b hikey https://github.com/96boards-hikey/arm-trusted-firmware.git
git clone --depth=1 https://github.com/96boards-hikey/l-loader.git
git clone git://git.linaro.org/uefi/uefi-tools.git

export AARCH64_TOOLCHAIN=GCC49
export EDK2_DIR=${PWD}/edk2
export OPTEE_DIR=${PWD}/optee_os
export ATF_DIR=${PWD}/arm-trusted-firmware
export UEFI_TOOLS_DIR=${PWD}/uefi-tools

cd ${UEFI_TOOLS_DIR}
git checkout 0ce9cb2a715bebdb6bf5b99ef59df532e655ce88
cd ${EDK2_DIR}
rmdir OpenPlatformPkg; ln -s ../OpenPlatformPkg
${UEFI_TOOLS_DIR}/uefi-build.sh -b RELEASE -a ${ATF_DIR} -s ${OPTEE_DIR} hikey


> aarch64-linux-gnu-gcc -v
gcc version 5.3.1 20160113 (Linaro GCC 5.3-2016.02)

> arm-linux-gnueabihf-gcc -v
gcc version 5.3.1 20160113 (Linaro GCC 5.3-2016.02)

Got past the aarch64-linux-gnu-gcc: error trying to exec ‘cc1’: execvp: No such file or directory issue. The problem was with the default bashrc on ubuntu xenial. :confused: it skipped the bashrc file entirely if the shell was non interactive and it looks like the build process invokes non interactive shells. All my exports for gcc were at the end of bashrc.
Now im having issues with python crypto and wand.image modules. Hopefully the python issues will be simpler to solve.

Build finished successfully after i installed pip, pycrypto and wand.
@vchong, thanks for the help.

Looks like your problem was with the shell all along and I kept trying to solve the ‘gcc5’ issue, so we were both headed in different directions. Sorry about that and glad you got it working.

The build instructions have been updated by the way for the gcc5 issue. For details see https://github.com/Linaro/documentation/pull/7.

@vchong, thanks again for all the help!

Hi @raghu-ncstate raghu-ncstate, I am new to this and I am getting this error during the build and the build breaks:

{{{
build: : warning: Tool chain [GCC5] is not defined

build.py…
: error 4000: Not available
[GCC5] not defined. No toolchain available for build!
}}}

Can you tell me how to get past this issue? or any background will help.
I know this topic was discussed long back. Sorry and thanks in advance.

Best,
Rakshith Patkar

@rakshithpatkar Which url/instructions are you following? Try setting below and rebuild again.

export AARCH64_TOOLCHAIN=GCC5

Sorry. I mean try setting it to GCC49.

@vchong, I am following the instructions in:

Even after setting export AARCH64_TOOLCHAIN=GCC49, I am getting the same error.

Attaching the script i am using:

{{{
#!/bin/sh

BUILD_OPTION=DEBUG

export AARCH64_TOOLCHAIN=GCC49

export UEFI_TOOLS_DIR=${BUILD_PATH}/uefi-tools

export EDK2_DIR=${BUILD_PATH}/edk2

EDK2_OUTPUT_DIR=${EDK2_DIR}/Build/HiKey960/${BUILD_OPTION}_${AARCH64_TOOLCHAIN}

cd ${EDK2_DIR}

Build UEFI & ARM Trust Firmware

${UEFI_TOOLS_DIR}/uefi-build.sh -b ${BUILD_OPTION} -a …/arm-trusted-firmware hikey960

Generate l-loader.bin

cd ${BUILD_PATH}/l-loader

ln -sf ${EDK2_OUTPUT_DIR}/FV/bl1.bin

ln -sf ${EDK2_OUTPUT_DIR}/FV/fip.bin

ln -sf ${EDK2_OUTPUT_DIR}/FV/BL33_AP_UEFI.fd

python gen_loader_hikey960.py -o l-loader.bin --img_bl1=bl1.bin --img_ns_bl1u=BL33_AP_UEFI.fd
}}}

After setting: export AARCH64_TOOLCHAIN=GCC49

{{{

OK
make[1]: Leaving directory ‘/home/rakshith/Projects/UEFI-source/edk2/BaseTools/Tests’
make: Leaving directory ‘/home/rakshith/Projects/UEFI-source/edk2/BaseTools’
Target: AARCH64
Build: X64
Building Hikey960 - AARCH64
CROSS_COMPILE=“aarch64-linux-gnu-”
hikey960_BUILDFLAGS=’ -D FIRMWARE_VER=9d69f68’
TOOLCHAIN is GCC5
Toolchain prefix: GCC5_AARCH64_PREFIX=aarch64-linux-gnu-
Build environment: Linux-4.4.0-21-generic-x86_64-with-Ubuntu-16.04-xenial
Build start time: 15:25:16, Jul.17 2017

build: : warning: Tool chain [GCC5] is not defined

build.py…
: error 4000: Not available
[GCC5] not defined. No toolchain available for build!

  • Failed -
    Build end time: 15:25:17, Jul.17 2017
    Build total time: 00:00:00

                                     Hikey960 DEBUG	fail

pass 0
fail 1
python: can’t open file ‘gen_loader_hikey960.py’: [Errno 2] No such file or directory
rakshith@patkar007:~/Projects/UEFI-source/edk2$
}}}

- Installed gcc version:
{{{
rakshith@patkar007:~/Projects/UEFI-source/edk2$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

rakshith@patkar007:~/Projects/UEFI-source/edk2$
}}}

@rakshithpatkar Do you have a gcc5 toolchain downloaded, installed and added to the PATH variable, before running the commands? E.g.

wget http://releases.linaro.org/components/toolchain/binaries/5.3-2016.02/aarch64-linux-gnu/gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu.tar.xz
wget http://releases.linaro.org/components/toolchain/binaries/5.3-2016.02/arm-linux-gnueabihf/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz
mkdir arm-tc arm64-tc
tar --strip-components=1 -C ${PWD}/arm-tc -xf gcc-linaro-5.3-*arm-linux-gnueabihf.tar.xz
tar --strip-components=1 -C ${PWD}/arm64-tc -xf gcc-linaro-5.3-*aarch64-linux-gnu.tar.xz
export PATH="${PWD}/arm-tc/bin:${PWD}/arm64-tc/bin:$PATH"

@vchong, thanks for the reply.

I already have the arm64 toolchain installed and put it in .bashrc file.

$ vim ~/.bashrc

{{{
//snip
export PATH=/home/rakshith/arm64-tc/bin:$PATH
export PATH=/home/rakshith/arm-tc/bin:$PATH
//snip
}}}

Verifying the above:

{{{
rakshith@patkar007:~/Projects/UEFI-source/edk2$ aarch64-linux-gnu-g
aarch64-linux-gnu-g++ aarch64-linux-gnu-gcc-ar aarch64-linux-gnu-gcov aarch64-linux-gnu-gfortran
aarch64-linux-gnu-gcc aarch64-linux-gnu-gcc-nm aarch64-linux-gnu-gcov-tool aarch64-linux-gnu-gprof
aarch64-linux-gnu-gcc-5.3.1 aarch64-linux-gnu-gcc-ranlib aarch64-linux-gnu-gdb
}}}

Still getting the following error:

{{{
//snip

Ran 247 tests in 0.917s

OK
make[1]: Leaving directory ‘/home/rakshith/Projects/UEFI-source/edk2/BaseTools/Tests’
make: Leaving directory ‘/home/rakshith/Projects/UEFI-source/edk2/BaseTools’
Target: AARCH64
Build: X64
Building Hikey960 - AARCH64
CROSS_COMPILE=“aarch64-linux-gnu-”
hikey960_BUILDFLAGS=’ -D FIRMWARE_VER=9d69f68’
TOOLCHAIN is GCC5
Toolchain prefix: GCC5_AARCH64_PREFIX=aarch64-linux-gnu-
Build environment: Linux-4.4.0-21-generic-x86_64-with-Ubuntu-16.04-xenial
Build start time: 11:03:02, Jul.19 2017

build: : warning: Tool chain [GCC5] is not defined

build.py…
: error 4000: Not available
[GCC5] not defined. No toolchain available for build!

  • Failed -
    Build end time: 11:03:02, Jul.19 2017
    Build total time: 00:00:00

                                     Hikey960 DEBUG	fail

pass 0
fail 1
python: can’t open file ‘gen_loader_hikey960.py’: [Errno 2] No such file or directory
}}}

I am using the latest cloned repos as source.

How are you cloning the repos? Looks like you might not be on right branches.

Hi @vchong,

I have cloned the repos as follows:

  1. ARM Trusted Firmware:
    $ git clone https://github.com/ARM-software/arm-trusted-firmware.git
  2. edk2:
    $ git clone https://github.com/96boards-hikey/edk2.git
  3. OpenPlatformPkg?:
    $ git clone https://github.com/96boards-hikey/OpenPlatformPkg.git
  4. l-loader:
    $ git clone https://github.com/96boards-hikey/l-loader.git
  5. uefi-tools: (master branch)
    $ git clone uefi-tools.git - [no description]
  6. atf-fastboot: (only for HiKey)
    $ git clone https://github.com/96boards-hikey/atf-fastboot.git

Following instructions to compile and install the uefi bootloader from here:
https://github.com/96boards-hikey/tools-images-hikey960/blob/master/build-from-source/README-ATF-UEFI-build-from-source.md

Yea wrong branches.

  1. ARM Trusted Firmware:
    $ git clone https://github.com/ARM-software/arm-trusted-firmware.git
  2. edk2:
    $ git clone https://github.com/96boards-hikey/edk2.git -b testing/hikey960_v2.5
  3. OpenPlatformPkg?:
    $ git clone https://github.com/96boards-hikey/OpenPlatformPkg.git -b testing/hikey960_v1.3.4
  4. l-loader:
    $ git clone https://github.com/96boards-hikey/l-loader.git -b testing/hikey960_v1.2
  5. uefi-tools: (master branch)
    $ git clone uefi-tools.git - [no description]
  6. atf-fastboot: (only for HiKey)
    $ git clone https://github.com/96boards-hikey/atf-fastboot.git

Thanks @vchong, i was indeed on the wrong branches.
While trying to build, I faced another error, something like this:

{{{
//snip
plat/hisilicon/hikey960/platform.mk:13: warning: ignoring old recipe for target ‘check_SCP_BL2’
Building hikey960
CC tbbr_config.c
CC fiptool.c
CC bl1/tbbr/tbbr_img_desc.c
CC drivers/io/io_block.c
fiptool.c:21:25: fatal error: openssl/sha.h: No such file or directory
compilation terminated.
Makefile:50: recipe for target ‘fiptool.o’ failed
make[1]: *** [fiptool.o] Error 1
make[1]: *** Waiting for unfinished jobs…
CC drivers/io/io_storage.c
CC drivers/synopsys/ufs/dw_ufs.c
CC drivers/io/io_fip.c
Makefile:663: recipe for target ‘tools/fiptool/fiptool’ failed
make: *** [tools/fiptool/fiptool] Error 2
make: *** Waiting for unfinished jobs…

                                     Hikey960 DEBUG	fail

pass 0
fail 1
±----------------------------------------------------------+
Input Images:
bl1: bl1.bin
ns_bl1u: BL33_AP_UEFI.fd
Ouput Image: l-loader.bin
±----------------------------------------------------------+

Traceback (most recent call last):
File “gen_loader_hikey960.py”, line 129, in
main(sys.argv[1:])
File “gen_loader_hikey960.py”, line 124, in main
loader.create(img_bl1, img_ns_bl1u, output_img)
File “gen_loader_hikey960.py”, line 92, in create
self.add(0, img_bl1)
File “gen_loader_hikey960.py”, line 32, in add
fsize = os.path.getsize(fname)
File “/usr/lib/python2.7/genericpath.py”, line 57, in getsize
return os.stat(filename).st_size
OSError: [Errno 2] No such file or directory: ‘bl1.bin’
}}}

I was able to solve this by doing:

$ sudo apt-get install libssl-dev

Anyway,

I was ale to complete step 2 in https://github.com/96boards-hikey/tools-images-hikey960/blob/master/build-from-source/README-ATF-UEFI-build-from-source.md

But I am having trouble setting up telnet for console.

- Install ser2net. Use telnet as the console since UEFI will output window that fails to display in minicom.
$sudo apt-get install ser2net

- Configure ser2net.
$sudo vi /etc/ser2net.conf

Append one line for serial-over-USB in below.

#ser2net.conf

2004:telnet:0:/dev/ttyUSB0:115200 8DATABITS NONE 1STOPBIT banner

Open the console.
$telnet localhost 2004

rakshith@patkar007:~/Projects/UEFI-source/l-loader$ telnet localhost 2004
Trying 127.0.0.1…
telnet: Unable to connect to remote host: Connection refused

My question is: @vchong @ric96

To do telnet isn’t it necessary that ethernet is active?
And why are we using telnet?
Could you please explain step 4 in a little detail? Or point me to a source of such information?
Thanks in advance.

You’re telnet-ing to localhost, i.e. your own computer, so it’s not necessary to have an outside connection. In reality, it’s just telnet-ing to the port where the serial port/connection is so you can see the console output. Restart ser2net to ‘activate’ the new line and telnet should be ok.

$ sudo killall ser2net
$ sudo ser2net -u
$ telnet localhost 2004

@vchong, Thanks.

For doing step4, could you tell me the set up of dip switches and USB cable?

Refer to https://github.com/96boards-hikey/tools-images-hikey960/blob/master/README.md#step-1-materials-and-preperations.

To boot into recovery mode set switch 1 & 2 to ON state and switch 3 to OFF state
Connect USB type C cable from board to PC
Connect serial uart console cable/adapter from board to PC if available