edouard@571: import os edouard@571: from subprocess import Popen,PIPE Edouard@648: from ..toolchain_makefile import toolchain_makefile edouard@571: import hashlib edouard@571: edouard@571: class LPC_target(toolchain_makefile): edouard@571: #extension = ".ld" edouard@571: #DebugEnabled = False edouard@571: def __init__(self, PluginsRootInstance): edouard@571: self.binmd5key = None edouard@571: toolchain_makefile.__init__(self, PluginsRootInstance) edouard@571: edouard@571: def _GetBinMD5FileName(self): edouard@571: return os.path.join(self.buildpath, "lastbuildPLCbin.md5") edouard@571: edouard@571: def _get_md5_header(self): edouard@571: """Returns signature header""" edouard@571: size = int(Popen( edouard@571: ['arm-elf-size','-B',os.path.join(self.buildpath,"ArmPLC_rom.elf")], edouard@571: stdout=PIPE).communicate()[0].splitlines()[1].split()[0]) edouard@571: res = "&" + hashlib.md5(open(os.path.join(self.buildpath, "ArmPLC_rom.bin"), "rb").read(size)).hexdigest() + '\n' +\ edouard@571: "$" + str(size) + '\n' edouard@571: return res edouard@571: edouard@571: def GetBinaryCode(self): edouard@571: """Returns ready to send signed + sized intel formated hex program""" edouard@571: try: edouard@571: res = self._get_md5_header() +\ edouard@571: open(os.path.join(self.buildpath, "ArmPLC_rom.hex"), "r").read() edouard@571: return res edouard@571: except Exception, e: edouard@571: return None edouard@571: edouard@571: def _get_cached_md5_header(self): edouard@571: if self.binmd5key is not None: edouard@571: return self.binmd5key edouard@571: else: edouard@571: try: Edouard@600: return open(self._GetBinMD5FileName(), "r").read() edouard@571: except IOError, e: edouard@571: return None edouard@571: edouard@571: def GetBinaryCodeMD5(self, mode): edouard@571: if mode == "BOOTLOADER": edouard@571: return self._get_cached_md5_header() edouard@571: else: edouard@571: return toolchain_makefile.GetBinaryCodeMD5(self) edouard@571: edouard@571: def build(self): edouard@571: res = toolchain_makefile.build(self) edouard@571: self.binmd5key = self._get_md5_header() edouard@571: f = open(self._GetBinMD5FileName(), "w") edouard@571: f.write(self.binmd5key) edouard@571: f.close() Edouard@600: try: Edouard@600: self.PluginsRootInstance.logger.write( Edouard@600: _("Binary is %s bytes long\n")% Edouard@600: str(os.path.getsize( Edouard@600: os.path.join(self.buildpath, "ArmPLC_rom.bin")))) Edouard@600: except Exception, e: Edouard@600: pass edouard@571: return res edouard@571: