SpinalHDL / openocd_riscv

Spen's Official OpenOCD Mirror
Other
47 stars 34 forks source link

Error when running openocd on Raspberry Pi 3B #3

Closed plex1 closed 5 years ago

plex1 commented 5 years ago

I am trying to run openocd on the Raspberry Pi 3B. Unfortunately I get a compilation error (see below). This problem can be overcome by removing the -Werror flag in the Makefile. Now, compilation and installation is successful. However when running the openocd executable I get a runtine error (see below at the end).

With a previous commit (a3421baa677c4ac1a1d4c0cb118e7187aeca6537) I do have the compilation problem but not the runtime error. So some changes between that commit and the current one (94655121c75ddc846e84fd86c580c324c5f55a22) must break the execution on my target.

Compilation Error:

pi@raspberrypi:~/raspice40/openocd_riscv $ make
...
...
ibtool: compile: gcc -DHAVE_CONFIG_H -I. -I./src -I./src -I./src/helper -DPKGDATADIR=\"/usr/local/share/openocd\" -DBINDIR=\"/usr/local/bin\" -I./jimtcl -I./jimtcl -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Werror -g -O2 -MT src/target/vexriscv.lo -MD -MP -MF src/target/.deps/vexriscv.Tpo -c src/target/vexriscv.c -o src/target/vexriscv.o
src/target/vexriscv.c: In function ‘vexriscv_network_write’:
src/target/vexriscv.c:841:5: error: cast increases required alignment of target type [-Werror=cast-align]
*((uint32_t *)(buffer + 2)) = address;
^
src/target/vexriscv.c:842:5: error: cast increases required alignment of target type [-Werror=cast-align]
*((uint32_t *)(buffer + 6)) = data;
^
src/target/vexriscv.c: In function ‘vexriscv_read_memory’:
src/target/vexriscv.c:1004:5: error: cast increases required alignment of target type [-Werror=cast-align]
((uint32_t*)buffer)[0] = 0;
^
src/target/vexriscv.c:1006:50: error: cast increases required alignment of target type [-Werror=cast-align]
vexriscv_readInstructionResult(target, false, (uint32_t*)buffer);
^
src/target/vexriscv.c:1009:5: error: cast increases required alignment of target type [-Werror=cast-align]
((uint16_t*)buffer)[0] = 0;
^
src/target/vexriscv.c:1011:52: error: cast increases required alignment of target type [-Werror=cast-align]
vexriscv_readInstructionResult16(target, false, (uint16_t*)buffer);
^
src/target/vexriscv.c: In function ‘vexriscv_write_memory’:
src/target/vexriscv.c:1067:31: error: cast increases required alignment of target type [-Werror=cast-align]
accesses[accessId].data = ((uint32_t*)buffer)[accessId];
^
src/target/vexriscv.c:1123:47: error: cast increases required alignment of target type [-Werror=cast-align]
vexriscv_write_regfile(target, false, 1,*((uint32_t*)buffer));
^
src/target/vexriscv.c:1128:47: error: cast increases required alignment of target type [-Werror=cast-align]
vexriscv_write_regfile(target, false, 1,*((uint16_t*)buffer));
^
src/target/vexriscv.c: In function ‘vexriscv_remove_breakpoint’:
src/target/vexriscv.c:1315:20: error: cast increases required alignment of target type [-Werror=cast-align]
uint32_t data = *((uint32_t*)breakpoint->orig_instr);
^
cc1: all warnings being treated as errors
Makefile:2864: recipe for target 'src/target/vexriscv.lo' failed
make[2]: *** [src/target/vexriscv.lo] Error 1
make[2]: Leaving directory '/home/pi/raspice40/openocd_riscv'
Makefile:3760: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/pi/raspice40/openocd_riscv'
Makefile:1616: recipe for target 'all' failed
make: *** [all] Error 2

Runtime Error

pi@raspberrypi:~/raspice40 $ sudo openocd_riscv/src/openocd -f /home/pi/raspice40/raspberrypi3-spinal.cfg -c "set MURAX_CPU0_YAML /home/pi/raspice40/cpu0.yaml" -f /home/pi/raspice40/openocd_riscv/tcl/target/murax.cfg
Open On-Chip Debugger 0.10.0+dev-00308-g94655121 (2018-12-22-15:22)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
BCM2835 GPIO config: tck = 19, tms = 16, tdi = 26, tdo = 20
BCM2835 GPIO config: srst = 21
srst_only separate srst_gates_jtag srst_push_pull connect_deassert_srst
/home/pi/raspice40/cpu0.yaml
adapter speed: 800 kHz
adapter_nsrst_delay: 260
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
jtag_ntrst_delay: 250
*** Error in `openocd_riscv/src/openocd': free(): invalid next size (fast): 0x015eab10 ***
Aborted
Dolu1990 commented 5 years ago

Hi,

I have a pi3 and have to give a try one it :)

Anyway, it look like the PI doesn't handle unaligned memory access properly. so fixing the compilation error could also fix the runtime errors.

Do you feel ready to fix it :D ?

plex1 commented 5 years ago

Hi,

Thanks for the reply. Yes changing all the unaligned memory accesses to aligned ones could also solve the runtime issue.

But on the other hand I don't understand why it worked with version a3421baa677c4ac1a1d4c0cb118e7187aeca6537. After disabling the compilation errors (remove -Werror in Makefile) I used that commit a year ago. And programming and debugging of the VexRiscv worked just fine.

Dolu1990 commented 5 years ago

Hi,

I think the issue is fixed now in the riscv_spinal branch. the memory missalignement should not be there anymore and the memory issue detected by valgrind are gone too.

Could you give a try ? Let's me know how it go :)

plex1 commented 5 years ago

Great. There was one more unaligned memory access which I had to fix. Please check my pull request if it is correct.

Dolu1990 commented 5 years ago

Merged, thanks :D

plex1 commented 5 years ago

Ok cool. I checked the newest version. And both issues I raised (compile and runtime error) are fixed now. Thanks for your help.