There are a lot of causes and nonsense in front, want to see the research directly point title jump ha

Refer to the article

Learn about creating image files in Android 10

Foreword & Cause

  • I also calculate the officer to circle, the circle there is almost no technology sharing, open source, because many of them involve the private interests, but I always will share their unique technology and can technology to separate, I will also share some of the other authors think own technology tutorials, was met by a series of attacks, But I tell anyone who asks me for technology that’s not strictly personal
  • MIUI system 4.27 released MIUI12, the authors of the official change circle have adapted to this latest system official change, almost everyone encountered the problem of camera undeletion after Mi10’s official change. Some senior official change authors I know basically fixed this problem during the 5.1 holiday
  • The result of this problem is that the camera of the official reform system generated by the toolbox I developed also flashes back, so unless I can bear that I can’t use any scan function when testing the system, I can’t continue to develop any related functions

5.1 A person to Rent a house in Chengdu, the first day to stay in a hotel, the second day to take a bus to live 20 kilometers away from my cousin, the third day to pay the rent, the next two days are also busy, those days are a long story… 🤬

Abnormal performance 🤔

  • In the latest 10/10 pro, millet k20, such as one plus eight devices have adopted dynamic partition mechanism, cited the super this partition, dynamic flash when set up the system/vender/odm/product partition size, save a space
  • The reason for writing this is that when the two models of Mi 10/10Pro were repacked, some permissions of the system/ Vendor partition would be abnormal, such as the camera flashes back, and the null pointer of getCap() is abnormal when the log is captured. However, there is no problem after the official package is washed in, so the abnormality must not be caused by the camera APP. Moreover, qq/ wechat and other apps cannot open the camera properly.

This part of the information is really too little, in addition to reference articles help me, other people are not willing to share this part of the knowledge

  • As a developer of official reform tools, the purpose of my toolbox is to let those who like to brush the machine make official reform by themselves, which also involves interests, so it is impossible for any of them to tell me the solution direction.

Camera error details 😑

io.reactivex.exceptions.OnErrorNotImplementedException: Attempt to invoke virtual method 'boolean com.android.camera2.CameraCapabilities.isSupportParallelCameraDevice()' on a null object reference
Copy the code

Error tracing 😑

Logcat shows that the camera service fails when the device is turned on, as follows:

1636 W CameraService_proxy: Cameraserver, camera service not available. 05-11 19:56:54.547 1636 1636 I CameraService_proxy: Could not notify camera service of user switch, retrying...Copy the code

Since the service fails to start up anywhere the camera is used, it keeps trying to start up, causing the phone to get hot and power consumption to speed up

Positioning to the service of the rc file/vendor/etc/init/[email protected]_64.rc

#! /bin/sh
#
#Copyright (c) 2019 Qualcomm Technologies, Inc.
#All Rights Reserved.
#Confidential and Proprietary - Qualcomm Technologies, Inc.
#The service vendor. Camera - the provider - 2-4 / vendor/bin/hw/[email protected]_64 override interface [email protected]: : ICameraProvider legacy / 0 class Hal user cameraserver group audio camera input drmrpc oem_2907 ioprio rt 4 capabilities SYS_NICE writepid /dev/cpuset/camera-daemon/tasks /dev/stune/foreground/tasksCopy the code

Find it service executable/vendor/bin/hw/[email protected]_64 is a binary, we direct execution, the output is as follows:

