From 86aeacca6792128cf16cd054a69018346a7aa601 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 15 Dec 2023 10:42:30 +0100 Subject: buildman: type cotaining %s/cotaining/containing/ Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- tools/buildman/boards.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/buildman/boards.py b/tools/buildman/boards.py index 341a5056df..3c2822715f 100644 --- a/tools/buildman/boards.py +++ b/tools/buildman/boards.py @@ -119,7 +119,7 @@ class Expr: """Set up a new Expr object. Args: - expr (str): String cotaining regular expression to store + expr (str): String containing regular expression to store """ self._expr = expr self._re = re.compile(expr) -- cgit v1.2.3 From 69c3705be9fe80a084408c5f8db7bceec4c720dd Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 16 Dec 2023 00:26:04 +0100 Subject: binman: used-before-assignment in ftest.py Pytest 7.4.3 complains if a variable is used in a finally clause without having been initialized before the try clause. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- tools/binman/ftest.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index a273120d9f..a4ac520cbb 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2842,12 +2842,14 @@ class TestFunctional(unittest.TestCase): fdt_size = entries['section'].GetEntries()['u-boot-dtb'].size fdtmap_offset = entries['fdtmap'].offset + tmpdir = None try: tmpdir, updated_fname = self._SetupImageInTmpdir() with test_util.capture_sys_output() as (stdout, stderr): self._DoBinman('ls', '-i', updated_fname) finally: - shutil.rmtree(tmpdir) + if tmpdir: + shutil.rmtree(tmpdir) lines = stdout.getvalue().splitlines() expected = [ 'Name Image-pos Size Entry-type Offset Uncomp-size', @@ -2868,12 +2870,14 @@ class TestFunctional(unittest.TestCase): def testListCmdFail(self): """Test failing to list an image""" self._DoReadFile('005_simple.dts') + tmpdir = None try: tmpdir, updated_fname = self._SetupImageInTmpdir() with self.assertRaises(ValueError) as e: self._DoBinman('ls', '-i', updated_fname) finally: - shutil.rmtree(tmpdir) + if tmpdir: + shutil.rmtree(tmpdir) self.assertIn("Cannot find FDT map in image", str(e.exception)) def _RunListCmd(self, paths, expected): @@ -3002,13 +3006,15 @@ class TestFunctional(unittest.TestCase): self._CheckLz4() self._DoReadFileRealDtb('130_list_fdtmap.dts') fname = os.path.join(self._indir, 'output.extact') + tmpdir = None try: tmpdir, updated_fname = self._SetupImageInTmpdir() with test_util.capture_sys_output() as (stdout, stderr): self._DoBinman('extract', '-i', updated_fname, 'u-boot', '-f', fname) finally: - shutil.rmtree(tmpdir) + if tmpdir: + shutil.rmtree(tmpdir) data = tools.read_file(fname) self.assertEqual(U_BOOT_DATA, data) @@ -5185,12 +5191,14 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFileRealDtb('207_fip_ls.dts') hdr, fents = fip_util.decode_fip(data) + tmpdir = None try: tmpdir, updated_fname = self._SetupImageInTmpdir() with test_util.capture_sys_output() as (stdout, stderr): self._DoBinman('ls', '-i', updated_fname) finally: - shutil.rmtree(tmpdir) + if tmpdir: + shutil.rmtree(tmpdir) lines = stdout.getvalue().splitlines() expected = [ 'Name Image-pos Size Entry-type Offset Uncomp-size', @@ -5395,12 +5403,14 @@ fdt fdtmap Extract the devicetree blob from the fdtmap use_real_dtb=True, extra_indirs=[os.path.join(self._indir, TEST_FDT_SUBDIR)]) + tmpdir = None try: tmpdir, updated_fname = self._SetupImageInTmpdir() with test_util.capture_sys_output() as (stdout, stderr): self._RunBinman('ls', '-i', updated_fname) finally: - shutil.rmtree(tmpdir) + if tmpdir: + shutil.rmtree(tmpdir) def testFitSubentryUsesBintool(self): """Test that binman FIT subentries can use bintools""" -- cgit v1.2.3 From 233a61373bfc474bbf48e6e278f835818083ef84 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 17 Dec 2023 09:36:15 -0700 Subject: fdtgrep: Tidy up a few type warnings and comments Align the code with the upstream version at fdt-tools which had a few tweaks before being applied. Signed-off-by: Simon Glass --- tools/fdtgrep.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index 7eabcab439..f5493aaed3 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -375,8 +375,9 @@ static int display_fdt_by_regions(struct display_info *disp, const void *blob, const char *str; int str_base = fdt_off_dt_strings(blob); - for (offset = 0; offset < fdt_size_dt_strings(blob); - offset += strlen(str) + 1) { + for (offset = 0; + offset < (int)fdt_size_dt_strings(blob); + offset += strlen(str) + 1) { str = fdt_string(blob, offset); int len = strlen(str) + 1; int show; @@ -431,7 +432,7 @@ static int dump_fdt_regions(struct display_info *disp, const void *blob, { struct fdt_header *fdt; int size, struct_start; - int ptr; + unsigned int ptr; int i; /* Set up a basic header (even if we don't actually write it) */ @@ -683,10 +684,10 @@ static int fdtgrep_find_regions(const void *fdt, return new_count; } else if (new_count <= max_regions) { /* - * The alias regions will now be at the end of the list. - * Sort the regions by offset to get things into the - * right order - */ + * The alias regions will now be at the end of the list. + * Sort the regions by offset to get things into the + * right order + */ count = new_count; qsort(region, count, sizeof(struct fdt_region), h_cmp_region); @@ -880,7 +881,7 @@ static int do_fdtgrep(struct display_info *disp, const char *filename) size = fdt_totalsize(fdt); } - if (size != fwrite(fdt, 1, size, disp->fout)) { + if ((size_t)size != fwrite(fdt, 1, size, disp->fout)) { fprintf(stderr, "Write failure, %d bytes\n", size); free(fdt); ret = 1; @@ -934,7 +935,7 @@ static const char usage_synopsis[] = static const char usage_short_opts[] = "haAc:b:C:defg:G:HIlLmn:N:o:O:p:P:rRsStTv" USAGE_COMMON_SHORT_OPTS; -static struct option const usage_long_opts[] = { +static const struct option usage_long_opts[] = { {"show-address", no_argument, NULL, 'a'}, {"colour", no_argument, NULL, 'A'}, {"include-node-with-prop", a_argument, NULL, 'b'}, -- cgit v1.2.3 From 9dab5bd3f8c4b9f09e1bcb7aefc090210d1fd52e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 17 Dec 2023 09:36:16 -0700 Subject: fdtgrep: Correct ordering of flags Two of the flags are out of order, so fix this. Also adjust the ordering of one flag in the main switch() Signed-off-by: Simon Glass --- tools/fdtgrep.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index f5493aaed3..41d8b41252 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -953,6 +953,8 @@ static const struct option usage_long_opts[] = { {"include-mem", no_argument, NULL, 'm'}, {"include-node", a_argument, NULL, 'n'}, {"exclude-node", a_argument, NULL, 'N'}, + {"out", a_argument, NULL, 'o'}, + {"out-format", a_argument, NULL, 'O'}, {"include-prop", a_argument, NULL, 'p'}, {"exclude-prop", a_argument, NULL, 'P'}, {"remove-strings", no_argument, NULL, 'r'}, @@ -961,8 +963,6 @@ static const struct option usage_long_opts[] = { {"skip-supernodes", no_argument, NULL, 'S'}, {"show-stringtab", no_argument, NULL, 't'}, {"show-aliases", no_argument, NULL, 'T'}, - {"out", a_argument, NULL, 'o'}, - {"out-format", a_argument, NULL, 'O'}, {"invert-match", no_argument, NULL, 'v'}, USAGE_COMMON_LONG_OPTS, }; @@ -984,6 +984,8 @@ static const char * const usage_opts_help[] = { "Include mem_rsvmap section in binary output", "Node to include in grep", "Node to exclude in grep", + "-o ", + "-O ", "Property to include in grep", "Property to exclude in grep", "Remove unused strings from string table", @@ -992,8 +994,6 @@ static const char * const usage_opts_help[] = { "Don't include supernodes of matching nodes", "Include string table in binary output", "Include matching aliases in output", - "-o ", - "-O ", "Invert the sense of matching (select non-matching lines)", USAGE_COMMON_OPTS_HELP }; @@ -1125,6 +1125,9 @@ static void scan_args(struct display_info *disp, int argc, char *argv[]) case 'H': disp->header = 1; break; + case 'I': + disp->show_dts_version = 1; + break; case 'l': disp->region_list = 1; break; @@ -1180,9 +1183,6 @@ static void scan_args(struct display_info *disp, int argc, char *argv[]) case 'v': disp->invert = 1; break; - case 'I': - disp->show_dts_version = 1; - break; } if (type && value_add(disp, &disp->value_head, type, inc, -- cgit v1.2.3 From f3acd206859ed516f79ba83da587196f66fe57d2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 17 Dec 2023 09:36:17 -0700 Subject: fdtgrep: Correct references to fdt_find_regions() The function name is actually fdtgrep_find_regions() so update the name in comments accordinging. Signed-off-by: Simon Glass --- tools/fdtgrep.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index 41d8b41252..b56d2fe21c 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -576,10 +576,10 @@ static int check_type_include(void *priv, int type, const char *data, int size) } /** - * h_include() - Include handler function for fdt_find_regions() + * h_include() - Include handler function for fdtgrep_find_regions() * * This function decides whether to include or exclude a node, property or - * compatible string. The function is defined by fdt_find_regions(). + * compatible string. The function is defined by fdtgrep_find_regions(). * * The algorithm is documented in the code - disp->invert is 0 for normal * operation, and 1 to invert the sense of all matches. @@ -822,7 +822,7 @@ static int do_fdtgrep(struct display_info *disp, const char *filename) region, max_regions, path, sizeof(path), disp->flags); if (count < 0) { - report_error("fdt_find_regions", count); + report_error("fdtgrep_find_regions", count); free(region); return -1; } -- cgit v1.2.3 From b1823ed1715910b1af68815a27c33c2c992e685c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 17 Dec 2023 09:36:18 -0700 Subject: fdtgrep: Tidy up comment for h_include() Copy the comment from fdt_first_region() so that it is clear what value this function returns. Signed-off-by: Simon Glass --- tools/fdtgrep.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index b56d2fe21c..a6cdc32670 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -576,15 +576,21 @@ static int check_type_include(void *priv, int type, const char *data, int size) } /** - * h_include() - Include handler function for fdtgrep_find_regions() + * h_include() - Include handler function for fdt_first_region() * * This function decides whether to include or exclude a node, property or - * compatible string. The function is defined by fdtgrep_find_regions(). + * compatible string. The function is defined by fdt_first_region(). * * The algorithm is documented in the code - disp->invert is 0 for normal * operation, and 1 to invert the sense of all matches. * - * See + * @priv: Private pointer as passed to fdtgrep_find_regions() + * @fdt: Pointer to FDT blob + * @offset: Offset of this node / property + * @type: Type of this part, FDT_IS_... + * @data: Pointer to data (node name, property name, compatible string) + * @size: Size of data, or 0 if none + * Return: 0 to exclude, 1 to include, -1 if no information is available */ static int h_include(void *priv, const void *fdt, int offset, int type, const char *data, int size) -- cgit v1.2.3 From 490afe74287fef246320c6473f74b2fc2a62c745 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 17 Dec 2023 09:36:19 -0700 Subject: fdtgrep: Simplify code to inverting the match The code to invert the match in h_include() is a bit convoluted. Simplify it by using disp->invert only once. Signed-off-by: Simon Glass --- tools/fdtgrep.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index a6cdc32670..b06a1a7a83 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -634,14 +634,8 @@ static int h_include(void *priv, const void *fdt, int offset, int type, inc = 0; } - switch (inc) { - case 1: - inc = !disp->invert; - break; - case 0: - inc = disp->invert; - break; - } + if (inc != -1 && disp->invert) + inc = !inc; debug(" - returning %d\n", inc); return inc; -- cgit v1.2.3 From 61a695e451fb6abe65de193c70dd981af6fb7a51 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 17 Dec 2023 09:36:20 -0700 Subject: fdtgrep: Move property checking into a function The h_include() function includes a piece which checks if a node contains a property being searched for. Move this into its own function to reduce the size of the h_include() function. Signed-off-by: Simon Glass --- tools/fdtgrep.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index b06a1a7a83..ca639a2d9f 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -575,6 +575,40 @@ static int check_type_include(void *priv, int type, const char *data, int size) return 0; } +/** + * check_props() - Check if a node has properties that we want to include + * + * Calls check_type_include() for each property in the nodn, returning 1 if + * that function returns 1 for any of them + * + * @disp: Display structure, holding info about our options + * @fdt: Devicetree blob to check + * @node: Node offset to check + * @inc: Current value of the 'include' variable (see h_include()) + * Return: 0 to exclude, 1 to include, -1 if no information is available + */ +static int check_props(struct display_info *disp, const void *fdt, int node, + int inc) +{ + int offset; + + for (offset = fdt_first_property_offset(fdt, node); + offset > 0 && inc != 1; + offset = fdt_next_property_offset(fdt, offset)) { + const struct fdt_property *prop; + const char *str; + + prop = fdt_get_property_by_offset(fdt, offset, NULL); + if (!prop) + continue; + str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); + inc = check_type_include(disp, FDT_NODE_HAS_PROP, str, + strlen(str)); + } + + return inc; +} + /** * h_include() - Include handler function for fdt_first_region() * @@ -617,19 +651,7 @@ static int h_include(void *priv, const void *fdt, int offset, int type, (disp->types_inc & FDT_NODE_HAS_PROP)) { debug(" - checking node '%s'\n", fdt_get_name(fdt, offset, NULL)); - for (offset = fdt_first_property_offset(fdt, offset); - offset > 0 && inc != 1; - offset = fdt_next_property_offset(fdt, offset)) { - const struct fdt_property *prop; - const char *str; - - prop = fdt_get_property_by_offset(fdt, offset, NULL); - if (!prop) - continue; - str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); - inc = check_type_include(priv, FDT_NODE_HAS_PROP, str, - strlen(str)); - } + inc = check_props(disp, fdt, offset, inc); if (inc == -1) inc = 0; } -- cgit v1.2.3 From 7a06cc2027c0169c462da63a68fa269c0d59a950 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 17 Dec 2023 09:36:22 -0700 Subject: fdtgrep: Allow propagating properties up to supernodes The existing bootph binding is defined such that properties in a subnode are also implied in the supernode also, as in this example: buttons { /* bootph,pre-ram is implied by btn1 */ compatible = "gpio-keys"; btn1 { bootph,pre-ram; gpios = <&gpio_a 3 0>; label = "button1"; linux,code = ; }; Provide an option to implement this in fdtgrep. Signed-off-by: Simon Glass --- tools/fdtgrep.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index ca639a2d9f..f1ff1946bd 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -63,6 +63,7 @@ struct display_info { int types_inc; /* Mask of types that we include (FDT_IS...) */ int types_exc; /* Mask of types that we exclude (FDT_IS...) */ int invert; /* Invert polarity of match */ + int props_up; /* Imply properties up to supernodes */ struct value_node *value_head; /* List of values to match */ const char *output_fname; /* Output filename */ FILE *fout; /* File to write dts/dtb output */ @@ -606,6 +607,16 @@ static int check_props(struct display_info *disp, const void *fdt, int node, strlen(str)); } + /* if requested, check all subnodes for this property too */ + if (inc != 1 && disp->props_up) { + int subnode; + + for (subnode = fdt_first_subnode(fdt, node); + subnode > 0 && inc != 1; + subnode = fdt_next_subnode(fdt, subnode)) + inc = check_props(disp, fdt, subnode, inc); + } + return inc; } @@ -955,7 +966,7 @@ static const char usage_synopsis[] = case '?': usage("unknown option"); static const char usage_short_opts[] = - "haAc:b:C:defg:G:HIlLmn:N:o:O:p:P:rRsStTv" + "haAc:b:C:defg:G:HIlLmn:N:o:O:p:P:rRsStTuv" USAGE_COMMON_SHORT_OPTS; static const struct option usage_long_opts[] = { {"show-address", no_argument, NULL, 'a'}, @@ -985,6 +996,7 @@ static const struct option usage_long_opts[] = { {"skip-supernodes", no_argument, NULL, 'S'}, {"show-stringtab", no_argument, NULL, 't'}, {"show-aliases", no_argument, NULL, 'T'}, + {"props-up-to-supernode", no_argument, NULL, 'u'}, {"invert-match", no_argument, NULL, 'v'}, USAGE_COMMON_LONG_OPTS, }; @@ -1016,6 +1028,7 @@ static const char * const usage_opts_help[] = { "Don't include supernodes of matching nodes", "Include string table in binary output", "Include matching aliases in output", + "Add -p properties to supernodes too", "Invert the sense of matching (select non-matching lines)", USAGE_COMMON_OPTS_HELP }; @@ -1202,6 +1215,9 @@ static void scan_args(struct display_info *disp, int argc, char *argv[]) case 'T': disp->add_aliases = 1; break; + case 'u': + disp->props_up = 1; + break; case 'v': disp->invert = 1; break; -- cgit v1.2.3