Setting up AOSP and OPTEE

I want to setup AOSP + OPTEE for Hikey 620. The goal is to setup the latest version possible.

The website indicates that one should first follow AOSP build instructions. I have two questions:

  1. Should I download and build the master branch for AOSP as mentioned on this page or should I use some specific older branch ?

  2. Does the instruction of downloading the manifest (git clone https://github.com/linaro-swg/optee_android_manifest) need be done in the root folder of the AOSP download ?

Thanks

The ‘first follow AOSP build instructions’ is just to make sure that you have a system (with all the dependencies installed) that can build AOSP. It’s a separate build from the AOSP + OPTEE build and should not be mixed together under the same folder path.

  1. Yes, the one on this page. The ‘website’ links to this page as well.

  2. No, please do this from a separate location/folder than 1.

Note that 2 ‘only’ builds P, not master like in 1. P is the latest version supported for 2.

Why make me run two builds when all I really need is one, especially when building takes up so much time and space?
Yes, sorry, but AOSP is such a big project that we as a small organization with only a handful of people working on AOSP don’t have the resources to help troubleshoot all possible build and run issues. The community here can help to a certain degree, and some individuals have really done a tremendous job of that (@doitright comes to mind as one of them), but the point is to make sure there are no issues building ‘plain’ AOSP, so then we can concentrate on supporting only the OP-TEE portion and any related issues thereafter.

Thanks for the response.

I will let you know if I have any issues.

My compilation was successful. I haven’t tried flashing yet.

I have a question about the build-p.sh script. Does this script cover any changes made to AOSP files and files under optee/optee_os/ ? I remember in the past OPTEE needed separate compilation.

I have a question about the build-p.sh script. Does this script cover any changes made to AOSP files and files under optee/optee_os/ ? I remember in the past OPTEE needed separate compilation.

OP-TEE doesn’t need separate compilation. We’ve integrated it as part of the main AOSP build. That said, if you make any changes under optee/optee_os, optee_os and fip.bin might not be rebuild automatically due the make target missing a dependency. We’ll try to get the fix ‘loaded’ into our repos asap, but in the meantime, you can patch device/linaro/hikey manually as below.

index eb8100a6..bc6e1a1c 100644
--- a/build/tasks/build_uefi.mk
+++ b/build/tasks/build_uefi.mk
@@ -14,7 +14,13 @@ endif
 
 HOST_PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
 
-$(DIST_DIR_PRODUCT)/fip.bin: $(BOOTLOADER_DIR)/Makefile
+OPTEE_OS_DIR=optee/optee_os
+
+# rebuild fip.bin whenever optee_os is modified
+$(DIST_DIR_PRODUCT)/fip.bin: $(BOOTLOADER_DIR)/Makefile $(sort $(shell find -L 
$(OPTEE_OS_DIR)))
        rm -fr $(DIST_DIR_PRODUCT) $(OPTEE_OS_DIR)/out $(PRODUCT_OUT)/obj/optee

As for changes made to other AOSP files not related to OP-TEE, yes those should be covered as well as long as the Makefiles/Android.mk/Android.bp for them are written properly. The scripts are basically just wrappers around the ‘repo’ and ‘make’ commands with extra commands added to facilitate/automate patching for OP-TEE support and (hopefully) make it more user friendly.

Some of OPTEE related files are under external/ folder (e.g. external/optee_client/). I’m assuming no additional changes are needed to cover changes in those folders ?

Just to double check, is the following build_uefi.mk modification correct ?

Some of OPTEE related files are under external/ folder (e.g. external/optee_client/). I’m assuming no additional changes are needed to cover changes in those folders ?

Yes, these should be good. No additional changes needed. Are you seeing any problems?

Just to double check, is the following build_uefi.mk modification correct ?

Lgtm. You can test it by making some trivial change in optee/optee_os and run build.sh -v p out/dist/fip.bin to see if a new fip.bin gets built.

I tried flashing the branch on a Hikey 620 board (LeMaker). At first the flashing didn’t succeed because vendor.img was having error (remote: invalid partition). I switched to an older version of fastboot and the flashing succeeded.

However when I try to boot the board, it goes into a loop. Some output on the terminal keeps repeating. The following are two screen shots I took:

In the terminal, I can see the output ending at the following and looping again:

init: processing action (init.svc.zygote=stopping) from (/system/etc/init/bootstat.rc:66)

For reference, I used this fastboot file: https://drive.google.com/file/d/1rUcImoKBkUpSfDIBjVXf9uQ_2fD-PxY8/view?usp=sharing

I built the branch using build-p.sh. The build succeeded without any errors.

How can I make the boot work ? Is it an audio related issue as it has a failed step related to audio hal ?

Update: I did find a related question on the forum, but am not sure which solution should be used.

At first the flashing didn’t succeed because vendor.img was having error (remote: invalid partition). I switched to an older version of fastboot and the flashing succeeded.

You probably had on your board an old ptable image which doesn’t have a vendor partition. A reboot after flashing the new ptable image should help. The fastboot version isn’t the cause I think.

For the looping terminal errors, try plugging in a monitor. As you can see in the related question on the forum, it’s a kernel issue and not really related to OP-TEE.