Android OTA related tools (2) dmctl of dynamic partition

This article is original by Rocky Watching the World (guyongqiangx), please indicate the source for reprinting.
Article link: https://guyongqiangx.blog.csdn.net/article/details/129229115

I introduced the snapshot debugging tool snapshotctl introduced from the virtual A/B system (Android R) in the previous article "Android OTA Related Tools (1) Virtual A/B snapshotctl" .

snapshotctl itself can do many things, such as dump upgrade information, map and unmap various virtual partitions, etc.

This article introduces the dynamic partition debugging tool dmctl. With the snapshotctl tool, it is more convenient to debug various dynamic partitions and virtual partitions beginning with dm.

Why are they called various ctl? Here ctl is short for control, sanpshotctl is snapshot control, and dmctl is device mapper control.

Therefore, as the name implies, dmctl is used to operate and control the device mapper device. The device mapper devices used in Android include:

  • Linear, linear mapping device, each area on the super device is mapped to a separate partition and linearthe device
  • Snapshot, snapshot devices, the snapshot devices introduced in the virtual A/B system include:
    • snapshot-originequipment
    • snapshotequipment
    • snapshot-mergeequipment
  • Verity, consistent device, after Android opens boot-time verification, use veritythe device to ensure the integrity of the partition

For more information about the list and content of Android OTA upgrade related articles, please refer to "Android OTA Upgrade Series Column Guide"

If you have already subscribed to the paid column, please be sure to add me on WeChat, and I will pull you into the Q&A group of the corresponding column.

This article is based on the Android code version: android-11.0.0_r21, but subsequent versions are similar

Online code: http://aospxref.com/android-11.0.0_r21/

In fact, I have already shown the simple usage of the dmctl tool in "Detailed Explanation of Android Dynamic Partition (2) Introduction to Core Modules and Related Tools" .

This article is dedicated to the dmctl tool.

1. Help information of dmctl

The dmctl tool has many functions, and the entrance to learning dmctl is to view its help information.

console:/ # dmctl help
usage: dmctl <command> [command options]
       dmctl -f file
commands:
  create <dm-name> [-ro] <targets...>
  delete <dm-name>
  list <devices | targets> [-v]
  getpath <dm-name>
  getuuid <dm-name>
  info <dm-name>
  status <dm-name>
  resume <dm-name>
  suspend <dm-name>
  table <dm-name>
  help

-f file reads command and all parameters from named file

Target syntax:
  <target_type> <start_sector> <num_sectors> [target_data]
console:/ # 

2. create operation

Various devices can be created through the create operation. The current implementation includes zero, linear, verity, snapshot, snapshot-origin and other devices.

Each device requires a common set of parameters when using the create operation:

<target_type> <start_sector> <num_sectors>

This group of parameters mainly specifies the type and size of the target device

In addition to the general parameters, for each type of device mapper device, it is also necessary to provide corresponding <targets>parameters . The detailed <targets>parameters of each device are as follows:

Equipment type Targets parameter
Zero none
Linear <block_device> <sector>
Android-verity <public-key-id> <block_device>
Bow <block_devices>
Snapshot-origin <block_devices>
Snapshot <block_device> <block_device> <mode> <chunk_size>
Snapshot-merge <block_device> <block_device> <chunk_size>

<targets>The parameters mainly specify the source device information, as well as additional parameters.

<targets>The parameters of dmctl correspond to --tablethe information of the dmsetup tool. In the code, dmctl converts <targets>the parameter into table information, and passes it to the bottom layer to create the device.

So, a dmctl create <dm-name>complete parameter should look like this:

# 通用参数格式
dmctl create <dm-name> <target_type> <start_sector> <num_sectors> <targets>

# Zero
dmctl create <dm-name> zero <start_sector> <num_sectors>

# Linear
dmctl create <dm-name> linear <start_sector> <num_sectors> <block_device> <sector>

# Android-verity
dmctl create <dm-name> android-verity <start_sector> <num_sectors> <public-key-id> <block_device>

# Bow
dmctl create <dm-name> bow <start_sector> <num_sectors> <block_devices>

# Snapshot-origin
dmctl create <dm-name> snapshot-origin <start_sector> <num_sectors> <block_devices>

# Snapshot
dmctl create <dm-name> snapshot <start_sector> <num_sectors> <block_device> <block_device> <mode> <chunk_size>

# Snapshot-merge
dmctl create <dm-name> snapshot <start_sector> <num_sectors> <block_device> <block_device> <chunk_size>

The device mapper device operates based on the smallest unit sector, and the size of the sector can be configured, but usually the default is 512 bytes.

Some device mapper devices operate based on chunks, where chunks are data blocks larger than sectors.

