bundle_firmware: run cbfstool through sh to enable variable expansion

For the cbfstool invocations controlled by the cbfs-files fmap.dts
attribute, run the command line through the shell so environment
variables are expanded.

BUG=chromium:48415
TEST=none

Change-Id: Ib4c69bf164d8441571c78ff8ed0987916c40501a
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://chromium-review.googlesource.com/317600
Commit-Ready: Patrick Georgi <pgeorgi@chromium.org>
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
diff --git a/host/lib/bundle_firmware.py b/host/lib/bundle_firmware.py
index 7f10c4d..2717dae 100644
--- a/host/lib/bundle_firmware.py
+++ b/host/lib/bundle_firmware.py
@@ -836,8 +836,12 @@
           raise CmdError("second argument in '%s' must be '-n'", f)
         cbfsname = f[2]
         try:
-          self._tools.Run('cbfstool', [cb_copy, 'remove', '-H', '%d' % base,
-                                       '-n', cbfsname])
+          # Calling through shell isn't strictly necessary here, but we still
+          # do it to keep operation more similar to the invocation in the next
+          # loop.
+          self._tools.Run('sh', [ '-c',
+            ' '.join(['cbfstool', cb_copy, 'remove', '-H', '%d' % base,
+                                       '-n', cbfsname]) ])
         except CmdError:
           pass # the most likely error is that the file doesn't already exist
 
@@ -847,9 +851,14 @@
         command = f[0]
         cbfsname = f[2]
         args = f[3:]
-        self._tools.Run('cbfstool', [cb_copy, command, '-H', '%d' % base,
-                                     '-n', cbfsname] + args,
-                                     self._tools.Filename(self._GetBuildRoot()))
+        # Call through shell so variable expansion can happen. With a change
+        # to the ebuild this enables specifying filename arguments to
+        # cbfstool as -f romstage.elf${COREBOOT_VARIANT} and have that be
+        # resolved to romstage.elf.serial when appropriate.
+        self._tools.Run('sh', [ '-c',
+            ' '.join(['cbfstool', cb_copy, command, '-H', '%d' % base,
+                      '-n', cbfsname] + args)],
+                      self._tools.Filename(self._GetBuildRoot()))
 
     # And extract the blob for the FW section
     rw_section = os.path.join(self._tools.outdir, '_'.join(part_sections))