Refine physical address mapping of flash chips.

 - Create distinct functions for mapping and unmapping for flash chips.
 - Map only when needed: map before probing and unmap immediately
   after it. Map again when a single chip was probed successfully before
   taking any actual actions and clean up afterwards.
 - Map special function chip registers centrally together with flash space
   instead of within (some) probing methods after successful probes.
 - Save the used base addresses of the mappings in struct flashctx as well.
 - Do not try to (un)map the zero-sized chip definitions that are merely hacks.
   This also fixes the printing of wrong warnings for these chip definitions
   introduced in r1765.

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

git-svn-id: svn://flashrom.org/flashrom/trunk@1847 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Introduce generic shutdown_free() and remove redundant internal_shutdown().

The former will be useful in cases where cleanup equals a simple call to free().

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

git-svn-id: svn://flashrom.org/flashrom/trunk@1848 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
dmi.c: Duplicate returned strings because they are meant to be freed.

Without this patch dmi_shutdown calls free() on read-only strings.

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

git-svn-id: svn://flashrom.org/flashrom/trunk@1849 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Add support for Winbond W25Q40.V chips.

Read-tested by Peter Ruesch.

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

git-svn-id: svn://flashrom.org/flashrom/trunk@1850 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Make read before write configurable (infrastructure part).

 - Introduce a variable in doit() that allows to influence
   read-before-write and its consequences.
 - 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>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>

git-svn-id: svn://flashrom.org/flashrom/trunk@1851 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
dmi.c: make sure we call isprint() correctly.

ISO C and POSIX require to call ctype functions with values representable
by unsigned char. We have used a char as input so far which might be
negative and hence get sign-extended.

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

git-svn-id: svn://flashrom.org/flashrom/trunk@1852 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Introduce helpers.c and unquote_string().

The unquoting function is the first to be moved to the new file which will
host various utility functions to be shared by multiple files but which do not
fit elsewhere.

unquote_string() extracts a possibly quoted phrase from a string by
using a set of separator characters, which is useful to allow user input
to be optionally quoted to support spaces within names such a region or
file names.
layout: Add -i <region>[:<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.
Existing function read_buf_from_file() is refined and reused to read the file.

based on chromiumos'
d0ea9ed71e7f86bb8e8db2ca7c32a96de25343d8
Signed-off-by: David Hendricks <dhendrix@chromium.org>
Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
layout: Better file parsing.

A complete rewrite of the layout file parser:
 - safe (unlike before)
 - support for comments
 - supports including/sourcing of other layout files (relative to the including
   file as well as via absolute paths) up to predefined nesting level
 - checks for duplicate region names
 - can handle region names and layout file names with spaces etc correctly
 - way better diagnostics
 - no more character arrays in struct romentry_t but pointers only

To help with migrating legacy layout files add a script for converting them
to format 2.

Also, document the whole layout handling including the new features a bit better
and refine wording regarding files, images, layouts and regions as discussed.
layout: Add support for top-aligned addresses.
layout: Add preliminary support for flags.
[WIP] layout: Bailout early in process_include_args() if region file is inaccessible.
layout: Add support 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 separate files. If the optional
argument is given it is used as a file name, else the region 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?
docs
Remove the explicit action limitation of a layout file is given.