目标:在设备系统中集成我的服务

1. 了解Android系统

1.1 Android系统固件组成

  1. recovery.img TWRP
  2. update.zip
    1. boot.img
    2. data/ init.rc开机执行你希望执行的命令
    3. system/ 是一系列希望放到系统中的工具
    4. META-INF/

1.2 Android系统的启动模式


2. 备份原系统ROM

  1. Android系统开放root权限
  2. adb shell 进行系统
  3. su 切入root权限
  4. dd if=/dev/block/mmcblk0p3 of=/sdcard/system.img 备份system分区
  5. dd if=/dev/block/mmcblk0p2 of=/sdcard/boot.img 备份boot.img

3. 修改原系统ROM

4. 刷入修改后的新系统ROM


LineageOS

一个第三方开源编译Android系统,最接近于Android原生,并支持大量设备型号。

为加快速度,将源代码先以镜像方式下载。

$ cd YOUR_MIRROR_PATH
$ repo init -u https://github.com/LineageOS/android.git -b lineage-18.1 --mirror
$ repo sync --no-tags
$ cd ~/android/lineage
$ repo init -u https://github.com/LineageOS/android.git -b lineage-18.1 --reference=YOUR_MIRROR_PATH
$ repo sync

使用国内镜像

repo镜像


编译记录

$ vi .repo/local_manifests/roomservice.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <project name="LineageOS/android_device_xiaomi_dipper" path="device/xiaomi/dipper" remote="github" />
  <project name="LineageOS/android_device_xiaomi_sdm845-common" path="device/xiaomi/sdm845-common" remote="github" />
  <project name="LineageOS/android_hardware_xiaomi" path="hardware/xiaomi" remote="github" />
  <project name="LineageOS/android_kernel_xiaomi_sdm845" path="kernel/xiaomi/sdm845" remote="github" />
</manifest>


$ source build/envsetup.sh
$ breakfast dipper
Looking for dependencies in device/xiaomi/dipper
Looking for dependencies in device/xiaomi/sdm845-common
Looking for dependencies in hardware/xiaomi
hardware/xiaomi has no additional dependencies.
Looking for dependencies in kernel/xiaomi/sdm845
kernel/xiaomi/sdm845 has no additional dependencies.

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
LINEAGE_VERSION=18.1-20210908-UNOFFICIAL-dipper
TARGET_PRODUCT=lineage_dipper
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.10.0-8-amd64-x86_64-Debian-GNU/Linux-11-(bullseye)
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ3A.210805.001.A1
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/xiaomi/sdm845-common hardware/google/interfaces hardware/google/pixel hardware/xiaomi vendor/nxp/opensource/pn5xx hardware/qcom-caf/sdm845 vendor/qcom/opensource/commonsys-intf/display vendor/qcom/opensource/data-ipa-cfg-mgr vendor/qcom/opensource/dataservices vendor/qcom/opensource/commonsys/packages/apps/Bluetooth vendor/qcom/opensource/commonsys/system/bt/conf
============================================


proprietary blobs 设备专有blobs

Extracting proprietary blobs from LineageOS zip files

文中讲了三种方式,分别是基于:

  1. Block-based OTA
  2. File-based OTA
  3. Payload-based OTA

blobs我理解为由硬件(开发版)厂商提供的硬件接口驱动等文件。

device specific configuration 设备特定配置

kernel 设备内核


实操小米手机

1. 解小米手机BL锁

  1. 下载官方解锁工具


基于厂商SDK编译Android系统

Firefly厂家提供SDK下载


固件定制演练

1. 解包

-rw-r--r-- 1 wii wii 314368784  9月  9 17:35 AIO-3288C_Android8.1_Beta_180810.7z

# 逐层解包

$ 7z e AIO-3288C_Android8.1_Beta_180810.7z
-rw-r--r-- 1 wii wii 883786200  8月  9  2018 AIO-3288C_Android8.1_Beta_180810.img

$ file AIO-3288C_Android8.1_Beta_180810.img 
AIO-3288C_Android8.1_Beta_180810.img: data

