Flashing Coreboot on the ThinkPad X220 using an Arch Linux Installed computer with CH341a usb Programmer.

Prepare 2nd Computer to build coreboot to flash the bios

Install Flashrom

sudo pacman -Syu  
sudo pacman -S flashrom

Install dependencies needed to build coreboot

sudo pacman -S base-devel gcc-ada flex bison ncurses wget zlib git

Clone coreboot repo and update submodules
( coreboot directory must not already exist in home directory)

cd ~
git clone https://review.coreboot.org/coreboot
cd ~/coreboot
git submodule update --init --checkout

Clone the latest version of me_cleaner repo

git clone https://github.com/corna/me_cleaner

Create directory for binary blobs

mkdir -p ~/coreboot/3rdparty/blobs/mainboard/lenovo/x220

Build and compile ifdtool

cd ~/coreboot/util/ifdtool
make

Remove X220 Keyboard / palmrest and expose flash chip

Disconnect power and Remove the battery.
Remove Keyboard:
Remove the two screws that secure keyboard  https://pcsupport.lenovo.com/ch/en/solutions/aa6a9228-d6ae-4a26-8b10-c8264b601be3
Remove Palmrest : 
Remove the five screws to secure the palm rest.  https://support.lenovo.com/ch/en/solutions/pd100776-removal-and-installation-steps-of-palm-rest-thinkpad-x220-tablet-and-x220i-tablet
Expose bios chip as in pic below :
charset=InvalidCharsetId e_mode”:”AutoModule”,”faces”:[]}

Hook up CH341a SPI USB Programmer & SOIC8 Clip to the SPI chip

I could provide a written explanation but refer to jensd_be for an excellant youtube video which shows how to put together the programmer and connection to the chip
https://youtu.be/r8f-3syiFSc

Extract the original Bios

Connect the SPI programmer clip and  reinsert the programmer USB  into your second computer. The LED  light should turn on. Extract  the BIOS.
(

cd ~/coreboot
sudo flashrom \
 -c 'MX25L6406E/MX25L6408E' \
 -p ch341a_spi \
 -r x220-old-bios.bin

check that the dump was ok by running the  same command, except write to a second file called x220-old-bios-2ndextract.bin . 
Then use the diff command on both .bin files:

diff x220-old-bios.bin x220-old-bios-2ndextract.bin  

if this produces nothing then you re good to go. 
Any issues you can refer to https://www.flashrom.org/Common_problems
Unplug usb and continue 

Partially neuter Intel ME by running me_cleaner the original Bios

cd ~/coreboot
python ./me_cleaner/me_cleaner.py -SO x220-me_cleaned-bios.bin x220-old-bios.bin  

(you should get some pleasant messages like :
Setting the AltMeDisable bit in PCHSTRP10 to disable Intel ME...
Checking the FTPR RSA signature... VALID
Done! Good luck!  )

Start coreboot build by running ifdtool

ifdtool is a tool for reading the Intel Firmware Descriptor  ( IFD).  Run ifdtool and separate regions of the flash chip: 

cd ~/coreboot
cp x220-me_cleaned-bios.bin util/ifdtool/      (copy cleaned bios to ifdtool location)
cd ~/coreboot/util/ifdtool
./ifdtool -x x220-me_cleaned-bios.bin

this will create the following files:

flashregion_3_gbe.bin
flashregion_2_intel_me.bin
flashregion_0_flashdescriptor.bin
flashregion_1_bios.bin


Create a directory for the blobs and move the files there 

mkdir -p ~/coreboot/3rdparty/blobs/mainboard/lenovo/x220
cd ~/coreboot/3rdparty/blobs/mainboard/lenovo/x220 

mv  ~/coreboot/util/ifdtool/flashregion_0_flashdescriptor.bin descriptor.bin     
mv  ~/coreboot/util/ifdtool/flashregion_2_intel_me.bin me.bin   
mv  ~/coreboot/util/ifdtool/flashregion_3_gbe.bin gbe.bin
                             


VGA BIOS extraction

This will allow graphics to be displayed via GRUB.  SeaBIOS works without it but you wont get the funky rabbit bootsplash.

cd ~/coreboot

Download UEFITool - get it from https://github.com/LongSoft/UEFITool   git clone https://github.com/LongSoft/UEFITool.git  

cd ~/coreboot/UEFITool/

Compile UEFITool  - qmake uefitool.pro && make (requires QT5)

cd ~/coreboot/UEFITool/UEFITool

./UEFITool

Open whole firmware image

Search "VGA Compatible BIOS" (Under "Text" tab, with "Unicode" off)

In the results in the bottom double click a (hopefully the only) result

UEFITool with the module containing the VGA BIOS selected
Right click "extract body", save as vgabios.bin

(Further optional) Double check the module extracted is correct:

Install fcode-utils from AUR repository 

Run romheaders vgabios.bin

Expect the following:
romheaders output for the X220 VGA BIOS

udo flashrom \  ✔
-c ‘MX25L6406E/MX25L6408E’ \
-p ch341a_spi \
-w build/coreboot.rom
[sudo] password for x1carbon:
flashrom v1.2 on Linux 6.1.31-1-MANJARO (x86_64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns).
Found Macronix flash chip “MX25L6406E/MX25L6408E” (8192 kB, SPI) on ch341a_spi.
Reading old flash chip contents… done.
Erasing and writing flash chip… Erase/write done.
Verifying flash… VERIFIED.