簡體   English   中英

如何從 c 代碼和匯編代碼 RISCV 生成 hex 文件

[英]how to generate hex files from c code and assembly code RISCV

我有一些 C 代碼/匯編代碼,我想編譯它並為 RISCV 漿糊生成十六進制文件。 任何人都可以幫助我完成此步驟。 當前運行 hello 代碼

#include <stdio.h>

int main()
{
  printf("Hello !\n");

  return 0;
}

在使用 riscv32 編譯時使用命令 riscv32-unknown-elf-gcc 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

git存儲庫中有一個完美的示例,可用於回答您的問題。 由於我沒有您正在使用的工具鏈,因此我使用的是從 bootlin web 站點下載的工具鏈。

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

現在您已經有了一個我認為是您的目標的紙漿平台的工作示例,您應該能夠根據您的需求對其進行調整。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM