When requested, prefix multipart blobs with an index structure.
An index is requested by having a with_index property in the blob or keyblock
type entries in the fdt fmap. The index structure has a 32 bit count, and then
pairs of 32 bit integers which have the offset and length of each
subcomponent. The device tree FMAP is adjusted to reflect the new offsets of
the subcomponents.
BUG=chrome-os-partner:16412
TEST=Built U-Boot with and without this change on Link and verified that it
still booted. As part of debugging, printed out the contents of the index and
the start of the RW firmware from within U-Boot and verified that they were
what we expected. Built snow firmware with and without this change and
verified that it was byte identical except for a version string which was
repeated a few times. Booted firmware built with this change on snow.
BRANCH=None
Change-Id: Ibe5ea068d63c3217e6d898c1bc0cf484cc76da56
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: https://gerrit.chromium.org/gerrit/41188
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
diff --git a/host/lib/tools.py b/host/lib/tools.py
index 1a5047e..3a80302 100755
--- a/host/lib/tools.py
+++ b/host/lib/tools.py
@@ -21,6 +21,7 @@
import os
import re
import shutil
+import struct
import sys
import tempfile
import unittest
@@ -225,11 +226,12 @@
fd.write(data)
fd.close()
- def ReadFileAndConcat(self, filenames, compress=None):
+ def ReadFileAndConcat(self, filenames, compress=None, with_index=False):
"""Read several files and concat them.
Args:
filenames: a list containing name of the files to read.
+ with_index: If true, an index structure is prepended to the data.
Returns:
A tuple of a string and two list. The string is the concated data read
@@ -237,16 +239,28 @@
first list contains the offset of each file in the data string and
the second one contains the actual (non-padded) length of each file,
both in the same order.
+
+ The optional index structure is a 32 bit integer set to the number of
+ entries in the index, followed by that many pairs of integers which
+ describe the offset and length of each chunk.
"""
data = ''
- offset = []
- length = []
+ offsets = []
+ lengths = []
for fname in filenames:
- offset.append(len(data))
+ offsets.append(len(data))
content = self.ReadFile(fname)
pad_len = ((len(content) + 3) & ~3) - len(content)
data += content + chr(0xff) * pad_len
- length.append(len(content))
+ lengths.append(len(content))
+
+ if with_index:
+ index_size = 4 + len(filenames) * 8
+ index = struct.pack("<I", len(filenames))
+ offsets = tuple(offset + index_size for offset in offsets)
+ for filename, offset, length in zip(filenames, offsets, lengths):
+ index += struct.pack("<II", offset, length)
+ data = index + data
if compress:
if compress == 'lzo':
@@ -261,7 +275,7 @@
data = self.ReadFile(outname)
else:
raise ValueError("Unknown compression method '%s'" % compress)
- return data, offset, length
+ return data, offsets, lengths
def GetChromeosVersion(self):
"""Returns the ChromeOS version string.