# Building libreboot from source

This section relates to building libreboot from source, and working with the git repository.

Or Back to main index.

- Install build dependencies
- Get the full source code from metadata (git clone)
- How to build "bucts" (for LenovoBIOS X60/X60S/X60T/T60)
- How to build "flashrom"
- Configuring libreboot
  - dmidecode
  - ThinkPad X60, X60S and X60 Tablet
  - ThinkPad T60
  - ThinkPad X200
  - MacBook2,1
  - QEMU (x86 i440fx/piix4)
  - QEMU (x86 q35/ich9)
- How to build the ROM images
- Add SeaBIOS to the ROM images

# Install build dependencies

Before doing anything, you need the dependencies first. This is true if you want to build libreboot from source, with either libreboot_src.tar.xz or git. If you are using libreboot_bin.tar.xz (binary archive) then you can ignore this, because ROM images and statically compiled executables for the utilities are included.

- deps-trisquel script installs dependencies for Trisquel 6 (also tested in Trisquel 7).

For all other GNU/Linux distributions, you may have to adapt these scripts. By all means send patches!

Back to top of page

# Get the full source code from metadata (git clone)

If you downloaded libreboot from git, then there are some steps to download and patch the source code for all relevant dependencies. The archive in the git repository used to be available as a tarball called 'libreboot_meta.tar.gz'. It contains 'metadata' (scripts) which define how the source was created (where it came from).

You can use the scripts included to download everything.

First, install the build dependencies.

Since libreboot makes extensive use of git, you need to configure git properly. If you have not yet configured git, then the minimum requirement is:
$ git config --global user.name "Your Name"
$ git config --global user.email your@emailaddress.com
This is what will also appear in git logs if you ever commit your own changes to a given repository. For more information, see http://git-scm.com/doc.

Another nice config for you (optional, but recommended):
$ git config --global core.editor nano
$ git config --global color.status auto
$ git config --global color.branch auto
$ git config --global color.interactive auto
$ git config --global color.diff auto

After that, run the get script:
$ ./getall

What this did was download everything (grub, coreboot, memtest86+, bucts, flashrom) at the versions last tested for this release, and patch them. Read the script in a text editor to learn more.

To build the ROM images, see #build.

Back to top of page.

# How to build "bucts" (for LenovoBIOS X60/X60S/X60T/T60)

This is for Lenovo BIOS users on the ThinkPad X60/X60S, X60 Tablet and T60. If you have coreboot or libreboot running already, ignore this.

