├── LICENSE ├── README.md ├── pinout.png └── vga-8086-0126.bin /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Mike Mob 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flash Coreboot on a Thinkpad X220 2 | 3 | This repository is a supplement for [my x220 coreboot flash guide on YouTube](https://youtu.be/kJRgBlXRy5I). 4 | 5 | While highly unlikely, it is possible to brick your x220 while attempting to flash 6 | coreboot. I take no responsibility if that horrible and unfortunate event were to 7 | occur, so do this at your own risk. 8 | 9 | *You can always re-flash your old BIOS. (**Keep backups!**)* 10 | 11 | 12 | ## Setup 13 | 14 | #### Enable SPI Interface 15 | ``` 16 | sudo raspi-config 17 | 18 | # Choose "[5] Interfacing Options" 19 | # Then choose "P4 SPI" and "Yes" to enable 20 | # Then reboot the pi 21 | reboot 22 | ``` 23 | 24 | #### Update packages index 25 | ```sh 26 | sudo apt update 27 | ``` 28 | 29 | #### Install flashrom 30 | ```sh 31 | sudo apt install flashrom 32 | ``` 33 | 34 | #### Install other dependencies 35 | ```sh 36 | sudo apt install build-essential git libftdi1 libftdi-dev libusb-dev \ 37 | libpci-dev m4 bison flex libncurses5-dev libncurses5 pciutils \ 38 | usbutils libpci-dev libusb-dev zlib1g-dev \ 39 | libusb-1.0 gnat-4.9 40 | ``` 41 | 42 | #### Clone coreboot repo and submodules 43 | ```sh 44 | git clone --recurse-submodules https://review.coreboot.org/coreboot.git ~/coreboot 45 | ``` 46 | 47 | #### Compile ifdtool 48 | ```sh 49 | cd ~/coreboot/util/ifdtool 50 | make && sudo make install 51 | ``` 52 | 53 | #### Clone me_cleaner repo (Optional) 54 | ```sh 55 | git clone https://github.com/corna/me_cleaner ~/me_cleaner 56 | ``` 57 | 58 | 59 | ## Pinout 60 | 61 | x220 Bios Chip Pinout 62 | 63 | You will need six jumper wires for VCC, MOSI, MISO, CLK, CS, and GND. 64 | *Note: VCC is 3.3 volts.* 65 | 66 | ## Read and Verify 67 | 68 | #### SPI speeds and alias 69 | ```sh 70 | # `spispeed=512` can be set to a higher value for faster reading and 71 | # writing, but slower rw speeds are generally more robust. 72 | # for reference: an spispeed of 512 took roughly 3m40s per read. 73 | 74 | # optional: fr alias for flashrom, less typing 75 | alias fr='sudo flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=512' 76 | ``` 77 | 78 | #### Find flash chip name 79 | ```sh 80 | # Print all flash chips 81 | fr 82 | 83 | # Multiple chips may be found, you probably can choose any of them. Be sure 84 | # to read and compare checksums for each of them just in case. 85 | ``` 86 | 87 | #### Read flash chip to determine if connection is OK 88 | ```sh 89 | # If multiple chips were found, use a seperate one for each read. 90 | # The `time` command is optional, but it is nice to know how long it takes. 91 | mkdir ~/rom 92 | cd $_ 93 | 94 | # Read the flash 4 times, you can do it fewer times. 95 | CHIP="YOUR CHIP NAME HERE" 96 | time fr -c "$CHIP" -r flash01.bin 97 | fr -c "$CHIP" -r flash02.bin 98 | fr -c "$CHIP" -r flash03.bin 99 | fr -c "$CHIP" -r flash04.bin 100 | ``` 101 | 102 | #### Compare checksums 103 | ```sh 104 | # Assure all checksums are the same! 105 | # If they're not, check out https://www.coreboot.org/Board:lenovo/x220 for 106 | # troubleshoooting; DO NOT CONTINUE. 107 | md5sum flash01.bin flash02.bin flash03.bin flash04.bin 108 | 109 | ``` 110 | *If all checksums are the same, then backup `flash01.bin` to **AT LEAST** one safe location.* 111 | 112 | ## Blobs 113 | 114 | #### Run me_cleaner (Optional) 115 | Run `me_cleaner` with `-S` option to enable the HAP AltMeDisable kill-switch and remove the extra code from the firmware. 116 | ```sh 117 | ~/me_cleaner/me_cleaner.py -S flash01.bin 118 | ``` 119 | 120 | #### Extract with idftool 121 | ```sh 122 | cd ~/rom 123 | ifdtool -x flash01.bin 124 | ``` 125 | 126 | #### Copy/move blobs 127 | ```sh 128 | mkdir -p ~/coreboot/3rdparty/blobs/mainboard/lenovo/x220 129 | cd $_ 130 | 131 | cp ~/rom/flashregion_0_flashdescriptor.bin descriptor.bin 132 | cp ~/rom/flashregion_2_intel_me.bin me.bin 133 | cp ~/rom/flashregion_3_gbe.bin gbe.bin 134 | ``` 135 | 136 | 137 | ## Coreboot 138 | 139 | Consider copying `~/coreboot` to a faster machine for compiling. Otherwise, the 140 | Raspberry Pi will take multiple hours to build. 141 | 142 | #### Configure coreboot 143 | To run Windows, SeaBIOS may need a VGABIOS firmware. You can extract it yourself by 144 | following [this guide](https://www.coreboot.org/VGA_support) 145 | --OR-- you can use the pre-extracted one below. 146 | ```sh 147 | # Optional: download pre-extracted vgabios firmware. 148 | wget https://github.com/thetarkus/x220-coreboot-guide/raw/master/vga-8086-0126.bin 149 | 150 | cd ~/coreboot 151 | make nconfig 152 | 153 | ### Coreboot configuration 154 | General 155 | [*] Compress ramstage with LZMA 156 | [*] Include coreboot .config file into the ROM image 157 | [*] Allow use of binary-only repository 158 | 159 | Mainboard 160 | Mainboard vendor (Lenovo) 161 | Mainboard model (ThinkPad X220) 162 | 163 | Chipset 164 | [*] Enable VMX for virtualization 165 | [*] Add Intel descriptor.bin file 166 | (3rdparty/blobs/mainboard/$(MAINBOARDDIR)/descriptor.bin) Path and filename 167 | [*] Add Intel ME/TXE firmware 168 | (3rdparty/blobs/mainboard/$(MAINBOARDDIR)/me.bin) Path to management engine firmware 169 | [*] Add gigabit ethernet firmware 170 | (3rdparty/blobs/mainboard/$(MAINBOARDDIR)/gbe.bin) Path to gigabit ethernet 171 | 172 | Devices ***if using the VGABIOS firmware*** 173 | [*] Graphics initialization (Run VGA Option ROMs) 174 | [*] Add a VGA BIOS image 175 | () VGA BIOS path and filename 176 | (8086,0126) VGA device PCI IDs 177 | [*] Add a Video Bios Table (VBT) binary to CBFS 178 | 179 | Generic Drivers 180 | [*] PS/2 keyboard init 181 | 182 | Console 183 | [*] Show POST codes on the debug console 184 | 185 | Payload 186 | Add a payload (SeaBIOS) ---> 187 | SeaBIOS version (master) ---> 188 | [*] Hardware init during option ROM execution 189 | ### 190 | ``` 191 | 192 | #### Build coreboot 193 | ```sh 194 | make 195 | # Will be placed into `~/coreboot/build/coreboot.rom`. 196 | ``` 197 | 198 | Or, in case you are running make from your raspberry pi, do: 199 | ```sh 200 | make crossgcc-i386 CPUS=4 201 | make iasl 202 | make 203 | ``` 204 | The above commands will take a couple of hours. If your raspberry pi runs out of memory like mine, then create a swapfile https://digitizor.com/create-swap-file-ubuntu-linux/ 205 | 206 | ## Write coreboot to flash chip 207 | 208 | #### Re-read flash chips to determine if connection is still OK 209 | See [previous section](#read-flash-chips-to-determine-if-connection-is-ok). 210 | ```sh 211 | fr -c "$CHIP" -r a.bin 212 | fr -c "$CHIP" -r b.bin 213 | 214 | # Assure these are still the same!!! 215 | md5sum a.bin b.bin 216 | ``` 217 | 218 | #### Write coreboot to flash chip... the moment of truth 219 | ```sh 220 | cd ~/coreboot/build 221 | fr -c "$CHIP" -w coreboot.rom 222 | 223 | # Getting "Erasing and writing flash chip... FAILED" once is normal. Do not panic. 224 | ``` 225 | 226 | #### Finale 227 | * If successful, turn off the Raspberry Pi by running `sudo shutdown now` before 228 | removing connections. 229 | * If not successful, you can check your connection and attempt to re-flash. 230 | * If still not successful, re-compile coreboot and re-flash. 231 | * If STILL not successful and you feel like giving up, you can re-flash `flash01.bin`. 232 | 233 | ## FAQ and Common Issues 234 | - I'm getting "No EEPROM/flash device found" when trying to read the BIOS rom. 235 | Make sure that you've enabled SPI and run `ls /dev | grep spi` to confirm that your SPI devices are detected properly. If they do not appear it may have to do with your kernel. Download and flash latest Raspbian Lite and follow the tutorial from the start. 236 | 237 | - `make` fails as the blobs folder is not empty. Resulting in an error similar to: 238 | ``` 239 | Microcode error: 3rdparty/blobs/cpu/intel/model_206ax/microcode.bin does not exist Microcode error: 3rdparty/blobs/cpu/intel/model_306ax/microcode.bin does not exist src/cpu/Makefile.inc:40: error execution recepie for target «build/cpu_microcode_blob.bin» make: ** [build/cpu_microcode_blob.bin] Error 1 240 | ``` 241 | 242 | A solution may be to clone 3rd party blobs from coreboot 243 | ```sh 244 | cd ~/coreboot/3rdparty 245 | git clone http://review.coreboot.org/blobs.git 246 | # resource: https://www.reddit.com/r/coreboot/comments/7y6nqo/missing_microcode/ 247 | ``` 248 | 249 | ## Other Helpful Information 250 | * coreboot's [wiki page](https://www.coreboot.org/Board:lenovo/x220) 251 | * tripcode!Q/7's [video](https://www.youtube.com/watch?v=ExQKOtZhLBM) 252 | * Tyler Cipriani's [blog post](https://tylercipriani.com/blog/2016/11/13/coreboot-on-the-thinkpad-x220-with-a-raspberry-pi/) 253 | -------------------------------------------------------------------------------- /pinout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelmob/x220-coreboot-guide/9f26171e18627666418c1d7974420b739732231e/pinout.png -------------------------------------------------------------------------------- /vga-8086-0126.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelmob/x220-coreboot-guide/9f26171e18627666418c1d7974420b739732231e/vga-8086-0126.bin --------------------------------------------------------------------------------