Zephyr RTOS HIFIVE!


(Daniel kirubakaran) #1

Anybody worked with zephyr?
i tried a sample ‘helloworld’ program for hifive1.
I am getting error in terms of zephyr version and some CMake error also.


(Daniel kirubakaran) #2

Can some one tell me the step by step procedure?
i am following the Zephyr getting started guide ,but i dont know how to execute from BUILD THE APPLICATION FOR HIFIVE1 !
i read the specific board document also.I want to run basic hello world program.


(Drew) #3

We have published a blog on Zephyr last week which includes a step-by-step:

If you are still having trouble, please let us know.


(Daniel kirubakaran) #4

Great, I ll go through it.
Thank you.


(Daniel kirubakaran) #5

I got successful result for qemu_riscv32
i am trying it for Hifive1 now…

when i run this command,

Run this command to load the program onto the HiFive 1:

$ gdb zephyr.elf --batch -ex 'set remotetimeout 240' \ -ex 'target extended-remote localhost:3333' \ -ex 'monitor reset halt' -ex 'monitor flash protect 0 64 last off' \ -ex 'load' -ex 'monitor resume'

It gives me the error like

maxvy04@maxvy04-OptiPlex-780:~/zephyr/samples/hello_world/build/zephyr$ gdb zephyr.elf --batch -ex ‘set remotetimeout 240’ \ -ex ‘target extended-remote localhost:3333’ \ -ex ‘monitor reset halt’ -ex ‘monitor flash protect 0 64 last off’ \ -ex ‘load’ -ex 'monitor resume’
Excess command line arguments ignored. (target extended-remote localhost:3333 …)
/home/maxvy04/zephyr/samples/hello_world/build/zephyr/ -ex: No such file or directory.
“monitor” command not supported by this target.
“monitor” command not supported by this target.

what could be the issue?


(Daniel kirubakaran) #6

And some minor changes are need to be made,because i faced some errors due to that.
It will be helpful for the beginners,i guess.

1.$ source zephyr-env.sh to $ source zephyr_env.sh
2.-DBOARD=hifive1 to -DBOARD=hifive1 …(only two dots)


(Nate Graff) #7

First off, thanks Daniel for finding my typos, and I apologize for not being able to catch them prior to publication.

Among them, one of the problems you might be having is that I failed to specify that you should use the GDB from the RISC-V toolchain, probably named riscv64-unknown-elf-gdb on your system.


(Daniel kirubakaran) #8

Yes i did it actually !
And what i actually understood from the following statement from the blog is

“Once you’ve installed the GNU embedded toolchain and OpenOCD, grab a copy of the OpenOCD configuration file for the HiFive1.”

I have downloaded these two , when i searched for openocd.cfg in the OpenOCD toolchain folder it was not there so i made a file in the name of openocd.cfg and copied “that copy of openocd configuration for Hifive1” and then i have put it into the
riscv-openocd-20181030-x86_64-linux-ubuntu14/bin folder.Am i right?
correct me if i am wrong.

Because now i am able to run …/bin:~$ ./openocd
previously i couldn’t run for this command openocd -f openocd.cfg

Then after following everything i am still facing a trouble while running this command

$ gdb zephyr.elf --batch -ex ‘set remotetimeout 240’ \ -ex ‘target extended-remote localhost:3333’ \ -ex ‘monitor reset halt’ -ex ‘monitor flash protect 0 64 last off’ \ -ex ‘load’ -ex ‘monitor resume’

I had mentioned the errors in previous replies.


(Nate Graff) #9

Putting the configuration in the same folder as the openocd executable should be fine. I usually add the executable to my PATH so I don’t have to think about where it is and then just put the openocd.cfg in whatever folder is most convenient for me.

Try removing the backslashes (’\’) from your command. I had them there because when I wrote the post in markdown they were intended to show that the command spanned line breaks, but it looks like that got messed up when the text got reflowed in HTML.


(Daniel kirubakaran) #10

I am sorry, still i am getting this error.

