From 888395d496b52b6114e4aefafacb1451780d43a9 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 11 Dec 2019 14:58:50 -0500 Subject: [PATCH] tools: replace tools for old shell with tools for new shell ref #80 --- tools/.gitignore | 6 ++-- tools/Makefile | 6 ++-- tools/blkdump.py | 59 ---------------------------------- tools/memdump.py | 66 ------------------------------------- tools/upload.py | 84 ------------------------------------------------ 5 files changed, 6 insertions(+), 215 deletions(-) delete mode 100755 tools/blkdump.py delete mode 100755 tools/memdump.py delete mode 100755 tools/upload.py diff --git a/tools/.gitignore b/tools/.gitignore index 1bb6708..41f9626 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -1,4 +1,4 @@ *.o -/memdumpb -/blkdumpb -/uploadb +/memdump +/blkdump +/upload diff --git a/tools/Makefile b/tools/Makefile index 0d05b18..7bbe9f6 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,8 +1,8 @@ -MEMDUMP_TGT = memdumpb +MEMDUMP_TGT = memdump MEMDUMP_SRC = memdump.c -BLKDUMP_TGT = blkdumpb +BLKDUMP_TGT = blkdump BLKDUMP_SRC = blkdump.c -UPLOAD_TGT = uploadb +UPLOAD_TGT = upload UPLOAD_SRC = upload.c TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) OBJS = common.o diff --git a/tools/blkdump.py b/tools/blkdump.py deleted file mode 100755 index dcf5bf3..0000000 --- a/tools/blkdump.py +++ /dev/null @@ -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()) - diff --git a/tools/memdump.py b/tools/memdump.py deleted file mode 100755 index 7f9aa1c..0000000 --- a/tools/memdump.py +++ /dev/null @@ -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()) - diff --git a/tools/upload.py b/tools/upload.py deleted file mode 100755 index 7f59210..0000000 --- a/tools/upload.py +++ /dev/null @@ -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())