Android/Open Devices

From Segfault
Jump to navigation Jump to search

Build AOSP

According to the build instructions,[1] but with some fixes applied:

sudo apt-get install openjdk-8-jdk bison g++-multilib git gperf libxml2-utils make \
                     zlib1g-dev:i386 zip liblz4-tool python unzip xz-utils libssl-dev flex
sudo dnf install     java-1.8.0-openjdk-devel bison gcc-c++ git gperf libxml \
                     ncurses-compat-libs make zip unzip openssl-devel zlib-devel flex lz4

sudo wget http://commondatastorage.googleapis.com/git-repo-downloads/repo -O /usr/local/bin/repo
sudo chmod 0755 /usr/local/bin/repo

mkdir -p /usr/local/src/android && cd $_
repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r26 # See platform/manifest/+refs

cd .repo
git clone https://github.com/sonyxperiadev/local_manifests
cd local_manifests
git checkout android-8.1.0_r26                                  # The branch should match the AOSP source above!
cd ../..

Sync repository:

repo sync                                                       # Maybe add --force-sync --prune
./repo_update.sh

Build:

export LC_ALL=C                                                 # flex might fail otherwise[2]
source build/envsetup.sh && lunch aosp_g8232-userdebug          # device: keyaki platform: tone variant: userdebug[3]
make -j4

Errors

Missing includes

In file included from bootable/recovery/minui/graphics.cpp:30:
bootable/recovery/minui/graphics_overlay.h:21:10: fatal error: 'linux/msm_mdp.h' file not found
#include <linux/msm_mdp.h>
         ^01:55, 23 May 2018 (CEST)01:55, 23 May 2018 (CEST)01:55, 23 May 2018 (CEST)~

Trying to fix:

$ cd bootable/recovery/
$ git diff
diff --git a/minui/Android.mk b/minui/Android.mk
index 76c6816f..9c076e0b 100644
--- a/minui/Android.mk
+++ b/minui/Android.mk
@@ -34,7 +34,7 @@ LOCAL_STATIC_LIBRARIES := \
     libbase
 
 LOCAL_CFLAGS := -Werror
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/../../../kernel/sony/msm/include/uapi/
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
 
 LOCAL_MODULE := libminui

But this of course (!) triggers:

In file included from bootable/recovery/minui/events.cpp:17:
In file included from bionic/libc/include/dirent.h:34:
In file included from bionic/libc/include/sys/types.h:36:
bootable/recovery/minui/../../../kernel/sony/msm/include/uapi/linux/types.h:9:2: error: "Attempt to use kernel headers from user space, see 
http://kernelnewbies.org/KernelHeaders" [-Werror,-W#warnings]
#warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders"
^

Revert that "fix" and instead do:

cp -ivp kernel/sony/msm/include/uapi/linux/msm_* bionic/libc/kernel/uapi/linux/

This helps for some objects, but will eventually fail again. The trick was to upgrade the repository from android-8.1.0_r15 to android-8.1.0_r26 :-|

Assertion failed

The pre-compiled flex binary errors out with:

[  1% 1220/84723] Lex: applypatch <= bootable/recovery/edify/lexer.ll
FAILED: out/target/product/keyaki/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp
/bin/bash -c "prebuilts/misc/linux-x86/flex/flex-2.5.39 -oout/target/product/keyaki/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp bootable/recovery/edify/lexer.ll"
flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
Aborted
[  1% 1223/84723] Building with Jack: out/target/common/obj/JAVA_LIBRARIES/libphonenumber_intermediates/classes.jack
ninja: build stopped: subcommand failed.

Fixed by:[2][4][5][6]

export LC_ALL=C

Cannot lock profiles

After 4.5 hours of compiling:

[ 80% 68132/84359] Dexpreopt Jar: wifi-service (out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates/oat/arm64/javalib.odex)
FAILED: out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates/oat/arm64/javalib.odex
/bin/bash -c "(rm -f out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates/oat/arm64/javalib.odex ) && (mkdir -p out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates/oat/arm64/ ) && (ANDROID_LOG_TAGS=\"*:e\" out/host/linux-x86/bin/dex2oatd --runtime-arg -Xms64m --runtime-arg -Xmx512m --class-loader-context=\"&\" --boot-image=out/target/product/keyaki/dex_bootjars/system/framework/boot.art --dex-file=out/target/common/obj/JAVA_LIBRARIES/wifi-service_intermediates/javalib.jar --dex-location=/system/framework/wifi-service.jar --oat-file=out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates/oat/arm64/javalib.odex --android-root=out/target/product/keyaki/system --instruction-set=arm64 --instruction-set-variant=kryo --instruction-set-features=default --runtime-arg -Xnorelocate --compile-pic --no-generate-debug-info --generate-build-id --abort-on-hard-verifier-error --force-determinism --no-inline-from=core-oj.jar  --compiler-filter=speed --app-image-file=out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates/oat/arm64/javalib.art --image-format=lz4 --profile-file=out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates//profile.prof )"
dex2oatd E 05-22 23:36:30 21569 21569 dex2oat.cc:2329] Cannot lock profiles: Failed to lock file 'out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates//profile.prof': Bad file descriptor
dex2oatd E 05-22 23:36:30 21569 21569 dex2oat.cc:3093] Failed to process profile file
[ 80% 68135/84359] //frameworks/rs:libRS_internal header-abi-dumper .intermediates/frameworks/rs/rs_generated_sources/gen/frameworks/rs/rsgApiReplay.cpp [arm]
ninja: build stopped: subcommand failed.
23:36:31 ninja failed with: exit status 1