For example, a snapshot device operates based on chunks, and its size is set through chunksize when creating a snapshot.

For example, setting chunksize = 8 indicates that a chunk is composed of 8 sectors, so 1 x chunk = 8 x sector = 4KB.

The default chunksize in the snapshot driver is 32, corresponding to a chunk size of 16KB.

Zero

The code says that it supports creating devices of type zero, but when I try to create them, the prompt fails because of "unknown target type":

console:/ # dmctl create dm-rocky-zero zero 0 2048
[ 1031.230156] device-mapper: table: 252:5: zero: unknown target type
dmctl E 10-11 17:26:57  3840  3840 dm.cpp:262] DM_TABLE_LOAD failed: Invalid argument
Failed to create device-mapper device with name: dm-rocky-zero

/dev/zeroThis zero-type device is similar to the device mapper virtual block device that comes with the system and is used to generate 0, which is rarely used.

Linear

Map the 2466912 sectors starting from the 2048 sector in the super device to the dm-rocky device.

# 使用 dmctl create 创建虚拟设备 dm-rocky
# 映射信息: "linear 0 2466912 /dev/block/by-name/super 2048"
console:/ # dmctl create dm-rocky linear 0 2466912 /dev/block/by-name/super 2048
console:/ # ls -lh /dev/block/mapper/
total 0
drwxr-xr-x 2 root root 200 2022-04-02 15:55 by-uuid
lrwxrwxrwx 1 root root  15 2022-04-02 15:55 dm-rocky -> /dev/block/dm-7
lrwxrwxrwx 1 root root  15 2015-01-01 08:00 system-verity -> /dev/block/dm-3
lrwxrwxrwx 1 root root  15 2015-01-01 08:00 system_a -> /dev/block/dm-0
lrwxrwxrwx 1 root root  15 2015-01-01 08:00 userdata -> /dev/block/dm-6
lrwxrwxrwx 1 root root  15 2015-01-01 08:00 vendor-verity -> /dev/block/dm-4
lrwxrwxrwx 1 root root  15 2015-01-01 08:00 vendor_a -> /dev/block/dm-1
lrwxrwxrwx 1 root root  15 2015-01-01 08:00 vendor_dlkm-verity -> /dev/block/dm-5
lrwxrwxrwx 1 root root  15 2015-01-01 08:00 vendor_dlkm_a -> /dev/block/dm-2

console:/ # dmctl table dm-rocky
Targets in the device-mapper table for dm-rocky:
0-2466912: linear, 259:3 2048

# 查看 system_a 的映射表
console:/ # dmctl table system_a
Targets in the device-mapper table for system_a:
0-2466912: linear, 259:3 2048

# 查看当前系统中的所有 device mapper 设备
console:/ # dmctl list devices
Available Device Mapper Devices:
userdata             : 252:4
system_a             : 252:0
vendor-verity        : 252:3
vendor_a             : 252:1
system-verity        : 252:2
dm-rocky             : 252:5

It can be seen from the above that the mapping information of dm-rocky and the current system_a partition is the same. At this time, the system maps the part mapped to the system_a partition as a new partition device again /dev/block/by-name/dm-rocky.

Snapshot,Snapshot-origin 和 Snapshot-merge

The operations of creating snapshot, snapshot-origin and snapshot-merge are relatively complicated, and will not be listed in detail here for the time being, and will be added later.

For more articles about the principles and operations of snapshots, please refer to my two articles introducing the principles and practices of snapshots:

Regarding the examples of dmctl createcreating various device mapper devices, the actual use is seldom, and the follow-up will be supplemented and improved.

3. list operation

Use to dmctl listlist all device mapper devices in the current system:

console:/ # dmctl list devices
Available Device Mapper Devices:
userdata             : 252:6
vendor_dlkm-verity   : 252:5
system_a             : 252:0
vendor-verity        : 252:4
vendor_dlkm_a        : 252:2
vendor_a             : 252:1
system-verity        : 252:3

If you want to see more detailed information, you can use -vthe option :

console:/ # dmctl list devices -v
Available Device Mapper Devices:
userdata             : 252:4
  target#1: 0-11534336: default-key, aes-xts-plain64 - 0 259:4 0 3 allow_discards sector_size:4096 iv_large_sectors
system_a             : 252:0
  target#1: 0-2466912: linear, 259:3 2048
vendor-verity        : 252:3
  target#1: 0-154592: verity, 1 252:1 252:1 4096 4096 19324 19324 sha1 758e924ff5378790707d7a890e656611a281e6ca 26cd8465eda1b97b94af4a2f95786b73cf61c777 10 restart_on_corruption ignore_zero_blocks use_fec_from_device 252:1 fec_blocks 19478 fec_start 19478 fec_roots 2
