annotate loadtools/romload.c @ 265:4c416868524a

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