mirror of
https://github.com/smaeul/u-boot.git
synced 2025-10-14 04:46:01 +01:00
binman: Fix unique names having '/.' for images read from files
Binman can embed a copy of the image description into the images it builds as a fdtmap entry, but it omits the /binman/<image-name> prefix from the node paths while doing so. When reading an already-built image file, entries are reconstructed using this fdtmap and their associated nodes still lack that prefix. Some entries like fit and vblock create intermediate files whose names are based on an entry unique name. This name is constructed from their node's path by concatenating the parents with dots up to the binman node, e.g. /binman/image/foo/bar becomes 'image.foo.bar'. However, we don't have this /binman/image prefix when replacing entries in such an image. The /foo/bar entry we read when doing so erroneously has the unique name of '/.foo.bar', causing permission errors when the entry attempts to create files based on that. Fix the unique-name generation by stopping at the '/' node like how it stops at the binman node. As the unique names are used as filenames, add tests that check if they're safe to use as filenames. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
9bb99fa958
commit
67bf2c8ded
@ -775,7 +775,7 @@ features to produce new behaviours.
|
|||||||
node = self._node
|
node = self._node
|
||||||
while node.parent:
|
while node.parent:
|
||||||
node = node.parent
|
node = node.parent
|
||||||
if node.name == 'binman':
|
if node.name in ('binman', '/'):
|
||||||
break
|
break
|
||||||
name = '%s.%s' % (node.name, name)
|
name = '%s.%s' % (node.name, name)
|
||||||
return name
|
return name
|
||||||
|
@ -5523,5 +5523,36 @@ fdt fdtmap Extract the devicetree blob from the fdtmap
|
|||||||
with self.assertRaises(ValueError) as e:
|
with self.assertRaises(ValueError) as e:
|
||||||
data = self._DoReadFile('231_pre_load_invalid_key.dts')
|
data = self._DoReadFile('231_pre_load_invalid_key.dts')
|
||||||
|
|
||||||
|
def _CheckSafeUniqueNames(self, *images):
|
||||||
|
"""Check all entries of given images for unsafe unique names"""
|
||||||
|
for image in images:
|
||||||
|
entries = {}
|
||||||
|
image._CollectEntries(entries, {}, image)
|
||||||
|
for entry in entries.values():
|
||||||
|
uniq = entry.GetUniqueName()
|
||||||
|
|
||||||
|
# Used as part of a filename, so must not be absolute paths.
|
||||||
|
self.assertFalse(os.path.isabs(uniq))
|
||||||
|
|
||||||
|
def testSafeUniqueNames(self):
|
||||||
|
"""Test entry unique names are safe in single image configuration"""
|
||||||
|
data = self._DoReadFileRealDtb('230_unique_names.dts')
|
||||||
|
|
||||||
|
orig_image = control.images['image']
|
||||||
|
image_fname = tools.get_output_filename('image.bin')
|
||||||
|
image = Image.FromFile(image_fname)
|
||||||
|
|
||||||
|
self._CheckSafeUniqueNames(orig_image, image)
|
||||||
|
|
||||||
|
def testSafeUniqueNamesMulti(self):
|
||||||
|
"""Test entry unique names are safe with multiple images"""
|
||||||
|
data = self._DoReadFileRealDtb('231_unique_names_multi.dts')
|
||||||
|
|
||||||
|
orig_image = control.images['image']
|
||||||
|
image_fname = tools.get_output_filename('image.bin')
|
||||||
|
image = Image.FromFile(image_fname)
|
||||||
|
|
||||||
|
self._CheckSafeUniqueNames(orig_image, image)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
34
tools/binman/test/230_unique_names.dts
Normal file
34
tools/binman/test/230_unique_names.dts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <1>;
|
||||||
|
|
||||||
|
binman {
|
||||||
|
size = <0xc00>;
|
||||||
|
allow-repack;
|
||||||
|
|
||||||
|
u-boot {
|
||||||
|
};
|
||||||
|
|
||||||
|
fdtmap {
|
||||||
|
};
|
||||||
|
|
||||||
|
u-boot2 {
|
||||||
|
type = "u-boot";
|
||||||
|
};
|
||||||
|
|
||||||
|
text {
|
||||||
|
text = "some text";
|
||||||
|
};
|
||||||
|
|
||||||
|
u-boot-dtb {
|
||||||
|
};
|
||||||
|
|
||||||
|
image-header {
|
||||||
|
location = "end";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
38
tools/binman/test/231_unique_names_multi.dts
Normal file
38
tools/binman/test/231_unique_names_multi.dts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <1>;
|
||||||
|
|
||||||
|
binman {
|
||||||
|
multiple-images;
|
||||||
|
|
||||||
|
image {
|
||||||
|
size = <0xc00>;
|
||||||
|
allow-repack;
|
||||||
|
|
||||||
|
u-boot {
|
||||||
|
};
|
||||||
|
|
||||||
|
fdtmap {
|
||||||
|
};
|
||||||
|
|
||||||
|
u-boot2 {
|
||||||
|
type = "u-boot";
|
||||||
|
};
|
||||||
|
|
||||||
|
text {
|
||||||
|
text = "some text";
|
||||||
|
};
|
||||||
|
|
||||||
|
u-boot-dtb {
|
||||||
|
};
|
||||||
|
|
||||||
|
image-header {
|
||||||
|
location = "end";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user