Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fastboot continue when omitting boot img from cdba command line #66

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cdba-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ static void msg_fastboot_download(const void *data, size_t len)
}
}

static void msg_fastboot_continue(void)
{
device_fastboot_continue(selected_device);
cdba_send(MSG_FASTBOOT_CONTINUE);
}

void cdba_send_buf(int type, size_t len, const void *buf)
{
struct msg msg = {
Expand Down Expand Up @@ -228,6 +234,9 @@ static int handle_stdin(int fd, void *buf)
case MSG_BOARD_INFO:
device_info(username, msg->data, msg->len);
break;
case MSG_FASTBOOT_CONTINUE:
msg_fastboot_continue();
break;
default:
fprintf(stderr, "unk %d len %d\n", msg->type, msg->len);
exit(1);
Expand Down
38 changes: 32 additions & 6 deletions cdba.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
static bool quit;
static bool fastboot_repeat;
static bool fastboot_done;
static bool fastboot_continue;

static int status_fd = -1;

Expand Down Expand Up @@ -340,6 +341,22 @@ static void request_power_off(void)
list_add(&work_items, &work.node);
}

static void request_fastboot_continue_fn(struct work *work, int ssh_stdin)
{
int ret;

ret = cdba_send(ssh_stdin, MSG_FASTBOOT_CONTINUE);
if (ret < 0)
err(1, "failed to send fastboot continue request");
}

static void request_fastboot_continue(void)
{
static struct work work = { request_fastboot_continue_fn };

list_add(&work_items, &work.node);
}

struct fastboot_download_work {
struct work work;

Expand Down Expand Up @@ -532,10 +549,14 @@ static int handle_message(struct circ_buf *buf)
case MSG_FASTBOOT_PRESENT:
if (*(uint8_t*)msg->data) {
// printf("======================================== MSG_FASTBOOT_PRESENT(on)\n");
if (!fastboot_done || fastboot_repeat)
if (fastboot_continue) {
request_fastboot_continue();
fastboot_continue = false;
} else if (!fastboot_done || fastboot_repeat) {
request_fastboot_files();
else
} else {
quit = true;
}
} else {
fastboot_done = true;
// printf("======================================== MSG_FASTBOOT_PRESENT(off)\n");
Expand All @@ -557,6 +578,9 @@ static int handle_message(struct circ_buf *buf)
handle_board_info(msg->data, msg->len);
return -1;
break;
case MSG_FASTBOOT_CONTINUE:
// printf("======================================== MSG_FASTBOOT_CONTINUE\n");
break;
default:
fprintf(stderr, "unk %d len %d\n", msg->type, msg->len);
return -1;
Expand Down Expand Up @@ -585,7 +609,7 @@ static void usage(void)
extern const char *__progname;

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

switch (verb) {
case CDBA_BOOT:
if (optind >= argc || !board)
if (optind > argc || !board)
usage();

fastboot_file = argv[optind];
if (lstat(fastboot_file, &sb))
if (!fastboot_file)
fastboot_continue = true;
else if (lstat(fastboot_file, &sb))
err(1, "unable to read \"%s\"", fastboot_file);
if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
else if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
errx(1, "\"%s\" is not a regular file", fastboot_file);

request_select_board(board);
Expand Down
1 change: 1 addition & 0 deletions cdba.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum {
MSG_SEND_BREAK,
MSG_LIST_DEVICES,
MSG_BOARD_INFO,
MSG_FASTBOOT_CONTINUE,
};

#endif
5 changes: 5 additions & 0 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ void device_fastboot_boot(struct device *device)
fastboot_boot(device->fastboot);
}

void device_fastboot_continue(struct device *device)
{
fastboot_continue(device->fastboot);
}

void device_fastboot_flash_reboot(struct device *device)
{
fastboot_flash(device->fastboot, "boot");
Expand Down
1 change: 1 addition & 0 deletions device.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void device_fastboot_flash_reboot(struct device *device);
void device_send_break(struct device *device);
void device_list_devices(const char *username);
void device_info(const char *username, const void *data, size_t dlen);
void device_fastboot_continue(struct device *device);

enum {
DEVICE_KEY_FASTBOOT,
Expand Down
14 changes: 14 additions & 0 deletions fastboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,17 @@ int fastboot_reboot(struct fastboot *fb)

return 0;
}

int fastboot_continue(struct fastboot *fb)
{
char buf[80];
int n;

fastboot_write(fb, "continue", 8);

n = fastboot_read(fb, buf, sizeof(buf));
if (n >= 0)
fprintf(stderr, "%s\n", buf);

return 0;
}
1 change: 1 addition & 0 deletions fastboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ int fastboot_erase(struct fastboot *fb, const char *partition);
int fastboot_set_active(struct fastboot *fb, const char *active);
int fastboot_flash(struct fastboot *fb, const char *partition);
int fastboot_reboot(struct fastboot *fb);
int fastboot_continue(struct fastboot *fb);

#endif
Loading