@@ -189,7 +189,7 @@ def init_hooks(self, hook, toolchain_name):
189
189
hook .hook_add_binary ("post" , self .binary_hook )
190
190
191
191
@staticmethod
192
- def binary_hook (t_self , resources , elf , binf ):
192
+ def binary_hook (t_self , elf , binf ):
193
193
if not os .path .isdir (binf ):
194
194
# Regular binary file, nothing to do
195
195
return
@@ -393,50 +393,64 @@ def __init__(self):
393
393
394
394
self .supported_toolchains = ["ARM" , "uARM" , "GCC_ARM" , "GCC_CS" , "GCC_CR" , "IAR" ]
395
395
396
+ self .binary_format = "hex"
397
+
396
398
def init_hooks (self , hook , toolchain_name ):
397
399
if toolchain_name in ['ARM_STD' , 'ARM_MICRO' ]:
398
400
hook .hook_add_binary ("post" , self .binary_hook )
399
401
400
402
@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 :
403
405
if hexf .find (NRF51822 .EXPECTED_SOFTDEVICE ) != - 1 :
404
406
break
405
407
else :
408
+ t_self .debug ("Hex file not found. Aborting." )
406
409
return
410
+
407
411
# Generate hex file
408
412
# NOTE: this is temporary, it will be removed later and only the
409
413
# combined binary file (below) will be used
410
414
from intelhex import IntelHex
411
415
binh = IntelHex ()
412
416
binh .loadbin (binf , offset = NRF51822 .APPCODE_OFFSET )
417
+
413
418
sdh = IntelHex (hexf )
414
419
sdh .merge (binh )
415
- outname = binf . replace ( ".bin" , ".hex" )
420
+ outname = binf + ".temp"
416
421
with open (outname , "w" ) as f :
417
422
sdh .tofile (f , format = 'hex' )
418
423
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
+
419
429
# Generate concatenated SoftDevice + application binary
420
430
# Currently, this is only supported for SoftDevice images that have
421
431
# an UICR area
422
432
sdh = IntelHex (hexf )
423
433
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. " )
425
435
return
426
436
addrlist = sdh .addresses ()
427
437
try :
428
438
uicr_start_index = addrlist .index (NRF51822 .UICR_START )
429
439
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. " )
431
441
return
442
+
432
443
# Assume that everything up to uicr_start_index are contiguous addresses
433
444
# in the SoftDevice code area
434
445
softdevice_code_size = addrlist [uicr_start_index - 1 ] + 1
435
446
t_self .debug ("SoftDevice code size is %d bytes" % softdevice_code_size )
447
+
436
448
# First part: SoftDevice code
437
449
bindata = sdh [:softdevice_code_size ].tobinstr ()
450
+
438
451
# Second part: pad with 0xFF up to APPCODE_OFFSET
439
452
bindata = bindata + '\xFF ' * (NRF51822 .APPCODE_OFFSET - softdevice_code_size )
453
+
440
454
# Last part: the application code
441
455
with open (binf , 'r+b' ) as f :
442
456
bindata = bindata + f .read ()
0 commit comments