#### failed to build some targets (04:24:21 (hh:mm:ss)) ####

Hm.

$ ls -l out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates//profile.prof
-rw-r--r-- 1 dummy dummy 1781 May 22 23:36 out/target/product/keyaki/obj/JAVA_LIBRARIES/wifi-service_intermediates//profile.prof
$ mount | grep nfs | grep lock
nfs:/usr/local/src on /usr/local/src type nfs4 \
       (rw,nosuid,nodev,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.56.144,fsc,local_lock=none,addr=192.168.0.115)

VNDK Abi broken

During the build:[7]

[ 69% 11285/16235] //hardware/interfaces/neuralnetworks/1.0:android.hardware.neuralnetworks@1.0 header-abi-diff android.hardware.neuralnetworks@1.0.so.abidiff
******************************************************
VNDK Abi broken: Please check compatiblity report at : \
 out/soong/.intermediates/hardware/interfaces/neuralnetworks/1.0/android.hardware.neuralnetworks@1.0/android_arm64_armv8-a_kryo_shared_core/android.hardware.neuralnetworks@1.0.so.abidiff

...?

Build warnings

[...]
[6/6] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja
bootable/recovery/minui/Android.mk was modified, regenerating...
[137/998] including ./device/sony/common/Android.mk ...
ln: failed to create symbolic link 'egl': File exists
ln: failed to create symbolic link 'libllvm-glnext.so': File exists
ln: failed to create symbolic link 'libllvm-qgl.so': File exists
ln: failed to create symbolic link 'libc2d30_bltlib.so': File exists
ln: failed to create symbolic link 'libc2d30-a3xx.so': File exists
ln: failed to create symbolic link 'libc2d30-a4xx.so': File exists
ln: failed to create symbolic link 'libc2d30-a5xx.so': File exists
ln: failed to create symbolic link 'libmm-qdcm.so': File exists
ln: failed to create symbolic link 'librs_adreno.so': File exists
ln: failed to create symbolic link 'libadreno_utils.so': File exists
ln: failed to create symbolic link 'libCB.so': File exists
ln: failed to create symbolic link 'libgsl.so': File exists
ln: failed to create symbolic link 'libC2D2.so': File exists
ln: failed to create symbolic link 'libRSDriver_adreno.so': File exists
ln: failed to create symbolic link 'libOpenCL.so': File exists
ln: failed to create symbolic link 'libllvm-qcom.so': File exists
ln: failed to create symbolic link 'librs_adreno_sha1.so': File exists
ln: failed to create symbolic link 'vulkan.msm8996.so': File exists
ln: failed to create symbolic link 'egl': File exists
ln: failed to create symbolic link 'libllvm-glnext.so': File exists
ln: failed to create symbolic link 'libllvm-qgl.so': File exists
ln: failed to create symbolic link 'libc2d30_bltlib.so': File exists
ln: failed to create symbolic link 'libc2d30-a3xx.so': File exists
ln: failed to create symbolic link 'libc2d30-a4xx.so': File exists
ln: failed to create symbolic link 'libc2d30-a5xx.so': File exists
ln: failed to create symbolic link 'libmm-qdcm.so': File exists
ln: failed to create symbolic link 'librs_adreno.so': File exists
ln: failed to create symbolic link 'libadreno_utils.so': File exists
ln: failed to create symbolic link 'libCB.so': File exists
ln: failed to create symbolic link 'libgsl.so': File exists
ln: failed to create symbolic link 'libC2D2.so': File exists
ln: failed to create symbolic link 'libRSDriver_adreno.so': File exists
ln: failed to create symbolic link 'libOpenCL.so': File exists
ln: failed to create symbolic link 'libllvm-qcom.so': File exists
ln: failed to create symbolic link 'librs_adreno_sha1.so': File exists
ln: failed to create symbolic link 'vulkan.msm8996.so': File exists
/bin/bash: line 0: pushd: out/target/product/keyaki/odm/: No such file or directory


