mirror of https://github.com/ARMmbed/mbed-os.git
[nRF51822] Change image generation mechanism
- The final image is now generated at "binary" step, which is compatible with the on-line build system structure - The SoftDevice image is appended to the application code, resulting in a single .hex image file - Python is used for merging and generating .hex files using the 'intelhex' module, no more dependencies on external toolspull/159/head
parent
fdb41b0ccb
commit
3f5c551d0a
|
@ -175,7 +175,7 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=F
|
|||
# Target specific sources
|
||||
HAL_SRC = join(MBED_TARGETS_PATH, "hal")
|
||||
hal_implementation = toolchain.scan_resources(HAL_SRC)
|
||||
toolchain.copy_files(hal_implementation.headers, BUILD_TARGET)
|
||||
toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files, BUILD_TARGET)
|
||||
objects = toolchain.compile_sources(hal_implementation, TMP_PATH, [MBED_LIBRARIES, BUILD_TARGET])
|
||||
|
||||
# Common Sources
|
||||
|
|
|
@ -75,7 +75,8 @@ if __name__ == '__main__':
|
|||
default=None, help="The mbed serial port")
|
||||
parser.add_option("-b", "--baud", type="int", dest="baud",
|
||||
default=None, help="The mbed serial baud rate")
|
||||
parser.add_option("--nrfjprog",dest="nrfjprog",default=None,help="Program nRF Chip via J-Link")
|
||||
parser.add_option("--nrfjprog", dest="nrfjprog", action="store_true",
|
||||
default=None, help="Program nRF Chip via J-Link")
|
||||
|
||||
# Ideally, all the tests with a single "main" thread can be run with, or
|
||||
# without the rtos
|
||||
|
@ -168,8 +169,7 @@ if __name__ == '__main__':
|
|||
copy(bin, options.disk)
|
||||
if options.nrfjprog:
|
||||
#Convert bin to Hex and Program nrf chip via jlink
|
||||
call(["c:\\msdos\\msdos.exe","c:\\BIN2HEX.EXE",bin])
|
||||
call(["nrfjprog","-e","--program",bin.replace(".bin",".hex"),"--verify","-p"])
|
||||
call(["nrfjprog","-e","--program",bin.replace(".bin", ".hex"),"--verify","-p"])
|
||||
if options.serial:
|
||||
# Import pyserial: https://pypi.python.org/pypi/pyserial
|
||||
from serial import Serial
|
||||
|
|
|
@ -176,7 +176,7 @@ class LPC4088(Target):
|
|||
hook.hook_add_binary("post", self.binary_hook)
|
||||
|
||||
@staticmethod
|
||||
def binary_hook(t_self, elf, binf):
|
||||
def binary_hook(t_self, resources, elf, binf):
|
||||
if not os.path.isdir(binf):
|
||||
# Regular binary file, nothing to do
|
||||
return
|
||||
|
@ -304,6 +304,9 @@ class LPC11U35_401(Target):
|
|||
|
||||
|
||||
class nRF51822(Target):
|
||||
|
||||
EXPECTED_SOFTDEVICE = 's110_nrf51822_6.0.0_softdevice.hex'
|
||||
|
||||
def __init__(self):
|
||||
Target.__init__(self)
|
||||
|
||||
|
@ -313,6 +316,26 @@ class nRF51822(Target):
|
|||
|
||||
self.supported_toolchains = ["ARM"]
|
||||
|
||||
def init_hooks(self, hook, toolchain_name):
|
||||
if toolchain_name in ['ARM_STD', 'ARM_MICRO']:
|
||||
hook.hook_add_binary("post", self.binary_hook)
|
||||
|
||||
@staticmethod
|
||||
def binary_hook(t_self, resources, elf, binf):
|
||||
for hexf in resources.hex_files:
|
||||
if hexf.find(nRF51822.EXPECTED_SOFTDEVICE) != -1:
|
||||
break
|
||||
else:
|
||||
return
|
||||
from intelhex import IntelHex
|
||||
binh = IntelHex()
|
||||
binh.loadbin(binf, offset = 0x14000)
|
||||
sdh = IntelHex(hexf)
|
||||
sdh.merge(binh)
|
||||
outname = binf.replace(".bin", ".hex")
|
||||
with open(outname, "w") as f:
|
||||
sdh.tofile(f, format = 'hex')
|
||||
t_self.debug("Generated SoftDevice-enabled image in '%s'" % outname)
|
||||
|
||||
# Get a single instance for each target
|
||||
TARGETS = [
|
||||
|
|
|
@ -65,6 +65,9 @@ class Resources:
|
|||
self.repo_files = []
|
||||
|
||||
self.linker_script = None
|
||||
|
||||
# Other files
|
||||
self.hex_files = []
|
||||
|
||||
def add(self, resources):
|
||||
self.inc_dirs += resources.inc_dirs
|
||||
|
@ -86,11 +89,13 @@ class Resources:
|
|||
|
||||
if resources.linker_script is not None:
|
||||
self.linker_script = resources.linker_script
|
||||
|
||||
|
||||
self.hex_files += resources.hex_files
|
||||
|
||||
def relative_to(self, base, dot=False):
|
||||
for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
|
||||
'cpp_sources', 'lib_dirs', 'objects', 'libraries',
|
||||
'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files']:
|
||||
'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files', 'hex_files']:
|
||||
v = [rel_path(f, base, dot) for f in getattr(self, field)]
|
||||
setattr(self, field, v)
|
||||
if self.linker_script is not None:
|
||||
|
@ -99,7 +104,7 @@ class Resources:
|
|||
def win_to_unix(self):
|
||||
for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
|
||||
'cpp_sources', 'lib_dirs', 'objects', 'libraries',
|
||||
'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files']:
|
||||
'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files', 'hex_files']:
|
||||
v = [f.replace('\\', '/') for f in getattr(self, field)]
|
||||
setattr(self, field, v)
|
||||
if self.linker_script is not None:
|
||||
|
@ -118,7 +123,9 @@ class Resources:
|
|||
|
||||
('Library directories', self.lib_dirs),
|
||||
('Objects', self.objects),
|
||||
('Libraries', self.libraries)
|
||||
('Libraries', self.libraries),
|
||||
|
||||
('Hex files', self.hex_files),
|
||||
):
|
||||
if resources:
|
||||
s.append('%s:\n ' % label + '\n '.join(resources))
|
||||
|
@ -296,14 +303,19 @@ class mbedToolchain:
|
|||
|
||||
elif ext == self.LINKER_EXT:
|
||||
resources.linker_script = file_path
|
||||
|
||||
|
||||
elif ext == '.lib':
|
||||
resources.lib_refs.append(file_path)
|
||||
|
||||
elif ext == '.bld':
|
||||
resources.lib_builds.append(file_path)
|
||||
|
||||
elif file == '.hgignore':
|
||||
resources.repo_files.append(file_path)
|
||||
|
||||
|
||||
elif ext == '.hex':
|
||||
resources.hex_files.append(file_path)
|
||||
|
||||
return resources
|
||||
|
||||
def scan_repository(self, path):
|
||||
|
@ -432,7 +444,7 @@ class mbedToolchain:
|
|||
|
||||
if self.need_update(bin, [elf]):
|
||||
self.progress("elf2bin", name)
|
||||
self.binary(elf, bin)
|
||||
self.binary(r, elf, bin)
|
||||
|
||||
if self.target.name.startswith('LPC'):
|
||||
self.debug("LPC Patch %s" % (name + '.bin'))
|
||||
|
|
|
@ -121,7 +121,7 @@ class ARM(mbedToolchain):
|
|||
self.default_cmd(self.ld + args + objects + libraries + self.sys_libs)
|
||||
|
||||
@hook_tool
|
||||
def binary(self, elf, bin):
|
||||
def binary(self, resources, elf, bin):
|
||||
self.default_cmd([self.elf2bin, '--bin', '-o', bin, elf])
|
||||
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ class GCC(mbedToolchain):
|
|||
self.default_cmd(self.ld + ["-T%s" % mem_map, "-o", output] +
|
||||
objects + ["-L%s" % L for L in lib_dirs] + libs)
|
||||
|
||||
def binary(self, elf, bin):
|
||||
def binary(self, resources, elf, bin):
|
||||
self.default_cmd([self.elf2bin, "-O", "binary", elf, bin])
|
||||
|
||||
|
||||
|
|
|
@ -102,5 +102,5 @@ class IAR(mbedToolchain):
|
|||
args = [self.ld, "-o", output, "--config", mem_map]
|
||||
self.default_cmd(args + objects + libraries)
|
||||
|
||||
def binary(self, elf, bin):
|
||||
def binary(self, resources, elf, bin):
|
||||
self.default_cmd([self.elf2bin, '--bin', elf, bin])
|
||||
|
|
Loading…
Reference in New Issue