You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
10 KiB

6 years ago
  1. # coreboot-x230
  2. pre-built [coreboot](https://www.coreboot.org/) images and documentation on
  3. how to flash them for the
  4. [Thinkpad X230](https://pcsupport.lenovo.com/en/products/laptops-and-netbooks/thinkpad-x-series-laptops/thinkpad-x230).
  5. SeaBIOS is used as coreboot payload to be compatible with Windows and Linux
  6. systems.
  7. ## Latest build (config overview and version info)
  8. See our [releases](https://github.com/merge/coreboot-x230/releases)
  9. * Lenovo's proprietary VGA BIOS ROM is executed in "secure" mode
  10. ### coreboot
  11. * We simply take coreboot's current state in it's master branch at the time we build a release image.
  12. That's the preferred way to use coreboot. The git revision we use is always included in the release.
  13. ### Intel microcode
  14. * revision `1f` from 2018-02-07 (Intel package [20180312](https://downloadcenter.intel.com/download/27591) not yet in coreboot upstream) under [Intel's license](LICENSE.microcode)
  15. ### SeaBIOS
  16. * version [1.11.0](https://seabios.org/Releases#SeaBIOS_1.11.0) from 2017-11-10 (part of coreboot upstream)
  17. ## table of contents
  18. * [TL;DR](#tl-dr)
  19. * [Flashing for the first time](#flashing-for-the-first-time)
  20. * [How to update](#how-to-update)
  21. * [When do we do a release?](#when-do-we-do-a-release)
  22. * [How we build](#how-we-build)
  23. * [Why does this work](#why-does-this-work)
  24. * [Alternatives](#alternatives)
  25. ## TL;DR
  26. Download a released image, connect your hardware SPI flasher to the "upper"
  27. 4MB chip in your X230, and do
  28. flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c "MX25L3206E" -w x230_coreboot_seabios_example_top.rom
  29. where `linux_spi:` is the example of using your SPI pins of, for example, a
  30. Raspberry Pi. A [Bus Pirate](http://dangerousprototypes.com/docs/Bus_Pirate) with
  31. `buspirate_spi` or others connected to the host directly should be fine too.
  32. ## Flashing for the first time
  33. Especially for the first time, you must flash externally. See below for the details
  34. for using a Rapberry Pi, for example.
  35. ### flashrom chip config
  36. We use [flashrom](https://flashrom.org/) for flashing. Run `flashrom -p <your_hardware>`
  37. (for [example](#how-to-flash) `flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128` for the
  38. Raspberry Pi) to let flashrom detect the chip. It will probably list a few you need to choose
  39. from when flashing (by adding `-c "<chipname>"`). While there might be specific examples
  40. in the commands below, please review the chip model for your device. In case you are
  41. unsure what to specify, here's some examples we find out there:
  42. #### 4MB chip
  43. * `MX25L3206E` seems to mostly be in use
  44. #### 8MB chip
  45. * `MX25L3206E/MX25L3208E` is seen working with various X230 models.
  46. * `MX25L6406E/MX25L6408E` is used in [this guide](https://github.com/mfc/flashing-docs/blob/master/walkthrough%20for%20flashing%20heads%20on%20an%20x230.md#neutering-me)
  47. * `EN25QH64` is used sometimes
  48. ### EC firmware (optional)
  49. Enter Lenovo's BIOS with __F1__ and check the embedded controller (EC) version to be
  50. __1.14__ and upgrade using [the latest bootable CD](https://support.lenovo.com/at/en/downloads/ds029188)
  51. if it isn't. The EC cannot be upgraded when coreboot is installed. (In case a newer
  52. version should ever be available (I doubt it), you could temporarily flash back your
  53. original Lenovo BIOS image)
  54. ### ifd unlock and me_cleaner
  55. The Intel Management Engine resides on the 8MB chip. We don't need to touch it
  56. for coreboot-upgrades in the future, but to enable internal flashing, we need
  57. to unlock it once.
  58. We run [ifdtool](https://github.com/coreboot/coreboot/tree/master/util/ifdtool)
  59. and, while we are at it, [me_cleaner](https://github.com/corna/me_cleaner) on it:
  60. We support using a RPi, see below for more details:
  61. Transfer the release tarball (when don't want to use
  62. a USB Stick or network):
  63. (convert)
  64. host$ uuencode <tarball>.tar.xz <tarball>.tar.xz.ascii > <tarball>.tar.xz.ascii
  65. (transfer)
  66. rpi$ cat > <tarball>.tar.xz.ascii
  67. host$ pv <tarball>.tar.xz.ascii > /dev/ttyUSBX
  68. (wait)
  69. rpi$ (CTRL-D)
  70. (convert back)
  71. rpi$ uudecode -o <tarball>.tar.xz <tarball>.tar.xz.ascii
  72. (verify)
  73. host$ sha1sum <tarball>.tar.xz
  74. rpi$ sha1sum <tarball>.tar.xz
  75. Unpack it (to the current directory and change into it):
  76. tar -xf <tarball>.tar.xz -C .
  77. cd <tarball>.tar.xz
  78. And finally unlock the 8M chip (be patient):
  79. flashrom_rpi_bottom_unlock.sh -m -c <chipname> -k <backup.bin>
  80. `-m` also runs `me_cleaner -S` before flashing back. Keep the backup safe.
  81. #### background
  82. If you don't use a RPi, change the flashrom programmer to your needs:
  83. flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c "MX25L6406E/MX25L6408E" -r ifdmegbe.rom
  84. flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c "MX25L6406E/MX25L6408E" -r ifdmegbe2.rom
  85. diff ifdmegbe.rom ifdmegbe2.rom
  86. git clone https://github.com/corna/me_cleaner.git && cd me_cleaner
  87. ./me_cleaner.py -S -O ifdmegbe_meclean.rom ifdmegbe.rom
  88. ifdtool -u ifdmegbe_meclean.rom
  89. flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c "MX25L6406E/MX25L6408E" -w ifdmegbe_meclean.rom.new
  90. ### BIOS: the 4MB chip
  91. (internally, memory of the two chips is mapped together, the 8MB being the lower
  92. part, but we can essientially ignore that). Again, using a RPi is supported
  93. here. We assume you have the unpacked release tarball ready, see above:
  94. flashrom_rpi_top_write.sh -i x230_coreboot_seabios_<release>_top.rom -c <chipname> -k <backup>
  95. Keep the backup safe.
  96. ## How to update
  97. When __upgrading__ to a new release, only the "upper" 4MB chip has to be written.
  98. Download the latest release image we provide and flash it:
  99. ### Example: Raspberry Pi 3
  100. Here you'll flash externally, using a "Pomona 5250 8-pin SOIC test clip". You'll find
  101. one easily. This is how the X230's SPI connection looks on both chips:
  102. Screen (furthest from you)
  103. __
  104. MOSI 5 --| |-- 4 GND
  105. CLK 6 --| |-- 3 N/C
  106. N/C 7 --| |-- 2 MISO
  107. VCC 8 --|__|-- 1 CS
  108. Edge (closest to you)
  109. and with our release tarball unpacked, the command you need looks like so:
  110. flashrom_rpi_top_write.sh -i x230_coreboot_seabios_<release>_top.rom -c <chipname>
  111. We run [Raspbian](https://www.raspberrypi.org/downloads/raspbian/)
  112. and have the following setup
  113. * [Serial connection](https://elinux.org/RPi_Serial_Connection) using a "USB to Serial" UART Adapter and picocom or minicom
  114. * Yes, in this case you need a second PC connected to the RPi over UART
  115. * in the SD Cards's `/boot/config.txt` file `enable_uart=1` and `dtparam=spi=on`
  116. * [For flashrom](https://www.flashrom.org/RaspberryPi) we put `spi_bcm2835` and `spidev` in /etc/modules
  117. * [Connect to a wifi](https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md) or to network over ethernet to install `flashrom`
  118. * only use the ...top.rom release file
  119. * connect the Clip to the Raspberry Pi 3 (there are [prettier images](https://github.com/splitbrain/rpibplusleaf) too:
  120. Edge of pi (furthest from you)
  121. (UART)
  122. L GND TX RX CS
  123. E | | | |
  124. F +---------------------------------------------------------------------------------+
  125. T | x x x x x x x x x x x x x x x x x x x x |
  126. | x x x x x x x x x x x x x x x x x x x x |
  127. E +----------------------------------^---^---^---^-------------------------------^--+
  128. D | | | | |
  129. G 3.3V MOSIMISO| GND
  130. E (VCC) CLK
  131. Body of Pi (closest to you)
  132. Now you should be able to copy the image over to your Rasperry Pi and run the
  133. mentioned `flashrom` commands. One way to copy, is convertig it to ascii using
  134. `uuencode` (part of Debian's sharutils package) described below. This is a very
  135. direct, shady and slow way to copy file. Another way is of course using a USB
  136. Stick or scp :) (but you need even more hardware or a network).
  137. (convert)
  138. host$ uuencode coreboot.rom coreboot.rom.ascii > coreboot.rom.ascii
  139. (transfer)
  140. rpi$ cat > coreboot.rom.ascii
  141. host$ pv coreboot.rom.ascii > /dev/ttyUSBX
  142. (wait)
  143. rpi$ (CTRL-D)
  144. (convert back)
  145. rpi$ uudecode -o coreboot.rom coreboot.rom.ascii
  146. (verify)
  147. host$ sha1sum coreboot.rom
  148. rpi$ sha1sum coreboot.rom
  149. ![Raspberry Pi at work](rpi_clip.jpg)
  150. ### Example: internal
  151. CAUTION: THIS IS NOT ENCOURAGED
  152. * Only for updating! You have to have your 8MB chip flashed externally after `ifdtool -u ifdmegbe.rom` before this, once
  153. * very convenient, but according to the [flashrom manpage](https://manpages.debian.org/stretch/flashrom/flashrom.8.en.html) this is very dangerous!
  154. * Boot Linux with the `iomem=relaxed` boot parameter (for example set in /etc/default/grub)
  155. * download a released 4MB "top" rom image
  156. * run `prepare_internal_flashing.sh` for generating all necessary files and instructions
  157. ## When do we do a release?
  158. Either when
  159. * There is a new SeaBIOS release,
  160. * There is a new Intel microcode release (for our CPU model),
  161. * There is a coreboot issue that affects us, or
  162. * We change the config
  163. ## How we build
  164. * Everything necessary to build coreboot (while only the top 4MB are usable of course) is included here
  165. * The task of [building coreboot](https://www.coreboot.org/Build_HOWTO) is not too difficult
  166. * When doing a release here, we always try to upload to coreboot's [board status project](https://www.coreboot.org/Supported_Motherboards)
  167. * If we add out-of-tree patches, we always [post them for review](http://review.coreboot.org/) upstream
  168. ## Why does this work?
  169. On the X230, there are 2 physical "BIOS" chips. The "upper" 4MB
  170. one holds the actual bios we can generate using coreboot, and the "lower" 8MB
  171. one holds the rest that you can [modify yourself once](#flashing-for-the-first-time),
  172. if you like, but strictly speaking, you
  173. [don't need to touch it at all](https://www.coreboot.org/Board:lenovo/x230#Building_Firmware).
  174. What's this "rest"?
  175. Mainly a tiny binary used by the Ethernet card and the Intel Management Engine.
  176. ## Alternatives
  177. * [Heads](https://github.com/osresearch/heads/releases) also releases pre-built
  178. flash images for the X230 - with __way__ more sophisticated functionality.