device: split fastboot_open from device_open

Create new function calling fastboot_open so that device_open doesn't
have dependency on the fastboot_ops or udev.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
This commit is contained in:
Dmitry Baryshkov
2024-03-12 20:30:25 +02:00
parent 2f1caa28c0
commit 62dc594cb1
3 changed files with 25 additions and 7 deletions

View File

@@ -55,12 +55,14 @@ static struct fastboot_ops fastboot_ops = {
static void msg_select_board(const void *param)
{
selected_device = device_open(param, username, &fastboot_ops);
selected_device = device_open(param, username);
if (!selected_device) {
fprintf(stderr, "failed to open %s\n", (const char *)param);
watch_quit();
}
device_fastboot_open(selected_device, &fastboot_ops);
cdba_send(MSG_SELECT_BOARD);
}

View File

@@ -95,8 +95,7 @@ static bool device_check_access(struct device *device,
}
struct device *device_open(const char *board,
const char *username,
struct fastboot_ops *fastboot_ops)
const char *username)
{
struct device *device;
@@ -136,8 +135,6 @@ found:
if (device->usb_always_on)
device_usb(device, true);
device->fastboot = fastboot_open(device->serial, fastboot_ops, NULL);
return device;
}
@@ -275,18 +272,36 @@ int device_write(struct device *device, const void *buf, size_t len)
return device_console(device, write, buf, len);
}
void device_fastboot_open(struct device *device,
struct fastboot_ops *fastboot_ops)
{
device->fastboot = fastboot_open(device->serial, fastboot_ops, NULL);
}
void device_fastboot_boot(struct device *device)
{
if (!device->fastboot) {
fprintf(stderr, "fastboot not opened\n");
return;
}
fastboot_boot(device->fastboot);
}
void device_fastboot_continue(struct device *device)
{
if (!device->fastboot) {
fprintf(stderr, "fastboot not opened\n");
return;
}
fastboot_continue(device->fastboot);
}
void device_fastboot_flash_reboot(struct device *device)
{
if (!device->fastboot) {
fprintf(stderr, "fastboot not opened\n");
return;
}
fastboot_flash(device->fastboot, "boot");
fastboot_reboot(device->fastboot);
}

View File

@@ -72,8 +72,7 @@ struct device_user {
void device_add(struct device *device);
struct device *device_open(const char *board,
const char *username,
struct fastboot_ops *fastboot_ops);
const char *username);
void device_close(struct device *dev);
int device_power(struct device *device, bool on);
@@ -83,6 +82,8 @@ int device_write(struct device *device, const void *buf, size_t len);
void device_boot(struct device *device, const void *data, size_t len);
void device_fastboot_open(struct device *device,
struct fastboot_ops *fastboot_ops);
void device_fastboot_boot(struct device *device);
void device_fastboot_flash_reboot(struct device *device);
void device_send_break(struct device *device);