43 lines
1.4 KiB
Python
Executable file
43 lines
1.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
|
|
def run_command(cmd, cwd=None):
|
|
subprocess.run(cmd, shell=True, check=True, cwd=cwd)
|
|
|
|
|
|
def main():
|
|
target = os.environ.get("OS_TARGET", "release")
|
|
if os.path.exists("img"):
|
|
shutil.rmtree("img")
|
|
os.makedirs("img/boot/efi/boot")
|
|
|
|
run_command("make -j4", cwd="lib/acpica-build")
|
|
|
|
components = ["init", "kernel", "loader"]
|
|
for component in components:
|
|
toolchain = "+x86_64-unknown-os"
|
|
if component == "kernel" or component == "loader":
|
|
toolchain = ""
|
|
cargo_cmd = f'cargo {toolchain} build {"--release" if target == "release" else ""}'
|
|
run_command(cargo_cmd, cwd=component)
|
|
|
|
loader_path = f"target/x86_64-unknown-uefi/{target}/loader.efi"
|
|
shutil.copy(loader_path, "img/boot/efi/boot/bootx64.efi")
|
|
|
|
os.chdir("img")
|
|
run_command("dd if=/dev/zero of=boot.img bs=1M count=16 status=none")
|
|
run_command("mformat -i boot.img")
|
|
run_command("mcopy -si boot.img boot/* ::")
|
|
|
|
run_command("dd if=/dev/zero of=os.img bs=1M count=32 status=none")
|
|
run_command("parted -s os.img mklabel gpt")
|
|
run_command("parted -s os.img mkpart primary fat32 2048s 100%")
|
|
run_command("parted -s os.img set 1 esp on")
|
|
run_command("dd if=boot.img of=os.img bs=1M seek=1 conv=notrunc status=none")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|