Why is there a difference between contents of source built and pre-built system images?

Hello All,

I have been facing an issue where the Hikey970 boot fails with source built system.img. I followed the procedure as follows:

While investigating, I happened to compare the contents of the raw system images by mounting them on my host machine.

Following are the contents of the pre-built system.img top directory:

nand@nand:/mnt/storage2/ArunJTS/ticket_5055/nishad/status/pre$ ls -lh
total 180K
drwxr-xr-x. 37 root root 4.0K Apr 27  2018 app
drwxr-xr-x.  3 root 2000 8.0K Apr 27  2018 bin
-rw-------.  1 root root 2.2K Apr 27  2018 build.prop
-rw-r--r--.  1 root root  73K Apr 27  2018 compatibility_matrix.xml
drwxr-xr-x. 13 root root 4.0K Apr 27  2018 etc
drwxr-xr-x.  2 root root 4.0K Apr 27  2018 fake-libs
drwxr-xr-x.  2 root root 4.0K Apr 27  2018 fake-libs64
drwxr-xr-x.  2 root root 8.0K Apr 27  2018 fonts
drwxr-xr-x.  5 root root 4.0K Apr 27  2018 framework
drwxr-xr-x.  6 root root  12K Apr 27  2018 lib
drwxr-xr-x.  6 root root  12K Apr 27  2018 lib64
drwx------.  2 root root  16K Apr 27  2018 lost+found
-rw-r--r--.  1 root root 2.8K Apr 27  2018 manifest.xml
drwxr-xr-x.  3 root root 4.0K Apr 27  2018 media
drwxr-xr-x. 37 root root 4.0K Apr 27  2018 priv-app
drwxr-xr-x.  8 root root 4.0K Apr 27  2018 usr
drwxr-xr-x.  7 root 2000 4.0K Apr 27  2018 vendor
drwxr-xr-x.  2 root 2000 4.0K Apr 27  2018 xbin

Following are the contents of the source-AOSP-built system.img top directory:

nand@nand:/mnt/storage2/ArunJTS/ticket_5055/nishad/status/src$ ls -lh
total 680K
drwxr-xr-x.  2 root root 4.0K Dec  5 15:50 acct
drwxr-xr-x.  2 root root 4.0K Dec  5 15:50 apex
lrw-r--r--.  1 root root   11 Dec 10 11:22 bin -> /system/bin
lrw-r--r--.  1 root root   50 Dec 10 11:22 bugreports -> /data/user_de/0/com.android.shell/files/bugreports
drwxrwx---.  2 nand 2001 4.0K Dec  5 15:50 cache
lrw-r--r--.  1 root root   13 Dec 10 11:22 charger -> /sbin/charger
dr-xr-xr-x.  2 root root 4.0K Dec  5 15:50 config
lrw-r--r--.  1 root root   17 Dec 10 11:22 d -> /sys/kernel/debug
drwxrwx--x.  2 nand nand 4.0K Dec  5 15:50 data
-rw-------.  1 root root 1.7K Dec  5 15:50 default.prop
drwxr-xr-x.  2 root root 4.0K Dec  5 15:50 dev
lrw-r--r--.  1 root root   11 Dec 10 11:22 etc -> /system/etc
-rw-r-----.  1 root 2000 1.5K Dec  5 15:50 fstab.hikey970
lrwxr-x---.  1 root 2000   16 Dec 10 11:22 init -> /system/bin/init
-rwxr-x---.  1 root 2000 1.1K Dec  5 15:50 init.environ.rc
-rwxr-x---.  1 root 2000 1.4K Dec  5 15:50 init.hikey970.power.rc
-rwxr-x---.  1 root 2000 3.2K Dec  5 15:50 init.hikey970.rc
-rwxr-x---.  1 root 2000 4.2K Dec  5 15:50 init.hikey970.usb.rc
-rwxr-x---.  1 root 2000  31K Dec  5 15:50 init.rc
-rwxr-x---.  1 root 2000 7.6K Dec  5 15:50 init.usb.configfs.rc
-rwxr-x---.  1 root 2000 5.6K Dec  5 15:50 init.usb.rc
-rwxr-x---.  1 root 2000  511 Dec  5 15:50 init.zygote32.rc
-rwxr-x---.  1 root 2000  875 Dec  5 15:50 init.zygote64_32.rc
drwx------.  2 root root  16K Dec 10 11:23 lost+found
drwxr-xr-x.  2 root nand 4.0K Dec  5 15:50 mnt
drwxr-xr-x.  2 root root 4.0K Dec  5 15:50 odm
drwxr-xr-x.  2 root root 4.0K Dec  5 15:50 oem
-rw-r--r--.  1 root root  26K Dec  6 10:52 plat_file_contexts
-rw-r--r--.  1 root root 7.7K Dec  6 10:52 plat_hwservice_contexts
-rw-r--r--.  1 root root 7.8K Dec  6 10:52 plat_property_contexts
-rw-r--r--.  1 root root 1.5K Dec  6 10:52 plat_seapp_contexts
-rw-r--r--.  1 root root  16K Dec  6 10:52 plat_service_contexts
drwxr-xr-x.  2 root root 4.0K Dec  5 15:50 proc
lrw-r--r--.  1 root root   15 Dec 10 11:22 product -> /system/product
lrw-r--r--.  1 root root   24 Dec 10 11:22 product_services -> /system/product_services
drwxr-x---.  2 root 2000 4.0K Dec  6 09:34 sbin
lrw-r--r--.  1 root root   21 Dec 10 11:22 sdcard -> /storage/self/primary
-rw-r--r--.  1 root root 427K Dec  6 10:52 sepolicy
drwxr-x--x.  2 root 1028 4.0K Dec  5 15:50 storage
drwxr-xr-x.  2 root root 4.0K Dec  5 15:50 sys
drwxr-xr-x. 19 root root 4.0K Dec  6 10:57 system
-rw-r--r--.  1 root root  375 Dec  5 15:50 ueventd.hikey970.rc
-rw-r--r--.  1 root root 5.3K Dec  5 15:50 ueventd.rc
lrw-r--r--.  1 root root   14 Dec 10 11:22 vendor -> /system/vendor
-rw-r--r--.  1 root root 7.4K Dec  6 10:52 vendor_file_contexts
-rw-r--r--.  1 root root    0 Dec  6 10:52 vendor_hwservice_contexts
-rw-r--r--.  1 root root  329 Dec  6 10:52 vendor_property_contexts
-rw-r--r--.  1 root root    0 Dec  6 10:52 vendor_seapp_contexts
-rw-r--r--.  1 root root   44 Dec  6 10:52 vendor_service_contexts
-rw-r--r--.  1 root root   65 Dec  6 10:52 vndservice_contexts

