cros_bundle_firmware: Tidy up exynos bl2 handling

There was a bug where the nul terminator of the machine parameter
string was not counted, so fix that.

Also tidy up the progress and logging output for the user. Use the tools
ReadFile/WriteFile instead of copyfile so that file names and sizes are
logged.

BUG=chromium-os:28242
TEST=cros_bundle_firmware -v3; see that messages appear for progress and
also file size.

Change-Id: I4687a4a48a9302b62cf30cbf3eb2e306ec558a48
Reviewed-on: https://gerrit.chromium.org/gerrit/18931
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Commit-Ready: Simon Glass <sjg@chromium.org>
diff --git a/host/lib/bundle_firmware.py b/host/lib/bundle_firmware.py
index 6ce0242..a138f57 100644
--- a/host/lib/bundle_firmware.py
+++ b/host/lib/bundle_firmware.py
@@ -473,7 +473,6 @@
     Returns:
       The new contents of the parameter block, after updating.
     """
-    self._out.Info('Configuring BL2')
     version, size = struct.unpack('<2L', data[pos + 4:pos + 12])
     if version != 1:
       raise CmdError("Cannot update machine parameter block version '%d'" %
@@ -489,7 +488,7 @@
     param_list = struct.unpack('<%ds' % (len(data) - pos), data[pos:])[0]
     param_len = param_list.find('\0')
     param_list = param_list[:param_len]
-    pos += (param_len + 3) & ~3
+    pos += (param_len + 4) & ~3
 
     # Work through the parameters one at a time, adding each value
     new_data = ''
@@ -534,8 +533,10 @@
       pack: The firmware packer object
       orig_bl2: Filename of original BL2 file to modify.
     """
+    self._out.Info('Configuring BL2')
     bl2 = os.path.join(self._tools.outdir, 'updated-spl.bin')
-    shutil.copyfile(self._tools.Filename(orig_bl2), bl2)
+    data = self._tools.ReadFile(orig_bl2)
+    self._tools.WriteFile(bl2, data)
 
     # Locate the parameter block
     data = self._tools.ReadFile(bl2)