-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate Xen unified kernel images
This is a prerequisite for secure boot.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |