Skip to content

Coreboot x230 GRUB2 flashing process

Documented here because I tend to forget all the steps every 6 months.

Notes:
  1. Memtest86+ doesn’t work as of ~20 March 2019.
  2. GRUB doesn’t display any message on boot (overall good thing, before this forced me to compile it outside of coreboot)

This is setup I found on coreboot’s mailing list, uses systemd-nspawn (most systemd distros should work fine) but as always I only test on Arch.

Titles in bold are to be run on machine you build coreboot on, italics on X230.

Create systemd container

1
2
3
4
5
6
7
8
9
cd /your/chosen/directory
mkdir container-directory
debootstrap stable ./container-directory/ https://deb.debian.org/debian/

# run container
systemd-nspawn -D ./container-directory/
# inside container
passwd
logout

Prepare container

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# run container
systemd-nspawn -bD ./container-directory/ --bind=/shared/directory/for/blobs

# inside container
apt install ca-certificates # fix certificates (wtf)
apt-get install -y git build-essential gnat flex bison libncurses5-dev wget zlib1g-dev # coreboot dependencies
apt-get install -y pkg-config unifont autoconf gettext automake autopoint libfreetype6-dev python # grub2 dependencies
apt-get install -y rename # needed for later step

git clone https://review.coreboot.org/coreboot.git
cd coreboot
git submodule update --init --checkout # might not be needed

make crossgcc-x64 CPUS=$(nproc) # might not be needed
make crossgcc-i386 CPUS=$(nproc)

Compile and install ifdtool

1
2
3
cd ~/coreboot/util/ifdtool
make
make install

Get old coreboot rom

1
2
3
4
5
6
7
8
9
# read previous coreboot into file
# iomem=relaxed in boot options needed
sudo flashrom -p internal -r one.bin
sudo flashrom -p internal -r two.bin
sudo flashrom -p internal -r three.bin
sudo flashrom -p internal -r four.bin

# compare them and if they all match proceed with one
cp coreboot.bin /shared/directory/for/blobs

Extract rom

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
mkdir ~/blobs
cp /shared/directory/for/blobs/coreboot.bin ~/blobs
cd ~/blobs

# extract old coreboot
ifdtool -x coreboot-grub-somedate.bin

# prepare folders with blobs for coreboot
mkdir -p ~/coreboot/3rdparty/blobs/mainboard/lenovo/x230
mv ~/blobs/*.bin ~/coreboot/3rdparty/blobs/mainboard/lenovo/x230
cd ~/coreboot/3rdparty/blobs/mainboard/lenovo/x230

# Strip the first 14 characters from the filename (flashregion_#_)
rename 's/.{14}//' *.bin

mv flashdescriptor.bin descriptor.bin
mv intel_me.bin me.bin

Config

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
make nconfig # or menuconfig

# I'm only listing changes from default here: 

General setup -->
	Use CMOS for configuration values
	Allow use of binary-only repository # might not be needed

Mainboard -->
	Mainboard vendor: Lenovo
	Mainboard model: ThinkPad X230

Chipset -->
	Add Intel descriptor.bin file
	Add Intel ME/TXE firmware
		Verify the integrity of the supplied ME/TXE firmware
		Strip down the Intel ME/TXE firmware # read the warning
	Add gigabit ethernet configuration

Devices -->
	Display
		Framebuffer mode: Linear "high-resolution" framebuffer # you can also lower max resolution
	Enable PCIe Clock Power Management # no idea if important or needed
	Enable PCIe ASPM L1 SubState # no idea if important or needed

Generic Drivers -- >
	PS/2 keyboard init

Payload -->
	Add a payload: GRUB2
	GRUB2 version: pick something stable
	Extra modules to include in GRUB image: usbserial_pl2303 usbserial_ftdi # GRUB spits out errors on boot if not present
	Include GRUB2 runtime config file into ROM image: /root/grub.cfg # bottom of this page
	Secondary Payloads
		Load coreinfo as a secondary payload
		Load Memtest86+ as a secondary payload
		Load nvramcui as a secondary payload
	

Prepare image for flashing

1
2
3
4
5
6
7
8
# compile
make

# unlock it so you can update with flashrom
ifdtool -u build/coreboot.rom 

# and copy the binary to X230
cp build/coreboot.rom.new /somewhere/on/x230

Flash

1
2
sudo flashrom -p internal -r coreboot.rom.new
# if flashrom outputs any errors do not reboot! 

~/grub.cfg
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
timeout_style=hidden
timeout=1

default=0

insmod ahci
insmod part_msdos
insmod part_gpt

menuentry 'arch zen' {
	root=(ahci0,gpt1)
	echo	'Loading linux'
	linux	/vmlinuz-linux-zen root=/dev/sda2 rw quiet acpi_backlight=none
	echo	'Loading initramfs'
	initrd /intel-ucode.img /initramfs-linux-zen.img
}

menuentry 'arch' {
	root=(ahci0,gpt1)
	echo	'Loading linux'
	linux	/vmlinuz-linux root=/dev/sda2 rw quiet acpi_backlight=none
	echo	'Loading initramfs'
	initrd /intel-ucode.img /initramfs-linux.img
}

menuentry 'settings' {
	set root='(cbfsdisk)'
	echo    'Loading img/nvramcui'
	chainloader /img/nvramcui
}

menuentry 'info' {
	set root='(cbfsdisk)'
	echo    'Loading img/coreinfo'
	chainloader /img/coreinfo
}

menuentry 'memtest' {
	set root='(cbfsdisk)'
	echo    'Loading img/memtest'
	chainloader /img/memtest
}

defconfig:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
CONFIG_VENDOR_LENOVO=y
# CONFIG_POST_DEVICE is not set
CONFIG_HAVE_IFD_BIN=y
CONFIG_BOARD_LENOVO_X230=y
CONFIG_PCIEXP_L1_SUB_STATE=y
CONFIG_PCIEXP_CLK_PM=y
CONFIG_H8_SUPPORT_BT_ON_WIFI=y
CONFIG_HAVE_ME_BIN=y
CONFIG_USE_ME_CLEANER=y
CONFIG_HAVE_GBE_BIN=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_DRIVERS_PS2_KEYBOARD=y
CONFIG_PAYLOAD_GRUB2=y
CONFIG_GRUB2_EXTRA_MODULES="usbserial_pl2303 usbserial_ftdi"
CONFIG_GRUB2_INCLUDE_RUNTIME_CONFIG_FILE=y
CONFIG_GRUB2_RUNTIME_CONFIG_FILE="/root/grub.cfg"
CONFIG_COREINFO_SECONDARY_PAYLOAD=y
CONFIG_MEMTEST_SECONDARY_PAYLOAD=y
CONFIG_NVRAMCUI_SECONDARY_PAYLOAD=y
sources:
  1. coreboot wiki (still being retired)
  2. https://kennyballou.com/blog/2017/01/coreboot-x230/
  3. https://www.chucknemeth.com/flash-lenovo-x230-coreboot/
  4. https://thiccpad.blogspot.com/2018/12/coreboot-x220-guide.html