Merge pull request #66 from 0xB0D/master

Implement fastboot continue when omitting boot img from cdba command line
This commit is contained in:
Konrad Dybcio
2024-01-17 11:12:13 +01:00
committed by GitHub
7 changed files with 63 additions and 6 deletions

View File

@@ -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 = {
@@ -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);

38
cdba.c
View File

@@ -51,6 +51,7 @@
static bool quit;
static bool fastboot_repeat;
static bool fastboot_done;
static bool fastboot_continue;
static int status_fd = -1;
@@ -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;
@@ -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");
@@ -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;
@@ -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);
@@ -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);

1
cdba.h
View File

@@ -30,6 +30,7 @@ enum {
MSG_SEND_BREAK,
MSG_LIST_DEVICES,
MSG_BOARD_INFO,
MSG_FASTBOOT_CONTINUE,
};
#endif

View File

@@ -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");

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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