cros_bundle_firmware: Update the BL2 checksum for exynos

We must update the checksum for the BL2. USB download has always required
it, and now with new BL1 apparently other booting options require it also.

cros_bundle_firmware -b daisy -w usb -B spi
See that it now downloads and runs the BL2 correctly

Change-Id: I6c814fe85df68faefcc9d4a195aab5f912312e72
Tested-by: Simon Glass <>
Reviewed-by: Doug Anderson <>
Tested-by: Doug Anderson <>
Commit-Ready: Doug Anderson <>
(cherry picked from commit e5e8afb753618ab0c57561161d116a48a0e152c0)
diff --git a/host/lib/ b/host/lib/
index d153b69..3a86641 100644
--- a/host/lib/
+++ b/host/lib/
@@ -611,6 +611,23 @@
     self._out.Info('BL2 configuration complete')
     return data
+  def _UpdateChecksum(self, data):
+    """Update the BL2 checksum.
+    The checksum is a 4 byte sum of all the bytes in the image before the
+    last 4 bytes (which hold the checksum).
+    Args:
+      data: The BL2 data to update.
+    Returns:
+      The new contents of the BL2 data, after updating the checksum.
+    """
+    checksum = 0
+    for ch in data[:-4]:
+      checksum += ord(ch)
+    return data[:-4] + struct.pack('<L', checksum & 0xffffffff)
   def _ConfigureExynosBl2(self, fdt, pack, orig_bl2):
     """Configure an Exynos BL2 binary for our needs.
@@ -634,6 +651,7 @@
       raise CmdError("Could not find machine parameter block in '%s'" %
     data = self._UpdateBl2Parameters(fdt, pack, data, pos)
+    data = self._UpdateChecksum(data)
     self._tools.WriteFile(bl2, data)
     return bl2