Skip to content

Commit 4b2b368

Browse files
committed
Fix build system merge with Nordic changes
1 parent 90d56a0 commit 4b2b368

File tree

3 files changed

+47
-54
lines changed

3 files changed

+47
-54
lines changed

workspace_tools/targets.py

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def program_cycle_s(self):
4949

5050
def get_labels(self):
5151
return [self.name, CORE_LABELS[self.core]] + self.extra_labels
52-
52+
5353
def init_hooks(self, hook, toolchain_name):
5454
pass
5555

@@ -123,18 +123,20 @@ def __init__(self):
123123

124124
self.is_disk_virtual = True
125125

126+
126127
class KL46Z(Target):
127128
def __init__(self):
128129
Target.__init__(self)
129130

130131
self.core = "Cortex-M0+"
131132

132133
self.extra_labels = ['Freescale', 'KLXX']
133-
134+
134135
self.supported_toolchains = ["GCC_ARM", "ARM"]
135-
136+
136137
self.is_disk_virtual = True
137138

139+
138140
class K20D5M(Target):
139141
def __init__(self):
140142
Target.__init__(self)
@@ -183,13 +185,15 @@ def __init__(self):
183185
self.extra_labels = ['NXP', 'LPC408X']
184186

185187
self.supported_toolchains = ["ARM", "GCC_CR", "GCC_ARM"]
188+
189+
self.is_disk_virtual = True
186190

187191
def init_hooks(self, hook, toolchain_name):
188192
if toolchain_name in ['ARM_STD', 'ARM_MICRO']:
189193
hook.hook_add_binary("post", self.binary_hook)
190-
194+
191195
@staticmethod
192-
def binary_hook(t_self, elf, binf):
196+
def binary_hook(t_self, resources, elf, binf):
193197
if not os.path.isdir(binf):
194198
# Regular binary file, nothing to do
195199
return
@@ -260,7 +264,7 @@ def __init__(self):
260264

261265
self.supported_toolchains = ["ARM", "GCC_ARM"]
262266

263-
267+
264268
class NUCLEO_F103RB(Target):
265269
def __init__(self):
266270
Target.__init__(self)
@@ -272,8 +276,8 @@ def __init__(self):
272276
self.supported_toolchains = ["ARM", "uARM", "GCC_ARM"]
273277

274278
self.binary_naming = "8.3"
275-
276-
279+
280+
277281
class NUCLEO_L152RE(Target):
278282
def __init__(self):
279283
Target.__init__(self)
@@ -286,7 +290,7 @@ def __init__(self):
286290

287291
self.binary_naming = "8.3"
288292

289-
293+
290294
class NUCLEO_F401RE(Target):
291295
def __init__(self):
292296
Target.__init__(self)
@@ -299,7 +303,7 @@ def __init__(self):
299303

300304
self.binary_naming = "8.3"
301305

302-
306+
303307
class NUCLEO_F030R8(Target):
304308
def __init__(self):
305309
Target.__init__(self)
@@ -311,17 +315,6 @@ def __init__(self):
311315
self.supported_toolchains = ["ARM", "uARM", "GCC_ARM"]
312316

313317
self.binary_naming = "8.3"
314-
315-
316-
class MBED_MCU(Target):
317-
def __init__(self):
318-
Target.__init__(self)
319-
320-
self.core = "Cortex-M0+"
321-
322-
self.extra_labels = ['ARM']
323-
324-
self.supported_toolchains = ["ARM"]
325318

326319

327320
class LPC1347(Target):
@@ -378,11 +371,14 @@ def __init__(self):
378371

379372
self.supported_toolchains = ["ARM", "uARM", "GCC_ARM", "GCC_CS", "GCC_CR", "IAR"]
380373

374+
381375
class NRF51822(Target):
382376
EXPECTED_SOFTDEVICE = 's110_nrf51822_6.0.0_softdevice.hex'
383377
UICR_START = 0x10001000
384378
APPCODE_OFFSET = 0x14000
385-
379+
380+
OUTPUT_EXT = '.hex'
381+
386382
def __init__(self):
387383
Target.__init__(self)
388384

@@ -391,43 +387,39 @@ def __init__(self):
391387
self.extra_labels = ["NORDIC"]
392388

