Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ from sandbox/cdba/cdba-server. Available devices are read from $HOME/.cdba
= Client side
The client is invoked as:

cdba -b <board> -h <host> [-c <power-cylce-count>] [-s <status-fifo>] 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
operation. As the board's fastboot interface shows up the given boot.img will
be transfered and booted on the device.
operation. As the board's fastboot interface shows up the given boot.img
will be transfered and booted on the device. If <host> is omitted, the
cdba-server is started locally without using ssh. If [boot.img] is omitted,
"fastboot continue" is run to boot the installed operating system.

The board will execute until the key sequence ^A q is invoked or the board
outputs a sequence of 20 ~ (tilde) chards in a row.
Expand Down
39 changes: 23 additions & 16 deletions cdba.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ static int fork_ssh(const char *host, const char *cmd, int *pipes)
close(piped_stderr[0]);
close(piped_stderr[1]);

execl("/usr/bin/ssh", "ssh", host, cmd, NULL);
err(1, "launching ssh failed");
if (host) {
execlp("ssh", "ssh", host, cmd, NULL);
err(1, "launching ssh failed");
} else {
execlp(cmd, cmd, NULL);
err(1, "launching cdba-server failed");
}
default:
close(piped_stdin[0]);
close(piped_stdout[1]);
Expand Down Expand Up @@ -583,12 +588,12 @@ static void usage(void)
{
extern const char *__progname;

fprintf(stderr, "usage: %s -b <board> -h <host> [-t <timeout>] "
"[-T <inactivity-timeout>] <boot.img>\n",
fprintf(stderr, "usage: %s -b <board> [-h <host>] [-t <timeout>] "
"[-T <inactivity-timeout>] [boot.img]\n",
__progname);
fprintf(stderr, "usage: %s -i -b <board> -h <host>\n",
fprintf(stderr, "usage: %s -i -b <board> [-h <host>]\n",
__progname);
fprintf(stderr, "usage: %s -l -h <host>\n",
fprintf(stderr, "usage: %s -l [-h <host>]\n",
__progname);
exit(1);
}
Expand All @@ -604,6 +609,7 @@ int main(int argc, char **argv)
bool power_cycle_on_timeout = true;
struct timeval timeout_inactivity_tv;
struct timeval timeout_total_tv;
struct timeval *timeout = NULL;
struct termios *orig_tios;
const char *server_binary = "cdba-server";
const char *status_pipe = NULL;
Expand Down Expand Up @@ -667,9 +673,6 @@ int main(int argc, char **argv)
}
}

if (!host)
usage();

switch (verb) {
case CDBA_BOOT:
if (optind > argc || !board)
Expand Down Expand Up @@ -707,6 +710,8 @@ int main(int argc, char **argv)

timeout_total_tv = get_timeout(timeout_total);
timeout_inactivity_tv = get_timeout(timeout_inactivity);
if (timeout_total || timeout_inactivity)
timeout = &tv;

while (!quit) {
if (received_power_off || reached_timeout) {
Expand Down Expand Up @@ -744,14 +749,16 @@ int main(int argc, char **argv)
if (!list_empty(&work_items))
FD_SET(ssh_fds[0], &wfds);

gettimeofday(&now, NULL);
if (timeout_inactivity && timercmp(&timeout_inactivity_tv, &timeout_total_tv, <)) {
timersub(&timeout_inactivity_tv, &now, &tv);
} else {
timersub(&timeout_total_tv, &now, &tv);
if (timeout) {
gettimeofday(&now, NULL);
if (timeout_inactivity && (!timeout_total ||
timercmp(&timeout_inactivity_tv, &timeout_total_tv, <))) {
timersub(&timeout_inactivity_tv, &now, timeout);
} else {
timersub(&timeout_total_tv, &now, timeout);
}
}

ret = select(nfds + 1, &rfds, &wfds, NULL, &tv);
ret = select(nfds + 1, &rfds, &wfds, NULL, timeout);
#if 0
printf("select: %d (%c%c%c)\n", ret, FD_ISSET(STDIN_FILENO, &rfds) ? 'X' : '-',
FD_ISSET(ssh_fds[1], &rfds) ? 'X' : '-',
Expand Down
Loading