FreeCalypso > hg > freecalypso-sw
annotate loadtools/romload.c @ 50:f1df95eed62c
loadtools: -b option works in fc-iram
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Jun 2013 03:32:04 +0000 |
parents | 54392d1ea474 |
children | ccc5161848c7 |
rev | line source |
---|---|
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module implements the communication protocol for pushing our |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * IRAM-loadable code to the Calypso ROM bootloader. |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/types.h> |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <sys/ioctl.h> |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <sys/time.h> |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <sys/errno.h> |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <stdint.h> |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <stdio.h> |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <stdlib.h> |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include <strings.h> |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include <termios.h> |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include <unistd.h> |
49
54392d1ea474
loadtools: first beginnings for the baud rate switching logic
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
17
diff
changeset
|
16 #include "baudrate.h" |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #include "srecreader.h" |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 extern int errno; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 extern char *target_ttydev; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 extern int target_fd; |
49
54392d1ea474
loadtools: first beginnings for the baud rate switching logic
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
17
diff
changeset
|
23 extern struct baudrate baud_rate_table[]; |
50
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
24 extern struct baudrate *find_baudrate_by_name(); |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 struct srecreader iramimage; |
49
54392d1ea474
loadtools: first beginnings for the baud rate switching logic
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
17
diff
changeset
|
27 struct baudrate *romload_baud_rate = baud_rate_table; /* 1st entry default */ |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 static int beacon_interval = 13; /* in milliseconds */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 static u_char beacon_cmd[2] = {'<', 'i'}; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 static u_char param_cmd[11] = {'<', 'p', |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 0x00, /* baud rate select code (115200) */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 0x00, /* DPLL setup: leave it off like on power-up, */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 /* OsmocomBB does the same thing */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 0x00, 0x04, /* chip select timing (WS) settings */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 /* our setting matches both OsmocomBB */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 /* and what the ROM runs with */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 /* before receiving this command */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 0x22, /* FFFF:F900 register config, low byte */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 /* OsmocomBB sends 0x00 here, but I've chosen */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 /* 0x22 to match the setting of this register */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 /* used by the boot ROM before this command. */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 0x00, 0x01, 0xD4, 0xC0 /* UART timeout */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 /* I've chosen the same value as what the */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 /* boot ROM runs with before getting this cmd */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 }; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 static u_char write_cmd[10] = {'<', 'w', 0x01, 0x01, 0x00}; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 static u_char cksum_cmd[3] = {'<', 'c'}; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 static u_char branch_cmd[6] = {'<', 'b'}; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 #define INTERMEDIATE_TIMEOUT 500 /* ms to wait for responses */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 #define SERIAL_FLUSH_DELAY 200 /* also in ms */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 /* |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 * The following function should be called by command line option |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 * parsers upon encountering the -i option. |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 set_beacon_interval(arg) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 char *arg; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 int i; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 i = atoi(arg); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 if (i < 2 || i > 500) { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 fprintf(stderr, "invalid -i argument specified\n"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 beacon_interval = i; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 |
17
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
74 /* |
50
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
75 * The following function should be called by command line option |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
76 * parsers upon encountering the -b option. |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
77 */ |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
78 set_romload_baudrate(arg) |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
79 char *arg; |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
80 { |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
81 struct baudrate *br; |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
82 |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
83 br = find_baudrate_by_name(arg); |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
84 if (!br) |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
85 exit(1); /* error msg already printed */ |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
86 if (br->bootrom_code < 0) { |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
87 fprintf(stderr, |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
88 "baud rate of %s is not supported by the Calypso boot ROM\n", |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
89 br->name); |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
90 exit(1); |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
91 } |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
92 romload_baud_rate = br; |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
93 } |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
94 |
f1df95eed62c
loadtools: -b option works in fc-iram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
49
diff
changeset
|
95 /* |
17
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
96 * The following functions alter some of the parameters sent to the |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
97 * boot ROM in the <p command. |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
98 */ |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
99 set_romload_pll_conf(byte) |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
100 { |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
101 param_cmd[3] = byte; |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
102 } |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
103 |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
104 set_romload_rhea_cntl(byte) |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
105 { |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
106 param_cmd[6] = byte; |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
107 } |
24b88c119465
loadtools: hw parameter file reading implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
10
diff
changeset
|
108 |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 static int |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 expect_response(timeout) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 char buf[2]; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 fd_set fds; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 struct timeval tv; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 int pass, cc; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 for (pass = 0; pass < 2; ) { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 FD_ZERO(&fds); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 FD_SET(target_fd, &fds); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 tv.tv_sec = 0; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 tv.tv_usec = timeout * 1000; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 cc = select(target_fd+1, &fds, NULL, NULL, &tv); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 if (cc < 0) { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 if (errno == EINTR) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 continue; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 perror("select"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 if (cc < 1) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 return(-1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 cc = read(target_fd, buf + pass, 2 - pass); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 if (cc <= 0) { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
133 perror("read after successful select"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 if (pass == 0 && buf[0] != '>') |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 continue; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 pass += cc; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 return(buf[1]); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 static |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 send_beacons() |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 printf("Sending beacons to %s\n", target_ttydev); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 do |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 write(target_fd, beacon_cmd, sizeof beacon_cmd); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 while (expect_response(beacon_interval) != 'i'); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 return 0; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 static uint32_t |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 compute_block_cksum() |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 uint32_t sum; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 int i, llen; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
159 sum = iramimage.datalen + 5; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 llen = iramimage.datalen + 4; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 for (i = 0; i < llen; i++) |
10
e2e80a09338e
fc-sertool actually works; output from loadagent is visible!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
9
diff
changeset
|
162 sum += iramimage.record[i+1]; |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 return sum; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 perform_romload() |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
167 { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
168 int resp; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 uint16_t image_cksum; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
170 unsigned long rec_count; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 static int zero = 0; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
173 if (open_srec_file(&iramimage) < 0) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
174 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
175 ioctl(target_fd, FIONBIO, &zero); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
176 send_beacons(); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 printf("Got beacon response, attempting download\n"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
178 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
179 usleep(SERIAL_FLUSH_DELAY * 1000); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
180 tcflush(target_fd, TCIFLUSH); |
49
54392d1ea474
loadtools: first beginnings for the baud rate switching logic
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
17
diff
changeset
|
181 param_cmd[2] = romload_baud_rate->bootrom_code; |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
182 write(target_fd, param_cmd, sizeof param_cmd); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 resp = expect_response(INTERMEDIATE_TIMEOUT); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
184 if (resp != 'p') { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
185 if (resp < 0) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
186 fprintf(stderr, "No response to <p command\n"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
187 else if (isprint(resp)) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
188 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
189 "Got >%c in response to <p command; expected >p\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
190 resp); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
191 else |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
192 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
193 "Got > %02X in response to <p command; expected >p\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
194 resp); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
195 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 } |
49
54392d1ea474
loadtools: first beginnings for the baud rate switching logic
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
17
diff
changeset
|
197 printf("<p command successful, switching to %s baud\n", |
54392d1ea474
loadtools: first beginnings for the baud rate switching logic
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
17
diff
changeset
|
198 romload_baud_rate->name); |
54392d1ea474
loadtools: first beginnings for the baud rate switching logic
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
17
diff
changeset
|
199 switch_baud_rate(romload_baud_rate); |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
200 usleep(SERIAL_FLUSH_DELAY * 1000); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
201 tcflush(target_fd, TCIFLUSH); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
202 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
203 image_cksum = 0; |
10
e2e80a09338e
fc-sertool actually works; output from loadagent is visible!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
9
diff
changeset
|
204 for (rec_count = 0; ; ) { |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
205 if (read_s_record(&iramimage) < 0) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
206 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
207 switch (iramimage.record_type) { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
208 case '0': |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
209 if (iramimage.lineno == 1) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
210 continue; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
211 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
212 "%s: S0 record found in line %d (expected in line 1 only)\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
213 iramimage.filename, iramimage.lineno); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
214 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
215 case '3': |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
216 case '7': |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
217 if (s3s7_get_addr_data(&iramimage) < 0) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
218 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
219 break; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
220 default: |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
221 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
222 "%s line %d: S%c record type not supported\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
223 iramimage.filename, iramimage.lineno, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
224 iramimage.record_type); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
225 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
226 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
227 if (iramimage.record_type == '7') |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
228 break; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
229 /* must be S3 */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
230 if (iramimage.datalen < 1) { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
231 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
232 "%s line %d: S3 record has zero data length\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
233 iramimage.filename, iramimage.lineno); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
234 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
235 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
236 /* form <w command */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
237 if (!rec_count) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
238 printf("Sending image payload\n"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
239 write_cmd[5] = iramimage.datalen; |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
240 bcopy(iramimage.record + 1, write_cmd + 6, 4); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
241 write(target_fd, write_cmd, sizeof write_cmd); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
242 write(target_fd, iramimage.record + 5, iramimage.datalen); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
243 /* update our checksum accumulator */ |
10
e2e80a09338e
fc-sertool actually works; output from loadagent is visible!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
9
diff
changeset
|
244 image_cksum += ~compute_block_cksum() & 0xFF; |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
245 /* collect response */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
246 resp = expect_response(INTERMEDIATE_TIMEOUT); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
247 if (resp != 'w') { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
248 fprintf(stderr, "Block #%lu: ", rec_count); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
249 if (resp < 0) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
250 fprintf(stderr, "No response to <w command\n"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
251 else if (isprint(resp)) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
252 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
253 "Got >%c in response to <w command; expected >w\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
254 resp); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
255 else |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
256 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
257 "Got > %02X in response to <w command; expected >w\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
258 resp); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
259 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
260 } |
10
e2e80a09338e
fc-sertool actually works; output from loadagent is visible!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
9
diff
changeset
|
261 putchar('.'); |
e2e80a09338e
fc-sertool actually works; output from loadagent is visible!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
9
diff
changeset
|
262 fflush(stdout); |
e2e80a09338e
fc-sertool actually works; output from loadagent is visible!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
9
diff
changeset
|
263 rec_count++; |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
264 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
265 /* got S7 */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
266 fclose(iramimage.openfile); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
267 if (!rec_count) { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
268 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
269 "%s line %d: S7 without any preceding S3 data records\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
270 iramimage.filename, iramimage.lineno); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
271 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
272 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
273 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
274 /* send <c */ |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
275 printf("Sending checksum\n"); |
10
e2e80a09338e
fc-sertool actually works; output from loadagent is visible!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
9
diff
changeset
|
276 cksum_cmd[2] = ~image_cksum & 0xFF; |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
277 write(target_fd, cksum_cmd, sizeof cksum_cmd); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
278 resp = expect_response(INTERMEDIATE_TIMEOUT); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
279 if (resp != 'c') { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
280 if (resp < 0) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
281 fprintf(stderr, "No response to <c command\n"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
282 else if (isprint(resp)) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
283 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
284 "Got >%c in response to <c command; expected >c\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
285 resp); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
286 else |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
287 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
288 "Got > %02X in response to <c command; expected >c\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
289 resp); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
290 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
291 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
292 printf("<c command successful, sending <b\n"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
293 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
294 bcopy(iramimage.record + 1, branch_cmd + 2, 4); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
295 write(target_fd, branch_cmd, sizeof branch_cmd); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
296 resp = expect_response(INTERMEDIATE_TIMEOUT); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
297 if (resp != 'b') { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
298 if (resp < 0) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
299 fprintf(stderr, "No response to <b command\n"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
300 else if (isprint(resp)) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
301 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
302 "Got >%c in response to <b command; expected >b\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
303 resp); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
304 else |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
305 fprintf(stderr, |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
306 "Got > %02X in response to <b command; expected >b\n", |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
307 resp); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
308 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
309 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
310 printf("<b command successful: downloaded image should now be running!\n"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
311 return(0); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
312 } |