1 # Tutorial for bootstrapping Gentoo with sffs compliance from source.
5 * bugreport: <https://bugs.libre-soc.org/show_bug.cgi?id=1131>
6 * (External) [Read the Gentoo handbook thoroughly, it's all you need](https://wiki.gentoo.org/wiki/Handbook:PPC64)
7 * please note this tarball contains executable binaries and it is 100% your responsibility to check them or take appropriate measures. we take no responsibility and accept no liability <https://ftp.libre-soc.org/sffs/stage3-ppc64le-openrc-20230720T024654Z.tar.xz>
8 * TODO investigate: a mirror of stage3 snapshots is available at archive.org
9 <https://web.archive.org/web/20221218010734/https://distfiles.gentoo.org/releases/ppc/autobuilds/20221217T033210Z/>
10 more recent snapshot: all stage3-ppc64le-openrc-20230823T030134Z.tar.xz* files:
11 <https://web.archive.org/web/20230823160828/https://distfiles.gentoo.org/releases/ppc/autobuilds/20230823T030134Z/>
19 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 stage 3 system to not include any of those instructions, making it compliant with [sffs (slides 5 & 6)](https://ics2020.bsc.es/sites/default/files/uploaded/brian_thompto_ICS2020_SLIDES.pdf).
21 To do this, you need to rebuild Gentoo from a known working stage3 archive, which we will guide you through.
23 Do note that given the rolling release nature of Gentoo, it is almost impossible to get the same system with the specific package versions we have without using the same stage3 version we used.
25 ## System requirements
27 - A POWER system that can run Debian Bookworm (meaning POWER8 and newer)
28 - At least 80GB of hard disk space
30 Cross compiling will make this process much more complicated and is generally not recommended.
32 It is expected for you to use Debian for the host OS (anything else
33 is unsupported: many contributors have repeatedly gotten into trouble by not following this advice)
35 ## Setting up Gentoo from stage3 and rebuilding (recommended method)
37 You will need to run these commands:
39 $ curl -O https://ftp.libre-soc.org/sffs/stage3-ppc64le-openrc-20230720T024654Z.tar.xz
40 $ sha256sum stage3-ppc64le-openrc-20230720T024654Z.tar.xz
42 The SHA256 checksum should be
44 `2c97446d09f2790ee6cc3e4cbff0d204f6f0914083fc36998d0b08fcb28f8e90`
47 # mkdir gentoo-sffs && cd gentoo-sffs
48 # tar xpvf ../stage3-ppc64le-openrc-20230720T024654Z.tar.xz --xattrs-include='*.*' --numeric-owner
51 Follow these steps from the Gentoo handbook:
53 * [Copy DNS info](https://wiki.gentoo.org/wiki/Handbook:PPC64/Installation/Base#Copy_DNS_info)
55 * [Mount necessary filesystems](https://wiki.gentoo.org/wiki/Handbook:PPC64/Installation/Base#Mounting_the_necessary_filesystems)
57 * [Enter the chroot environment](https://wiki.gentoo.org/wiki/Handbook:PPC64/Installation/Base#Entering_the_new_environment)
59 After which you need to add our build flags replacing the default ones in `/etc/portage/make.conf`
61 `COMMON_FLAGS="-O2 -pipe -mcpu=power9 -mno-altivec -mno-vsx -mno-crypto -mno-htm -mlong-double-64"`
65 Finally, rebuild everything on the system:
67 # emerge -e --ask --keep-going @world
69 # (Optional) Building an updated Gentoo SFFS
71 This is highly not recommended unless you specifically want to explore how newer versions of software will behave when built with the SFFS flags.
73 One way of doing this is to just set up Gentoo SFFS from the provided stage3, add out `make.conf` options and then upgrade everything, that is much simpler and easier to roll-back if need be.
75 After having a working chroot using the stage3 as outlined earlier, run these commands in the chroot:
78 # emerge --ask --verbose --update --deep --newuse @world
80 The other way is to create a new Gentoo chroot or virtual machine under POWER using the [handbook](https://wiki.gentoo.org/wiki/Handbook:PPC64), and once you reach the [stage3 tarball](https://wiki.gentoo.org/wiki/Handbook:PPC64/Installation/Stage#Unpacking_the_stage_tarball) step, download our [make.conf](link) and copy it to
81 `/etc/portage/make.conf`, replacing the provided one, and run:
83 # emerge -e --ask --keep-going @world
85 # emerge --ask --verbose --update --deep --newuse @world
87 To first rebuild Gentoo for SFFS, and then update the repositories, and finally to upgrade the software you have.
89 # Testing for VSX in object files
91 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.
93 This is not a perfect solution and the proper way would be either to:
95 - Simulate an SFFS compliant chip running this code such as [Microwatt](https://libre-soc.org/HDL_workflow/microwatt/) (very time consuming)
96 - Use a softcore FPGA core or ASIC of Microwatt / LibreSOC to run this code (doable, FPGA softcore in progress [in progress](https://bugs.libre-soc.org/show_bug.cgi?id=1037))
97 - Use the finalized Libre-SOC chip (doable once it is ready)
99 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.
101 To attempt this test, you will need the scripts from our `dev-env-setup` repository
103 $ git clone https://git.libre-soc.org/git/dev-env-setup.git
106 Do *look through* the
107 [code](https://git.libre-soc.org/?p=dev-env-setup.git;a=tree) before running
108 any of those scripts.
109 This is your own legal responsibility (to not run
110 arbitrary code off of the internet) and we take no responsibility or accept
111 any liability whatsoever for your use or misuse of them.
113 It is expected for you to use Debian for the host OS (anything else
114 is unsupported: many contributors have repeatedly gotten into trouble by not
115 following this advice), while all the chroots - which are developed
116 very specifically for "reproducible builds" - run Debian 10 (Buster).
118 Edit the `test-vsx` script to point the `CHROOT` variable to your respective chroot of Gentoo, read through the script thoroughly, and run
122 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.
124 You can also test specific binaries at any time by running this part of the script
126 $ objdump -d $OBJ_FILE | fgrep -of VSX_INSNS.txt | sort | uniq -c | awk '{print $2 " " $1}'
128 Where $OBJ_FILE is the binary you need to check.
132 * Gentoo's base system packages will not complain when building for SFFS (as of July 2023, can change depending on updates)
133 * 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](https://lore.kernel.org/all/CAPweEDw710zFK8KLZY5gsQxEkQKrDiFkNRgABY9HJZ1rxpeVCg@mail.gmail.com/T/) and to incorporate the needed patches upstream in the future.
134 * 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.
135 * glibc *may* have some issues on sffs, the only way to test this is to run on microwatt which will be done soon.