Automatically unmap physmap()s.

Similarly to the previous PCI self-clean up patch this one allows to get rid
of a huge number of programmer shutdown functions and makes introducing
bugs harder. It adds a new function rphysmap() that takes care of unmapping
at shutdown. Callers are changed where it makes sense.

Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
uintptr_t-ify physmap.c.

unsigned long is not the right type for manipulating pointer values.
Since C99 there are suitable unsigned and signed types available, namely
uintptr_t and intptr_t respectively.

Use them in physmap.c where applicable. This should be done in a lot of
other places in flashrom too, but that's a huge pile of work and we better
start it with a small step than never (which is the forseeable alternative ;)

This patch also changes the display width of all address values in
physmap.c to 16/8 hex characters depending on the architecture.
Allow physmap_common() to round address ranges to page boundaries.

Automatically round address ranges requested from rphysmap() to page
boundaries. Other physmap() variants were not changed so this is
safe regarding unmapping.

I had also to shorten the readbility defines for the physmap_common
parameters to make the calls fit a single line.

Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
Add an internal DMI decoder

Previously we had to rely on dmidecode to decode the DMI/SMBIOS table.
This patch integrates a DMI decoder into flashrom. The old behavior of calling
dmidecode can be brought back by setting DMI_INTERNAL to 0.

Significant portions of this patch were taken from dmidecode, hence add its
authors to the copyright notice (dmidecode is also GPL2+). We do a few things
differently though. First of all we do more bounds checking to prevent accessing
unmapped memory. We do not support disovery via EFI (yet), but memory
scanning only. We handle the chassis-type lock bit correctly.

The API to the rest of flashrom remains stable, but the output changes slightly.
To share as much code as possible (which actually is not much), i have added
dmi_fill methods that get called in dmi_init. They are reponsible to fill the
dmi_strings array and setting the is_laptop variable. After it is called, dmi_init
prints all dmi_strings. Previously the strings were printed in the order they were
discovered, followed by the chassis-type, which is now output earlier (in dmi_fill).

Signed-off-by: Sean Nelson<audiohacked@gmail.com>
Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
Tested-by: Maciej Pijanka <maciej.pijanka@gmail.com>
Tested-by: Idwer Vollering <vidwer@gmail.com>
Combine serialport_write and serialport_read into serialport_rw.

Because they share almost all code, combine them into serialport_rw
and export the old functions as wrappers. This makes reads "empty reads"-
aware and programmers able to detect such problems even on "blocking"
reads. Also, this fixes error detection on Windows.
Introduce serialport_config().

This allows to easily reconfigure a serial port as needed in
the Bus Pirate speedup.

Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
Get rid of sp_die().

- Export msg_perr_strerror()
- Add return values to sp_flush_stream(), sp_pass_writen(),
  sp_execute_opbuf(), sp_execute_opbuf_noflush(),
  sp_check_opbuf_usage(), sp_do_read_n().
- Use those return values to propagate errors instead of exiting.
  In some places this has to wait for core API changes (error handling for
  chip_readb, chip_readn, chip_write) hence comments are added instead.
layout: Add -i <image>[:<file>] support

Add an optional sub-parameter to the -i parameter to allow building the
image to be written from multiple files. This will also allow regions to
be read from flash and written to separate image files in a later patch.

based on chromiumos'
d0ea9ed71e7f86bb8e8db2ca7c32a96de25343d8
Signed-off-by: David Hendricks <dhendrix@chromium.org>

Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
---

TODO:
 - man page
 - handling or at least an explanation of precedence of command line
   parameters in case of overlapping regions.
Make read before write configurable (infrastructure part)

 - Introduce a variable in doit() that allows to influence
   read-before-write and its consequences.
 - Rename handle_romentries to build_new_image and a description of
   its purpose.
 - Modify build_new_image so that it still works even if the old content
   is not read before.
 - Add copy_old_content() to ease the pain for future patches.

Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>

---

TODO: add UI

This is completely wrong.

When the user wants to skip most of the chip AND wants to avoid the
safety net, it makes no sense at all to read most of the chip in
build_new_image. This is needed because the write/skip logic works by
comparing the old content with the new content.

In the case that old content is already known (because we have read
the whole chip before), this is no problem and even nice from a
architectural point of view. Allowing to skip the reading breaks the
concept though. This patch provides the ugly code that is necessary
so that this concept does not explode. It does not fix the concept
itself. In the case the user wants to write the whole chip, this
provides a real benefit. The smaller the region is that he wants to
update, the smaller the benefit becomes.

The real solution would be to provide the erase and write logic not
just a complete image, from which it can deduce what it can and
should skip, but also a layout-like map of what the user wants to be
changed (or something similar that allows the following). If the old
contents are known, then fine, but if not, read only the parts
needed due to erase block overheads and not everything unnecessarily.
Use layout for read operations too

Previously using layout files was useful for write operations only, for
reads it was ignored. This patch added layout handling for reads.

Based on the "Add -i <image>[:<file>] support" patch this one will
output the selected regions to files. If the optional argument is given
it is used as a file name, else the image name will be used.

---
TODO: man page

side note: the execution path of forced reads is wrong or at least
worth a look. it does not use doit() but calls read_flash_to_file()
directly.
Use layout for verify operations too

---
this still reads the whole image in...
(not for merge) Fix the "Use layout for verify operations too" patch in a hacky way

if you look at the second half of doit with this patch applied, it
is quite clear, that most of it should be guarded by a huge
if(write_it) clause. maybe move this into a function?
teh fuck