From 64ae9cae997a794d82c7e121561c10323e9ba8ce Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Wed, 29 Nov 2023 18:07:40 -0500 Subject: [PATCH] Working version Tested with: qemu-system-x86_64 -nic none -serial mon:stdio \ -drive file=fat:rw:PATH_HERE,format=raw \ -bios /usr/share/edk2/ovmf/OVMF_CODE.fd \ -m 2048M \ -display gtk,grab-on-hover=off --- uki-generate | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/uki-generate b/uki-generate index ace77c1..0771462 100755 --- a/uki-generate +++ b/uki-generate @@ -1,11 +1,12 @@ #!/usr/bin/python3 -I import os -import rpm import subprocess import sys +import re from typing import List, Tuple def main(args): + section_re = re.compile(rb"\A *(?:0|[1-9][0-9]*) +([!-~]+) +([0-9a-f]{8}) +([0-9a-f]{16}) +[0-9a-f]{16} +[0-9a-f]{8} +2") alignment_mask = (1 << 21) - 1 if len(args) != 6: print(f"Usage: uki-generate HYPERVISOR CONFIG KERNEL INITRAMFS OUTPUT", file=sys.stderr) @@ -15,27 +16,47 @@ def main(args): hyp = './' + hyp if out[0] != '/': out = './' + out + output = subprocess.check_output([ + "objdump", + "-WE", # do not use debuginfod + "--section-headers", + "--", + hyp, + ]) + max_vma = 0 + print(output.decode("UTF-8", 'surrogateescape')) + for line in output.splitlines(): + m = section_re.match(line) + if not m: + continue + section_name, size, start_vma = m.group(1), int(m.group(2), 16), int(m.group(3), 16) + if section_name.startswith(b".annobin"): + continue + max_vma = max(max_vma, size, + start_vma) def round_to_next(f: int) -> int: max_address = (0xffffffffffffffff & ~alignment_mask) if f > max_address: print(f"Fatal error: Address overflow: {f} exceeds {max_address}", file=sys.stderr) sys.exit(1) return (f + alignment_mask) & ~alignment_mask - base_address = 0xffff82d042000000 + base_address = round_to_next(max_vma) + print(f"Base address is 0x{base_address:x}") kernel_vma = round_to_next(base_address + os.stat(cfg).st_size) initramfs_vma = round_to_next(kernel_vma + os.stat(kern).st_size) cmdline = [ "objcopy", f"--section-alignment={alignment_mask + 1}", - "--remove-section=.gnu.*", - "--remove-section=.buildid", - "--strip-debug", + f"--file-alignment={1 << 5}", + #"--remove-section=.buildid", + "--remove-section=.annobin.*", + #"--strip-debug", f"--add-section=.config={cfg}", f"--change-section-vma=.config={base_address}", f"--add-section=.kernel={kern}", f"--change-section-vma=.kernel={kernel_vma}", f"--add-section=.ramdisk={initramfs}", f"--change-section-vma=.ramdisk={initramfs_vma}", + "--long-section-names=disable", "--", hyp, out,