Archive Tags RSS Feed

 

Entries tagged coreboot

Flashing coreboot on a Lenovo Thinkpad X220 with a ch341a USB programmer Tutorial

2 April 2019 17:57

In this tutorial, we will go through the steps to get coreboot compiled and flashed on a Lenovo Thinkpad X220 laptop. We'll also change the Wifi card so that Wifi will work with a libre kernel driver.

Prerequisites

Prerequisites

Things you need:

  • Lenovo Thinkpad X220
  • Atheros AR9382 AR5BHB116 Mini PCIE Dual Band Wifi card
  • ch341a USB programmer
  • Pomona 5250 SOIC-8 clip
  • 6 x 10 cm female - female jumper wires
  • Screwdriver

Files needed:

dejavusansmono.pf2
grub.cfg
background.jpg

For more information about DejaVu Fonts, see:
https://dejavu-fonts.github.io/

For DejaVu Font license, see:
https://dejavu-fonts.github.io/License.html

'background.jpg' is borrowed from the libreboot project and it's license information is as follows:

These images are based on http://libreboot.org/logo/logo.svg
which is Copyright 2014 Marcus Moeller and released under CC-0
https://creativecommons.org/publicdomain/zero/1.0/legalcode

Packages needed to compile flashrom/coreboot/grub

sudo apt-get install git build-essential gnat flex bison libncurses5-dev wget libpci-dev libusb-dev libftdi1 libftdi-dev unifont zlib1g-dev

Compile flashrom

Clone flashrom git repository:

git clone https://review.coreboot.org/flashrom.git

Compile flashrom:

cd flashrom
make -j4
sudo make install
sudo cp /usr/local/sbin/flashrom /usr/local/bin/

Compile GRUB

See 'Prerequisites' above for the files needed.

Clone GRUB git repository:

git clone https://git.savannah.gnu.org/git/grub.git

Compile GRUB:

cd grub
./bootstrap
./configure --with-platform=coreboot
make -j4

Create 'pack-payload-minimal.sh' script file:

touch pack-payload-minimal.sh
chmod +x pack-payload-minimal.sh

Paste the following in 'pack-payload-minimal.sh':

#! /bin/bash

# ./pack-payload-minimal.sh – To be invoked within GRUB project folder, packs
# an executable elf payload file for the coreboot project, using just one
# keyboard layout file. Adapt “settings” to your needs. Specify a lighter
# pf2-fontfile if available on your system.

# settings
elf_output="grub2.elf"
#pf2_fontfile="unicode.pf2"
pf2_fontfile="dejavusansmono.pf2"
keyboard_layout="se"
grub_modules="cbfs"

# generate keyboard layout
ckbcomp "${keyboard_layout}" | ./grub-mklayout -o "${keyboard_layout}.gkb"

# pack the GRUB payload file
./grub-mkstandalone \
        --grub-mkimage=./grub-mkimage \
        -O i386-coreboot \
        -o "${elf_output}" \
        -d grub-core \
        --fonts= \
        --themes= \
        --locales= \
        --modules="${grub_modules}" \
        /boot/grub/grub.cfg=coreboot.cfg \
        /boot/grub/fonts/${pf2_fontfile}="${pf2_fontfile}" \
        /boot/grub/layouts/${keyboard_layout}.gkb="${keyboard_layout}.gkb"

# message
echo "Payload ${elf_output} has been packed with:"
echo " * fontfile: ${pf2_fontfile}"
echo " * keyboard layout: ${keyboard_layout}"
echo " * GRUB modules, to be preloaded: ${grub_modules}"

# code snippet suggestion
echo "Don't forget to add 'keymap ${keyboard_layout}' to your GRUB Configuration File."

# clean up
rm "${keyboard_layout}.gkb"

Execute the script to create 'grub2.elf' file:

./pack-payload-minimal.sh

Connect ch341a USB programmer to flash chip

Remove the following parts to access the flash chip:

Battery
Keyboard
Palmrest

Connect ch341a USB programmer

Connect Pomona 5250 to flash chip like this:

Screen (furthest from you)
             __
  MOSI  5 --|  |-- 4  GND
   CLK  6 --|  |-- 3  N/C
   N/C  7 --|  |-- 2  MISO
   VCC  8 --|__|-- 1  CS

   Edge (closest to you)

ch341a USB programmer connected

Read Factory BIOS

Read Factory BIOS 3 times:

sudo flashrom -p ch341a_spi -r factory_bios_01.rom -V
sudo flashrom -p ch341a_spi -r factory_bios_02.rom -V
sudo flashrom -p ch341a_spi -r factory_bios_03.rom -V

Make sure checksums are identical:

sha512sum *.rom

Download coreboot

Download coreboot:

