| 1 |
===================== |
| 2 |
Board Enable Overview |
| 3 |
===================== |
| 4 |
|
| 5 |
**Note the document below was migrated from old website and the content >10yrs old** |
| 6 |
Patches to add/update documentation are very much appreciated. |
| 7 |
|
| 8 |
The term "board enable" describes mainboard specific code to make flash rom |
| 9 |
write access possible on this mainboard. Usually this means programming some |
| 10 |
directly programmable output pin (usually called general purpose I/O or GPIO for short) |
| 11 |
of the chipset that is connect to a write protect input of the BIOS ROM chip to release write protection. |
| 12 |
|
| 13 |
How to find the board enable procedure on your board |
| 14 |
==================================================== |
| 15 |
|
| 16 |
The reverse engineering method at the end is preferred because it has a bit lower risk. |
| 17 |
|
| 18 |
Try & Error method on GPIO pins |
| 19 |
------------------------------- |
| 20 |
|
| 21 |
The following is a mail from Ron: |
| 22 |
|
| 23 |
we just had the need to find a flash write enable on some servers. |
| 24 |
These are Dell S1850s and we're tired of having a non-Linux-based Flash tool, |
| 25 |
and, still worse, one to which we do not have source. Flashrom would be great, |
| 26 |
save that it can't get the flash to write. We decided to see if it was the classic |
| 27 |
GPIO-enabled FLASH write pin, which is the standard it seems in PC hardware. |
| 28 |
|
| 29 |
In this note I am just describing a program that I wrote long ago at LANL |
| 30 |
and have used from time to time when I could not get the info I needed on enabling FLASH write. |
| 31 |
|
| 32 |
One thing we have found over the past 10 years: the single most common write enable control |
| 33 |
is a GPIO attached to a southbridge. Don't know why it always seems to be this way, but there it is. |
| 34 |
|
| 35 |
This leads to a simple strategy to test for a GPIO enable, and to find which one it is. |
| 36 |
|
| 37 |
First, we find the southbridge, which in this case is an ICH5. |
| 38 |
The GPIO programming on this part is little changed from earlier parts. |
| 39 |
|
| 40 |
Then we find the pci function which has the GPIOs. It's usually the LPC bridge. |
| 41 |
|
| 42 |
So for ICH5: |
| 43 |
|
| 44 |
00:1f.0 ISA bridge: Intel Corporation 82801EB/ER (ICH5/ICH5R) LPC Interface Bridge (rev 02) |
| 45 |
|
| 46 |
it's that one. |
| 47 |
|
| 48 |
So, to make it easy, rather than look at the BAR for the GPIO, just ``cat /proc/ioports`` and find this:: |
| 49 |
|
| 50 |
0880-08bf : 0000:00:1f.0 |
| 51 |
0880-08bf : pnp 00:06 |
| 52 |
|
| 53 |
OK, we are about ready to go. The base address of the GPIOs is 0x880. |
| 54 |
If you're paranoid confirm it with setpci:: |
| 55 |
|
| 56 |
[root@tn4 ~]# setpci -s 0:1f.0 58.l |
| 57 |
00000881 |
| 58 |
[root@tn4 ~]# |
| 59 |
|
| 60 |
You need to look up the IO space mappings of SOME of the registers, |
| 61 |
but for this simple program, not ALL. In fact all we're going to do is |
| 62 |
read in the GPIO data level register, complement it, write it out, |
| 63 |
then run flashrom to see if it works. But, you ask: |
| 64 |
|
| 65 |
* what if you read inputs and write them out nothing, so don't worry. They're inputs. |
| 66 |
* you change GPIO pins that do some other thing well, it gets harder in that case. |
| 67 |
For instance, some laptops use a GPIO pin to enable DRAM power. |
| 68 |
Don't worry, you'll find out if they do. |
| 69 |
|
| 70 |
In that case, you'll have to do 32 boot/test cycles in the worst case, |
| 71 |
instead of the five we do here. It actually can be instructive on a laptop |
| 72 |
to change output GPIO levels and see what happens, so this is a fun test to do anyway. |
| 73 |
|
| 74 |
First, though, do this: ``flashrom -r factory.img`` |
| 75 |
|
| 76 |
Then ``emacs factory.img`` , (Go into OVRWRT mode!) and look for a string like this:: |
| 77 |
|
| 78 |
F2 = Setup |
| 79 |
|
| 80 |
I changed it to:: |
| 81 |
|
| 82 |
F2 = FIXup |
| 83 |
|
| 84 |
I may have used some other F-based words, as time went on, but that's another story. |
| 85 |
|
| 86 |
You want to make sure that if you really do rewrite it that it is easy to tell! |
| 87 |
With this change, as soon as the BIOS splash screen comes up, you will know. |
| 88 |
|
| 89 |
OK, some code: Just set a few things up we think we'll need.:: |
| 90 |
|
| 91 |
#include <stdio.h> |
| 92 |
#include <sys/io.h> |
| 93 |
|
| 94 |
#define LVL 0xc |
| 95 |
|
| 96 |
LVL is the level register for the GPIO. Now let's go to work.:: |
| 97 |
|
| 98 |
int main(int argc, char *argv[]) |
| 99 |
{ |
| 100 |
unsigned long gpioport = 0x880; |
| 101 |
unsigned long gpioval; |
| 102 |
iopl(3); |
| 103 |
/* first simple test: read in all GPIOs, complement them, |
| 104 |
* output them, see if flashrom works */ |
| 105 |
gpioval = inl(gpioport + LVL); |
| 106 |
printf("GPIO is 0x%x (default 0x1f1f0000)\n", gpioval); |
| 107 |
/* invert */ |
| 108 |
gpioval = ~gpioval; |
| 109 |
printf("GPIO will be set to 0x%x \n", gpioval); |
| 110 |
outl(gpioval, gpioport + LVL); |
| 111 |
gpioval = inl(gpioport + LVL); |
| 112 |
printf("GPIO is 0x%x \n", gpioval); |
| 113 |
} |
| 114 |
|
| 115 |
OK, call this program 'one'. At this point, you want to try a flashrom run. |
| 116 |
As it happens this works and is sufficient to allow us to use flashrom! |
| 117 |
|
| 118 |
How to finish the task? It's actually a fairly simple newtonian search. |
| 119 |
|
| 120 |
First try ``gpioval ^= 0xffff0000;`` |
| 121 |
|
| 122 |
If that works, then try 0xff000000, etc. etc. Even if you get it wrong, |
| 123 |
which I did, it still doesn't take long to find it. |
| 124 |
|
| 125 |
Warning, though: each time you try, be sure to change the FIXup string in the rom image, |
| 126 |
to be very very sure that you really did rewrite it. You need to be careful about this step. |
| 127 |
|
| 128 |
Anyway, hope that is a little useful. It really is a very simple process to find a GPIO enable. |
| 129 |
That's one reason that vendors are going to make this much, much harder on future systems. |
| 130 |
GPIO enables are not a security feature, in spite of what you may have heard; |
| 131 |
they are really accident protection in case some piece of software goes insane |
| 132 |
and starts writing to random memory locations. |
| 133 |
|
| 134 |
Reverse Engineering your BIOS |
| 135 |
----------------------------- |
| 136 |
|
| 137 |
Reverse engineering the BIOS is more straight-forward than just poking around all GPIO pins, |
| 138 |
but in itself a quite advanced topic, so it is explained in detail in :doc:`reverse_engineering`. |
| 139 |
It basically is about analyzing what the BIOS or the vendor tool does to update the flash rom. |
| 140 |
|
| 141 |
How to add the board enable to flashrom |
| 142 |
======================================= |
| 143 |
|
| 144 |
First, find out whether the board enable method you found out is already used for another mainboard. |
| 145 |
In the case that it is just raising or lowering one GPIO pin, it could be quite possible that this is the case. |
| 146 |
As we don't like code duplication, reuse that function. If it is named something like "board_vendor_model" |
| 147 |
but really just changes a single pin (board_epox_ep_bx3 is an example in r803), rename it to what it does, |
| 148 |
which would be intel_piix4_gpo22_raise in this case. Add a comment to the function that it also works on your board. |
| 149 |
|
| 150 |
If you don't find a function that does what you want, write it yourself, |
| 151 |
also trying to reuse codes for parts of what you have to do. |
| 152 |
Add a comment mentioning the board name and the involved chips in this case too. |
| 153 |
|
| 154 |
After having written an enable function, you just need to add it to the board enable table |
| 155 |
(board_pciids_enables). This table maps PCI IDs found on the board to the correct enabling functions. |
| 156 |
Be sure to write a good match (which mostly means that you have to choose onboard chips |
| 157 |
that have vendor-assigned subsystem IDs that are unique for each board that vendor produced). |
| 158 |
If a unique match is not possible at all, provide vendor and model name (short form, usually lower case only) |
| 159 |
as "coreboot IDs" for use with the "-m" option, which means that the board won't be autodetected |
| 160 |
but can be selected by hand. The board name and vendor name following the coreboot ID strings are freeform |
| 161 |
and should disply vendor and model name in their preferred form. |