Browse Source

support firmwareupdate

Olaf Rempel 12 years ago
parent
commit
779bfd51d3
4 changed files with 40 additions and 10 deletions
  1. 5
    0
      context.h
  2. 13
    3
      statemachine.c
  3. 2
    2
      xmodem.c
  4. 20
    5
      zyxel-revert.c

+ 5
- 0
context.h View File

@@ -5,6 +5,10 @@
5 5
 #include "linebuffer.h"
6 6
 #include "list.h"
7 7
 
8
+#define FLAG_CONFIG 0x01
9
+#define FLAG_FIRMWARE 0x02
10
+#define FLAG_SPEEDUP 0x04
11
+
8 12
 struct context {
9 13
 	struct list_head list;
10 14
 
@@ -20,6 +24,7 @@ struct context {
20 24
 
21 25
 	/* statemachine */
22 26
 	int state;
27
+	int flags;
23 28
 
24 29
 	/* line buffer */
25 30
 	struct linebuffer *lbuf;

+ 13
- 3
statemachine.c View File

@@ -75,13 +75,18 @@ int statemachine_read(int fd, void *privdata)
75 75
 		/* debug mode entered */
76 76
 		} else if (msg == MSG_DEBUG) {
77 77
 			/* if device supports it, switch to high baudrate */
78
-			if (ctx->dev_setbaudrate != NULL) {
78
+			if ((ctx->flags & FLAG_SPEEDUP) && ctx->dev_setbaudrate != NULL) {
79 79
 				ctx->state = STATE_SWITCH_BAUDRATE;
80 80
 				write(fd, "ATBA5\r\n", 7);
81 81
 
82 82
 			} else {
83 83
 				ctx->state = STATE_XMODEM;
84
-				write(fd, "ATLC\r\n", 6);
84
+
85
+				if (ctx->flags & FLAG_CONFIG)
86
+					write(fd, "ATLC\r\n", 6);
87
+
88
+				else if (ctx->flags & FLAG_FIRMWARE)
89
+					write(fd, "ATUR\r\n", 6);
85 90
 			}
86 91
 
87 92
 		/* follow device to high baudrate */
@@ -90,7 +95,12 @@ int statemachine_read(int fd, void *privdata)
90 95
 			linebuffer_clear(ctx->lbuf);
91 96
 
92 97
 			ctx->state = STATE_XMODEM;
93
-			write(fd, "ATLC\r\n", 6);
98
+
99
+			if (ctx->flags & FLAG_CONFIG)
100
+				write(fd, "ATLC\r\n", 6);
101
+
102
+			else if (ctx->flags & FLAG_FIRMWARE)
103
+				write(fd, "ATUR\r\n", 6);
94 104
 
95 105
 		/* transfer was success */
96 106
 		} else if (msg == MSG_XMODEM_OK && ctx->state == STATE_XMODEM_COMPLETE) {

+ 2
- 2
xmodem.c View File

@@ -62,12 +62,12 @@ int xmodem_read(int fd, void *privdata)
62 62
 
63 63
 	switch (pkt.header) {
64 64
 	case XM_C:	/* first packet */
65
-		log_print(LOG_DEBUG, "%s: XMODEM started", ctx->devname);
65
+		log_print(LOG_DEBUG, "%s: XMODEM started (%d bytes)", ctx->devname, ctx->file->size);
66 66
 		pktnum = 0;
67 67
 		break;
68 68
 
69 69
 	case XM_ACK:	/* next packet */
70
-		if (ctx->lastpkt * 128 == ctx->file->size)
70
+		if (ctx->lastpkt * 128 >= ctx->file->size)
71 71
 			return -1;
72 72
 
73 73
 		pktnum = ctx->lastpkt +1;

+ 20
- 5
zyxel-revert.c View File

@@ -10,31 +10,41 @@
10 10
 #include "serial.h"
11 11
 
12 12
 static struct option opts[] = {
13
+	{"config",	1, 0, 'c'},
13 14
 	{"device",	1, 0, 'd'},
14
-	{"device",	1, 0, 'f'},
15
+	{"firmware",	1, 0, 'f'},
16
+	{"slow",	0, 0, 's'},
15 17
 	{0, 0, 0, 0}
16 18
 };
17 19
 
18 20
 int main(int argc, char *argv[])
19 21
 {
20 22
 	char *devicename = NULL, *filename = NULL;
21
-	int code, arg = 0;
23
+	int code, arg = 0, flags = FLAG_SPEEDUP;
22 24
 
23 25
 	do {
24
-		code = getopt_long(argc, argv, "d:f:", opts, &arg);
26
+		code = getopt_long(argc, argv, "c:d:f:s", opts, &arg);
25 27
 
26 28
 		switch (code) {
29
+		case 'c':	filename = optarg;
30
+				flags |= FLAG_CONFIG;
31
+				break;
32
+
27 33
 		case 'd':	devicename = optarg;
28 34
 				break;
29 35
 
30 36
 		case 'f':	filename = optarg;
37
+				flags |= FLAG_FIRMWARE;
31 38
 				break;
32 39
 
33 40
 		case 'h':	/* help */
34
-				printf("Usage: zyxel-revert -d <device> -f <file>\n");
41
+				printf("Usage: zyxel-revert -d <device> [-s] [ -f <file> | -c <file> ]\n");
35 42
 				exit(0);
36 43
 				break;
37 44
 
45
+		case 's':	flags &= ~FLAG_SPEEDUP;
46
+				break;
47
+
38 48
 		case '?':	/* error */
39 49
 				exit(-1);
40 50
 				break;
@@ -44,11 +54,16 @@ int main(int argc, char *argv[])
44 54
 		}
45 55
 	} while (code != -1);
46 56
 
57
+	if (devicename == NULL || filename == NULL)
58
+		return -1;
59
+
47 60
 	struct context *ctx = create_context(filename);
48 61
 	if (ctx == NULL)
49 62
 		exit(1);
50 63
 
51
-	if (devicename == NULL || serial_init(ctx, devicename)) {
64
+	ctx->flags = flags;
65
+
66
+	if (serial_init(ctx, devicename)) {
52 67
 		context_close();
53 68
 		exit(1);
54 69
 	}

Loading…
Cancel
Save