From 8f4a52a6f107ed37b38d2908a30378cc9dd65396 Mon Sep 17 00:00:00 2001 From: s0170071 <33855380+s0170071@users.noreply.github.com> Date: Thu, 22 Feb 2018 18:55:45 +0100 Subject: [PATCH] Include name of binary file in crc2.py and sysinfo (#918) * preparations for lwip2 * Add CRC32 to settings * Add CRC to progmem * Add crc of program memory to stettings and security settings .. so that there is a warning if the settings are used by another binary than they were written with. * Moved to md5 * Flash included, moved to MD5 now * Broken comment * Stability improvements free memory went as low as 3000 bytes which made the webserver unresponsive. * Add binary filename to crc2.py and sysinfo * Update WebServer.ino --- crc2.py | 28 ++++++++++++++++++++++++---- src/ESPEasy.ino | 1 + src/WebServer.ino | 4 ++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/crc2.py b/crc2.py index acd1108fc..2c5aef559 100644 --- a/crc2.py +++ b/crc2.py @@ -1,10 +1,12 @@ - import sys import binascii import struct import md5 -MD5DUMMY = "MD5_MD5_MD5_MD5_BoundariesOfTheSegmentsGoHere..." +import os +MD5DUMMY = "MD5_MD5_MD5_MD5_BoundariesOfTheSegmentsGoHere..." #48 chars +FILENAMEDUMMY = "ThisIsTheDummyPlaceHolderForTheBinaryFilename..." #48 chars + MemorySegmentStart,MemorySegmentEnd,MemoryContent=[],[],[] ################################################################## @@ -14,12 +16,15 @@ def showSegments (fileContent,offset): global MemorySegmentStart, MemorySegmentEnd, MemoryContent header = struct.unpack("ii", fileContent[offset:offset+8]) herestr ="" + herestr2 ="" MemorySegmentStart.append(struct.pack("I",header[0])) MemorySegmentEnd.append(struct.pack("I",header[0]+header[1])) MemoryContent.append(fileContent[offset+8:offset+8+header[1]]) if fileContent.find( MD5DUMMY, offset+8, offset+8+header[1]) >0 : herestr= " <-- CRC is here." - print ("SEGMENT "+ str(len(MemorySegmentStart)-1)+ ": memory position: " + hex(header[0])+" to " + hex(header[0]+header[1]) + " length: " + hex(header[1])+herestr) + if fileContent.find( FILENAMEDUMMY, offset+8, offset+8+header[1]) >0 : + herestr2= " <-- filename is here." + print ("SEGMENT "+ str(len(MemorySegmentStart)-1)+ ": memory position: " + hex(header[0])+" to " + hex(header[0]+header[1]) + " length: " + hex(header[1])+herestr+herestr2) #print ("first byte positoin in file: " + hex( offset+8)) #print ("last byte postion in file: " + hex(offset+8+header[1]-1)) return (8+offset+ header[1]); # return start of next segment @@ -82,6 +87,17 @@ while len(startArray) < 16 : if (len(endArray) + len (startArray)) != 32 : print("ERROR: please make sure you add / remove padding if you change the semgents.") +BinaryFileName = ""; +if fileContent.find( FILENAMEDUMMY) < 0: + print("ERROR: FILENAMEDUMMY dummy not found in binary") +else: + BinaryFileName=os.path.basename(FileName) +"\0" + if len(BinaryFileName) >48: # check that filename is <48 chars + BinaryFileName=BinaryFileName[0:48] # truncate if necessary. 49th char in ESP is zero already + else: + BinaryFileName= BinaryFileName.ljust(48,'\0'); # pad with zeros. + + if fileContent.find( MD5DUMMY) < 0: print("ERROR: MD5 dummy not found in binary") else: @@ -91,6 +107,10 @@ else: md5hash = m.digest() print("MD5 hash: "+ m.hexdigest()) print("\nwriting output file:\n" + FileName) + + fileContent=fileContent.replace(MD5DUMMY,md5hash+startArray+endArray) + fileContent=fileContent.replace(FILENAMEDUMMY,BinaryFileName) + with open(FileName, mode='wb') as file: # b is important -> binary - file.write(fileContent.replace(MD5DUMMY,md5hash+startArray+endArray)) + file.write(fileContent) #k=input("press close to exit") diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index 5389a35b5..b151e3426 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -485,6 +485,7 @@ WiFiUDP portUDP; struct CRCStruct{ char compileTimeMD5[16+32+1]= "MD5_MD5_MD5_MD5_BoundariesOfTheSegmentsGoHere..."; + char binaryFilename[16+32+1]= "ThisIsTheDummyPlaceHolderForTheBinaryFilename..."; char compileTime[16]= __TIME__; char compileDate[16]= __DATE__; uint8_t runTimeMD5[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; diff --git a/src/WebServer.ino b/src/WebServer.ino index ca0d3d130..5cee19518 100644 --- a/src/WebServer.ino +++ b/src/WebServer.ino @@ -320,6 +320,7 @@ void sendWebPageChunkedBegin(String& log) void sendWebPageChunkedData(String& log, String& data) { checkRAM(F("sendWebPageChunkedData")); + if (data.length() > 0) { statusLED(true); @@ -4576,6 +4577,9 @@ void handle_sysinfo() { reply += " "; reply += String(CRCValues.compileTime); + reply += F("