wget https://coreboot.org/releases/coreboot-4.10.tar.xz
wget https://coreboot.org/releases/coreboot-blobs-4.10.tar.xz

Extract coreboot and blobs needed:

tar xvf coreboot-4.10.tar.xz
tar xvf coreboot-blobs-4.10.tar.xz --strip-components=1 -C coreboot-4.10

Create folder to hold 'descriptor/gbe/me.bin' files:

mkdir -pv coreboot-4.10/3rdparty/blobs/mainboard/lenovo/x220/

Extract blob files from Factory BIOS (see 'flashrom/util/ich_descriptors_tool' folder:

cd ~/misc-src/flashrom/util/ich_descriptors_tool
./ich_descriptors_tool -f your/path/to/factory_bios.rom -d

Copy blob files to coreboot folder:

cp factory_bios.rom.Descriptor.bin coreboot-4.10/3rdparty/blobs/mainboard/lenovo/x220/descriptor.bin
cp factory_bios.rom.GbE.bin coreboot-4.10/3rdparty/blobs/mainboard/lenovo/x220/gbe.bin
cp factory_bios.rom.ME.bin coreboot-4.10/3rdparty/blobs/mainboard/lenovo/x220/me.bin

Setup and compile coreboot

Enter coreboot folder:

cd coreboot-4.10

Build toolchain needed first (this will take a long time, be patient):

make crossgcc-i386 CPUS=4

coreboot settings menu:

make menuconfig

Set the following options:

NOTE: Leave default values as is and specifically set the following
options:

general  --|
           |-[*] Use CMOS for configuration values
mainboard -|
           |-Mainboard vendor (Lenovo)
           |-Mainboard model (ThinkPad X220)
           |-ROM chip size (8192 KB (8 MB))
           |-(0x300000) Size of CBFS filesystem in ROM
chipset ---|
           |-Include CPU microcode in CBFS (Do not include microcode updates)
           |-[*] Add Intel descriptor.bin file (leave default path as is)
           |-(3rdparty/blobs/mainboard/$(MAINBOARDDIR)/descriptor.bin) Path and filename of the descriptor.bin file
           |-[*] Add Intel ME/TXE firmware (leave default path as is)
           |-(3rdparty/blobs/mainboard/$(MAINBOARDDIR)/me.bin) Path to management engine firmware
           |-    [*] Verify the integrity of the supplied ME/TXE firmware
           |-    [*] Strip down the Intel ME/TXE firmware
           |-[*] Add gigabit ethernet firmware (leave default path as is)
           |-(3rdparty/blobs/mainboard/$(MAINBOARDDIR)/gbe.bin) Path to gigabit ethernet firmware
Devices ---|
           |-Graphics initialization (Use libgfxinit)
           |-Display
           |-    Framebuffer mode (Linear "high-resolution" framebuffer)
payload ---|
           |-Add a payload (An ELF executable payload)
           |-"(grub2.elf)" Payload path and filename

If you want to include CPU microcode updates:

chipset ---|
           |-Include CPU microcode in CBFS (Generate from tree)

This will create a '.config' file containing all settings.

Compile coreboot:

make -j4

This will create 'build/coreboot.rom' image with the size of 8mb.

Add custom files to 'coreboot.rom' image

Add 'grub.cfg' and 'background.jpg' to coreboot.rom. See 'Prerequisites' above for the files needed.

Make sure 'cbfstool' is built:

cd coreboot-4.10/util/cbfstool
make -j4

Add custom GRUB configuration file:

./cbfstool ../../build/coreboot.rom add -t raw -n etc/grub.cfg -f your/path/to/grub.cfg

Check so that 'etc/grub.cfg' exists in coreboot.rom:

./cbfstool ../../build/coreboot.rom print

Add background image:

./cbfstool ../../build/coreboot.rom add -t raw -n background.jpg -f your/path/to/background.jpg

Check so that 'background.jpg' exists in coreboot.rom:

./cbfstool ../../build/coreboot.rom print

Tweak parameters in 'cmos.default'

Make sure 'nvramtool' is built:

cd coreboot-4.10/util/nvramtool
make -j4

Get an overview of tweakable parameters:

./nvramtool -C ../../build/coreboot.rom -a

Tweak values we need:

./nvramtool -C ../../build/coreboot.rom -w gfx_uma_size=224M
./nvramtool -C ../../build/coreboot.rom -w wwan=Disable
./nvramtool -C ../../build/coreboot.rom -w bluetooth=Disable
./nvramtool -C ../../build/coreboot.rom -w touchpad=Disable

Check specific parameter possible values:

./nvramtool -C ../../build/coreboot.rom -e gfx_uma_size

Make sure values are changed:

./nvramtool -C ../../build/coreboot.rom -a

Done! Now it's time to flash the new 'coreboot.rom' image!

Flash coreboot image

See 'Connect ch341a USB programmer to flash chip' for details on how to connect ch341a USB programmer.

Flash coreboot using ch341a USB programmer:

sudo flashrom -p ch341a_spi -w coreboot.rom -V

Change Wifi card

Remove the following parts to access the Wifi card:

Battery
Keyboard
Palmrest

See 'Connect ch341a USB programmer to flash chip' for details on where the Wifi card is located.

Congratulations! We're done. Now you can install a libre distro such as Debian GNU/Linux.

Recommended reading

https://www.coreboot.org/
https://libreboot.org/
https://flashrom.org/Flashrom
https://www.thinkwiki.org/wiki/Category:X220
https://download.lenovo.com/ibmdl/pub/pc/pccbbs/mobiles_pdf/0a60739.pdf
https://github.com/boseji/CH341-Store
https://libreboot.org/docs/gnulinux/encrypted_debian.html
https://dejavu-fonts.github.io/
https://dejavu-fonts.github.io/License.html

 

Flashing coreboot on Gigabyte GA-G41M-ES2L with a ch341a USB programmer Tutorial

3 April 2019 16:59

In this tutorial, we will go through the steps to get coreboot compiled and flashed on Gigabyte GA-G41M-ES2L.

Prerequisites

Prerequisites

Things you need:

  • Gigabyte GA-G41M-ES2L
  • ch341a USB programmer
  • Pomona 5250 SOIC-8 clip
  • 6 x 10 cm female - female jumper wires

Files needed:

dejavusansmono.pf2
grub.cfg

For more information about DejaVu Fonts, see:
https://dejavu-fonts.github.io/

For DejaVu Font license, see:
https://dejavu-fonts.github.io/License.html

Packages needed to compile flashrom/coreboot/grub

sudo apt-get install git build-essential gnat flex bison libncurses5-dev wget libpci-dev libusb-dev libftdi1 libftdi-dev unifont zlib1g-dev

Compile flashrom

Clone flashrom git repository:

git clone https://review.coreboot.org/flashrom.git

Compile flashrom:

cd flashrom
make -j4
sudo make install
sudo cp /usr/local/sbin/flashrom /usr/local/bin/

Compile GRUB

See 'Prerequisites' above for the font file needed.

Clone GRUB git repository:

git clone https://git.savannah.gnu.org/git/grub.git

Compile GRUB:

cd grub
./bootstrap
./configure --with-platform=coreboot
make -j4

Create 'pack-payload-minimal.sh' script file:

touch pack-payload-minimal.sh
chmod +x pack-payload-minimal.sh

Paste the following in 'pack-payload-minimal.sh':

#! /bin/bash

# ./pack-payload-minimal.sh – To be invoked within GRUB project folder, packs
# an executable elf payload file for the coreboot project, using just one
# keyboard layout file. Adapt “settings” to your needs. Specify a lighter
# pf2-fontfile if available on your system.

# settings
elf_output="grub2.elf"
#pf2_fontfile="unicode.pf2"
pf2_fontfile="dejavusansmono.pf2"
keyboard_layout="se"
grub_modules="cbfs"

# generate keyboard layout
ckbcomp "${keyboard_layout}" | ./grub-mklayout -o "${keyboard_layout}.gkb"

# pack the GRUB payload file
./grub-mkstandalone \
        --grub-mkimage=./grub-mkimage \
        -O i386-coreboot \
        -o "${elf_output}" \
        -d grub-core \
        --fonts= \
        --themes= \
        --locales= \
        --modules="${grub_modules}" \
        /boot/grub/grub.cfg=coreboot.cfg \
        /boot/grub/fonts/${pf2_fontfile}="${pf2_fontfile}" \
        /boot/grub/layouts/${keyboard_layout}.gkb="${keyboard_layout}.gkb"

# message
echo "Payload ${elf_output} has been packed with:"
echo " * fontfile: ${pf2_fontfile}"
echo " * keyboard layout: ${keyboard_layout}"
echo " * GRUB modules, to be preloaded: ${grub_modules}"

# code snippet suggestion
echo "Don't forget to add 'keymap ${keyboard_layout}' to your GRUB Configuration File."

# clean up
rm "${keyboard_layout}.gkb"

Execute the script to create 'grub2.elf' file:

./pack-payload-minimal.sh

Connect ch341a USB programmer to flash chip

Connect ch341a USB programmer

Connect Pomona 5250 to flash chip named 'M_BIOS' like this:

             __
    CS  5 --|  |-- 4  VCC
  MISO  6 --|  |-- 3  N/C
   N/C  7 --|  |-- 2  CLK
   GND  8 --|__|-- 1  MOSI

ch341a USB programmer connected

Read Factory BIOS

Read Factory BIOS 3 times:

sudo flashrom -p ch341a_spi -r factory_bios_01.rom -V
sudo flashrom -p ch341a_spi -r factory_bios_02.rom -V
sudo flashrom -p ch341a_spi -r factory_bios_03.rom -V

Make sure checksums are identical:

sha512sum *.rom

Download coreboot

Download coreboot:

wget https://coreboot.org/releases/coreboot-4.10.tar.xz

Extract coreboot:

tar xvf coreboot-4.10.tar.xz

Setup and compile coreboot

Enter coreboot folder:

cd coreboot-4.10

Build toolchain needed first (this will take a long time, be patient):

make crossgcc-i386 CPUS=4

coreboot settings menu:

make menuconfig

Set the following options:

NOTE: Leave default values as is and specifically set the following
options:

mainboard ---------|
                   |-Mainboard vendor (GIGABYTE)
                   |-Mainboard model (GA-G41M-ES2L)
                   |-ROM chip size (1024 KB (1 MB))
                   |-(0x100000) Size of CBFS filesystem in ROM
chipset -----------|
                   |-Include CPU microcode in CBFS (Do not include microcode updates)
Devices -----------|
                   |-Graphics initialization (Use libgfxinit)
                   |-Display
                   |-    Legacy VGA text mode
Generic Drivers ---|
                   |-(XX:XX:XX:XX:XX:XX) Realtek rt8168 mac address
payload -----------|
                   |-Add a payload (An ELF executable payload)
                   |-"(grub2.elf)" Payload path and filename

Check the mac address for the onboard RT8168 network card and enter that in 'Generic Drivers -> Realtek rt8168 mac address'. My board is rev. 1.1 and it didn't find the onboard network card at all. If this happens to you, just leave default mac address as is and install a PCI or PCI express network card instead. I'm using a PCI network card 'D-Link DGE-528T' which uses RTL8169 kernel driver. Do some research beforehand to make sure your network card will work with default libre kernel drivers.

This will create a '.config' file containing all settings.

Compile coreboot:

make -j4

This will create 'build/coreboot.rom' image with the size of 1mb.

Add custom files to 'coreboot.rom' image

Add 'grub.cfg' to coreboot.rom. See 'Prerequisites' above for the file needed.

Make sure 'cbfstool' is built:

cd coreboot-4.10/util/cbfstool
make -j4

Add custom GRUB configuration file:

./cbfstool ../../build/coreboot.rom add -t raw -n etc/grub.cfg -f your/path/to/grub.cfg

Check so that 'etc/grub.cfg' exists in coreboot.rom:

./cbfstool ../../build/coreboot.rom print

Done! Now it's time to flash the new 'coreboot.rom' image!

Flash coreboot image

See 'Connect ch341a USB programmer to flash chip' for details on how to connect ch341a USB programmer.

Flash coreboot using ch341a USB programmer:

sudo flashrom -p ch341a_spi -w coreboot.rom -V

Additional parts needed

To build a desktop/server the following additional parts are needed:

Desktop case
Power supply
CPU
CPU Fan
Memory
Harddrive

Here's the parts I used to build a server:

Desktop case: Fractal Design Define R6 Gunmetal
Power supply: Corsair RM750X 750W v2
CPU: Intel Core 2 Quad Q9550 2,83 GHz 12M
CPU Fan: Arctic Cooling Freezer 7 Pro rev.2
Memory: Corsair 2 x 2 GB DDR2 800 (PC2-6400) Memory
Network card: D-Link DGE-528T PCI (RTL8169 kernel driver)
Harddrive: Samsung 850 EVO 250GB SSD harddrive
PCI Express to USB 3.0 4-Port PCI Express Expansion Card Adapter Hub VIA 5Gbps
PCI Express SATA 3 Controller Card, 2 Port PCIe SATA III 6GB/s Internal Ada L80

The parts were carefully choosen so that the server would be as close to completely silent as possible and be able to run 100% free/libre software.

For a list of compatible CPU's (socket LGA 775), see:
https://en.wikipedia.org/wiki/List_of_Intel_Core_2_microprocessors

The onboard network card might not work by default, and if so, just get a PCI or PCI Express network card.

Congratulations! We're done. Now you can install a libre distro such as Debian GNU/Linux.

Recommended reading

https://www.coreboot.org/
https://libreboot.org/
https://flashrom.org/Flashrom
https://github.com/boseji/CH341-Store
https://libreboot.org/docs/gnulinux/encrypted_debian.html
https://en.wikipedia.org/wiki/List_of_Intel_Core_2_microprocessors
https://dejavu-fonts.github.io/
https://dejavu-fonts.github.io/License.html