[672/998] including ./system/sepolicy/Android.mk ...
./system/sepolicy/Android.mk:111: warning: BOARD_SEPOLICY_VERS not specified, assuming current platform version
[998/998] including ./vendor/qcom/opensource/wlan/wcnss-service/Android.mk ... 
PRODUCT_COPY_FILES device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml ignored.
No private recovery resources for TARGET_DEVICE keyaki
platform_testing/build/tasks/tests/instrumentation_metric_test_list.mk: warning: continuous_instrumentation_metric_tests: Unknown installed file for module perf-setup.sh 
platform_testing/build/tasks/tests/instrumentation_test_list.mk: warning: continuous_instrumentation_tests: Unknown installed file for module RecyclerViewTests 
platform_testing/build/tasks/tests/instrumentation_test_list.mk: warning: continuous_instrumentation_tests: Unknown installed file for module SettingsFunctionalTests 
platform_testing/build/tasks/tests/instrumentation_test_list.mk: warning: continuous_instrumentation_tests: Unknown installed file for module LauncherFunctionalTests 
platform_testing/build/tasks/tests/instrumentation_test_list.mk: warning: continuous_instrumentation_tests: Unknown installed file for module EmergencyInfoTests 
platform_testing/build/tasks/tests/native_metric_test_list.mk: warning: continuous_native_metric_tests: Unknown installed file for module perf-setup.sh 

build/core/Makefile:34: warning: overriding commands for target `out/target/product/keyaki/system/vendor/etc/gps.conf'
build/core/base_rules.mk:390: warning: ignoring old commands for target `out/target/product/keyaki/system/vendor/etc/gps.conf'
[100% 2/2] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja
[ 50% 1/2] glob bionic/libc/kernel/uapi/linux/**/*.h
[  0% 84/84727] Install: out/target/product/keyaki/root/init.environ.rc

ln: failed to access 'out/target/product/keyaki/root/d/debug': Permission denied
[  0% 144/84727] Ensuring Jack server is installed and started
Jack server already installed in "/home/dummy/.jack-server"
Server is already running
  • Why is out/target/product/keyaki/odm/ missing?
  • out/target/product/keyaki/root/d points to /sys/kernel/debug, which is of course readable only by root
  • Build warnings can be...ignored?

Misc

Me, trying to reset the repositories:

cd /usr/local/src/android
find . -type d -name .git | while read d; do cd "$d"/.. && pwd && git clean -dfx && git reset --hard && cd - > /dev/null || break; echo; done

Installation

Once the build is complete, the following images should be available:

$ ls -gohtr out/target/product/*/*img
-rw-r--r-- 1 193K May 23 00:30 out/target/product/keyaki/cache.img
-rw-r--r-- 1  30M May 23 01:12 out/target/product/keyaki/userdata.img
-rw-r--r-- 1 1.2M May 23 01:13 out/target/product/keyaki/ramdisk.img
-rw-r--r-- 1  12M May 23 01:13 out/target/product/keyaki/boot.img
-rw-r--r-- 1 6.8M May 23 01:13 out/target/product/keyaki/ramdisk-recovery.img
-rw-r--r-- 1  18M May 23 01:13 out/target/product/keyaki/recovery.img
-rw-r--r-- 1 929M May 23 01:14 out/target/product/keyaki/system.img

Let's try to find out which kernel version has been built:

$ grep -m1 KERNEL_VERSION device/sony/tone/platform.mk
SOMC_KERNEL_VERSION := 4.4

$ gzip -fdc out/target/product/*/kernel | strings | grep -m1 ^Linux
Linux version 4.4.153-ge8c10776b71b-dirty (root@seldlx21330) (gcc version 4.9.x 20150123 (prerelease) (GCC)) #6 SMP PREEMPT Mon Sep 3 12:06:10 CEST 2018

Install with fastboot:

fastboot flash boot     out/target/product/keyaki/boot.img
fastboot flash recovery out/target/product/keyaki/recovery.img
fastboot flash system   out/target/product/keyaki/system.img
fastboot flash vendor   out/target/product/keyaki/vendor.img
fastboot flash userdata out/target/product/keyaki/userdata.img                    # Only if needed!

Install the correct[8] vendor image for the right platform:

sha256sum SW*.zip | grep db78fc0e8ce578489e5aa51ed5f64118a968d2e9af950af6ee649a1283a0b84b
unzip  SW*.zip

fastboot flash oem SW*.img

Recovery

TBD

Links


TBD:

References