cros_write_firmware: Extract U-Boot from payload image in extremis
When using cros_write_firmware outside of the chroot, it is inconvenient
to have to provide u-boot.bin and other components just so that
write_firmware can build a flasher.
In fact all the necessary components are in the image and can be extracted
from this automatically. Add this feature.
BUG=chromium-os:38684
TEST=manual
Remove the files from the firmware directory:
$ sudo rm /build/daisy/firmware/smdk5250-spl.*
$ sudo rm /build/daisy/firmware/E5250.nbl1.bin
$ sudo rm /build/daisy/firmware/u-boot.bin
Check that cros_write_firmware still works and prints appropriate warnings:
$ cros_write_firmware -b daisy /build/daisy/firmware/image-snow.bin \
-d exynos250-snow -F spi
Extracting U-Boot from payload
Extracting BL1 from payload
Extracting BL2 from payload
...
Run the same with the -D flag:
$ cros_write_firmware -b daisy /build/daisy/firmware/image-snow.bin \
-d /build/daisy/firmware/dts/exynos5250-snow.dts -F spi
Extracting U-Boot from payload
Extracting BL1 from payload
Extracting BL2 from payload
...
Change-Id: I38a5651d3fe82f256d64a1d628f514bbadfc753f
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/43005
diff --git a/host/lib/write_firmware.py b/host/lib/write_firmware.py
index 4df891e..fd8b60a 100644
--- a/host/lib/write_firmware.py
+++ b/host/lib/write_firmware.py
@@ -470,8 +470,12 @@
bl2_end = uboot_offset - 0x800
self._tools.WriteFile(bl2, data[0x2000:bl2_end])
+ # U-Boot itself starts at 24KB, after the gap. As a hack, truncate it
+ # to an assumed maximum size.
+ # TODO(sjg@chromium.org): Get a proper flash map here so we know how
+ # large it is
# U-Boot itself starts after the gap
- self._tools.WriteFile(image, data[uboot_offset:])
+ self._tools.WriteFile(image, data[uboot_offset:uboot_offset + 0xa0000])
return bl1, bl2, image
def ExynosFlashImage(self, flash_dest, flash_uboot, bl1, bl2, payload,
@@ -493,10 +497,23 @@
Returns:
True if ok, False if failed.
"""
+ tools = self._tools
+ payload_bl1, payload_bl2, payload_image = (
+ self._ExtractPayloadParts(payload))
if flash_dest:
+ # If we don't have some bits, get them from the image
+ if not flash_uboot or not os.path.exists(tools.Filename(flash_uboot)):
+ self._out.Warning('Extracting U-Boot from payload')
+ flash_uboot = payload_image
+ if not bl1 or not os.path.exists(tools.Filename(bl1)):
+ self._out.Warning('Extracting BL1 from payload')
+ bl1 = payload_bl1
+ if not bl2 or not os.path.exists(tools.Filename(bl2)):
+ self._out.Warning('Extracting BL2 from payload')
+ bl2 = payload_bl2
image = self._PrepareFlasher(flash_uboot, payload, flash_dest, '1:0')
else:
- bl1, bl2, image = self._ExtractPayloadParts(payload)
+ bl1, bl2, image = payload_bl1, payload_bl2, payload_image
vendor_id = 0x04e8
product_id = 0x1234