-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_test.sh
More file actions
executable file
·57 lines (43 loc) · 1.68 KB
/
Copy pathbuild_test.sh
File metadata and controls
executable file
·57 lines (43 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
set -e
GCC="./xpack-riscv-none-elf-gcc-15.2.0-1/bin/riscv-none-elf-gcc"
AS="./xpack-riscv-none-elf-gcc-15.2.0-1/bin/riscv-none-elf-as"
OBJCOPY="./xpack-riscv-none-elf-gcc-15.2.0-1/bin/riscv-none-elf-objcopy"
SRC_CRT0="./test/crt0.s"
SRC_SYSCALLS="./test/syscalls.c"
SRC_DEBUG="./test/debug.c"
SRC_MEMTEST="./test/memtest.c"
SRC_TEST="./test/test.c"
LDSCRIPT="./test/linker.ld"
OBJ_CRT0="/tmp/crt0.o"
OBJ_SYSCALLS="/tmp/syscalls.o"
OBJ_DEBUG="/tmp/debug.o"
OBJ_MEMTEST="/tmp/memtest.o"
OBJ_TEST="/tmp/test.o"
ELF="/tmp/test_out.elf"
BIN="/tmp/test_out.bin"
echo "Assembling crt0..."
$AS -march=rv32i -mabi=ilp32 "$SRC_CRT0" -o "$OBJ_CRT0"
echo "Compiling syscalls..."
$GCC -c -O1 -march=rv32i -mabi=ilp32 "$SRC_SYSCALLS" -o "$OBJ_SYSCALLS"
echo "Compiling debug..."
$GCC -c -O1 -march=rv32i -mabi=ilp32 "$SRC_DEBUG" -o "$OBJ_DEBUG"
echo "Compiling memtest..."
$GCC -c -O1 -march=rv32i -mabi=ilp32 "$SRC_MEMTEST" -o "$OBJ_MEMTEST"
echo "Compiling test..."
$GCC -c -O1 -fno-builtin-printf -fno-builtin-puts -march=rv32i -mabi=ilp32 "$SRC_TEST" -o "$OBJ_TEST"
echo "Linking (with newlib via -lc -lgcc)..."
$GCC -march=rv32i -mabi=ilp32 -nostartfiles \
-T "$LDSCRIPT" \
-o "$ELF" "$OBJ_CRT0" "$OBJ_SYSCALLS" "$OBJ_DEBUG" "$OBJ_MEMTEST" "$OBJ_TEST" -lc -lgcc
echo "Converting to binary..."
$OBJCOPY -O binary "$ELF" "$BIN"
echo "Converting to hex..."
python convert.py "$BIN"
cp "${BIN%.bin}.hex" ./last_test_build.hex
echo "Saved a copy of the hex for inspection: ./last_test_build.hex"
echo "Loading program..."
python load_program.py "${BIN%.bin}.hex" --port /dev/ttyUSB1
echo "Cleaning up..."
rm -f "$OBJ_CRT0" "$OBJ_SYSCALLS" "$OBJ_DEBUG" "$OBJ_MEMTEST" "$OBJ_TEST" "$ELF" "$BIN"
echo "Done."