You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB
Python

#!/usr/bin/env python3
# DISCLAIMER: I don't know python. And i don't like python.
# This is only written in python because pretty much everyone already has it
# installed and rust doesn't support post-build scripts for some reason.
import sys
from utils import crc32, run_sync
if len(sys.argv) >= 2:
PROFILE = sys.argv[1]
else:
PROFILE = "debug"
def finalize_stage1(filename: str):
run_sync(
"objcopy", "-O", "binary",
"target/x86-pc-none/" + PROFILE + "/bussy-stage1",
filename
)
with open(filename, "r+b") as file:
data = bytearray(file.read())
size = len(data)
if size > 0x8000:
print("stage1 is too big (greater than 32 K)")
exit(1)
data[2] = size & 0xff
data[3] = size >> 8
csum = crc32(data)
print("CRC32 checksum of stage1 is " + hex(csum))
data[4] = csum & 0xff
data[5] = (csum >> 8) & 0xff
data[6] = (csum >> 16) & 0xff
data[7] = csum >> 24
file.seek(2)
file.write(data[2:8])
print("Running cargo")
if PROFILE == "debug":
run_sync("cargo", "build", "--workspace")
elif PROFILE == "release":
run_sync("cargo", "build", "--workspace", "--release")
else:
run_sync("cargo", "build", "--workspace", "--profile", PROFILE)
print("Finalizing stage1")
finalize_stage1("target/x86-pc-none/" + PROFILE + "/stage1.bin")