I wrote this code for the Metro M4 (that board can hold 50kB of firmware):
Code: Select all
void uploadSignature(){
Serial1.print("signature ");
Serial1.print(SIGNATURESIZE);
Serial1.write(' ');
Serial1.write(0x02);
for (int n=0;n<SIGNATURESIZE;n++){
//Serial1.print(signature[n],HEX);
Serial1.write(signature[n]);
}
Serial1.write(0x03);
}
I was trying to follow the instruction that is send to the serial monitor if you type help:
Code: Select all
BuildHAT bootloader version 1631704133 2021-09-15T12:08:53+01:00
Commands available:
help, ? : display this text
version : display version string
load <length> <checksum> : initiate upload
followed by <STX><<length> data bytes><ETX>
signature <length> : upload signature
followed by <STX><<length> data bytes><ETX>
clear : clear any uploaded image
verify : verify upload
reboot
"Timed out waiting for data".
What am I doing wrong? Should the data be send as HEX, are the STX/ETX commands wrong? What is checksum and what is signature? The latter was in a 64 byte file.
This might clearify things: under Python the firmware is uploaded with this code I believe:
Code: Select all
def loadfirmware(self, firmware, signature):
"""Load firmware
:param firmware: Firmware to load
:param signature: Signature to load
"""
with open(firmware, "rb") as f:
firm = f.read()
with open(signature, "rb") as f:
sig = f.read()
self.write(b"clear\r")
self.getprompt()
self.write(f"load {len(firm)} {self.checksum(firm)}\r".encode())
time.sleep(0.1)
self.write(b"\x02", replace="0x02")
self.write(firm, replace="--firmware file--")
self.write(b"\x03\r", replace="0x03")
self.getprompt()
self.write(f"signature {len(sig)}\r".encode())
time.sleep(0.1)
self.write(b"\x02", replace="0x02")
self.write(sig, replace="--signature file--")
self.write(b"\x03\r", replace="0x03")
self.getprompt()