Bucts is needed when flashing in software the X60/X60S/X60T/T60 ROM while Lenovo BIOS is running; external flashing will be safe regardless. Each ROM contains identical data inside the two final 64K region in the file. This corresponds to the final two 64K regions in the flash chip. Lenovo BIOS will prevent you from writing the final one, so running "bucts 1" will set the machine to boot from the other block instead (which is writeable along with everything beneath it when using a patched flashrom. see #build_flashrom). After shutting down and booting up after the first flash, the final 64K block is writeable so you flash the ROM again with an unpatched flashrom and run "bucts 0" to make the machine boot from the normal (highest) block again.

BUC.TS utility is included in libreboot_src.tar.xz and libreboot_bin.tar.xz.
If you downloaded from git, follow #build_meta before you proceed.

"BUC" means "Backup Control" (it's a register) and "TS" means "Top Swap" (it's a status bit). Hence "bucts" (BUC.TS). TS 1 and TS 0 corresponds to bucts 1 and bucts 0.

If you have the binary release archive, you'll find executables under ./bucts/. Otherwise if you need to build from source, continue reading.

First, install the build dependencies.

To build bucts, do this in the main directory:
$ ./builddeps-bucts

The "builddeps" script in libreboot_src also makes use of builddeps-bucts.

Back to top of page.

# How to build "flashrom"

Flashrom is the utility for flashing/dumping ROM images. This is what you will use to install libreboot.

Flashrom source code is included in libreboot_src.tar.gz and libreboot_bin.tar.gz.
If you downloaded from git, follow #build_meta before you proceed.

If you are using the binary release archive, then there are already binaries included under ./flashrom/. The flashing scripts will try to choose the correct one for you. Otherwise if you wish to re-build flashrom from source, continue reading.

First, install the build dependencies.

To build it, do that in the main directory:
$ ./builddeps-flashrom

After you've done that, under ./flashrom/ you will find the following executables:

- flashrom
  - For flashing while coreboot or libreboot is running.
- flashrom_lenovobios_sst
  - This is patched for flashing while Lenovo BIOS is running on an X60 or T60 with the SST25VF016B (SST) flash chip.
- flashrom_lenovobios_macronix
  - This is patched for flashing while Lenovo BIOS is running on an X60 or T60 with the MX25L1605D (Macronix) flash chip.

The "builddeps" script in libreboot_src also makes use of builddeps-flashrom.

Back to top of page.

# Configuring libreboot

Before building a ROM in libreboot (or coreboot, for that matter), you need to configure it. This is done using the following inside the source tree:
$ cd coreboot/
$ make menuconfig

If you've already built a kernel before, you know how to use this interface.

Configurations are then saved as files called ".config". Copies of each configuration used for each machine type by the libreboot build scripts are stored in resources/libreboot/config/

## dmidecode

There is certain information that can be useful to enter in particular:

- Local version string
- SMBIOS Serial Number
- SMBIOS Manufacturer
- SMBIOS Version
- SMBIOS Product name

This information can be obtained using:
$ sudo dmidecode
# dmidecode

Specifically, it's good practise to enter the same information for libreboot that you found when running this with the original BIOS or firmware. libreboot has already done this for you. This information is for reference, in the hope that it will be useful.

## ThinkPad X60, X60S and X60 Tablet configuration (file: resources/libreboot/config/x60/config)

- General setup / Expert mode = enable
- Mainboard / Mainboard vendor = Lenovo
- Mainboard / Mainboard model = ThinkPad X60 / X60s / X60t
- Mainboard / ROM chip size = 2048 KB (2 MB)
- Chipset / Include CPU microcode in CBFS = Do not include microcode updates
- Devices / Use native graphics initialization = enable
- Display / Keep VESA framebuffer = disable (disable for text-mode graphics, enable for coreboot vesa framebuffer)
  - Libreboot provides this with text-mode enabled by default, but it automatically patches a copy of the config at build time to enable coreboot framebuffer for a separate set of ROM images, in each machine.
- Generic Drivers / Digitizer = Autodetect
- Generic Drivers / USB 2.0 EHCI debug dongle support = Enable
- Generic Drivers / Enable early (pre-RAM) usbdebug = Enable
- Generic Drivers / Type of dongle = BeagleBone Black
- Generic Drivers / Digitizer = Present
- Console / Send console output to a CBMEM buffer = enable
- Console / USB dongle log output = enable
- Payload / Add a payload = An ELF executable payload
- Payload / Payload path and filename = grub.elf

Now go back into Devices:

- Devices / Run VGA Option ROMs = disable
- Devices / Run Option ROMs on PCI devices = disable

The resulting .config file was saved as resources/libreboot/config/x60/config and is used by the build scripts for this machine.

This configuration is used on all variants: X60, X60S and X60 Tablet.

## ThinkPad T60 configuration (file: resources/libreboot/config/t60/config)

- General setup / Expert mode = enable
- General setup / Local version string = 79ETE7WW (2.27 )
- Mainboard / Mainboard vendor = Lenovo
- Mainboard / Mainboard model = ThinkPad T60 / T60p
- Mainboard / ROM chip size = 2048 KB (2 MB)
- System tables / SMBIOS Serial Number = L3DKE06
- System tables / SMBIOS Version Number = ThinkPad T60
- System tables / SMBIOS Manufacturer = LENOVO
- System tables / SMBIOS Product name = 1951FEG
- Chipset / Include CPU microcode in CBFS = Do not include microcode updates
- Devices / Use native graphics initialization = enable
- Display / Keep VESA framebuffer = disable (disable for text-mode graphics, enable for coreboot vesa framebuffer)
  - Libreboot provides this with text-mode enabled by default, but it automatically patches a copy of the config at build time to enable coreboot framebuffer for a separate set of ROM images, in each machine.
- Generic Drivers / USB 2.0 EHCI debug dongle support = Enable
- Generic Drivers / Enable early (pre-RAM) usbdebug = Enable
- Generic Drivers / Type of dongle = BeagleBone Black
- Console / Send console output to a CBMEM buffer = enable
- Console / USB dongle log output = enable
- Payload / Add a payload = An ELF executable payload
- Payload / Payload path and filename = grub.elf

Go back into Devices:

- Devices / Run VGA Option ROMs = disable
- Devices / Run Option ROMs on PCI devices = disable

The resulting .config file was saved as resources/libreboot/config/t60/config and is used by the build scripts for this machine.

It is believed that the motherboards on 14.1" and 15.1" T60s are the same, so the same configuration is used on both the 14.1" and 15.1" T60s.

## ThinkPad X200 configuration (file: resources/libreboot/config/x200_4mb/config and resources/libreboot/config/x200_8mb/config)

These are saved as two configs, because there are 2 size flash chips: 4MB or 8MB.

- General / Expert mode = enable
- Mainboard / Mainboard vendor = Lenovo
- Mainboard / Mainboard model = ThinkPad X200
- Mainboard / ROM chip size = 4096 KB (4 MB) or 8192 KB (8 MB) depending on flash chip size
- Chipset / Include CPU microcode in CBFS = Do not include microcode updates
- Chipset / Size of CBFS filesystem in ROM = byte size 0x7FD000 (for 8MB flash chip) or 3FD000 (for 4MB flash chip)
- Devices / Use native graphics initialization = enable
- Display / Keep VESA framebuffer = disable (disable for text-mode graphics, enable for coreboot vesa framebuffer)
  - Libreboot provides this with text-mode enabled by default, but it automatically patches a copy of the config at build time to enable coreboot framebuffer for a separate set of ROM images, in each machine.
- Generic Drivers / USB 2.0 EHCI debug dongle support = Enable
- Generic Drivers / Enable early (pre-RAM) usbdebug = Enable
- Generic Drivers / Type of dongle = BeagleBone Black
- Console / Send console output to a CBMEM buffer = enable
- Console / USB dongle log output = enable
- Payload / Add a payload = An ELF executable payload
- Payload / Payload path and filename = grub.elf

Go back and disable option ROMs:

- Devices / Run VGA Option ROMs = disable
- Devices / Run Option ROMs on PCI devices = disable

The resulting .config file was saved as resources/libreboot/config/x200_8mb/config and resources/libreboot/config/x200_4mb/config and is used by the build scripts for this machine.

## MacBook2,1 configuration (file: resources/libreboot/config/macbook21/config)

- General / Expert mode = enable
- General / Local version string = " MB21.88Z.00A5.B07.0706270922" (without the quotes)
- Mainboard / Mainboard vendor = Apple
- Mainboard / Mainboard model = Macbook2,1 ICH7 TESTING
- Mainboard / ROM chip size = 2048 KB (2 MB)
- System tables / SMBIOS Serial Number = W8724XXXXXX
- System tables / SMBIOS Version Number = 1.0
- System tables / SMBIOS Manufacturer = Apple Inc.
- System tables / SMBIOS Product Name = MacBook2,1
- Chipset / Include CPU microcode in CBFS = Do not include microcode updates
- Devices / Use native graphics initialization = enable
- Display / Keep VESA framebuffer = disable (disable for text-mode graphics, enable for coreboot vesa framebuffer)
  - Libreboot provides this with text-mode enabled by default, but it automatically patches a copy of the config at build time to enable coreboot framebuffer for a separate set of ROM images, in each machine.
- Generic Drivers / USB 2.0 EHCI debug dongle support = Enable
- Generic Drivers / Enable early (pre-RAM) usbdebug = Enable
- Generic Drivers / Type of dongle = BeagleBone Black
- Console / Send console output to a CBMEM buffer = enable
- Console / USB dongle log output = enable
- Payload / Add a payload = An ELF executable payload
- Payload / Payload path and filename = grub.elf

Go back and disable option ROMs:

- Devices / Run VGA Option ROMs = disable
- Devices / Run Option ROMs on PCI devices = disable

The resulting .config file was saved as resources/libreboot/config/macbook21/config and is used by the build scripts for this machine. This config is also used for the MacBook1,1.

## QEMU (x86 i440fx/piix4) configuration (file: resources/libreboot/config/qemu_i440fx_piix4/config)

- General / Expert mode = enable
- Mainboard / Mainboard vendor = Emulation
- Mainboard / Mainboard model = QEMU x86 i440fx/piix4 (aka qemu -M pc)
- Mainboard / ROM chip size = 8192 KB (8 MB)
- Devices / Use native graphics initialization = enable (should already be enabled)
- Display / Keep VESA framebuffer = enable (disable for text-mode graphics, enable for coreboot vesa framebuffer)
  - Libreboot provides this with framebuffer enabled by default, but it automatically patches a copy of the config at build time to enable coreboot text-mode for a separate set of ROM images, in each machine.
- Console / Send console output to a CBMEM buffer = enable
- Payload / Add a payload = An ELF executable payload
- Payload / Payload path and filename = grub.elf

Go back and disable option ROMs:

- Devices / Run VGA Option ROMs = disable
- Devices / Run Option ROMs on PCI devices = disable

The resulting .config file was saved as resources/libreboot/config/qemu_i440fx_piix4/config and is used by the build scripts for this machine.

## QEMU (x86 q35/ich9) configuration (file: resources/libreboot/config/qemu_q35_ich9/config)

- General / Expert mode = enable
- Mainboard / Mainboard vendor = Emulation
- Mainboard / Mainboard model = QEMU x86 q35/ich9 (aka qemu -M q35)
- Mainboard / ROM chip size = 8192 KB (8 MB)
- Devices / Use native graphics initialization = enable (should already be enabled)
- Display / Keep VESA framebuffer = enable (disable for text-mode graphics, enable for coreboot vesa framebuffer)
  - Libreboot provides this with framebuffer enabled by default, but it automatically patches a copy of the config at build time to enable coreboot text-mode for a separate set of ROM images, in each machine.
- Console / Send console output to a CBMEM buffer = enable
- Payload / Add a payload = An ELF executable payload
- Payload / Payload path and filename = grub.elf

Go back and disable option ROMs:

- Devices / Run VGA Option ROMs = disable
- Devices / Run Option ROMs on PCI devices = disable

The resulting .config file was saved as resources/libreboot/config/qemu_q35_ich9/config and is used by the build scripts for this machine.

Back to top of page.

# How to build the ROM images!

You don't need to do much, as there are scripts already written for you that can build everything automatically.

You can build libreboot from source on a 32-bit (i686) or 64-bit (x86_64) system. Recommended (if possible): x86_64. On a ThinkPad T60, you can replace the CPU (Core 2 Duo T5600, T7200 or T7600. T5600 recommended) for 64-bit support. On an X60s, you can replace the board with one that has a Core 2 Duo L7400 (you could also use an X60 Tablet board with the same CPU). On an X60, you can replace the board with one that has a Core 2 Duo T5600 or T7200 (T5600 is recommended). All MacBook2,1 laptops are 64-bit, as are all ThinkPad X200, X200S and X200 Tablet laptops. Warning: MacBook1,1 laptops are all 32-bit only.

First, install the build dependencies.

If you downloaded libreboot from git, refer to #build_meta.

If running for the first time, run this:
$ ./buildall (also performs the "./build" step below)
Or if you only want to build dependencies (crossgcc, grub and so on):
$ ./builddeps

If you've already run ./builddeps and/or ./buildall before, you don't need to run them again. Just run that from now on to build the ROM images:
$ ./build

To un-build (clean) the build dependencies that you built before, do the following:
This also deletes the ROM images under ./bin/:
$ ./cleandeps

Note: after running 'cleandeps', you will need to run 'builddeps' or 'buildall' again before you can use 'build'.

After 'build' or 'buildall' has finished, you'll find the ROM images for each machine under ./bin/

## Preparing release archives (optional)

Run that script:
$ ./build-release

If you are building on an i686 host, this will include statically linked 32-bit binaries in the binary release archive that you created, for: nvramtool, cbfstool, bucts, flashrom, ich9deblob, cbmem.

If you are building on an x86_64 host, this will include statically linked 32- and 64-bit binaries for cbmem, ich9deblob, cbfstool and nvramtool, while flashrom and bucts will be included only as 64-bit statically linked binaries. To include a statically linked flashrom and bucts for i686, you will need to build them on a chroot, a virtual machine or a real 32-bit system. You can find the build dependencies for these packages listed in deps-*

armv7l binaries (tested on a BeagleBone Black) are also included in libreboot_bin, for:

- cbfstool
- ich9gen
- ich9deblob
- flashrom

If you are building 32-bit binaries on a live system or chroot (for flashrom/bucts), you can use the following to statically link them:
$ ./builddeps-flashrom static
$ ./builddeps-bucts static

The same as above applies for ARM (except, building bucts on ARM is pointless, and for flashrom you only need the normal executable since the lenovobios_sst and _macronix executables are meant to run on an X60/T60 while lenovo bios is present, working around the security restrictions).

The script mkextbuild will generate a small source tarball called tobuild.tar.xz that contains everything you need (including source) with which to build flashrom/bucts on these hosts. The build-release script will have already executed this script for you, so the archive should already exist.

You'll find that the files libreboot_bin.tar.xz and libreboot_src.tar.xz have been created.

Back to top of page

# How to add SeaBIOS to the ROM images

SeaBIOS isn't really needed since libreboot uses the GRUB payload which is much better (for several reasons), so it is no longer included in the ROM images by default. Instead, you can add it afterwards.

In the supplied binary archives, or in your own (if you did 'build-release') you can add SeaBIOS to the ROM images, along with SeaVGABIOS which is a free/libre Video BIOS implementation that wraps around the 'native graphics initializitation' code in coreboot, for boards that have support for it.

First, install the build dependencies.

Binaries for cbfstool are provided (built from libreboot_src) statically linked under cbfstool/ and the addseabios script (see below) will try to automatically select the right one to use.

Now:
$ ./addseabios

SeaBIOS and SeaVGABIOS (which the build scripts created, and the build-release script put - compiled - inside the binary archive) have now been added to all of the ROM images under ./bin/. A GRUB menuentry will show up when you boot your machine, allowing you to use SeaBIOS.

Back to top of page

Copyright © 2014, 2015 Francis Rowe <info@gluglug.org.uk>
This document is released under the Creative Commons Attribution-ShareAlike 4.0 International Public License and all future versions. A copy of the license can be found at ../license.txt.

This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See ../license.txt for more information.