Debian Codegraph @

doc/user_docs/fw_updates_vs_spi_wp.rst

raw
1 ========================================
2 Firmware updates vs SPI write-protection
3 ========================================
4
5 Enabling write-protection of any kind is meant to obstruct changing data, but it also limits
6 what you can do to the part of firmware that's still writable. This document is meant to cover
7 some of the origins of such limitations and situations which might arise after
8 part of a flash chip has been protected.
9
10 Firmware updates after locking bootblock
11 ========================================
12
13 This section is primarily concerned with :code:`coreboot` with bootblock being protected from writing,
14 but similar problems can happen for any kind of firmware.
15
16 Risks of partial updates
17 ------------------------
18
19 Partial updates can produce an unbootable image if an old bootblock doesn't work with a more recent
20 version of :code:`coreboot`. This can be manifested in various ways ranging from an old bootblock not being able
21 to find new romstage to system booting successfully but data in :code:`coreboot` tables being mangled or incomplete.
22
23 The incompatibilities might happen when switching version of firmware or even when using the same version
24 with a slightly different configuration.
25
26 Another thing that can potentially cause trouble is CBFS layout. When bootblock is part of CBFS,
27 it doesn't necessarily have a fixed address, moreover it can change location as well if it depends on file size
28 (when bootblock's last byte must be the last byte of the image, which is the case on x86). If newer bootblock
29 is smaller such that an old WP range now covers bootblock and some other file, this file won't be fully updated
30 due to write-protection, potentially resulting in a corrupt image. Luckily, when bootblock is the last file
31 it's normally preceded by a significant amount of empty space, which won't let this situation to occur.
32
33 On top of that, last 4 bytes of the image contain offset to the master header of CBFS. Depending on
34 the :code:`coreboot` version this offset might be crucial for the loading of romstage, in which case moving CBFS
35 within the image without updating the offset (when it's locked by WP) can also prevent the system from booting.
36
37 Recovering from a broken state
38 ------------------------------
39
40 Since broken flash won't let the system to boot, the way to fix it is to flash the chip externally by connecting
41 it to a different device. A possible alternative could be to have a backup flash created beforehand and swapping
42 it for the broken one (not very applicable if swapping doesn't require soldering). There are also some mainboards
43 with dual flash chips one of which acts as a backup that can be restored by holding power on button long enough.
44
45 Flashing whole firmware image
46 =============================
47
48 The function of the hardware protection mechanism (:code:`W#` or :code:`W/` pin of flash chips) is to lock state of
49 software protection thus preventing it from being disabled. After the chip is physically unlocked by changing
50 the state of the pin, the state of the write protection doesn't change. However, in this state the protection
51 can be easily turned off programmatically, which is what :code:`flashrom` tries to do before performing an operation on a chip.
52
53 In other words, changing state of the WP pin might be enough to be able to flash the chip in full.
54 If :code:`flashrom` errors or you don't want to rely on the automatic behaviour, you can try to
55 explicitly disable the protection by running :code:`flashrom` like this::
56
57 flashrom --wp-disable
58
59 If you need to pass extra parameters to flash your chip (e.g., programmer or chip name), add them to the above command
60 (order of such parameters shouldn't matter).