Files
c_soft/make_riscv.py

55 lines
1.1 KiB
Python
Raw Normal View History

2025-04-17 00:04:59 +08:00
import os
import sys
import time
import shutil
2025-04-17 00:04:59 +08:00
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/test.c",
2025-04-18 19:18:49 +08:00
"riscv/interrupt.c",
"riscv/start.S",
"riscv/trap.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"
OUTPUT="output"
2025-04-17 00:04:59 +08:00
if __name__ == "__main__":
if not os.path.exists(OUTPUT):
os.mkdir(OUTPUT)
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"{OBJCPY} -O ihex {TARGET}.elf {TARGET}.hex")
2025-04-17 11:14:53 +08:00
os.system(f"{OBJDUMP} -d {TARGET}.elf > {TARGET}.lst")
tagets_list=[f"{TARGET}.bin",f"{TARGET}.hex",f"{TARGET}.lst",f"{TARGET}.map",f"{TARGET}.elf"]
for item in tagets_list:
if os.path.exists(item):
shutil.move(item,f"{OUTPUT}/{item}")