riscv-gnu-toolchain 使い方メモ
riscv-gnu-toolchain インストール方法
hexファイルの生成(FPGA書き込み用)
ソースコード準備
hoge.c ... C言語ファイル(今回の対象プログラム)
start.S ... アセンブリファイル(不要/未実装な初期化ルーチンを実行しないよう指定)
// riscv32-unknown-linux-gnu-gcc .section .text.init; .globl _start _start: call main
link.ld ... リンカスクリプト(命令を0番地から実行するよう指定)
// riscv64-unknown-elf-gcc SECTIONS { . = 0x00000000; .text : { *(.text) } }
or
// riscv32-unknown-linux-gnu-gcc OUTPUT_ARCH( "riscv" ) ENTRY(_start) SECTIONS { . = 0x00000000; .text.init : { *(.text.init) } .tohost : { *(.tohost) } .text : { *(.text) } .data : { *(.data) } .bss : { *(.bss) } _end = .; }
riscv64-unknown-elf-gcc 使用
// コンパイル riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o test.o test.c // リンク riscv64-unknown-elf-ld -b elf32-littleriscv test.o -T link.ld -o test // バイナリ生成 riscv64-unknown-elf-objcopy -O binary test test.bin // hex生成 od -An -tx4 -w4 -v test.bin > test.hex
riscv32-unknown-linux-gnu-gcc 使用
// コンパイル riscv32-unknown-linux-gnu-gcc -march=rv32id -c -o start.o start.S riscv32-unknown-linux-gnu-gcc -march=rv32id -c -o test.o test.c // リンク riscv32-unknown-linux-gnu-ld test.o start.o -L/opt/riscv32/riscv32-unknown-linux-gnu/lib/ -T link.ld -static -o test.elf // バイナリ生成 riscv32-unknown-linux-gnu-objcopy -O binary test.elf test.bin // hex生成 od -An -tx4 -w4 -v test.bin > test.hex
あとで追記するかも.
それでは.いろはにへとへと.