[email protected]_64; exit       <
WARNING: linker: Warning: "/vendor/lib64/libmialgo_ie_preview.so" unused DT entry: DT_RPATH (type 0xf arg 0x22741) (ignoring)
WARNING: linker: Warning: "/vendor/lib64/libcamera_scene.so" unused DT entry: DT_RPATH (type 0xf arg 0xe1b) (ignoring)
WARNING: linker: Warning: "/vendor/lib64/libarcsoft_bodyslim.so" unused DT entry: DT_RPATH (type 0xf arg 0xb74) (ignoring)
WARNING: linker: Warning: unable to normalize "D" (ignoring)
WARNING: linker: Warning: unable to normalize "\ tools \ android - the NDK - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ Linux \ aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "E" (ignoring)
WARNING: linker: Warning: unable to normalize "\ Working \ Code \ android - the NDK - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ Linux \ aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "E" (ignoring)
WARNING: linker: Warning: unable to normalize "\ Working \ Code \ android - the NDK - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ Linux \ aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "D" (ignoring)
WARNING: linker: Warning: unable to normalize "\ tools \ android - the NDK - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ Linux \ aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "E" (ignoring)
WARNING: linker: Warning: unable to normalize "\ Working \ Code \ android - the NDK - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ Linux \ aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "E" (ignoring)
WARNING: linker: Warning: unable to normalize "\ Working \ Code \ android - the NDK - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ Linux \ aarch64" (ignoring)
WARNING: linker: Warning: "/vendor/lib64/libmibokeh_845_video.so" unused DT entry: DT_RPATH (type 0xf arg 0x1e80) (ignoring)
WARNING: linker: Warning: "/vendor/lib64/libmibokeh_855.so" unused DT entry: DT_RPATH (type 0xf arg 0x1954) (ignoring)
WARNING: linker: Warning: unable to normalize "D" (ignoring)
WARNING: linker: Warning: unable to normalize "\ android_tools \ android - the NDK - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ Linux \ aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "D" (ignoring)
WARNING: linker: Warning: unable to normalize "/ User/User \ AppData \ Local \ Android \ Sdk \ the NDK - bundle - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ linu x\aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "D" (ignoring)
WARNING: linker: Warning: unable to normalize "/ User/User \ AppData \ Local \ Android \ Sdk \ the NDK - bundle - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ linu x\aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "D" (ignoring)
WARNING: linker: Warning: unable to normalize "\ android_tools \ android - the NDK - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ Linux \ aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "D" (ignoring)
WARNING: linker: Warning: unable to normalize "/ User/User \ AppData \ Local \ Android \ Sdk \ the NDK - bundle - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ linu x\aarch64" (ignoring)
WARNING: linker: Warning: unable to normalize "D" (ignoring)
WARNING: linker: Warning: unable to normalize "/ User/User \ AppData \ Local \ Android \ Sdk \ the NDK - bundle - r18b \ toolchains \ LLVM \ prebuilt \ Windows - x86_64 / lib64 / clang \ 7.0.2 \ lib \ linu x\aarch64" (ignoring)
terminating with uncaught exception of type std::bad_cast: std::bad_cast
Aborted
Copy the code

It is all wrong. There is no such error in the execution of this file by the official system. I can only confirm that it is caused by the secondary packaging, which cannot be located from the program layer

Try to locate 🧐 with ext4 IMG information

Fs_config contains the permission, UID, and GID information of each node in the ext partition parsed from the file system partition. It will be used during image generation. The format of fs_config is as follows:

lost+found 0000 0000 00700
Uid =0(root) gid=0(root) Permission is RWX ------
Copy the code

File_context is the Selinux information of each node in the ext4 partition parsed from the ext4 partition and used in image generation. The format is as follows:

/lost\+found u:object_r:rootfs:s0
# \ to escape
Copy the code

Preliminary positioning

  • 1. Use the toolbox to pack the official system twice
  • 2. Figure out the fs_config, file_context, and capabilities of the system/vendor image that is large after the secondary process of the toolkit
  • 3. Compare the information in the official mirror (no difference found, this is the most troublesome 🤯)

It took me about two days to make sure all of the above, and I went through the class while locating the bugs. Later, WHEN I was lying in bed at 2 or 3 am, I realized that there was an error in Android Pie(9) that file_context was missing the root directory Selinux. That is, it records the information of all nodes in the partition, that is, it does not record the information of the nodes to which it is mounted

The secondary positioning

System.img is the system partition, which contains a large number of system software /framework layers. This article will not go into detail

Vendor. img is the underlying partition that contains the underlying device drivers

In order to solve the problem of system upgrade and massive data replacement brought by system adaptation, Google separated the system layer from the driver layer (together in the early stage) from the initial A Only structure to the current SAR structure.

  • Img mount point information. In a system with a SAR (System as root) partition structure, the mount point information of system.img is the same as the official source information
  • Check the information about the mount point of vendor.mg. The mount point is /vendor

The vendor mount point is abnormal as follows

Official system mount point information

/vendor 0000 2000 00755
Copy the code

That is, the vendor mount point information after uid=0(root) and GID =2000(shell) are packed twice

/vendor 0000 0000 00755
Copy the code

The gid is from 2000 to 0000, so the permission of the root directory of the partition is changed to root. As a result, programs without root permission cannot access the root directory of the partition. For example, services of the camera service whose GID is 2000 cannot get the permission of the underlying driver

Android image file generation

To understand this part, you can no doubt read a lot of posts and look at the compiled source code for Android

I began to realize the second generation of mirror image 3 years ago, I wrote a set of universal generation scheme, covering Android 5-10, recently MIUI12 came out gg

The old generation scheme

It’s the one I’ve been using

Use the make_ext4fs program (this program cannot use the Android SDK platform-tools, is not compatible with Android 9 and later, need to compile github third-party developers for pie fix).

The make_ext4fs function is to generate the standard ext4 partition IMG from the consolidated folder

Make_ext4fs method to generate a mirror

make_ext4fs -L $point -T 1230739200 $simg -s -S file_contexts -C fs_config -l $filesize -a $point volume.img $flodername
Copy the code

Argument parsing

  • -l: lable, the label of the mirror.
  • -t: Time stamps of all nodes in a partition. On MIUI, the time stamps are usually 0 or 1230739200, which are equivalent to 1970/01/01. This inconsistency also causes many abnormal bugs in the system
  • -S: Generated SPARSE IMG (the difference between SIMG and RIMG is not analyzed here). If the switch is cancelled, RIMG will be generated
  • -s: Selinux information of a partition
  • -l: indicates the partition size
  • -A: mount point of a partition (a/ B partition is /, a only is system)
  • Volume. img: indicates the image name
  • $floderName: folder that needs to be packaged as an image

