Merge pull request #71 from lumag/cdba-power

cdba-power: add tool to control power-on/-off
This commit is contained in:
Konrad Dybcio
2024-03-30 17:06:41 +01:00
committed by GitHub
30 changed files with 495 additions and 775 deletions

87
cdba-power.c Normal file
View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 2024, Linaro Ltd.
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "cdba-server.h"
#include "device.h"
#include "device_parser.h"
#include "watch.h"
void cdba_send_buf(int type, size_t len, const void *buf)
{
/* ignore console messages */
}
static void usage(const char *name)
{
fprintf(stderr, "Usage: %s <board> on|off\n", name);
exit(EXIT_FAILURE);
}
static struct device *selected_device;
bool ready(void)
{
return device_is_running(selected_device);
}
int main(int argc, char **argv)
{
const char *home;
const char *name;
bool on;
int ret;
if (argc != 3)
usage(argv[0]);
if (!strcmp(argv[2], "on"))
on = true;
else if (!strcmp(argv[2], "off"))
on = false;
else
usage(argv[0]);
home = getenv("HOME");
if (home)
chdir(home);
ret = device_parser(".cdba");
if (ret) {
ret = device_parser("/etc/cdba");
if (ret) {
fprintf(stderr, "device parser: unable to open config file\n");
exit(1);
}
}
name = argv[1];
selected_device = device_open(name, "nobody");
if (!selected_device) {
fprintf(stderr, "failed to open %s\n", name);
exit(EXIT_FAILURE);
}
if (on) {
device_power(selected_device, true);
watch_main_loop(ready);
selected_device->usb_always_on = true;
selected_device->power_always_on = true;
} else {
device_usb(selected_device, false);
device_power(selected_device, false);
}
device_close(selected_device);
return 0;
}

View File

