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 <dmitry.baryshkov@linaro.org>
[bjorn: Rebased the patch onto master, reversed the logic in power_on/off]
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Dmitry Baryshkov
2020-08-04 18:43:05 +03:00
committed by Bjorn Andersson
parent 5eac176fb5
commit b626f41185
2 changed files with 9 additions and 11 deletions

View File

@@ -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;

View File

@@ -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);
}