Add flashrom memory layout detection by FMAP (using fmap_decode)

To support arbitrary memory layout in the future, we need to support
fmap_decode.

Before starting using / testing:
(1) you must have fmap_decode ( http://code.google.com/p/flashmap/ ) installed and in PATH.
    on systems without fmap_decode, flashrom_util will fallback to internal layout.
(2) you must have a BIOS firmware image with FMAP. (most recent images already have that - you can execute fmap_decode FILENAME to check)

To use it <flashrom_util>:
Add an extra image (flashrom image content, usually read  by flashrom_util::read_whole() ) parameter when you call flashrom_util::detect_*_layout.
If fmap_decode is found in system PATH and the image does have fmap, flashrom_util will use its layout instead.

To use it <FlashromUtility>:
No need to change anything. FlashromUtility will try to use fmap_decode if it's available.

To verify / test:
 image = open(firmware_filename).read()
 <base test>
  # check the if the output offset/names are the same by compile_layout / decode_fmap_layout to same image.
  print compile_layout(DEFAULT_CHROMEOS_FIRMWARE_LAYOUT_DESCRIPTIONS['bios'], len(image))
  print decode_fmap_layout(DEFAULT_CHROMEOS_FMAP_CONVERTION, image)

 <integrated test>
  # without image, only internal layout is used.
  print flashrom.detect_chromeos_bios_layout(len(image))
  # with image, fmap will be tried.
  print flashrom.detect_chromeos_bios_layout(len(image), image)

BUG=chrome-os-partner:920
TEST=manual

Change-Id: I810a3a3ac8885ff4ac245c77d5b0ea8bcaec86de

Review URL: http://codereview.chromium.org/3246002
4 files changed