Skip to content

Commit a02ae82

Browse files
author
Sean Cross
committed
Merge branch 'pfalcon-loader-wait'
2 parents 005e2d6 + 6020a92 commit a02ae82

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

fernly-usb-loader.c

+28-5
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ static void print_help(const char *name)
12031203
printf("\n");
12041204
printf("Arguments:\n");
12051205
printf(" -l [logfile] Log boot output to the specified file\n");
1206+
printf(" -w Wait for serial port to appear\n");
12061207
printf(" -s Enter boot shell\n");
12071208
printf(" -h Print this help\n");
12081209
printf("\n");
@@ -1222,8 +1223,9 @@ int main(int argc, char **argv) {
12221223
uint32_t ret;
12231224
int opt;
12241225
int shell = 0;
1226+
int wait_serial = 0;
12251227

1226-
while ((opt = getopt(argc, argv, "hl:s")) != -1) {
1228+
while ((opt = getopt(argc, argv, "hl:sw")) != -1) {
12271229
switch(opt) {
12281230

12291231
case 'l':
@@ -1234,6 +1236,10 @@ int main(int argc, char **argv) {
12341236
shell = 1;
12351237
break;
12361238

1239+
case 'w':
1240+
wait_serial = 1;
1241+
break;
1242+
12371243
default:
12381244
case 'h':
12391245
print_help(argv[0]);
@@ -1251,10 +1257,27 @@ int main(int argc, char **argv) {
12511257
exit(1);
12521258
}
12531259

1254-
serfd = open(argv[1], O_RDWR);
1255-
if (-1 == serfd) {
1256-
perror("Unable to open serial port");
1257-
exit(1);
1260+
if (wait_serial) {
1261+
printf("Waiting for serial port to connect: .");
1262+
fflush(stdout);
1263+
}
1264+
while (1) {
1265+
serfd = open(argv[1], O_RDWR);
1266+
if (-1 == serfd) {
1267+
if (wait_serial) {
1268+
printf(".");
1269+
fflush(stdout);
1270+
sleep(1);
1271+
continue;
1272+
} else {
1273+
perror("Unable to open serial port");
1274+
exit(1);
1275+
}
1276+
}
1277+
break;
1278+
}
1279+
if (wait_serial) {
1280+
printf("\n");
12581281
}
12591282

12601283
s1blfd = open(argv[2], O_RDONLY);

0 commit comments

Comments
 (0)