mirror of https://github.com/ARMmbed/mbed-os.git
parent
a3a52123e4
commit
5038233192
|
@ -116,8 +116,6 @@ def build_library(src_paths, build_path, target, toolchain_name,
|
||||||
toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
|
toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
|
||||||
dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)
|
dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)
|
||||||
|
|
||||||
toolchain.resources = resources
|
|
||||||
|
|
||||||
# Compile Sources
|
# Compile Sources
|
||||||
objects = []
|
objects = []
|
||||||
for resource in resources:
|
for resource in resources:
|
||||||
|
|
|
@ -176,7 +176,7 @@ class LPC4088(Target):
|
||||||
hook.hook_add_binary("post", self.binary_hook)
|
hook.hook_add_binary("post", self.binary_hook)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def binary_hook(t_self, elf, binf):
|
def binary_hook(t_self, resources, elf, binf):
|
||||||
if not os.path.isdir(binf):
|
if not os.path.isdir(binf):
|
||||||
# Regular binary file, nothing to do
|
# Regular binary file, nothing to do
|
||||||
return
|
return
|
||||||
|
@ -318,64 +318,50 @@ class NRF51822(Target):
|
||||||
|
|
||||||
self.supported_toolchains = ["ARM"]
|
self.supported_toolchains = ["ARM"]
|
||||||
|
|
||||||
self.binary_format = "hex"
|
|
||||||
|
|
||||||
def init_hooks(self, hook, toolchain_name):
|
def init_hooks(self, hook, toolchain_name):
|
||||||
if toolchain_name in ['ARM_STD', 'ARM_MICRO']:
|
if toolchain_name in ['ARM_STD', 'ARM_MICRO']:
|
||||||
hook.hook_add_binary("post", self.binary_hook)
|
hook.hook_add_binary("post", self.binary_hook)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def binary_hook(t_self, elf, binf):
|
def binary_hook(t_self, resources, elf, binf):
|
||||||
for hexf in t_self.resources.hex_files:
|
for hexf in resources.hex_files:
|
||||||
if hexf.find(NRF51822.EXPECTED_SOFTDEVICE) != -1:
|
if hexf.find(NRF51822.EXPECTED_SOFTDEVICE) != -1:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
t_self.debug("Hex file not found. Aborting.")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Generate hex file
|
# Generate hex file
|
||||||
# NOTE: this is temporary, it will be removed later and only the
|
# NOTE: this is temporary, it will be removed later and only the
|
||||||
# combined binary file (below) will be used
|
# combined binary file (below) will be used
|
||||||
from intelhex import IntelHex
|
from intelhex import IntelHex
|
||||||
binh = IntelHex()
|
binh = IntelHex()
|
||||||
binh.loadbin(binf, offset = NRF51822.APPCODE_OFFSET)
|
binh.loadbin(binf, offset = NRF51822.APPCODE_OFFSET)
|
||||||
|
|
||||||
sdh = IntelHex(hexf)
|
sdh = IntelHex(hexf)
|
||||||
sdh.merge(binh)
|
sdh.merge(binh)
|
||||||
outname = binf + ".temp"
|
outname = binf.replace(".bin", ".hex")
|
||||||
with open(outname, "w") as f:
|
with open(outname, "w") as f:
|
||||||
sdh.tofile(f, format = 'hex')
|
sdh.tofile(f, format = 'hex')
|
||||||
t_self.debug("Generated SoftDevice-enabled image in '%s'" % outname)
|
t_self.debug("Generated SoftDevice-enabled image in '%s'" % outname)
|
||||||
|
|
||||||
if t_self.target.binary_format == "hex":
|
|
||||||
os.rename(outname, binf)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Generate concatenated SoftDevice + application binary
|
# Generate concatenated SoftDevice + application binary
|
||||||
# Currently, this is only supported for SoftDevice images that have
|
# Currently, this is only supported for SoftDevice images that have
|
||||||
# an UICR area
|
# an UICR area
|
||||||
sdh = IntelHex(hexf)
|
sdh = IntelHex(hexf)
|
||||||
if sdh.maxaddr() < NRF51822.UICR_START:
|
if sdh.maxaddr() < NRF51822.UICR_START:
|
||||||
t_self.error("SoftDevice image does not have UICR area. Aborting.")
|
t_self.error("SoftDevice image does not have UICR area, aborting")
|
||||||
return
|
return
|
||||||
addrlist = sdh.addresses()
|
addrlist = sdh.addresses()
|
||||||
try:
|
try:
|
||||||
uicr_start_index = addrlist.index(NRF51822.UICR_START)
|
uicr_start_index = addrlist.index(NRF51822.UICR_START)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
t_self.error("UICR start address not found in the SoftDevice image. Aborting.")
|
t_self.error("UICR start address not found in the SoftDevice image, aborting")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Assume that everything up to uicr_start_index are contiguous addresses
|
# Assume that everything up to uicr_start_index are contiguous addresses
|
||||||
# in the SoftDevice code area
|
# in the SoftDevice code area
|
||||||
softdevice_code_size = addrlist[uicr_start_index - 1] + 1
|
softdevice_code_size = addrlist[uicr_start_index - 1] + 1
|
||||||
t_self.debug("SoftDevice code size is %d bytes" % softdevice_code_size)
|
t_self.debug("SoftDevice code size is %d bytes" % softdevice_code_size)
|
||||||
|
|
||||||
# First part: SoftDevice code
|
# First part: SoftDevice code
|
||||||
bindata = sdh[:softdevice_code_size].tobinstr()
|
bindata = sdh[:softdevice_code_size].tobinstr()
|
||||||
|
|
||||||
# Second part: pad with 0xFF up to APPCODE_OFFSET
|
# Second part: pad with 0xFF up to APPCODE_OFFSET
|
||||||
bindata = bindata + '\xFF' * (NRF51822.APPCODE_OFFSET - softdevice_code_size)
|
bindata = bindata + '\xFF' * (NRF51822.APPCODE_OFFSET - softdevice_code_size)
|
||||||
|
|
||||||
# Last part: the application code
|
# Last part: the application code
|
||||||
with open(binf, 'r+b') as f:
|
with open(binf, 'r+b') as f:
|
||||||
bindata = bindata + f.read()
|
bindata = bindata + f.read()
|
||||||
|
|
Loading…
Reference in New Issue