如何从 C 代码和汇编代码 RISCV 生成十六进制文件
how to generate hex files from c code and assembly code RISCV
我有一些 C 代码/汇编代码,我想编译它并为 RISCV pulpissimo 生成 hex 文件。谁能帮我解决这个问题。
当前 运行 问候代码
#include <stdio.h>
int main()
{
printf("Hello !\n");
return 0;
}
使用命令 riscv32-unknown-elf-gcc 使用 riscv32 进行编译时 hello.c
出现这样的错误
RISCV/lib/gcc/riscv32-unknown-elf/7.1.1/../../../../riscv32-unknown-elf/bin/ld: cannot open linker script file riscv.ld: No such file or directory
collect2: error: ld returned 1 exit status
pulp 平台 git 存储库中有一个完美示例 boot code 可用于回答您的问题。由于我没有您正在使用的工具链,我使用的是从 bootlin 网站下载的工具链。
wget https://toolchains.bootlin.com/downloads/releases/toolchains/riscv32-ilp32d/tarballs/riscv32-ilp32d--glibc--bleeding-edge-2020.02-2.tar.bz2
mkdir -p /opt/bootlin
tar jxvf riscv32-ilp32d--glibc--bleeding-edge-2020.02-2.tar.bz2 -C /opt/bootlin
git clone git clone https://github.com/pulp-platform/boot-code
cd boot-code
编辑 Makefile
,并调整以下行以反映您正在使用的工具链的位置:
PULP_CC = riscv32-unknown-elf-gcc
PULP_LD = riscv32-unknown-elf-gcc
当使用 bootlin 工具链时,这将导致以下两行:
PULP_CC = /opt/bootlin/riscv32-ilp32d--glibc--bleeding-edge-2020.02-2/bin/riscv32-buildroot-linux-gnu-gcc
PULP_LD = /opt/bootlin/riscv32-ilp32d--glibc--bleeding-edge-2020.02-2/bin/riscv32-buildroot-linux-gnu-gcc
相同 Makefile
,替换以下行 - 代码未按我认为的方式编译:
CFLAGS += -Os -g -fno-jump-tables -I$(CURDIR)/include
作者:
CFLAGS += -Os -g -fno-jump-tables -I$(CURDIR)/include -DMCHAN_CMD_ILE_BIT=21 -DMCHAN_CMD_ELE_BIT=20
您现在可以构建 build/bootcode
可执行文件:
make
CC boot_code.c
In file included from /home/frant/mnt/git/boot-code/include/hal/chips/pulp/pulp.h:20,
from /home/frant/mnt/git/boot-code/include/hal/pulp.h:27,
from boot_code.c:18:
/home/frant/mnt/git/boot-code/include/hal/riscv/riscv_v5.h: In function ‘hal_cluster_id’:
/home/frant/mnt/git/boot-code/include/hal/riscv/riscv_v5.h:172:10: warning: implicit declaration of function ‘__builtin_pulp_ClusterId’ [-Wimplicit-function-declaration]
172 | return __builtin_pulp_ClusterId();
| ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/frant/mnt/git/boot-code/include/hal/chips/pulp/pulp.h:21,
from /home/frant/mnt/git/boot-code/include/hal/pulp.h:27,
from boot_code.c:18:
/home/frant/mnt/git/boot-code/include/hal/eu/eu_v3.h: In function ‘evt_read32’:
/home/frant/mnt/git/boot-code/include/hal/eu/eu_v3.h:43:11: warning: implicit declaration of function ‘__builtin_pulp_event_unit_read’ [-Wimplicit-function-declaration]
43 | value = __builtin_pulp_event_unit_read((int *)base, offset);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC crt0.S
LD /home/frant/mnt/git/boot-code/build/bootcode
./stim_utils.py \
--binary=/home/frant/mnt/git/boot-code/build/bootcode \
--stim-bin=rom.bin \
--area=0x1a000000:0x01000000
Created stimuli generator
Added binary: /home/frant/mnt/git/boot-code/build/bootcode
Added target area: [0x1a000000 -> 0x1b000000]
Handling section (base: 0x1a000000, size: 0x57c)
Bypassing section (base:make
CC boot_code.c
In file included from /home/frant/mnt/git/boot-code/include/hal/chips/pulp/pulp.h:20,
from /home/frant/mnt/git/boot-code/include/hal/pulp.h:27,
from boot_code.c:18:
/home/frant/mnt/git/boot-code/include/hal/riscv/riscv_v5.h: In function ‘hal_cluster_id’:
/home/frant/mnt/git/boot-code/include/hal/riscv/riscv_v5.h:172:10: warning: implicit declaration of function ‘__builtin_pulp_ClusterId’ [-Wimplicit-function-declaration]
172 | return __builtin_pulp_ClusterId();
| ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/frant/mnt/git/boot-code/include/hal/chips/pulp/pulp.h:21,
from /home/frant/mnt/git/boot-code/include/hal/pulp.h:27,
from boot_code.c:18:
/home/frant/mnt/git/boot-code/include/hal/eu/eu_v3.h: In function ‘evt_read32’:
/home/frant/mnt/git/boot-code/include/hal/eu/eu_v3.h:43:11: warning: implicit declaration of function ‘__builtin_pulp_event_unit_read’ [-Wimplicit-function-declaration]
43 | value = __builtin_pulp_event_unit_read((int *)base, offset);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC crt0.S
LD /home/frant/mnt/git/boot-code/build/bootcode
./stim_utils.py \
--binary=/home/frant/mnt/git/boot-code/build/bootcode \
--stim-bin=rom.bin \
--area=0x1a000000:0x01000000
Created stimuli generator
Added binary: /home/frant/mnt/git/boot-code/build/bootcode
Added target area: [0x1a000000 -> 0x1b000000]
Handling section (base: 0x1a000000, size: 0x57c)
Bypassing section (base: 0x1c000000, size: 0x1928)
objcopy --srec-len 1 --output-target=srec /home/frant/mnt/git/boot-code/build/bootcode /home/frant/mnt/git/boot-code/build/bootcode.s19
./s19toboot.py /home/frant/mnt/git/boot-code/build/bootcode.s19 boot_code.cde pulp 0x1c000000, size: 0x1928)
objcopy --srec-len 1 --output-target=srec /home/frant/mnt/git/boot-code/build/bootcode /home/frant/mnt/git/boot-code/build/bootcode.s19
./s19toboot.py /home/frant/mnt/git/boot-code/build/bootcode.s19 boot_code.cde pulp
并将其转换为 Intel Hex 格式:
/opt/bootlin/riscv32-ilp32d--glibc--bleeding-edge-2020.02-2/bin/riscv32-buildroot-linux-gnu-objcopy --output-target=ihex build/bootcode bootcode.ihex
cat bootcode.ihex
:020000041A00E0
:100000006F0080086F0040086F0000086F00C00795
:100010006F0080076F0040076F0000076F00C00689
../...
:081920000000000000000000BF
:040000051A000000DD
:00000001FF
现在你已经有了一个我认为是你目标的 pulp 平台的工作示例,你应该能够根据你的需要调整它。
我有一些 C 代码/汇编代码,我想编译它并为 RISCV pulpissimo 生成 hex 文件。谁能帮我解决这个问题。 当前 运行 问候代码
#include <stdio.h>
int main()
{
printf("Hello !\n");
return 0;
}
使用命令 riscv32-unknown-elf-gcc 使用 riscv32 进行编译时 hello.c
出现这样的错误
RISCV/lib/gcc/riscv32-unknown-elf/7.1.1/../../../../riscv32-unknown-elf/bin/ld: cannot open linker script file riscv.ld: No such file or directory
collect2: error: ld returned 1 exit status
pulp 平台 git 存储库中有一个完美示例 boot code 可用于回答您的问题。由于我没有您正在使用的工具链,我使用的是从 bootlin 网站下载的工具链。
wget https://toolchains.bootlin.com/downloads/releases/toolchains/riscv32-ilp32d/tarballs/riscv32-ilp32d--glibc--bleeding-edge-2020.02-2.tar.bz2
mkdir -p /opt/bootlin
tar jxvf riscv32-ilp32d--glibc--bleeding-edge-2020.02-2.tar.bz2 -C /opt/bootlin
git clone git clone https://github.com/pulp-platform/boot-code
cd boot-code
编辑 Makefile
,并调整以下行以反映您正在使用的工具链的位置:
PULP_CC = riscv32-unknown-elf-gcc
PULP_LD = riscv32-unknown-elf-gcc
当使用 bootlin 工具链时,这将导致以下两行:
PULP_CC = /opt/bootlin/riscv32-ilp32d--glibc--bleeding-edge-2020.02-2/bin/riscv32-buildroot-linux-gnu-gcc
PULP_LD = /opt/bootlin/riscv32-ilp32d--glibc--bleeding-edge-2020.02-2/bin/riscv32-buildroot-linux-gnu-gcc
相同 Makefile
,替换以下行 - 代码未按我认为的方式编译:
CFLAGS += -Os -g -fno-jump-tables -I$(CURDIR)/include
作者:
CFLAGS += -Os -g -fno-jump-tables -I$(CURDIR)/include -DMCHAN_CMD_ILE_BIT=21 -DMCHAN_CMD_ELE_BIT=20
您现在可以构建 build/bootcode
可执行文件:
make
CC boot_code.c
In file included from /home/frant/mnt/git/boot-code/include/hal/chips/pulp/pulp.h:20,
from /home/frant/mnt/git/boot-code/include/hal/pulp.h:27,
from boot_code.c:18:
/home/frant/mnt/git/boot-code/include/hal/riscv/riscv_v5.h: In function ‘hal_cluster_id’:
/home/frant/mnt/git/boot-code/include/hal/riscv/riscv_v5.h:172:10: warning: implicit declaration of function ‘__builtin_pulp_ClusterId’ [-Wimplicit-function-declaration]
172 | return __builtin_pulp_ClusterId();
| ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/frant/mnt/git/boot-code/include/hal/chips/pulp/pulp.h:21,
from /home/frant/mnt/git/boot-code/include/hal/pulp.h:27,
from boot_code.c:18:
/home/frant/mnt/git/boot-code/include/hal/eu/eu_v3.h: In function ‘evt_read32’:
/home/frant/mnt/git/boot-code/include/hal/eu/eu_v3.h:43:11: warning: implicit declaration of function ‘__builtin_pulp_event_unit_read’ [-Wimplicit-function-declaration]
43 | value = __builtin_pulp_event_unit_read((int *)base, offset);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC crt0.S
LD /home/frant/mnt/git/boot-code/build/bootcode
./stim_utils.py \
--binary=/home/frant/mnt/git/boot-code/build/bootcode \
--stim-bin=rom.bin \
--area=0x1a000000:0x01000000
Created stimuli generator
Added binary: /home/frant/mnt/git/boot-code/build/bootcode
Added target area: [0x1a000000 -> 0x1b000000]
Handling section (base: 0x1a000000, size: 0x57c)
Bypassing section (base:make
CC boot_code.c
In file included from /home/frant/mnt/git/boot-code/include/hal/chips/pulp/pulp.h:20,
from /home/frant/mnt/git/boot-code/include/hal/pulp.h:27,
from boot_code.c:18:
/home/frant/mnt/git/boot-code/include/hal/riscv/riscv_v5.h: In function ‘hal_cluster_id’:
/home/frant/mnt/git/boot-code/include/hal/riscv/riscv_v5.h:172:10: warning: implicit declaration of function ‘__builtin_pulp_ClusterId’ [-Wimplicit-function-declaration]
172 | return __builtin_pulp_ClusterId();
| ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/frant/mnt/git/boot-code/include/hal/chips/pulp/pulp.h:21,
from /home/frant/mnt/git/boot-code/include/hal/pulp.h:27,
from boot_code.c:18:
/home/frant/mnt/git/boot-code/include/hal/eu/eu_v3.h: In function ‘evt_read32’:
/home/frant/mnt/git/boot-code/include/hal/eu/eu_v3.h:43:11: warning: implicit declaration of function ‘__builtin_pulp_event_unit_read’ [-Wimplicit-function-declaration]
43 | value = __builtin_pulp_event_unit_read((int *)base, offset);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC crt0.S
LD /home/frant/mnt/git/boot-code/build/bootcode
./stim_utils.py \
--binary=/home/frant/mnt/git/boot-code/build/bootcode \
--stim-bin=rom.bin \
--area=0x1a000000:0x01000000
Created stimuli generator
Added binary: /home/frant/mnt/git/boot-code/build/bootcode
Added target area: [0x1a000000 -> 0x1b000000]
Handling section (base: 0x1a000000, size: 0x57c)
Bypassing section (base: 0x1c000000, size: 0x1928)
objcopy --srec-len 1 --output-target=srec /home/frant/mnt/git/boot-code/build/bootcode /home/frant/mnt/git/boot-code/build/bootcode.s19
./s19toboot.py /home/frant/mnt/git/boot-code/build/bootcode.s19 boot_code.cde pulp 0x1c000000, size: 0x1928)
objcopy --srec-len 1 --output-target=srec /home/frant/mnt/git/boot-code/build/bootcode /home/frant/mnt/git/boot-code/build/bootcode.s19
./s19toboot.py /home/frant/mnt/git/boot-code/build/bootcode.s19 boot_code.cde pulp
并将其转换为 Intel Hex 格式:
/opt/bootlin/riscv32-ilp32d--glibc--bleeding-edge-2020.02-2/bin/riscv32-buildroot-linux-gnu-objcopy --output-target=ihex build/bootcode bootcode.ihex
cat bootcode.ihex
:020000041A00E0
:100000006F0080086F0040086F0000086F00C00795
:100010006F0080076F0040076F0000076F00C00689
../...
:081920000000000000000000BF
:040000051A000000DD
:00000001FF
现在你已经有了一个我认为是你目标的 pulp 平台的工作示例,你应该能够根据你的需要调整它。