Skip to content

Commit 78b141b

Browse files
Revert "Revert "Use hex delivery mode for NRF51822""
This reverts commit 5038233.
1 parent 026b661 commit 78b141b

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

workspace_tools/build_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def build_library(src_paths, build_path, target, toolchain_name,
116116
toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
117117
dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)
118118

119+
toolchain.resources = resources
120+
119121
# Compile Sources
120122
objects = []
121123
for resource in resources:

workspace_tools/targets.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def init_hooks(self, hook, toolchain_name):
189189
hook.hook_add_binary("post", self.binary_hook)
190190

191191
@staticmethod
192-
def binary_hook(t_self, resources, elf, binf):
192+
def binary_hook(t_self, elf, binf):
193193
if not os.path.isdir(binf):
194194
# Regular binary file, nothing to do
195195
return
@@ -393,50 +393,64 @@ def __init__(self):
393393

394394
self.supported_toolchains = ["ARM", "uARM", "GCC_ARM", "GCC_CS", "GCC_CR", "IAR"]
395395

396+
self.binary_format = "hex"
397+
396398
def init_hooks(self, hook, toolchain_name):
397399
if toolchain_name in ['ARM_STD', 'ARM_MICRO']:
398400
hook.hook_add_binary("post", self.binary_hook)
399401

400402
@staticmethod
401-
def binary_hook(t_self, resources, elf, binf):
402-
for hexf in resources.hex_files:
403+
def binary_hook(t_self, elf, binf):
404+
for hexf in t_self.resources.hex_files:
403405
if hexf.find(NRF51822.EXPECTED_SOFTDEVICE) != -1:
404406
break
405407
else:
408+
t_self.debug("Hex file not found. Aborting.")
406409
return
410+
407411
# Generate hex file
408412
# NOTE: this is temporary, it will be removed later and only the
409413
# combined binary file (below) will be used
410414
from intelhex import IntelHex
411415
binh = IntelHex()
412416
binh.loadbin(binf, offset = NRF51822.APPCODE_OFFSET)
417+
413418
sdh = IntelHex(hexf)
414419
sdh.merge(binh)
415-
outname = binf.replace(".bin", ".hex")
420+
outname = binf + ".temp"
416421
with open(outname, "w") as f:
417422
sdh.tofile(f, format = 'hex')
418423
t_self.debug("Generated SoftDevice-enabled image in '%s'" % outname)
424+
425+
if t_self.target.binary_format == "hex":
426+
os.rename(outname, binf)
427+
return
428+
419429
# Generate concatenated SoftDevice + application binary
420430
# Currently, this is only supported for SoftDevice images that have
421431
# an UICR area
422432
sdh = IntelHex(hexf)
423433
if sdh.maxaddr() < NRF51822.UICR_START:
424-
t_self.error("SoftDevice image does not have UICR area, aborting")
434+
t_self.error("SoftDevice image does not have UICR area. Aborting.")
425435
return
426436
addrlist = sdh.addresses()
427437
try:
428438
uicr_start_index = addrlist.index(NRF51822.UICR_START)
429439
except ValueError:
430-
t_self.error("UICR start address not found in the SoftDevice image, aborting")
440+
t_self.error("UICR start address not found in the SoftDevice image. Aborting.")
431441
return
442+
432443
# Assume that everything up to uicr_start_index are contiguous addresses
433444
# in the SoftDevice code area
434445
softdevice_code_size = addrlist[uicr_start_index - 1] + 1
435446
t_self.debug("SoftDevice code size is %d bytes" % softdevice_code_size)
447+
436448
# First part: SoftDevice code
437449
bindata = sdh[:softdevice_code_size].tobinstr()
450+
438451
# Second part: pad with 0xFF up to APPCODE_OFFSET
439452
bindata = bindata + '\xFF' * (NRF51822.APPCODE_OFFSET - softdevice_code_size)
453+
440454
# Last part: the application code
441455
with open(binf, 'r+b') as f:
442456
bindata = bindata + f.read()

0 commit comments

Comments
 (0)