$ vim -b AIO-3288C_Android8.1_Beta_180810.img
00000000: 524b 4657 6600 0000 0107 0000 0601 e207  RKFWf...........
00000010: 0809 143a 3a80 0000 0066 0000 004e 6902  ...::....f...Ni.
00000020: 00b4 6902 0004 18ab 3400 0000 0001 0000  ..i.....4.......
00000030: 0000 0000 0010 0100 0000 0000 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 0000 0000 424f 4f54 6600 3602 0000  ......BOOTf.6...
:%!xxd

$ sudo apt-get install rkflashtool
$ rkunpack AIO-3288C_Android8.1_Beta_180810.img 
rkunpack: info: RKFW signature detected
rkunpack: info: version: 7.1.0
rkunpack: info: date: 2018-08-09 20:58:58
rkunpack: info: family: rk32xx
rkunpack: info: 00000066-000269b3 BOOT                       (size: 158030)
rkunpack: info: 000269b4-34ad81b7 embedded-update.img        (size: 883628036) # 升级包
unpacked

$ rkunpack embedded-update.img 
rkunpack: info: RKAF signature detected
rkunpack: info: file size matches (883628036 bytes)
rkunpack: info: manufacturer: rk3288
rkunpack: info: model: RK3288
rkunpack: info: number of files: 14
rkunpack: info: 00000800-00000800 package-file               (size: 697)
rkunpack: info: 00001000-0000104d Image/MiniLoaderAll.bin    (size: 158030)
rkunpack: info: 00028000-00028000 Image/parameter.txt        (size: 871)
rkunpack: info: 00028800-00028fff Image/trust.img            (size: 4194304)
rkunpack: info: 00428800-00428fff Image/uboot.img            (size: 4194304)
rkunpack: info: 00828800-00828817 Image/misc.img             (size: 49152)
rkunpack: info: 00834800-00834868 Image/resource.img         (size: 213504)
rkunpack: info: 00869000-00869f58 Image/kernel.img           (size: 8046348)
rkunpack: info: 01015800-01015aa1 Image/boot.img             (size: 1379068)
rkunpack: info: 01166800-01167652 Image/recovery.img         (size: 7509088)
rkunpack: info: 01890000-018e4b52 Image/system.img           (size: 710578420)  # 系统分区,根/目录
rkunpack: info: 2be39800-2be4b040 Image/vendor.img           (size: 146931836)  # 底层分区,里面有设备底层驱动
rkunpack: info: 34a5a000-34a5a0ae Image/oem.img              (size: 356452)
rkunpack: info: 00000000-ffffffff RESERVED                   (size: 0)
unpacked


# system.img 格式转换


$ file system.img 
system.img: Android sparse image, version: 1.0, Total of 524288 4096-byte output blocks in 18 input chunks.

$ sudo apt-get install simg2img
$ simg2img system.img system_raw.img

$ file system_raw.img
system_raw.img: Linux rev 1.0 ext4 filesystem data, UUID=115d422f-283c-4425-a525-6e68ab4836e6, volume name "system" (extents) (64bit) (large files) (huge files)


# 挂载 system.img

$ mkdir system
$ sudo mount -o loop system_raw.img system
wii@wiiD:/media/wii/d1/AIO-3288C_Android8.1/Image$ ll system
总用量 168
drwxr-xr-x. 42 root root  4096  8月  9  2018 app                            # 存放app
drwxr-xr-x.  3 root 2000  8192  8月  9  2018 bin
-rw-------.  1 root root  1928  8月  9  2018 build.prop
-rw-r--r--.  1 root root 74748  8月  9  2018 compatibility_matrix.xml
drwxr-xr-x. 10 root root  4096  8月  9  2018 etc
drwxr-xr-x.  2 root root  4096  8月  9  2018 fake-libs
drwxr-xr-x.  2 root root  8192  8月  9  2018 fonts
drwxr-xr-x.  4 root root  4096  8月  9  2018 framework
drwxr-xr-x.  6 root root 12288  8月  9  2018 lib
drwxr-xr-x.  2 root root  4096  8月  9  2018 lib64
drwx------.  2 root root 16384  8月  9  2018 lost+found
-rw-r--r--.  1 root root  2946  8月  9  2018 manifest.xml
drwxr-xr-x.  3 root root  4096  8月  9  2018 media
drwxr-xr-x. 39 root root  4096  8月  9  2018 priv-app                       # 存放app
drwxr-xr-x.  3 root root  4096  8月  9  2018 tts
drwxr-xr-x.  8 root root  4096  8月  9  2018 usr
lrw-r--r--.  1 root root     7  8月  9  2018 vendor -> /vendor
drwxr-xr-x.  2 root 2000  4096  8月  9  2018 xbin

