From cca1d5581a3008a1c492c70178a6bfa0c01d1ddb Mon Sep 17 00:00:00 2001 From: Tony Wu Date: Tue, 13 Mar 2018 18:32:24 +0800 Subject: [PATCH] armcc - remove fromelf output before regenerating Fix armcc recompile errors during elf2bin stage. Errors shown as follows: Elf2Bin: mbed-os-example-wifi Error: Q0147E: Failed to create Directory .\BUILD\REALTEK_RTL8195AM\ARM\mbed-os-example-wifi.bin\IMAGE2_TABLE: File exists Finished: 0 information, 0 warning and 1 error messages. [ERROR] Error: Q0147E: Failed to create Directory .\BUILD\REALTEK_RTL8195AM\ARM\mbed-os-example-wifi.bin\IMAGE2_TABLE: File exists Finished: 0 information, 0 warning and 1 error messages. Signed-off-by: Tony Wu --- tools/toolchains/arm.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/toolchains/arm.py b/tools/toolchains/arm.py index 2df0bfac10..be43f40760 100644 --- a/tools/toolchains/arm.py +++ b/tools/toolchains/arm.py @@ -16,9 +16,10 @@ limitations under the License. """ import re from copy import copy -from os.path import join, dirname, splitext, basename, exists, relpath -from os import makedirs, write, curdir +from os.path import join, dirname, splitext, basename, exists, relpath, isfile +from os import makedirs, write, curdir, remove from tempfile import mkstemp +from shutil import rmtree from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS from tools.hooks import hook_tool @@ -251,6 +252,14 @@ class ARM(mbedToolchain): bin_arg = {".bin": "--bin", ".hex": "--i32"}[fmt] cmd = [self.elf2bin, bin_arg, '-o', bin, elf] cmd = self.hook.get_cmdline_binary(cmd) + + # remove target binary file/path + if exists(bin): + if isfile(bin): + remove(bin) + else: + rmtree(bin) + self.cc_verbose("FromELF: %s" % ' '.join(cmd)) self.default_cmd(cmd)