Tutorial for bootstrapping Debian Bookworm (12) from source.

This project is part of NLnet NGI0 Entrust and has received funding from the European Union’s Horizon Europe research and innovation programme under grant agreement No 101069594.

Useful Links:

Useful links (Libre-SOC):

Video Tutorial

todo

Reasoning:

Libre-SOC builds upon the OpenPOWER ISA v3.0 but does not include many parts of the architecture typically found on production silicon, like AltiVec, VSX, and 128-bit hardware floating point. Because of this, we need (at this time, might change in the future when glibc supports detecting VSX vs SVP64 etc) to rebuild the full software repository to not include any of those instructions, making it compliant with sffs (slides 5 & 6).

You can approach this in two ways: either build the full base Debian chroot packages yourself using Debian's build tools, optionally automated with our scripts, or use the prebuilt rootfs for which you accept full liability and responsibility in a compressed tar archive.

System requirements

  • A POWER system that can run Debian Bookworm (meaning POWER8 and newer)
  • At least 80GB of hard disk space

Cross compiling will make this process much more complicated and is generally not recommended.

Development Setup Scripts

If you haven't already, clone Libre-SOC's development environment setup scripts. These are bash scripts, and greatly simplify the time it takes to create a:

  • Stable environment
  • With all software and libraries at specific versions (which are known to work).

These attributes are absolutely critical, and no support will be provided, unless you use these scripts to setup a development environment. This helps us fix any bugs in the scripts, and make sure everyone runs on the same page.

$ git clone https://git.libre-soc.org/git/dev-env-setup.git

Do look through the code before running any of those scripts. This is your own legal responsibility (to not run arbitrary code off of the internet) and we take no responsibility or accept any liability whatsoever for your use or misuse of them.

It is expected for you to use Debian for the host OS (anything else is unsupported: many contributors have repeatedly gotten into trouble by not following this advice), while all the chroots - which are developed very specifically for "reproducible builds" - run Debian 10 (Buster).

Setting up the build schroot

Scripts we will be using for the setup are:

  • install-sbuild-apt-reqs for installing sbuild and configuring it to Debian's defaults
  • mk-schroot-bookworm for creating the bookworm schroot used by sbuild and adding our dpkg-buildflags to build for sffs
  • build-glibc-debian to build glibc, currently has to be standalone because of this
  • add-sffs-flags-debian to add the SFFS CFLAGS
  • build-bookworm-sffs to build the packages needed for a debootstrap chroot directory
  • create-deb-repo to create a local dpkg repository of the built packages
  • mk-sffs-chroot to finally create the chroot using the repository of built packages

Commands to run in terminal to rebuild Debian 12 with sffs compliance:

$ cd dev-env-setup
$ sudo bash
# ./install-sbuild-apt-reqs
# ./mk-schroot-bookworm
# exit
$ ./build-glibc-debian
$ sudo bash
# ./add-sffs-flags-debian
# exit
$ ./build-bookworm-sffs
$ ./create-deb-repo
$ ./mk-sffs-chroot

Using prebuilt tarball

If you prefer to use the prebuilt tarball (which will save days of your time), you could simply download and extract the tarball to a convenient location and chroot into it. Bear in mind though that it is entirely your responsibility when downloading arbitrary binaries, and we accept no liability whatsoever for anything arising by you downloading them.

$ curl -O https://ftp.libre-soc.org/sffs/debian-12-sffs.2023sep01.tar.xz
$ mkdir bookworm-sffs && cd bookworm-sffs
$ tar xpvf bookworm-sffs.tar.xz --xattrs-include='*.*' --numeric-owner
$ cd ..
$ sudo chroot bookworm-sffs

Testing for VSX in object files

To verify that our buildflags were applied by the build tools and respected by the build scripts of packages, we need to check for the inclusion of VSX as well as any other instructions not available in SFFS.

This is not a perfect solution and the proper way would be either to:

  • Simulate an SFFS compliant chip running this code such as Microwatt (very time consuming)
  • Use a softcore FPGA core or ASIC of Microwatt / LibreSOC to run this code (doable, FPGA softcore in progress)
  • Use the finalized Libre-SOC chip (doable once it is ready)

Also note that this only tests for a subset of VSX instructions at the moment, more will be added in the future, this is simply a quick test to run before attempting to run on simulation and/or a softcore as both can be somewhat time consuming. In other words, if this test gives any VSX instructions, don't attempt to run the code in simulation or a softcore to avoid wasting precious time.

To attempt this test, you will need the scripts from our dev-env-setup repository

$ git clone https://git.libre-soc.org/git/dev-env-setup.git

Again, previous notes about running the scripts apply here, do make sure to read whatever you run, they are short and human-readable.

Edit the test-vsx script to point the CHROOT variable to your respective chroot of Debian, read through the script thoroughly, and run

$ ./test-vsx

If you see any number of instructions in certain binary files, those files do contain VSX and work needs to be done (patching the build scripts and/or source code) for these packages. If not, great! Try to run this in a proper SFFS environment to fully test the code you have.

You can also test specific binaries at any time by running this part of the script

$ objdump -d $OBJ_FILE | fgrep -of VSX_INSNS.txt | sort | uniq -c \
  | awk '{print $2 " " $1}'

Where $OBJ_FILE is the binary you need to check.

Notes and issues

  • Some packages will refuse to build with sffs compliant build flags and need workarounds, this will be handled in the future.
  • The Linux kernel cannot boot without AltiVec and VSX, even though they are build-time options. The solution for now is to use microwatt's 5.7 kernel and to incorporate the needed patches upstream in the future.
  • Previous note also means this is purely a chroot environment, this page will be updated once it becomes possible to boot a full VM of this build.
  • glibc may have some issues on sffs, the only way to test this is to run on microwatt which will be done soon.