From fb91d5675edf9a45141b69740f10979e221dd72e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 6 Sep 2020 10:35:33 -0600 Subject: [PATCH] binman: Support adding a U-Boot environment In some cases it is useful to include a U-Boot environment region in an image. This allows the board to start up with an environment ready to go. Add a new entry type for this. The input is a text file containing the environment entries, one per line, in the format: var=value Signed-off-by: Simon Glass Acked-by: Andy Shevchenko --- tools/binman/etype/u_boot_env.py | 42 +++++++++++++++++++++++++ tools/binman/ftest.py | 31 ++++++++++++++++++ tools/binman/test/174_env.dts | 20 ++++++++++++ tools/binman/test/175_env_no_size.dts | 19 +++++++++++ tools/binman/test/176_env_too_small.dts | 20 ++++++++++++ 5 files changed, 132 insertions(+) create mode 100644 tools/binman/etype/u_boot_env.py create mode 100644 tools/binman/test/174_env.dts create mode 100644 tools/binman/test/175_env_no_size.dts create mode 100644 tools/binman/test/176_env_too_small.dts diff --git a/tools/binman/etype/u_boot_env.py b/tools/binman/etype/u_boot_env.py new file mode 100644 index 0000000000..1694c2a6ee --- /dev/null +++ b/tools/binman/etype/u_boot_env.py @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018 Google, Inc +# Written by Simon Glass +# + +import struct +import zlib + +from binman.etype.blob import Entry_blob +from dtoc import fdt_util +from patman import tools + +class Entry_u_boot_env(Entry_blob): + """An entry which contains a U-Boot environment + + Properties / Entry arguments: + - filename: File containing the environment text, with each line in the + form var=value + """ + def __init__(self, section, etype, node): + super().__init__(section, etype, node) + + def ReadNode(self): + super().ReadNode() + if self.size is None: + self.Raise("'u-boot-env' entry must have a size property") + self.fill_value = fdt_util.GetByte(self._node, 'fill-byte', 0) + + def ReadBlobContents(self): + indata = tools.ReadFile(self._pathname) + data = b'' + for line in indata.splitlines(): + data += line + b'\0' + data += b'\0'; + pad = self.size - len(data) - 5 + if pad < 0: + self.Raise("'u-boot-env' entry too small to hold data (need %#x more bytes)" % -pad) + data += tools.GetBytes(self.fill_value, pad) + crc = zlib.crc32(data) + buf = struct.pack('; + #size-cells = <1>; + + binman { + u-boot { + }; + u-boot-env { + filename = "env.txt"; + size = <0x18>; + fill-byte = [ff]; + }; + u-boot-nodtb { + }; + }; +}; diff --git a/tools/binman/test/175_env_no_size.dts b/tools/binman/test/175_env_no_size.dts new file mode 100644 index 0000000000..267acd1549 --- /dev/null +++ b/tools/binman/test/175_env_no_size.dts @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + u-boot-env { + filename = "env.txt"; + fill-byte = [ff]; + }; + u-boot-nodtb { + }; + }; +}; diff --git a/tools/binman/test/176_env_too_small.dts b/tools/binman/test/176_env_too_small.dts new file mode 100644 index 0000000000..2db8d05463 --- /dev/null +++ b/tools/binman/test/176_env_too_small.dts @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + u-boot-env { + filename = "env.txt"; + size = <0x8>; + fill-byte = [ff]; + }; + u-boot-nodtb { + }; + }; +}; -- 2.39.5