targets/LPC/__init__.py
changeset 571 427bf9130d12
parent 540 bacc1314fee6
child 600 310455d73131
equal deleted inserted replaced
570:46abd6b2f639 571:427bf9130d12
     2 from subprocess import Popen,PIPE
     2 from subprocess import Popen,PIPE
     3 from .. import toolchain_makefile
     3 from .. import toolchain_makefile
     4 import hashlib
     4 import hashlib
     5 
     5 
     6 class LPC_target(toolchain_makefile):
     6 class LPC_target(toolchain_makefile):
     7     extension = ".ld"
     7     #extension = ".ld"
     8     DebugEnabled = False
     8     #DebugEnabled = False
       
     9     def __init__(self, PluginsRootInstance):
       
    10         self.binmd5key = None
       
    11         toolchain_makefile.__init__(self, PluginsRootInstance)
       
    12 
       
    13     def _GetBinMD5FileName(self):
       
    14         return os.path.join(self.buildpath, "lastbuildPLCbin.md5")
       
    15 
       
    16     def _get_md5_header(self):
       
    17         """Returns signature header"""
       
    18         size = int(Popen(
       
    19              ['arm-elf-size','-B',os.path.join(self.buildpath,"ArmPLC_rom.elf")],
       
    20              stdout=PIPE).communicate()[0].splitlines()[1].split()[0])
       
    21         res = "&" + hashlib.md5(open(os.path.join(self.buildpath, "ArmPLC_rom.bin"), "rb").read(size)).hexdigest() + '\n' +\
       
    22               "$" + str(size) + '\n'
       
    23         return res
     9 
    24 
    10     def GetBinaryCode(self):
    25     def GetBinaryCode(self):
    11         """Returns ready to send signed + sized intel formated hex program"""
    26         """Returns ready to send signed + sized intel formated hex program"""
    12         try:
    27         try:
    13             size = int(Popen(
    28             res = self._get_md5_header() +\
    14                  ['arm-elf-size','-B',os.path.join(self.buildpath,"ArmPLC_rom.elf")],
       
    15                  stdout=PIPE).communicate()[0].splitlines()[1].split()[0])
       
    16             res = "&" + hashlib.md5(open(os.path.join(self.buildpath, "ArmPLC_rom.bin"), "rb").read(size)).hexdigest() + '\n' +\
       
    17                    "$" + str(size) + '\n' +\
       
    18                    open(os.path.join(self.buildpath, "ArmPLC_rom.hex"), "r").read()
    29                    open(os.path.join(self.buildpath, "ArmPLC_rom.hex"), "r").read()
    19             return res
    30             return res
    20         except Exception, e:
    31         except Exception, e:
    21             return None
    32             return None
    22 
    33 
       
    34     def _get_cached_md5_header(self):
       
    35         if self.binmd5key is not None:
       
    36             return self.binmd5key
       
    37         else:
       
    38             try:
       
    39                 return open(self._GetMD5FileName(), "r").read()
       
    40             except IOError, e:
       
    41                 return None
       
    42 
       
    43     def GetBinaryCodeMD5(self, mode):
       
    44         if mode == "BOOTLOADER":
       
    45             return self._get_cached_md5_header()
       
    46         else:
       
    47             return toolchain_makefile.GetBinaryCodeMD5(self)
       
    48 
       
    49     def build(self):
       
    50         res = toolchain_makefile.build(self)
       
    51         self.binmd5key = self._get_md5_header()
       
    52         f = open(self._GetBinMD5FileName(), "w")
       
    53         f.write(self.binmd5key)
       
    54         f.close()
       
    55         return res
       
    56