From b77646a8d2bf2108cff020e5de50b43ca7d7d9a1 Mon Sep 17 00:00:00 2001 From: anilsoni85 Date: Sun, 31 Oct 2021 13:18:29 -0400 Subject: [PATCH 1/3] Fix for Issue #7253 On windows 10 xltensa-lx106-elf-objdump sporadically returns no output and results into build errors. Adding logic to retry to read segment from elf. --- tools/elf2bin.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/elf2bin.py b/tools/elf2bin.py index 035f7a93ae..386fdffaba 100755 --- a/tools/elf2bin.py +++ b/tools/elf2bin.py @@ -44,15 +44,20 @@ def get_elf_entry(elf, path): raise Exception('Unable to find entry point in file "' + elf + '"') def get_segment_size_addr(elf, segment, path): - p = subprocess.Popen([path + '/xtensa-lx106-elf-objdump', '-h', '-j', segment, elf], stdout=subprocess.PIPE, universal_newlines=True ) - lines = p.stdout.readlines() - for line in lines: - if segment in line: - words = re.split('\s+', line) - size = int(words[3], 16) - addr = int(words[4], 16) - return [ size, addr ] - raise Exception('Unable to find size and start point in file "' + elf + '" for "' + segment + '"') + attempts = 0 + maxAttempts = 5 + while (attempts < maxAttempts): + attempts = attempts + 1 + with subprocess.Popen([path + '/xtensa-lx106-elf-objdump', '-h', '-j', segment, elf], stdout=subprocess.PIPE, universal_newlines=True ) as p: + lines = p.stdout.readlines() + if (len(lines) > 0): + for line in lines: + if segment in line: + words = re.split('\s+', line) + size = int(words[3], 16) + addr = int(words[4], 16) + return [ size, addr ] + raise Exception('Unable to find size and start point in file "' + elf + '" for "' + segment + '" path "' + path + '"') def read_segment(elf, segment, path): fd, tmpfile = tempfile.mkstemp() From 1e6ac60fb3ea531076babc6056dc026f78a45070 Mon Sep 17 00:00:00 2001 From: anilsoni85 Date: Sun, 31 Oct 2021 14:23:55 -0400 Subject: [PATCH 2/3] raise exception at right level --- tools/elf2bin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/elf2bin.py b/tools/elf2bin.py index 386fdffaba..da64c914b6 100755 --- a/tools/elf2bin.py +++ b/tools/elf2bin.py @@ -57,7 +57,7 @@ def get_segment_size_addr(elf, segment, path): size = int(words[3], 16) addr = int(words[4], 16) return [ size, addr ] - raise Exception('Unable to find size and start point in file "' + elf + '" for "' + segment + '" path "' + path + '"') + raise Exception('Unable to find size and start point in file "' + elf + '" for "' + segment + '" path "' + path + '"') def read_segment(elf, segment, path): fd, tmpfile = tempfile.mkstemp() From ee808c22a97685c77e8fe687f349ba4366523fb6 Mon Sep 17 00:00:00 2001 From: anilsoni85 Date: Mon, 8 Nov 2021 19:13:54 -0500 Subject: [PATCH 3/3] Read STDERR when segment read fails Print STDERR and STDOUT on console when segment read fails. --- tools/elf2bin.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/elf2bin.py b/tools/elf2bin.py index da64c914b6..3052be499f 100755 --- a/tools/elf2bin.py +++ b/tools/elf2bin.py @@ -48,15 +48,18 @@ def get_segment_size_addr(elf, segment, path): maxAttempts = 5 while (attempts < maxAttempts): attempts = attempts + 1 - with subprocess.Popen([path + '/xtensa-lx106-elf-objdump', '-h', '-j', segment, elf], stdout=subprocess.PIPE, universal_newlines=True ) as p: + with subprocess.Popen([path + '/xtensa-lx106-elf-objdump', '-h', '-j', segment, elf], stdout=subprocess.PIPE, stderr = subprocess.PIPE, universal_newlines=True ) as p: lines = p.stdout.readlines() - if (len(lines) > 0): - for line in lines: - if segment in line: - words = re.split('\s+', line) - size = int(words[3], 16) - addr = int(words[4], 16) - return [ size, addr ] + if (len(lines) == 0): + errLines = p.stderr.readlines() + print("\t!!!Segment: {}. Attempt: {}/{} STDERR: {} STDOUT: {}".format(segment, attempts, maxAttempts, errLines, lines)) + continue + for line in lines: + if segment in line: + words = re.split('\s+', line) + size = int(words[3], 16) + addr = int(words[4], 16) + return [ size, addr ] raise Exception('Unable to find size and start point in file "' + elf + '" for "' + segment + '" path "' + path + '"') def read_segment(elf, segment, path):