当前位置:   article > 正文

Android super.img结构及解包和重新组包_android 重新生成super.img

android 重新生成super.img

Android super.img结构及解包和重新组包

从Android10版本开始,Android系统使用动态分区,system、vendor、 odm等都包含在super.img里面,编译后的最终镜像不再有这些单独的 image,取而代之的是一个总的 super.img.

1. 基础知识

1.1 为什么用 super 分区代替独立的分区?

传统的分区方式将 system、vendor、product、分区各自独立,在实际的项目开发中,通常每个分区都会留有部分空间,三个(可能没有 product) 分区累计就需要预留不少的空间,并且各个分区的大小被固定,不能灵活调整,比如 system 分区容量不够了,但是 vendor 分区又有多余的空间。

统一合并成一个分区后,使用 super 动态调整分区功能可以灵活调整内部分区大小,从而能更好的利用存储空间。

1.2 支持的动态分区包括

  • system

  • Vendor

  • Product

  • System Ext

  • ODM

对于 A/B 设备,super 分区的大小需要包括两个槽位的大小,super 分区会在内部处理 A/B 槽位,因此 A/B 设备不需要单独的 super_a 和 super_b 分区。

1.3 super分区结构

可以通过lpdump命令dump出super.img的结构:

  1. # lpdump super_ext4.img
  2. $ sudo linux-x86/bin/lpdump super_ext4.img
  3. Slot 0:
  4. Metadata version: 10.2
  5. Metadata size: 1232 bytes
  6. Metadata max size: 65536 bytes
  7. Metadata slot count: 3
  8. Header flags: virtual_ab_device
  9. Partition table:
  10. ------------------------
  11. Name: product_a
  12. Group: qti_dynamic_partitions_a
  13. Attributes: readonly
  14. Extents:
  15. 0 .. 487015 linear super 2048
  16. ------------------------
  17. Name: product_b
  18. Group: qti_dynamic_partitions_b
  19. Attributes: readonly
  20. Extents:
  21. ------------------------
  22. Name: system_a
  23. Group: qti_dynamic_partitions_a
  24. Attributes: readonly
  25. Extents:
  26. 0 .. 4051775 linear super 489472
  27. ------------------------
  28. Name: system_b
  29. Group: qti_dynamic_partitions_b
  30. Attributes: readonly
  31. Extents:
  32. ------------------------
  33. Name: system_dlkm_a
  34. Group: qti_dynamic_partitions_a
  35. Attributes: readonly
  36. Extents:
  37. 0 .. 24071 linear super 4542464
  38. ------------------------
  39. Name: system_dlkm_b
  40. Group: qti_dynamic_partitions_b
  41. Attributes: readonly
  42. Extents:
  43. ------------------------
  44. Name: system_ext_a
  45. Group: qti_dynamic_partitions_a
  46. Attributes: readonly
  47. Extents:
  48. 0 .. 550263 linear super 4567040
  49. ------------------------
  50. Name: system_ext_b
  51. Group: qti_dynamic_partitions_b
  52. Attributes: readonly
  53. Extents:
  54. ------------------------
  55. Name: vendor_a
  56. Group: qti_dynamic_partitions_a
  57. Attributes: readonly
  58. Extents:
  59. 0 .. 747055 linear super 5117952
  60. ------------------------
  61. Name: vendor_b
  62. Group: qti_dynamic_partitions_b
  63. Attributes: readonly
  64. Extents:
  65. ------------------------
  66. Name: vendor_dlkm_a
  67. Group: qti_dynamic_partitions_a
  68. Attributes: readonly
  69. Extents:
  70. 0 .. 3036791 linear super 5865472
  71. ------------------------
  72. Name: vendor_dlkm_b
  73. Group: qti_dynamic_partitions_b
  74. Attributes: readonly
  75. Extents:
  76. ------------------------
  77. Super partition layout:
  78. ------------------------
  79. super: 2048 .. 489064: product_a (487016 sectors)
  80. super: 489472 .. 4541248: system_a (4051776 sectors)
  81. super: 4542464 .. 4566536: system_dlkm_a (24072 sectors)
  82. super: 4567040 .. 5117304: system_ext_a (550264 sectors)
  83. super: 5117952 .. 5865008: vendor_a (747056 sectors)
  84. super: 5865472 .. 8902264: vendor_dlkm_a (3036792 sectors)
  85. ------------------------
  86. Block device table:
  87. ------------------------
  88. Partition name: super
  89. First sector: 2048
  90. Size: 12884901888 bytes
  91. Flags: none
  92. ------------------------
  93. Group table:
  94. ------------------------
  95. Name: default
  96. Maximum size: 0 bytes
  97. Flags: none
  98. ------------------------
  99. Name: qti_dynamic_partitions_a
  100. Maximum size: 6438256640 bytes
  101. Flags: none
  102. ------------------------
  103. Name: qti_dynamic_partitions_b
  104. Maximum size: 6438256640 bytes
  105. Flags: none
  106. ------------------------

