mirror of
https://github.com/linux-msm/cdba.git
synced 2026-02-25 13:11:56 -08:00
cdba-server: Make "console" handling generic
It's possible for devices that are automated using e.g. a CDB Assist to have console coming over a separate FTDI USB tty. Move the alpaca specific implementation of the "console" directive to device.c to make it generic. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
33
alpaca.c
33
alpaca.c
@@ -46,30 +46,10 @@
|
||||
|
||||
struct alpaca {
|
||||
int alpaca_fd;
|
||||
int console_fd;
|
||||
|
||||
struct termios alpaca_tios;
|
||||
struct termios console_tios;
|
||||
};
|
||||
|
||||
static int alpaca_console_data(int fd, void *data)
|
||||
{
|
||||
struct msg hdr;
|
||||
char buf[128];
|
||||
ssize_t n;
|
||||
|
||||
n = read(fd, buf, sizeof(buf));
|
||||
if (n < 0)
|
||||
return n;
|
||||
|
||||
hdr.type = MSG_CONSOLE;
|
||||
hdr.len = n;
|
||||
write(STDOUT_FILENO, &hdr, sizeof(hdr));
|
||||
write(STDOUT_FILENO, buf, n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *alpaca_open(struct device *dev)
|
||||
{
|
||||
struct alpaca *alpaca;
|
||||
@@ -80,12 +60,6 @@ void *alpaca_open(struct device *dev)
|
||||
if (alpaca->alpaca_fd < 0)
|
||||
err(1, "failed to open %s", dev->alpaca_dev);
|
||||
|
||||
alpaca->console_fd = tty_open(dev->console_dev, &alpaca->console_tios);
|
||||
if (alpaca->console_fd < 0)
|
||||
err(1, "failed to open %s", dev->console_dev);
|
||||
|
||||
watch_add_readfd(alpaca->console_fd, alpaca_console_data, alpaca);
|
||||
|
||||
return alpaca;
|
||||
}
|
||||
|
||||
@@ -140,10 +114,3 @@ int alpaca_power_off(struct device *dev)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int alpaca_write(struct device *dev, const void *buf, size_t len)
|
||||
{
|
||||
struct alpaca *alpaca = dev->cdb;
|
||||
|
||||
return write(alpaca->console_fd, buf, len);;
|
||||
}
|
||||
|
||||
1
alpaca.h
1
alpaca.h
@@ -8,6 +8,5 @@ struct alpaca;
|
||||
void *alpaca_open(struct device *dev);
|
||||
int alpaca_power_on(struct device *dev);
|
||||
int alpaca_power_off(struct device *dev);
|
||||
int alpaca_write(struct device *dev, const void *buf, size_t len);
|
||||
|
||||
#endif
|
||||
|
||||
39
device.c
39
device.c
@@ -39,6 +39,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cdba-server.h"
|
||||
#include "device.h"
|
||||
#include "fastboot.h"
|
||||
#include "list.h"
|
||||
@@ -77,6 +78,33 @@ static void device_lock(struct device *device)
|
||||
err(1, "failed to lock lockfile %s", lock);
|
||||
}
|
||||
|
||||
static int device_console_data(int fd, void *data)
|
||||
{
|
||||
struct msg hdr;
|
||||
char buf[128];
|
||||
ssize_t n;
|
||||
|
||||
n = read(fd, buf, sizeof(buf));
|
||||
if (n < 0)
|
||||
return n;
|
||||
|
||||
hdr.type = MSG_CONSOLE;
|
||||
hdr.len = n;
|
||||
write(STDOUT_FILENO, &hdr, sizeof(hdr));
|
||||
write(STDOUT_FILENO, buf, n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void console_open(struct device *device)
|
||||
{
|
||||
device->console_fd = tty_open(device->console_dev, &device->console_tios);
|
||||
if (device->console_fd < 0)
|
||||
err(1, "failed to open %s", device->console_dev);
|
||||
|
||||
watch_add_readfd(device->console_fd, device_console_data, device);
|
||||
}
|
||||
|
||||
struct device *device_open(const char *board,
|
||||
struct fastboot_ops *fastboot_ops)
|
||||
{
|
||||
@@ -98,6 +126,9 @@ found:
|
||||
if (!device->cdb)
|
||||
errx(1, "failed to open device controller");
|
||||
|
||||
if (device->console_dev)
|
||||
console_open(device);
|
||||
|
||||
device->fastboot = fastboot_open(device->serial, fastboot_ops, NULL);
|
||||
|
||||
return device;
|
||||
@@ -144,9 +175,13 @@ int device_write(struct device *device, const void *buf, size_t len)
|
||||
if (!device)
|
||||
return 0;
|
||||
|
||||
assert(device->write);
|
||||
if (device->console_fd) {
|
||||
return write(device->console_fd, buf, len);;
|
||||
} else {
|
||||
assert(device->write);
|
||||
|
||||
return device->write(device, buf, len);
|
||||
return device->write(device, buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
void device_fastboot_boot(struct device *device)
|
||||
|
||||
4
device.h
4
device.h
@@ -1,6 +1,7 @@
|
||||
#ifndef __DEVICE_H__
|
||||
#define __DEVICE_H__
|
||||
|
||||
#include <termios.h>
|
||||
#include "list.h"
|
||||
|
||||
struct cdb_assist;
|
||||
@@ -33,6 +34,9 @@ struct device {
|
||||
|
||||
void *cdb;
|
||||
|
||||
int console_fd;
|
||||
struct termios console_tios;
|
||||
|
||||
struct list_head node;
|
||||
};
|
||||
|
||||
|
||||
@@ -117,7 +117,6 @@ static void parse_board(struct device_parser *dp)
|
||||
dev->open = alpaca_open;
|
||||
dev->power_on = alpaca_power_on;
|
||||
dev->power_off = alpaca_power_off;
|
||||
dev->write = alpaca_write;
|
||||
} else if (!strcmp(key, "console")) {
|
||||
dev->console_dev = strdup(value);
|
||||
} else if (!strcmp(key, "voltage")) {
|
||||
|
||||
Reference in New Issue
Block a user