For more parameters, run make_ext4fs -h

Android8.0 after the introduction of the generation scheme

As you can see, Google removed the make_ext4fs file from platform-Tools in Android 9.0

I considered using this method when COMPILING a compatible package scheme at the beginning, but I gave up due to my limited ability at that time. If you Google make_ext4fs, you should be able to directly search my issue under someone else’s open source

  • Read a lot of android compiled source code (I personally read a lot of third-party literature)
  • Read the Android mirror compilation code for Aos-Mirror on Github

This is finally found in tools/ releaseTools in the aosp-mirror platform_build library

Key documents involved

  • Build_image. py: package the consolidated folder as ext4, parse the received parameters, and call mkuserimg_mke2fs to generate the IMG image
  • Mkuserimg_mke2fs. sh: calls mke2fs and e2fsdroid according to the parameters
  • Mke2fs: Used to generate a blank partition
  • E2fsdroid: used to copy folders to empty partitions and restore fs_config and file_conetxt

The following is the dynamic partition correlation, this paper will not do the research (I have tried no problem)

  • Build_super_image. Py: existing system/vendor/product/odm mirror generates super. Img image
  • Lpmake: used to generate super.img with arguments for each partition that has been generated
  • Lpunpack: Used to pressurize super.img

First attempt to generate a mirror (system.img as an example)

Source several reference posts at the top of this article

Use the following command

build_image.py ./system ./system_image_info.txt system.img
Copy the code

system_image_info.txt

ext_mkusering=./mkusering_mke2fs
fs_type=ext4
system_size=3508158464
extfs_sparse_flag=-s
squashfs_sparse_flag=-s
skip_fsck=true
selinux_fc=file_context
fs_config=fs_config
Copy the code

As a result, all kinds of failures

After the script is executed, the RAM of Linux system changes from 1g to 7G in an instant, and is occasionally directly full (when the computer is full, it freezes). Finally, what memory is out, and the output is completely unable to locate the problem, and this part did not pay attention to record the output

The above results I generated locally on the mobile phone are the same as those on Linux. I have tried all the third-party configuration schemes, but none of them worked

The second attempt is made to generate a mirror

After reading build_image.py, it puts the received parameters into the dictionary to generate and evaluate the new parameters to mkeusering_mke2fs.sh

So we use the mkeUsering_mke2fs.sh script directly

Look at the help output first

mkuserimg.sh [-s] SRC_DIR OUTPUT_FILE EXT_VARIANT MOUNT_POINT SIZE [-j <journal_size>]
             [-T TIMESTAMP] [-C FS_CONFIG] [-D PRODUCT_OUT] [-B BLOCK_LIST_FILE]
             [-d BASE_ALLOC_FILE_IN ] [-A BASE_ALLOC_FILE_OUT ] [-L LABEL]
             [-i INODES ] [-M RSV_PCT] [-e ERASE_BLOCK_SIZE] [-o FLASH_BLOCK_SIZE]
             [-U MKE2FS_UUID] [-S MKE2FS_HASH_SEED] [-c] [FILE_CONTEXTS]
Copy the code

After many attempts, the command is summarized

mkuserimg.sh -s "\$PATH" "\$OUTPUT" ext4 / \$SIZE -T 0 -L / \$FILE_CONTEXTS
Copy the code

Fs_config changes

Add vendor root mount point permissions

/ 0000 2000 00755
Copy the code

If the permissions of all nodes in the partition have been reserved on the Linux device (that is, the permissions of nodes in the folder before the package are correct), you can omit the fs_config file used by all tools above.

The generated pit

It is because I read more related blogs, most of the authors add -m 0 -j 0 these two parameters, and finally after a lot of my tests, one of these two parameters will not boot!! 🤪

Quick reference

Later in the fix, it was discovered that there was also a new packaging solution 🤯 in ErfanGSIs, the open source library used to generate GSI

conclusion

In other words, the make_ext4fs tool cannot restore the root privileges of a partition, only the new scheme

  • Thank you for pointing out any mistakes in this article.
  • I don’t care about these circles attacking me, I just need to do my own thing (I was accused by a group of people on Kuan that I stole their technology because I pointed out something wrong with it, plus I have a bit of reverse APK, kuan fans can’t be pissed off)
  • The amount of money I can earn from the toolbox in two months is less than I can live on in one month. Since the beginning, I have added a lot of paid features, and the price hasn’t increased at all, and I think it will take me at least a few years to get what the big guys are getting
  • The world is full of people who have it easier and harder than you. Don’t complain about your life
  • In my junior year, I took a year off from school. I struggled to learn other skills while still reading good books. As a result, I failed more and more courses, and I still had too many things to do. A long story 😑