Skip to content

Commit

Permalink
updated load script to send data in blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanseifert committed Nov 3, 2019
1 parent 023ffd3 commit 84f60b2
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions cpu-68008/bootrom/tools/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from termcolor import colored, cprint
import sys
import os
################################################################################
# block size
kBlockSize = 256

################################################################################
# waits for an acknowledge
Expand All @@ -31,26 +34,37 @@ def waitForAck(port):
print('usage: {exec} [binary path] [load address] [serial port] [baud rate]'.format(exec=sys.argv[0]))
sys.exit(-1)

# load the entire file into memory and pad it to multiples of 128 bytes
data = open(sys.argv[1], "rb").read()
data = bytearray(data)

numPadRequired = (kBlockSize - (len(data) % kBlockSize))

if numPadRequired is not 0 and numPadRequired is not kBlockSize:
for i in range(numPadRequired):
data.append(0)

cprint('• Added {added} bytes of padding to file'.format(added=numPadRequired), attrs=['bold'])
cprint('\tBlock size is {block}'.format(block=kBlockSize))


# get some infos
loadAddr = int(sys.argv[2], 0)
size = os.path.getsize(sys.argv[1])
size = len(data)

# calculate the checksum over the file
cprint('• Calculating file checksum', attrs=['bold'])

checksum = 0

with open(sys.argv[1], "rb") as f:
byte = f.read(1)
for byte in data:
# just sum all bytes up
checksum += byte

while byte:
# just sum all bytes up
checksum += ord(byte)
# read the next byte
byte = f.read(1)
cprint('\tChecksum: ${check:08x}'.format(check=checksum))

# open and configure the serial port with timeout of 1sec
port = serial.Serial(sys.argv[3], int(sys.argv[4]), timeout=1)
port = serial.Serial(sys.argv[3], int(sys.argv[4]), timeout=0.5)

# send the load address and wait for an ack
cprint('• Sending load address: ${addr:08x}'.format(addr=loadAddr), attrs=['bold'])
Expand All @@ -67,22 +81,17 @@ def waitForAck(port):
port.write('{size:08x}'.format(size=size).encode('ascii'))
waitForAck(port)

# then, send each byte of the file
# then, send each block of the file
cprint('• Sending payload', attrs=['bold'])
counter = 0

with progressbar.ProgressBar(max_value=size) as bar:
with open(sys.argv[1], "rb") as f:
byte = f.read(1)
counter = 0

while byte:
# send it and demand an ack
port.write('{data:02x}'.format(data=ord(byte)).encode('ascii'))
waitForAck(port)

# read the next byte
byte = f.read(1)

# update progress
counter += 1
bar.update(counter)
for blockOff in range(0, size, kBlockSize):
# get block of data, send it and wait for acknowledgement
block = data[blockOff:(blockOff+kBlockSize)]
port.write(bytes(block))
waitForAck(port)

# update the progress bar
counter += kBlockSize
bar.update(counter)

0 comments on commit 84f60b2

Please sign in to comment.