1*4ab13489SMika Westerberg==============================
2*4ab13489SMika WesterbergUpgrading BIOS using spi-intel
3*4ab13489SMika Westerberg==============================
4*4ab13489SMika Westerberg
5*4ab13489SMika WesterbergMany Intel CPUs like Baytrail and Braswell include SPI serial flash host
6*4ab13489SMika Westerbergcontroller which is used to hold BIOS and other platform specific data.
7*4ab13489SMika WesterbergSince contents of the SPI serial flash is crucial for machine to function,
8*4ab13489SMika Westerbergit is typically protected by different hardware protection mechanisms to
9*4ab13489SMika Westerbergavoid accidental (or on purpose) overwrite of the content.
10*4ab13489SMika Westerberg
11*4ab13489SMika WesterbergNot all manufacturers protect the SPI serial flash, mainly because it
12*4ab13489SMika Westerbergallows upgrading the BIOS image directly from an OS.
13*4ab13489SMika Westerberg
14*4ab13489SMika WesterbergThe spi-intel driver makes it possible to read and write the SPI serial
15*4ab13489SMika Westerbergflash, if certain protection bits are not set and locked. If it finds
16*4ab13489SMika Westerbergany of them set, the whole MTD device is made read-only to prevent
17*4ab13489SMika Westerbergpartial overwrites. By default the driver exposes SPI serial flash
18*4ab13489SMika Westerbergcontents as read-only but it can be changed from kernel command line,
19*4ab13489SMika Westerbergpassing "spi_intel.writeable=1".
20*4ab13489SMika Westerberg
21*4ab13489SMika WesterbergPlease keep in mind that overwriting the BIOS image on SPI serial flash
22*4ab13489SMika Westerbergmight render the machine unbootable and requires special equipment like
23*4ab13489SMika WesterbergDediprog to revive. You have been warned!
24*4ab13489SMika Westerberg
25*4ab13489SMika WesterbergBelow are the steps how to upgrade MinnowBoard MAX BIOS directly from
26*4ab13489SMika WesterbergLinux.
27*4ab13489SMika Westerberg
28*4ab13489SMika Westerberg 1) Download and extract the latest Minnowboard MAX BIOS SPI image
29*4ab13489SMika Westerberg    [1]. At the time writing this the latest image is v92.
30*4ab13489SMika Westerberg
31*4ab13489SMika Westerberg 2) Install mtd-utils package [2]. We need this in order to erase the SPI
32*4ab13489SMika Westerberg    serial flash. Distros like Debian and Fedora have this prepackaged with
33*4ab13489SMika Westerberg    name "mtd-utils".
34*4ab13489SMika Westerberg
35*4ab13489SMika Westerberg 3) Add "spi_intel.writeable=1" to the kernel command line and reboot
36*4ab13489SMika Westerberg    the board (you can also reload the driver passing "writeable=1" as
37*4ab13489SMika Westerberg    module parameter to modprobe).
38*4ab13489SMika Westerberg
39*4ab13489SMika Westerberg 4) Once the board is up and running again, find the right MTD partition
40*4ab13489SMika Westerberg    (it is named as "BIOS")::
41*4ab13489SMika Westerberg
42*4ab13489SMika Westerberg	# cat /proc/mtd
43*4ab13489SMika Westerberg	dev:    size   erasesize  name
44*4ab13489SMika Westerberg	mtd0: 00800000 00001000 "BIOS"
45*4ab13489SMika Westerberg
46*4ab13489SMika Westerberg    So here it will be /dev/mtd0 but it may vary.
47*4ab13489SMika Westerberg
48*4ab13489SMika Westerberg 5) Make backup of the existing image first::
49*4ab13489SMika Westerberg
50*4ab13489SMika Westerberg	# dd if=/dev/mtd0ro of=bios.bak
51*4ab13489SMika Westerberg	16384+0 records in
52*4ab13489SMika Westerberg	16384+0 records out
53*4ab13489SMika Westerberg	8388608 bytes (8.4 MB) copied, 10.0269 s, 837 kB/s
54*4ab13489SMika Westerberg
55*4ab13489SMika Westerberg 6) Verify the backup::
56*4ab13489SMika Westerberg
57*4ab13489SMika Westerberg	# sha1sum /dev/mtd0ro bios.bak
58*4ab13489SMika Westerberg	fdbb011920572ca6c991377c4b418a0502668b73  /dev/mtd0ro
59*4ab13489SMika Westerberg	fdbb011920572ca6c991377c4b418a0502668b73  bios.bak
60*4ab13489SMika Westerberg
61*4ab13489SMika Westerberg    The SHA1 sums must match. Otherwise do not continue any further!
62*4ab13489SMika Westerberg
63*4ab13489SMika Westerberg 7) Erase the SPI serial flash. After this step, do not reboot the
64*4ab13489SMika Westerberg    board! Otherwise it will not start anymore::
65*4ab13489SMika Westerberg
66*4ab13489SMika Westerberg	# flash_erase /dev/mtd0 0 0
67*4ab13489SMika Westerberg	Erasing 4 Kibyte @ 7ff000 -- 100 % complete
68*4ab13489SMika Westerberg
69*4ab13489SMika Westerberg 8) Once completed without errors you can write the new BIOS image::
70*4ab13489SMika Westerberg
71*4ab13489SMika Westerberg    # dd if=MNW2MAX1.X64.0092.R01.1605221712.bin of=/dev/mtd0
72*4ab13489SMika Westerberg
73*4ab13489SMika Westerberg 9) Verify that the new content of the SPI serial flash matches the new
74*4ab13489SMika Westerberg    BIOS image::
75*4ab13489SMika Westerberg
76*4ab13489SMika Westerberg	# sha1sum /dev/mtd0ro MNW2MAX1.X64.0092.R01.1605221712.bin
77*4ab13489SMika Westerberg	9b4df9e4be2057fceec3a5529ec3d950836c87a2  /dev/mtd0ro
78*4ab13489SMika Westerberg	9b4df9e4be2057fceec3a5529ec3d950836c87a2 MNW2MAX1.X64.0092.R01.1605221712.bin
79*4ab13489SMika Westerberg
80*4ab13489SMika Westerberg    The SHA1 sums should match.
81*4ab13489SMika Westerberg
82*4ab13489SMika Westerberg 10) Now you can reboot your board and observe the new BIOS starting up
83*4ab13489SMika Westerberg     properly.
84*4ab13489SMika Westerberg
85*4ab13489SMika WesterbergReferences
86*4ab13489SMika Westerberg----------
87*4ab13489SMika Westerberg
88*4ab13489SMika Westerberg[1] https://firmware.intel.com/sites/default/files/MinnowBoard%2EMAX_%2EX64%2E92%2ER01%2Ezip
89*4ab13489SMika Westerberg
90*4ab13489SMika Westerberg[2] http://www.linux-mtd.infradead.org/
91