AVB-avbtool中添加log时碰到的一些问题
起因:
一来,为了查看Makefile调用avbtool生成vbmeta相关数据时的一些细节,尝试在avbtool中增加log。
二则,在查看hashtree校验的几个分区的footer时,发现footer中指示的vbmeta offset超过了分区的大小,很是疑惑,决定加点log来对比下(这个“offset越界”的问题,最后会给下原因,是我狭隘了o(╥﹏╥)o)
还是丢个数据,我以为的vbmeta offset越界,红色部分圈出来的是vbmeta offset,已经超过了黄色部分的img大小
$ xxd system_ext.img |tail 11817020: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11817030: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11817040: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11817050: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11817060: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11817070: 0000 0000 0000 0000 4156 4266 0000 0001 ........AVBf.... 11817080: 0000 0000 0000 0000 1148 5000 0000 0000 .........HP..... 11817090: 118e b000 0000 0000 0000 0340 0000 0000 ...........@.... 118170a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 118170b0: 0000 0000 0000 0000 ........
本以为是个很简单的事情,结果在这个过程中居然还碰到了一些问题。
这里稍微做个记录。
能成功打印的log:
因为首先看的是生成vbmeta.img的过程,所以只在生成hash footer和vbmeta blob的时候添加了部分log,如下,截取部分添加的log:
+ print('avbtool make_vbmeta_image --> _generate_vbmeta_blob') + print('avbtool _generate_vbmeta_blob append chain partition: ', partition_name) + print('avbtool _generate_vbmeta_blob add descriptor from partition: ', image.name) + print('avbtool extract_public_key key_path:{}'.format(key_path)) + print('avbtool add_hash_footer partition = ', partition_name) + print('avbtool add_hash_footer image_size = ', image.image_size) + print('avbtool add_hash_footer --> _generate_vbmeta_blob')
实测下来,log能正常输出,截取部分打印log如下:
442 avbtool add_hash_footer partition = dtbo 443 avbtool add_hash_footer image_size = 1193543 444 avbtool add_hash_footer --> _generate_vbmeta_blob 445 avbtool add_hash_footer append vbmeta blob with padding 446 avbtool add_hash_footer append footer with padding 448 avbtool add_hash_footer partition = vendor_boot 449 avbtool add_hash_footer image_size = 327680 450 avbtool add_hash_footer --> _generate_vbmeta_blob 451 avbtool add_hash_footer append vbmeta blob with padding 452 avbtool add_hash_footer append footer with padding 454 avbtool add_hash_footer partition = boot 455 avbtool add_hash_footer image_size = 28340224 456 avbtool add_hash_footer --> _generate_vbmeta_blob 457 avbtool add_hash_footer append vbmeta blob with padding 458 avbtool add_hash_footer append footer with padding 601 avbtool make_vbmeta_image --> _generate_vbmeta_blob 602 avbtool _generate_vbmeta_blob add descriptor from partition: out/target/product/evb/system.img 603 avbtool _generate_vbmeta_blob add descriptor from partition: out/target/product/evb/system_ext.img 604 avbtool _generate_vbmeta_blob add descriptor from partition: out/target/product/evb/product.img
失败的log:
有了上述打印成功的log,信心满满的在生成hashtree footer的函数中增加了许多打印:
+ print('avbtool add_hashtree_footer image name = ', image.filename) + print('avbtool add_hashtree_footer image size = ', image.image_size) + print('avbtool add_hashtree_footer partition_size = ', partition_size) + print('avbtool add_hashtree_footer footer exist') + print('avbtool add_hashtree_footer original_image_size = ', original_image_size) + print('avbtool add_hashtree_footer original_image_size = ', original_image_size) + print('avbtool add_hashtree_footer --> generate_hash_tree') + print('avbtool add_hashtree_footer Write the hash tree') + print('avbtool add_hashtree_footer Generate the VBMeta footer and add padding as needed') + print('avbtool add_hashtree_footer Write vbmeta blob, if requested') + print('avbtool add_hashtree_footer Append vbmeta blob and footer') + print('avbtool add_hashtree_footer Generate the Footer that tells where the VBMeta footer is') + print('avbtool add_hashtree_footer vbmeta_offset = ', footer.vbmeta_offset) + print('avbtool add_hashtree_footer vbmeta_size = ', footer.vbmeta_size) + print('avbtool add_hashtree_footer Truncate back to original size, then re-raise')
结果惨被打脸。
编译报错,如下:
08446 avb CreateVerityImageBuilder, Image uses hashtree footer 08447 Traceback (most recent call last): 08448 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/internal/stdlib/runpy.py", line 174, in _run_module_as_main 08449 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/internal/stdlib/runpy.py", line 72, in _run_code 08450 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/__main__.py", line 12, in <module> 08451 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/internal/stdlib/runpy.py", line 174, in _run_module_as_main 08452 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/internal/stdlib/runpy.py", line 72, in _run_code 08453 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/build_image.py", line 815, in <module> 08454 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/build_image.py", line 807, in main 08455 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/build_image.py", line 476, in BuildImage 08456 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/verity_utils.py", line 448, in CalculateDynamicPartitionSize 08457 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/verity_utils.py", line 403, in CalculateMinPartitionSize 08458 File "/home/useraaa/evb/android/out/host/linux-x86/bin/build_image/verity_utils.py", line 480, in CalculateMaxImageSize 08459 ValueError: invalid literal for int() with base 10: 'avb add_hashtree_footer enter-\nadd_hashtree_footer return 285290496\n' 08462 FAILED: out/target/product/evb/product.img
看看这个480行是个什么东东:
文件:build/make/tools/releasetools/verity_utils.py
add_footer = ("add_hash_footer" if self.footer_type == self.AVB_HASH_FOOTER else "add_hashtree_footer") cmd = [self.avbtool, add_footer, "--partition_size", str(partition_size), "--calc_max_image_size"] cmd.extend(shlex.split(self.signing_args)) proc = common.Run(cmd) output, _ = proc.communicate() if proc.returncode != 0: raise BuildVerityImageError( "Failed to calculate max image size:\n{}".format(output)) image_size = int(output)
我们来看下上面标红的两行代码。
首先是Run函数,会得到一个subprocess.Popen对象:
build/make/tools/releasetools/common.py
def Run(args, verbose=None, **kwargs): """Creates and returns a subprocess.Popen object. Args: args: The command represented as a list of strings. verbose: Whether the commands should be shown. Default to the global verbosity if unspecified. kwargs: Any additional args to be passed to subprocess.Popen(), such as env, stdin, etc. stdout and stderr will default to subprocess.PIPE and subprocess.STDOUT respectively unless caller specifies any of them. universal_newlines will default to True, as most of the users in releasetools expect string output. Returns: A subprocess.Popen object. """ if 'stdout' not in kwargs and 'stderr' not in kwargs: kwargs['stdout'] = subprocess.PIPE kwargs['stderr'] = subprocess.STDOUT if 'universal_newlines' not in kwargs: kwargs['universal_newlines'] = True # Don't log any if caller explicitly says so. if verbose != False: logger.info(" Running: \"%s\"", " ".join(args)) return subprocess.Popen(args, **kwargs)
接着是subprocess.Popen的communicate函数,看这里的解释:https://docs.python.org/zh-cn/3.6/library/subprocess.html#subprocess.Popen.communicate
Popen.communicate(input=None, timeout=None)
与进程交互:向 stdin 传输数据。从 stdout 和 stderr 读取数据,直到文件结束符。等待进程终止。可选的 input 参数应当未被传输给子进程的数据,如果没有数据应被传输给子进程则为 None。如果流以文本模式打开, input 必须为字符串。否则,它必须为字节。
所以,CalculateMaxImageSize中,调用avbtool计算img size的时候,是直接通过返回值来转成int类型的。image_size = int(output)
如此一来,在log中看到的打印:ValueError: invalid literal for int() with base 10: 'avb add_hashtree_footer enter-\nadd_hashtree_footer return 285290496\n'也就能说得通了。
那么,如果想要在avbtool中增加log输出,该怎么做呢?
avbtool中将log输出到文件:
参考如下改动:
行 52: logfile=None 行 3427: print('add_hashtree_footer', file=logfile) 行 3451: print('calc_max_image_size:{}'.format(max_image_size), file=logfile) 行 3455: print('image_filename:', image_filename, file=logfile) 行 3480: print('original_image_size:{},image.image_size:{}'.format(original_image_size, image.image_size), file=logfile) 行 3583: print('vbmeta_offset:{}, tree_offset:{},len_hashtree_and_fec:{}'.format(vbmeta_offset, tree_offset, len_hashtree_and_fec), file=logfile) 行 4654: logfile=open("/home/useraaa/evb/avblog.txt", "a+") //这个是加在__main__中的 行 4655: print(sys.argv, file=logfile)
贴一下本地的log,这里将avbtool的每一次调用参数都做了输出:
['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--print_required_libavb_version', '--prop', 'com.android.build.system.fingerprint:xxx', '--prop', 'com.android.build.system.os_version:11', '--prop', 'com.android.build.system.security_patch:2023-04-05'] ['/home/useraaa/evb/android/out/soong/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--do_not_generate_fec', '--algorithm', 'SHA256_RSA4096', '--hash_algorithm', 'sha256', '--key', 'art/build/apex/com.android.art.pem', '--prop', 'apex.key:com.android.art', '--salt', 'xxx', '--image', '/home/useraaa/evb/android/out/soong/.temp/tmpvWMecV/content/apex_payload.img', '--no_hashtree'] add_hashtree_footer image_filename: /home/useraaa/evb/android/out/soong/.temp/tmpvWMecV/content/apex_payload.img original_image_size:134586368,image.image_size:134586368 vbmeta_offset:134586368, tree_offset:134586368,len_hashtree_and_fec:0 ['/home/useraaa/evb/android/out/soong/host/linux-x86/bin/avbtool', 'info_image', '--image', '/home/useraaa/evb/android/out/soong/.temp/tmpvWMecV/content/apex_payload.img'] ['/home/useraaa/evb/android/out/soong/host/linux-x86/bin/avbtool', 'resize_image', '--image', '/home/useraaa/evb/android/out/soong/.temp/tmpvWMecV/content/apex_payload.img', '--partition_size', '134594560'] ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '289951744', '--calc_max_image_size', '--prop', 'com.android.build.system_ext.fingerprint:xxx', '--prop', 'com.android.build.system_ext.os_version:11', '--prop', 'com.android.build.system_ext.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:285290496 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '294682624', '--calc_max_image_size', '--prop', 'com.android.build.system_ext.fingerprint:xxx', '--prop', 'com.android.build.system_ext.os_version:11', '--prop', 'com.android.build.system_ext.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:289943552 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '294686720', '--calc_max_image_size', '--prop', 'com.android.build.system_ext.fingerprint:xxx', '--prop', 'com.android.build.system_ext.os_version:11', '--prop', 'com.android.build.system_ext.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:289947648 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '294694912', '--calc_max_image_size', '--prop', 'com.android.build.system_ext.fingerprint:xxx', '--prop', 'com.android.build.system_ext.os_version:11', '--prop', 'com.android.build.system_ext.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:289955840 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '294686720', '--calc_max_image_size', '--prop', 'com.android.build.system_ext.fingerprint:xxx', '--prop', 'com.android.build.system_ext.os_version:11', '--prop', 'com.android.build.system_ext.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:289947648 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '294690816', '--calc_max_image_size', '--prop', 'com.android.build.system_ext.fingerprint:xxx', '--prop', 'com.android.build.system_ext.os_version:11', '--prop', 'com.android.build.system_ext.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:289951744 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '294690816', '--calc_max_image_size', '--prop', 'com.android.build.system_ext.fingerprint:xxx', '--prop', 'com.android.build.system_ext.os_version:11', '--prop', 'com.android.build.system_ext.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:289951744 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '371732480', '--calc_max_image_size', '--prop', 'com.android.build.product.fingerprint:xxx', '--prop', 'com.android.build.product.os_version:11', '--prop', 'com.android.build.product.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:365780992 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '377774080', '--calc_max_image_size', '--prop', 'com.android.build.product.fingerprint:xxx', '--prop', 'com.android.build.product.os_version:11', '--prop', 'com.android.build.product.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:371728384 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '377778176', '--calc_max_image_size', '--prop', 'com.android.build.product.fingerprint:xxx', '--prop', 'com.android.build.product.os_version:11', '--prop', 'com.android.build.product.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:371732480 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '377774080', '--calc_max_image_size', '--prop', 'com.android.build.product.fingerprint:xxx', '--prop', 'com.android.build.product.os_version:11', '--prop', 'com.android.build.product.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:371728384 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '377778176', '--calc_max_image_size', '--prop', 'com.android.build.product.fingerprint:xxx', '--prop', 'com.android.build.product.os_version:11', '--prop', 'com.android.build.product.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:371732480 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '294690816', '--partition_name', 'system_ext', '--image', 'out/target/product/evb/system_ext.img', '--prop', 'com.android.build.system_ext.fingerprint:xxx', '--prop', 'com.android.build.system_ext.os_version:11', '--prop', 'com.android.build.system_ext.security_patch:2023-04-05'] add_hashtree_footer image_filename: out/target/product/evb/system_ext.img original_image_size:289951744,image.image_size:289951744 vbmeta_offset:294563840, tree_offset:289951744,len_hashtree_and_fec:4612096 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '377778176', '--partition_name', 'product', '--image', 'out/target/product/evb/product.img', '--prop', 'com.android.build.product.fingerprint:xxx', '--prop', 'com.android.build.product.os_version:11', '--prop', 'com.android.build.product.security_patch:2023-04-05'] add_hashtree_footer image_filename: out/target/product/evb/product.img original_image_size:371732480,image.image_size:371732480 vbmeta_offset:377634816, tree_offset:371732480,len_hashtree_and_fec:5902336 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hash_footer', '--image', 'out/target/product/evb/dtbo.img', '--partition_size', '0x01800000', '--partition_name', 'dtbo', '--prop', 'com.android.build.dtbo.fingerprint:xxx'] ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hash_footer', '--image', 'out/target/product/evb/vendor_boot.img', '--partition_size', '0x06000000', '--partition_name', 'vendor_boot', '--prop', 'com.android.build.vendor_boot.fingerprint:xxx'] ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hash_footer', '--image', 'out/target/product/evb/boot.img', '--partition_size', '0x06000000', '--partition_name', 'boot', '--prop', 'com.android.build.boot.fingerprint:xxx', '--prop', 'com.android.build.boot.os_version:11', '--prop', 'com.android.build.boot.security_patch:2022-11-05'] ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '1030410240', '--calc_max_image_size', '--prop', 'com.android.build.system.fingerprint:xxx', '--prop', 'com.android.build.system.os_version:11', '--prop', 'com.android.build.system.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:1014063104 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '1047015424', '--calc_max_image_size', '--prop', 'com.android.build.system.fingerprint:xxx', '--prop', 'com.android.build.system.os_version:11', '--prop', 'com.android.build.system.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:1030406144 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '1047019520', '--calc_max_image_size', '--prop', 'com.android.build.system.fingerprint:xxx', '--prop', 'com.android.build.system.os_version:11', '--prop', 'com.android.build.system.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:1030410240 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '1047015424', '--calc_max_image_size', '--prop', 'com.android.build.system.fingerprint:xxx', '--prop', 'com.android.build.system.os_version:11', '--prop', 'com.android.build.system.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:1030406144 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '1047019520', '--calc_max_image_size', '--prop', 'com.android.build.system.fingerprint:xxx', '--prop', 'com.android.build.system.os_version:11', '--prop', 'com.android.build.system.security_patch:2023-04-05'] add_hashtree_footer calc_max_image_size:1030410240 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '1047019520', '--partition_name', 'system', '--image', 'out/target/product/evb/obj/PACKAGING/systemimage_intermediates/system.img', '--prop', 'com.android.build.system.fingerprint:xxx', '--prop', 'com.android.build.system.os_version:11', '--prop', 'com.android.build.system.security_patch:2023-04-05'] add_hashtree_footer image_filename: out/target/product/evb/obj/PACKAGING/systemimage_intermediates/system.img original_image_size:1030410240,image.image_size:1030410240 vbmeta_offset:1046749184, tree_offset:1030410240,len_hashtree_and_fec:16338944 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'make_vbmeta_image', '--algorithm', 'SHA256_RSA2048', '--key', 'external/avb/test/data/testkey_rsa2048.pem', '--padding_size', '4096', '--rollback_index', '1680652800', '--include_descriptors_from_image', 'out/target/product/evb/system.img', '--include_descriptors_from_image', 'out/target/product/evb/system_ext.img', '--include_descriptors_from_image', 'out/target/product/evb/product.img', '--output', 'out/target/product/evb/vbmeta_system.img'] ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '614162432', '--calc_max_image_size', '--prop', 'com.android.build.vendor.fingerprint:xxx', '--prop', 'com.android.build.vendor.os_version:11', '--prop', 'com.android.build.vendor.security_patch:2022-11-05'] add_hashtree_footer calc_max_image_size:604385280 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '624091136', '--calc_max_image_size', '--prop', 'com.android.build.vendor.fingerprint:xxx', '--prop', 'com.android.build.vendor.os_version:11', '--prop', 'com.android.build.vendor.security_patch:2022-11-05'] add_hashtree_footer calc_max_image_size:614154240 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '624095232', '--calc_max_image_size', '--prop', 'com.android.build.vendor.fingerprint:xxx', '--prop', 'com.android.build.vendor.os_version:11', '--prop', 'com.android.build.vendor.security_patch:2022-11-05'] add_hashtree_footer calc_max_image_size:614158336 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '624103424', '--calc_max_image_size', '--prop', 'com.android.build.vendor.fingerprint:xxx', '--prop', 'com.android.build.vendor.os_version:11', '--prop', 'com.android.build.vendor.security_patch:2022-11-05'] add_hashtree_footer calc_max_image_size:614166528 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '624095232', '--calc_max_image_size', '--prop', 'com.android.build.vendor.fingerprint:xxx', '--prop', 'com.android.build.vendor.os_version:11', '--prop', 'com.android.build.vendor.security_patch:2022-11-05'] add_hashtree_footer calc_max_image_size:614158336 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '624099328', '--calc_max_image_size', '--prop', 'com.android.build.vendor.fingerprint:xxx', '--prop', 'com.android.build.vendor.os_version:11', '--prop', 'com.android.build.vendor.security_patch:2022-11-05'] add_hashtree_footer calc_max_image_size:614162432 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '624099328', '--calc_max_image_size', '--prop', 'com.android.build.vendor.fingerprint:xxx', '--prop', 'com.android.build.vendor.os_version:11', '--prop', 'com.android.build.vendor.security_patch:2022-11-05'] add_hashtree_footer calc_max_image_size:614162432 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'add_hashtree_footer', '--partition_size', '624099328', '--partition_name', 'vendor', '--image', 'out/target/product/evb/vendor.img', '--prop', 'com.android.build.vendor.fingerprint:xxx', '--prop', 'com.android.build.vendor.os_version:11', '--prop', 'com.android.build.vendor.security_patch:2022-11-05'] add_hashtree_footer image_filename: out/target/product/evb/vendor.img original_image_size:614162432,image.image_size:614162432 vbmeta_offset:623906816, tree_offset:614162432,len_hashtree_and_fec:9744384 ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'extract_public_key', '--key', 'external/avb/test/data/testkey_rsa2048.pem', '--output', 'out/target/product/evb/obj/avb_chain_keys/vbmeta_system.avbpubkey'] ['/home/useraaa/evb/android/out/host/linux-x86/bin/avbtool', 'make_vbmeta_image', '--include_descriptors_from_image', 'out/target/product/evb/boot.img', '--include_descriptors_from_image', 'out/target/product/evb/vendor_boot.img', '--include_descriptors_from_image', 'out/target/product/evb/vendor.img', '--include_descriptors_from_image', 'out/target/product/evb/dtbo.img', '--chain_partition', 'vbmeta_system:2:out/target/product/evb/obj/avb_chain_keys/vbmeta_system.avbpubkey', '--algorithm', 'SHA256_RSA4096', '--key', 'vendor/xxx/common/keytools/veritykey_rsa4096.pem', '--padding_size', '4096', '--output', 'out/target/product/evb/vbmeta.img']
关于hashtree footer中vbmeta offset越界的乌龙:
无他,因为这些都是大分区,采用了sparse格式。
所以,通过以下命令将sparse格式img转换为raw ext4格式再看:
/home/useraaa/evb/android/out/host/linux-x86/bin/simg2img system_ext.img system_ext.raw
$ xxd system_ext.raw |tail 11909f60: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11909f70: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11909f80: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11909f90: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11909fa0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11909fb0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 11909fc0: 4156 4266 0000 0001 0000 0000 0000 0000 AVBf............ 11909fd0: 1148 5000 0000 0000 118e b000 0000 0000 .HP............. 11909fe0: 0000 0340 0000 0000 0000 0000 0000 0000 ...@............ 11909ff0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
这下子就不会越界了,囧。