Baremetal "Hello World"


(Greg Cieslewski) #1

Hi,

I am trying to get the baremetal “Hello World” example running on the HiFive Unleashed board.
In FreedomStudio I generate a “hello” example targeted at the sifive-hifive-unleashed board. Everything seems to compile correctly. The debug configuration is created correctly. I updated the jumpers to 0x0001. When I debug OpenOCD and GDB seem to connect but the breakpoint point at main() never gets triggered. When I pause the execution it seems that the PC is at 0x0.

When I was poking some more, it seemed to me that the SPI0 never got programmed.

Any one has any ideas?


(Greg Cieslewski) #2

I switched to testing this directly with freedom-e-sdk. And performed following steps:

make TARGET=sifive-hifive-unleashed PROGRAM=hello CONFIGURATION=debug clean
make TARGET=sifive-hifive-unleashed PROGRAM=hello CONFIGURATION=debug software
make TARGET=sifive-hifive-unleashed PROGRAM=hello CONFIGURATION=debug upload
make TARGET=sifive-hifive-unleashed PROGRAM=hello CONFIGURATION=debug debug

The temporary breakpoint at main is never reached. I proceeded to check if the elf was loaded correctly

(gdb) compare-sections
Section .init, range 0x20000000 -- 0x2000017e: MIS-MATCHED!
Section .text, range 0x20000180 -- 0x20003fe6: MIS-MATCHED!
Section .rodata, range 0x20003fe8 -- 0x20004858: MIS-MATCHED!
Section .init_array, range 0x20004858 -- 0x20004868: MIS-MATCHED!
Section .data, range 0x20004868 -- 0x20006db0: MIS-MATCHED!
warning: One or more sections of the target image does not match
the loaded file

I attached the Logic analyser to the SPI0 Flash (ISSI is25wp256d) and observed traffic during the upload command. It turns out that the flash does not gets erased.

I first attempted to update the openocd.cfg by adding the erase command:

flash protect 0 0 last off
flash erase_sector 0 0 16

That unfortunately did not work. After doing some more wave captures it seems to me that openocd uses erase command incorrectly. Openocd issues DCh commands but follows it only with 3 address bytes.

I finally booted into linux and executed

flash_erase /dev/mtd0 0 1024

That seemed to erase the flash correctly using the 21h command.
So now we repeat the upload (after reverting changes to openocd.cfg" and switching the jumpers)

make TARGET=sifive-hifive-unleashed PROGRAM=hello CONFIGURATION=debug upload
make TARGET=sifive-hifive-unleashed PROGRAM=hello CONFIGURATION=debug debug

and we get “Hello, World!”

and if we check if the elf is loaded correctly we get

(gdb) compare-sections
Section .init, range 0x20000000 -- 0x2000017e: matched.
Section .text, range 0x20000180 -- 0x20003954: matched.
Section .rodata, range 0x20003958 -- 0x20003d30: matched.
Section .init_array, range 0x20003d30 -- 0x20003d40: matched.
Section .data, range 0x20003d40 -- 0x20006288: matched.
(gdb)

Questions:

  1. Ideally, where the flash should get erased? Should this be done in openocd.cfg, gdb elsewhere?
  2. Is there a bug in openocd related to how it interfaces with this flash chip? Openocd complaints when executing commands
Info : Found flash device 'issi is25wp256d' (ID 0x0019709d)                                                          
Warn : device needs paging or 4-byte addresses - not implemented 
  1. Did I miss a step somewhere as to how I should load baremetal program?