sifive / freedom-tools

Tools for SiFive's Freedom Platform
217 stars 52 forks source link

Sifive Prebuilt gdb can't target HiFive1 #22

Closed abeco closed 4 years ago

abeco commented 4 years ago

I'm trying to flash my board using this guide https://risc-v-getting-started-guide.readthedocs.io/en/latest/zephyr-hifive1.html and openocd starts fine with the supplied cfg file (bsp/sifive-hifive1/openocd.cfg) but when I try "target extended-remote localhost:3333" on gdb it throws "bfd requires xlen 8, but target has xlen 4". I ran show configuration on gdb and here's the output:

(gdb) show configuration This GDB was configured as follows: configure --host=x86_64-linux-gnu --target=riscv64-unknown-elf --with-auto-load-dir=$debugdir:$datadir/auto-load --with-auto-load-safe-path=$debugdir:$datadir/auto-load --with-expat --with-gdb-datadir=/scratch/carsteng/freedom-tools-master/obj/x86_64-linux-ubuntu14/install/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/share/gdb (relocatable) --with-jit-reader-dir=/scratch/carsteng/freedom-tools-master/obj/x86_64-linux-ubuntu14/install/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/lib/gdb (relocatable) --without-libunwind-ia64 --with-lzma --without-babeltrace --without-intel-pt --disable-libmcheck --without-mpfr --without-python --without-guile --disable-source-highlight --with-separate-debug-dir=/scratch/carsteng/freedom-tools-master/obj/x86_64-linux-ubuntu14/install/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/lib/debug (relocatable)

I think my problem stems from the "--target=riscv64-unknown-elf" but on sifive's site they say the prebuilt toolchain is configured to work with both 32 and 64 bit targets

jim-wilson commented 4 years ago

I don't have a Hifive1 so I don't have experience with using one. And keep in mind that the HiFive1 and HiFive1 Rev B are different boards. Instructions for the HiFive1 likely won't work for a HiFive1 Rev B.

Gdb always includes both 32-bit and 64-bit support. The configure option only determines which one is the default to use when no architecture info is provided.

You can get gdb into 32-bit mode by using "set arch riscv:rv32". However, you can still run into problems if gdb and the target disagree on the size and/or number of FP registers. Generally, the best way to start gdb is to give it a binary compiled for the target, and let gdb grab arch info from the binary instead of using defaults.

However, I would expect that when gdb connects to openocd, that openocd then supplies gdb with target architecture info, so this should work automatically, even if no binary is supplied to gdb. But I don't have a HiFive1 so I don't have any experience in this area. If you want to try to debug this, you can use the gdb command "set debug remote 1" before the "target remote ..." command, and then you should see info on the packets being sent between gdb and the remote target, which should include a query command followed by XML register set descriptions being sent from openocd to gdb, which gdb should then use to set the architecture info from.

abeco commented 4 years ago

This was extremely helpful, thanks so much!

intelligenttoasters commented 4 years ago

For anyone else struggling with this error message (as I have for 2 days), note that regardless of the GCC options used to compile your code, the parameters used to build the toolchain may override the settings. When configuring the toolchain, use this for 4-byte (single precision) floats : ./configure --prefix=/opt/riscv --with-arch=rv32if --with-abi=ilp32f or ./configure --prefix=/opt/riscv --with-arch=rv32i --with-abi=ilp32 for no hard floats, matching the target flen of zero.

cgsfv commented 4 years ago

Sorry for asking, but what is it exactly you have been struggling with?

rgdaddio commented 3 years ago

@cgsfv I think it is this: "bfd requires xlen 8, but target has xlen 4" Which I have seen before and it brings it own kind of unhappiness.