vivado-risc-v icon indicating copy to clipboard operation
vivado-risc-v copied to clipboard

Baremetal program upload

Open svpolonsky opened this issue 2 years ago • 5 comments

Hi Eugene,

I play with uploading my own baremetal program to your RISC-V@FPGA Your documentation suggest that I

Copy boot.elf to the SD card

I do this manually: unplug FPGA board, put SD card into cardreader, connect the cardreader it to USB, etc.. This is time-consuming.

I wonder if I can update boot.elf on SD card while my FPGA board is connected to the host computer via USB. I use Digilent Artix-7 100T.

Thanks in advance, Stas

svpolonsky avatar Jun 22 '22 16:06 svpolonsky

No, you cannot update boot.elf on SD card over USB while the card is inserted in the board slot. However, you can upload boot.elf directly into RISC-V memory and run it using Xilinx debugger - XSDB. With this workflow, you don't need SD card. For example, in XSDB:

xsdb% connect
tcfchan#0
xsdb% targets -set -filter {name =~ "Hart #0*"}
xsdb% dow -clear E:/admin/sd-test/boot.elf
Downloading Program -- E:/admin/sd-test/boot.elf
        section, .text: 0x80000000 - 0x8000b05f
        section, .data: 0x8000b060 - 0x8000b06f
        section, .bss: 0x8000b070 - 0x8000ffbf
100%    0MB   0.4MB/s  00:00
Setting PC to Program Start Address 0x80000008
Successfully downloaded E:/admin/sd-test/boot.elf
xsdb% con
Info: Hart #0 (target 3) Running
xsdb%

eugene-tarassov avatar Jun 22 '22 17:06 eugene-tarassov

Great! That's what I need!

svpolonsky avatar Jun 22 '22 18:06 svpolonsky

One more thing, Eugene. I understand it's not directly related to your project, but I ask in hope you have a short and fast answer, as always) When I use malloc(), the linker gives me the error: malloc.c:(.text+0x0): relocation truncated to fit: R_RISCV_HI20 I did some search on this error, and I believe I should recompile the runtime libc.a with some "right" flags. Right?

svpolonsky avatar Jun 27 '22 17:06 svpolonsky

A standard libc needs an OS for things like memory allocation, so it will not work on bare metal. You either add your own implementation of malloc() to your project, or search for a special "bare metal" or "embedded" libc. At the moment, I don't have a recommendation for embedded RISC-V libc.

Even with "embedded" libc, it is still up to you to implement low-level memory management, file system, networking, multi-threading, etc.

eugene-tarassov avatar Jun 27 '22 20:06 eugene-tarassov

Thanks, Eugene!

svpolonsky avatar Jun 27 '22 20:06 svpolonsky