Skip to content

Commit

Permalink
Add script to generate Xen unified kernel images
Browse files Browse the repository at this point in the history
This is a prerequisite for secure boot.
  • Loading branch information
DemiMarie committed Jul 3, 2023
1 parent 8a45805 commit 0485b38
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions uki-generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python3 -I
import os
import rpm
import subprocess
import sys
from typing import List, Tuple

def main(args):
alignment_mask = (1 << 21) - 1
if len(args) != 7 || args[1] != '--':
print(f"Usage: uki-generate -- HYPERVISOR CONFIG KERNEL INITRAMFS OUTPUT", file=sys.stderr)
sys.exit(1)
_, _, hyp, cfg, kern, initramfs, out = args
if hyp[0] != '/':
hyp = './' + hyp
if out[0] != '/':
out = './' + out
def round_to_next(f: int) -> int:
if f > (0xffffffffffffffff & ~alignment_mask):
raise ValueError("Address overflow")
return (f + alignment_mask) & ~alignment_mask
base_address = 0xffff82d042000000
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"--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}",
"--",
hyp,
out,
]
subprocess.check_call(cmdline, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
if __name__ == '__main__':
main(sys.argv)

0 comments on commit 0485b38

Please sign in to comment.