Lenovo T420 Coreboot W/Raspberry Pi
by jkaye99 in Circuits > Computers
11931 Views, 28 Favorites, 0 Comments
Lenovo T420 Coreboot W/Raspberry Pi
Coreboot is an open source bios replacement. This guide will describe the steps needed to install it on a Lenovo T420.
Before you start you should be comfortable using a Linux terminal as well as disassembling your laptop.
There is a chance that this will brick your laptop you do this at your own risk.
Supplies
- Ponoma 5250 Test Clip - For connecting to the bios chip.
- Female to Female Breadboard Jumper Cables - Also known as Dupont wires.
- Phillips Screwdriver
- Small Pliers, or 5.0 mm hex bit.
- Thermal compound
- Isopropyl alcohol
- Cotton Swabs
- Lenovo T420
- Computer running Linux. "Main PC"
- Raspberry Pi(3 or 4) - running the latest version or Raspberry Pi OS - Instructions on installing can be found here.
- T420 Hardware Maintenance Manual
Update the Embedded Controller on the T420
It is a good idea to update the Embedded Controller to the latest version. The easiest way to do this is install the latest version of the factory bios. Coreboot is unable to touch the EC. You will be unable to update it after flashing unless you revert to the factory bios.
Prepare the Raspberry Pi for Flashing. (ON RPI)
In order to read/write to the bios chip you need to enable some kernel modules.
Access the raspberry pi config utility.
sudo raspi-config
Under interface options enable :
- P2 SSH - if you will be running the pi headless
- P4 SPI
- P5 I2C
- P8 Remote GPIO - If using ssh to connect to the pi
Prepare the 'Main' Computer for Building Coreboot (On Main PC)
First thing to do is install the dependencies needed to build coreboot.
For a Debian based system
sudo apt install git build-essential gnat flex bison libncurses5-dev wget zlib1g-dev
For an Arch based system
sudo pacman -S base-devel gcc-ada flex bison ncurses wget zlib git
Make a directory in your home dir to work in. For this example I will be calling it 'work'. You will also want a directory to store the factory images. I will call that directory 'roms' You can do this in one line to save time
mkdir -p ~/work/roms
Move into the work directory
cd ~/work
Download the latest version of ME_Cleaner from github
git clone https://github.com/corna/me_cleaner
Download the latest version of Coreboot
git clone https://review.coreboot.org/coreboot
Move into the coreboot directory
cd ~/work/coreboot
Download the required submodules
git submodule update --init --checkout
Make a directory to hold some files specific to your T420 it will be needed later.
mkdir -p ~/work/coreboot/3rdparty/blobs/mainboard/lenovo/t420
Build the ifd tool. This will be used to split the factory bios into it's different regions.
cd ~/work/coreboot/utils/ifdtool make
Wire Up the Clip.
Use the 6 female to female wire to connect the clip to the Pi
Bios 1 > Pi 24
Bios 2 > Pi 21
Bios 4 > Pi 25
Bios 5 > Pi 19
Bios 7 > Pi 23
Bios 8 > Pi 17
Pins 3 and 7 on the Bios are not used.
Access the Bios Chip
The bios chip is located under the roll cage. In order to access it you will need to remove the mother board.
The Hardware Maintenance Manual can provide instructions if you are having trouble figuring it out.
I have included my teardown images.They we're never intended for public viewing (my handwriting is horrible sorry) but what the heck they may help.
Connect the Clip to the Bios Chip
With the Pi powered OFF connect the clip to the bios chip.
Read the Flash Chip (On RPI)
Power on the Pi
Create a roms directory and move to it .
mkdir -p ~/work/roms cd ~/work/roms
To read and write the chip you will need to use a program called Flashrom. First make sure it is installed
sudo apt install flashrom
Use flashrom to probe the chip and make sure it is connected
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128
Read the factory bios off the chip 3 times and save them as factory1.rom factory2.rom factory3.rom
Use the -c option to specify your flash chip. Make sure to enter everything between the quotes
Each read will take some time depending on the chip it could be between 30-45 min each read. Dont worry if it seems like the pi is hung.
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c <chip name> -r factory1.rom
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c <chip name> -r factory2.rom
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c <chip name> -r factory3.rom
Compare the 3 Files (On RPI)
Next you want to compare the 3 files to make sure you had a good read / connections
sha512sum factory*.rom
If they all match copy them to the main computer in the ~/work/roms directory.
Power off the Pi. You can leave the clip connected.
Clean the ME (On Main PC)
Move to ~/work/roms
cd ~/work/roms
The factory roms should not be edited. Make a copy of one of them to clean.
cp factory1.rom cleaned.rom
Clean the IME on cleaned .rom
~/work/me_cleaner/me_cleaner.py -S cleaned.rom
Split the Rom Image. (On Main PC)
The bios chip is split into 4 regions. You need to split the cleaned.rom image into its different regions with the ifd tool provided by coreboot
~/work/coreboot/utils/ifdtool/ifdtool -x cleaned.rom
This will produce 4 files. We need to rename 3 of them and can delete 1
Rename the descriptor region
mv flashregion_0_flashdescriptor.bin descriptor.bin
Delete the bios region - It will be replaced with coreboot.
rm flashregion_1_bios.bin
Rename the GBE region
mv flashregion_2_gbe.bin gbe.bin
Rename the ME region
mv flashregion_3_me.bin me.bin
Copy the files to the coreboot directory
cp descriptor.bin gbe.bin me.bin ~/work/coreboot/3rdparty/blobs/mainboard/lenovo/t420/
Configure the Coreboot Image. (On Main PC)
Move to the coreboot directory
cd ~/work/coreboot
Configure coreboot.
make nconfig
This will bring up the Coreboot config editor. Most of the default settings are fine, but there are a few that can be added. This is a very basic config. More advanced options such as splash screens, vga roms , alternate payloads are available. These options are beyond the scope of this guide.
General Setup
- Use CMOS for configuration values
Mainboard
- Mainboard vendor >>> Select >> Lenovo
- Mainboard model >>> Select >>> T420
Chipset
- Add Intel descriptor.bin file
- Add Intel ME/TXE firmware
- Add gigabit ethernet configuration
Devices
- Enable PCIe Clock Power Management
- Enable PCIe ASPM L1 SubState
Generic Driver
- PS/2 keyboard init
Build Coreboot (On Main PC)
Time to compile!
First built the gcc toolchain
make crossgcc-i386 CPUS=X
X = the number of threads your CPU has.
Build coreboot
make iasl make
This will produce a file ~/work/coreboot/build/coreboot.rom.
Power on the Pi and copy that file to your ~/work/roms directory.
Write Coreboot to T420 (On RPI)
Move to the roms directory
cd ~/work/roms
Probe the chip to make sure its detected
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128
Write the coreboot image. This will take longer then reading the image.
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c <chip name> -w coreboot.rom
After the write is verified power off the pi. Remove the Clip and reassemble the T420.
Congrats you have just flashed Coreboot.