mirror of https://github.com/ARMmbed/mbed-os.git
[NRF51822] Generate binary output, removing UICR section.
Add IntelHex utility to print section addressespull/182/head
parent
32764eb5d5
commit
4109142348
|
@ -0,0 +1,18 @@
|
|||
def print_section(start, end):
|
||||
print "[0x%08X - 0x%08X]" % (start, end)
|
||||
|
||||
def print_sections(h):
|
||||
start, last_address = None, None
|
||||
for a in h.addresses():
|
||||
if last_address is None:
|
||||
start, last_address = a, a
|
||||
continue
|
||||
|
||||
if a > last_address + 1:
|
||||
print_section(start, last_address)
|
||||
start = a
|
||||
|
||||
last_address = a
|
||||
|
||||
if start:
|
||||
print_section(start, last_address)
|
|
@ -387,12 +387,13 @@ class UBLOX_C027(Target):
|
|||
|
||||
|
||||
class NRF51822(Target):
|
||||
OUTPUT_EXT = '.hex'
|
||||
|
||||
EXPECTED_SOFTDEVICE = 's110_nrf51822_6.0.0_softdevice.hex'
|
||||
UICR_START = 0x10001000
|
||||
|
||||
APPCODE_OFFSET = 0x14000
|
||||
|
||||
UICR_START = 0x10001000
|
||||
UICR_END = 0x10001013
|
||||
|
||||
def __init__(self):
|
||||
Target.__init__(self)
|
||||
|
||||
|
@ -402,6 +403,8 @@ class NRF51822(Target):
|
|||
|
||||
self.supported_toolchains = ["ARM"]
|
||||
|
||||
self.is_disk_virtual = True
|
||||
|
||||
def init_hooks(self, hook, toolchain_name):
|
||||
if toolchain_name in ['ARM_STD', 'ARM_MICRO']:
|
||||
hook.hook_add_binary("post", self.binary_hook)
|
||||
|
@ -425,45 +428,11 @@ class NRF51822(Target):
|
|||
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)
|
||||
# Remove UICR section
|
||||
del sdh[NRF51822.UICR_START:NRF51822.UICR_END+1]
|
||||
|
||||
# Generate concatenated SoftDevice + application binary
|
||||
# Currently, this is only supported for SoftDevice images that have
|
||||
# an UICR area
|
||||
"""
|
||||
sdh = IntelHex(hexf)
|
||||
if sdh.maxaddr() < NRF51822.UICR_START:
|
||||
t_self.error("SoftDevice image does not have UICR area. Aborting.")
|
||||
return
|
||||
addrlist = sdh.addresses()
|
||||
try:
|
||||
uicr_start_index = addrlist.index(NRF51822.UICR_START)
|
||||
except ValueError:
|
||||
t_self.error("UICR start address not found in the SoftDevice image. Aborting.")
|
||||
return
|
||||
|
||||
# Assume that everything up to uicr_start_index are contiguous addresses
|
||||
# in the SoftDevice code area
|
||||
softdevice_code_size = addrlist[uicr_start_index - 1] + 1
|
||||
t_self.debug("SoftDevice code size is %d bytes" % softdevice_code_size)
|
||||
|
||||
# First part: SoftDevice code
|
||||
bindata = sdh[:softdevice_code_size].tobinstr()
|
||||
|
||||
# Second part: pad with 0xFF up to APPCODE_OFFSET
|
||||
bindata = bindata + '\xFF' * (NRF51822.APPCODE_OFFSET - softdevice_code_size)
|
||||
|
||||
# Last part: the application code
|
||||
with open(binf, 'r+b') as f:
|
||||
bindata = bindata + f.read()
|
||||
# Write back the binary
|
||||
f.seek(0)
|
||||
f.write(bindata)
|
||||
t_self.debug("Generated concatenated binary of %d bytes" % len(bindata))
|
||||
"""
|
||||
with open(binf, "w") as f:
|
||||
sdh.tofile(f, format = 'bin')
|
||||
|
||||
|
||||
# Get a single instance for each target
|
||||
|
|
Loading…
Reference in New Issue