fernly-usb-loader.c: Add -w option, wait for serial port to appear.

Many MTK devices have bootloader connection available only for few seconds
after power-up. To not try to synchronize all of device connection over USB/
power-on and fernly-usb-loader start up, the latter can be run in this "wait"
mode, and a device connected and bootloader start at leisure.
This commit is contained in:
Paul Sokolovsky 2015-04-01 02:35:44 +03:00 committed by Sean Cross
parent 005e2d67d5
commit 6020a9248a

View file

@ -1203,6 +1203,7 @@ static void print_help(const char *name)
printf("\n"); printf("\n");
printf("Arguments:\n"); printf("Arguments:\n");
printf(" -l [logfile] Log boot output to the specified file\n"); printf(" -l [logfile] Log boot output to the specified file\n");
printf(" -w Wait for serial port to appear\n");
printf(" -s Enter boot shell\n"); printf(" -s Enter boot shell\n");
printf(" -h Print this help\n"); printf(" -h Print this help\n");
printf("\n"); printf("\n");
@ -1222,8 +1223,9 @@ int main(int argc, char **argv) {
uint32_t ret; uint32_t ret;
int opt; int opt;
int shell = 0; int shell = 0;
int wait_serial = 0;
while ((opt = getopt(argc, argv, "hl:s")) != -1) { while ((opt = getopt(argc, argv, "hl:sw")) != -1) {
switch(opt) { switch(opt) {
case 'l': case 'l':
@ -1234,6 +1236,10 @@ int main(int argc, char **argv) {
shell = 1; shell = 1;
break; break;
case 'w':
wait_serial = 1;
break;
default: default:
case 'h': case 'h':
print_help(argv[0]); print_help(argv[0]);
@ -1251,10 +1257,27 @@ int main(int argc, char **argv) {
exit(1); exit(1);
} }
serfd = open(argv[1], O_RDWR); if (wait_serial) {
if (-1 == serfd) { printf("Waiting for serial port to connect: .");
perror("Unable to open serial port"); fflush(stdout);
exit(1); }
while (1) {
serfd = open(argv[1], O_RDWR);
if (-1 == serfd) {
if (wait_serial) {
printf(".");
fflush(stdout);
sleep(1);
continue;
} else {
perror("Unable to open serial port");
exit(1);
}
}
break;
}
if (wait_serial) {
printf("\n");
} }
s1blfd = open(argv[2], O_RDONLY); s1blfd = open(argv[2], O_RDONLY);