| 1 |
====================== |
| 2 |
Info on laptops and EC |
| 3 |
====================== |
| 4 |
|
| 5 |
The page contains some info about flashing the EC on the laptops without official vendor support. |
| 6 |
|
| 7 |
For the info how to flash system firmware on modern laptops with vendor support, please check |
| 8 |
"Flashing coreboot" document in user docs. |
| 9 |
|
| 10 |
**Note the document below was migrated from old website and the content >10yrs old** |
| 11 |
(exept the links to mailing list and dev guide, those are up-to-date). |
| 12 |
|
| 13 |
Why laptops are difficult |
| 14 |
========================= |
| 15 |
|
| 16 |
Laptops, notebooks and netbooks are difficult to support and we recommend to use the vendor flashing utility. |
| 17 |
The embedded controller (EC) in these machines often interacts badly with flashing, |
| 18 |
either by blocking all read/write access to the flash chip or by crashing |
| 19 |
(it may power off the machine or mess with the battery or cause system instability). |
| 20 |
|
| 21 |
ECs are particularly difficult besides blocking access and crashing: |
| 22 |
|
| 23 |
* Almost all ECs do not have public datasheets with programming information. |
| 24 |
|
| 25 |
* Even if the programming information for an EC is public, |
| 26 |
the errata (often needed to use the EC for flashing) are not. |
| 27 |
|
| 28 |
* Even if you have the datasheets with programming information (under NDA or by convincing the EC vendor to release them), |
| 29 |
the following problems remain: |
| 30 |
|
| 31 |
* flashrom has to detect/probe the EC. For this, it writes a magic byte sequence to a magic port. |
| 32 |
The bad news is that a laptop vendor can customize the magic sequence and the magic port and the response to that, |
| 33 |
so even if you try all magic sequences mentioned in the datasheet on all magic ports mentioned in the datasheet, |
| 34 |
it will either not react (because the laptop vendor came up with its own secret magic sequence/port or |
| 35 |
because the laptop vendor decided to disable all detection support) or it will respond with a non-default ID |
| 36 |
which is not present in any table. If you are really extremely lucky, |
| 37 |
the EC will react to the probing sequence mentioned in the datasheet and respond with the ID mentioned in the datasheet. |
| 38 |
|
| 39 |
* Most ECs support 3-5 different interfaces to the flash chip. Depending on the software running on the EC, |
| 40 |
none, some or all of them can be disabled. So if you want to support a given embedded controller with reasonable reliability, |
| 41 |
you have to write code for all flash interfaces (usually vastly different from each other). |
| 42 |
|
| 43 |
* During a flash erase/read/write, flashrom competes with the EC for flash access. The EC usually executes |
| 44 |
its software directly from flash (no RAM involved) and starving the EC instruction decoder may crash the EC. |
| 45 |
If you erase the part of the flash chip where the EC fetches its instructions from, the EC will execute garbage |
| 46 |
and crash/misbehave. When (not if, it always happens) the flash chip is in ID mode during flash probing, |
| 47 |
the EC will mistake the ID data for instructions and execute them, resulting in a crash. |
| 48 |
|
| 49 |
* You have to find a way to let the EC software run for some time without requiring flash access. |
| 50 |
This can be achieved by writing a loop (not really a loop, but this is just to illustrate the point) |
| 51 |
to EC-internal tiny RAM and then jumping there. Only during that time |
| 52 |
you can access the flash chip reliably without side effects. |
| 53 |
|
| 54 |
* After flashing, you have to reset the EC so that it can resume running normally. |
| 55 |
This is not optional because the EC controls battery charging (among others) and you want that to work. |
| 56 |
|
| 57 |
Adding support for laptops |
| 58 |
========================== |
| 59 |
|
| 60 |
That said, adding support for an EC is doable. Here is a cheat sheet on what to do. |
| 61 |
|
| 62 |
* Find out which flash chip you have by physical inspection of the board |
| 63 |
(or by looking at the internal docs of the manufacturer or the repair manual). |
| 64 |
|
| 65 |
* Find out the controller where the flash chip is attached to. Can be the EC (likely), |
| 66 |
SuperI/O (somewhat likely), Southbridge (pretty unlikely, if it were, you wouldn't be reading this). |
| 67 |
This is a job done by physical inspection of the board (or by looking at the internal docs |
| 68 |
of the manufacturer which sometimes only the ODM and not even the laptop vendor has). |
| 69 |
|
| 70 |
* You can post on the flashrom mailing list (see :ref:`mailing list`) that you plan to work on your EC, |
| 71 |
mention the exact EC model (and laptop model). You can ask if someone has public docs for the EC, |
| 72 |
knows how to get them under NDA or has vendor contacts at the EC vendor. |
| 73 |
With some luck, you might even get docs (some vendors are more friendly than others). |
| 74 |
|
| 75 |
* Get hold of a BIOS image for your laptop (flashrom dump in force mode won't work reliably here). |
| 76 |
Locate the EC code in the BIOS image. The EC often is 8051 compatible or has an architecture with similar limitations. |
| 77 |
The EC code will be uncompressed in flash. Download BIOS images for other laptops with the same EC |
| 78 |
and try to compare the EC code. It may be 100% vanilla code directly from the EC manufacturer |
| 79 |
(which makes your task rather easy) or a heavily customized variant of the original code |
| 80 |
(bad, because you have to analyze it). |
| 81 |
|
| 82 |
* Cross-check the EC code with the EC docs to find out which interfaces for detecting the EC |
| 83 |
and which interfaces for flashing are enabled and working. |
| 84 |
|
| 85 |
* The above two steps can be skipped if you get that information from the laptop vendor. |
| 86 |
|
| 87 |
* Make sure your flash chip is removable in case something goes wrong. If it is not removable, |
| 88 |
look for an in-system-programming header on the board and check if it is supported by flashrom |
| 89 |
(or your hardware programmer of choice). If there is no header and the chip is soldered, |
| 90 |
desolder it and solder a socket in place. |
| 91 |
|
| 92 |
* Dump the old firmware via the programming header or via reading the chip in an external programmer |
| 93 |
and store it safely (backup on a readonly medium like CD-ROM). It contains your laptop serial number, |
| 94 |
your MAC address, and sometimes your Windows preactivation keys. |
| 95 |
|
| 96 |
* (optional) Disconnect the battery. You don't know how the EC behaves if it crashes |
| 97 |
and batteries are expensive and prone to unwanted reactions. |
| 98 |
|
| 99 |
* Start implementing and testing EC detection code. We recommend to do this either |
| 100 |
as external programmer driver init code (and have the code return 1 to make sure flashrom aborts after init) |
| 101 |
or in a standalone program (this helps you keep an overview). |
| 102 |
|
| 103 |
* Start implementing flasher support for your EC. The best way to do this is an external programmer driver. |
| 104 |
|
| 105 |
* Note that you can push your patch for review even if it is still in Work In Progress state, if you want to |
| 106 |
get early feedback and/or share your effort with the people on the mailing list. See :doc:`/dev_guide/development_guide`. |
| 107 |
|
| 108 |
Laptop enable |
| 109 |
============= |
| 110 |
|
| 111 |
Most (all?) laptop designs use an EC (embedded controller) to control the backlight, |
| 112 |
watch the battery status, etcetera. |
| 113 |
|
| 114 |
To access the flash chip (safely), the EC needs to be suspended/stopped. |
| 115 |
The code to stop the EC typically is found at the end of a BIOS binary. |
| 116 |
This page is about that trailing part of a binary. |
| 117 |
|
| 118 |
PhoenixBIOS specifics |
| 119 |
--------------------- |
| 120 |
|
| 121 |
This subsection is about the disassembly of a laptop BIOS file (Compal HTW20, ENE KB910QF, SMC LPC47B227?, Phoenix TrustedCore) |
| 122 |
that is 1052598 bytes large, the trailer starts at 0x100000 (1024 * 1024) and is 4022 bytes in size. |
| 123 |
|
| 124 |
To extract the trailer, use dd:: |
| 125 |
|
| 126 |
dd if=<romfile> of=bios.bin bs=1024k skip=1 |
| 127 |
|
| 128 |
Example of a disassembly |
| 129 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 130 |
|
| 131 |
The disassembler that is used is IDAPro, the freeware version. |
| 132 |
|
| 133 |
Example of how the disassembly of the trailer looks:: |
| 134 |
|
| 135 |
TRAILER:0010 09 00 00 00 00 00 00 00 00 00 00 43 6F 6D 70 61 ..........Compa |
| 136 |
TRAILER:0020 6C 20 57 69 6E 50 68 6C 61 73 68 20 2D 20 46 6C l WinPhlash - Fl |
| 137 |
TRAILER:0030 61 73 68 69 6E 74 2E 61 73 6D 20 76 30 2E 30 33 ashint.asm v0.03 |
| 138 |
TRAILER:0040 5A 46 4C 50 46 25 00 00 00 00 00 00 00 59 02 00 ZFLPF% |
| 139 |
|
| 140 |
Hints and facts |
| 141 |
^^^^^^^^^^^^^^^ |
| 142 |
|
| 143 |
Facts: |
| 144 |
|
| 145 |
* ZFLPF is found at 0x40 |
| 146 |
* len(ZFLPH) = 5 |
| 147 |
|
| 148 |
The location of the entrypoint is stored at 0x51: |
| 149 |
|
| 150 |
(base of ZFLPF) + len(ZFLPF) + 0xc = 0x40 + 5 + 0xc = 0x51 |
| 151 |
|
| 152 |
|
| 153 |
Let's take a look at position 0x51:: |
| 154 |
|
| 155 |
TRAILER:0051 DE 02 dw 2DEh |
| 156 |
|
| 157 |
Fact: |
| 158 |
|
| 159 |
* 0x2de + 0x1b = 0x2f9 |
| 160 |
|
| 161 |
Preview of the begin of the board specific code |
| 162 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 163 |
|
| 164 |
:: |
| 165 |
|
| 166 |
TRAILER:02F9 ; --------------------------------------------------------------------------- |
| 167 |
TRAILER:02F9 9C pushf |
| 168 |
TRAILER:02FA 60 pusha |
| 169 |
TRAILER:02FB E8 C2 00 call determine_lpc_pci_id |