tools: add blkdumpb
This commit is contained in:
parent
9ec71ecfee
commit
b40b39f45c
1
tools/.gitignore
vendored
1
tools/.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.o
|
||||
/memdumpb
|
||||
/blkdumpb
|
||||
/uploadb
|
||||
|
@ -1,8 +1,10 @@
|
||||
MEMDUMP_TGT = memdumpb
|
||||
MEMDUMP_SRC = memdump.c
|
||||
BLKDUMP_TGT = blkdumpb
|
||||
BLKDUMP_SRC = blkdump.c
|
||||
UPLOAD_TGT = uploadb
|
||||
UPLOAD_SRC = upload.c
|
||||
TARGETS = $(MEMDUMP_TGT) $(UPLOAD_TGT)
|
||||
TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT)
|
||||
OBJS = common.o
|
||||
|
||||
all: $(TARGETS)
|
||||
@ -14,6 +16,9 @@ all: $(TARGETS)
|
||||
$(MEMDUMP_TGT): $(MEMDUMP_SRC) $(OBJS)
|
||||
$(CC) $(CFLAGS) $(MEMDUMP_SRC) $(OBJS) -o $@
|
||||
|
||||
$(BLKDUMP_TGT): $(BLKDUMP_SRC) $(OBJS)
|
||||
$(CC) $(CFLAGS) $(BLKDUMP_SRC) $(OBJS) -o $@
|
||||
|
||||
$(UPLOAD_TGT): $(UPLOAD_SRC) $(OBJS)
|
||||
$(CC) $(CFLAGS) $(UPLOAD_SRC) $(OBJS) -o $@
|
||||
|
||||
|
37
tools/blkdump.c
Normal file
37
tools/blkdump.c
Normal file
@ -0,0 +1,37 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/* Read specified number of bytes in active blkdev at active offset.
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: ./memdump device bytecount\n");
|
||||
return 1;
|
||||
}
|
||||
unsigned int bytecount = strtol(argv[2], NULL, 16);
|
||||
if (!bytecount) {
|
||||
// nothing to spit
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = open(argv[1], O_RDWR|O_NOCTTY);
|
||||
char s[3];
|
||||
for (int i=0; i<bytecount; i++) {
|
||||
sendcmd(fd, "getb");
|
||||
read(fd, s, 2); // read prompt
|
||||
sendcmd(fd, "puth a");
|
||||
read(fd, s, 2); // read hex pair
|
||||
s[2] = 0; // null terminate
|
||||
unsigned char c = strtol(s, NULL, 16);
|
||||
putchar(c);
|
||||
read(fd, s, 2); // read prompt
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user