cros_bundle_firmware: Put the updated fdt in coreboot cbfs

At present we put the original unmodified fdt file into the coreboot
rom. This is fine if cros_bundle_firmware doesn't update it, but it
does. To date these changes have not mattered much, but now we need to
pass the position of the EC binary in, so need the code to do the right
thing.

We can't currently use the ARM approach of just tacking the file onto
the end of the U-Boot section, since we have no guarantee that
coreboot's ELF loader will even load data we put there. We could do
that if we switched coreboot to loading a raw binary U-Boot instead of
an ELF file. But for now, add the fdt file after it has been updated
fully.

BUG=chrome-os-partner:11148
TEST=manual
$ cros_bundle_firmware -u u-boot.bin -d board/chromebook-x86/dts/link.dts
       -I arch/x86/dts -I cros/dts -b link -w em100

Run on link, type 'vboot_test fmap'
See that ecbin fields are non-zero.

Change-Id: Ie183a5fb04211e959d45376b86dc264f453c3c66
Reviewed-on: https://gerrit.chromium.org/gerrit/28174
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Ready: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
diff --git a/host/lib/bundle_firmware.py b/host/lib/bundle_firmware.py
index ed281bd..d5a1d78 100644
--- a/host/lib/bundle_firmware.py
+++ b/host/lib/bundle_firmware.py
@@ -551,17 +551,16 @@
 
     return bootstub, signed_postload
 
-  def _CreateCorebootStub(self, uboot, coreboot, fdt, seabios):
+  def _CreateCorebootStub(self, uboot, coreboot, seabios):
     """Create a coreboot boot stub.
 
     Args:
       uboot: Path to u-boot.bin (may be chroot-relative)
       coreboot: Path to coreboot.rom
-      fdt: Device Tree
       seabios: Path to SeaBIOS payload binary or None
 
     Returns:
-      Full path to bootstub (coreboot + uboot + fdt).
+      Full path to bootstub (coreboot + uboot).
 
     Raises:
       CmdError if a command fails.
@@ -583,8 +582,8 @@
     else:
         self._tools.Run('cbfstool', [bootstub, 'add-payload', uboot_elf,
             'fallback/payload', 'lzma'])
-    self._tools.Run('cbfstool', [bootstub, 'add', fdt.fname, 'u-boot.dtb',
-        '0xac'])
+
+    # Don't add the fdt yet since it is not in final form
     return bootstub
 
   def _UpdateBl2Parameters(self, fdt, spl_load_size, data, pos):
@@ -733,7 +732,7 @@
     """
     if blob_type == 'coreboot':
       coreboot = self._CreateCorebootStub(self.uboot_fname,
-          self.coreboot_fname, fdt, self.seabios_fname)
+          self.coreboot_fname, self.seabios_fname)
       pack.AddProperty('coreboot', coreboot)
       pack.AddProperty('image', coreboot)
     elif blob_type == 'signed':
@@ -838,6 +837,19 @@
     # Record position and size of all blob members in the FDT
     pack.UpdateBlobPositions(fdt)
 
+    # TODO(sjg@chromium.org): This is not in a good place. _CreateCorebootStub
+    # has created a rom file without the dtb, because until now it is not
+    # complete. Add the dtb here.
+    # A better anwer might be to put the dtb in memory immediately after
+    # U-Boot as is done for ARM and have coreboot load it as a binary file
+    # instead of an elf. However, I need to check whether coreboot supports
+    # this, and whether this is desirable for other reasons.
+    if 'coreboot' in blob_list:
+      bootstub = pack.GetProperty('coreboot')
+      fdt = fdt.Copy(os.path.join(self._tools.outdir, 'bootstub.dtb'))
+      self._tools.Run('cbfstool', [bootstub, 'add', fdt.fname, 'u-boot.dtb',
+          '0xac'])
+
     image = os.path.join(self._tools.outdir, 'image.bin')
     pack.PackImage(self._tools.outdir, image)
     pack.AddProperty('image', image)