Edit page AbridgedResume
[wiki.git] / CorebootX230
1 <div style="width: 1024px; margin:0 auto">
2
3 == <span style="text-align: right"> Flashing Coreboot on the Thinkpad X230</span> ==
4
5 By Bernie Innocenti \\
6 23 March 2014 (re-published with minor edits on 30 June 2020)
7
8 <div style="width: 640px; margin:0 auto">{{pictures/misc/x230-flashing.jpg | maxwidth=640}}</div>
9
10 Coreboot, the free PC BIOS that powers all Google Chromebooks, was recently ported to the Thinkpad X230
11 by the long time GRUB hacker Vladimir 'φ-coder' Serbinenko. So this week-end, just while Libre Planet was
12 taking place at the nearby MIT Stata Center, I decided to give a shot at it. Building a custom Coreboot
13 image for the X230 was relatively easy:
14
15 {{{
16 git clone http://review.coreboot.org/p/coreboot    cd coreboot
17 git submodule update --init --checkout
18 make crosstools-i386
19 # install the .config file provided by phcoder on the Coreboot wiki
20 make oldconfig
21 make
22 }}}
23
24 The build process generates a 12MB image containing all the board-specific code to initialize the hardware
25 and a "payload" program to continue the boot process. I chose SeaBIOS, a legacy PC BIOS which can boot off
26 hard-drives and other media.
27
28 Things get interesting at this point: until someone figures out a way to workaround for Lenovo's BIOS
29 write protection, flashing Coreboot requires a SPI programmer.  So I borrowed a Pirate Bus with a Pomona 5250
30 SOIC test clip from some friends at the [[https://www.fsf.org/ | Free Software Foundation]].
31 The +3.3V pin of the SOIC chip is connected to several other components on the motherboard and pulls a
32 lot of current while flashing (>400mA), so I had to hook it up to a beefy external power supply, being
33 careful not to fry the entire motherboard.
34
35 The X230 BIOS resides in two SPI flash chips of 8 and 4 megabytes that contain several things
36 (for the details, check the X230 flashing instructions in the Coreboot wiki). Because my Coreboot image
37 was small enough to fit into the top 4MB, I only had to flash one chip. From a separate machine, I used
38 the 'flashrom' tool to backup the original BIOS, so I could easily restore it in case I couldn't get
39 Coreboot to work.
40
41 {{{
42 sudo flashrom -p buspirate_spi:dev=/dev/ttyUSB0,spispeed=8M -c MX25L3206E -r x230-orig-4M.rom
43 }}}
44
45 Next, I crossed fingers and wrote my Coreboot image:
46
47 {{{
48 sudo flashrom -p buspirate_spi:dev=/dev/ttyUSB0,spispeed=8M -c MX25L3206E -w x230-bernie-4M.rom
49 }}}
50
51 The entire operation takes about 15 minutes. The Pirate Bus isn't the fastest SPI programmer on
52 the planet, but it costs only $30 and it's pretty reliable. Ok, now let's disconnect the clip and
53 power on the laptop. The leds blink a little. The machine seems alive, but the LCD panel doesn't
54 turn on. From the hard drive led it's evident that the system is booting, so I hook up an external
55 VGA monitor and see a familiar password prompt.
56
57 I already knew I was missing the VGA BIOS blob that initialize the video ports, but I wanted to see
58 if Linux was able to do it after boot. So I cried for help in the #coreboot IRC channel, and phcoder
59 pointed me at [[http://review.coreboot.org/#/c/5396/ | a patch]] floating around in Gerrit which
60 contains 8KB of magical numbers to initialize the flat panel.
61
62 The title photo shows the colorful result I got while trying phcoder's off-tree patch with SeaBIOS.
63 Phcoder hinted that a recent snapshot of GRUB2 should initialize the display properly, and then went to sleep.
64 Other Coreboot developers on IRC helped me debug my configuration until, finally, I powered on the laptop and
65 in a couple of seconds a familiar GRUB2 prompt appeared on the panel.
66 From there, I could easily load the OS bootmenu:
67
68 {{{
69 set root=(ahci,msdos1)
70 source /grub/grub.cfg
71 normal
72 }}}
73
74 Of course, it's also possible to build a custom grub.cfg into the Coreboot image and let the machine boot
75 automatically. There's also [[http://www.coreboot.org/pipermail/seabios/2014-February/007651.html | a set of SeaBIOS patches]]
76 which enable native VGA initialization. I got these patches to apply to my tree, but the resulting display is still messed up.
77 The author, Kevin O'Connor, is away from the keyboard at the moment.
78
79 Another open problem is that the S3 mode (aka sleep mode) is totally broken: instead of resuming, the machine simply reboots.
80 This is annoying enough to prevent me from using Coreboot on my main machine. Before I can even attempt debugging this I need
81 to figure out a way to get a debug console, because there are no usable serial ports on the X230. One of the Coreboot devs
82 on IRC said that Android phones can serve as usbdebug dongles; I guess I'll try it next week if I have time.
83
84 Note that the resulting machine is still running plenty of scary proprietary code: there's the firmware for the Embedded Controller,
85 a separate processor which manages power and keyboard input, and the Intel Management Engine (ME),
86 which runs even while the machine is sleeping, and for which interesting persistent rootkits have been demonstrated by clever
87 security researchers years ago.
88
89 There are no alternatives for the ME firmware at this time, but free  implementations of the EC firmware exist for various
90 Chromebooks and for the OLPC XO laptops. The codebase is quite board-specific, and porting it to the Thinkpad without
91 documentation from Lenovo isn't a trivial project.
92
93 Nevertheless, Coreboot seems to be improving rapidly in terms of usability and hardware support. There's a lively developer
94 community and some business participation. It's not yet something I'd recommend to casual users, but if you're a nerd with a
95 spare laptop and a fetish for hardware hacking, you might want to give Coreboot a try while it's still l33t 😉
96
97 </div>