393389
self.supported_toolchains = ["ARM"]
394-
395-
self.binary_format = "hex"
396-
390+
397391
def init_hooks(self, hook, toolchain_name):
398392
if toolchain_name in ['ARM_STD', 'ARM_MICRO']:
399393
hook.hook_add_binary("post", self.binary_hook)
400-
394+
401395
@staticmethod
402-
def binary_hook(t_self, elf, binf):
403-
for hexf in t_self.resources.hex_files:
396+
def binary_hook(t_self, resources, elf, binf):
397+
for hexf in resources.hex_files:
404398
if hexf.find(NRF51822.EXPECTED_SOFTDEVICE) != -1:
405399
break
406400
else:
407401
t_self.debug("Hex file not found. Aborting.")
408402
return
409-
403+
410404
# Generate hex file
411405
# NOTE: this is temporary, it will be removed later and only the
412406
# combined binary file (below) will be used
413407
from intelhex import IntelHex
414408
binh = IntelHex()
415409
binh.loadbin(binf, offset = NRF51822.APPCODE_OFFSET)
416-
410+
417411
sdh = IntelHex(hexf)
418412
sdh.merge(binh)
419-
outname = binf + ".temp"
413+
414+
outname = binf.replace('.bin', '.hex')
420415
with open(outname, "w") as f:
421416
sdh.tofile(f, format = 'hex')
422417
t_self.debug("Generated SoftDevice-enabled image in '%s'" % outname)
423-
424-
if t_self.target.binary_format == "hex":
425-
os.rename(outname, binf)
426-
return
427-
418+
428419
# Generate concatenated SoftDevice + application binary
429420
# Currently, this is only supported for SoftDevice images that have
430421
# an UICR area
422+
"""
431423
sdh = IntelHex(hexf)
432424
if sdh.maxaddr() < NRF51822.UICR_START:
433425
t_self.error("SoftDevice image does not have UICR area. Aborting.")
@@ -438,25 +430,27 @@ def binary_hook(t_self, elf, binf):
438430
except ValueError:
439431
t_self.error("UICR start address not found in the SoftDevice image. Aborting.")
440432
return
441-
433+
442434
# Assume that everything up to uicr_start_index are contiguous addresses
443435
# in the SoftDevice code area
444436
softdevice_code_size = addrlist[uicr_start_index - 1] + 1
445437
t_self.debug("SoftDevice code size is %d bytes" % softdevice_code_size)
446-
438+
447439
# First part: SoftDevice code
448440
bindata = sdh[:softdevice_code_size].tobinstr()
449-
441+
450442
# Second part: pad with 0xFF up to APPCODE_OFFSET
451443
bindata = bindata + '\xFF' * (NRF51822.APPCODE_OFFSET - softdevice_code_size)
452-
444+
453445
# Last part: the application code
454446
with open(binf, 'r+b') as f:
455447
bindata = bindata + f.read()
456448
# Write back the binary
457449
f.seek(0)
458450
f.write(bindata)
459451
t_self.debug("Generated concatenated binary of %d bytes" % len(bindata))
452+
"""
453+
460454

461455
# Get a single instance for each target
462456
TARGETS = [
@@ -477,7 +471,6 @@ def binary_hook(t_self, elf, binf):
477471
NUCLEO_L152RE(),
478472
NUCLEO_F401RE(),
479473
NUCLEO_F030R8(),
480-
MBED_MCU(),
481474
LPC1347(),
482475
LPC1114(),
483476
LPC11C24(),

workspace_tools/toolchains/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,38 +443,39 @@ def build_library(self, objects, dir, name):
443443
self.archive(objects, fout)
444444

445445
def link_program(self, r, tmp_path, name):
446-
if hasattr(self.target, 'binary_format'):
447-
ext = self.target.binary_format
448-
else:
449-
ext = 'bin'
450-
446+
ext = 'bin'
447+
451448
if hasattr(self.target, 'binary_naming'):
452449
if self.target.binary_naming == "8.3":
453450
name = name[0:8]
454451
ext = ext[0:3]
455-
452+
456453
filename = name+'.'+ext
457-
454+
458455
elf = join(tmp_path, name + '.elf')
459456
bin = join(tmp_path, filename)
460457

461458
if self.need_update(elf, r.objects + r.libraries + [r.linker_script]):
462459
self.progress("link", name)
463460
self.link(elf, r.objects, r.libraries, r.lib_dirs, r.linker_script)
464-
461+
465462
if self.need_update(bin, [elf]):
466463
self.progress("elf2bin", name)
464+
467465
self.binary(r, elf, bin)
468466

469467
if self.target.name.startswith('LPC'):
470468
self.debug("LPC Patch %s" % filename)
471469
patch(bin)
472-
470+
473471
self.var("compile_succeded", True)
474472
self.var("binary", filename)
475473
if hasattr(self.target, 'binary_naming'):
476474
self.var("binary_naming", self.target.binary_naming)
477-
475+
476+
if hasattr(self.target, 'OUTPUT_EXT'):
477+
bin = bin.replace('.bin', self.target.OUTPUT_EXT)
478+
478479
return bin
479480

480481
def default_cmd(self, command):

workspace_tools/toolchains/arm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,12 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
128128
self.default_cmd(self.ld + args + objects + libraries + self.sys_libs)
129129

130130
@hook_tool
131-
132131
def binary(self, resources, elf, bin):
133132
args = [self.elf2bin, '--bin', '-o', bin, elf]
134-
133+
135134
if hasattr(self.target, "binary_cmdline_hook"):
136135
args = self.target.binary_cmdline_hook(self.__class__.__name__, args)
137-
136+
138137
self.default_cmd(args)
139138

140139
class ARM_STD(ARM):

0 commit comments

Comments
 (0)