1 Tutorial, part 1: Starting from scratch
2 ===========================================
4 This tutorial will guide you through the process of setting up a working
5 coreboot toolchain. In same cases you will find specific instructions
6 for Debian (apt-get), Fedora (dnf) and Arch Linux (pacman) based package
7 management systems. Use the instructions according to your system.
9 To test the toolchain and make sure it works, we will build coreboot for
10 an emulated system provided by QEMU. This allows you to get familiar
11 with the general process of configuring and building coreboot without
12 needing to flash any hardware.
15 **Do not attempt to flash the coreboot ROM built here to a real board**
17 coreboot is board specific, so a ROM built for one board model (such as
18 the QEMU emulation boards) cannot be expected to work on a different
19 board. You must reconfigure coreboot for your board and rebuild the ROM
20 before flashing it to a physical system.
22 **Note: Summaries of each of the steps are at the end of the document.**
25 Download, configure, and build coreboot
26 ---------------------------------------
29 ### Step 1 - Install tools and libraries needed for coreboot
32 `sudo apt-get install -y bison build-essential curl flex git gnat
33 libncurses5-dev libssl-dev m4 zlib1g-dev pkg-config`
36 `sudo pacman -S base-devel curl git gcc-ada ncurses zlib`
39 `sudo dnf install git make gcc-gnat flex bison xz bzip2 gcc g++
40 ncurses-devel wget zlib-devel patch`
43 ### Step 2 - Download coreboot source tree
46 git clone https://review.coreboot.org/coreboot
52 ### Step 3 - Build the coreboot toolchain
54 Please note that this can take a significant amount of time. Use `CPUS=`
55 to specify number of `make` jobs to run in parallel.
57 This will list toolchain options and supported architectures:
63 Here are some examples:
66 make crossgcc-i386 CPUS=$(nproc) # build i386 toolchain
67 make crossgcc-aarch64 CPUS=$(nproc) # build Aarch64 toolchain
68 make crossgcc-riscv CPUS=$(nproc) # build RISC-V toolchain
71 Note that the i386 toolchain is currently used for all x86 platforms,
72 including x86_64. For this tutorial we only need the i386 toolchain.
74 Also note that you can possibly use your system toolchain, but the
75 results are not reproducible, and may have issues, so this is not
76 recommended. See step 5 to use your system toolchain.
79 ### Step 4 - Build the payload - coreinfo
82 make -C payloads/coreinfo olddefconfig
83 make -C payloads/coreinfo
87 ### Step 5 - Configure the build
89 ##### Configure your mainboard
95 Do the next steps in the menu:
98 select 'Mainboard' menu
99 Beside 'Mainboard vendor' should be '(Emulation)'
100 Beside 'Mainboard model' should be 'QEMU x86 i440fx/piix4'
104 These should be the default selections, so if anything else was set, run
105 `make distclean` to remove your old config file and start over.
107 ##### Optionally use your system toolchain (Again, not recommended)
110 select 'General Setup' menu
111 select 'Allow building with any toolchain'
115 ##### Select the payload
118 select 'Payload' menu
119 select 'Payload to add (SeaBIOS) --->'
120 choose 'An ELF executable payload'
121 select 'Payload path and filename'
122 enter 'payloads/coreinfo/build/coreinfo.elf'
128 ##### Check your configuration (optional step):
135 There should only be 9 lines (or 10 if you're using the system
139 CONFIG_CBFS_SIZE=0x00400000
140 CONFIG_CONSOLE_CBMEM_BUFFER_SIZE=0x20000
141 CONFIG_SUBSYSTEM_VENDOR_ID=0x0000
142 CONFIG_SUBSYSTEM_DEVICE_ID=0x0000
143 CONFIG_I2C_TRANSFER_TIMEOUT_US=500000
144 CONFIG_CONSOLE_QEMU_DEBUGCON_PORT=0x402
145 CONFIG_POST_IO_PORT=0x80
147 CONFIG_PAYLOAD_FILE="payloads/coreinfo/build/coreinfo.elf"
150 Note that this may differ depending on the revision of the coreboot
151 source you are building from and should not be taken as the required
152 contents of defconfig.
154 ### Step 6 - Build coreboot
160 At the end of the build, you should see:
162 `Built emulation/qemu-i440fx (QEMU x86 i440fx/piix4)`
164 This means your build was successful. The output from the build is in
165 the `build` directory. `build/coreboot.rom` is the full rom file.
168 Test the image using QEMU
169 -------------------------
172 ### Step 7 - Install QEMU
174 * Debian: `sudo apt-get install -y qemu-system`
175 * Arch: `sudo pacman -S qemu`
176 * Redhat: `sudo dnf install qemu`
179 ### Step 8 - Run QEMU
181 Start QEMU, and point it to the ROM you just built:
184 qemu-system-x86_64 -bios build/coreboot.rom -serial stdio
187 You should see the serial output of coreboot in the original console
188 window, and a new window will appear running the coreinfo payload.
195 ### Step 1 summary - Install tools and libraries needed for coreboot
197 Depending on your distribution you have installed the minimum additional
198 software requirements to continue with downloading and building
199 coreboot. Not every distribution has the tools, that would be required,
200 installed by default. In the following we shortly introduce the purpose
201 of the installed packages:
203 * `build-essential` or `base-devel` are the basic tools for building software.
204 * `git` is needed to download coreboot from the coreboot git repository.
205 * `libncurses5-dev` or `ncurses` is needed to build the menu for 'make menuconfig'
206 * `m4, bison, curl, flex, zlib1g-dev, gcc, gnat` and `g++` or `clang`
207 are needed to build the coreboot toolchain. `gcc` and `gnat` have to be
209 * `libssl-dev, pkg-config` are needed to build coreboot image (Step 6).
210 In particular, `libcrypto` provided by `libssl-dev` package.
212 If you started with a different distribution or package management
213 system you might need to install other packages. Most likely they are
214 named slightly different. If that is the case for you, we'd like to
215 encourage you to contribute to the project and submit a pull request
216 with an update for this documentation for your system.
219 ### Step 2 summary - Download coreboot source tree
221 This will download a 'read-only' copy of the coreboot tree. This just
222 means that if you made changes to the coreboot tree, you couldn't
223 immediately contribute them back to the community. To pull a copy of
224 coreboot that would allow you to contribute back, you would first need
225 to sign up for an account on gerrit.
228 ### Step 3 summary - Build the coreboot toolchain.
230 This builds one of the coreboot cross-compiler toolchains for X86
231 platforms. Because of the variability of compilers and the other
232 required tools between the various operating systems that coreboot can
233 be built on, coreboot supplies and uses its own cross-compiler toolchain
234 to build the binaries that end up as part of the coreboot ROM. The
235 toolchain provided by the operating system (the 'host toolchain') is
236 used to build various tools that will run on the local system during the
240 ### Step 4 summary - Build the payload
242 To actually do anything useful with coreboot, you need to build a
243 payload to include into the rom. The idea behind coreboot is that it
244 does the minimum amount possible before passing control of the machine
245 to a payload. There are various payloads such as grub or SeaBIOS that
246 are typically used to boot the operating system. Instead, we used
247 coreinfo, a small demonstration payload that allows the user to look at
248 various things such as memory and the contents of the coreboot file
249 system (CBFS) - the pieces that make up the coreboot rom.
251 Usually, the coreboot build system automatically builds the payload
252 selected in the "Payload to add" menu and sets it as the default payload
253 (also known as the "primary payload"). Such payloads are able to boot an
254 operating system and may be able to load another payload. Although
255 coreinfo can be found in the "Secondary Payloads" menu, in which case it
256 would be handled automatically, it is not available as a primary payload
257 since it cannot load an OS or another payload. Secondary payloads must
258 be loaded from other primary or secondary payloads and will not be run
259 when coreboot hands off execution after initializing hardware. Thus, to
260 get coreinfo to run as if it were a primary payload, it must be manually
261 built and explicitly set as the primary payload using the "ELF
262 executable payload" option.
265 ### Step 5 summary - Configure the build
267 This step configures coreboot's build options using the menuconfig
268 interface to Kconfig. Kconfig is the same configuration program used by
269 the linux kernel. It allows you to enable, disable, and change various
270 values to control the coreboot build process, including which
271 mainboard(motherboard) to use, which toolchain to use, and how the
272 runtime debug console should be presented and saved. Anytime you change
273 mainboards in Kconfig, you should always run `make distclean` before
274 running `make menuconfig`. Due to the way that Kconfig works, values
275 will be kept from the previous mainboard if you skip the clean step.
276 This leads to a hybrid configuration which may or may not work as
280 ### Step 6 summary - Build coreboot
282 You may notice that a number of other pieces are downloaded at the
283 beginning of the build process. These are the git submodules used in
284 various coreboot builds. By default, the _blobs_ submodule is not
285 downloaded. This git submodule may be required for other builds for
286 microcode or other binaries. To enable downloading this submodule,
287 select the option "Allow use of binary-only repository" in the "General
288 Setup" menu of Kconfig This attempts to build the coreboot rom. The rom
289 file itself ends up in the build directory as 'coreboot.rom'. At the end
290 of the build process, the build displayed the contents of the rom file.
293 ### Step 7 summary - Install QEMU
295 QEMU is a processor emulator which we can use to show the coreboot boot
296 process in a virtualised environment.
299 ### Step 8 summary - Run QEMU
301 Here's the command line instruction broken down:
302 * `qemu-system-x86_64`
303 This starts the QEMU emulator with the i440FX host PCI bridge and PIIX3
305 * `-bios build/coreboot.rom`
306 Use the coreboot rom image that we just built. If this flag is left out,
307 the standard SeaBIOS image that comes with QEMU is used.
309 Send the serial output to the console. This allows you to view the