OpTEE + Android in Hikey960

cd device/linaro/hikey
git reset --hard HEAD~2 #be very careful when u do this!
repo sync .
cd ../edk2
git clean -xfd #also be careful here
cd ../../../
rm -f out/dist/fip.bin #ignore any warning/error

Build again.

plat/common/aarch64/plat_common.c: In function ‘plat_get_syscnt_freq2’:
plat/common/aarch64/plat_common.c:60:2: warning: ‘plat_get_syscnt_freq’ is deprecated [-Wdeprecated-declarations]
  unsigned long long freq = plat_get_syscnt_freq();
  ^
In file included from plat/common/aarch64/plat_common.c:8:0:
include/plat/common/platform.h:41:20: note: declared here
 unsigned long long plat_get_syscnt_freq(void) __deprecated;
                    ^
  CC      lib/stdlib/assert.c
  CC      lib/stdlib/exit.c
  CC      lib/stdlib/mem.c
  CC      lib/stdlib/printf.c
  CC      lib/stdlib/putchar.c
  CC      lib/stdlib/puts.c
  CC      lib/stdlib/sscanf.c
  CC      lib/stdlib/strchr.c
  CC      lib/stdlib/strcmp.c
  CC      lib/stdlib/strlen.c
  CC      lib/stdlib/strncmp.c
  CC      lib/stdlib/strnlen.c
  CC      lib/stdlib/subr_prf.c
  CC      lib/stdlib/timingsafe_bcmp.c
  CC      drivers/delay_timer/delay_timer.c
  CC      drivers/delay_timer/generic_delay_timer.c
  CC      lib/aarch64/xlat_tables.c
  CC      plat/hisilicon/hikey960/aarch64/hikey960_common.c
  CC      plat/hisilicon/hikey960/hikey960_boardid.c
  AS      lib/cpus/aarch64/cortex_a53.S
  AS      lib/cpus/aarch64/cortex_a72.S
  AS      lib/cpus/aarch64/cortex_a73.S
  AS      plat/hisilicon/hikey960/aarch64/hikey960_helpers.S
  AS      bl31/aarch64/runtime_exceptions.S
  AS      bl31/aarch64/crash_reporting.S
  AS      bl31/aarch64/bl31_entrypoint.S
  AS      plat/common/aarch64/platform_mp_stack.S
  AS      lib/el3_runtime/aarch64/cpu_data.S
bl31/aarch64/runtime_exceptions.S: Assembler messages:
bl31/aarch64/runtime_exceptions.S:157: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:165: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:170: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:175: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:189: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:193: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:197: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:201: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:215: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:219: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:223: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:231: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:245: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:249: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:253: Error: non-constant expression in ".if" statement
bl31/aarch64/runtime_exceptions.S:261: Error: non-constant expression in ".if" statement
Makefile:558: recipe for target 'build/hikey960/release/bl31/runtime_exceptions.o' failed
make[1]: *** [build/hikey960/release/bl31/runtime_exceptions.o] Error 1
make[1]: *** Waiting for unfinished jobs....
  AS      lib/locks/exclusive/aarch64/spinlock.S
  AS      lib/cpus/aarch64/cpu_helpers.S
make[1]: Leaving directory '/home/xx/optee_android_manifest/device/linaro/arm-trusted-firmware'
------------------------------------------------------------
                                       Hikey960 RELEASE	fail
------------------------------------------------------------
pass	0
fail	1
Makefile:45: recipe for target '/home/xx/optee_android_manifest/out/dist/fip.bin' failed
make: *** [/home/xx/optee_android_manifest/out/dist/fip.bin] Error 1
make: Leaving directory '/home/xx/optee_android_manifest/device/linaro/hikey/bootloader'
[  2% 2283/76802] target  C++: libv8src <= external/v8/src/builtins/builtins-number.cc
ninja: build stopped: subcommand failed.
09:13:38 ninja failed with: exit status 1

#### failed to build some targets (03:36 (mm:ss)) ####

I didn’t see this error when trying yesterday. Maybe make distclean in arm-trusted-firmware and try again?

I have done it and rebuilded again. Error is changed. It is same with previous error but Makefile:548: recipe for target 'build/hikey960/release/bl2/early_exceptions.o' failed

It can be different gnu or gcc version?
Edit: I used :
sudo apt-get install gcc-aarch64-linux-gnu
sudo apt-get install gcc-arm-linux-gnueabihf

Edit2: I tried to build it again. Now, It is Makefile:544: recipe for target 'build/hikey960/release/bl1/bl1_exceptions.o' failed . It changed again.

It shouldn’t matter because the makefile downloads and uses its own toochains.

  1. Which arm-trusted-firmware did you clean? It should be the one in device/linaro/.

  2. If 1 is ok, can you try below?

make distclean in arm-trusted-firmware.
cd device/linaro/hikey/bootloader
make tst_fipbin_bld
If build passes, then just continue android build.

It is OK. I clean it in device/linaro/arm-trusted-firmware.

