Skip to content

Commit

Permalink
device: add support for leaving device powered
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lumag committed Mar 12, 2024
1 parent 71cf9f3 commit 308484c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion device.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ static bool device_check_access(struct device *device,
return false;
}

static int device_power_off(struct device *device);

struct device *device_open(const char *board,
const char *username)
{
Expand Down Expand Up @@ -156,6 +158,12 @@ struct device *device_open(const char *board,
if (!device->console)
errx(1, "failed to open device console");

/* Power off before opening fastboot */
if (device->power_always_on) {
device_power_off(device);
sleep(2);
}

if (device->usb_always_on)
device_usb(device, true);

Expand Down Expand Up @@ -386,7 +394,8 @@ void device_close(struct device *dev)
{
if (!dev->usb_always_on)
device_usb(dev, false);
device_power(dev, false);
if (!dev->power_always_on)
device_power(dev, false);

if (device_has_control(dev, close))
device_control(dev, close);
Expand Down
1 change: 1 addition & 0 deletions device.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct device {
unsigned voltage;
bool tickle_mmc;
bool usb_always_on;
bool power_always_on;
struct fastboot *fastboot;
unsigned int fastboot_key_timeout;
int state;
Expand Down
2 changes: 2 additions & 0 deletions device_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ static void parse_board(struct device_parser *dp)
dev->ppps3_path = strdup(value);
} else if (!strcmp(key, "status-cmd")) {
dev->status_cmd = strdup(value);
} else if (!strcmp(key, "power_always_on")) {
dev->power_always_on = !strcmp(value, "true");
} else {
fprintf(stderr, "device parser: unknown key \"%s\"\n", key);
exit(1);
Expand Down

0 comments on commit 308484c

Please sign in to comment.