在android R版本全编译时,遇到编译打包super.img时报错,这里介绍一下这种问题如何定位原因和解决,主要是描述一下分析的思路。
错误日志如下:
out/target/product/tt/obj/PACKAGING/check-all-partition-sizes_intermediates/misc_info.txt )"
Traceback (most recent call last):
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/internal/stdlib/runpy.py", line 174, in _run_module_as_main
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/internal/stdlib/runpy.py", line 72, in _run_code
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/__main__.py", line 12, in <module>
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/internal/stdlib/runpy.py", line 174, in _run_module_as_main
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/internal/stdlib/runpy.py", line 72, in _run_code
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/check_partition_sizes.py", line 271, in <module>
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/check_partition_sizes.py", line 265, in main
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/check_partition_sizes.py", line 253, in CheckPartitionSizes
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/check_partition_sizes.py", line 245, in Run
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/check_partition_sizes.py", line 242, in _CheckAllPartitionSizes
File "/home/test/tt_r_temp/android/out/host/linux-x86/bin/check_partition_sizes/check_partition_sizes.py", line 61, in CheckLe
RuntimeError: sum of sizes of ['youroem_dynamic_partitions'] is greater than BOARD_SUPER_PARTITION_SIZE / 2: 2147483648
4290772992 == 4290772992 > 2147483648 == 2147483648
[100% 312/312] Target super fs image for debug: out/target/product/tt/super.img
2021-07-12 10:20:00 - build_super_image.py - INFO : Building super image from info dict...
2021-07-12 10:20:00 - sparse_img.py - INFO : Total of 217749 4096-byte output blocks in 20 input chunks.
核心错误在句日志
RuntimeError: sum of sizes of [‘youroem_dynamic_partitions’] is greater than BOARD_SUPER_PARTITION_SIZE / 2: 2147483648
4290772992 == 4290772992 > 2147483648 == 2147483648
初步看起来是size比较的问题,追一下python脚本代码,从日志错误来看是调用的check_partition_sizes.py脚本,去build目录下find一下,找到后打开check_partition_sizes.py,找到报错的行号
if "super_partition_size" in info_dict:
group_size_list = [int(info_dict.get(
"super_{}_group_size".format(group), 0)) for group in groups]
sum_size = Expression("sum of sizes of {}".format(groups),
"+".join(str(size) for size in group_size_list),
sum(group_size_list))
max_size = Expression(
"BOARD_SUPER_PARTITION_SIZE{}".format(size_limit_suffix),
int(info_dict["super_partition_size"]) // num_slots)
sum_size.CheckLe(max_size)
查看一下max_size的定义和sum_size的来源,基本上就明白咋回事了,就是指在打开A/B配置的情况下,sum_size不能大于max_size的一半,对应到板卡makefile中的BOARD_SUPER_PARTITION_SIZE值,最后编译到了out产物中的misc_info.txt中,打包super时最后会检查一下这个size
到这里就基础明白跟BOARD_SUPER_PARTITION_SIZE有关了,全局查看一下发现走到8GB的那个配置了,导致的报错,初步修改是打开ENABLE_VIRTUAL_AB宏,解决了当前的报错,先分析到这里吧。
ifeq ($(ENABLE_AB), true)
ifeq ($(ENABLE_VIRTUAL_AB), true)
BOARD_SUPER_PARTITION_SIZE := 4294967296
else
BOARD_SUPER_PARTITION_SIZE := 8589934592
endif
TARGET_RECOVERY_FSTAB := device/youroem/test/recovery_AB_dynamic_partition.fstab
else
BOARD_SUPER_PARTITION_SIZE := 4294967296
TARGET_RECOVERY_FSTAB := device/youroem/test/recovery_non-AB_dynamic_partition.fstab
endif