From 308484c7ac9a08b4d51f4737a16521e49f40719d Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Tue, 21 Dec 2021 02:24:52 +0300 Subject: [PATCH] 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 --- device.c | 11 ++++++++++- device.h | 1 + device_parser.c | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/device.c b/device.c index 6d8754c..a791e73 100644 --- a/device.c +++ b/device.c @@ -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) { @@ -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); @@ -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); diff --git a/device.h b/device.h index 220eeb0..0b8d0e9 100644 --- a/device.h +++ b/device.h @@ -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; diff --git a/device_parser.c b/device_parser.c index fd65816..76c2cc6 100644 --- a/device_parser.c +++ b/device_parser.c @@ -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);