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