summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Widen <andreas@harmonicflow.org>2019-04-02 18:15:34 +0200
committerAndreas Widen <andreas@harmonicflow.org>2019-04-02 18:15:34 +0200
commit9d9df1c6b507c8099f359b0d5be05ffb76c39096 (patch)
treeb3abaa21373ea76b81bfc2b1a0edb1bcef7b1fc9
parentca71fda9221aca554423ae55fa848f8fc950ee9a (diff)
downloadHarmonicFlowOrgWeb-9d9df1c6b507c8099f359b0d5be05ffb76c39096.tar.xz
HarmonicFlowOrgWeb-9d9df1c6b507c8099f359b0d5be05ffb76c39096.zip
New blog post about coreboot on lenovo x220.
Signed-off-by: Andreas Widen <andreas@harmonicflow.org>
-rw-r--r--blog/data/2019-04-02-17:57:53-flashing-coreboot-on-a-lenovo-thinkpad-x220-with-a-ch341a-usb-programmer-tutorial.txt387
-rwxr-xr-xinclude/sidebar.inc.php9
-rw-r--r--media/x220/01-prerequisites.jpgbin0 -> 45318 bytes
-rw-r--r--media/x220/02-lenovo-thinkpad-x220-internals.jpgbin0 -> 87849 bytes
-rw-r--r--media/x220/03-ch341a-programmer-connected.jpgbin0 -> 110362 bytes
-rw-r--r--media/x220/background.jpgbin0 -> 233004 bytes
-rw-r--r--media/x220/dejavusansmono.pf2bin0 -> 100513 bytes
-rw-r--r--media/x220/grub.cfg129
8 files changed, 525 insertions, 0 deletions
diff --git a/blog/data/2019-04-02-17:57:53-flashing-coreboot-on-a-lenovo-thinkpad-x220-with-a-ch341a-usb-programmer-tutorial.txt b/blog/data/2019-04-02-17:57:53-flashing-coreboot-on-a-lenovo-thinkpad-x220-with-a-ch341a-usb-programmer-tutorial.txt
new file mode 100644
index 0000000..5839ab4
--- /dev/null
+++ b/blog/data/2019-04-02-17:57:53-flashing-coreboot-on-a-lenovo-thinkpad-x220-with-a-ch341a-usb-programmer-tutorial.txt
@@ -0,0 +1,387 @@
+Title: Flashing coreboot on a Lenovo Thinkpad X220 with a ch341a USB programmer Tutorial
+Tags: lenovo-thinkpad-x220, coreboot, libreboot, flashrom, ch341a
+Date: 2019-04-02 17:57:53
+Format: markdown
+
+In this tutorial, we will go through the steps to get
+[coreboot](https://www.coreboot.org/) 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.
+__CUT__
+
+## Prerequisites
+
+![Prerequisites](../media/x220/01-prerequisites.jpg)
+
+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](../media/x220/dejavusansmono.pf2)<br>
+[grub.cfg](../media/x220/grub.cfg)<br>
+[background.jpg](../media/x220/background.jpg)
+
+
+## Packages needed to compile flashrom/coreboot/grub
+
+<pre>
+sudo apt-get install git build-essential gnat flex bison libncurses5-dev wget libpci-dev libusb-dev libftdi1 libftdi-dev unifont zlib1g-dev
+</pre>
+
+## Compile flashrom
+
+Clone flashrom git repository:
+
+<pre>
+git clone https://review.coreboot.org/flashrom.git
+</pre>
+
+Compile flashrom:
+
+<pre>
+cd flashrom
+make -j4
+sudo make install
+sudo cp /usr/local/sbin/flashrom /usr/local/bin/
+</pre>
+
+## Compile GRUB
+
+See '**Prerequisites**' above for the font file needed.
+
+Clone GRUB git repository:
+
+<pre>
+git clone https://git.savannah.gnu.org/git/grub.git
+</pre>
+
+Compile GRUB:
+
+<pre>
+cd grub
+git checkout grub-2.02
+./autogen.sh
+./configure --with-platform=coreboot
+make -j4
+</pre>
+
+Create '**pack-payload-minimal.sh**' script file:
+
+<pre>
+touch pack-payload-minimal.sh
+chmod +x pack-payload-minimal.sh
+</pre>
+
+Paste the following in '**pack-payload-minimal.sh**':
+
+<pre>
+#! /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"
+</pre>
+
+Execute the script to create '**grub2.elf**' file:
+
+<pre>
+./pack-payload-minimal.sh
+</pre>
+
+## Connect ch341a USB programmer to flash chip
+
+Remove the following parts to access the flash chip:
+
+<pre>
+Battery
+Keyboard
+Palmrest
+</pre>
+
+![Connect ch341a USB programmer](../media/x220/02-lenovo-thinkpad-x220-internals.jpg)
+
+Connect Pomona 5250 to flash chip like this:
+
+<pre>
+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)
+</pre>
+
+![ch341a USB programmer connected](../media/x220/03-ch341a-programmer-connected.jpg)
+
+## Read Factory BIOS
+
+Read Factory BIOS 3 times:
+
+<pre>
+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
+</pre>
+
+Make sure checksums are identical:
+
+<pre>
+sha512sum *.rom
+</pre>
+
+## Download coreboot
+
+Download coreboot:
+
+<pre>
+wget https://coreboot.org/releases/coreboot-4.9.tar.xz
+wget https://coreboot.org/releases/coreboot-blobs-4.9.tar.xz
+</pre>
+
+Extract coreboot and blobs needed:
+
+<pre>
+tar xvf coreboot-4.9.tar.xz
+tar xvf coreboot-blobs-4.9.tar.xz --strip-components=1 -C coreboot-4.9
+</pre>
+
+Create folder to hold '**descriptor/gbe/me.bin**' files:
+
+<pre>
+mkdir -pv coreboot-4.9/3rdparty/blobs/mainboard/lenovo/x220/
+</pre>
+
+Extract blob files from Factory BIOS (see '**flashrom/util/ich_descriptors_tool**' folder:
+
+<pre>
+cd ~/misc-src/flashrom/util/ich_descriptors_tool
+./ich_descriptors_tool -f your/path/to/factory_bios.rom -d
+</pre>
+
+Copy blob files to coreboot folder:
+
+<pre>
+cp factory_bios.rom.Descriptor.bin coreboot-4.9/3rdparty/blobs/mainboard/lenovo/x220/descriptor.bin
+cp factory_bios.rom.GbE.bin coreboot-4.9/3rdparty/blobs/mainboard/lenovo/x220/gbe.bin
+cp factory_bios.rom.ME.bin coreboot-4.9/3rdparty/blobs/mainboard/lenovo/x220/me.bin
+</pre>
+
+## Setup and compile coreboot
+
+Enter coreboot folder:
+
+<pre>
+cd coreboot-4.9
+</pre>
+
+Build toolchain needed first (this will take a long time, be patient):
+
+<pre>
+make crossgcc CPUS=4
+</pre>
+
+coreboot settings menu:
+
+<pre>
+make menuconfig
+</pre>
+
+Set the following options:
+
+<pre>
+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 (Generate from tree)
+ |-[*] 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 native graphics init)
+ |-Display
+ |- Framebuffer mode (Linear "high-resolution" framebuffer)
+payload ---|
+ |-Add a payload (An ELF executable payload)
+ |-"(grub2.elf)" Payload path and filename
+</pre>
+
+This will create a '**.config**' file containing all settings.
+
+Compile coreboot:
+
+<pre>
+make -j4
+</pre>
+
+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:
+
+<pre>
+cd coreboot-4.9/util/cbfstool
+make -j4
+</pre>
+
+Add custom GRUB configuration file:
+
+<pre>
+./cbfstool ../../build/coreboot.rom add -t raw -n etc/grub.cfg -f your/path/to/grub.cfg
+</pre>
+
+Check so that '**etc/grub.cfg**' exists in coreboot.rom:
+
+<pre>
+./cbfstool ../../build/coreboot.rom print
+</pre>
+
+Add background image:
+
+<pre>
+./cbfstool ../../build/coreboot.rom add -t raw -n background.jpg -f your/path/to/background.jpg
+</pre>
+
+Check so that '**background.jpg**' exists in coreboot.rom:
+
+<pre>
+./cbfstool ../../build/coreboot.rom print
+</pre>
+
+## Tweak parameters in 'cmos.default'
+
+Make sure '**nvramtool**' is built:
+
+<pre>
+cd coreboot-4.9/util/nvramtool
+make -j4
+</pre>
+
+Get an overview of tweakable parameters:
+
+<pre>
+./nvramtool -C ../../build/coreboot.rom -a
+</pre>
+
+Tweak values we need:
+
+<pre>
+./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
+</pre>
+
+Check specific parameter possible values:
+
+<pre>
+./nvramtool -C ../../build/coreboot.rom -e gfx_uma_size
+</pre>
+
+Make sure values are changed:
+
+<pre>
+./nvramtool -C ../../build/coreboot.rom -a
+</pre>
+
+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:
+
+<pre>
+sudo flashrom -p ch341a_spi -w coreboot.rom -V
+</pre>
+
+## Change Wifi card
+
+Remove the following parts to access the Wifi card:
+
+<pre>
+Battery
+Keyboard
+Palmrest
+</pre>
+
+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](https://www.debian.org/). I recommend setting up
+[full disc encryption (including
+/boot)](https://libreboot.org/docs/gnulinux/encrypted_debian.html) ! The
+'**grub.cfg**' supports and defaults to this option.
+
+## Recommended reading
+
+[https://www.coreboot.org/](https://www.coreboot.org/)<br>
+[https://flashrom.org/Flashrom](https://flashrom.org/Flashrom)<br>
+[https://www.thinkwiki.org/wiki/Category:X220](https://www.thinkwiki.org/wiki/Category:X220)<br>
+[https://github.com/boseji/CH341-Store](https://github.com/boseji/CH341-Store)<br>
+[https://libreboot.org/docs/gnulinux/encrypted_debian.html](https://libreboot.org/docs/gnulinux/encrypted_debian.html)<br>
diff --git a/include/sidebar.inc.php b/include/sidebar.inc.php
index 6b94b06..c43c28e 100755
--- a/include/sidebar.inc.php
+++ b/include/sidebar.inc.php
@@ -19,3 +19,12 @@ src="/media/header_left.png" alt="Harmonic Flow Logo" /></a>
<li<?php if($current_page=="hffwk-git-repo") echo" class=\"active\"";?>><a href="/harmonicflow-framework/git-repo.php">Git repo</a></li>
</ul>
</div>
+<div class="box blue">
+ <h4>Misc. Research</h4>
+ <ul>
+ <li<?php if($current_page=="misc-coreboot-x220") echo"
+ class=\"active\"";?>><a
+ href="/blog/Flashing_coreboot_on_a_Lenovo_Thinkpad_X220_with_a_ch341a_USB_programmer_Tutorial.php">coreboot
+ on Lenovo X220</a></li>
+ </ul>
+</div>
diff --git a/media/x220/01-prerequisites.jpg b/media/x220/01-prerequisites.jpg
new file mode 100644
index 0000000..6c7b440
--- /dev/null
+++ b/media/x220/01-prerequisites.jpg
Binary files differ
diff --git a/media/x220/02-lenovo-thinkpad-x220-internals.jpg b/media/x220/02-lenovo-thinkpad-x220-internals.jpg
new file mode 100644
index 0000000..b6f0597
--- /dev/null
+++ b/media/x220/02-lenovo-thinkpad-x220-internals.jpg
Binary files differ
diff --git a/media/x220/03-ch341a-programmer-connected.jpg b/media/x220/03-ch341a-programmer-connected.jpg
new file mode 100644
index 0000000..490c18b
--- /dev/null
+++ b/media/x220/03-ch341a-programmer-connected.jpg
Binary files differ
diff --git a/media/x220/background.jpg b/media/x220/background.jpg
new file mode 100644
index 0000000..6358271
--- /dev/null
+++ b/media/x220/background.jpg
Binary files differ
diff --git a/media/x220/dejavusansmono.pf2 b/media/x220/dejavusansmono.pf2
new file mode 100644
index 0000000..9ba557e
--- /dev/null
+++ b/media/x220/dejavusansmono.pf2
Binary files differ
diff --git a/media/x220/grub.cfg b/media/x220/grub.cfg
new file mode 100644
index 0000000..2547ab4
--- /dev/null
+++ b/media/x220/grub.cfg
@@ -0,0 +1,129 @@
+# Harmonic Flow's GRUB Configuration --- Use ThinkPads with Coreboot Firmware.
+# Modules 'cbfs' and 'normal' are supposed to be already loaded,
+# as well as its dependencies: terminal crypto extcmd boot gettext
+
+# Prefix --- The location of the "/boot/grub" directory as an absolute file name.
+set prefix=(memdisk)/boot/grub
+
+# Load Modules --- Load selected modules which are not loaded due
+# to dependencies and which have probably not been pre-loaded.
+insmod nativedisk
+insmod luks
+insmod lvm
+insmod ahci
+insmod ohci
+insmod uhci
+insmod ehci
+insmod part_msdos
+insmod part_gpt
+insmod fat
+insmod ext2
+insmod usbms
+insmod usb_keyboard
+insmod usbserial_usbdebug
+insmod syslinuxcfg
+insmod cryptodisk
+insmod jpeg
+
+# Desktop Boards --- Let's load additional modules:
+insmod at_keyboard
+insmod pata
+
+# Set Environment
+set gfxpayload=keep
+set pager=1
+set default=0
+set timeout_style="menu"
+set timeout=5
+set color_highlight=white/green
+set color_normal=light-gray/black
+
+# Terminal Settings
+terminal_input --append at_keyboard
+terminal_output --append cbmemc
+terminal_output --append gfxterm
+
+# VESA Framebuffer Settings
+background_image (cbfsdisk)/background.jpg
+loadfont dejavusansmono
+
+# Keymap --- several options available, adapt to your needs:
+# us gb de be nl it es pt fr tr ro bg pl cz hu se dk fi
+# us_intl us_dvorak ca_fr tr_f ch_de ch_fr sk_qwerty fr_latin9 de_nodeadkeys
+keymap se
+
+# GRUB Functions and Menu Options --- borrowed from the Libreboot Project
+function try_user_config {
+ set root="${1}"
+ for dir in boot grub grub2 boot/grub boot/grub2; do
+ for name in '' autoboot_ libreboot_ coreboot_; do
+ if [ -f /"${dir}"/"${name}"grub.cfg ]; then
+ unset superusers
+ configfile /"${dir}"/"${name}"grub.cfg
+ fi
+ done
+ done
+}
+function search_grub {
+ for i in 0 1; do
+ # raw devices
+ try_user_config "(${1}${i})"
+ for part in 1 2 3 4 5; do
+ # MBR/GPT partitions
+ try_user_config "(${1}${i},${part})"
+ done
+ done
+}
+function try_isolinux_config {
+ set root="${1}"
+ for dir in '' /boot; do
+ if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
+ syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
+ elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
+ syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
+ fi
+ done
+}
+function search_isolinux {
+ for i in 0 1; do
+ # raw devices
+ try_isolinux_config "(${1}${i})"
+ for part in 1 2 3 4 5; do
+ # MBR/GPT partitions
+ try_isolinux_config "(${1}${i},${part})"
+ done
+ done
+}
+menuentry '[o] Load OS Encrypted /boot.. (default settings)' --hotkey='o' {
+ cryptomount -a
+ set root='lvm/matrix-rootvol'
+ linux /vmlinuz root=/dev/mapper/matrix-rootvol cryptdevice=/dev/mapper/matrix-rootvol:root
+ initrd /initrd.img
+}
+menuentry '[i] Load OS Encrypted /boot.. (with iomem=relaxed) ' --hotkey='i' {
+ cryptomount -a
+ set root='lvm/matrix-rootvol'
+ linux /vmlinuz root=/dev/mapper/matrix-rootvol cryptdevice=/dev/mapper/matrix-rootvol:root iomem=relaxed
+ initrd /initrd.img
+}
+menuentry '[g] Search GRUB2 Configuration (AHCI)' --hotkey='g' {
+ search_grub ahci
+}
+menuentry '[s] Search GRUB2 Configuration (USB)' --hotkey='s' {
+ search_grub usb
+}
+menuentry '[u] Search ISOLINUX Menu (USB)' --hotkey='u' {
+ search_isolinux usb
+}
+menuentry '[a] Search ISOLINUX Menu (AHCI)' --hotkey='a' {
+ search_isolinux ahci
+}
+menuentry '[d] Search ISOLINUX Menu (CD/DVD)' --hotkey='d' {
+ try_isolinux_config ahci1
+}
+menuentry '[p] Poweroff' --hotkey='p' {
+ halt --no-apm
+}
+menuentry '[r] Reboot' --hotkey='r' {
+ reboot
+}