vendor_a             : 252:1
  target#1: 0-157240: linear, 259:3 2469888
system-verity        : 252:2
  target#1: 0-2427824: verity, 1 252:0 252:0 4096 4096 303478 303478 sha1 de3446b6b2b4e86e9b941df4f7714824e4a60e29 21f2e10d1358ed8ac32df838ba446c3fe6bf883a 10 restart_on_corruption ignore_zero_blocks use_fec_from_device 252:0 fec_blocks 305869 fec_start 305869 fec_roots 2
console:/ # 

When -vthe option is selected, not only can all device mapper devices be listed, but also detailed mapping information of devices can be displayed.

4. Suspend and resume operations

Use dmctl suspendthe operation to suspend new I/O operations on the specified device mapper device, and the I/O operations already in progress will not be affected.

console:/ # dmctl info system_a
device        : system_a
active        : true
access        : ro 
activeTable   : true
inactiveTable : false
bufferFull    : false
console:/ # 
console:/ # 
console:/ # dmctl suspend system_a
console:/ # dmctl info system_a
device        : system_a
active        : false
access        : ro 
activeTable   : true
inactiveTable : false
bufferFull    : false
console:/ # 

From the above operations, it can be seen that

dmctl suspendBefore the operation , dmctl info system_athe active state seen by is true;

dmctl suspend After the operation , dmctl info system_athe active state seen by is false;

Use dmctl resumethe operation to resume the I/O operation on the specified device mapper device (the device that has been suspended by suspend).

console:/ # dmctl resume system_a
console:/ # dmctl info system_a
device        : system_a
active        : true
access        : ro 
activeTable   : true
inactiveTable : false
bufferFull    : false

dmctl resumeAfter , dmctl info system_athe active state seen by is restored to true;

5. delete operation

Use to dmctl delete delete the device mapper device with the specified name:

# 查看当前所有的 device mapper 设备
console:/ # dmctl list devices
Available Device Mapper Devices:
userdata             : 252:4
system_a             : 252:0
vendor-verity        : 252:3
vendor_a             : 252:1
system-verity        : 252:2
dm-rocky             : 252:5

# 删除名为 dm-rocky 的设备
console:/ # dmctl delete dm-rocky

# 再次查看设备列表时,已经没有 dm-rocky 设备了
console:/ # dmctl list devices
Available Device Mapper Devices:
userdata             : 252:4
system_a             : 252:0
vendor-verity        : 252:3
vendor_a             : 252:1
system-verity        : 252:2

6. getpath operation

Use dmctl getpathto view the path of the system_a partition.

console:/ # dmctl getpath system_a
/dev/block/dm-0

7. getuuid operation

Use dmctl getuuidto get the UUID of partition system_a:

console:/ # dmctl getuuid system_a
a8f76dd5-278d-4800-973a-0c9fc8607ff2

8. info operation

Use dmctl infoto view the information of the system_a partition:

console:/ # dmctl info system_a
device        : system_a
active        : true
access        : ro 
activeTable   : true
inactiveTable : false
bufferFull    : false

9. status operation

Use dmctl statusto view the status of the system_a partition:

console:/ # dmctl status system_a
Targets in the device-mapper table for system_a:
0-2498104: linear

10. table operations

Use dmctl tableto view the mapping information of the system_a partition:

console:/ # dmctl table system_a
Targets in the device-mapper table for system_a:
0-2498104: linear, 259:3 2048

11. Other

So far, I have written about Android OTA upgrade related topics including:

  • Basic introduction: "Android A/B System" series
  • Core module: "Android Update Engine Analysis" series
  • Dynamic Partitions: "Android Dynamic Partitions" series
  • Virtual A/B: "Android Virtual A/B Partition" series
  • Upgrade tools: "Android OTA related tools" series

For more information on these articles about Android OTA upgrades, please refer to "Introduction to Android OTA Upgrade Series Column Articles" .

If you have already subscribed to the dynamic partition and virtual partition paid column, please be sure to add me on WeChat, note the subscription account, and pull you into the "Dynamic Partition & Virtual Partition Column VIP Q&A Group". I will answer your questions about A/B systems, dynamic partitions, virtual partitions, various OTA upgrades and signatures at a convenient time.

In addition, I have an Android OTA upgrade discussion group, which now has 400+ friends, mainly discussing OTA upgrade topics for various devices such as mobile phones, car machines, TVs, set-top boxes, and tablets. If you are engaged in OTA upgrade work, welcome Join the group to communicate together, please indicate "Android OTA Discussion Group" when adding me on WeChat. This group is limited to Android OTA developers~

Reply "wx" in the backstage of the official account "Rocky Watching the World" to get personal WeChat.

Guess you like

Origin blog.csdn.net/guyongqiangx/article/details/129229115