coreboot-kgpe-d16/util/flashrom
Carl-Daniel Hailfinger 59c36f97db During the conversion of flash chip accesses to helper functions, I
spotted assignments to volatile variables which were neither placed
inside the mmapped ROM area nor were they counters.
Due to the use of accessor functions, volatile usage can be reduced
significantly because the accessor functions take care of actually
performing the reads/writes correctly.

The following semantic patch spotted them (linebreak in python string
for readability reasons, please remove before usage):
@r exists@
expression b;
typedef uint8_t;
volatile uint8_t a;
position p1;
@@
 a@p1 = readb(b);

@script:python@
p1 << r.p1;
a << r.a;
b << r.b;
@@
print "* file: %s line %s has assignment to unnecessarily volatile
variable: %s = readb(%s);" % (p1[0].file, p1[0].line, a, b)

Result was:
HANDLING: sst28sf040.c
* file: sst28sf040.c line 44 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 43 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 42 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 41 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 40 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 39 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 38 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 58 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 57 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 56 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 55 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 54 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 53 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 52 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);

The following semantic patch uses the spatch builtin match printing
functionality by prepending a "*" to the line with the pattern:
@@
expression b;
typedef uint8_t;
volatile uint8_t a;
@@
* a = readb(b);

Result is:
HANDLING: sst28sf040.c
diff =
--- sst28sf040.c        2009-03-06 01:04:49.000000000 +0100
@@ -35,13 +35,6 @@ static __inline__ void protect_28sf040(v
        /* ask compiler not to optimize this */
        volatile uint8_t tmp;
 
-       tmp = readb(bios + 0x1823);
-       tmp = readb(bios + 0x1820);
-       tmp = readb(bios + 0x1822);
-       tmp = readb(bios + 0x0418);
-       tmp = readb(bios + 0x041B);
-       tmp = readb(bios + 0x0419);
-       tmp = readb(bios + 0x040A);
 }
 
 static __inline__ void unprotect_28sf040(volatile uint8_t *bios)
@@ -49,13 +42,6 @@ static __inline__ void unprotect_28sf040
        /* ask compiler not to optimize this */
        volatile uint8_t tmp;
 
