Skip to content

Commit 01204f1

Browse files
committed
Reintroduce LPC4088 and Teensy3.1 post build hooks
1 parent 8b09560 commit 01204f1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tools/targets/__init__.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ def lpc_patch(t_self, resources, elf, binf):
470470
t_self.notify.debug("LPC Patch: %s" % os.path.split(binf)[1])
471471
patch(binf)
472472

473+
473474
class MTSCode(object):
474475
"""Generic MTS code"""
475476
@staticmethod
@@ -505,6 +506,53 @@ def combine_bins_mts_dragonfly(t_self, resources, elf, binf):
505506
MTSCode._combine_bins_helper("MTS_DRAGONFLY_F411RE", binf)
506507

507508

509+
class LPC4088Code(object):
510+
"""Code specific to the LPC4088"""
511+
@staticmethod
512+
def binary_hook(t_self, resources, elf, binf):
513+
"""Hook to be run after an elf file is built"""
514+
if not os.path.isdir(binf):
515+
# Regular binary file, nothing to do
516+
LPCTargetCode.lpc_patch(t_self, resources, elf, binf)
517+
return
518+
outbin = open(binf + ".temp", "wb")
519+
partf = open(os.path.join(binf, "ER_IROM1"), "rb")
520+
# Pad the fist part (internal flash) with 0xFF to 512k
521+
data = partf.read()
522+
outbin.write(data)
523+
outbin.write(b'\xFF' * (512*1024 - len(data)))
524+
partf.close()
525+
# Read and append the second part (external flash) in chunks of fixed
526+
# size
527+
chunksize = 128 * 1024
528+
partf = open(os.path.join(binf, "ER_IROM2"), "rb")
529+
while True:
530+
data = partf.read(chunksize)
531+
outbin.write(data)
532+
if len(data) < chunksize:
533+
break
534+
partf.close()
535+
outbin.close()
536+
# Remove the directory with the binary parts and rename the temporary
537+
# file to 'binf'
538+
shutil.rmtree(binf, True)
539+
os.rename(binf + '.temp', binf)
540+
t_self.notify.debug(
541+
"Generated custom binary file (internal flash + SPIFI)"
542+
)
543+
LPCTargetCode.lpc_patch(t_self, resources, elf, binf)
544+
545+
546+
class TEENSY3_1Code(object):
547+
"""Hooks for the TEENSY3.1"""
548+
@staticmethod
549+
def binary_hook(t_self, resources, elf, binf):
550+
"""Hook that is run after elf is generated"""
551+
# This function is referenced by old versions of targets.json and
552+
# should be kept for backwards compatibility.
553+
pass
554+
555+
508556
class MCU_NRF51Code(object):
509557
"""NRF51 Hooks"""
510558
@staticmethod

0 commit comments

Comments
 (0)