# 对system进行写操作需要root权限


2. 修改

$ sudo cp busybox system/bin
$ sudo chown 0.2000 system/bin/busybox
$ sudo chmod 755 system/bin/busybox
$ cd system/bin
$ sudo ln -s busybox run-parts
$ sudo chown 0.2000 run-parts
$ sudo chmod 755 run-parts

$ sudo ln -s busybox crond
$ sudo ln -s busybox crontab
$ sudo ln -s busybox vi

$ ll busybox 
-rwxr-xr-x. 1 root 2000 280000  9月 10 08:46 busybox
$ ll run-parts 
lrwxrwxrwx 1 root 2000 7  9月 10 08:51 run-parts -> busybox

$ sudo vi sysinit 
#!/system/bin/sh
# init.d support

export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
run-parts /system/etc/init.d

$ sudo chmod 755 sysinit 
$ sudo chown 0.2000 sysinit 
$ ll sysinit 
-rwxr-xr-x 1 root 2000 121  9月 10 09:02 sysinit

$ cd ../etc
sudo vi install-recovery.sh
#!/system/bin/sh
# init.d support

/system/bin/sysinit

$ sudo chown 0.0 install-recovery.sh
$ sudo chmod 755 install-recovery.sh

$ sudo mkdir init.d
$ sudo vi init.d/08setperm
#!/system/bin/sh
# set correct permissions to /system/etc/init.d folder

mount -o remount,rw -t auto /system
chmod -R 777 /system/etc/init.d
mount -o remount,ro -t auto /system


$ sudo vi init.d/00test
#!/system/bin/sh
#init.d test

if [ -f /data/Test.log ]; then
rm /data/Test.log
fi

echo "Init.d is working !!!" >> /data/Test.log
echo "executed on $(date +"%d-%m-%Y %r" )" >> /data/Test.log

$ sudo chmod 777 init.d -R
$ sudo chown 0.0 init.d -R

$ cd ../../

3. 重新打包

# sudo apt-get install android-sdk-ext4-utils Debian 10/11 已经不提供
# 注意:Pandaboard中一下语句的“ -s ”参数不能省略!如果省略了“ -s ”参数,虽然可以生产system.img文件!但是你用“ simg2img system.img system.img.ext4 ”时会报错!
# 这个工具代码在Android源代码中 system/extras/ext4_utils
# https://packages.debian.org/buster/android-tools-fsutils 下载旧版本的安装包 android-tools-fsutils_5.1.1.r38-1.1_amd64.deb
# 因其与系统的android-sdk-libsparse-utils有冲突,先卸载之前安装的simg2img
# sudo apt-get remove simg2img android-sdk-libsparse-utils
# sudo dpkg -i android-tools-fsutils_5.1.1.r38-1.1_amd64.deb
# -s 制作ext4格式文件系统
# -T 时间戳
# -S 上下文文件
# -L 标签
# -l 1610612736:分区的大小为1.5G (1610612736的大小为1.5G)
# -a system  是指这个img用于android系统,挂载点是/system

# $ sudo make_ext4fs -s -T 0 -S file_contexts -l 1024M -a system system_new.img system

$ sudo make_ext4fs -s -T 0 -l 1024M -a system system_new.img system
Creating filesystem with parameters:
    Size: 1073741824
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8192
    Inode size: 256
    Journal blocks: 4096
    Label: 
    Blocks: 262144
    Block groups: 8
    Reserved block group size: 63
Created filesystem with 2238/65536 inodes and 173297/262144 blocks

$ file system.img 
system.img: Android sparse image, version: 1.0, Total of 524288 4096-byte output blocks in 18 input chunks.
$ file system_new.img 
system_new.img: Android sparse image, version: 1.0, Total of 262144 4096-byte output blocks in 2077 input chunks.