There is a lot of difference here,

Seems like, the source built image contains a directory system, where it should only have the contents of the system directory.

Can anyone tell me why is there such a difference between contents of source built and pre-built system images ?

Thanks for your time,

Regards,
Nishad

Hello Nishad,

This seems to be related to the system-as-root feature:

All new devices launching with Android 9 must use system-as-root ( BOARD_BUILD_SYSTEM_ROOT_IMAGE must be true ), which merges ramdisk.img into system.img , which in turn is mounted as rootfs.

I was able to boot the Hikey970 with the system.img generated using master branches of AOSP by modifying the cmdline embedded in the boot.img. To do so, you can replace in build_kernel.sh:

${MKBOOTTOOL_DIR}/mkbootimg --kernel ${HIKEY970_KERNEL}/Image-dtb --ramdisk ${RAMDISK} --cmdline "androidboot.hardware=hikey970 firmware_class.path=/system/etc/firmware loglevel=15 buildvariant=userdebug androidboot.selinux=permissive clk_ignore_unused=true" --base 0x0 --tags_offset 0x07A00000 --kernel_offset 0x00080000 --ramdisk_offset 0x07c00000 --os_version 7.0 --os_patch_level 2016-08-05 --output ${PRODUCT_OUT}/boot.img

by

${MKBOOTTOOL_DIR}/mkbootimg.py --kernel ${HIKEY970_KERNEL}/Image-dtb --ramdisk ${RAMDISK} --cmdline "androidboot.hardware=hikey970 firmware_class.path=/system/etc/firmware loglevel=15 buildvariant=userdebug androidboot.selinux=permissive clk_ignore_unused=true root=/dev/sdd12 rootwait skip_initramfs init=/init" --base 0x0 --tags_offset 0x07A00000 --kernel_offset 0x00080000 --ramdisk_offset 0x07c00000 --os_version 9.0 --os_patch_level 2016-08-05 --output ${PRODUCT_OUT}/boot.img

Best regards,

2 Likes

I can confirm it works and boots without any noticeable issue. Thanks @Charly-D

Hello Charly-D,

Thanks a lot for the information.

After applying these changes, I am able to boot the Hikey970 with the system.img generated from the master branch of AOSP.

Thanks again,

Regards,
Nishad

Hi!

I’m trying to follow these instructions to build the pie-release branch of AOSP. It stops in the middle of boot and I get only a black screen from the HDMI output.

Was there any other modification than the ones listed here that you had to make for it to boot properly?

Cheers,
Fredrik

@freedrikp I think this would be good summary of most important adjustments to the original build instructions to make it work:

Hikey970 boot fails when Source built system.img is flashed - #13 by nishad_kamdar

I was following those instructions. I retried it but on aosp master instead of pie-release and there it actually worked.

I will attempt a clean checkout of pie-release and doing the exact same step to see if it works then.

Interesting… Following the same instructions do not work on pie-release branch of AOSP.

@freedrikp alright, so the instruction here apply to master only. To build pie release you should be fine with just the instructions I linked before

Hi, yeah, I created a separate topic for this but I did manage to build it just now. Thank you for your help!