@@ -2,34 +2,8 @@
* Copyright (c) 2016-2018, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sys/time.h>
#include <alloca.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
@@ -46,40 +20,12 @@
#include "device_parser.h"
#include "fastboot.h"
#include "list.h"
#include "watch.h"
static bool quit_invoked;
static const char *username;
struct device *selected_device;
int tty_open(const char *tty, struct termios *old)
{
struct termios tios;
int ret;
int fd;
fd = open(tty, O_RDWR | O_NOCTTY | O_EXCL);
if (fd < 0)
err(1, "unable to open \"%s\"", tty);
ret = tcgetattr(fd, old);
if (ret < 0)
err(1, "unable to retrieve \"%s\" tios", tty);
memset(&tios, 0, sizeof(tios));
tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
tios.c_iflag = IGNPAR;
tios.c_oflag = 0;
tcflush(fd, TCIFLUSH);
ret = tcsetattr(fd, TCSANOW, &tios);
if (ret < 0)
err(1, "unable to update \"%s\" tios", tty);
return fd;
}
static void fastboot_opened(struct fastboot *fb, void *data)
{
const uint8_t one = 1;
@@ -109,12 +55,14 @@ static struct fastboot_ops fastboot_ops = {
static void msg_select_board(const void *param)
{
selected_device = device_open(param, username, &fastboot_ops);
selected_device = device_open(param, username);
if (!selected_device) {
fprintf(stderr, "failed to open %s\n", (const char *)param);
quit_invoked = true;
watch_quit();
}
device_fastboot_open(selected_device, &fastboot_ops);
cdba_send(MSG_SELECT_BOARD);
}
@@ -248,119 +196,14 @@ static int handle_stdin(int fd, void *buf)
return 0;
}
struct watch {
struct list_head node;
int fd;
int (*cb)(int, void*);
void *data;
};
struct timer {
struct list_head node;
struct timeval tv;
void (*cb)(void *);
void *data;
};
static struct list_head read_watches = LIST_INIT(read_watches);
static struct list_head timer_watches = LIST_INIT(timer_watches);
void watch_add_readfd(int fd, int (*cb)(int, void*), void *data)
{
struct watch *w;
w = calloc(1, sizeof(*w));
w->fd = fd;
w->cb = cb;
w->data = data;
list_add(&read_watches, &w->node);
}
void watch_timer_add(int timeout_ms, void (*cb)(void *), void *data)
{
struct timeval tv_timeout;
struct timeval now;
struct timer *t;
t = calloc(1, sizeof(*t));
gettimeofday(&now, NULL);
tv_timeout.tv_sec = timeout_ms / 1000;
tv_timeout.tv_usec = (timeout_ms % 1000) * 1000;
t->cb = cb;
t->data = data;
timeradd(&now, &tv_timeout, &t->tv);
list_add(&timer_watches, &t->node);
}
static struct timeval *watch_timer_next(void)
{
static struct timeval timeout;
struct timeval now;
struct timer *next;
struct timer *t;
if (list_empty(&timer_watches))
return NULL;
next = list_entry_first(&timer_watches, struct timer, node);
list_for_each_entry(t, &timer_watches, node) {
if (timercmp(&t->tv, &next->tv, <))
next = t;
}
gettimeofday(&now, NULL);
timersub(&next->tv, &now, &timeout);
if (timeout.tv_sec < 0) {
timeout.tv_sec = 0;
timeout.tv_usec = 0;
}
return &timeout;
}
static void watch_timer_invoke(void)
{
struct timeval now;
struct timer *tmp;
struct timer *t;
gettimeofday(&now, NULL);
list_for_each_entry_safe(t, tmp, &timer_watches, node) {
if (timercmp(&t->tv, &now, <)) {
t->cb(t->data);
list_del(&t->node);
free(t);
}
}
}
static void sigpipe_handler(int signo)
{
quit_invoked = true;
}
void watch_quit(void)
{
quit_invoked = true;
watch_quit();
}
int main(int argc, char **argv)
{
struct timeval *timeoutp;
struct watch *w;
fd_set rfds;
int flags;
int nfds;
int ret;
signal(SIGPIPE, sigpipe_handler);
@@ -389,40 +232,7 @@ int main(int argc, char **argv)
flags = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
while (!quit_invoked) {
nfds = 0;
list_for_each_entry(w, &read_watches, node) {
nfds = MAX(nfds, w->fd);
FD_SET(w->fd, &rfds);
}
if (!FD_ISSET(STDIN_FILENO, &rfds)) {
fprintf(stderr, "rfds is trash!\n");
goto done;
}
timeoutp = watch_timer_next();
ret = select(nfds + 1, &rfds, NULL, NULL, timeoutp);
if (ret < 0 && errno == EINTR)
continue;
else if (ret < 0)
break;
watch_timer_invoke();
list_for_each_entry(w, &read_watches, node) {
if (FD_ISSET(w->fd, &rfds)) {
ret = w->cb(w->fd, w->data);
if (ret < 0) {
fprintf(stderr, "cb returned %d\n", ret);
goto done;
}
}
}
}
done:
watch_run();
/* if we got here, stdin/out/err might be not accessible anymore */
ret = open("/dev/null", O_RDWR);

View File

@@ -6,14 +6,6 @@
#include "cdba.h"
void watch_add_readfd(int fd, int (*cb)(int, void*), void *data);
int watch_add_quit(int (*cb)(int, void*), void *data);
void watch_timer_add(int timeout_ms, void (*cb)(void *), void *data);
void watch_quit(void);
int watch_run(void);
int tty_open(const char *tty, struct termios *old);
void cdba_send_buf(int type, size_t len, const void *buf);
#define cdba_send(type) cdba_send_buf(type, 0, NULL)

26
cdba.c
View File

@@ -2,31 +2,7 @@
* Copyright (c) 2016-2018, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sys/select.h>
#include <sys/stat.h>

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2018, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <errno.h>

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2018, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __CIRC_BUF_H__
#define __CIRC_BUF_H__

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2020, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sys/file.h>
#include <sys/stat.h>
@@ -37,6 +13,8 @@
#include "cdba-server.h"
#include "device.h"
#include "tty.h"
#include "watch.h"
struct console {
int console_fd;

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2016-2018, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sys/file.h>
#include <sys/stat.h>
@@ -47,6 +23,7 @@
#include "list.h"
#include "ppps.h"
#include "status-cmd.h"
#include "watch.h"
#define ARRAY_SIZE(x) ((sizeof(x)/sizeof((x)[0])))
@@ -117,9 +94,10 @@ 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,
struct fastboot_ops *fastboot_ops)
const char *username)
{
struct device *device;
@@ -156,11 +134,21 @@ found:
if (!device->console)
errx(1, "failed to open device console");
/*
* Power off before opening fastboot. Otherwise if the device is
* already in the fastboot state, CDBA will detect it, then power up
* procedure will restart the device causing fastboot to disappear and
* appear again. This will cause CDBA to exit, ending up with the
* unbreakable fastboot-reset-second_fastboot-quit cycle.
* */
if (device->power_always_on) {
device_power_off(device);
sleep(2);
}
if (device->usb_always_on)
device_usb(device, true);
device->fastboot = fastboot_open(device->serial, fastboot_ops, NULL);
return device;
}
@@ -239,6 +227,11 @@ static void device_tick(void *data)
}
}
bool device_is_running(struct device *device)
{
return device->state == DEVICE_STATE_RUNNING;
}
static int device_power_on(struct device *device)
{
if (!device || !device_has_control(device, power))
@@ -298,18 +291,36 @@ int device_write(struct device *device, const void *buf, size_t len)
return device_console(device, write, buf, len);
}
void device_fastboot_open(struct device *device,
struct fastboot_ops *fastboot_ops)
{
device->fastboot = fastboot_open(device->serial, fastboot_ops, NULL);
}
void device_fastboot_boot(struct device *device)
{
if (!device->fastboot) {
fprintf(stderr, "fastboot not opened\n");
return;
}
fastboot_boot(device->fastboot);
}
void device_fastboot_continue(struct device *device)
{
if (!device->fastboot) {
fprintf(stderr, "fastboot not opened\n");
return;
}
fastboot_continue(device->fastboot);
}
void device_fastboot_flash_reboot(struct device *device)
{
if (!device->fastboot) {
fprintf(stderr, "fastboot not opened\n");
return;
}
fastboot_flash(device->fastboot, "boot");
fastboot_reboot(device->fastboot);
}
@@ -382,7 +393,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);

