Files
c_soft/make_riscv.py

95 lines
2.4 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"
]
2025-06-13 14:38:32 +08:00
INC=[
"-I./riscv/rtthread/libcpu/risc-v/common",
"-I./riscv/rtthread/include",
"-I./riscv/startup",
"-I./riscv/rtthread/components/drivers/include"
]
2025-04-17 00:04:59 +08:00
SRC=[
2025-06-13 14:38:32 +08:00
"riscv/startup/main.c",
"riscv/startup/test.c",
# "riscv/startup/interrupt.c",
"riscv/startup/start.S",
# "riscv/startup/trap.S",
"riscv/startup/rtthread_irq.c",
"riscv/rtthread/libcpu/risc-v/common/atomic_riscv.c",
"riscv/rtthread/libcpu/risc-v/common/context_gcc.S",
"riscv/rtthread/libcpu/risc-v/common/cpuport.c",
"riscv/rtthread/libcpu/risc-v/common/interrupt_gcc.S",
"riscv/rtthread/libcpu/risc-v/common/trap_common.c",
"riscv/rtthread/src/clock.c",
"riscv/rtthread/src/components.c",
"riscv/rtthread/src/cpu.c",
"riscv/rtthread/src/idle.c",
"riscv/rtthread/src/ipc.c",
"riscv/rtthread/src/irq.c",
"riscv/rtthread/src/kservice.c",
"riscv/rtthread/src/mem.c",
"riscv/rtthread/src/memheap.c",
"riscv/rtthread/src/mempool.c",
"riscv/rtthread/src/object.c",
"riscv/rtthread/src/scheduler_comm.c",
# "riscv/rtthread/src/scheduler_mp.c",
"riscv/rtthread/src/scheduler_up.c",
"riscv/rtthread/src/signal.c",
"riscv/rtthread/src/slab.c",
"riscv/rtthread/src/thread.c",
"riscv/rtthread/src/timer.c",
"riscv/rtthread/src/klibc/kstdio.c",
"riscv/rtthread/src/klibc/kstring.c",
"riscv/rtthread/components/drivers/core/device.c"
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-06-13 14:38:32 +08:00
cmd=f"{CC} {' '.join(CFLAG)} {' '.join(INC)} {' '.join(SRC)} -T{LD_FILE} -Wall -Wextra -nostartfiles -Wl,-Map,\"{TARGET}.map\" -o {TARGET}.elf"
print(cmd)
os.system(cmd)
2025-04-17 11:14:53 +08:00
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}")