From 7344186c621014755c219e262b5db8730e15cb08 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 1 May 2020 14:39:13 -0400 Subject: [PATCH] tools: add blkup not actually tested yet... --- tools/Makefile | 6 ++++-- tools/common.c | 10 ++++++++-- tools/common.h | 1 + tools/upload.c | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index 69a0d59..94f9eab 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -8,9 +8,10 @@ BIN2C_TGT = bin2c EXEC_TGT = exec BLKPACK_TGT = blkpack BLKUNPACK_TGT = blkunpack +BLKUP_TGT = blkup TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \ - $(TTYSAFE_TGT) $(PINGPONG_TGT) \ - $(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT) $(BLKUNPACK_TGT) + $(TTYSAFE_TGT) $(PINGPONG_TGT) $(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT) \ + $(BLKUNPACK_TGT) $(BLKUP_TGT) OBJS = common.o all: $(TARGETS) @@ -29,6 +30,7 @@ $(BIN2C_TGT): $(BIN2C_TGT).c $(EXEC_TGT): $(EXEC_TGT).c $(BLKPACK_TGT): $(BLKPACK_TGT).c $(BLKUNPACK_TGT): $(BLKUNPACK_TGT).c +$(BLKUP_TGT): $(BLKUP_TGT).c $(TARGETS): $(OBJS) $(CC) $(CFLAGS) $@.c $(OBJS) -o $@ diff --git a/tools/common.c b/tools/common.c index d0979cf..0de4532 100644 --- a/tools/common.c +++ b/tools/common.c @@ -16,6 +16,12 @@ void mread(int fd, char *s, int count) } } +void readprompt(int fd) +{ + char junk[3]; + mread(fd, junk, 3); // " ok" prompt +} + void sendcmd(int fd, char *cmd) { char junk[2]; @@ -32,12 +38,12 @@ void sendcmd(int fd, char *cmd) usleep(1000); } -// Send a cmd and also read the "> " prompt +// Send a cmd and also read the " ok" prompt void sendcmdp(int fd, char *cmd) { char junk[2]; sendcmd(fd, cmd); - mread(fd, junk, 2); + readprompt(fd); } // from https://stackoverflow.com/a/6947758 diff --git a/tools/common.h b/tools/common.h index ea36a15..0c662b9 100644 --- a/tools/common.h +++ b/tools/common.h @@ -1,6 +1,7 @@ void sendcmd(int fd, char *cmd); void sendcmdp(int fd, char *cmd); void mread(int fd, char *s, int count); +void readprompt(int fd); int set_interface_attribs(int fd, int speed, int parity); void set_blocking(int fd, int should_block); diff --git a/tools/upload.c b/tools/upload.c index d0cac13..d4833a1 100644 --- a/tools/upload.c +++ b/tools/upload.c @@ -67,7 +67,7 @@ int main(int argc, char **argv) } usleep(1000); // let it breathe } - mread(fd, s, 2); // "> " prompt + readprompt(fd); sendcmdp(fd, "FORGET _"); printf("Done!\n"); fclose(fp);