$ sudo make_ext4fs -s -T 0 -l 2048M -a system system_new.img system
Creating filesystem with parameters:
    Size: 2147483648
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8192
    Inode size: 256
    Journal blocks: 8192
    Label: 
    Blocks: 524288
    Block groups: 16
    Reserved block group size: 127
Created filesystem with 2238/131072 inodes and 181954/524288 blocks
$ file system_new.img 
system_new2.img: Android sparse image, version: 1.0, Total of 524288 4096-byte output blocks in 2096 input chunks.

# 由此判断原system.img应该是按分区2G创建的

# 我将新创建system_new.img重新转换挂在后可看之前增加的内容,发现bin目录下的内容正常,但新建sbin以及etc/init.d目录及文件的权限均不对。
# 应该是上一步缺少 -S file_contexts 上下文文件造成的

$ vi system/etc/selinux/plat_file_contexts
/system/sbin/busybox            u:object_r:busybox_shell_exec:s0
/system/sbin/run-parts          u:object_r:run_parts_exec:s0
/system/etc/init.d(/.*)?        u:object_r:init_d_exec:s0
$ sudo make_ext4fs -s -T 0 -S system/etc/selinux/plat_file_contexts -l 2048M -a system system_new3.img system
# 测试没有起作用


# https://github.com/naobsd/rkutils

$ ./rkafpack manufacturer:rk3288 machine_model:RK3288 package-file:package-file bootloader:Image/MiniLoaderAll.bin parameter:Image/parameter.txt trust:Image/trust.img uboot:Image/uboot.img misc:Image/misc.img resource:Image/resource.img kernel:Image/kernel.img boot:Image/boot.img recovery:Image/recovery.img system:Image/system.img vendor:Image/vendor.img oem:Image/oem.img backup:RESERVED > embedded-update_new.img
$ ll embedded-update*.img
-rw-r--r-- 1 wii wii 883628036  9月  9 18:01 embedded-update.img
-rw-r--r-- 1 wii wii 884303876  9月 10 11:11 embedded-update_new.img

$ rkunpack embedded-update.img 
rkunpack: info: RKAF signature detected
rkunpack: info: file size matches (883628036 bytes)
rkunpack: info: manufacturer: rk3288
rkunpack: info: model: RK3288
rkunpack: info: number of files: 14
rkunpack: info: 00000800-00000800 package-file               (size: 697)
rkunpack: info: 00001000-0000104d Image/MiniLoaderAll.bin    (size: 158030)
rkunpack: info: 00028000-00028000 Image/parameter.txt        (size: 871)
rkunpack: info: 00028800-00028fff Image/trust.img            (size: 4194304)
rkunpack: info: 00428800-00428fff Image/uboot.img            (size: 4194304)
rkunpack: info: 00828800-00828817 Image/misc.img             (size: 49152)
rkunpack: info: 00834800-00834868 Image/resource.img         (size: 213504)
rkunpack: info: 00869000-00869f58 Image/kernel.img           (size: 8046348)
rkunpack: info: 01015800-01015aa1 Image/boot.img             (size: 1379068)
rkunpack: info: 01166800-01167652 Image/recovery.img         (size: 7509088)
rkunpack: info: 01890000-018e4b52 Image/system.img           (size: 710578420)
rkunpack: info: 2be39800-2be4b040 Image/vendor.img           (size: 146931836)
rkunpack: info: 34a5a000-34a5a0ae Image/oem.img              (size: 356452)
rkunpack: info: 00000000-ffffffff RESERVED                   (size: 0)
unpacked
$ rkunpack embedded-update_new.img 
rkunpack: info: RKAF signature detected
rkunpack: info: file size matches (884303876 bytes)
rkunpack: info: manufacturer: rk3288
rkunpack: info: model: RK3288
rkunpack: info: number of files: 14
rkunpack: info: 00000800-00000fff package-file               (size: 697)
rkunpack: info: 00001000-00027fff Image/MiniLoaderAll.bin    (size: 158030)
rkunpack: info: 00028000-000287ff Image/parameter.txt        (size: 859)
rkunpack: info: 00028800-004287ff Image/trust.img            (size: 4194304)
rkunpack: info: 00428800-008287ff Image/uboot.img            (size: 4194304)
rkunpack: info: 00828800-008347ff Image/misc.img             (size: 49152)
rkunpack: info: 00834800-00868fff Image/resource.img         (size: 213504)
rkunpack: info: 00869000-010157ff Image/kernel.img           (size: 8046348)
rkunpack: info: 01015800-011667ff Image/boot.img             (size: 1379068)
rkunpack: info: 01166800-0188ffff Image/recovery.img         (size: 7509088)
rkunpack: info: 01890000-2bede7ff Image/system.img           (size: 711254632)
rkunpack: info: 2bede800-34afefff Image/vendor.img           (size: 146931836)
rkunpack: info: 34aff000-34b567ff Image/oem.img              (size: 356452)
rkunpack: info: 34b56800-34b567ff RESERVED                   (size: 0)
unpacked


