执行"fastboot -w"的需求一般来自于测试GMS 刷GSI的需求,刷完google system image需要重新格式化三个分区
userdata、cache及metadata
代码引用如下
system/core/fastboot
fastboot.c
int FastBootTool::Main(int argc, char* argv[]) {
...
if (wants_wipe) {
if (force_flash) {
CancelSnapshotIfNeeded();
}
std::vector<std::string> partitions = { "userdata", "cache", "metadata" };
for (const auto& partition : partitions) {
std::string partition_type;
if (fb->GetVar("partition-type:" + partition, &partition_type) != fastboot::SUCCESS) {
continue;
}
if (partition_type.empty()) continue;
fb->Erase(partition);
if (partition == "userdata" && set_fbe_marker) {
fprintf(stderr, "setting FBE marker on initial userdata...\n");
std::string initial_userdata_dir = create_fbemarker_tmpdir();
fb_perform_format(partition, 1, partition_type, "", initial_userdata_dir, fs_options);
delete_fbemarker_tmpdir(initial_userdata_dir);
} else {
fb_perform_format(partition, 1, partition_type, "", "", fs_options);
}
}
}
...
}
在Android Q及以后,引用动态分区,GSI的更新,不能载进入bootloader模式下了,只能是进入用户态的fastbootd模式下;
在bootloader模式下,执行fastboot -w后,无法开机主要可能是以下问题点:
1.查看一下对应的fstab配置,目前项目上对应userdata挂载的type类型为F2FS
#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>
/dev/block/bootdevice/by-name/userdata /data f2fs
noatime,nosuid,nodev,discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier
latemount,wait,check,formattable,fileencryption=ice,wrappedkey,keydirectory=/metadata/vold/metadata_encryption,quota,reservedsize=128M,checkpoint=fs
2.如果挂载方式是F2FS,并且bootloader是uefi架构,还需要将对应的partitioninfo对应起来
bootable/bootloader/edk2/
diff --git a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
index 2b82b97..2c5a9b0
--- a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
+++ b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
@@ -86,7 +86,7 @@ found at
STATIC struct GetVarPartitionInfo part_info[] = {
{"system", "partition-size:", "partition-type:", "", "ext4"},
- {"userdata", "partition-size:", "partition-type:", "", "ext4"},
+ {"userdata", "partition-size:", "partition-type:", "", "f2fs"},
{"cache", "partition-size:", "partition-type:", "", "ext4"},
};
3.另外,如果userdata的加密方式为ME,即采用metadata方式加密,还需要格式化metadata分区
google默认没有给metadata分区设置文件系统,我们获取分区类型时,metadata为raw数据类型, 所以当format时会不生效,
$ fastboot getvar partition-type:metadata
partition-type:metadata: raw
未更改前,执行fastboot -w的log如下:
$ fastboot -w
Erasing 'userdata' OKAY [ 0.119s]
mke2fs 1.44.4 (18-Aug-2018)
Creating filesystem with 24811814 4k blocks and 6209536 inodes
Filesystem UUID: f0096258-2bb1-11ea-a7ee-efa76cb0902a
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done
Sending 'userdata' (4560 KB) OKAY [ 0.110s]
Writing 'userdata' OKAY [ 0.002s]
Erasing 'metadata' OKAY [ 0.005s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Finished. Total time: 0.815s
4.我们在bootloader的fastbootcmd partitioninfo中指定partition-type为ext4
bootable/bootloader/edk2/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
STATIC struct GetVarPartitionInfo part_info[] = {
{"system", "partition-size:", "partition-type:", "", "ext4"},
{"userdata", "partition-size:", "partition-type:", "", "f2fs"},
{"cache", "partition-size:", "partition-type:", "", "ext4"},
+ {"metadata", "partition-size:", "partition-type:", "", "ext4"},
};
那我们看看最终执行成功执行完fastboot -w后的结果如下:
C:\windows\system32>fastboot -w
Erasing 'userdata' OKAY [ 0.099s]
F2FS-tools: mkfs.f2fs Ver: 1.13.0 (2019-09-24)
Info: Disable heap-based policy
Info: Debug level = 1
Info: Trim is disabled
Info: Set conf for android
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 39312856 (19195 MB)
Info: zone aligned segment0 blkaddr: 512
Info: add quota type = 0 => 4
Info: add quota type = 1 => 5
[f2fs_init_sit_area: 560] Filling sit area at offset 0x00600000
[f2fs_init_nat_area: 594] Filling nat area at offset 0x00a00000
[f2fs_write_root_inode:1168] Writing root inode (hot node), 8800 0 200 at offset 0x00034816
[f2fs_write_default_quota:1244] Writing quota data, at offset 00008e01, 00008e02
[f2fs_write_qf_inode:1335] Writing quota inode (hot node), 8800 0 200 at offset 0x00034817
[f2fs_write_default_quota:1244] Writing quota data, at offset 00008e03, 00008e04
[f2fs_write_qf_inode:1335] Writing quota inode (hot node), 8800 0 200 at offset 0x00034818
[f2fs_update_nat_root:1389] Writing nat root, at offset 0x00000a00
[f2fs_add_default_dentry_root:1580] Writing default dentry root, at offset 0x00008e00
Info: Overprovision ratio = 1.450%
Info: Overprovision segments = 281 (GC reserved = 145)
[f2fs_write_check_point_pack: 738] Writing main segments, cp at offset 0x00000200
[f2fs_write_check_point_pack: 875] Writing Segment summary for HOT/WARM/COLD_DATA, at offset 0x00000201
[f2fs_write_check_point_pack: 902] Writing Segment summary for HOT_NODE, at offset 0x00000202
[f2fs_write_check_point_pack: 914] Writing Segment summary for WARM_NODE, at offset 0x00000203
[f2fs_write_check_point_pack: 925] Writing Segment summary for COLD_NODE, at offset 0x00000204
[f2fs_write_check_point_pack: 933] Writing cp page2, at offset 0x00000205
[f2fs_write_check_point_pack: 953] Writing NAT bits pages, at offset 0x000003ff
[f2fs_write_check_point_pack: 974] Writing cp page 1 of checkpoint pack 2, at offset 0x00000400
[f2fs_write_check_point_pack: 993] Writing cp page 2 of checkpoint pack 2, at offset 0x00000405
[f2fs_write_super_block:1026] Writing super block, at offset 0x00000000
Info: format successful
Sending 'userdata' (80 KB) OKAY [ 0.010s]
Writing 'userdata' OKAY [ 0.002s]
Erasing 'metadata' OKAY [ 0.005s]
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 4096 4k blocks and 4096 inodes
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
Sending 'metadata' (48 KB) OKAY [ 0.009s]
Writing 'metadata' OKAY [ 0.003s]
Finished. Total time: 8.834s