DEV Community

Luca Barbato
Luca Barbato

Posted on

cross-stages experiments

I'm still playing with RISC-V and the bpi-f3.

Support status for BPI-F3 upstream

The upstreaming effort at least for the kernel is ongoing.

The bsp seems actively maintained with changes landing quite often in their fork of opensbi, u-boot and linux. Sadly being bsp and since it covers multiple boards they tend of lump lots of changes together so it can get annoying to follow what they are fixing or adding.

Given enough opensource developers are getting the board or similar hardware, I hope we'll have enough eyes and hands to clean up the code in a shape it can also be upstreamed to u-boot and opensbi.

My experiments

I wanted to see how different would feel a whole system built to leverage at least a bit RVV 1.0 through the compiler, sadly until this bug won't be addressed it would be hard to have a fully working system compiled with the autovectorizer on and I found it out the hard way.

The Gentoo default way to build stages and images via catalyst relies on qemu-user when no fast native system is available to avoid pitfalls of packages failing at cross-compilation. It is a bit slow but fairly reliable.

Since things should improve over time, I tried to leverage crossdev and see if:

  • [x] At least the stage1 packages could be cross-compiled and installed via crossdev (perl seems the only package misbehaving)
  • [x] Freshening a stage3 works. As seen with cross-boss it feasible, I wanted to see it can be made even more straightforward.
  • [x] Add packages and setup demons

All without using qemu-user so it can be made quickly, so far it mostly works.

On top of it I just cross-compiled the bsp packages and copied the approach they used to assemble the final image using genimage, trying to make it as simple as possible by using a single configuration file that does everything in a single invocation.

The crossdev-stages set of scripts should let anybody with a recent Gentoo with the dependencies listed to build their images in reasonable time.

Usage

I prepared 3 scripts:

  • chroot-stage.sh that make quite easy to fetch a stage3, unpack it and and optionally enter it using bubblewrap (thanks chewi for introducing me to it).
# If you already have Gentoo you can just fetch the stage
$ bash chroot-stage.sh setup stage3/ riscv64
# If you do not have Gentoo you can use the script to have a host chroot
$ bash chroot-stage.sh setup my-chroot
$ bash chroot-stage.sh enter my-chroot
Enter fullscreen mode Exit fullscreen mode
  • cross-stage.sh that takes care of all the building, you can go from-scratch or start from a pre-existing stage3
# This will rebuild all the stage3 using the newer compiler and the CFLAGS you set in the script
$ bash cross-stage.sh update stage3/
# Install the bare minimum needed to have the bootloader working
$ bash cross-stage.sh install_boot stage3/
# Install additional packages you may find useful
$ bash cross-stage.sh install_more stage3/
Enter fullscreen mode Exit fullscreen mode
  • make-image.sh that puts everything together and build the bsp packages.
# It will produce a gentoo-linux-k1_dev-sdcard.img.xz in the build-directory
$ bash make-image.sh /tmp/build-directory stage3/
Enter fullscreen mode Exit fullscreen mode

So far it works for me you are welcome to try it, help improving it or just use the pre-made image.

Enjoy!

Top comments (0)