公司rk3399设备Android系统研究

# df
Filesystem            1K-blocks    Used Available Use% Mounted on
rootfs                  1958172    4844   1953328   1% /
tmpfs                   1968168     436   1967732   1% /dev
tmpfs                   1968168       0   1968168   0% /mnt
/dev/block/mmcblk1p10   1499760  774096    725664  52% /system
/dev/block/mmcblk1p9     124912     176    124736   1% /cache
/dev/block/mmcblk1p11     12016      40     11976   1% /metadata
/dev/block/mmcblk1p15  27956876 4851076  23105800  18% /data
/data/media            27956876 4851076  23105800  18% /mnt/runtime/default/emulated
/data/media            27956876 4851076  23105800  18% /mnt/runtime/read/emulated
/data/media            27956876 4851076  23105800  18% /mnt/runtime/write/emulated

# mount
rootfs on / type rootfs (ro,seclabel,size=1958172k,nr_inodes=489543)
tmpfs on /dev type tmpfs (rw,seclabel,nosuid,relatime,mode=755)
devpts on /dev/pts type devpts (rw,seclabel,relatime,mode=600)
proc on /proc type proc (rw,relatime,gid=3009,hidepid=2)
sysfs on /sys type sysfs (rw,seclabel,relatime)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
/sys/kernel/debug on /sys/kernel/debug type debugfs (rw,seclabel,relatime,mode=755)
/sys/kernel/debug/tracing on /sys/kernel/debug/tracing type tracefs (rw,seclabel,relatime,mode=755)
none on /acct type cgroup (rw,relatime,cpuacct)
none on /dev/stune type cgroup (rw,relatime,schedtune)
tmpfs on /mnt type tmpfs (rw,seclabel,relatime,mode=755,gid=1000)
none on /config type configfs (rw,relatime)
none on /dev/memcg type cgroup (rw,relatime,memory)
none on /dev/cpuctl type cgroup (rw,relatime,cpu)
none on /dev/cpuset type cgroup (rw,relatime,cpuset,noprefix,release_agent=/sbin/cpuset_release_agent)
pstore on /sys/fs/pstore type pstore (rw,seclabel,relatime)
/dev/block/mmcblk1p10 on /system type ext4 (ro,seclabel,noatime,nodiratime,noauto_da_alloc,data=ordered)  # <--
/dev/block/mmcblk1p9 on /cache type ext4 (rw,seclabel,nosuid,nodev,noatime,nodiratime,discard,noauto_da_alloc,data=ordered)
/dev/block/mmcblk1p11 on /metadata type ext4 (rw,seclabel,nosuid,nodev,noatime,nodiratime,discard,noauto_da_alloc,data=ordered)
/dev/block/mmcblk1p15 on /data type ext4 (rw,dirsync,seclabel,nosuid,nodev,noatime,nodiratime,discard,noauto_da_alloc,errors=panic,data=ordered)
tmpfs on /storage type tmpfs (rw,seclabel,relatime,mode=755,gid=1000)
adb on /dev/usb-ffs/adb type functionfs (rw,relatime)
/data/media on /mnt/runtime/default/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,multiuser,mask=6)
/data/media on /storage/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,multiuser,mask=6)
/data/media on /mnt/runtime/read/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,multiuser,mask=23)
/data/media on /mnt/runtime/write/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,multiuser,mask=7)

