From 01204f1ed432fb0d3d5a10a1bc5f920c2ebff219 Mon Sep 17 00:00:00 2001 From: Rob Walton Date: Fri, 5 Jun 2020 09:32:19 +0100 Subject: [PATCH] Reintroduce LPC4088 and Teensy3.1 post build hooks --- tools/targets/__init__.py | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/targets/__init__.py b/tools/targets/__init__.py index f450bedbe7..5cacd730d1 100644 --- a/tools/targets/__init__.py +++ b/tools/targets/__init__.py @@ -470,6 +470,7 @@ class LPCTargetCode(object): t_self.notify.debug("LPC Patch: %s" % os.path.split(binf)[1]) patch(binf) + class MTSCode(object): """Generic MTS code""" @staticmethod @@ -505,6 +506,53 @@ class MTSCode(object): MTSCode._combine_bins_helper("MTS_DRAGONFLY_F411RE", binf) +class LPC4088Code(object): + """Code specific to the LPC4088""" + @staticmethod + def binary_hook(t_self, resources, elf, binf): + """Hook to be run after an elf file is built""" + if not os.path.isdir(binf): + # Regular binary file, nothing to do + LPCTargetCode.lpc_patch(t_self, resources, elf, binf) + return + outbin = open(binf + ".temp", "wb") + partf = open(os.path.join(binf, "ER_IROM1"), "rb") + # Pad the fist part (internal flash) with 0xFF to 512k + data = partf.read() + outbin.write(data) + outbin.write(b'\xFF' * (512*1024 - len(data))) + partf.close() + # Read and append the second part (external flash) in chunks of fixed + # size + chunksize = 128 * 1024 + partf = open(os.path.join(binf, "ER_IROM2"), "rb") + while True: + data = partf.read(chunksize) + outbin.write(data) + if len(data) < chunksize: + break + partf.close() + outbin.close() + # Remove the directory with the binary parts and rename the temporary + # file to 'binf' + shutil.rmtree(binf, True) + os.rename(binf + '.temp', binf) + t_self.notify.debug( + "Generated custom binary file (internal flash + SPIFI)" + ) + LPCTargetCode.lpc_patch(t_self, resources, elf, binf) + + +class TEENSY3_1Code(object): + """Hooks for the TEENSY3.1""" + @staticmethod + def binary_hook(t_self, resources, elf, binf): + """Hook that is run after elf is generated""" + # This function is referenced by old versions of targets.json and + # should be kept for backwards compatibility. + pass + + class MCU_NRF51Code(object): """NRF51 Hooks""" @staticmethod