From b626f41185c2e301bef27988c9bdd45cef762ff7 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Tue, 4 Aug 2020 18:43:05 +0300 Subject: [PATCH] device: support working in non-automated setup Make device power controller optional, allowing one to use cdba in non-automated setup (just simplifying the fastboot + console handling). Signed-off-by: Dmitry Baryshkov [bjorn: Rebased the patch onto master, reversed the logic in power_on/off] Signed-off-by: Bjorn Andersson --- device.c | 18 ++++++++---------- device_parser.c | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/device.c b/device.c index 25f185d..376a38a 100644 --- a/device.c +++ b/device.c @@ -92,13 +92,15 @@ struct device *device_open(const char *board, return NULL; found: - assert(device->open); + assert(device->open || device->console_dev); device_lock(device); - device->cdb = device->open(device); - if (!device->cdb) - errx(1, "failed to open device controller"); + if (device->open) { + device->cdb = device->open(device); + if (!device->cdb) + errx(1, "failed to open device controller"); + } if (device->console_dev) console_open(device); @@ -117,11 +119,9 @@ static void device_release_fastboot_key(void *data) int device_power_on(struct device *device) { - if (!device) + if (!device || !device->power_on) return 0; - assert(device->power_on); - if (device->fastboot_key_timeout) device->fastboot_key(device, true); @@ -135,11 +135,9 @@ int device_power_on(struct device *device) int device_power_off(struct device *device) { - if (!device) + if (!device || !device->power_off) return 0; - assert(device->power_off); - device->power_off(device); return 0; diff --git a/device_parser.c b/device_parser.c index d31b3c5..0ebe151 100644 --- a/device_parser.c +++ b/device_parser.c @@ -144,7 +144,7 @@ static void parse_board(struct device_parser *dp) } } - if (!dev->board || !dev->serial || !dev->open) { + if (!dev->board || !dev->serial || !(dev->open || dev->console_dev)) { fprintf(stderr, "device parser: insufficiently defined device\n"); exit(1); }