Skip to content

Commit 62dc594

Browse files
committed
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 <[email protected]>
1 parent 2f1caa2 commit 62dc594

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

cdba-server.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ static struct fastboot_ops fastboot_ops = {
5555

5656
static void msg_select_board(const void *param)
5757
{
58-
selected_device = device_open(param, username, &fastboot_ops);
58+
selected_device = device_open(param, username);
5959
if (!selected_device) {
6060
fprintf(stderr, "failed to open %s\n", (const char *)param);
6161
watch_quit();
6262
}
6363

64+
device_fastboot_open(selected_device, &fastboot_ops);
65+
6466
cdba_send(MSG_SELECT_BOARD);
6567
}
6668

device.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ static bool device_check_access(struct device *device,
9595
}
9696

9797
struct device *device_open(const char *board,
98-
const char *username,
99-
struct fastboot_ops *fastboot_ops)
98+
const char *username)
10099
{
101100
struct device *device;
102101

@@ -136,8 +135,6 @@ struct device *device_open(const char *board,
136135
if (device->usb_always_on)
137136
device_usb(device, true);
138137

139-
device->fastboot = fastboot_open(device->serial, fastboot_ops, NULL);
140-
141138
return device;
142139
}
143140

@@ -275,18 +272,36 @@ int device_write(struct device *device, const void *buf, size_t len)
275272
return device_console(device, write, buf, len);
276273
}
277274

275+
void device_fastboot_open(struct device *device,
276+
struct fastboot_ops *fastboot_ops)
277+
{
278+
device->fastboot = fastboot_open(device->serial, fastboot_ops, NULL);
279+
}
280+
278281
void device_fastboot_boot(struct device *device)
279282
{
283+
if (!device->fastboot) {
284+
fprintf(stderr, "fastboot not opened\n");
285+
return;
286+
}
280287
fastboot_boot(device->fastboot);
281288
}
282289

283290
void device_fastboot_continue(struct device *device)
284291
{
292+
if (!device->fastboot) {
293+
fprintf(stderr, "fastboot not opened\n");
294+
return;
295+
}
285296
fastboot_continue(device->fastboot);
286297
}
287298

288299
void device_fastboot_flash_reboot(struct device *device)
289300
{
301+
if (!device->fastboot) {
302+
fprintf(stderr, "fastboot not opened\n");
303+
return;
304+
}
290305
fastboot_flash(device->fastboot, "boot");
291306
fastboot_reboot(device->fastboot);
292307
}

device.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ struct device_user {
7272
void device_add(struct device *device);
7373

7474
struct device *device_open(const char *board,
75-
const char *username,
76-
struct fastboot_ops *fastboot_ops);
75+
const char *username);
7776
void device_close(struct device *dev);
7877
int device_power(struct device *device, bool on);
7978

@@ -83,6 +82,8 @@ int device_write(struct device *device, const void *buf, size_t len);
8382

8483
void device_boot(struct device *device, const void *data, size_t len);
8584

85+
void device_fastboot_open(struct device *device,
86+
struct fastboot_ops *fastboot_ops);
8687
void device_fastboot_boot(struct device *device);
8788
void device_fastboot_flash_reboot(struct device *device);
8889
void device_send_break(struct device *device);

0 commit comments

Comments
 (0)