0%

vab机型fastbootd使用

vnote_backup_file_826537664 /home/mi/Documents/backup/VnoteBook/OTA相关/动态分区机型fastbootd使用.md

动态分区机型fastbootd使用

fastbootd简介

在动态分区机型上bootloader的fastboot不能烧写动态分区的镜像, 需要使用recovery子系统下的fastbootd来进行用户空间的烧写镜像的工作

fastbootd是recovery子系统下的一个native进程, 由init fork出来. 具体实现方式类似于adbd.
包括进程创建, 驱动通道, 与init的协作都与adbd一致, 是属于借助usb的config配置实现的功能.
因此不能同时启用adb和fastboot模式, 因为这两个独占同一个通道.

fastbootd命令

Command Description Available when device is OEM locked
getvar is-userspace Return yes Yes
getvar
is-logical:
Return yes if the given partition is a
logical partition, no otherwise
Yes
getvar super-partition-name MUST return super for a device
launching with logical partitions
Yes
create-logical-partition
Create a logical partition with the
given name and size
No
delete-logical-partition
Delete the given logical partition No
resize-logical-partition
Resize the logical partition to the new
size without changing its contents
No
update-super Similar to flash super, except rather
than flashing raw data to the super
partition, this will ensure that all
partitions within the downloaded
image are created
No
getvar max-download-size Return the maximum size of an image
that can be downloaded in bytes in
hex
Yes
getvar partition-type
Return file system type: ext4, f2fs,
raw
Yes
flash partition_name filename Flash the partition through a series of
download and flash fastboot
protocol commands
No
reboot bootloader Reboot into bootloader mode Yes
reboot fastboot Reboot back into fastbootd mode Yes

安装最新的fastboot工具

platform-tools获取最新的fastboot和adb的工具

  • linux下替换
    解压后得到platform-tools 目录
1
export $PATH=<platform-tools目录>:$PATH
  • windows下替换
    打开资源管理器explorer, 右键此电脑 -> 属性 -> 高级系统设置 -> 环境变量 -> 用户变量 ->Path下添加解压platform-tools的目录
    注销, 重新登录生效.

fastboot devices查看是否有设备号输出, 如果没有, 需要配置端口或更新驱动

win下, 通过设备管理器 -> 其他设备 (未识别的!设备)-> 右键更新驱动 -> 自动搜索驱动

linux下, lsusb 设备号, 将识别出的设备号按照adb 配置设备的方式进行配置, 这里不再赘述

从super img分离出包含的动态分区

转换super img为原始镜像

动态分区线刷包中是super.img,格式是sparse image,要查看super.img首先需要使用simg2img进行转化。若转化后为super_ext4.

Android Sparse Image

为了缩小镜像大小,Android会以稀疏格式生成system.img,vendor.img userdata.img和cache.img。镜像被拆分为4K字节倍数的块。
任何不包含有用数据的块都将标记为Don't Care

sparse
header

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
system/core/libsparse/simg_dump.py   -v  cache.img
cache.img: Total of 98304 4096-byte output blocks in 10 input chunks.
input_bytes output_blocks
chunk offset number offset number
1 40 114688 0 28 Raw data
2 114740 0 28 2047 Don't care
3 114752 24576 2075 6 Raw data
4 139340 0 2081 30687 Don't care
5 139352 8192 32768 2 Raw data
6 147556 0 32770 32766 Don't care
7 147568 4096 65536 1 Raw data
8 151676 0 65537 2049 Don't care
9 151688 4096 67586 1 Raw data
10 155796 0 67587 30717 Don't care
155796 98304 End
[$] -> ll cache.img cache.img_ext4
-rw-rw-r-- 1 mi mi 155796 11月 14 08:12 cache.img
-rw-rw-r-- 1 mi mi 402653184 11月 19 14:15 cache.img_ext4
1
simg2img ~/Downloads/umi_images_1.2.2_20191021.0000.00_10.0_cn/images/super.img    ~/Downloads/umi_images_1.2.2_20191021.0000.00_10.0_cn/images/super.img_ext4

dump super img

如果需要查看super.img里包含哪些img, 其格式是怎样的, 可以使用lpdump工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[$] -> ./lpdump ~/Downloads/umi_images_1.2.2_20191021.0000.00_10.0_cn/images/super.img_ext4
Metadata version: 10.0
Metadata size: 592 bytes
Metadata max size: 65536 bytes
Metadata slot count: 2
Partition table:
------------------------
Name: system
Group: qti_dynamic_partitions
Attributes: readonly
Extents:
0 .. 5716647 linear super 2048
------------------------
Name: product
Group: qti_dynamic_partitions
Attributes: readonly
Extents:
0 .. 916055 linear super 5720064
------------------------
Name: vendor
Group: qti_dynamic_partitions
Attributes: readonly
Extents:
0 .. 2410687 linear super 6637568
...
------------------------
Block device table:
------------------------
Partition name: super
First sector: 2048
Size: 9126805504 bytes
Flags: none
------------------------
Group table:
------------------------
Name: default
Maximum size: 0 bytes
Flags: none
------------------------
Name: qti_dynamic_partitions
Maximum size: 9126805504 bytes
Flags: none

如果需要从super.img中解出其包含的分区镜像, 可以使用lpunpack工具

  • lpunpack [-p partition_name] SUPER_IMAGE [OUTPPUT_DIR], -p后面跟要取出的分区名,若不指定,都会取出*

解出system.img

1
2
3
4
5
6
7
./lpunpack -p system ~/Downloads/umi_images_1.2.2_20191021.0000.00_10.0_cn/images/super.img_ext4   unpack
[~/work_space/v10-q-umi/out/host/linux-x86/bin/unpack] - [五 11月 15, 12:51]
[$] -> ll
总用量 2845812
drwxrwxr-x 2 mi mi 4096 11月 15 12:50 .
drwxrwxr-x 3 mi mi 4096 11月 15 12:50 ..
-rw-r--r-- 1 mi mi 2926923776 11月 15 12:51 system.img

解出的system.img即为原始的带文件系统的镜像, 可以直接挂载

1
2
3
4
# 查看system.img镜像的文件系统类型
file system.img
mkdir system
sudo mount -t <文件系统类型> system.img system

如上提到的工具

可以直接在打开动态分区的机型上编译对应的工具

1
2
3
4
make simg2img lpdump lpunpack
# 或者使用ninja编译
# 生成目录
out/host/linux-x86/bin

也可以直接下载我这里编译好的(64位的)