cros_bundle_firmware: Handle new upstream U-Boot
Between now and the new release it looks like mainline U-Boot will change
its first instruction on ARMv7. Adjust things so that we can deal with
both cases.
This is pretty fragile, so hopefully we can come up with a better
method. The information we need is in the device tree, but perhaps a better
solution is to move to variable-sized SPL where we can read the U-Boot
header and not have to scan the image.
BUG=chromium:245311
BRANCH=none
TEST=manual
Build and boot upstream U-Boot on snow with Albert's new patches, currently
going through variable revisions, but titled as follows:
arm: factorize relocate_code routine
arm: make relocation section symbols compiler-generated
arm: make __image_copy_{start, end} compiler-generated
Rename arch/arm/lib/bss.c to sections.c
Change-Id: Ifeb1fb9a0065bdbab7621637a4aea4f1d9836b92
Reviewed-on: https://gerrit.chromium.org/gerrit/55547
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Commit-Queue: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
diff --git a/host/lib/write_firmware.py b/host/lib/write_firmware.py
index 28e6a91..3b205f4 100644
--- a/host/lib/write_firmware.py
+++ b/host/lib/write_firmware.py
@@ -460,17 +460,18 @@
bl1_size = 0x2000
self._tools.WriteFile(bl1, data[:bl1_size])
- # Try to detect the BL2 size. We look for 0xea000014 which is the
- # 'B reset' instruction at the start of U-Boot. When U-Boot is LZO
- # compressed, we look for a LZO magic instead.
- first_instr = struct.pack('<L', 0xea000014)
- lzo_magic = struct.pack('>B3s', 0x89, 'LZO')
- first_instr_offset = data.find(first_instr, bl1_size + 0x3800)
- lzo_magic_offset = data.find(lzo_magic, bl1_size + 0x3800)
- uboot_offset = min(first_instr_offset, lzo_magic_offset)
- if uboot_offset == -1:
- uboot_offset = max(first_instr_offset, lzo_magic_offset)
- if uboot_offset == -1:
+ # Try to detect the BL2 size. We look for 0xea000014 or 0xea000013
+ # which is the 'B reset' instruction at the start of U-Boot. When
+ # U-Boot is LZO compressed, we look for a LZO magic instead.
+ start_data = [struct.pack('<L', 0xea000014),
+ struct.pack('<L', 0xea000013),
+ struct.pack('>B3s', 0x89, 'LZO')]
+ starts = [data.find(magic, bl1_size + 0x3800) for magic in start_data]
+ uboot_offset = None
+ for start in starts:
+ if start != -1 and (not uboot_offset or start < uboot_offset):
+ uboot_offset = start
+ if not uboot_offset:
raise ValueError('Could not locate start of U-Boot')
bl2_size = uboot_offset - bl1_size - 0x800 # 2KB gap after BL2