AOSP+OPTEE: How to build optee_example host only

Hi there,

I boot up my hikey960 with AOSP+OPTEE as the instructions here: https://optee.readthedocs.io/building/aosp/aosp.html?highlight=aosp. Now I’m trying to rewrite some host code in external/optee_examples while I’m wondering how can I build the host without building the whole system?

Thank you.

Answered in: https://github.com/OP-TEE/optee_os/issues/2920

1 Like

Hello, I want to build AOSP+OPTEE,but the instructions is a little brief for me. And I want to know whether I should build a AOSP according tohttps://source.android.com/source/devices.html. Could you give me a more detail instruction? Thank you in advance.

Which instructions are brief? The build according to https://source.android.com/source/devices.html is the standard/generic hikey 620/960 build, but it doesn’t support OP-TEE. The OP-TEE build [1] builds upon the one in https://source.android.com/source/devices.html, with additions to support OP-TEE. It also, among other things, wraps the instructions in https://source.android.com/source/devices.html into build scripts so you don’t have to run them again manually. Just run the build scripts.

[1] Suggest you use the 3.4.0 stable build: https://github.com/linaro-swg/optee_android_manifest/tree/optee_kmgk_3.4.0

[EDIT] Please use 3.4.1 build instead: https://github.com/linaro-swg/optee_android_manifest/tree/optee_kmgk_3.4.1

Thank you a lot! I will try it. By the way ,It seems that the instruction https://optee.readthedocs.io/building/aosp/aosp.html?highlight=aosp does not distinguish the 4G ram and 3GRam board of hikey960. What configurations should I change or add if I want to build for the 4g RAM hikey960 board?

Hello ,I am not sure whether it is right that satisfy the 4G hikey960 board by adding options when run the build command just like the hikey620 do:

# for HiKey620
./sync-p.sh
./build-p.sh #or `./build.sh -v p -4g` for a 4GB board!

and can I use the binary files and images directly instead of finishing the whole steps and build the files?
Thank you very much!

The ‘-4g’ switch for the hikey620 build is for the eMMC storage size, not ram, because it comes with 4 or 8 g storage. It has no effect on the hikey960 build. The hikey960 only comes with 32g of storage. Afaik, there’s no AOSP specific option for different amount of ram. This applies to both the hikey620 and hikey960.

can I use the binary files and images directly instead of finishing the whole steps and build the files?

You mean using prebuilt images? Click on the ‘Download’ link on https://github.com/linaro-swg/optee_android_manifest/tree/optee_kmgk_3.4.0.

Hello! Thank you very much! I have downloaded these binary files, and flashed them. cuz I don’t have the dictionary tree, so I just run the last handful lines of command one by one in “flash-all.sh”.

fastboot flash ptable “${INSTALLER_DIR}”/prm_ptable.img
fastboot flash xloader “${INSTALLER_DIR}”/hisi-sec_xloader.img
fastboot flash fastboot “${INSTALLER_DIR}”/l-loader.bin
fastboot flash fip “${INSTALLER_DIR}”/fip.bin
#fastboot flash nvme “${INSTALLER_DIR}”/hisi-nvme.img
fastboot flash boot “${ANDROID_PRODUCT_OUT}”/boot.img
fastboot flash cache “${ANDROID_PRODUCT_OUT}”/cache.img
fastboot flash system “${ANDROID_PRODUCT_OUT}”/system.img
fastboot flash userdata “${ANDROID_PRODUCT_OUT}”/userdata.img
fastboot flash vendor “${ANDROID_PRODUCT_OUT}”/vendor.img

and the downloaded files are not boot.img, cache.img, ramdisk.img, but boot.img.xz, cache.img.xz ramdisk.img.xz and so on. so I use the .xz files to flash.
after these steps, I power up the board but these error occured:

remove-symbol-file /home/victor.chong/work/swg/aosp/tst/optee/edk2/Build/HiKey90
Image Return Status = Success
[Bds]Booting Boot from SD
[Bds]Booting Grub
[Bds]Booting Android Boot
add-symbol-file /home/victor.chong/work/swg/aosp/tst/optee/edk2/Build/HiKey960/0
Loading driver at 0x000B9B1E000 EntryPoint=0x000B9B1F000 AndroidBootApp.efi
Failed to get Abootimg Size: Invalid Parameter
Failed to load boot image from boot partition: Invalid Parameter
Failed to boot from partition: Invalid Parameter
Error: Image at 000B9B1E000 start failed: Invalid Parameter
remove-symbol-file /home/victor.chong/work/swg/aosp/tst/optee/edk2/Build/HiKey90
Image Return Status = Invalid Parameter
[Bds]Booting Android Fastboot
add-symbol-file /home/victor.chong/work/swg/aosp/tst/optee/edk2/Build/HiKey960/0
Loading driver at 0x000B9B1B000 EntryPoint=0x000B9B1C000 AndroidFastbootApp.efi
Android Fastboot mode - version 0.7.
Press RETURN or SPACE key to quit.

What mistake I have made, and what to do to sovel these problems? does these flashed files include optee_os? Is boot.img optee_os? or what version of optee should I use. I am so confused!

I want to follow these instruction to build my optee_AOSP
https://github.com/linaro-swg/optee_android_manifest/tree/optee_kmgk_3.4.0
but I have always met the time-out and fetch errors when sync it :

0curl: (7) Failed to connect to android.googlesource.com port 443:
0curl: (22) The requested URL returned error: 404 Not Found
Server does not provide clone.bundle; ignoring.

But I can successfully sync the AOSP repo according to

Are there any other way to solve the sync error?
Thank you for your kindly reply!

unxz *.img.xz to extract the files from .img.xz to .img before running flash-all.sh

optee_os is in fip.bin, version 3.4.0

not sure about the sync error, it should be the same command in the script, nothing fancy about it

Thank you so much! now it seems works, and I can also build my own optee-asop build. I am so lucky to get your help. BTW, it seems a bug or incompatibility in HDMI display, The screen always flickers and display disorder. I am not sure it is a known issue or not.

You’re welcome! Glad you got it to work. For the display, try running wm size 1280x720 on the board and reboot. If that also fails then sorry, no more ideas. Perhaps others can comment.

Dear vchong
I set the resolution of the screen, and it still disorder. but it doesn’t matter!
In the Android system, I can run the xtest without any error from the console, but I can find the location of the xtest and its .ta files. xtest dosen’t appear in /bin or /system/bin or some other folders which seem include binary files. Did I miss something or make some mistakes? If I find the folder that locate xtest and the corresponding .ta files respectively, It seems that I can build an example program and push the “host” files and .ta files to the folder respectively using adb instead of build them in the filesystem, and run the program. Is that right?
I want to build a simple android app with optee, and I have refered to your reply in this link https://discuss.96boards.org/t/building-an-android-app-using-op-tee/735
and the tutorials you mentioned in the link above. It is quite clear for me after that.

xtest is in /vendor/bin/.
TAs are in /vendor/lib/optee_armtz/.

It seems that I can build an example program and push the “host” files and .ta files to the folder respectively using adb instead of build them in the filesystem, and run the program. Is that right?

Right!

Building an Android App using OP-TEE

This link is quite old and won’t work with more recent builds where Treble is enabled. You can also see Developing Native Android Application with Optee - #15 by tesmnorth, where the author got it to work, but later had troubles too: How to link so library from optee client app with android ndk in Android 9. Perhaps you can check with him to see if/how he resolved the issue, and whether he’s willing to share some reference code.