tools: replace tools for old shell with tools for new shell

ref #80
This commit is contained in:
Virgil Dupras 2019-12-11 14:58:50 -05:00
parent 1710c865dc
commit 888395d496
5 changed files with 6 additions and 215 deletions

6
tools/.gitignore vendored
View File

@ -1,4 +1,4 @@
*.o *.o
/memdumpb /memdump
/blkdumpb /blkdump
/uploadb /upload

View File

@ -1,8 +1,8 @@
MEMDUMP_TGT = memdumpb MEMDUMP_TGT = memdump
MEMDUMP_SRC = memdump.c MEMDUMP_SRC = memdump.c
BLKDUMP_TGT = blkdumpb BLKDUMP_TGT = blkdump
BLKDUMP_SRC = blkdump.c BLKDUMP_SRC = blkdump.c
UPLOAD_TGT = uploadb UPLOAD_TGT = upload
UPLOAD_SRC = upload.c UPLOAD_SRC = upload.c
TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT)
OBJS = common.o OBJS = common.o

View File

@ -1,59 +0,0 @@
#!/usr/bin/env python3
# Read specified number of bytes in specified blkdev ID and spit it to stdout.
# The proper blkdev has to be selected and placed already.
import argparse
import os
import sys
import time
# Some place where it's safe to write 0xff bytes.
MEMPTR = '9000'
def sendcmd(fd, cmd):
# The serial link echoes back all typed characters and expects us to read
# them. We have to send each char one at a time.
print("Executing {}".format(cmd.decode()), file=sys.stderr)
for c in cmd:
os.write(fd, bytes([c]))
os.read(fd, 1)
os.write(fd, b'\n')
os.read(fd, 2) # sends back \r\n
def main():
parser = argparse.ArgumentParser()
parser.add_argument('device')
parser.add_argument('bytecount')
args = parser.parse_args()
try:
bytecount = int(args.bytecount, 16)
except ValueError:
print("bytecount has to be hexadecimal without prefix.")
return 1
fd = os.open(args.device, os.O_RDWR)
sendcmd(fd, 'mptr {}'.format(MEMPTR).encode())
os.read(fd, 9)
while bytecount > 0:
toread = min(bytecount, 0x100)
sendcmd(fd, 'load {:x}'.format(toread & 0xff).encode())
os.read(fd, 5)
sendcmd(fd, 'peek {:x}'.format(toread & 0xff).encode())
peek = b''
while len(peek) < toread * 2:
peek += os.read(fd, 1)
time.sleep(0.0001)
os.read(fd, 5)
while peek:
c = peek[:2]
sys.stdout.buffer.write(bytes([int(c, 16)]))
peek = peek[2:]
bytecount -= toread
os.close(fd)
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,66 +0,0 @@
#!/usr/bin/env python3
# Read specified number of bytes at specified memory address and dump it to
# stdout.
import argparse
import os
import sys
import time
def sendcmd(fd, cmd):
# The serial link echoes back all typed characters and expects us to read
# them. We have to send each char one at a time.
for c in cmd:
os.write(fd, bytes([c]))
os.read(fd, 1)
os.write(fd, b'\n')
os.read(fd, 2) # sends back \r\n
def main():
parser = argparse.ArgumentParser()
parser.add_argument('device')
parser.add_argument('memptr')
parser.add_argument('bytecount')
args = parser.parse_args()
try:
memptr = int('0x' + args.memptr, 0)
except ValueError:
print("memptr are has to be hexadecimal without prefix.")
return 1
try:
bytecount = int('0x' + args.bytecount, 0)
except ValueError:
print("bytecount are has to be hexadecimal without prefix.")
return 1
if memptr >= 0x10000:
print("memptr out of range.")
return 1
if bytecount + memptr >= 0x10000:
print("Bytecount too big.")
return 1
fd = os.open(args.device, os.O_RDWR)
while bytecount > 0:
sendcmd(fd, 'mptr {:04x}'.format(memptr).encode())
os.read(fd, 9)
toread = min(bytecount, 0xff)
sendcmd(fd, 'peek {:x}'.format(toread).encode())
peek = b''
while len(peek) < toread * 2:
peek += os.read(fd, 1)
time.sleep(0.0001)
os.read(fd, 5)
while peek:
c = peek[:2]
sys.stdout.buffer.write(bytes([int(c, 16)]))
peek = peek[2:]
memptr += toread
bytecount -= toread
os.close(fd)
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,84 +0,0 @@
#!/usr/bin/env python3
# Push specified file to specified device and verify that the contents is
# correct by sending a "peek" command afterwards and check the output. Errors
# out if the contents isn't the same. The parameter passed to the "peek"
# command is the length of the uploaded file.
import argparse
import os
import sys
import time
def sendcmd(fd, cmd):
# The serial link echoes back all typed characters and expects us to read
# them. We have to send each char one at a time.
print("Executing {}".format(cmd.decode()))
for c in cmd:
os.write(fd, bytes([c]))
os.read(fd, 1)
os.write(fd, b'\n')
os.read(fd, 2) # sends back \r\n
def main():
parser = argparse.ArgumentParser()
parser.add_argument('device')
parser.add_argument('memptr')
parser.add_argument('filename')
args = parser.parse_args()
try:
memptr = int('0x' + args.memptr, 0)
except ValueError:
print("memptr are has to be hexadecimal without prefix.")
return 1
if memptr >= 0x10000:
print("memptr out of range.")
return 1
maxsize = 0x10000 - memptr
st = os.stat(args.filename)
if st.st_size > maxsize:
print("File too big. 0x{:04x} bytes max".format(maxsize))
return 1
fd = os.open(args.device, os.O_RDWR)
with open(args.filename, 'rb') as fp:
while True:
fcontents = fp.read(0xff)
if not fcontents:
break
print("Seeking...")
sendcmd(fd, 'mptr {:04x}'.format(memptr).encode())
os.read(fd, 9)
sendcmd(fd, 'poke {:x}'.format(len(fcontents)).encode())
print("Poking...")
for c in fcontents:
os.write(fd, bytes([c]))
# Let's give the machine a bit of time to breathe. We ain't in a
# hurry now, are we?
time.sleep(0.0001)
print("Poked")
os.read(fd, 5)
print("Peeking back...")
sendcmd(fd, 'peek {:x}'.format(len(fcontents)).encode())
peek = b''
while len(peek) < len(fcontents) * 2:
peek += os.read(fd, 1)
time.sleep(0.0001)
os.read(fd, 5)
print("Got {}".format(peek.decode()))
print("Comparing...")
for i, c in enumerate(fcontents):
hexfmt = '{:02X}'.format(c).encode()
if hexfmt != peek[:2]:
print("Mismatch at byte {}! {} != {}".format(i, peek[:2], hexfmt))
return 1
peek = peek[2:]
print("All good!")
memptr += len(fcontents)
print("Done!")
os.close(fd)
return 0
if __name__ == '__main__':
sys.exit(main())