How to generate a hex file in RISC-V

帅比萌擦擦* 提交于 2021-02-10 05:32:26

问题


Now, I'm implemented an ASP (Application Specific Processor) and I want to develop it with an RISC-type architecture. Reading a bit on the web, I concluded that the best option is to use RISC-V.

The idea is to develop a design in Verilog so that it can run the RISC-V ISA. And the software application that the processor should run is very simple, only a few arithmetic operations. For this reason as it is only one application it is not necessary that the processor supports an operating system.

I'm thinking of generating a hex file from my C application and loading the file into a ROM memory. But I could not find how I can generate the hex file from my code in C?

I built correctly my program with riscv64-unknown-elf-gcc

$ riscv64-unknown-elf-gcc -o hello hello.c

But I don't know how to generate a hex file.

Could someone tell me how can I create this file?


回答1:


You can use the program elf2hex, which is installed when building the RISC-V toolchain. You can see an example of generating hex files in the riscv-tests/benchmark repository's Makefile (https://github.com/riscv/riscv-tests/blob/master/benchmarks/Makefile):

%.hex: %
    elf2hex 16 32768 $< > $@

And the usage:

elf2hex <width> <depth> <elf_file>


来源:https://stackoverflow.com/questions/31321469/how-to-generate-a-hex-file-in-risc-v

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!