1 // SPDX-License-Identifier: GPL-2.0+
12 #include <sys/types.h>
18 char *serialdev = "/dev/term/b";
19 speed_t speed = B230400;
20 int verbose = 0, docont = 0;
21 unsigned long addr = 0x10000UL;
24 main(int ac, char **av)
30 if ((pname = strrchr(av[0], '/')) == NULL)
35 while ((c = getopt(ac, av, "a:b:cp:v")) != EOF)
41 addr = strtol(optarg, &ep, 0);
42 if (ep == optarg || *ep != '\0')
43 Error("can't decode address specified in -a option");
48 if ((speed = cvtspeed(optarg)) == B0)
49 Error("can't decode baud rate specified in -b option");
67 "Usage: %s [-a addr] [-b bps] [-c] [-p dev] [-v] imagefile\n",
77 fprintf(stderr, "Opening file and reading image...\n");
79 if ((ifd = open(ifn, O_RDONLY)) < 0)
80 Perror("can't open kernel image file '%s'", ifn);
82 if (fstat(ifd, &ist) < 0)
83 Perror("fstat '%s' failed", ifn);
85 if ((image = (char *)malloc(ist.st_size)) == NULL)
86 Perror("can't allocate %ld bytes for image", ist.st_size);
88 if ((c = read(ifd, image, ist.st_size)) < 0)
89 Perror("read of %d bytes from '%s' failed", ist.st_size, ifn);
92 Error("read of %ld bytes from '%s' failed (%d)", ist.st_size, ifn, c);
95 Perror("close of '%s' failed", ifn);
98 fprintf(stderr, "Opening serial port and sending image...\n");
100 if ((sfd = serialopen(serialdev, speed)) < 0)
101 Perror("open of serial device '%s' failed", serialdev);
105 remote_write_bytes(addr, image, ist.st_size);
109 fprintf(stderr, "[continue]");
113 if (serialclose(sfd) < 0)
114 Perror("close of serial device '%s' failed", serialdev);
117 fprintf(stderr, "Done.\n");