Random posts

That no one cares about

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
# run container
systemd-nspawn -bD ./container-directory/ --bind=/shared/directory/for/blobs

# inside container
apt-get install git build-essential gnat flex bison libncurses5-dev wget zlib1g-dev # coreboot dependencies
apt-get install pkg-config unifont # grub2 dependencies

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

make crossgcc-x64 CPUS=$(nproc) # replace x64 with i386 for 32bit x86 system

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 do_this_at_least_3_times_and_compare.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 coreboot.rom 

# and copy the binary to X230
cp coreboot.rom.new /somewhere/to/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' {
	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 'arch fallback' {
	root=(ahci0,gpt1)
	echo	'Loading linux fallback'
	linux	/vmlinuz-linux root=/dev/sda2 rw
	echo	'Loading initramfs fallback'
	initrd /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
}

check out https://puri.sm/posts/librem-13-coreboot-report-february-25th-2017/ needs VGA blob

sources:
  1. coreboot wiki (now 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