mirror of
https://github.com/linux-msm/cdba.git
synced 2026-02-25 13:11:56 -08:00
Compare commits
39 Commits
v1.0
...
topic/prot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
672eeb89c3 | ||
|
|
f4e95f6f0c | ||
|
|
8f668bde64 | ||
|
|
798a76ad62 | ||
|
|
ca5f95d6cd | ||
|
|
762879fd0c | ||
|
|
62dc594cb1 | ||
|
|
2f1caa28c0 | ||
|
|
f6bd2d01d7 | ||
|
|
bde90b4a15 | ||
|
|
b6c6807add | ||
|
|
1da135b08e | ||
|
|
efd1b44e74 | ||
|
|
baa48a82c2 | ||
|
|
98b4aa893a | ||
|
|
d678216fd7 | ||
|
|
68ca7e49b4 | ||
|
|
30e6838a12 | ||
|
|
f9c4d71650 | ||
|
|
266d885cde | ||
|
|
4a38c0e8e1 | ||
|
|
316119c473 | ||
|
|
fcada07889 | ||
|
|
65d867355e | ||
|
|
581f14d8f6 | ||
|
|
2c465e56dd | ||
|
|
d35abc800d | ||
|
|
5edc55cff8 | ||
|
|
43ed93357d | ||
|
|
b32d98f7a4 | ||
|
|
3269b8b891 | ||
|
|
0ad34da4f2 | ||
|
|
6d8ff75e31 | ||
|
|
cc91b34f3a | ||
|
|
81e46878ed | ||
|
|
c8e29e3400 | ||
|
|
130720a6df | ||
|
|
0a3d51e9c8 | ||
|
|
1cef583b11 |
54
README
54
README
@@ -5,6 +5,7 @@ attached using a CDB Assist [https://github.com/sonyxperiadev/CDB-Assist] or Con
|
|||||||
= Dependencies
|
= Dependencies
|
||||||
sudo apt-get install libudev-dev libyaml-dev libftdi1-dev pkg-config meson for debian systems
|
sudo apt-get install libudev-dev libyaml-dev libftdi1-dev pkg-config meson for debian systems
|
||||||
dnf install systemd-devel libyaml-devel libftdi1-devel pkg-config meson for fedora systems
|
dnf install systemd-devel libyaml-devel libftdi1-devel pkg-config meson for fedora systems
|
||||||
|
pacman -S libftdi libgpiod libyaml pkgconf meson for Arch systems
|
||||||
|
|
||||||
= Device side
|
= Device side
|
||||||
On the host with the CDB Assist or Conmux attached the "cdba-server" executable is run
|
On the host with the CDB Assist or Conmux attached the "cdba-server" executable is run
|
||||||
@@ -18,7 +19,7 @@ from sandbox/cdba/cdba-server. Available devices are read from $HOME/.cdba
|
|||||||
= Client side
|
= Client side
|
||||||
The client is invoked as:
|
The client is invoked as:
|
||||||
|
|
||||||
cdba -b <board> -h <host> [-c <power-cylce-count>] boot.img
|
cdba -b <board> -h <host> [-c <power-cylce-count>] [-s <status-fifo>] boot.img
|
||||||
|
|
||||||
<host> will be connected to using ssh and <board> will be selected for
|
<host> will be connected to using ssh and <board> will be selected for
|
||||||
operation. As the board's fastboot interface shows up the given boot.img will
|
operation. As the board's fastboot interface shows up the given boot.img will
|
||||||
@@ -31,9 +32,25 @@ If the optional -c is given, the board will upon receiving the tilde sequence
|
|||||||
restart the board the given number of times. Each time booting the given
|
restart the board the given number of times. Each time booting the given
|
||||||
boot.img.
|
boot.img.
|
||||||
|
|
||||||
|
The optional -s argument can be used to specify that a fifo should be created
|
||||||
|
and opened. cdba will request the server to start sending status/measurement
|
||||||
|
updates, which will be written to this fifo.
|
||||||
|
|
||||||
|
How to quit the console and close session: ctrl+a then q
|
||||||
|
|
||||||
|
= Server side
|
||||||
|
|
||||||
== Device configuration
|
== Device configuration
|
||||||
The list of attached devices is read from $HOME/.cdba and is YAML formatted.
|
The list of attached devices is read from $HOME/.cdba and is YAML formatted.
|
||||||
|
|
||||||
|
== Status command
|
||||||
|
|
||||||
|
The "status-cmd" property for a board specifies a command line that should be
|
||||||
|
executed to perform measurements and report status updates to the client. The
|
||||||
|
command is expected to run for the duration of the board session and should
|
||||||
|
produce a continuous stream of json-formatted lines of status updates according
|
||||||
|
to the format defined in this document.
|
||||||
|
|
||||||
=== Example
|
=== Example
|
||||||
devices:
|
devices:
|
||||||
- board: db2k
|
- board: db2k
|
||||||
@@ -110,3 +127,38 @@ devices:
|
|||||||
fastboot: cacafada
|
fastboot: cacafada
|
||||||
fastboot_set_active: true
|
fastboot_set_active: true
|
||||||
fastboot_key_timeout: 2
|
fastboot_key_timeout: 2
|
||||||
|
|
||||||
|
= Status messages
|
||||||
|
|
||||||
|
The status messages that are used by the client fifo and the server's status
|
||||||
|
command should be json-formatted, with one status update per line.
|
||||||
|
|
||||||
|
Each message should contain one timestamp member "ts", and one or more
|
||||||
|
measurement members. Like so:
|
||||||
|
|
||||||
|
{"ts":%d.%03d, "name": {["mv"|"ma"]: %u}(, "name2": {["mv"|"ma"]: %u})*}
|
||||||
|
|
||||||
|
The timestamp member ("ts"), should provide the time since first measurement in
|
||||||
|
decimal form with millisecond accuracy.
|
||||||
|
|
||||||
|
The key for the measurement members should be an identifier of the measured
|
||||||
|
resources, and the value should be an object with members for each unit
|
||||||
|
measured for the given resource and the measured value.
|
||||||
|
|
||||||
|
Valid units to report are "mv", "ma", and "mw".
|
||||||
|
|
||||||
|
Note that the cadence of measurement might differ between different items to be
|
||||||
|
measured, so not all status messages contains data for all items that can be
|
||||||
|
measured.
|
||||||
|
|
||||||
|
== Examples
|
||||||
|
|
||||||
|
Single resource "dc" measured at 20.271s, with voltage and current reported:
|
||||||
|
|
||||||
|
{"ts":20.271, "dc":{ "mv": 12165, "ma": 114}}
|
||||||
|
|
||||||
|
Multiple resources measured in a single status message, followed by single
|
||||||
|
resource measurement, all with voltage and current reported:
|
||||||
|
|
||||||
|
{"ts":38.341, "battery":{"mv":8023, "ma":725}, "vdd_cx":{"mv":750, "ma":466}}
|
||||||
|
{"ts":44.339, "battery":{"mv":8023, "ma":733}}
|
||||||
|
|||||||
87
cdba-power.c
Normal file
87
cdba-power.c
Normal 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;
|
||||||
|
}
|
||||||
226
cdba-server.c
226
cdba-server.c
@@ -2,34 +2,8 @@
|
|||||||
* Copyright (c) 2016-2018, Linaro Ltd.
|
* Copyright (c) 2016-2018, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#include <sys/time.h>
|
|
||||||
#include <alloca.h>
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -38,6 +12,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
#include "cdba-server.h"
|
#include "cdba-server.h"
|
||||||
#include "circ_buf.h"
|
#include "circ_buf.h"
|
||||||
@@ -45,40 +20,12 @@
|
|||||||
#include "device_parser.h"
|
#include "device_parser.h"
|
||||||
#include "fastboot.h"
|
#include "fastboot.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "watch.h"
|
||||||
|
|
||||||
static bool quit_invoked;
|
|
||||||
static const char *username;
|
static const char *username;
|
||||||
|
|
||||||
struct device *selected_device;
|
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)
|
static void fastboot_opened(struct fastboot *fb, void *data)
|
||||||
{
|
{
|
||||||
const uint8_t one = 1;
|
const uint8_t one = 1;
|
||||||
@@ -108,12 +55,14 @@ static struct fastboot_ops fastboot_ops = {
|
|||||||
|
|
||||||
static void msg_select_board(const void *param)
|
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) {
|
if (!selected_device) {
|
||||||
fprintf(stderr, "failed to open %s\n", (const char *)param);
|
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);
|
cdba_send(MSG_SELECT_BOARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,6 +93,12 @@ static void msg_fastboot_download(const void *data, size_t len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void msg_fastboot_continue(void)
|
||||||
|
{
|
||||||
|
device_fastboot_continue(selected_device);
|
||||||
|
cdba_send(MSG_FASTBOOT_CONTINUE);
|
||||||
|
}
|
||||||
|
|
||||||
void cdba_send_buf(int type, size_t len, const void *buf)
|
void cdba_send_buf(int type, size_t len, const void *buf)
|
||||||
{
|
{
|
||||||
struct msg msg = {
|
struct msg msg = {
|
||||||
@@ -210,7 +165,7 @@ static int handle_stdin(int fd, void *buf)
|
|||||||
// fprintf(stderr, "fastboot boot\n");
|
// fprintf(stderr, "fastboot boot\n");
|
||||||
break;
|
break;
|
||||||
case MSG_STATUS_UPDATE:
|
case MSG_STATUS_UPDATE:
|
||||||
device_print_status(selected_device);
|
device_status_enable(selected_device);
|
||||||
break;
|
break;
|
||||||
case MSG_VBUS_ON:
|
case MSG_VBUS_ON:
|
||||||
device_usb(selected_device, true);
|
device_usb(selected_device, true);
|
||||||
@@ -227,6 +182,9 @@ static int handle_stdin(int fd, void *buf)
|
|||||||
case MSG_BOARD_INFO:
|
case MSG_BOARD_INFO:
|
||||||
device_info(username, msg->data, msg->len);
|
device_info(username, msg->data, msg->len);
|
||||||
break;
|
break;
|
||||||
|
case MSG_FASTBOOT_CONTINUE:
|
||||||
|
msg_fastboot_continue();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "unk %d len %d\n", msg->type, msg->len);
|
fprintf(stderr, "unk %d len %d\n", msg->type, msg->len);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -238,124 +196,27 @@ static int handle_stdin(int fd, void *buf)
|
|||||||
return 0;
|
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)
|
static void sigpipe_handler(int signo)
|
||||||
{
|
{
|
||||||
quit_invoked = true;
|
watch_quit();
|
||||||
}
|
|
||||||
|
|
||||||
void watch_quit(void)
|
|
||||||
{
|
|
||||||
quit_invoked = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct timeval *timeoutp;
|
|
||||||
struct watch *w;
|
|
||||||
fd_set rfds;
|
|
||||||
int flags;
|
int flags;
|
||||||
int nfds;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
signal(SIGPIPE, sigpipe_handler);
|
signal(SIGPIPE, sigpipe_handler);
|
||||||
|
|
||||||
|
fprintf(stderr, "Starting cdba server\n");
|
||||||
|
|
||||||
username = getenv("CDBA_USER");
|
username = getenv("CDBA_USER");
|
||||||
|
if (!username)
|
||||||
|
username = getenv("USER");
|
||||||
|
if (!username)
|
||||||
|
username = "nobody";
|
||||||
|
|
||||||
|
openlog("cdba-server", 0, LOG_DAEMON);
|
||||||
|
|
||||||
ret = device_parser(".cdba");
|
ret = device_parser(".cdba");
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@@ -371,40 +232,7 @@ int main(int argc, char **argv)
|
|||||||
flags = fcntl(STDIN_FILENO, F_GETFL, 0);
|
flags = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||||
fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
|
fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
|
||||||
|
|
||||||
while (!quit_invoked) {
|
watch_run();
|
||||||
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:
|
|
||||||
|
|
||||||
/* if we got here, stdin/out/err might be not accessible anymore */
|
/* if we got here, stdin/out/err might be not accessible anymore */
|
||||||
ret = open("/dev/null", O_RDWR);
|
ret = open("/dev/null", O_RDWR);
|
||||||
|
|||||||
@@ -6,14 +6,6 @@
|
|||||||
|
|
||||||
#include "cdba.h"
|
#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);
|
void cdba_send_buf(int type, size_t len, const void *buf);
|
||||||
#define cdba_send(type) cdba_send_buf(type, 0, NULL)
|
#define cdba_send(type) cdba_send_buf(type, 0, NULL)
|
||||||
|
|
||||||
|
|||||||
111
cdba.c
111
cdba.c
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2016-2018, Linaro Ltd.
|
* Copyright (c) 2016-2018, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -51,6 +27,9 @@
|
|||||||
static bool quit;
|
static bool quit;
|
||||||
static bool fastboot_repeat;
|
static bool fastboot_repeat;
|
||||||
static bool fastboot_done;
|
static bool fastboot_done;
|
||||||
|
static bool fastboot_continue;
|
||||||
|
|
||||||
|
static int status_fd = -1;
|
||||||
|
|
||||||
static const char *fastboot_file;
|
static const char *fastboot_file;
|
||||||
|
|
||||||
@@ -338,6 +317,22 @@ static void request_power_off(void)
|
|||||||
list_add(&work_items, &work.node);
|
list_add(&work_items, &work.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void request_fastboot_continue_fn(struct work *work, int ssh_stdin)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = cdba_send(ssh_stdin, MSG_FASTBOOT_CONTINUE);
|
||||||
|
if (ret < 0)
|
||||||
|
err(1, "failed to send fastboot continue request");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void request_fastboot_continue(void)
|
||||||
|
{
|
||||||
|
static struct work work = { request_fastboot_continue_fn };
|
||||||
|
|
||||||
|
list_add(&work_items, &work.node);
|
||||||
|
}
|
||||||
|
|
||||||
struct fastboot_download_work {
|
struct fastboot_download_work {
|
||||||
struct work work;
|
struct work work;
|
||||||
|
|
||||||
@@ -398,12 +393,40 @@ static void request_fastboot_files(void)
|
|||||||
|
|
||||||
static void handle_status_update(const void *data, size_t len)
|
static void handle_status_update(const void *data, size_t len)
|
||||||
{
|
{
|
||||||
char *str = alloca(len + 1);
|
if (status_fd < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
memcpy(str, data, len);
|
write(status_fd, data, len);
|
||||||
str[len] = '\n';
|
}
|
||||||
|
|
||||||
write(STDOUT_FILENO, str, len + 1);
|
static void status_enable_fn(struct work *work, int ssh_stdin)
|
||||||
|
{
|
||||||
|
cdba_send(ssh_stdin, MSG_STATUS_UPDATE);
|
||||||
|
|
||||||
|
free(work);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void status_pipe_open(const char *path)
|
||||||
|
{
|
||||||
|
struct work *work;
|
||||||
|
int ret;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
ret = mkfifo(path, 0600);
|
||||||
|
if (ret < 0 && errno != EEXIST)
|
||||||
|
err(1, "failed to create fifo %s", path);
|
||||||
|
|
||||||
|
fd = open(path, O_RDWR | O_NONBLOCK);
|
||||||
|
if (fd < 0)
|
||||||
|
err(1, "failed to open fifo %s", path);
|
||||||
|
|
||||||
|
status_fd = fd;
|
||||||
|
|
||||||
|
/* Queue a MSG_STATUS_UPDATE request */
|
||||||
|
work = malloc(sizeof(*work));
|
||||||
|
work->fn = status_enable_fn;
|
||||||
|
|
||||||
|
list_add(&work_items, &work->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_list_devices(const void *data, size_t len)
|
static void handle_list_devices(const void *data, size_t len)
|
||||||
@@ -502,10 +525,14 @@ static int handle_message(struct circ_buf *buf)
|
|||||||
case MSG_FASTBOOT_PRESENT:
|
case MSG_FASTBOOT_PRESENT:
|
||||||
if (*(uint8_t*)msg->data) {
|
if (*(uint8_t*)msg->data) {
|
||||||
// printf("======================================== MSG_FASTBOOT_PRESENT(on)\n");
|
// printf("======================================== MSG_FASTBOOT_PRESENT(on)\n");
|
||||||
if (!fastboot_done || fastboot_repeat)
|
if (fastboot_continue) {
|
||||||
|
request_fastboot_continue();
|
||||||
|
fastboot_continue = false;
|
||||||
|
} else if (!fastboot_done || fastboot_repeat) {
|
||||||
request_fastboot_files();
|
request_fastboot_files();
|
||||||
else
|
} else {
|
||||||
quit = true;
|
quit = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fastboot_done = true;
|
fastboot_done = true;
|
||||||
// printf("======================================== MSG_FASTBOOT_PRESENT(off)\n");
|
// printf("======================================== MSG_FASTBOOT_PRESENT(off)\n");
|
||||||
@@ -527,6 +554,9 @@ static int handle_message(struct circ_buf *buf)
|
|||||||
handle_board_info(msg->data, msg->len);
|
handle_board_info(msg->data, msg->len);
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
case MSG_FASTBOOT_CONTINUE:
|
||||||
|
// printf("======================================== MSG_FASTBOOT_CONTINUE\n");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "unk %d len %d\n", msg->type, msg->len);
|
fprintf(stderr, "unk %d len %d\n", msg->type, msg->len);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -555,7 +585,7 @@ static void usage(void)
|
|||||||
extern const char *__progname;
|
extern const char *__progname;
|
||||||
|
|
||||||
fprintf(stderr, "usage: %s -b <board> -h <host> [-t <timeout>] "
|
fprintf(stderr, "usage: %s -b <board> -h <host> [-t <timeout>] "
|
||||||
"[-T <inactivity-timeout>] boot.img\n",
|
"[-T <inactivity-timeout>] <boot.img>\n",
|
||||||
__progname);
|
__progname);
|
||||||
fprintf(stderr, "usage: %s -i -b <board> -h <host>\n",
|
fprintf(stderr, "usage: %s -i -b <board> -h <host>\n",
|
||||||
__progname);
|
__progname);
|
||||||
@@ -577,6 +607,7 @@ int main(int argc, char **argv)
|
|||||||
struct timeval timeout_total_tv;
|
struct timeval timeout_total_tv;
|
||||||
struct termios *orig_tios;
|
struct termios *orig_tios;
|
||||||
const char *server_binary = "cdba-server";
|
const char *server_binary = "cdba-server";
|
||||||
|
const char *status_pipe = NULL;
|
||||||
int timeout_inactivity = 0;
|
int timeout_inactivity = 0;
|
||||||
int timeout_total = 600;
|
int timeout_total = 600;
|
||||||
struct work *next;
|
struct work *next;
|
||||||
@@ -597,7 +628,7 @@ int main(int argc, char **argv)
|
|||||||
int opt;
|
int opt;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "b:c:C:h:ilRt:S:T:")) != -1) {
|
while ((opt = getopt(argc, argv, "b:c:C:h:ilRt:S:s:T:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'b':
|
case 'b':
|
||||||
board = optarg;
|
board = optarg;
|
||||||
@@ -623,6 +654,9 @@ int main(int argc, char **argv)
|
|||||||
case 'S':
|
case 'S':
|
||||||
server_binary = optarg;
|
server_binary = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
status_pipe = optarg;
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
timeout_total = atoi(optarg);
|
timeout_total = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
@@ -639,13 +673,15 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
switch (verb) {
|
switch (verb) {
|
||||||
case CDBA_BOOT:
|
case CDBA_BOOT:
|
||||||
if (optind >= argc || !board)
|
if (optind > argc || !board)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
fastboot_file = argv[optind];
|
fastboot_file = argv[optind];
|
||||||
if (lstat(fastboot_file, &sb))
|
if (!fastboot_file)
|
||||||
|
fastboot_continue = true;
|
||||||
|
else if (lstat(fastboot_file, &sb))
|
||||||
err(1, "unable to read \"%s\"", fastboot_file);
|
err(1, "unable to read \"%s\"", fastboot_file);
|
||||||
if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
|
else if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
|
||||||
errx(1, "\"%s\" is not a regular file", fastboot_file);
|
errx(1, "\"%s\" is not a regular file", fastboot_file);
|
||||||
|
|
||||||
request_select_board(board);
|
request_select_board(board);
|
||||||
@@ -661,6 +697,9 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (status_pipe)
|
||||||
|
status_pipe_open(status_pipe);
|
||||||
|
|
||||||
ret = fork_ssh(host, server_binary, ssh_fds);
|
ret = fork_ssh(host, server_binary, ssh_fds);
|
||||||
if (ret)
|
if (ret)
|
||||||
err(1, "failed to connect to \"%s\"", host);
|
err(1, "failed to connect to \"%s\"", host);
|
||||||
|
|||||||
1
cdba.h
1
cdba.h
@@ -30,6 +30,7 @@ enum {
|
|||||||
MSG_SEND_BREAK,
|
MSG_SEND_BREAK,
|
||||||
MSG_LIST_DEVICES,
|
MSG_LIST_DEVICES,
|
||||||
MSG_BOARD_INFO,
|
MSG_BOARD_INFO,
|
||||||
|
MSG_FASTBOOT_CONTINUE,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ case $CC in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
pacman -Syu --noconfirm \
|
pacman -Syu --noconfirm \
|
||||||
libftdi-compat \
|
libftdi \
|
||||||
libyaml \
|
libyaml \
|
||||||
systemd-libs \
|
systemd-libs \
|
||||||
libgpiod \
|
libgpiod \
|
||||||
|
|||||||
26
circ_buf.c
26
circ_buf.c
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2018, Linaro Ltd.
|
* Copyright (c) 2018, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|||||||
26
circ_buf.h
26
circ_buf.h
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2018, Linaro Ltd.
|
* Copyright (c) 2018, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#ifndef __CIRC_BUF_H__
|
#ifndef __CIRC_BUF_H__
|
||||||
#define __CIRC_BUF_H__
|
#define __CIRC_BUF_H__
|
||||||
|
|||||||
8
config-samples/sample11.yaml
Normal file
8
config-samples/sample11.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
devices:
|
||||||
|
- board: myboard
|
||||||
|
name: "My Board"
|
||||||
|
alpaca: /dev/ttyACM0
|
||||||
|
console: /dev/ttyUSB0
|
||||||
|
fastboot: cacafada
|
||||||
|
status-cmd: /usr/bin/sample-measure-app --sample-rate 100 /dev/measure0
|
||||||
13
config-samples/sample12.yaml
Normal file
13
config-samples/sample12.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
devices:
|
||||||
|
- board: myboard
|
||||||
|
name: "My Board"
|
||||||
|
description: |
|
||||||
|
My Awesome board
|
||||||
|
console: /dev/ttyABC0
|
||||||
|
fastboot: cacafada
|
||||||
|
fastboot_set_active: true
|
||||||
|
fastboot_key_timeout: 2
|
||||||
|
laurent:
|
||||||
|
server: laurent.lan
|
||||||
|
relay: 5
|
||||||
28
console.c
28
console.c
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2020, Linaro Ltd.
|
* Copyright (c) 2020, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -37,6 +13,8 @@
|
|||||||
|
|
||||||
#include "cdba-server.h"
|
#include "cdba-server.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "tty.h"
|
||||||
|
#include "watch.h"
|
||||||
|
|
||||||
struct console {
|
struct console {
|
||||||
int console_fd;
|
int console_fd;
|
||||||
|
|||||||
106
device.c
106
device.c
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2016-2018, Linaro Ltd.
|
* Copyright (c) 2016-2018, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -39,12 +15,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
#include "cdba-server.h"
|
#include "cdba-server.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "fastboot.h"
|
#include "fastboot.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "ppps.h"
|
#include "ppps.h"
|
||||||
|
#include "status-cmd.h"
|
||||||
|
#include "watch.h"
|
||||||
|
|
||||||
#define ARRAY_SIZE(x) ((sizeof(x)/sizeof((x)[0])))
|
#define ARRAY_SIZE(x) ((sizeof(x)/sizeof((x)[0])))
|
||||||
|
|
||||||
@@ -115,9 +94,10 @@ static bool device_check_access(struct device *device,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int device_power_off(struct device *device);
|
||||||
|
|
||||||
struct device *device_open(const char *board,
|
struct device *device_open(const char *board,
|
||||||
const char *username,
|
const char *username)
|
||||||
struct fastboot_ops *fastboot_ops)
|
|
||||||
{
|
{
|
||||||
struct device *device;
|
struct device *device;
|
||||||
|
|
||||||
@@ -126,11 +106,17 @@ struct device *device_open(const char *board,
|
|||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syslog(LOG_INFO, "user %s asked for non-existing board %s", username, board);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
found:
|
found:
|
||||||
if (!device_check_access(device, username))
|
if (!device_check_access(device, username)) {
|
||||||
|
syslog(LOG_INFO, "user %s access denied to the board %s", username, board);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
syslog(LOG_INFO, "user %s opening board %s", username, board);
|
||||||
|
|
||||||
assert(device->console_ops);
|
assert(device->console_ops);
|
||||||
assert(device->console_ops->open);
|
assert(device->console_ops->open);
|
||||||
@@ -148,11 +134,21 @@ found:
|
|||||||
if (!device->console)
|
if (!device->console)
|
||||||
errx(1, "failed to open 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)
|
if (device->usb_always_on)
|
||||||
device_usb(device, true);
|
device_usb(device, true);
|
||||||
|
|
||||||
device->fastboot = fastboot_open(device->serial, fastboot_ops, NULL);
|
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,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)
|
static int device_power_on(struct device *device)
|
||||||
{
|
{
|
||||||
if (!device || !device_has_control(device, power))
|
if (!device || !device_has_control(device, power))
|
||||||
@@ -260,10 +261,18 @@ int device_power(struct device *device, bool on)
|
|||||||
return device_power_off(device);
|
return device_power_off(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_print_status(struct device *device)
|
void device_status_enable(struct device *device)
|
||||||
{
|
{
|
||||||
if (device_has_control(device, print_status))
|
if (device->status_enabled)
|
||||||
device_control(device, print_status);
|
return;
|
||||||
|
|
||||||
|
if (device_has_control(device, status_enable))
|
||||||
|
device_control(device, status_enable);
|
||||||
|
|
||||||
|
if (device->status_cmd)
|
||||||
|
status_cmd_open(device);
|
||||||
|
|
||||||
|
device->status_enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_usb(struct device *device, bool on)
|
void device_usb(struct device *device, bool on)
|
||||||
@@ -282,13 +291,36 @@ int device_write(struct device *device, const void *buf, size_t len)
|
|||||||
return device_console(device, write, buf, 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)
|
void device_fastboot_boot(struct device *device)
|
||||||
{
|
{
|
||||||
|
if (!device->fastboot) {
|
||||||
|
fprintf(stderr, "fastboot not opened\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
fastboot_boot(device->fastboot);
|
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)
|
void device_fastboot_flash_reboot(struct device *device)
|
||||||
{
|
{
|
||||||
|
if (!device->fastboot) {
|
||||||
|
fprintf(stderr, "fastboot not opened\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
fastboot_flash(device->fastboot, "boot");
|
fastboot_flash(device->fastboot, "boot");
|
||||||
fastboot_reboot(device->fastboot);
|
fastboot_reboot(device->fastboot);
|
||||||
}
|
}
|
||||||
@@ -300,6 +332,11 @@ void device_boot(struct device *device, const void *data, size_t len)
|
|||||||
fastboot_set_active(device->fastboot, device->set_active);
|
fastboot_set_active(device->fastboot, device->set_active);
|
||||||
fastboot_download(device->fastboot, data, len);
|
fastboot_download(device->fastboot, data, len);
|
||||||
device->boot(device);
|
device->boot(device);
|
||||||
|
|
||||||
|
if (device->status_enabled && !device->usb_always_on) {
|
||||||
|
warnx("disabling USB, use ^A V to enable");
|
||||||
|
device_usb(device, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_send_break(struct device *device)
|
void device_send_break(struct device *device)
|
||||||
@@ -356,7 +393,8 @@ void device_close(struct device *dev)
|
|||||||
{
|
{
|
||||||
if (!dev->usb_always_on)
|
if (!dev->usb_always_on)
|
||||||
device_usb(dev, false);
|
device_usb(dev, false);
|
||||||
device_power(dev, false);
|
if (!dev->power_always_on)
|
||||||
|
device_power(dev, false);
|
||||||
|
|
||||||
if (device_has_control(dev, close))
|
if (device_has_control(dev, close))
|
||||||
device_control(dev, close);
|
device_control(dev, close);
|
||||||
|
|||||||
17
device.h
17
device.h
@@ -17,7 +17,7 @@ struct control_ops {
|
|||||||
int (*power)(struct device *dev, bool on);
|
int (*power)(struct device *dev, bool on);
|
||||||
void (*usb)(struct device *dev, bool on);
|
void (*usb)(struct device *dev, bool on);
|
||||||
void (*key)(struct device *device, int key, bool asserted);
|
void (*key)(struct device *device, int key, bool asserted);
|
||||||
void (*print_status)(struct device *dev);
|
void (*status_enable)(struct device *dev);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct console_ops {
|
struct console_ops {
|
||||||
@@ -41,11 +41,14 @@ struct device {
|
|||||||
unsigned voltage;
|
unsigned voltage;
|
||||||
bool tickle_mmc;
|
bool tickle_mmc;
|
||||||
bool usb_always_on;
|
bool usb_always_on;
|
||||||
|
bool power_always_on;
|
||||||
struct fastboot *fastboot;
|
struct fastboot *fastboot;
|
||||||
unsigned int fastboot_key_timeout;
|
unsigned int fastboot_key_timeout;
|
||||||
int state;
|
int state;
|
||||||
bool has_power_key;
|
bool has_power_key;
|
||||||
|
|
||||||
|
bool status_enabled;
|
||||||
|
|
||||||
void (*boot)(struct device *);
|
void (*boot)(struct device *);
|
||||||
|
|
||||||
const struct control_ops *control_ops;
|
const struct control_ops *control_ops;
|
||||||
@@ -56,6 +59,8 @@ struct device {
|
|||||||
void *cdb;
|
void *cdb;
|
||||||
void *console;
|
void *console;
|
||||||
|
|
||||||
|
char *status_cmd;
|
||||||
|
|
||||||
struct list_head node;
|
struct list_head node;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,22 +73,25 @@ struct device_user {
|
|||||||
void device_add(struct device *device);
|
void device_add(struct device *device);
|
||||||
|
|
||||||
struct device *device_open(const char *board,
|
struct device *device_open(const char *board,
|
||||||
const char *username,
|
const char *username);
|
||||||
struct fastboot_ops *fastboot_ops);
|
|
||||||
void device_close(struct device *dev);
|
void device_close(struct device *dev);
|
||||||
int device_power(struct device *device, bool on);
|
int device_power(struct device *device, bool on);
|
||||||
|
|
||||||
void device_print_status(struct device *device);
|
void device_status_enable(struct device *device);
|
||||||
void device_usb(struct device *device, bool on);
|
void device_usb(struct device *device, bool on);
|
||||||
int device_write(struct device *device, const void *buf, size_t len);
|
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_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_boot(struct device *device);
|
||||||
void device_fastboot_flash_reboot(struct device *device);
|
void device_fastboot_flash_reboot(struct device *device);
|
||||||
void device_send_break(struct device *device);
|
void device_send_break(struct device *device);
|
||||||
void device_list_devices(const char *username);
|
void device_list_devices(const char *username);
|
||||||
void device_info(const char *username, const void *data, size_t dlen);
|
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 {
|
enum {
|
||||||
DEVICE_KEY_FASTBOOT,
|
DEVICE_KEY_FASTBOOT,
|
||||||
@@ -97,6 +105,7 @@ extern const struct control_ops ftdi_gpio_ops;
|
|||||||
extern const struct control_ops local_gpio_ops;
|
extern const struct control_ops local_gpio_ops;
|
||||||
extern const struct control_ops external_ops;
|
extern const struct control_ops external_ops;
|
||||||
extern const struct control_ops qcomlt_dbg_ops;
|
extern const struct control_ops qcomlt_dbg_ops;
|
||||||
|
extern const struct control_ops laurent_ops;
|
||||||
|
|
||||||
extern const struct console_ops conmux_console_ops;
|
extern const struct console_ops conmux_console_ops;
|
||||||
extern const struct console_ops console_ops;
|
extern const struct console_ops console_ops;
|
||||||
|
|||||||
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2018, Linaro Ltd.
|
* Copyright (c) 2018, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -139,6 +115,11 @@ static void parse_board(struct device_parser *dp)
|
|||||||
if (dev->control_options)
|
if (dev->control_options)
|
||||||
set_control_ops(dev, &ftdi_gpio_ops);
|
set_control_ops(dev, &ftdi_gpio_ops);
|
||||||
continue;
|
continue;
|
||||||
|
} else if (!strcmp(key, "laurent")) {
|
||||||
|
dev->control_options = laurent_ops.parse_options(dp);
|
||||||
|
if (dev->control_options)
|
||||||
|
set_control_ops(dev, &laurent_ops);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_parser_expect(dp, YAML_SCALAR_EVENT, value, TOKEN_LENGTH);
|
device_parser_expect(dp, YAML_SCALAR_EVENT, value, TOKEN_LENGTH);
|
||||||
@@ -193,6 +174,10 @@ static void parse_board(struct device_parser *dp)
|
|||||||
dev->ppps_path = strdup(value);
|
dev->ppps_path = strdup(value);
|
||||||
} else if (!strcmp(key, "ppps3_path")) {
|
} else if (!strcmp(key, "ppps3_path")) {
|
||||||
dev->ppps3_path = strdup(value);
|
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 {
|
} else {
|
||||||
fprintf(stderr, "device parser: unknown key \"%s\"\n", key);
|
fprintf(stderr, "device parser: unknown key \"%s\"\n", key);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2018, Linaro Ltd.
|
* Copyright (c) 2018, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -41,8 +17,8 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "cdba-server.h"
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "tty.h"
|
||||||
|
|
||||||
struct alpaca {
|
struct alpaca {
|
||||||
int alpaca_fd;
|
int alpaca_fd;
|
||||||
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2016-2018, Linaro Ltd.
|
* Copyright (c) 2016-2018, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -41,8 +17,10 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "cdba-server.h"
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "status.h"
|
||||||
|
#include "tty.h"
|
||||||
|
#include "watch.h"
|
||||||
|
|
||||||
struct cdb_assist {
|
struct cdb_assist {
|
||||||
char serial[9];
|
char serial[9];
|
||||||
@@ -99,7 +77,7 @@ static void cdb_parser_bool(struct cdb_assist *cdb, const char *key, bool set)
|
|||||||
for (i = 0; i < 5; i++)
|
for (i = 0; i < 5; i++)
|
||||||
if (strcmp(key, sz_keys[i]) == 0)
|
if (strcmp(key, sz_keys[i]) == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
cdb->vbat = set;
|
cdb->vbat = set;
|
||||||
@@ -125,7 +103,7 @@ static void cdb_parser_voltage(struct cdb_assist *cdb, unsigned set, unsigned ac
|
|||||||
cdb->voltage_actual = actual;
|
cdb->voltage_actual = actual;
|
||||||
cdb->voltage_set = set;
|
cdb->voltage_set = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdb_parser_vref(struct cdb_assist *cdb, unsigned vref)
|
static void cdb_parser_vref(struct cdb_assist *cdb, unsigned vref)
|
||||||
{
|
{
|
||||||
cdb->vref = vref;
|
cdb->vref = vref;
|
||||||
@@ -223,7 +201,7 @@ static void cdb_parser_push(struct cdb_assist *cdb, char ch)
|
|||||||
case STATE_key_of:
|
case STATE_key_of:
|
||||||
if (ch == 'f')
|
if (ch == 'f')
|
||||||
cdb_parser_bool(cdb, cdb->key, false);
|
cdb_parser_bool(cdb, cdb->key, false);
|
||||||
cdb->state = STATE_;
|
cdb->state = STATE_;
|
||||||
break;
|
break;
|
||||||
case STATE_key_value:
|
case STATE_key_value:
|
||||||
if (isdigit(ch)) {
|
if (isdigit(ch)) {
|
||||||
@@ -338,23 +316,37 @@ static void cdb_gpio(struct cdb_assist *cdb, int gpio, bool on)
|
|||||||
cdb_ctrl_write(cdb, &cmd[gpio][on], 1);
|
cdb_ctrl_write(cdb, &cmd[gpio][on], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdb_assist_print_status(struct device *dev)
|
static void cdb_assist_print_status(void *data)
|
||||||
|
{
|
||||||
|
struct cdb_assist *cdb = data;
|
||||||
|
struct status_value vbat[] = {
|
||||||
|
{
|
||||||
|
.unit = STATUS_MV,
|
||||||
|
.value = cdb->voltage_set,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.unit = STATUS_MA,
|
||||||
|
.value = cdb->current_actual,
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
struct status_value vref[] = {
|
||||||
|
{
|
||||||
|
.unit = STATUS_MV,
|
||||||
|
.value = cdb->vref,
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
status_send_values("vbat", vbat);
|
||||||
|
status_send_values("vref", vref);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cdb_assist_status_enable(struct device *dev)
|
||||||
{
|
{
|
||||||
struct cdb_assist *cdb = dev->cdb;
|
struct cdb_assist *cdb = dev->cdb;
|
||||||
char buf[128];
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = sprintf(buf, "%umV %umA%s%s%s%s%s ref: %umV",
|
watch_timer_add(1000, cdb_assist_print_status, cdb);
|
||||||
cdb->voltage_set,
|
|
||||||
cdb->current_actual,
|
|
||||||
cdb->vbat ? " vbat" : "",
|
|
||||||
cdb->vbus ? " vbus" : "",
|
|
||||||
cdb->btn[0] ? " btn1" : "",
|
|
||||||
cdb->btn[1] ? " btn2" : "",
|
|
||||||
cdb->btn[2] ? " btn3" : "",
|
|
||||||
cdb->vref);
|
|
||||||
|
|
||||||
cdba_send_buf(MSG_STATUS_UPDATE, n, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdb_set_voltage(struct cdb_assist *cdb, unsigned mV)
|
static void cdb_set_voltage(struct cdb_assist *cdb, unsigned mV)
|
||||||
@@ -384,7 +376,7 @@ const struct control_ops cdb_assist_ops = {
|
|||||||
.open = cdb_assist_open,
|
.open = cdb_assist_open,
|
||||||
.close = cdb_assist_close,
|
.close = cdb_assist_close,
|
||||||
.power = cdb_assist_power,
|
.power = cdb_assist_power,
|
||||||
.print_status = cdb_assist_print_status,
|
.status_enable = cdb_assist_status_enable,
|
||||||
.usb = cdb_assist_usb,
|
.usb = cdb_assist_usb,
|
||||||
.key = cdb_assist_key,
|
.key = cdb_assist_key,
|
||||||
};
|
};
|
||||||
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2018, Linaro Ltd.
|
* Copyright (c) 2018, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -42,6 +18,7 @@
|
|||||||
|
|
||||||
#include "cdba-server.h"
|
#include "cdba-server.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "watch.h"
|
||||||
|
|
||||||
extern int h_errno;
|
extern int h_errno;
|
||||||
|
|
||||||
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2021-2023, Linaro Ltd.
|
* Copyright (c) 2021-2023, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -2,31 +2,7 @@
|
|||||||
* Copyright (c) 2023, Linaro Ltd.
|
* Copyright (c) 2023, Linaro Ltd.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user