diff --git a/tools/toolchains/arm.py b/tools/toolchains/arm.py index 2df0bfac10d..be43f407603 100644 --- a/tools/toolchains/arm.py +++ b/tools/toolchains/arm.py @@ -16,9 +16,10 @@ """ 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 @@ def binary(self, resources, elf, bin): 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)