update_mks_robin: Add script to update firmware for MKS Robin bootloader

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-03-24 10:30:02 -04:00
parent 91a27ef083
commit 302cd38217
1 changed files with 38 additions and 0 deletions

38
scripts/update_mks_robin.py Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python2
# Script to update firmware for MKS Robin bootloader
#
# Copyright (C) 2020 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import os, optparse, sys
XOR_PATTERN = [
0xA3, 0xBD, 0xAD, 0x0D, 0x41, 0x11, 0xBB, 0x8D, 0xDC, 0x80,
0x2D, 0xD0, 0xD2, 0xC4, 0x9B, 0x1E, 0x26, 0xEB, 0xE3, 0x33,
0x4A, 0x15, 0xE4, 0x0A, 0xB3, 0xB1, 0x3C, 0x93, 0xBB, 0xAF,
0xF7, 0x3E
]
def main():
# Parse command-line arguments
usage = "%prog <input_file> <output_file>"
opts = optparse.OptionParser(usage)
options, args = opts.parse_args()
if len(args) != 2:
opts.error("Incorrect number of arguments")
infilename, outfilename = args
# Read input
f = open(infilename, "rb")
srcfirmware = f.read()
f.close()
# Update
firmware = bytearray(srcfirmware)
for pos in range(320, min(31040, len(firmware))):
firmware[pos] ^= XOR_PATTERN[pos & 31]
# Write output
f = open(outfilename, "wb")
f.write(firmware)
f.close()
if __name__ == '__main__':
main()