def parse_cmdline():
478 version_parser = ArgumentParser(add_help=False)
479 version_parser.add_argument(’–header_version’, type=parse_int, default=0)
480 if version_parser.parse_known_args()[0].header_version < 3:
481 # For boot header v0 to v2, the kernel commandline field is split into
482 # two fields, cmdline and extra_cmdline. Both fields are asciiz strings,
483 # so we minus one here to ensure the encoded string plus the
484 # null-terminator can fit in the buffer size.
485 cmdline_size = BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE - 1
486 else:
487 cmdline_size = BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE
488
489 parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,
490 epilog=get_vendor_boot_v4_usage())
491 parser.add_argument(’–kernel’, type=FileType(‘rb’),
492 help=‘path to the kernel’)
493 parser.add_argument(’–ramdisk’, type=FileType(‘rb’),
494 help=‘path to the ramdisk’)
495 parser.add_argument(’–second’, type=FileType(‘rb’),
496 help=‘path to the second bootloader’)
497 parser.add_argument(’–dtb’, type=FileType(‘rb’), help=‘path to the dtb’)
498 dtbo_group = parser.add_mutually_exclusive_group()
499 dtbo_group.add_argument(’–recovery_dtbo’, type=FileType(‘rb’),
500 help=‘path to the recovery DTBO’)
501 dtbo_group.add_argument(’–recovery_acpio’, type=FileType(‘rb’),
502 metavar=‘RECOVERY_ACPIO’, dest=‘recovery_dtbo’,
503 help=‘path to the recovery ACPIO’)
504 parser.add_argument(’–cmdline’, type=AsciizBytes(bufsize=cmdline_size),
505 default=’’, help=‘kernel command line arguments’)
506 parser.add_argument(’–vendor_cmdline’,
507 type=AsciizBytes(bufsize=VENDOR_BOOT_ARGS_SIZE),
508 default=’’,
509 help=‘vendor boot kernel command line arguments’)
510 parser.add_argument(’–base’, type=parse_int, default=0x10000000,
511 help=‘base address’)
512 parser.add_argument(’–kernel_offset’, type=parse_int, default=0x00008000,
513 help=‘kernel offset’)
514 parser.add_argument(’–ramdisk_offset’, type=parse_int, default=0x01000000,
515 help=‘ramdisk offset’)
516 parser.add_argument(’–second_offset’, type=parse_int, default=0x00f00000,
517 help=‘second bootloader offset’)
518 parser.add_argument(’–dtb_offset’, type=parse_int, default=0x01f00000,
519 help=‘dtb offset’)
520
521 parser.add_argument(’–os_version’, type=parse_os_version, default=0,
522 help=‘operating system version’)
523 parser.add_argument(’–os_patch_level’, type=parse_os_patch_level,
524 default=0, help=‘operating system patch level’)
525 parser.add_argument(’–tags_offset’, type=parse_int, default=0x00000100,
526 help=‘tags offset’)
527 parser.add_argument(’–board’, type=AsciizBytes(bufsize=BOOT_NAME_SIZE),
528 default=’’, help=‘board name’)
529 parser.add_argument(’–pagesize’, type=parse_int,
530 choices=[2**i for i in range(11, 15)], default=2048,
531 help=‘page size’)
532 parser.add_argument(’–id’, action=‘store_true’,
533 help=‘print the image ID on standard output’)
534 parser.add_argument(’–header_version’, type=parse_int, default=0,
535 help=‘boot image header version’)
536 parser.add_argument(’-o’, ‘–output’, type=FileType(‘wb’),
537 help=‘output file name’)
538 parser.add_argument(’–gki_signing_algorithm’,
539 help=‘GKI signing algorithm to use’)
540 parser.add_argument(’–gki_signing_key’,
541 help=‘path to RSA private key file’)
542 parser.add_argument(’–gki_signing_signature_args’,
543 help=‘other hash arguments passed to avbtool’)
544 parser.add_argument(’–gki_signing_avbtool_path’,
545 help=‘path to avbtool for boot signature generation’)
546 parser.add_argument(’–vendor_boot’, type=FileType(‘wb’),
547 help=‘vendor boot output file name’)
548 parser.add_argument(’–vendor_ramdisk’, type=FileType(‘rb’),
549 help=‘path to the vendor ramdisk’)
550 parser.add_argument(’–vendor_bootconfig’, type=FileType(‘rb’),
551 help=‘path to the vendor bootconfig file’)
552
553 args, extra_args = parser.parse_known_args()
554 if args.vendor_boot is not None and args.header_version > 3:
555 extra_args = parse_vendor_ramdisk_args(args, extra_args)
556 if len(extra_args) > 0:
557 raise ValueError(f’Unrecognized arguments: {extra_args}’)
558
559 if args.header_version < 3:
560 args.extra_cmdline = args.cmdline[BOOT_ARGS_SIZE-1:]
561 args.cmdline = args.cmdline[:BOOT_ARGS_SIZE-1] + b’\x00’
562 assert len(args.cmdline) <= BOOT_ARGS_SIZE
563 assert len(args.extra_cmdline) <= BOOT_EXTRA_ARGS_SIZE
564
565 return args
566
2021-09-06 parse_cmdline()
最新推荐文章于 2021-11-12 19:37:56 发布
这段代码定义了一个用于解析命令行参数的函数,这些参数涉及内核、ramdisk、引导加载器、设备树等的位置和大小。它还处理不同版本的引导头,调整命令行字符串的大小,并提供了输出文件名、基地址、页大小等配置选项。此外,代码还支持GKI签名算法、私钥文件和Avbtool路径,用于生成签名。
摘要由CSDN通过智能技术生成