# ls -l /dev/block/platform/fe330000.sdhci/by-name/                                                                                                                                                                             
total 0
lrwxrwxrwx 1 root root 20 2021-09-10 17:31 backup -> /dev/block/mmcblk1p8
lrwxrwxrwx 1 root root 20 2021-09-10 17:31 boot -> /dev/block/mmcblk1p6
lrwxrwxrwx 1 root root 20 2021-09-10 17:31 cache -> /dev/block/mmcblk1p9
lrwxrwxrwx 1 root root 21 2021-09-10 17:31 frp -> /dev/block/mmcblk1p14
lrwxrwxrwx 1 root root 20 2021-09-10 17:31 kernel -> /dev/block/mmcblk1p5
lrwxrwxrwx 1 root root 21 2021-09-10 17:31 metadata -> /dev/block/mmcblk1p11
lrwxrwxrwx 1 root root 20 2021-09-10 17:31 misc -> /dev/block/mmcblk1p3
lrwxrwxrwx 1 root root 20 2021-09-10 17:31 recovery -> /dev/block/mmcblk1p7
lrwxrwxrwx 1 root root 21 2021-09-10 17:31 reserved -> /dev/block/mmcblk1p13
lrwxrwxrwx 1 root root 20 2021-09-10 17:31 resource -> /dev/block/mmcblk1p4
lrwxrwxrwx 1 root root 21 2021-09-10 17:31 system -> /dev/block/mmcblk1p10
lrwxrwxrwx 1 root root 20 2021-09-10 17:31 trust -> /dev/block/mmcblk1p2
lrwxrwxrwx 1 root root 20 2021-09-10 17:31 uboot -> /dev/block/mmcblk1p1
lrwxrwxrwx 1 root root 21 2021-09-10 17:31 userdata -> /dev/block/mmcblk1p15
lrwxrwxrwx 1 root root 21 2021-09-10 17:31 verity_mode -> /dev/block/mmcblk1p12

$ su

# mount -o remount,rw /dev/block/mmcblk1p10 /system
mount: '/system' not in /proc/mounts

$ adb root
$ adb disable-verity
$ adb remount
$ adb shell


问题 : WARNING: linker: /system/bin/busybox: unsupported flags DT_FLAGS_1=0x8000001

并不影响使用


操boot.img

工具所在位置:

  • kernel/scripts/mkkrnlimg
  • out/host/linux-x86/bin/mkbootfs
    • system/core/cpio/mkbootfs.c
  • out/host/linux-x86/bin/mkbootimg
    • system/core/mkbootimg/mkbootimg

1. 解包

$ file boot.img 
boot.img: data     <-KRNL->

$ mkkrnlimg -r boot.img boot.img-ramdisk.gz
$ file boot.img-ramdisk.gz 
boot.img-ramdisk.gz: gzip compressed data, from Unix, original size modulo 2^32 4832000

$ mkdir ramdisk
$ cd ramdisk
$ gzip -dc ../boot.img-ramdisk.gz | cpio -i


2. 修改

$ vi init.rc
service initd /system/bin/sysinit
    class main
    user root
    group root
    oneshot

3. 重构

$ out/host/linux-x86/bin/mkbootfs -d out/target/product/nanopc-t4/system out/target/product/nanopc-t4/root | out/host/linux-x86/bin/minigzip > out/target/product/nanopc-t4/ramdisk.img
$ out/host/linux-x86/bin/mkbootimg  --kernel out/target/product/nanopc-t4/kernel --ramdisk out/target/product/nanopc-t4/ramdisk.img --cmdline \"buildvariant=userdebug\" --os_version 7.1.2 --os_patch_level 2017-04-05  --output out/target/product/nanopc-t4/boot.img"

$ rkst/mkkrnlimg $OUT/ramdisk.img $IMAGE_PATH/boot.img

$ find . | cpio -o -H newc | gzip > ../newramdisk.cpio.gz
$ cd ..
$ mkkrnlimg -a newramdisk.cpio.gz boot_new.img