annotate loadtools/romload.c @ 868:f6c379f0cbbe

ringtools/examples: move the old BU "melodies" into old subdir
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 28 Mar 2022 05:53:58 +0000
parents ecea01f65146
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the communication protocol for pushing our
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * IRAM-loadable code to the Calypso ROM bootloader.
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/ioctl.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/time.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/errno.h>
663
46d7ed4ee634 loadtools/romload.c: isprint() was used without <ctype.h>
Mychaela Falconia <falcon@freecalypso.org>
parents: 636
diff changeset
10 #include <ctype.h>
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdint.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdio.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <strings.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <termios.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <unistd.h>
250
8c011177adb9 loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
17 #include "../libserial/baudrate.h"
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "srecreader.h"
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern int errno;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern char *target_ttydev;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern int target_fd;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern struct baudrate baud_rate_table[];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern struct baudrate *find_baudrate_by_name();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 struct srecreader iramimage;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 struct baudrate *romload_baud_rate = baud_rate_table; /* 1st entry default */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static int beacon_interval = 13; /* in milliseconds */
683
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
31 static int beacon_timeout; /* ditto */
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 static u_char beacon_cmd[2] = {'<', 'i'};
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 static u_char param_cmd[11] = {'<', 'p',
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 0x00, /* baud rate select code (115200) */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 0x00, /* DPLL setup: leave it off like on power-up, */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /* OsmocomBB does the same thing */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 0x00, 0x04, /* chip select timing (WS) settings */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 /* our setting matches both OsmocomBB */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 /* and what the ROM runs with */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 /* before receiving this command */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 0x22, /* FFFF:F900 register config, low byte */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 /* OsmocomBB sends 0x00 here, but I've chosen */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 /* 0x22 to match the setting of this register */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 /* used by the boot ROM before this command. */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 0x00, 0x01, 0xD4, 0xC0 /* UART timeout */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 /* I've chosen the same value as what the */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 /* boot ROM runs with before getting this cmd */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 };
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
636
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
52 static u_char write_cmd[1024] = {'<', 'w', 0x01, 0x01};
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
53 static u_char cksum_cmd[3] = {'<', 'c'};
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
54 static u_char branch_cmd[6] = {'<', 'b'};
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
55
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
56 static uint32_t write_cmd_endaddr;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
57 static unsigned write_cmd_datalen;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
58 static unsigned write_block_count;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
59 static uint16_t image_cksum;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
60
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
61 #define MAX_WRITE_LEN 0x3F6
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 #define INTERMEDIATE_TIMEOUT 500 /* ms to wait for responses */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 #define SERIAL_FLUSH_DELAY 200 /* also in ms */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 /*
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 * The following function should be called by command line option
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 * parsers upon encountering the -i option.
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 set_beacon_interval(arg)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 char *arg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 int i;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 i = atoi(arg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (i < 2 || i > 500) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fprintf(stderr, "invalid -i argument specified\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 beacon_interval = i;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 /*
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 * The following function should be called by command line option
683
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
85 * parsers upon encountering the -t option.
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
86 */
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
87 set_romload_timeout(arg)
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
88 char *arg;
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
89 {
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
90 beacon_timeout = atoi(arg);
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
91 }
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
92
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
93 /*
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
94 * The following function should be called by command line option
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 * parsers upon encountering the -b option.
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 set_romload_baudrate(arg)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 char *arg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 struct baudrate *br;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 br = find_baudrate_by_name(arg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 if (!br)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 exit(1); /* error msg already printed */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 if (br->bootrom_code < 0) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 "baud rate of %s is not supported by the Calypso boot ROM\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 br->name);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 romload_baud_rate = br;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 /*
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 * The following functions alter some of the parameters sent to the
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 * boot ROM in the <p command.
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 set_romload_pll_conf(byte)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 param_cmd[3] = byte;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 set_romload_rhea_cntl(byte)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 param_cmd[6] = byte;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 static int
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 expect_response(timeout)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 char buf[2];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 fd_set fds;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 struct timeval tv;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 int pass, cc;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 for (pass = 0; pass < 2; ) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 FD_ZERO(&fds);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 FD_SET(target_fd, &fds);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 tv.tv_sec = 0;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 tv.tv_usec = timeout * 1000;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 cc = select(target_fd+1, &fds, NULL, NULL, &tv);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (cc < 0) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 if (errno == EINTR)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 perror("select");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 if (cc < 1)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 cc = read(target_fd, buf + pass, 2 - pass);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 if (cc <= 0) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 perror("read after successful select");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 if (pass == 0 && buf[0] != '>')
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 pass += cc;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 return(buf[1]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 static
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 send_beacons()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 {
683
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
165 int time_accum;
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
166
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 printf("Sending beacons to %s\n", target_ttydev);
683
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
168 for (time_accum = 0; ; ) {
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 write(target_fd, beacon_cmd, sizeof beacon_cmd);
683
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
170 if (expect_response(beacon_interval) == 'i')
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
171 return 0;
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
172 time_accum += beacon_interval;
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
173 if (beacon_timeout && time_accum >= beacon_timeout) {
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
174 fprintf(stderr,
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
175 "Timeout waiting for boot ROM response\n");
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
176 exit(1);
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
177 }
ecea01f65146 loadtools: implemented -t option for boot ROM wait timeout
Mychaela Falconia <falcon@freecalypso.org>
parents: 663
diff changeset
178 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180
633
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
181 static int
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
182 expect_add_response(buf, expect_bytes, timeout)
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
183 u_char *buf;
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
184 {
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
185 fd_set fds;
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
186 struct timeval tv;
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
187 int pass, cc;
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
188
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
189 for (pass = 0; pass < expect_bytes; ) {
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
190 FD_ZERO(&fds);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
191 FD_SET(target_fd, &fds);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
192 tv.tv_sec = 0;
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
193 tv.tv_usec = timeout * 1000;
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
194 cc = select(target_fd+1, &fds, NULL, NULL, &tv);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
195 if (cc < 0) {
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
196 if (errno == EINTR)
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
197 continue;
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
198 perror("select");
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
199 exit(1);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
200 }
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
201 if (cc < 1)
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
202 return(-1);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
203 cc = read(target_fd, buf + pass, expect_bytes - pass);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
204 if (cc <= 0) {
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
205 perror("read after successful select");
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
206 exit(1);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
207 }
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
208 pass += cc;
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
209 }
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
210 return(0);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
211 }
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
212
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 static uint32_t
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 compute_block_cksum()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 uint32_t sum;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 int i, llen;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218
636
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
219 sum = write_cmd_datalen + 5;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
220 llen = write_cmd_datalen + 4;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 for (i = 0; i < llen; i++)
636
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
222 sum += write_cmd[i+6];
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 return sum;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225
636
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
226 static void
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
227 send_write_cmd()
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
228 {
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
229 int resp;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
230
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
231 write_cmd[4] = write_cmd_datalen >> 8;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
232 write_cmd[5] = write_cmd_datalen & 0xFF;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
233 write(target_fd, write_cmd, write_cmd_datalen + 10);
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
234 /* update our checksum accumulator */
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
235 image_cksum += ~compute_block_cksum() & 0xFF;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
236 /* collect response */
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
237 resp = expect_response(INTERMEDIATE_TIMEOUT);
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
238 if (resp != 'w') {
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
239 fprintf(stderr, "Block #%lu: ", write_block_count);
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
240 if (resp < 0)
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
241 fprintf(stderr, "No response to <w command\n");
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
242 else if (isprint(resp))
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
243 fprintf(stderr,
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
244 "Got >%c in response to <w command; expected >w\n",
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
245 resp);
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
246 else
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
247 fprintf(stderr,
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
248 "Got > %02X in response to <w command; expected >w\n",
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
249 resp);
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
250 exit(1);
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
251 }
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
252 putchar('.');
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
253 fflush(stdout);
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
254 write_block_count++;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
255 }
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
256
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 perform_romload()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 int resp;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 unsigned long rec_count;
633
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
261 u_char addresp[2];
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 static int zero = 0;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 if (open_srec_file(&iramimage) < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 exit(1);
250
8c011177adb9 loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
266 set_fixed_baudrate("19200");
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 ioctl(target_fd, FIONBIO, &zero);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 send_beacons();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 printf("Got beacon response, attempting download\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 usleep(SERIAL_FLUSH_DELAY * 1000);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 tcflush(target_fd, TCIFLUSH);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 param_cmd[2] = romload_baud_rate->bootrom_code;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 write(target_fd, param_cmd, sizeof param_cmd);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 resp = expect_response(INTERMEDIATE_TIMEOUT);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 if (resp != 'p') {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 if (resp < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 fprintf(stderr, "No response to <p command\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 else if (isprint(resp))
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 "Got >%c in response to <p command; expected >p\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 resp);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 else
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 "Got > %02X in response to <p command; expected >p\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 resp);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 }
633
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
289 resp = expect_add_response(addresp, 2, INTERMEDIATE_TIMEOUT);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
290 if (resp < 0 || addresp[0] != 0x00 || addresp[1] != 0x04) {
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
291 fprintf(stderr,
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
292 "error: extra bytes after >p not received as expected\n");
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
293 exit(1);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
294 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 printf("<p command successful, switching to %s baud\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 romload_baud_rate->name);
250
8c011177adb9 loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
297 set_serial_baudrate(romload_baud_rate);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 usleep(SERIAL_FLUSH_DELAY * 1000);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 tcflush(target_fd, TCIFLUSH);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300
636
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
301 write_cmd_datalen = 0;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
302 write_block_count = 0;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 image_cksum = 0;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 for (rec_count = 0; ; ) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 if (read_s_record(&iramimage) < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 switch (iramimage.record_type) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 case '0':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 if (iramimage.lineno == 1)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 "%s: S0 record found in line %d (expected in line 1 only)\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 iramimage.filename, iramimage.lineno);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 case '3':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 case '7':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 if (s3s7_get_addr_data(&iramimage) < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 break;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 default:
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 "%s line %d: S%c record type not supported\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 iramimage.filename, iramimage.lineno,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 iramimage.record_type);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 if (iramimage.record_type == '7')
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 break;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 /* must be S3 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 if (iramimage.datalen < 1) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 "%s line %d: S3 record has zero data length\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 iramimage.filename, iramimage.lineno);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 }
636
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
336 /* get to work */
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 if (!rec_count)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 printf("Sending image payload\n");
636
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
339 if (write_cmd_datalen &&
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
340 (iramimage.addr != write_cmd_endaddr ||
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
341 write_cmd_datalen + iramimage.datalen > MAX_WRITE_LEN)) {
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
342 send_write_cmd();
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
343 write_cmd_datalen = 0;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 }
636
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
345 if (!write_cmd_datalen) {
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
346 bcopy(iramimage.record + 1, write_cmd + 6, 4);
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
347 write_cmd_endaddr = iramimage.addr;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
348 }
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
349 bcopy(iramimage.record + 5, write_cmd + 10 + write_cmd_datalen,
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
350 iramimage.datalen);
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
351 write_cmd_endaddr += iramimage.datalen;
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
352 write_cmd_datalen += iramimage.datalen;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 rec_count++;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 /* got S7 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 fclose(iramimage.openfile);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 if (!rec_count) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 "%s line %d: S7 without any preceding S3 data records\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 iramimage.filename, iramimage.lineno);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 }
636
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
363 send_write_cmd(); /* last block */
3172e3111ab7 loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents: 633
diff changeset
364 putchar('\n'); /* end line of dots */
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 /* send <c */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 printf("Sending checksum\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368 cksum_cmd[2] = ~image_cksum & 0xFF;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 write(target_fd, cksum_cmd, sizeof cksum_cmd);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370 resp = expect_response(INTERMEDIATE_TIMEOUT);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 if (resp != 'c') {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 if (resp < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 fprintf(stderr, "No response to <c command\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374 else if (isprint(resp))
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 "Got >%c in response to <c command; expected >c\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 resp);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 else
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 "Got > %02X in response to <c command; expected >c\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381 resp);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
382 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
383 }
633
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
384 resp = expect_add_response(addresp, 1, INTERMEDIATE_TIMEOUT);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
385 if (resp < 0) {
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
386 fprintf(stderr,
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
387 "error: extra byte after >c not received as expected\n");
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
388 exit(1);
4dca8542f569 loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents: 574
diff changeset
389 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390 printf("<c command successful, sending <b\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
391
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392 bcopy(iramimage.record + 1, branch_cmd + 2, 4);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393 write(target_fd, branch_cmd, sizeof branch_cmd);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394 resp = expect_response(INTERMEDIATE_TIMEOUT);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
395 if (resp != 'b') {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
396 if (resp < 0)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
397 fprintf(stderr, "No response to <b command\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398 else if (isprint(resp))
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
399 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
400 "Got >%c in response to <b command; expected >b\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
401 resp);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
402 else
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
403 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
404 "Got > %02X in response to <b command; expected >b\n",
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
405 resp);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
406 exit(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
407 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
408 printf("<b command successful: downloaded image should now be running!\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
409 return(0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
410 }