Skip to content

Commit 4109142

Browse files
committed
[NRF51822] Generate binary output, removing UICR section.
Add IntelHex utility to print section addresses
1 parent 32764eb commit 4109142

File tree

2 files changed

+28
-41
lines changed

2 files changed

+28
-41
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def print_section(start, end):
2+
print "[0x%08X - 0x%08X]" % (start, end)
3+
4+
def print_sections(h):
5+
start, last_address = None, None
6+
for a in h.addresses():
7+
if last_address is None:
8+
start, last_address = a, a
9+
continue
10+
11+
if a > last_address + 1:
12+
print_section(start, last_address)
13+
start = a
14+
15+
last_address = a
16+
17+
if start:
18+
print_section(start, last_address)

workspace_tools/targets.py

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,13 @@ def __init__(self):
387387

388388

389389
class NRF51822(Target):
390-
OUTPUT_EXT = '.hex'
391-
392390
EXPECTED_SOFTDEVICE = 's110_nrf51822_6.0.0_softdevice.hex'
393-
UICR_START = 0x10001000
391+
394392
APPCODE_OFFSET = 0x14000
395393

394+
UICR_START = 0x10001000
395+
UICR_END = 0x10001013
396+
396397
def __init__(self):
397398
Target.__init__(self)
398399

@@ -401,6 +402,8 @@ def __init__(self):
401402
self.extra_labels = ["NORDIC"]
402403

403404
self.supported_toolchains = ["ARM"]
405+
406+
self.is_disk_virtual = True
404407

405408
def init_hooks(self, hook, toolchain_name):
406409
if toolchain_name in ['ARM_STD', 'ARM_MICRO']:
@@ -425,45 +428,11 @@ def binary_hook(t_self, resources, elf, binf):
425428
sdh = IntelHex(hexf)
426429
sdh.merge(binh)
427430

428-
outname = binf.replace('.bin', '.hex')
429-
with open(outname, "w") as f:
430-
sdh.tofile(f, format = 'hex')
431-
t_self.debug("Generated SoftDevice-enabled image in '%s'" % outname)
432-
433-
# Generate concatenated SoftDevice + application binary
434-
# Currently, this is only supported for SoftDevice images that have
435-
# an UICR area
436-
"""
437-
sdh = IntelHex(hexf)
438-
if sdh.maxaddr() < NRF51822.UICR_START:
439-
t_self.error("SoftDevice image does not have UICR area. Aborting.")
440-
return
441-
addrlist = sdh.addresses()
442-
try:
443-
uicr_start_index = addrlist.index(NRF51822.UICR_START)
444-
except ValueError:
445-
t_self.error("UICR start address not found in the SoftDevice image. Aborting.")
446-
return
431+
# Remove UICR section
432+
del sdh[NRF51822.UICR_START:NRF51822.UICR_END+1]
447433

448-
# Assume that everything up to uicr_start_index are contiguous addresses
449-
# in the SoftDevice code area
450-
softdevice_code_size = addrlist[uicr_start_index - 1] + 1
451-
t_self.debug("SoftDevice code size is %d bytes" % softdevice_code_size)
452-
453-
# First part: SoftDevice code
454-
bindata = sdh[:softdevice_code_size].tobinstr()
455-
456-
# Second part: pad with 0xFF up to APPCODE_OFFSET
457-
bindata = bindata + '\xFF' * (NRF51822.APPCODE_OFFSET - softdevice_code_size)
458-
459-
# Last part: the application code
460-
with open(binf, 'r+b') as f:
461-
bindata = bindata + f.read()
462-
# Write back the binary
463-
f.seek(0)
464-
f.write(bindata)
465-
t_self.debug("Generated concatenated binary of %d bytes" % len(bindata))
466-
"""
434+
with open(binf, "w") as f:
435+
sdh.tofile(f, format = 'bin')
467436

468437

469438
# Get a single instance for each target

0 commit comments

Comments
 (0)