From 9404fc85ab2e60fb81c8faaa58349ee1187a2501 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 6 Mar 2016 19:45:32 -0700 Subject: fdtgrep: Improve error handling with invalid device tree This tool requires that the aliases node be the first node in the tree. But when it is not, it does not handle things gracefully. In fact it crashes. Fix this, and add a more helpful error message. Signed-off-by: Simon Glass Reported-by: Masahiro Yamada --- tools/fdtgrep.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index 67aa41a..8d3fef4 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -660,6 +660,8 @@ static int fdtgrep_find_regions(const void *fdt, if (!ret) count++; } + if (ret && ret != -FDT_ERR_NOTFOUND) + return ret; /* Find all the aliases and add those regions back in */ if (disp->add_aliases && count < max_regions) { @@ -667,7 +669,11 @@ static int fdtgrep_find_regions(const void *fdt, new_count = fdt_add_alias_regions(fdt, region, count, max_regions, &state); - if (new_count <= max_regions) { + if (new_count == -FDT_ERR_NOTFOUND) { + /* No alias node found */ + } else if (new_count < 0) { + 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 @@ -679,9 +685,6 @@ static int fdtgrep_find_regions(const void *fdt, } } - if (ret != -FDT_ERR_NOTFOUND) - return ret; - return count; } @@ -807,6 +810,9 @@ 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.1 From 9ad96982e8c8c89cf75d4ebfc3e7e8afd3fe3364 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 6 Mar 2016 19:45:33 -0700 Subject: patman: Add a missing space in GetMetaDataForList() Fix this nit to keep the code consistent. Signed-off-by: Simon Glass Reviewed-by: Joe Hershberger --- tools/patman/patchstream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py index 6d3c41f..27d031e 100644 --- a/tools/patman/patchstream.py +++ b/tools/patman/patchstream.py @@ -376,7 +376,7 @@ def GetMetaDataForList(commit_range, git_dir=None, count=None, if not series: series = Series() series.allow_overwrite = allow_overwrite - params = gitutil.LogCmd(commit_range,reverse=True, count=count, + params = gitutil.LogCmd(commit_range, reverse=True, count=count, git_dir=git_dir) stdout = command.RunPipe([params], capture=True).stdout ps = PatchStream(series, is_log=True) -- cgit v1.1 From 2bdeade0eac66e7b12db847ffbbcbe2e63a17fd4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 6 Mar 2016 19:45:34 -0700 Subject: buildman: patman: Fix -H when installed as a symlink It is convenient to install symlinks to buildman and patman in the search patch, such as /usr/local/bin. But when this is done, the -H option fails to work because it looks in the directory containing the symlink instead of its target. Fix this. Signed-off-by: Simon Glass Reviewed-by: Joe Hershberger --- tools/buildman/control.py | 3 ++- tools/patman/patman.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/buildman/control.py b/tools/buildman/control.py index 8b3cd30..c2c54bf 100644 --- a/tools/buildman/control.py +++ b/tools/buildman/control.py @@ -101,7 +101,8 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None, pager = os.getenv('PAGER') if not pager: pager = 'more' - fname = os.path.join(os.path.dirname(sys.argv[0]), 'README') + fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), + 'README') command.Run(pager, fname) return 0 diff --git a/tools/patman/patman.py b/tools/patman/patman.py index d05c5ff..fe50eb4 100755 --- a/tools/patman/patman.py +++ b/tools/patman/patman.py @@ -117,7 +117,8 @@ elif options.full_help: pager = os.getenv('PAGER') if not pager: pager = 'more' - fname = os.path.join(os.path.dirname(sys.argv[0]), 'README') + fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), + 'README') command.Run(pager, fname) # Process commits, produce patches files, check them, email them -- cgit v1.1 From ad24ebace118f4145b1a3f782ddf9b9ce5f8dcf3 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 6 Mar 2016 19:45:35 -0700 Subject: buildman: Fix up a few code inconsistencies in toolchain.py Normally we use a single quote for strings unless there is a reason not to (such as an embedded single quote). Fix a few counter-examples in this file. Also add a missing function-argument comment. Signed-off-by: Simon Glass Reviewed-by: Joe Hershberger --- tools/buildman/toolchain.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py index e33e105..5e77fed 100644 --- a/tools/buildman/toolchain.py +++ b/tools/buildman/toolchain.py @@ -57,6 +57,7 @@ class Toolchain: Args: fname: Filename of the gcc component test: True to run the toolchain to test it + verbose: True to print out the information """ self.gcc = fname self.path = os.path.dirname(fname) @@ -155,8 +156,8 @@ class Toolchains: """ toolchains = bsettings.GetItems('toolchain') if not toolchains: - print ("Warning: No tool chains - please add a [toolchain] section" - " to your buildman config file %s. See README for details" % + print ('Warning: No tool chains - please add a [toolchain] section' + ' to your buildman config file %s. See README for details' % bsettings.config_fname) paths = [] @@ -367,14 +368,14 @@ class Toolchains: Full path to the downloaded archive file in that directory, or None if there was an error while downloading """ - print "Downloading: %s" % url + print 'Downloading: %s' % url leaf = url.split('/')[-1] tmpdir = tempfile.mkdtemp('.buildman') response = urllib2.urlopen(url) fname = os.path.join(tmpdir, leaf) fd = open(fname, 'wb') meta = response.info() - size = int(meta.getheaders("Content-Length")[0]) + size = int(meta.getheaders('Content-Length')[0]) done = 0 block_size = 1 << 16 status = '' @@ -388,7 +389,7 @@ class Toolchains: done += len(buffer) fd.write(buffer) - status = r"%10d MiB [%3d%%]" % (done / 1024 / 1024, + status = r'%10d MiB [%3d%%]' % (done / 1024 / 1024, done * 100 / size) status = status + chr(8) * (len(status) + 1) print status, -- cgit v1.1 From ff690df9fce2db07391a53f6cf4c5858b9ea6fad Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 6 Mar 2016 19:45:37 -0700 Subject: buildman: Allow the toolchain priority to be specified At present the priority of a toolchain is calculated from its filename based on hard-coded rules. Allow it to be specified by the caller. We will use this in a later patch. Also display the priority and provide a message when it is overriden by another toolchain of higher priority. Signed-off-by: Simon Glass Reviewed-by: Joe Hershberger --- tools/buildman/toolchain.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py index 5e77fed..1874d73 100644 --- a/tools/buildman/toolchain.py +++ b/tools/buildman/toolchain.py @@ -14,6 +14,8 @@ import urllib2 import bsettings import command +PRIORITY_CALC = 0 + # Simple class to collect links from a page class MyHTMLParser(HTMLParser): def __init__(self, arch): @@ -50,14 +52,17 @@ class Toolchain: cross: Cross compile string, e.g. 'arm-linux-' arch: Architecture of toolchain as determined from the first component of the filename. E.g. arm-linux-gcc becomes arm + priority: Toolchain priority (0=highest, 20=lowest) """ - def __init__(self, fname, test, verbose=False): + def __init__(self, fname, test, verbose=False, priority=PRIORITY_CALC): """Create a new toolchain object. Args: fname: Filename of the gcc component test: True to run the toolchain to test it verbose: True to print out the information + priority: Priority to use for this toolchain, or PRIORITY_CALC to + calculate it """ self.gcc = fname self.path = os.path.dirname(fname) @@ -76,6 +81,10 @@ class Toolchain: # As a basic sanity check, run the C compiler with --version cmd = [fname, '--version'] + if priority == PRIORITY_CALC: + self.priority = self.GetPriority(fname) + else: + self.priority = priority if test: result = command.RunPipe([cmd], capture=True, env=env, raise_on_error=False) @@ -83,7 +92,7 @@ class Toolchain: if verbose: print 'Tool chain test: ', if self.ok: - print 'OK' + print 'OK, priority %d' % self.priority else: print 'BAD' print 'Command: ', cmd @@ -91,7 +100,6 @@ class Toolchain: print result.stderr else: self.ok = True - self.priority = self.GetPriority(fname) def GetPriority(self, fname): """Return the priority of the toolchain. @@ -102,15 +110,15 @@ class Toolchain: Args: fname: Filename of toolchain Returns: - Priority of toolchain, 0=highest, 20=lowest. + Priority of toolchain, PRIORITY_CALC=highest, 20=lowest. """ priority_list = ['-elf', '-unknown-linux-gnu', '-linux', '-none-linux-gnueabi', '-uclinux', '-none-eabi', '-gentoo-linux-gnu', '-linux-gnueabi', '-le-linux', '-uclinux'] for prio in range(len(priority_list)): if priority_list[prio] in fname: - return prio - return prio + return PRIORITY_CALC + prio + return PRIORITY_CALC + prio def MakeEnvironment(self, full_path): """Returns an environment for using the toolchain. @@ -171,7 +179,7 @@ class Toolchains: def GetSettings(self): self.paths += self.GetPathList() - def Add(self, fname, test=True, verbose=False): + def Add(self, fname, test=True, verbose=False, priority=PRIORITY_CALC): """Add a toolchain to our list We select the given toolchain as our preferred one for its @@ -180,14 +188,20 @@ class Toolchains: Args: fname: Filename of toolchain's gcc driver test: True to run the toolchain to test it + priority: Priority to use for this toolchain """ - toolchain = Toolchain(fname, test, verbose) + toolchain = Toolchain(fname, test, verbose, priority) add_it = toolchain.ok if toolchain.arch in self.toolchains: add_it = (toolchain.priority < self.toolchains[toolchain.arch].priority) if add_it: self.toolchains[toolchain.arch] = toolchain + elif verbose: + print ("Toolchain '%s' at priority %d will be ignored because " + "another toolchain for arch '%s' has priority %d" % + (toolchain.gcc, toolchain.priority, toolchain.arch, + self.toolchains[toolchain.arch].priority)) def ScanPath(self, path, verbose): """Scan a path for a valid toolchain -- cgit v1.1 From 608e399fdef82e983db44c5cb8f5e772bba870e2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 6 Mar 2016 19:45:38 -0700 Subject: buildman: Allow the toolchain architecture to be specified At present the architecture is deduced from the toolchain filename. Allow it to be specified by the caller. Signed-off-by: Simon Glass Reviewed-by: Joe Hershberger