From 6db06f94e19d539bb7001a666e7c52672e0682ea Mon Sep 17 00:00:00 2001 From: George McCollister Date: Thu, 30 Mar 2017 09:44:24 -0500 Subject: patman: Convert byte arrays to strings os.read() returns a byte array in Python 3.5.2 and needs to be converted into a string. Check if the returned value is an instance of bytes and if it is decode it as a utf-8 string. If it is not a utf-8 encoded string the decoding may fail with an exception. Prior to this fix the comparisions check data == "" would fail when data was b'' and would cause an infinite memory leaking loop. joins would also fail with an exception below but due to the infinite loop it never made it that far. Signed-off-by: George McCollister Acked-by: Simon Glass --- tools/patman/cros_subprocess.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools') diff --git a/tools/patman/cros_subprocess.py b/tools/patman/cros_subprocess.py index ebd4300dfd5..7c760143407 100644 --- a/tools/patman/cros_subprocess.py +++ b/tools/patman/cros_subprocess.py @@ -190,6 +190,8 @@ class Popen(subprocess.Popen): # We will get an error on read if the pty is closed try: data = os.read(self.stdout.fileno(), 1024) + if isinstance(data, bytes): + data = data.decode('utf-8') except OSError: pass if data == "": @@ -205,6 +207,8 @@ class Popen(subprocess.Popen): # We will get an error on read if the pty is closed try: data = os.read(self.stderr.fileno(), 1024) + if isinstance(data, bytes): + data = data.decode('utf-8') except OSError: pass if data == "": -- cgit v1.3.1 From f156b5b59750f4140ffa2dd6a5eab686ba0212c3 Mon Sep 17 00:00:00 2001 From: George McCollister Date: Thu, 30 Mar 2017 09:44:25 -0500 Subject: dtoc: Decode val if it's a byte string With Python 3.5.2 encode will throw an exception if val is a byte array. Decode it to a string first. This assumes it's utf-8, if it's not valid utf-8 it will throw an exception. Signed-off-by: George McCollister Acked-by: Simon Glass --- tools/dtoc/fdt_util.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools') diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py index e6d523b9de6..b9dfae8d0e7 100644 --- a/tools/dtoc/fdt_util.py +++ b/tools/dtoc/fdt_util.py @@ -24,6 +24,8 @@ def fdt32_to_cpu(val): A native-endian integer value """ if sys.version_info > (3, 0): + if isinstance(val, bytes): + val = val.decode('utf-8') val = val.encode('raw_unicode_escape') return struct.unpack('>I', val)[0] -- cgit v1.3.1 From c47a38b47770887dc9416382207364fb62899fc2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 2 Apr 2017 12:26:44 -0600 Subject: fdtgrep: Cope with the /aliases node being last With skeleton.dtsi being dropped it is more likely that the /aliases node will be last in the device tree. Update fdtgrep to handle this. Signed-off-by: Simon Glass Tested-by: Masahiro Yamada --- lib/libfdt/fdt_region.c | 40 +++++++++++++++++++++++++++++++++++----- tools/fdtgrep.c | 3 --- 2 files changed, 35 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/lib/libfdt/fdt_region.c b/lib/libfdt/fdt_region.c index d2ce4c1c537..8b8a5475554 100644 --- a/lib/libfdt/fdt_region.c +++ b/lib/libfdt/fdt_region.c @@ -63,6 +63,30 @@ static int region_list_contains_offset(struct fdt_region_state *info, return 0; } +/** + * fdt_add_alias_regions() - Add regions covering the aliases that we want + * + * The /aliases node is not automatically included by fdtgrep unless the + * command-line arguments cause to be included (or not excluded). However + * aliases are special in that we generally want to include those which + * reference a node that fdtgrep includes. + * + * In fact we want to include only aliases for those nodes still included in + * the fdt, and drop the other aliases since they point to nodes that will not + * be present. + * + * This function scans the aliases and adds regions for those which we want + * to keep. + * + * @fdt: Device tree to scan + * @region: List of regions + * @count: Number of regions in the list so far (i.e. starting point for this + * function) + * @max_regions: Maximum number of regions in @region list + * @info: Place to put the region state + * @return number of regions after processing, or -FDT_ERR_NOSPACE if we did + * not have enough room in the regions table for the regions we wanted to add. + */ int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count, int max_regions, struct fdt_region_state *info) { @@ -74,11 +98,17 @@ int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count, if (node < 0) return -FDT_ERR_NOTFOUND; - /* The aliases node must come before the others */ + /* + * Find the next node so that we know where the /aliases node ends. We + * need special handling if /aliases is the last node. + */ node_end = fdt_next_subnode(fdt, node); - if (node_end <= 0) - return -FDT_ERR_BADLAYOUT; - node_end -= sizeof(fdt32_t); + if (node_end == -FDT_ERR_NOTFOUND) + /* Move back to the FDT_END_NODE tag of '/' */ + node_end = fdt_size_dt_struct(fdt) - sizeof(fdt32_t) * 2; + else if (node_end < 0) /* other error */ + return node_end; + node_end -= sizeof(fdt32_t); /* Move to FDT_END_NODE tag of /aliases */ did_alias_header = 0; info->region = region; @@ -109,7 +139,7 @@ int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count, fdt_add_region(info, base + offset, next - offset); } - /* Add the 'end' tag */ + /* Add the FDT_END_NODE tag */ if (did_alias_header) fdt_add_region(info, base + node_end, sizeof(fdt32_t)); diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index b9078273c95..e373c43e369 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -810,9 +810,6 @@ static int do_fdtgrep(struct display_info *disp, const char *filename) disp->flags); if (count < 0) { report_error("fdt_find_regions", count); - if (count == -FDT_ERR_BADLAYOUT) - fprintf(stderr, - "/aliases node must come before all other nodes\n"); return -1; } if (count <= max_regions) -- cgit v1.3.1 From b48bfc74ee410b1e6681c620633ffef32aafaba0 Mon Sep 17 00:00:00 2001 From: Stefano Babic Date: Wed, 5 Apr 2017 17:46:41 +0200 Subject: tools: allow to override python Not force to use python from PATH. Issue was noted when building with Yocto, because python from the distro is always taken instead of python-native built during Yocto process. Signed-off-by: Stefano Babic CC: Simon Glass Reviewed-by: Simon Glass --- Makefile | 2 +- tools/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/Makefile b/Makefile index 09b597d4505..8d4e6050b37 100644 --- a/Makefile +++ b/Makefile @@ -348,7 +348,7 @@ OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump AWK = awk PERL = perl -PYTHON = python +PYTHON ?= python DTC = dtc CHECK = sparse diff --git a/tools/Makefile b/tools/Makefile index fa1b85bdae2..2fc4a583d44 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -120,7 +120,7 @@ _libfdt.so-sharedobjs += $(LIBFDT_OBJS) libfdt: tools/_libfdt.so: $(patsubst %.o,%.c,$(LIBFDT_OBJS)) tools/libfdt_wrap.c - LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= python $(srctree)/lib/libfdt/setup.py \ + LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= ${PYTHON} $(srctree)/lib/libfdt/setup.py \ "$(_hostc_flags)" $^ mv _libfdt.so $@ -- cgit v1.3.1 From 9a6d2e2a6b0561732e52bd98e71432a7f4e9b3e2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 12 Apr 2017 18:23:26 -0600 Subject: buildman: Handle commit subjects containing unicode One of these has crept in in this commit: 40a808f1 ARCv2: SLC: Make sure busy bit is set properly on SLC flushing Adjust buildman to handle it. Signed-off-by: Simon Glass --- tools/buildman/builder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py index 236e0617ac4..b0ea57ebb4a 100644 --- a/tools/buildman/builder.py +++ b/tools/buildman/builder.py @@ -95,8 +95,9 @@ u-boot/ source directory # Possible build outcomes OUTCOME_OK, OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN = range(4) -# Translate a commit subject into a valid filename -trans_valid_chars = string.maketrans("/: ", "---") +# Translate a commit subject into a valid filename (and handle unicode) +trans_valid_chars = string.maketrans('/: ', '---') +trans_valid_chars = trans_valid_chars.decode('latin-1') BASE_CONFIG_FILENAMES = [ 'u-boot.cfg', 'u-boot-spl.cfg', 'u-boot-tpl.cfg' -- cgit v1.3.1