From 13982ced2ccce0838afb6db87f05b2cd74355b56 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 8 Jul 2022 23:50:43 +0200 Subject: cmd: fdt: Add support for reading stringlist property values The fdt command currently handles stringlists as strings in 'fdt get value' subcommand. Since strings in FDT stringlists are separated by '\0', only the first value gets inserted into the environment variable passed to the 'fdt get value' command. Example, consider the following DT snippet: / { compatible = "foo", "bar" }; The following command only reports the first string in stringlist: => fdt get value var / compatible ; print var foo It is not possible to assign list of null-terminated strings into U-Boot environment variable. Add optional 'index' parameter to the subcommand 'fdt get value []' which lets user specify which string within the stringlist should be assigned into the 'var' variable. The default value of 'index' is 0 in case it is not present. This way the 'fdt' command API does not change and existing scripts are not broken. The following command now reports the Nth string in stringlist, counting from zero: => fdt get value var / compatible 1 ; print var bar Signed-off-by: Marek Vasut Cc: Heinrich Schuchardt Cc: Simon Glass Cc: Tom Rini --- cmd/fdt.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index 842e6cb..6fbd920 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -48,11 +48,27 @@ void set_working_fdt_addr(ulong addr) /* * Get a value from the fdt and format it to be set in the environment */ -static int fdt_value_env_set(const void *nodep, int len, const char *var) +static int fdt_value_env_set(const void *nodep, int len, + const char *var, int index) { - if (is_printable_string(nodep, len)) - env_set(var, (void *)nodep); - else if (len == 4) { + if (is_printable_string(nodep, len)) { + const char *nodec = (const char *)nodep; + int i; + + /* + * Iterate over all members in stringlist and find the one at + * offset $index. If no such index exists, indicate failure. + */ + for (i = 0; i < len; i += strlen(nodec) + 1) { + if (index-- > 0) + continue; + + env_set(var, nodec + i); + return 0; + } + + return 1; + } else if (len == 4) { char buf[11]; sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep)); @@ -426,10 +442,14 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return 0; } else if (nodep && len > 0) { if (subcmd[0] == 'v') { + int index = 0; int ret; + if (argc == 7) + index = simple_strtoul(argv[6], NULL, 10); + ret = fdt_value_env_set(nodep, len, - var); + var, index); if (ret != 0) return ret; } else if (subcmd[0] == 'a') { @@ -1085,7 +1105,9 @@ static char fdt_help_text[] = "fdt resize [] - Resize fdt to size + padding to 4k addr + some optional if needed\n" "fdt print [] - Recursive print starting at \n" "fdt list [] - Print one level starting at \n" - "fdt get value - Get and store in \n" + "fdt get value [] - Get and store in \n" + " In case of stringlist property, use optional \n" + " to select string within the stringlist. Default is 0.\n" "fdt get name - Get name of node and store in \n" "fdt get addr - Get start address of and store in \n" "fdt get size [] - Get size of [] or num nodes and store in \n" -- cgit v1.1 From d64af08f19132c85422b442657920f4024b5caf7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 17 Sep 2022 09:01:19 -0600 Subject: binman: Get futility by building it A binary download is not great, since it depends on libraries being present in the system. Build futility from source instead. Signed-off-by: Simon Glass --- tools/binman/bintool.py | 10 +++++++--- tools/binman/btool/futility.py | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/binman/bintool.py b/tools/binman/bintool.py index 032179a..a582d9d 100644 --- a/tools/binman/bintool.py +++ b/tools/binman/bintool.py @@ -319,7 +319,7 @@ class Bintool: return result.stdout @classmethod - def build_from_git(cls, git_repo, make_target, bintool_path): + def build_from_git(cls, git_repo, make_target, bintool_path, flags=None): """Build a bintool from a git repo This clones the repo in a temporary directory, builds it with 'make', @@ -330,6 +330,7 @@ class Bintool: make_target (str): Target to pass to 'make' to build the tool bintool_path (str): Relative path of the tool in the repo, after build is complete + flags (list of str): Flags or variables to pass to make, or None Returns: tuple: @@ -341,8 +342,11 @@ class Bintool: print(f"- clone git repo '{git_repo}' to '{tmpdir}'") tools.run('git', 'clone', '--depth', '1', git_repo, tmpdir) print(f"- build target '{make_target}'") - tools.run('make', '-C', tmpdir, '-j', f'{multiprocessing.cpu_count()}', - make_target) + cmd = ['make', '-C', tmpdir, '-j', f'{multiprocessing.cpu_count()}', + make_target] + if flags: + cmd += flags + tools.run(*cmd) fname = os.path.join(tmpdir, bintool_path) if not os.path.exists(fname): print(f"- File '{fname}' was not produced") diff --git a/tools/binman/btool/futility.py b/tools/binman/btool/futility.py index 75a05c2..04c9aef 100644 --- a/tools/binman/btool/futility.py +++ b/tools/binman/btool/futility.py @@ -160,8 +160,17 @@ class Bintoolfutility(bintool.Bintool): Raises: Valuerror: Fetching could not be completed """ - if method != bintool.FETCH_BIN: + if method != bintool.FETCH_BUILD: return None - fname, tmpdir = self.fetch_from_drive( - '1hdsInzsE4aJbmBeJ663kYgjOQyW1I-E0') - return fname, tmpdir + + # The Chromium OS repo is here: + # https://chromium.googlesource.com/chromiumos/platform/vboot_reference/ + # + # Unfortunately this requires logging in and obtaining a line for the + # .gitcookies file. So use a mirror instead. + result = self.build_from_git( + 'https://github.com/sjg20/vboot_reference.git', + 'all', + 'build/futility/futility', + flags=['USE_FLASHROM=0']) + return result -- cgit v1.1