Where to find the risc-v default linker script?

Most welcome @bsvtgc Vincent, glad it helps. Great little code example and disassembly you’ve tested. Sure, nothing bad will happen, especially if it only loads to ram – power off, reset, or unplug and it’s back to “normal”. I do this all the time.

After, or in place of your “dummy” instruction, you might want to put a forever loop with

j . ;# or, jal x0, .

so that the core stops in its tracks and doesn’t try to execute unknown code at unknown places.

I’ve never had a HiFive board, and have never used the Freedom GUI toolchain package, so I am not much the expert there but am confident nothing bad will happen. I have and use the LoFive board; and for debugger interfaces both the Raspberry Pi (bitbang jtag) and the FTDI FT(2)232H chip (Olimex, etc).

You might wish to revise your openocd “.cfg” file with some of my suggestions. The HiFive has a built-in J-Link USB device, so only “interface” (or, lately, called “adapter”) section is probably different.

As long as you use load_image and not flash write_image (or equiv. flash submodules) then you’ll be fine and not touch the rom chip contents.

Let me repeat this critical point: For ram-only work, comment out, or remove, any and all lines beginning with “flash”, such as

# flash bank ...
# flash protect ...
# flash erase ...
# flash write_image ...

or even the helper script, if it exists in your .cfg,

# program ...

A handy openocd reference is OpenOCD Command Reference in case you’re interested.


I have encapsulated all necessary steps into a single [tcl] procedure, asic_ram_load, which you would invoke like so:

openocd -f fe310-g002.cfg -c "adapter speed 2000" -c init -c "asic_ram_load my_prog" -c shutdown -c exit

where my_prog is whatever is the name of your binary file. Change lines 150 and 151 if you don’t put the “-ram” suffix on your filename, or use another format beside “bin”.

I am not sure how the jlink chip on the HiFive board (schematic, sheet 4, U3-64, PTD7) handles reset; thus, you might only want to take my high level procedures in the “APPLICATIONS” section at the bottom. Further work to check and revise lines 78-81 whether jlink uses trst, srst, or some other hardware signal. For now, keeping all the command handlers as-is, un-overridden, gives benefit of doubt.

You might like to keep hardware interface specific stuff (such as the adapter driver jlink statement; see tips on HiFive connection for suggestions) in another config file. If so, you would invoke like so:

openocd -f hifive-rev-b.cfg -f fe310-g002.cfg ...

Just make sure that the first .cfg file doesn’t have any init statement; it should be put in only at the right sequence, such as at the command line:

  1. hardware-specific-interface-stuff
  2. target-specific-stuff
  3. speed
  4. init
  5. high-level-application-command
  6. shutdown
  7. exit
    For interactive gdb sessions, omit 6 and 7.