3
* Murray Jensen <Murray.Jensen@csiro.au>
5
* SPDX-License-Identifier: GPL-2.0+
13
#include <sys/types.h>
19
char *serialdev = "/dev/term/b";
20
speed_t speed = B230400;
21
int verbose = 0, docont = 0;
22
unsigned long addr = 0x10000UL;
25
main(int ac, char **av)
31
if ((pname = strrchr(av[0], '/')) == NULL)
36
while ((c = getopt(ac, av, "a:b:cp:v")) != EOF)
42
addr = strtol(optarg, &ep, 0);
43
if (ep == optarg || *ep != '\0')
44
Error("can't decode address specified in -a option");
49
if ((speed = cvtspeed(optarg)) == B0)
50
Error("can't decode baud rate specified in -b option");
68
"Usage: %s [-a addr] [-b bps] [-c] [-p dev] [-v] imagefile\n",
78
fprintf(stderr, "Opening file and reading image...\n");
80
if ((ifd = open(ifn, O_RDONLY)) < 0)
81
Perror("can't open kernel image file '%s'", ifn);
83
if (fstat(ifd, &ist) < 0)
84
Perror("fstat '%s' failed", ifn);
86
if ((image = (char *)malloc(ist.st_size)) == NULL)
87
Perror("can't allocate %ld bytes for image", ist.st_size);
89
if ((c = read(ifd, image, ist.st_size)) < 0)
90
Perror("read of %d bytes from '%s' failed", ist.st_size, ifn);
93
Error("read of %ld bytes from '%s' failed (%d)", ist.st_size, ifn, c);
96
Perror("close of '%s' failed", ifn);
99
fprintf(stderr, "Opening serial port and sending image...\n");
101
if ((sfd = serialopen(serialdev, speed)) < 0)
102
Perror("open of serial device '%s' failed", serialdev);
106
remote_write_bytes(addr, image, ist.st_size);
110
fprintf(stderr, "[continue]");
114
if (serialclose(sfd) < 0)
115
Perror("close of serial device '%s' failed", serialdev);
118
fprintf(stderr, "Done.\n");