maxvy04@maxvy04-OptiPlex-780:~/zephyr/samples/hello_world/build/zephyr$ gdb zephyr.elf --batch -ex ‘set remotetimeout 240’ -ex ‘target extended-remote localhost:3333’ -ex ‘monitor reset halt’ -ex ‘monitor flash protect 0 64 last off’ -ex ‘load’ -ex ‘monitor resume’
warning: Architecture rejected target-supplied description
Truncated register 22 in remote ‘g’ packet
"monitor" command not supported by this target.
“monitor” command not supported by this target.
You can’t do that when your target is `exec’
“monitor” command not supported by this target.

Iremoved those back slashes as you said.


(Nate Graff) #11

I think your issue might be that you’re not using the riscv64-unknown-elf-gdb executable from the RISC-V toolchain. Try explicitly calling the executable with its full path:

$ /path/to/your/riscv64-unknown-elf-gcc-20181030-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gdb zephyr.elf --batch -ex “set remotetimeout 240” -ex “target extended-remote localhost:3333” -ex “monitor reset halt” -ex “monitor flash protect 0 64 last off” -ex “load” -ex “monitor resume”


(Daniel kirubakaran) #12

Oops! then that’s my mistake only !
Thanks Nate,

Well, i tried with proper command ,i am not getting the previous errors so the command worked properly i guess.But the code is not properly loaded why?

like this,
halted at 0x2040114a due to debug interrupt
cleared protection for sectors 64 through 255 on flash bank 0
Loading section vector, size 0x41c lma 0x1000
Loading section reset, size 0x4 lma 0x80000000
Load failed
Can’t detach process.

Then i deleted everything ,started from the beginning
This time HelloWorld using qemu emulator also showing error

Scanning dependencies of target run
**[100%] **
To exit from QEMU enter: ‘CTRL+a, x’
[QEMU] CPU: riscv32
qemu-system-riscv32: -nographic: unsupported machine type
Use -machine help to list supported machines
zephyr/CMakeFiles/run.dir/build.make:57: recipe for target ‘zephyr/CMakeFiles/run’ failed
make[3]: *** [zephyr/CMakeFiles/run] Error 1
CMakeFiles/Makefile2:376: recipe for target ‘zephyr/CMakeFiles/run.dir/all’ failed
make[2]: *** [zephyr/CMakeFiles/run.dir/all] Error 2
CMakeFiles/Makefile2:383: recipe for target ‘zephyr/CMakeFiles/run.dir/rule’ failed
make[1]: *** [zephyr/CMakeFiles/run.dir/rule] Error 2
Makefile:209: recipe for target ‘run’ failed
make: *** [run] Error 2

last time i had problem with using Hifive1 board alone,which was my mistake, i didn’t give the proper command .

Please help me out.

Thank you.


(Nate Graff) #13

The load to HiFive1 is failing because the offsets are wrong. If the Zephyr ELF is built correctly you should see it trying to load in the ~0x2040xxxx region:

Loading section vector, size 0x10 lma 0x20400000
Loading section exceptions, size 0x268 lma 0x20400010
Loading section text, size 0x2bd4 lma 0x20400278
Loading section devconfig, size 0x60 lma 0x20402e4c
Loading section log_const_sections, size 0x8 lma 0x20402eac
Loading section rodata, size 0x560 lma 0x20402eb4
Loading section datas, size 0x18 lma 0x20403414
Loading section initlevel, size 0x60 lma 0x2040342c

In your case the reset section is being loaded at 0x80000000, which isn’t in the region of memory mapped to the SPI flash.

One gotcha when developing a Zephyr app is that if you don’t completely clean the build sources when switching targets it doesn’t properly switch target configurations. So if you’ve built for qemu_riscv32, you’ll need to completely clean your build directory and re-run cmake. From .../zephyr/samples/hello_world/build run:

$ make pristine
$ cmake -DBOARD=hifive1 ..
$ make -j$(nproc)

At that point you should be able to flash the board with the resulting zephyr.elf. You’ll need to run make pristine and cmake -DBOARD=qemu_riscv32 again if you want to build for qemu_riscv32.

For the QEMU simulation failure, you probably hit the issue uncovered in this forum post. Long story short, in order to simulate qemu_riscv32 using the Zephyr SDK-packaged QEMU, you need Zephyr SDK 0.9.3.

Thank you for your patience working through these problems.


(Daniel kirubakaran) #14

Finally ! it worked.In both qemu and hifive1 board.
Thank you so much Nate , for explaining me patiently and you had already mentioned in the blog

For Zephyr v1.13.0, install SDK version 0.9.3, not a newer release like 0.9.4 or 0.9.5,

but sometimes we humans fail to notice some most important things in just a single glance! likewise i did unknowingly.

And you gave me another answer for my unasked doubt "make pristine"
because when i wanted to change the targets, i had to delete everything right from the zephyr git cloning.I was about to ask this doubt to you.My goodness! you have given me at right time.

Anyways thanks a lot Nate.


(Nate Graff) #15

I’m quite happy to help, and I’m very glad that you got it working!

Thank you for helping me improve my blog post so more people have an easier time getting started with Zephyr!