I have run above commands. Result is same.
bl1/aarch64/bl1_exceptions.S: Assembler messages:
bl1/aarch64/bl1_exceptions.S:29: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:35: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:41: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:47: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:57: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:63: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:69: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:75: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:94: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:100: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:106: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:112: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:122: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:128: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:134: Error: non-constant expression in “.if” statement
bl1/aarch64/bl1_exceptions.S:140: Error: non-constant expression in “.if” statement
Makefile:544: recipe for target ‘build/hikey960/release/bl1/bl1_exceptions.o’ failed
make[1]: *** [build/hikey960/release/bl1/bl1_exceptions.o] Error 1
make[1]: *** Waiting for unfinished jobs…
make[1]: Leaving directory ‘/home/xx/optee_android_manifest/device/linaro/arm-trusted-firmware’
------------------------------------------------------------
Hikey960 RELEASE fail
------------------------------------------------------------
pass 0
fail 1
Makefile:45: recipe for target ‘/home/xx/optee_android_manifest/out/dist/fip.bin’ failed
make: *** [/home/xx/optee_android_manifest/out/dist/fip.bin] Error 1

#### failed to build some targets (15 seconds) ####

Builds fine for me.

------------------------------------------------------------
                                       Hikey960 RELEASE	pass
------------------------------------------------------------
pass	1
fail	0

On further research, it might be a toolchain problem. Are you using Ubuntu 16.04? Can you try a linaro toolchain? E.g. http://releases.linaro.org/components/toolchain/binaries/5.4-2017.05/aarch64-linux-gnu/gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu.tar.xz and http://releases.linaro.org/components/toolchain/binaries/5.4-2017.05/arm-linux-gnueabihf/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz.

Yes, I am using Ubuntu 16.04. Now I am trying it. After trying I will edit this comment.
Edit: I think I have done somethings wrongly. Same error.
Edit2: I have installed Ubuntu 14.04.5 on my computer. I will try it again.
Edit3: @vchong

I re-installed Ubuntu as 14.04.5. I did everything step by step. I used linaro toolchain. But, Error is same. More detailed log : https://pastebin.com/Gs8tkN4a

Edit4: @vchong
This is for some tools version problem?

Edit5: @vchong I solved the problem. make TARGET_BUILD_UEFI=true TARGET_TEE_IS_OPTEE=true command needs root priviliges.

Building is finished now. But, What do I need to do in following steps?

#build kernel and boot img
#MUST be after building aosp since we need <out_dir>/ramdisk.img
cd kernel/linaro/hisilicon
../../../device/linaro/l-loader/cc

Just that. Go to the kernel/linaro/hisilicon folder and run the device/linaro/l-loader/cc script from there.

../scripts/gcc-version.sh: line 25: aarch64-linux-android-gcc: command not found
../scripts/gcc-version.sh: line 26: aarch64-linux-android-gcc: command not found
make[1]: aarch64-linux-android-gcc: Command not found
make[1]: aarch64-linux-android-gcc: Command not found

I have aarch64-linux-android-gcc but I think there is a version problem. How can I change this? I can not find it.

Secondly, it has “ANDROID_BUILD_TOP not found problem” line 67 in cc file. I changed $(ANDROID_BUILD_TOP) as ${ANDROID_BUILD_TOP} then problem is solved.

Did you run . ./build/envsetup.sh first before running cc?

Also, I fixed ANDROID_BUILD_TOP problem, so please update l-loader.

cd device/linaro/l-loader
repo sync .
cd ../../../kernel/linaro/hisilicon
make ARCH=arm64 distclean
../../../device/linaro/l-loader/cc

If cc doesn’t run due to permission error, make sure you set it to be an executable, i.e. chmod +x cc.

This is my aarch64-linux-android-gcc version. Yours should be the same since it’s part of the aosp source code.

$ aarch64-linux-android-gcc --version
real-aarch64-linux-android-gcc (GCC) 4.9.x 20150123 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.

I updated l-loader. I could run make TARGET_BUILD_UEFI=true TARGET_TEE_IS_OPTEE=true via sudo. So, I think I need to sudo command while I am working ../../../device/linaro/l-loader/cc despite cc is executable. What do you think about is this problem?

This is my aarch64-linux-android-gcc version:

aarch64-linux-android-gcc (GCC) 4.9.x 20150123 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.

But, error is same: command not found. (I used . ./build/envsetup.sh). I am working on solving this problem.

I don’t use sudo for make and cc. Sounds like something off with the system.

What is the output of uname -a?

From which folder did you run aarch64-linux-android-gcc?

Run echo $PATH. Among the folders listed, is there one that contains aarch64-linux-android-gcc?

Linux martin 4.4.0-98-generic #121~14.04.1-Ubuntu SMP Wed Oct 11 11:54:55 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

/home/martin/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin

/home/martin/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/martin/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin:/home/martin/optee_android_manifest/device/linaro/gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu/bin:/home/martin/optee_android_manifest/device/linaro/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin

Problem is solved. root does not show aarch64-linux-android-gcc. Now it is compiling. But, I dont understand why make TARGET_BUILD_UEFI=true TARGET_TEE_IS_OPTEE=true doesn’t run without sudo.

What’s the error with make without sudo?

We talked about : OpTEE + Android in Hikey960 - #37 by tesmnorth