View File

@@ -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;
@@ -72,8 +73,7 @@ struct device_user {
void device_add(struct device *device);
struct device *device_open(const char *board,
const char *username,
struct fastboot_ops *fastboot_ops);
const char *username);
void device_close(struct device *dev);
int device_power(struct device *device, bool on);
@@ -83,12 +83,15 @@ int device_write(struct device *device, const void *buf, size_t len);
void device_boot(struct device *device, const void *data, size_t len);
void device_fastboot_open(struct device *device,
struct fastboot_ops *fastboot_ops);
void device_fastboot_boot(struct device *device);
void device_fastboot_flash_reboot(struct device *device);
void device_send_break(struct device *device);
void device_list_devices(const char *username);
void device_info(const char *username, const void *data, size_t dlen);
void device_fastboot_continue(struct device *device);
bool device_is_running(struct device *device);
enum {
DEVICE_KEY_FASTBOOT,

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2018, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <stdbool.h>
@@ -195,6 +171,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);

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2018, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sys/socket.h>
#include <sys/types.h>
@@ -41,8 +17,8 @@
#include <termios.h>
#include <unistd.h>
#include "cdba-server.h"
#include "device.h"
#include "tty.h"
struct alpaca {
int alpaca_fd;

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2016-2018, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sys/types.h>
#include <ctype.h>
@@ -41,9 +17,10 @@
#include <termios.h>
#include <unistd.h>
#include "cdba-server.h"
#include "device.h"
#include "status.h"
#include "tty.h"
#include "watch.h"
struct cdb_assist {
char serial[9];

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2018, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sys/socket.h>
#include <sys/types.h>
@@ -42,6 +18,7 @@
#include "cdba-server.h"
#include "device.h"
#include "watch.h"
extern int h_errno;

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2021-2023, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sys/types.h>

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2023, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#define _GNU_SOURCE
#include <sys/socket.h>

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2023, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <ctype.h>
#include <err.h>

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2023, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#define _GNU_SOURCE
#include <ctype.h>

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2023, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <ctype.h>
#include <err.h>

39
drivers/local-gpio.h Normal file
View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023, Linaro Ltd.
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _LOCAL_GPIO_H_
#define _LOCAL_GPIO_H_
enum {
GPIO_POWER = 0, // Power input enable
GPIO_FASTBOOT_KEY, // Usually volume key
GPIO_POWER_KEY, // Key to power the device
GPIO_USB_DISCONNECT, // Simulate main USB connection
GPIO_COUNT
};
struct local_gpio_options {
struct {
char *chip;
bool present;
unsigned int offset;
bool active_low;
} gpios[GPIO_COUNT];
};
struct local_gpio {
struct local_gpio_options *options;
struct {
void *chip;
void *line;
} gpios[GPIO_COUNT];
};
int local_gpio_init(struct local_gpio *local_gpio);
int local_gpio_set_value(struct local_gpio *local_gpio, unsigned int gpio, bool on);
#endif /* _LOCAL_GPIO_H_ */

View File

@@ -2,31 +2,7 @@
* Copyright (c) 2021, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <sys/types.h>
@@ -45,6 +21,8 @@
#include "cdba-server.h"
#include "device.h"
#include "status.h"
#include "tty.h"
#include "watch.h"
enum qcomlt_parse_state {
STATE_,

Some files were not shown because too many files have changed in this diff Show More