Skip to content

Commit

Permalink
Working version
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DemiMarie committed Nov 30, 2023
1 parent 4b65b2d commit 64ae9ca
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions uki-generate
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 64ae9ca

Please sign in to comment.