12 char *serialdev = "/dev/term/b";
13 speed_t speed = B230400;
14 int verbose = 0, docont = 0;
15 unsigned long addr = 0x10000UL;
18 main(int ac, char **av)
24 if ((pname = strrchr(av[0], '/')) == NULL)
29 while ((c = getopt(ac, av, "a:b:cp:v")) != EOF)
35 addr = strtol(optarg, &ep, 0);
36 if (ep == optarg || *ep != '\0')
37 Error("can't decode address specified in -a option");
42 if ((speed = cvtspeed(optarg)) == B0)
43 Error("can't decode baud rate specified in -b option");
61 "Usage: %s [-a addr] [-b bps] [-c] [-p dev] [-v] imagefile\n",
71 fprintf(stderr, "Opening file and reading image...\n");
73 if ((ifd = open(ifn, O_RDONLY)) < 0)
74 Perror("can't open kernel image file '%s'", ifn);
76 if (fstat(ifd, &ist) < 0)
77 Perror("fstat '%s' failed", ifn);
79 if ((image = (char *)malloc(ist.st_size)) == NULL)
80 Perror("can't allocate %ld bytes for image", ist.st_size);
82 if ((c = read(ifd, image, ist.st_size)) < 0)
83 Perror("read of %d bytes from '%s' failed", ist.st_size, ifn);
86 Error("read of %ld bytes from '%s' failed (%d)", ist.st_size, ifn, c);
89 Perror("close of '%s' failed", ifn);
92 fprintf(stderr, "Opening serial port and sending image...\n");
94 if ((sfd = serialopen(serialdev, speed)) < 0)
95 Perror("open of serial device '%s' failed", serialdev);
99 remote_write_bytes(addr, image, ist.st_size);
103 fprintf(stderr, "[continue]");
107 if (serialclose(sfd) < 0)
108 Perror("close of serial device '%s' failed", serialdev);
111 fprintf(stderr, "Done.\n");