Skip to content

Commit d678216

Browse files
authored
Merge pull request #66 from 0xB0D/master
Implement fastboot continue when omitting boot img from cdba command line
2 parents f9c4d71 + 68ca7e4 commit d678216

File tree

7 files changed

+63
-6
lines changed

7 files changed

+63
-6
lines changed

cdba-server.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ static void msg_fastboot_download(const void *data, size_t len)
145145
}
146146
}
147147

148+
static void msg_fastboot_continue(void)
149+
{
150+
device_fastboot_continue(selected_device);
151+
cdba_send(MSG_FASTBOOT_CONTINUE);
152+
}
153+
148154
void cdba_send_buf(int type, size_t len, const void *buf)
149155
{
150156
struct msg msg = {
@@ -228,6 +234,9 @@ static int handle_stdin(int fd, void *buf)
228234
case MSG_BOARD_INFO:
229235
device_info(username, msg->data, msg->len);
230236
break;
237+
case MSG_FASTBOOT_CONTINUE:
238+
msg_fastboot_continue();
239+
break;
231240
default:
232241
fprintf(stderr, "unk %d len %d\n", msg->type, msg->len);
233242
exit(1);

cdba.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
static bool quit;
5252
static bool fastboot_repeat;
5353
static bool fastboot_done;
54+
static bool fastboot_continue;
5455

5556
static int status_fd = -1;
5657

@@ -340,6 +341,22 @@ static void request_power_off(void)
340341
list_add(&work_items, &work.node);
341342
}
342343

344+
static void request_fastboot_continue_fn(struct work *work, int ssh_stdin)
345+
{
346+
int ret;
347+
348+
ret = cdba_send(ssh_stdin, MSG_FASTBOOT_CONTINUE);
349+
if (ret < 0)
350+
err(1, "failed to send fastboot continue request");
351+
}
352+
353+
static void request_fastboot_continue(void)
354+
{
355+
static struct work work = { request_fastboot_continue_fn };
356+
357+
list_add(&work_items, &work.node);
358+
}
359+
343360
struct fastboot_download_work {
344361
struct work work;
345362

@@ -532,10 +549,14 @@ static int handle_message(struct circ_buf *buf)
532549
case MSG_FASTBOOT_PRESENT:
533550
if (*(uint8_t*)msg->data) {
534551
// printf("======================================== MSG_FASTBOOT_PRESENT(on)\n");
535-
if (!fastboot_done || fastboot_repeat)
552+
if (fastboot_continue) {
553+
request_fastboot_continue();
554+
fastboot_continue = false;
555+
} else if (!fastboot_done || fastboot_repeat) {
536556
request_fastboot_files();
537-
else
557+
} else {
538558
quit = true;
559+
}
539560
} else {
540561
fastboot_done = true;
541562
// printf("======================================== MSG_FASTBOOT_PRESENT(off)\n");
@@ -557,6 +578,9 @@ static int handle_message(struct circ_buf *buf)
557578
handle_board_info(msg->data, msg->len);
558579
return -1;
559580
break;
581+
case MSG_FASTBOOT_CONTINUE:
582+
// printf("======================================== MSG_FASTBOOT_CONTINUE\n");
583+
break;
560584
default:
561585
fprintf(stderr, "unk %d len %d\n", msg->type, msg->len);
562586
return -1;
@@ -585,7 +609,7 @@ static void usage(void)
585609
extern const char *__progname;
586610

587611
fprintf(stderr, "usage: %s -b <board> -h <host> [-t <timeout>] "
588-
"[-T <inactivity-timeout>] boot.img\n",
612+
"[-T <inactivity-timeout>] <boot.img>\n",
589613
__progname);
590614
fprintf(stderr, "usage: %s -i -b <board> -h <host>\n",
591615
__progname);
@@ -673,13 +697,15 @@ int main(int argc, char **argv)
673697

674698
switch (verb) {
675699
case CDBA_BOOT:
676-
if (optind >= argc || !board)
700+
if (optind > argc || !board)
677701
usage();
678702

679703
fastboot_file = argv[optind];
680-
if (lstat(fastboot_file, &sb))
704+
if (!fastboot_file)
705+
fastboot_continue = true;
706+
else if (lstat(fastboot_file, &sb))
681707
err(1, "unable to read \"%s\"", fastboot_file);
682-
if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
708+
else if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
683709
errx(1, "\"%s\" is not a regular file", fastboot_file);
684710

685711
request_select_board(board);

cdba.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum {
3030
MSG_SEND_BREAK,
3131
MSG_LIST_DEVICES,
3232
MSG_BOARD_INFO,
33+
MSG_FASTBOOT_CONTINUE,
3334
};
3435

3536
#endif

device.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ void device_fastboot_boot(struct device *device)
303303
fastboot_boot(device->fastboot);
304304
}
305305

306+
void device_fastboot_continue(struct device *device)
307+
{
308+
fastboot_continue(device->fastboot);
309+
}
310+
306311
void device_fastboot_flash_reboot(struct device *device)
307312
{
308313
fastboot_flash(device->fastboot, "boot");

device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void device_fastboot_flash_reboot(struct device *device);
8888
void device_send_break(struct device *device);
8989
void device_list_devices(const char *username);
9090
void device_info(const char *username, const void *data, size_t dlen);
91+
void device_fastboot_continue(struct device *device);
9192

9293
enum {
9394
DEVICE_KEY_FASTBOOT,

fastboot.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,17 @@ int fastboot_reboot(struct fastboot *fb)
490490

491491
return 0;
492492
}
493+
494+
int fastboot_continue(struct fastboot *fb)
495+
{
496+
char buf[80];
497+
int n;
498+
499+
fastboot_write(fb, "continue", 8);
500+
501+
n = fastboot_read(fb, buf, sizeof(buf));
502+
if (n >= 0)
503+
fprintf(stderr, "%s\n", buf);
504+
505+
return 0;
506+
}

fastboot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ int fastboot_erase(struct fastboot *fb, const char *partition);
1717
int fastboot_set_active(struct fastboot *fb, const char *active);
1818
int fastboot_flash(struct fastboot *fb, const char *partition);
1919
int fastboot_reboot(struct fastboot *fb);
20+
int fastboot_continue(struct fastboot *fb);
2021

2122
#endif

0 commit comments

Comments
 (0)