riscvarchive / riscv-qemu

QEMU with RISC-V (RV64G, RV32G) Emulation Support
387 stars 154 forks source link

Build fails on Ubuntu 14.04.5 32 bit #44

Closed TommyMurphyTM1234 closed 6 years ago

TommyMurphyTM1234 commented 7 years ago

Should it build on 32 bit? When I try on Ubuntu 14.04.5 LTS 32 bit the build fails. I do this:

git clone https://github.com/riscv/riscv-qemu
cd riscv-qemu
git submodule update --init pixman
./configure --target-list=riscv32-softmmu --prefix=riscv-qemu-install
make

and get this:

  CC    riscv64-softmmu/hw/riscv/riscv_rtc.o
/home/user/Downloads/riscv-qemu/hw/riscv/riscv_rtc.c: In function ‘timer_mm_read’:
/home/user/Downloads/riscv-qemu/hw/riscv/riscv_rtc.c:178:9: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘hwaddr’ [-Werror=format=]
         printf("Invalid timer register address %016lx\n", (uint64_t)addr);
         ^
/home/user/Downloads/riscv-qemu/hw/riscv/riscv_rtc.c: In function ‘timer_mm_write’:
/home/user/Downloads/riscv-qemu/hw/riscv/riscv_rtc.c:204:9: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘hwaddr’ [-Werror=format=]
         printf("Invalid timer register address %016lx\n", (uint64_t)addr);
         ^
cc1: all warnings being treated as errors
make[1]: *** [hw/riscv/riscv_rtc.o] Error 1
make: *** [subdir-riscv64-softmmu] Error 2

Am I doing something wrong? Thanks.

sorear commented 7 years ago

No, you're not doing anything wrong. The toolchain is broken on 32-bit and has been for some time. I think @shrshore got qemu to build but it's still crashing in BBL ( riscv/riscv-pk#43 )

TommyMurphyTM1234 commented 7 years ago

Thanks - but would it be possible to be more specific (e.g. link to relevant issues/posts?) about the 32 bit toolchain being "broken"? Do you mean 32 bit hosted tools or 32 but RISC-V target support? As far as I can see I can get a 32 bit hosted RV32IM toolchain built and working but I can't build qemu on a 32 bit host. In case it matters I'm only interested in the bare metal and not the linux toolchain support a the moment.

sorear commented 7 years ago

What I mean is that the Foundation and SiFive people all have 64-bit machines and 32-bit support is poorly tested, I've seen several error reports, and very few success reports.

I was able to build the toolchain in a 32-bit container just now but it made a toolchain for riscv64-, not riscv32-. Looks like --with-arch and --with-abi are needed, I'll make a PR to document that, then I'll see about fixing this. There will be more problems later.

sorear commented 7 years ago

With #46 riscv64-softmmu works on a 32-bit Debian chroot using a riscv64 Linux kernel + initramfs built from freedom-u-sdk (be sure to use the version of freedom-u-sdk mentioned in README.md after checking out the PR).

The tests were done on 64-bit Intel hardware + a 32-bit OS, so it's still theoretically possible you could have compatibility problems with 32-bit hardware. Let me know how it goes.

riscv32 support is a separate problem, but this should be enough to get you running.

haoransh commented 7 years ago

@sorear Sorry for delayed reply. But I have tried on 32bit ubuntu, just to fail allocating memory. I build a riscv64 Linux Kernel and initramfs according to freedom-u-sdk(git reset --hard 5d28ed), and build qemu with #46 riscv64-softmmu. However, when it comes to

./riscv64-softmmu/qemu-system-riscv64 -kernel freedom-u-sdk/work/riscv-pk/bbl -nographic -machine sifive

It will remind that

qemu-system-riscv32: cannot set up guest memory 'riscv_sifive_board.ram': Cannot allocate memory

Even if I try this patch 8d870e9, the error still exists. Could you offer any help?

Thanks for your effort!

sorear commented 7 years ago

@shrshore Get rid of -machine sifive for now.

  1. The fix 8d870e9 only applies to the spike_board; I have a very similar fix for the sifive_board I need to PR.
  2. The current sifive_board doesn't work with the current freedom-u-sdk even on a 64-bit host with 8GB because the register assignment of the UART has changed (on my TODO)
haoransh commented 7 years ago

Wow!!! I have boot the kernel now! Thanks so much! And could you commit your fix of sifive_board so other people can also apply?

By the way, do you know how to login in the system? T.T According to http://wiki.in-circuit.de/index.php5?title=Buildroot_login the username should be "root"/"default" and passwd should be empty. But it always reminds "login incorrect". Maybe it's due to ssh connection. But I have no idea how to login in successfully.

Welcome to Buildroot
buildroot login: root
Password:
Login incorrect
buildroot login: default
Password:
Login incorrect
buildroot login:
Login timed out after 60 seconds
sorear commented 7 years ago

@shrshore root / sifive

haoransh commented 7 years ago

@sorear Okay, thanks so much. It seems all right now. Still looking forward to RV32 support if possible.

Best Regards!

TommyMurphyTM1234 commented 7 years ago

FWIW (in case the build instructions can/should be updated) this worked for me:

First step was a clean install of Ubuntu 14.04.5 LTS 64 bit and then all available updates installed. Then...

sudo apt-get install git
git clone https://github.com/riscv/riscv-qemu
cd riscv-qemu
git submodule update --init pixman
sudo apt-get install g++
sudo apt-get install zlib1g-dev
sudo apt-get install libglib2.0-dev
sudo apt-get install autoconf 
sudo apt-get install libtool
./configure --target-list=riscv64-softmmu,riscv32-softmmu --prefix=`pwd`/riscv-qemu-install
make install

Hope this helps.

michaeljclark commented 6 years ago

Boot tested qemu-system-riscv64 on ubuntu 14.04.5-i386: https://github.com/riscv/riscv-qemu/commit/6273610d5a23d0799a89fa826a97baa23b8781d2

TommyMurphyTM1234 commented 6 years ago

I can't really see how the fix relates to the original issue report? In any case 32 bit linux builds have been working fine for a long time now at least using Liviu's GNU MCU Eclipse scripted docker approach.

michaeljclark commented 6 years ago

It relates pretty much exactly in that it fixes 32-bit builds on ubuntu 14.04.5-i386

Without https://github.com/riscv/riscv-qemu/commit/6273610d5a23d0799a89fa826a97baa23b8781d2 this is what happens when building on ubuntu 14.04.5-i386

/home/mclark/src/riscv-qemu/target-riscv/op_helper.c: In function ‘csr_read_helper’:
/home/mclark/src/riscv-qemu/target-riscv/op_helper.c:531:9: error: left shift count >= width of type [-Werror]
         return (1L << (TARGET_LONG_BITS - 5));
         ^
cc1: all warnings being treated as errors
make[1]: *** [target-riscv/op_helper.o] Error 1
make: *** [subdir-riscv64-softmmu] Error 2
michaeljclark commented 6 years ago

i.e. we had to fix builds on ubuntu 14.04.5-i386 so we could close out the bug

michaeljclark commented 6 years ago

The reason for the build failure on 32-bit linux is because long is 32-bits. It needs to be long long (1LL) so that qemu-system-riscv64 will build on 32-bit linux. Essentially the bug report is about a build failure on 32-bit linux which is exactly what the patch fixes (perhaps a different build failure to the one happening at the time of the report).

In any case builds no longer fail on Ubuntu 14.04.5 32 bit i.e. the bug title