-       tmp = readb(bios + 0x1823);
-       tmp = readb(bios + 0x1820);
-       tmp = readb(bios + 0x1822);
-       tmp = readb(bios + 0x0418);
-       tmp = readb(bios + 0x041B);
-       tmp = readb(bios + 0x0419);
-       tmp = readb(bios + 0x041A);
 }
 
 static __inline__ int erase_sector_28sf040(volatile uint8_t *bios,

It's arguably a bit easier to read if you get used to the leading "-"
for matching lines.

This patch was enabled by Coccinelle:
http://www.emn.fr/x-info/coccinelle/


Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Joseph Smith <joe@settoplinux.org>
-- 
http://www.hailfinger.org/


git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3973 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
2009-03-06 00:40:25 +00:00
..
82802ab.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
COPYING Add a copy of the GPL in the flashrom repository as it's an independent 2007-09-08 14:36:01 +00:00
Makefile flashrom: Driver for ST M29F002T/NT/B. T/NT TEST_OK_ PROBE READ ERASE WRITE 2009-01-26 06:42:02 +00:00
README flashrom: Document exit() codes introduced in r3907. 2009-01-26 02:20:56 +00:00
am29f040b.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
board_enable.c flashrom: MSI MS-7046 board enable 2009-02-02 22:55:26 +00:00
cbtable.c flashrom: Darwin / Mac OS X 2009-01-26 01:23:31 +00:00
chipset_enable.c Following patch fixes VIA SPI (VT8237S). It needs to have opcodes 2009-02-01 18:40:50 +00:00
coreboot_tables.h rename linuxbios_* files in utils repository. 2008-01-18 16:17:44 +00:00
en29f002a.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
flash.h flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
flashchips.c flashrom: Add SST25VF040.REMS with TEST_OK_ PROBE READ 2009-02-25 08:07:33 +00:00
flashrom.8 flashrom: Document exit() codes introduced in r3907. 2009-01-26 02:20:56 +00:00
flashrom.c flashrom: Fix broken flash chip base address logic 2009-02-09 20:26:14 +00:00
ichspi.c flashrom: Fix one dead increment and one dead assignment as found by clang. 2009-01-26 15:19:43 +00:00
it87spi.c flashrom: IT8718F works just like IT8716F. 2009-01-12 21:28:03 +00:00
jedec.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
layout.c flashrom: Check return value of fscanf()/fwrite()/fread() 2009-01-12 21:00:35 +00:00
m29f002.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
m29f400bt.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
mx29f002.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
physmap.c flashrom: exit(2) on /dev/mem open() failure and exit(3) on mmap() failure. 2009-01-26 02:04:19 +00:00
pm49fl00x.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
sb600spi.c Copyright update by Jason Wang for freshly written sb600 code. 2008-11-29 15:07:15 +00:00
sharplhf00l04.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
spi.c flashrom: SST25VF040B using 0x90 identification and AAI write. 2009-01-26 03:37:40 +00:00
spi.h Declare special commands to support the Atmel AT25F512A. 2008-11-28 23:47:55 +00:00
sst28sf040.c During the conversion of flash chip accesses to helper functions, I 2009-03-06 00:40:25 +00:00
sst39sf020.c I looked at the datasheet and erase_sector_39sf020() is totally and 2008-05-16 21:11:53 +00:00
sst49lf040.c Reduce serial output, otherwise flashing will fail very often (trivial). 2008-10-21 22:09:02 +00:00
sst49lfxxxc.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
sst_fwhub.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
stm50flw0x0x.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
udelay.c Coding-style fixes for flashrom, partly indent-aided (trivial). 2008-10-18 21:14:13 +00:00
w29ee011.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
w39v040c.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
w39v080fa.c flashrom: Use helper functions to access flash chips. 2009-03-05 19:24:22 +00:00
w49f002u.c Some cosmetic cleanups in the flashrom code and output. 2007-10-17 23:55:15 +00:00
wbsio_spi.c flashrom: Winbond SuperIO SPI driver. 2009-01-26 03:08:45 +00:00

README

-------------------------------------------------------------------------------
Flashrom README
-------------------------------------------------------------------------------

Flashrom is a universal flash programming utility for DIP, PLCC, or SPI
flash ROM chips. It can be used to flash BIOS/coreboot/firmware images.

(see http://coreboot.org for details on coreboot)


Build Requirements
------------------

To build the flashrom utility you need to install the following packages:

* pciutils
* pciutils-devel / pciutils-dev / libpci-dev
* zlib-devel / zlib1g-dev


Usage
-----

 $ flashrom [-rwvEVfLhR] [-c chipname] [-s exclude_start] [-e exclude_end]
            [-m [vendor:]part] [-l file.layout] [-i imagename] [file]
   -r | --read:                      read flash and save into file
   -w | --write:                     write file into flash (default when
                                     file is specified)
   -v | --verify:                    verify flash against file
   -E | --erase:                     erase flash device
   -V | --verbose:                   more verbose output
   -c | --chip <chipname>:           probe only for specified flash chip
   -s | --estart <addr>:             exclude start position
   -e | --eend <addr>:               exclude end postion
   -m | --mainboard <[vendor:]part>: override mainboard settings
   -f | --force:                     force write without checking image
   -l | --layout <file.layout>:      read rom layout from file
   -i | --image <name>:              only flash image name from flash layout
   -L | --list-supported:            print supported devices
   -h | --help:                      print this help text
   -R | --version:                   print the version (release)

 If no file is specified, then all that happens
 is that flash info is dumped and the flash chip is set to writable.


Exit status
-----------
flashrom exits with 0 on success, 1 on most failures but with 2 if /dev/mem
(/dev/xsvc on Solaris) can not be opened and with 3 if a call to mmap() fails.


coreboot Table and Mainboard Identification
--------------------------------------------

Flashrom reads the coreboot table to determine the current mainboard
(parse DMI as well in future?). If no coreboot table could be read
or if you want to override these values, you can specify -m, e.g.:

 $ flashrom -w --mainboard AGAMI:ARUMA agami_aruma.rom

See the 'Supported mainboards' section in the output of 'flashrom -L' for
a list of boards which require the specification of the board name, if no
coreboot table is found.


ROM Layout Support
------------------

Flashrom supports ROM layouts. This allows you to flash certain parts of
the flash chip only. A ROM layout file looks like follows:

  00000000:00008fff gfxrom
  00009000:0003ffff normal
  00040000:0007ffff fallback

  i.e.:
  startaddr:endaddr name

  All addresses are offsets within the file, not absolute addresses!
  
If you only want to update the normal image in a ROM you can say:

  flashrom -w --layout rom.layout --image normal agami_aruma.rom
     
To update normal and fallback but leave the VGA BIOS alone, say:

  flashrom -w -l rom.layout -i normal -i fallback agami_aruma.rom
 
Currently overlapping sections are not supported.

ROM layouts should replace the -s and -e option since they are more 
flexible and they should lead to a ROM update file format with the 
ROM layout and the ROM image in one file (cpio, zip or something?).


Disk on Chip support
--------------------

Disk on Chip support was removed from flashrom in r3382. It had already
been disabled by default in flashrom for several years because the code
was considered unstable and incomplete. The products intended to work
have been End-Of-Lifed by the manufacturer for a long time.


Supported Flash Chips / Chipsets / Mainboards
---------------------------------------------

Please check the output of 'flashrom -L' for the list of supported
flash chips, chipsets/southbridges, and mainboards.

See also http://coreboot.org/Flashrom for more details.