Lines Matching full:args
121 def get_recovery_dtbo_offset(args): argument
124 num_kernel_pages = get_number_of_pages(filesize(args.kernel), args.pagesize)
125 num_ramdisk_pages = get_number_of_pages(filesize(args.ramdisk),
126 args.pagesize)
127 num_second_pages = get_number_of_pages(filesize(args.second), args.pagesize)
128 dtbo_offset = args.pagesize * (num_header_pages + num_kernel_pages +
133 def should_add_legacy_gki_boot_signature(args): argument
134 if args.gki_signing_key and args.gki_signing_algorithm:
139 def write_header_v3_and_above(args): argument
140 if args.header_version > 3:
145 args.output.write(pack(f'{BOOT_MAGIC_SIZE}s', BOOT_MAGIC.encode()))
147 args.output.write(pack('I', filesize(args.kernel)))
149 args.output.write(pack('I', filesize(args.ramdisk)))
151 args.output.write(pack('I', (args.os_version << 11) | args.os_patch_level))
152 args.output.write(pack('I', boot_header_size))
154 args.output.write(pack('4I', 0, 0, 0, 0))
156 args.output.write(pack('I', args.header_version))
157 args.output.write(pack(f'{BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE}s',
158 args.cmdline))
159 if args.header_version >= 4:
162 if should_add_legacy_gki_boot_signature(args):
164 args.output.write(pack('I', boot_signature_size))
165 pad_file(args.output, BOOT_IMAGE_HEADER_V3_PAGESIZE)
168 def write_vendor_boot_header(args): argument
169 if args.header_version > 3:
170 vendor_ramdisk_size = args.vendor_ramdisk_total_size
173 vendor_ramdisk_size = filesize(args.vendor_ramdisk)
176 args.vendor_boot.write(pack(f'{VENDOR_BOOT_MAGIC_SIZE}s',
179 args.vendor_boot.write(pack('I', args.header_version))
181 args.vendor_boot.write(pack('I', args.pagesize))
183 args.vendor_boot.write(pack('I', args.base + args.kernel_offset))
185 args.vendor_boot.write(pack('I', args.base + args.ramdisk_offset))
187 args.vendor_boot.write(pack('I', vendor_ramdisk_size))
188 args.vendor_boot.write(pack(f'{VENDOR_BOOT_ARGS_SIZE}s',
189 args.vendor_cmdline))
191 args.vendor_boot.write(pack('I', args.base + args.tags_offset))
193 args.vendor_boot.write(pack(f'{VENDOR_BOOT_NAME_SIZE}s', args.board))
196 args.vendor_boot.write(pack('I', vendor_boot_header_size))
199 args.vendor_boot.write(pack('I', filesize(args.dtb)))
201 args.vendor_boot.write(pack('Q', args.base + args.dtb_offset))
203 if args.header_version > 3:
204 vendor_ramdisk_table_size = (args.vendor_ramdisk_table_entry_num *
207 args.vendor_boot.write(pack('I', vendor_ramdisk_table_size))
209 args.vendor_boot.write(pack('I', args.vendor_ramdisk_table_entry_num))
211 args.vendor_boot.write(pack('I', VENDOR_RAMDISK_TABLE_ENTRY_V4_SIZE))
213 args.vendor_boot.write(pack('I', filesize(args.vendor_bootconfig)))
214 pad_file(args.vendor_boot, args.pagesize)
217 def write_header(args): argument
218 if args.header_version > 4:
220 f'Boot header version {args.header_version} not supported')
221 if args.header_version in {3, 4}:
222 return write_header_v3_and_above(args)
224 ramdisk_load_address = ((args.base + args.ramdisk_offset)
225 if filesize(args.ramdisk) > 0 else 0)
226 second_load_address = ((args.base + args.second_offset)
227 if filesize(args.second) > 0 else 0)
229 args.output.write(pack(f'{BOOT_MAGIC_SIZE}s', BOOT_MAGIC.encode()))
231 args.output.write(pack('I', filesize(args.kernel)))
233 args.output.write(pack('I', args.base + args.kernel_offset))
235 args.output.write(pack('I', filesize(args.ramdisk)))
237 args.output.write(pack('I', ramdisk_load_address))
239 args.output.write(pack('I', filesize(args.second)))
241 args.output.write(pack('I', second_load_address))
243 args.output.write(pack('I', args.base + args.tags_offset))
245 args.output.write(pack('I', args.pagesize))
247 args.output.write(pack('I', args.header_version))
249 args.output.write(pack('I', (args.os_version << 11) | args.os_patch_level))
251 args.output.write(pack(f'{BOOT_NAME_SIZE}s', args.board))
252 args.output.write(pack(f'{BOOT_ARGS_SIZE}s', args.cmdline))
255 update_sha(sha, args.kernel)
256 update_sha(sha, args.ramdisk)
257 update_sha(sha, args.second)
259 if args.header_version > 0:
260 update_sha(sha, args.recovery_dtbo)
261 if args.header_version > 1:
262 update_sha(sha, args.dtb)
266 args.output.write(img_id)
267 args.output.write(pack(f'{BOOT_EXTRA_ARGS_SIZE}s', args.extra_cmdline))
269 if args.header_version > 0:
270 if args.recovery_dtbo:
272 args.output.write(pack('I', filesize(args.recovery_dtbo)))
274 args.output.write(pack('Q', get_recovery_dtbo_offset(args)))
277 args.output.write(pack('I', 0))
278 args.output.write(pack('Q', 0))
281 if args.header_version == 1:
282 args.output.write(pack('I', BOOT_IMAGE_HEADER_V1_SIZE))
283 elif args.header_version == 2:
284 args.output.write(pack('I', BOOT_IMAGE_HEADER_V2_SIZE))
286 if args.header_version > 1:
287 # if filesize(args.dtb) == 0:
291 args.output.write(pack('I', filesize(args.dtb)))
293 args.output.write(pack('Q', args.base + args.dtb_offset))
295 pad_file(args.output, args.pagesize)
453 def parse_vendor_ramdisk_args(args, args_list): argument
456 Args:
457 args: An argparse.Namespace object. Parsed results are stored into this
477 if args.vendor_ramdisk is not None:
479 args.vendor_ramdisk.name, VENDOR_RAMDISK_TYPE_PLATFORM, b'', None)
501 args.vendor_ramdisk_total_size = (vendor_ramdisk_table_builder
503 args.vendor_ramdisk_table_entry_num = len(vendor_ramdisk_table_builder
505 args.vendor_ramdisk_table_builder = vendor_ramdisk_table_builder
590 args, extra_args = parser.parse_known_args()
591 if args.vendor_boot is not None and args.header_version > 3:
592 extra_args = parse_vendor_ramdisk_args(args, extra_args)
596 if args.header_version < 3:
597 args.extra_cmdline = args.cmdline[BOOT_ARGS_SIZE-1:]
598 args.cmdline = args.cmdline[:BOOT_ARGS_SIZE-1] + b'\x00'
599 assert len(args.cmdline) <= BOOT_ARGS_SIZE
600 assert len(args.extra_cmdline) <= BOOT_EXTRA_ARGS_SIZE
602 return args
605 def add_boot_image_signature(args, pagesize): argument
616 args.output.flush()
623 image=args.output.name, avbtool=args.gki_signing_avbtool_path,
624 name='boot', algorithm=args.gki_signing_algorithm,
625 key=args.gki_signing_key, salt='d00df00d',
626 additional_avb_args=args.gki_signing_signature_args.split(),
637 args.output.write(boot_signature_bytes)
638 pad_file(args.output, pagesize)
641 def write_data(args, pagesize): argument
642 write_padded_file(args.output, args.kernel, pagesize)
643 write_padded_file(args.output, args.ramdisk, pagesize)
644 write_padded_file(args.output, args.second, pagesize)
646 if args.header_version > 0 and args.header_version < 3:
647 write_padded_file(args.output, args.recovery_dtbo, pagesize)
648 if args.header_version == 2:
649 write_padded_file(args.output, args.dtb, pagesize)
650 if args.header_version >= 4 and should_add_legacy_gki_boot_signature(args):
651 add_boot_image_signature(args, pagesize)
654 def write_vendor_boot_data(args): argument
655 if args.header_version > 3:
656 builder = args.vendor_ramdisk_table_builder
657 builder.write_ramdisks_padded(args.vendor_boot, args.pagesize)
658 write_padded_file(args.vendor_boot, args.dtb, args.pagesize)
659 builder.write_entries_padded(args.vendor_boot, args.pagesize)
660 write_padded_file(args.vendor_boot, args.vendor_bootconfig,
661 args.pagesize)
663 write_padded_file(args.vendor_boot, args.vendor_ramdisk, args.pagesize)
664 write_padded_file(args.vendor_boot, args.dtb, args.pagesize)
668 args = parse_cmdline()
669 if args.vendor_boot is not None:
670 if args.header_version not in {3, 4}:
673 if args.header_version == 3 and args.vendor_ramdisk is None:
675 write_vendor_boot_header(args)
676 write_vendor_boot_data(args)
677 if args.output is not None:
678 if args.second is not None and args.header_version > 2:
681 img_id = write_header(args)
682 if args.header_version > 2:
683 write_data(args, BOOT_IMAGE_HEADER_V3_PAGESIZE)
685 write_data(args, args.pagesize)
686 if args.id and img_id is not None: