Deploy C executable on PetaLinux for Rocket Chip on Zynq FPGA

1k views Asked by At

I'm currently trying to deploy an application (simple c program) to the Zynq ZedBoard. I followed the Rocket Chip on Zynq FPGAs github page to generate all the necessary files, put them on a SD card and boot PetaLinux.

In the tutorial, a pre-packed hello application can be executed after booting

root@zynq:~# ./fesvr-zynq pk hello
hello!

I successfully managed to get to this point. However, i'm wondering how i can deploy my own c code to an executable that will appear in the internal filesystem like the hello one above.

1

There are 1 answers

0
mtosch On BEST ANSWER

Thanks @user3528438 for giving me the right hint. I'm writing this for future reference.

I was able to deploy and execute my own C application by doing the following:


Write my own C code i want to execute on the Rocket Chip.

#include <stdio.h>
int main(void) {
    printf("Hello Rocket!\n");
    return 0;
}

Compile the code for the riscv architecture and generate executable. This requires the riscv toolchain to be installed of course!

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

Copy the generated myhello executable on your sd card that you insert in the ZedBoard.

Turn on the ZedBoard and login.

Mount the sd card to be able to access your myhello executable.

$ mkdir /sdcard
$ mount /dev/mmcblk0p1 /sdcard

Change to the /sdcard directory and copy your executable to the /home/root directory. (This is where you find the standard hello executable)

$ cd ../../sdcard
$ cp myhello /home/root

Switch back to the /home/root directory and execute your myhello file on the Rocket Chip via the frontend-server!

$ ./fesvr-zynq pk myhello

This prints the expected output to the console.

Hello Rocket!