80 char limit, indentation missing, added limited liability on downloads
[libreriscv.git] / SFFS / debian_bootstrap.mdwn
1 # Tutorial for bootstrapping Debian Bookworm (12) from source.
2
3 Useful Links (External):
4
5 * [Read about sbuild and understand how it works](https://wiki.debian.org/sbuild)
6 * [dpkg-buildflags man page](https://manpages.debian.org/bookworm/dpkg-dev/dpkg-buildflags.1.en.html) (optional, in case some flags need to be changed)
7 * [apt-ftparchive man page](https://manpages.debian.org/bookworm/apt-utils/apt-ftparchive.1.en.html) (optional, in case you want to customize the repo)
8 * [debootstrap wiki page](https://wiki.debian.org/Debootstrap) (optional,
9 in case you want to customize your chroot)
10
11 Useful links (Libre-SOC):
12
13 * bugreport <https://bugs.libre-soc.org/show_bug.cgi?id=1130>
14 * Devscripts Libre-SOC page: [[devscripts]]
15 * [Libre-SOC devscripts repo](https://git.libre-soc.org/?p=dev-env-setup.git;a=tree)
16
17 ## Video Tutorial
18
19 [todo](todo)
20
21 ## Reasoning:
22
23 Libre-SOC builds upon the OpenPOWER ISA v3.0 but does not include
24 many parts of the architecture typically found on production
25 silicon, like AltiVec, VSX, and 128-bit hardware floating
26 point. Because of this, we need (at this time, might change
27 in the future when glibc supports detecting VSX vs SVP64 etc)
28 to rebuild the full software repository to not include any of
29 those instructions, making it compliant with [sffs (slides 5 &
30 6)](https://ics2020.bsc.es/sites/default/files/uploaded/brian_thompto_ICS2020_SLIDES.pdf).
31
32 You can approach this in two ways: either build the full base Debian
33 chroot packages yourself using Debian's build tools, optionally automated
34 with our [scripts](https://git.libre-soc.org/?p=dev-env-setup.git;a=tree),
35 or use the [prebuilt rootfs] in a compressed tar archive.
36
37 ## System requirements
38
39 - A POWER system that can run Debian Bookworm (meaning POWER8 and newer)
40 - At least 80GB of hard disk space
41
42 Cross compiling will make this process much more complicated and is
43 generally not recommended.
44
45 ## Development Setup Scripts
46
47 If you haven't already, clone Libre-SOC's development environment setup
48 scripts. These are bash scripts, and greatly simplify the time it takes
49 to create a:
50
51 - Stable environment
52 - With all software and libraries at specific versions
53 (which are known to work).
54
55 These attributes are absolutely critical, and no support will be provided,
56 unless you use these scripts to setup a development environment. This
57 helps us fix any bugs in the scripts, and make sure everyone runs on
58 the same page.
59
60 $ git clone https://git.libre-soc.org/git/dev-env-setup.git
61
62 Do *look through* the
63 [code](https://git.libre-soc.org/?p=dev-env-setup.git;a=tree) before running
64 any of those scripts.
65 This is your own legal responsibility (to not run
66 arbitrary code off of the internet) and we take no responsibility or accept
67 any liability whatsoever for your use or misuse of them.
68
69 It is expected for you to use Debian for the host OS (anything else is
70 unsupported: many contributors have repeatedly gotten into trouble by
71 not following this advice), while all the chroots - which are developed
72 very specifically for "reproducible builds" - run Debian 10 (Buster).
73
74 ## Setting up the build schroot
75
76 Scripts we will be using for the setup are:
77
78 * `install-sbuild-apt-reqs` for installing sbuild and configuring it to
79 Debian's defaults
80 * `mk-schroot-bookworm` for creating the bookworm schroot used by sbuild
81 and adding our dpkg-buildflags to build for sffs
82 * `build-bookworm-sffs` to build the packages needed for a debootstrap
83 chroot directory
84 * `create-deb-repo` to create a local dpkg repository of the built packages
85 * `mk-sffs-chroot` to finally create the chroot using the repository of
86 built packages
87
88 Commands to run in terminal to rebuild Debian 12 with sffs compliance:
89
90 $ cd dev-env-setup
91 $ sudo bash
92 # ./install-sbuild-apt-reqs
93 # ./mk-schroot-bookworm
94 # exit
95 $ ./build-bookworm-sffs
96 $ ./create-deb-repo
97 $ ./mk-sffs-chroot
98
99 ## Using prebuilt tarball
100
101 If you prefer to use the prebuilt tarball (which will save days of your
102 time), you could simply download and extract the tarball to a convenient
103 location and chroot into it. Bear in mind though that it is entirely your
104 responsibility when downloading arbitrary binaries, and we accept no
105 liability whatsoever for anything arising by you downloading them.
106
107 $ curl -O [link to be added]
108 $ mkdir bookworm-sffs && cd bookworm-sffs
109 $ tar xpvf bookworm-sffs.tar.xz --xattrs-include='*.*' --numeric-owner
110 $ cd ..
111 $ sudo chroot bookworm-sffs
112
113 # Testing for VSX in object files
114
115 To verify that our buildflags were applied by the build tools and
116 respected by the build scripts of packages, we need to check for the
117 inclusion of VSX as well as any other instructions not available in SFFS.
118
119 This is not a perfect solution and the proper way would be either to:
120
121 - Simulate an SFFS compliant chip running this code such as
122 [Microwatt](https://libre-soc.org/HDL_workflow/microwatt/)
123 (very time consuming)
124 - Use a softcore FPGA core or ASIC of Microwatt /
125 LibreSOC to run this code (doable, FPGA softcore
126 [in progress](https://bugs.libre-soc.org/show_bug.cgi?id=1037))
127 - Use the finalized Libre-SOC chip (doable once it is ready)
128
129 Also note that this only tests for a subset of VSX instructions at the
130 moment, more will be added in the future, this is simply a quick test to
131 run before attempting to run on simulation and/or a softcore as both can
132 be somewhat time consuming. In other words, if this test gives any VSX
133 instructions, don't attempt to run the code in simulation or a softcore
134 to avoid wasting precious time.
135
136 To attempt this test, you will need the scripts from our `dev-env-setup`
137 repository
138
139 $ git clone https://git.libre-soc.org/git/dev-env-setup.git
140
141 Again, previous notes about running the scripts apply here, do make sure
142 to read whatever you run, they are short and human-readable.
143
144 Edit the `test-vsx` script to point the `CHROOT` variable to your
145 respective chroot of Debian, read through the script thoroughly, and run
146
147 $ ./test-vsx
148
149 If you see any number of instructions in certain binary files, those
150 files do contain VSX and work needs to be done (patching the build
151 scripts and/or source code) for these packages. If not, great! Try to
152 run this in a proper SFFS environment to fully test the code you have.
153
154 You can also test specific binaries at any time by running this part of
155 the script
156
157 $ objdump -d $OBJ_FILE | fgrep -of VSX_INSNS.txt | sort | uniq -c \
158 | awk '{print $2 " " $1}'
159
160 Where `$OBJ_FILE` is the binary you need to check.
161
162 ## Notes and issues
163
164 * Some packages will refuse to build with sffs compliant build flags
165 and need workarounds, this will be handled in the future.
166 * The Linux kernel cannot boot without AltiVec and VSX, even though they
167 are build-time options. The solution for now is to use [microwatt's 5.7
168 kernel](https://lore.kernel.org/all/CAPweEDw710zFK8KLZY5gsQxEkQKrDiFkNRgABY9HJZ1rxpeVCg@mail.gmail.com/T/)
169 and to incorporate the needed patches upstream in the future.
170 * Previous note also means this is purely a chroot environment, this page
171 will be updated once it becomes possible to boot a full VM of this build.
172 * glibc *may* have some issues on sffs, the only way to test this is to
173 run on microwatt which will be done soon.
174