Files
c_soft/make_riscv.py

43 lines
747 B
Python
Raw Normal View History

2025-04-17 00:04:59 +08:00
import os
import sys
import time
CC="riscv64-unknown-elf-gcc"
2025-04-17 11:14:53 +08:00
OBJCPY="riscv64-unknown-elf-objcopy"
OBJDUMP="riscv64-unknown-elf-objdump"
2025-04-17 00:04:59 +08:00
CFLAG=[
"-march=rv32i",
"-mabi=ilp32",
"-ffunction-sections",
"-fdata-sections",
"-ffast-math",
"-fno-common",
"-fno-builtin-printf",
"-Wall",
"-Werror",
"-g",
2025-04-17 15:35:32 +08:00
"-O0",
2025-04-17 00:04:59 +08:00
"-fno-omit-frame-pointer",
"-msave-restore"
]
SRC=[
2025-04-17 11:14:53 +08:00
"riscv/main.c",
"riscv/start.S"
2025-04-17 00:04:59 +08:00
]
2025-04-17 11:14:53 +08:00
LD_FILE="riscv.ld"
2025-04-17 00:04:59 +08:00
TARGET="riscv"
if __name__ == "__main__":
2025-04-17 11:14:53 +08:00
os.system(f"{CC} {' '.join(CFLAG)} {' '.join(SRC)} -T{LD_FILE} -Wall -Wextra -nostartfiles -Wl,-Map,\"{TARGET}.map\" -o {TARGET}.elf")
os.system(f"{OBJCPY} -O binary {TARGET}.elf {TARGET}.bin")
os.system(f"{OBJDUMP} -d {TARGET}.elf > {TARGET}.lst")