cros_bundle_firmware: Support generation of RW firmware

The only difference between RO and RW firmware is the preamable flags. Add
an easy option to force the flags to 0 (thus forcing RO firmware to boot
through RW).

BUG=chromium-os:35369
BRANCH=snow
TEST=manual
(auto test to come later before I close the bug)
$ cros_bundle_firmware -b daisy -d board/samsung/dts/exynos5250-snow.dts \
   -I cros/dts -I arch/arm/dts -O out
$ fdtdump out/updated.dtb |grep pream
            preamble-flags = <0x00000001>;
            preamble-flags = <0x00000001>;

$ cros_bundle_firmware -b daisy -d board/samsung/dts/exynos5250-snow.dts \
   -I cros/dts -I arch/arm/dts -O out --force-rw
$ fdtdump out/updated.dtb |grep pream
            preamble-flags = <0x00000000>;
            preamble-flags = <0x00000000>;

Reviewed-on: https://gerrit.chromium.org/gerrit/36738
Commit-Ready: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
(cherry picked from commit 6e486c2a4a8a3d1dba39a6661d099010c8bda3af)

Change-Id: I50864ef9f2801024958008ac02e02048c2b62587
Reviewed-on: https://gerrit.chromium.org/gerrit/37292
Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
diff --git a/host/cros_bundle_firmware b/host/cros_bundle_firmware
index e15e277..9877f13 100755
--- a/host/cros_bundle_firmware
+++ b/host/cros_bundle_firmware
@@ -83,7 +83,8 @@
                   exynos_bl1=options.exynos_bl1, exynos_bl2=options.exynos_bl2,
                   skeleton=options.skeleton, ecrw=options.ecrw,
                   ecro=options.ecro, kernel=options.kernel)
-  bundle.SetOptions(small=options.small, gbb_flags=options.gbb_flags)
+  bundle.SetOptions(small=options.small, gbb_flags=options.gbb_flags,
+                    force_rw=options.force_rw)
 
   try:
     # Set up the fdt and options that we want.
@@ -162,6 +163,8 @@
         action='store', help='EC read-only binary file')
   parser.add_option('-F', '--flash', dest='flash_dest', type='string',
       action='store', help='Create a flasher to flash the device (spi, mmc)')
+  parser.add_option('--force-rw', action='store_true',
+      help='Force jump to RW firmware')
   parser.add_option('--gbb-flags', type='string',
       action='store', help='''Set GBB flags:
 Argument is either a hex value like c2, or a list of flags, or a list of
diff --git a/host/lib/bundle_firmware.py b/host/lib/bundle_firmware.py
index 2f7b1cc..9b970a3 100644
--- a/host/lib/bundle_firmware.py
+++ b/host/lib/bundle_firmware.py
@@ -169,16 +169,19 @@
     self.ecro_fname = ecro
     self.kernel_fname = kernel
 
-  def SetOptions(self, small, gbb_flags):
+  def SetOptions(self, small, gbb_flags, force_rw=False):
     """Set up options supported by Bundle.
 
     Args:
       small: Only create a signed U-Boot - don't produce the full packed
           firmware image. This is useful for devs who want to replace just the
           U-Boot part while keeping the keys, gbb, etc. the same.
+      gbb_flags: Specification for string containing adjustments to make.
+      force_rw: Force firmware into RW mode.
     """
     self._small = small
     self._gbb_flags = gbb_flags
+    self._force_rw = force_rw
 
   def CheckOptions(self):
     """Check provided options and select defaults."""
@@ -899,6 +902,10 @@
     pack.AddProperty('skeleton', self.skeleton_fname)
     pack.AddProperty('dtb', fdt.fname)
 
+    if self._force_rw:
+        fdt.PutInteger('/flash/rw-a-vblock', 'preamble-flags', 0)
+        fdt.PutInteger('/flash/rw-b-vblock', 'preamble-flags', 0)
+
     # If we are writing a kernel, add its offset from TEXT_BASE to the fdt.
     if self.kernel_fname:
       fdt.PutInteger('/config', 'kernel-offset', pack.image_size)