building coreboot, run emulations, flash firmware, start hacking
Disclaimer: You'll need to bring your own laptop. If you didn't, get it now.
Open Source Firmware Workshop by Patrik Tesarik is licensed under a Creative Commons Attribution 4.0 International License.
These slides & workshop is based on previous work done by:
and would have not been possible without them
Part I
Part II
Part III
Hands-on: Build coreboot for UP²
Hands-on: Run coreboot on UP²
Optional:
Start hacking!
Host processor
firmware
Vendor firmware:
Remember:
Firmware controls our hardware
at sub-OS level
open source firmware
$ git clone --recurse-submodules https://github.com/9elements/coreboot.git $ cd coreboot
20 min
Clone coreboot repository and submodules:
Build the toolchain:
$ make crossgcc-i386 CPUS=`nproc`
Install the following packages:
apt install git make build-essential gnat flex bison libncurses5-dev \ wget zlib1g-dev acpica-tools patch pciutils-dev ccache qemu python \ uuid-dev nasm
dnf install git make gcc-gnat flex bison xz bzip2 gcc g++ ncurses-devel \ wget zlib-devel acpica-tools patch pciutils-devel ccache qemu python \ libuuid-devel nasm
20 min
Select payload:
$ make menuconfig
Open the config menu:
$ make nconfig
$ make xconfig
Add a payload --> (None)
Build:
$ make
Run:
$ qemu-system-i386 -M pc -m 1024M -bios build/coreboot.rom -serial stdio
CC-by-SA Raimond Spekking
CC-by-SA Tobias ToMar Maier
CC-by-SA MOS6502
1980
Today
64KB
512KB
4MB
16MB
512MB
internal
external
internal
external
Baseboard Management Controller
SF100
CC-By-SA Patrick Rudolph
SF600
CC-By-SA Patrick Rudolph
CC-By-SA Patrick Rudolph
CC-By-SA Patrick Rudolph
for hackers: Raspberry PI
CC-By-SA Patrick Rudolph
buspirate and SPI compatible
wiring
SPI flash IC
SPI flash IC
rules for wiring
https://doc.coreboot.org/flash_tutorial/index.html
CPU
Board
10min
general
https://review.coreboot.org/flashrom.git
advice reading firmware
Task:
What you need:
20min
Reading the flash IC:
$ flashrom -pdediprog:voltage=1.8V -r /tmp/dump1.bin
$ flashrom -pdediprog:voltage=1.8V -r /tmp/dump2.bin $ diff /tmp/dump1.bin /tmp/dump2.bin
Writing the flash IC:
$ flashrom -pdediprog:voltage=1.8V -w /tmp/backup.bin
Verify what you got:
$ cd coreboot/util/ifdtool $ make $ ./ifdtool -d /tmp/dump1.bin
but ...
Flash IC
Flash IC
Vendor firmware uses two LBP, but coreboot uses one LBP
We have to patch IFD to support one LBP!
Task:
What you need:
30min
Task:
What you need:
10 min
$ util/ifdtool/ifdtool -x backup.bin
Extract regions from flash dump using the IFD:
$ make -C util/ifdtool
Build ifdtool:
Place BLOBs at:
$ mkdir -p 3rdparty/blobs/mainboard/up/squared/
Create a folder whithin coreboot:
3rdparty/blobs/mainboard/up/squared/ifwi.bin
3rdparty/blobs/mainboard/up/squared/descriptor.bin
Patch IFD at offset 0x1ff and set bit3!
Set the following path in menuconfig:
$ make
fallback/postcar 0xb6800 stage 18272 none
fallback/dsdt.aml 0xbafc0 raw 5581 none
img/coreinfo 0xbc600 simple elf 50932 none
fallback/payload 0xc8d40 simple elf 67438 none
payload_revision 0xd9500 raw 235 none
(empty) 0xd9640 null 11125080 none
bootblock 0xb757c0 bootblock 32768 none
Built up/squared (Squared)
Image written successfully to build/cbfs/fallback/ifwi.bin.tmp.
Image does not contain sub-partition OBBP(6).
Sub-partition IBBP(4) entry IBBL replaced from file build/cbfs/fallback/bootblock.bin.
Image written successfully to build/cbfs/fallback/ifwi.bin.tmp.
W: Written area will abut bottom of target region: any unused space will keep its current contents
Final output:
coreboot rom is placed:
./build/coreboot.rom
2min
CC 4.0
CC 4.0
Task:
What you need:
15min
Flashing coreboot on UP²:
$ flashrom -pdediprog:voltage=1.8 --fmap -i COREBOOT -w build/coreboot.rom
Flashing update IFD on UP²:
$ flashrom -pdediprog:voltage=1.8 --ifd -i ifd -w build/coreboot.rom
linuxboot.org
u-root.tk
Task:
What you need:
45min
Note: The coreboot toolchain isn't used for Linux paylods
Linux Kernel gets build with '-fstack-protector' in host toolchain.
This breaks booting the target kernel while loading x86/purgatory.
"Fix":
Disable stack-protection in Kconfig
Run:
$ cd payloads/external/Linuxboot/linuxboot/kernel-*
$ make menuconfig
Architecture-dependend options >
[ ] Stack Protector Buffer overflow protection
Run:
cd $your_coreboot_dir
make CPUS=$(nproc)
$ util/ifdtool/ifdtool -f layout backup.bin
Extract the layout from IFD:
Use the layout in flashrom:
$ flashrom -pdediprog:voltage=1.8 -w backup.bin -l layout -i bios
Starting with flashrom 1.0:
$ flashrom -pdediprog:voltage=1.8 -w backup.bin --ifd -i bios
$ cat /src/mainboard/up/squared/upsquared.fmd
FLASH 16M {
SI_DESC@0x0 0x1000
SI_BIOS@0x1000 0xefe000 {
IFWI@0x0 0x2ff000
OBB@0x2ff000 0xbff000 {
FMAP@0x0 0x800
UNIFIED_MRC_CACHE@0x800 0x21000 {
RECOVERY_MRC_CACHE@0x0 0x10000
RW_MRC_CACHE@0x10000 0x10000
RW_VAR_MRC_CACHE@0x20000 0x1000
}
CONSOLE@0x21800 0x20000
COREBOOT(CBFS)@0x41800 0xb7d800
BIOS_UNUSABLE@0xbbf000 0x40000
}
}
SI_DEVICEEXT@0xeff000 0x101000 {
DEVICE_EXTENSION@0x0 0x100000
UNUSED_HOLE@0x100000 0x1000
}
}
$ flashrom --fmap -i RW_SECTION_B -w coreboot.rom
Use flashrom -r backup.rom to read the full image
Use ifdtool -x backup.rom to extract Intel IFD and Intel ME
Copy BLOBs to 3rdparty/blobs
Integrate them into the build
Where to find blobs: