Skip to content

Commit 762879f

Browse files
committed
device: add support for leaving device powered
For some devices it might be desirable to leave device powered on after the cdba exits (e.g. to run some long-running tests). Add the 'power_always_on' option that tells cdba server to leave device powered on after exiting and to toggle power (to reset the device) when connecting. Signed-off-by: Dmitry Baryshkov <[email protected]>
1 parent 62dc594 commit 762879f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

device.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ static bool device_check_access(struct device *device,
9494
return false;
9595
}
9696

97+
static int device_power_off(struct device *device);
98+
9799
struct device *device_open(const char *board,
98100
const char *username)
99101
{
@@ -132,6 +134,18 @@ struct device *device_open(const char *board,
132134
if (!device->console)
133135
errx(1, "failed to open device console");
134136

137+
/*
138+
* Power off before opening fastboot. Otherwise if the device is
139+
* already in the fastboot state, CDBA will detect it, then power up
140+
* procedure will restart the device causing fastboot to disappear and
141+
* appear again. This will cause CDBA to exit, ending up with the
142+
* unbreakable fastboot-reset-second_fastboot-quit cycle.
143+
* */
144+
if (device->power_always_on) {
145+
device_power_off(device);
146+
sleep(2);
147+
}
148+
135149
if (device->usb_always_on)
136150
device_usb(device, true);
137151

@@ -374,7 +388,8 @@ void device_close(struct device *dev)
374388
{
375389
if (!dev->usb_always_on)
376390
device_usb(dev, false);
377-
device_power(dev, false);
391+
if (!dev->power_always_on)
392+
device_power(dev, false);
378393

379394
if (device_has_control(dev, close))
380395
device_control(dev, close);

device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct device {
4141
unsigned voltage;
4242
bool tickle_mmc;
4343
bool usb_always_on;
44+
bool power_always_on;
4445
struct fastboot *fastboot;
4546
unsigned int fastboot_key_timeout;
4647
int state;

device_parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ static void parse_board(struct device_parser *dp)
171171
dev->ppps3_path = strdup(value);
172172
} else if (!strcmp(key, "status-cmd")) {
173173
dev->status_cmd = strdup(value);
174+
} else if (!strcmp(key, "power_always_on")) {
175+
dev->power_always_on = !strcmp(value, "true");
174176
} else {
175177
fprintf(stderr, "device parser: unknown key \"%s\"\n", key);
176178
exit(1);

0 commit comments

Comments
 (0)