cbf: accommodate storm coreboot layout

The cros_bundle_firmware (cbf) tool expects the RO coreboot blob not
to exceed 1MB in size. This has been the case so far, but storm breaks
this convention, at least presently.

Let's take the location of coreboot in the image from the fmap
supplied through the FDT. It remains to be seen if this will work for
all targets. Note that a refactor of this tool if planned for the near

BUG=chrome-os-partner:27784, chromium:384183
TEST=with all other changes landed, invoking

  emerge-storm chromeos-bootimage

  produces a bootable AP148 firmware which starts up, verifies kernel
  image placed on the USB stick, and then loads and starts the kernel.

Change-Id: Ia559e66a532f00df10df4d30fb5e6f9a9983090c
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/203548
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
diff --git a/host/lib/bundle_firmware.py b/host/lib/bundle_firmware.py
index 0651e8d..dbc3418 100644
--- a/host/lib/bundle_firmware.py
+++ b/host/lib/bundle_firmware.py
@@ -903,7 +903,21 @@
       data = self._tools.ReadFile(bootstub)
       bootstub_copy = os.path.join(self._tools.outdir, 'coreboot-8mb.rom')
       self._tools.WriteFile(bootstub_copy, data)
-      self._tools.WriteFile(bootstub, data[-0x100000:])
+      if self._board in ('storm', ):
+        # This is a hack, as storm does not fall into any of the two
+        # categories of images covered by the [-0x100000:] range. Not applying
+        # this to all targets yet, as it is not clear that they all would fit
+        # this scheme where the /flash/ro-boot node has the 'reg' property
+        # showing the location of the ro coreboot part in the image.
+        #
+        # The upcoming refactor of this tool will have to take care of this in
+        # a more consistent way.
+        fdt_ro_boot = fdt.GetProp('/flash/ro-boot', 'reg')
+        rom_range = [int(x) for x in fdt_ro_boot.split()]
+        self._tools.WriteFile(bootstub, data[rom_range[0]:rom_range[1]])
+      else:
+        self._tools.WriteFile(bootstub, data[-0x100000:])
     pack.AddProperty('fdtmap', fdt.fname)
     image = os.path.join(self._tools.outdir, 'image.bin')