3 * Murray Jensen <Murray.Jensen@csiro.au>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <sys/types.h>
35 char *serialdev = "/dev/term/b";
36 speed_t speed = B230400;
37 int verbose = 0, docont = 0;
38 unsigned long addr = 0x10000UL;
41 main(int ac, char **av)
47 if ((pname = strrchr(av[0], '/')) == NULL)
52 while ((c = getopt(ac, av, "a:b:cp:v")) != EOF)
58 addr = strtol(optarg, &ep, 0);
59 if (ep == optarg || *ep != '\0')
60 Error("can't decode address specified in -a option");
65 if ((speed = cvtspeed(optarg)) == B0)
66 Error("can't decode baud rate specified in -b option");
84 "Usage: %s [-a addr] [-b bps] [-c] [-p dev] [-v] imagefile\n",
94 fprintf(stderr, "Opening file and reading image...\n");
96 if ((ifd = open(ifn, O_RDONLY)) < 0)
97 Perror("can't open kernel image file '%s'", ifn);
99 if (fstat(ifd, &ist) < 0)
100 Perror("fstat '%s' failed", ifn);
102 if ((image = (char *)malloc(ist.st_size)) == NULL)
103 Perror("can't allocate %ld bytes for image", ist.st_size);
105 if ((c = read(ifd, image, ist.st_size)) < 0)
106 Perror("read of %d bytes from '%s' failed", ist.st_size, ifn);
108 if (c != ist.st_size)
109 Error("read of %ld bytes from '%s' failed (%d)", ist.st_size, ifn, c);
112 Perror("close of '%s' failed", ifn);
115 fprintf(stderr, "Opening serial port and sending image...\n");
117 if ((sfd = serialopen(serialdev, speed)) < 0)
118 Perror("open of serial device '%s' failed", serialdev);
122 remote_write_bytes(addr, image, ist.st_size);
126 fprintf(stderr, "[continue]");
130 if (serialclose(sfd) < 0)
131 Perror("close of serial device '%s' failed", serialdev);
134 fprintf(stderr, "Done.\n");