# Build and debug with toolchain

**URL:** <https://forums.sifive.com/t/build-and-debug-with-toolchain/6319>\
**Category:** HiFive1 Rev B\
**Created:** [October 30, 2023, 6:18pm UTC](https://forums.sifive.com/t/build-and-debug-with-toolchain/6319 "2023-10-30T18:18:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jahro\_me](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jahro\_me](https://forums.sifive.com/u/jahro_me)\
**Post date:** [October 30, 2023, 6:18pm UTC](https://forums.sifive.com/t/build-and-debug-with-toolchain/6319/1 "2023-10-30T18:18:48Z")

</div>

Hello,

I am starting over with the HiFive 1 Rev B. I want to learn Assembly, C and Rust with this board and I want to have it down seriously. But I am a complete noob even when it comes to building a simple “Hello world!” I have already tried Freedom Studio and SEGGER Embedded Studio. Both are fine, but I want to use the toolchain only,

I am using Debian bookworm and these are the steps I have performed.  
I have installed [SEGGER - The Embedded Experts - Downloads](https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb)  
extracted the toolchain to $HOME/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86\_64-linux-ubuntu14/ and added this bin path to $PATH  
I could get [GitHub - riscv-rust/riscv-rust-quickstart: A template for building Rust applications for HiFive1 boards](https://github.com/riscv-rust/riscv-rust-quickstart) to run, but i don’t know, how to build and run a simple “Hello world” in C on the device. Any help would be appreciated!

When I execute “riscv64-unknown-elf-gcc -march=rv32imac -mabi=ilp32 main.c” on

> #include \<stdio.h\>  
> #include \<stdlib.h\>
> 
> int main(void) {  
> printf(“Hello, world!\n”);  
> return 0;  
> }

i get the a.out file. Executing it exec: Failed to execute process: ‘./a.out’ the file could not be run by the operating system.

The debugger is running in another terminal with  
JLinkGDBServer -device FE310 -if JTAG -speed 4000 -port 3333 -nogui  
and another one has cat \< /dev/ttyACM0, which shows the SiFive logo.

How can I get my program to run on the device? Please help.

---

<div class="post-metadata">

**Author:** ![Boris\_SiFive](https://avatars.discourse-cdn.com/v4/letter/b/7993a0/32.png) [@Boris\_SiFive](https://forums.sifive.com/u/Boris_SiFive)\
**Post date:** [November 2, 2023, 9:00pm UTC](https://forums.sifive.com/t/build-and-debug-with-toolchain/6319/2 "2023-11-02T21:00:59Z")

</div>

Hello @jahro_me

The easiest way to run C and Assembly programs is by using SiFive Freedom Studio IDE. This is the recommended way to start with the board development.  
Alternatively, you can use Freedom-E-SDK with the command line toolchain.  
Please refer to section “7.3 Software Development Using Freedom E SDK Command  
Line Tools” in SiFive HiFive1 Rev B Getting Started Guide for more details:  
[https://www.sifive.com/document-file/hifive1b-getting-started-guide](https://www.sifive.com/document-file/hifive1b-getting-started-guide)

---

<div class="post-metadata">

**Author:** ![pds](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pds](https://forums.sifive.com/u/pds)\
**Post date:** [November 4, 2023, 7:26am UTC](https://forums.sifive.com/t/build-and-debug-with-toolchain/6319/3 "2023-11-04T07:26:28Z")

</div>

Perhaps the smallest (and simplest) toolchain in the world, @jahro_me, is `riscv.mk` shown by way of example in my [Demonstrating AMO](https://github.com/psherman42/Demonstrating-AMO) repo.

Revise a few lines at the top of the `.mk` file and you can compile, assemble, link, load, and even debug with one command:

```auto
make -f riscv.mk ramload

```

Of course, use _ramrun_ to start the target running; or the _rom…_ equivalents to load and run from Flash. Memory map physical layout is in the `.lds` linker definition script files.

You’ll also need to customize (and copy/paste) the few lines to define your source files, whether asm’s, c’s, etc.

For details on building your toolchain applications (I use `openocd` for the loader) from source, you can see my notes at [RISC-V Easy As PI](https://github.com/psherman42/riscv-easy-as-pi).

An overview and refresher of RISC-V concepts is in the [JCSSE Hands-on Workshop](http://192.142.160.4/~sherman/rvt/JCSSE2023-HOW-NU4YOU-RISCV_Sherman-20230713.pdf) – it’s on my [www.riscvthai.org](http://www.riscvthai.org) site.  
User name: _paul_  
Password: _paul_

Let me know how goes 🙂