lpdump 只能解析非 sparse 格式的 image,而系统编译的 super.img 是 sparse 格式,需要使用 simg2img 将 Android 编译生成的 sparse 格式的 super.img 转换成 raw 格式。

simg2img super.img super_ext4.img

2. super.img解包和组包

可以按如下方式对super.img进行解包和组包。

2.1 super.img解包

super的解包需要工具lpunpack,但是默认没有编译,源码目录位于:system/extras/partition_tools/ ,需要手动编译生成;

在android根目录下执行

make lpunpack

编译后生成物位置:

out/host/linux-86/bin/lpunpack

开始解包:

第一步,格式转换,转化为ext4

simg2img super.img super_ext4.img

第二步,创建目录super_ext4/ 存放解包后的文件

mkdir super_ext4

第三步,解包super_ext4.img

out/host/linux-86/bin/lpunpack super_ext4.img super_ext4/

解包后在super_ext4/存放着是哪个完整的system.img vendor.img product.img 是ext4格式的,也可以通过mount挂载为文件目录

2.2 打包super.img

打包需要的工具lpmake,工具位置:

out/host/linux-86/bin/lpmake

第一步,确认各个img的大小

上面解包出来super_ext4目录下的img文件,需要重新打包成super.img,在super_ext4/目录下执行

  1. $ stat -c '%n %s' *
  2. odm.img 626688
  3. product.img 213348352
  4. system_ext.img 123666432
  5. system.img 980586496
  6. vendor.img 315723776

第二步,开始打包super.img

按如下命令打包

  1. out/host/linux-86/bin/lpmake \
  2. --metadata-size 65536 --super-name super \
  3. --metadata-slots 2 \
  4. --device super:3263168512 \
  5. --group rockchip_dynamic_partitions:3258974208 \
  6. --partition system:readonly:980586496:rockchip_dynamic_partitions --image system=out/target/product/rk3568_r/system.img \
  7. --partition system_ext:readonly:123666432:rockchip_dynamic_partitions --image system_ext=out/target/product/rk3568_r/system_ext.img \
  8. --partition vendor:readonly:315723776:rockchip_dynamic_partitions --image vendor=out/target/product/rk3568_r/vendor.img \
  9. --partition product:readonly:213348352:rockchip_dynamic_partitions --image product=out/target/product/rk3568_r/product.img \
  10. --partition odm:readonly:626688:rockchip_dynamic_partitions --image odm=out/target/product/rk3568_r/odm.img \
  11. --sparse \
  12. --output out/target/product/rk3568_r/super.img

这个命令可以在编译android的时候通过编译log获取,log保存在out/verbose.log.gz中,可以通过如下命令显示所有log,然后在里面找lpmake

gzip -cd out/verbose.log.gz|less

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/796040
推荐阅读
相关标签
  

闽ICP备14008679号