summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-07-05 18:01:59 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-07-05 18:01:59 +0200
commitfa668fe1849d75c7f62e4fed0ab9f71ddbba61e5 (patch)
tree31ef1c1e62cf8eeab80bb767c6fe1758c408af06
parent5735a344786aa5b266c4eeac9ba8ddf7a2650e7b (diff)
downloadbarebox-fa668fe1849d75c7f62e4fed0ab9f71ddbba61e5.tar.gz
barebox-fa668fe1849d75c7f62e4fed0ab9f71ddbba61e5.tar.xz
svn_rev_502
complete multiple console support
-rw-r--r--arch/linux/board/Makefile2
-rw-r--r--arch/linux/lib/common.c47
-rw-r--r--common/Kconfig5
-rw-r--r--common/Makefile2
-rw-r--r--common/console.c54
-rw-r--r--common/startup.c6
-rw-r--r--drivers/serial/linux_console.c41
-rw-r--r--include/asm-linux/arch-linux/linux.h10
-rw-r--r--include/common.h6
-rw-r--r--include/console.h10
-rw-r--r--include/linux/types.h2
-rw-r--r--include/net.h2
-rw-r--r--include/param.h5
-rw-r--r--net/net.c2
14 files changed, 127 insertions, 67 deletions
diff --git a/arch/linux/board/Makefile b/arch/linux/board/Makefile
index 6c23dc7a49..af62aa25dc 100644
--- a/arch/linux/board/Makefile
+++ b/arch/linux/board/Makefile
@@ -1,3 +1,5 @@
obj-y += board.o
obj-y += clock.o
obj-y += hostfile.o
+obj-y += console.o
+
diff --git a/arch/linux/lib/common.c b/arch/linux/lib/common.c
index b44bdad403..2611a1b7cd 100644
--- a/arch/linux/lib/common.c
+++ b/arch/linux/lib/common.c
@@ -25,9 +25,9 @@ static void rawmode(void)
{
tcgetattr(0, &term_orig);
term_vi = term_orig;
- term_vi.c_lflag &= (~ICANON & ~ECHO & ~ISIG); // leave ISIG ON- allow intr's
+ term_vi.c_lflag &= (~ICANON & ~ECHO & ~ISIG);
term_vi.c_iflag &= (~IXON & ~ICRNL);
- term_vi.c_oflag &= (~ONLCR);
+ term_vi.c_oflag |= (ONLCR);
term_vi.c_cc[VMIN] = 1;
term_vi.c_cc[VTIME] = 0;
erase_char = term_vi.c_cc[VERASE];
@@ -51,19 +51,19 @@ void linux_putc (const char c)
fflush(stdout);
}
-int linux_tstc (void)
+int linux_tstc (int fd)
{
fd_set rfds;
struct timeval tv;
int ret;
FD_ZERO(&rfds);
- FD_SET(0, &rfds);
+ FD_SET(fd, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 100;
- ret = select(1, &rfds, NULL, NULL, &tv);
+ ret = select(fd + 1, &rfds, NULL, NULL, &tv);
if (ret)
return 1;
@@ -148,9 +148,9 @@ ssize_t linux_write(int fd, const void *buf, size_t count)
return write(fd, buf, count);
}
-off_t linux_lseek(int fildes, off_t offset)
+off_t linux_lseek(int fd, off_t offset)
{
- return lseek(fildes, offset, SEEK_SET);
+ return lseek(fd, offset, SEEK_SET);
}
void flush_cache (unsigned long dummy1, unsigned long dummy2)
@@ -232,7 +232,11 @@ static void print_usage(const char *prgname)
" -e <file> Map a file to U-Boot. With this option files are mapped as\n"
" /dev/env0 ... /dev/envx and thus are used as default\n"
" environment. An empty file generated with dd will do to get\n"
-" started wth an empty environment\n",
+" started wth an empty environment\n"
+" -O <file> Register file as a console capable of doing stdout. File can\n"
+" be a regular file or a fifo.\n"
+" -I <file> Register file as a console capable of doing stdin. File can\n"
+" be a regular file or a fifo.\n",
prgname
);
}
@@ -240,9 +244,8 @@ static void print_usage(const char *prgname)
int main(int argc, char *argv[])
{
void *ram;
- int opt;
+ int opt, ret, fd;
int malloc_size = 1024 * 1024;
- int ret;
ram = malloc(malloc_size);
if (!ram) {
@@ -251,7 +254,7 @@ int main(int argc, char *argv[])
}
mem_malloc_init(ram, ram + malloc_size);
- while ((opt = getopt(argc, argv, "hi:e:")) != -1) {
+ while ((opt = getopt(argc, argv, "hi:e:I:O:")) != -1) {
switch (opt) {
case 'h':
print_usage(basename(argv[0]));
@@ -273,9 +276,31 @@ int main(int argc, char *argv[])
if (ret)
exit(1);
break;
+ case 'O':
+ fd = open(optarg, O_WRONLY);
+ if (fd < 0) {
+ perror("open");
+ exit(1);
+ }
+
+ u_boot_register_console("cout", -1, fd);
+ break;
+ case 'I':
+ fd = open(optarg, O_RDWR);
+ if (fd < 0) {
+ perror("open");
+ exit(1);
+ }
+
+ u_boot_register_console("cin", fd, -1);
+ break;
+ default:
+ exit(1);
}
}
+ u_boot_register_console("console", 1, 0);
+
rawmode();
start_uboot();
diff --git a/common/Kconfig b/common/Kconfig
index dae6251e5e..d8a04356f0 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -105,11 +105,6 @@ config CMD_CONSOLE
bool
prompt "coninfo"
-config CMD_ENV
- bool
- default y
- prompt "getenv/setenv"
-
config CMD_HELP
bool
default y
diff --git a/common/Makefile b/common/Makefile
index 6978253a4d..2a1e929c40 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -29,7 +29,7 @@ obj-y += clock.o
obj-y += command.o
obj-y += console.o
obj-y += partition.o
-obj-$(CONFIG_CMD_ENV) += env.o
+obj-y += env.o
obj-y += startup.o
obj-y += misc.o
obj-y += getopt.o
diff --git a/common/console.c b/common/console.c
index 2a22206859..ca11a514e7 100644
--- a/common/console.c
+++ b/common/console.c
@@ -25,6 +25,7 @@
#include <common.h>
#include <stdarg.h>
#include <malloc.h>
+#include <param.h>
#include <console.h>
#include <exports.h>
#include <serial.h>
@@ -33,16 +34,49 @@
static struct console_device *first_console;
+static int console_std_set(struct device_d *dev, struct param_d *param, const char *val)
+{
+ struct console_device *cdev = dev->type_data;
+ unsigned int flag = 0, i = 0;
+
+ if (strchr(val, 'i') && cdev->f_caps & CONSOLE_STDIN) {
+ cdev->active[i++] = 'i';
+ flag |= CONSOLE_STDIN;
+ }
+
+ if (strchr(val, 'o') && cdev->f_caps & CONSOLE_STDOUT) {
+ cdev->active[i++] = 'o';
+ flag |= CONSOLE_STDOUT;
+ }
+
+ if (strchr(val, 'e') && cdev->f_caps & CONSOLE_STDERR) {
+ cdev->active[i++] = 'e';
+ flag |= CONSOLE_STDERR;
+ }
+
+ cdev->active[i] = 0;
+ cdev->f_active = flag;
+
+ return 0;
+}
+
int console_register(struct console_device *newcdev)
{
struct console_device *cdev = first_console;
+ struct device_d *dev = newcdev->dev;
- if (!first_console) {
+ newcdev->active_param.set = console_std_set;
+ newcdev->active_param.name = "active";
+ newcdev->active_param.value = newcdev->active;
+ dev_add_param(dev, &newcdev->active_param);
+ console_std_set(dev, &newcdev->active_param, "ioe");
+
+ if (!first_console) {
first_console = newcdev;
- return 0;
- }
+ return 0;
+ }
- while (1) {
+ while (1) {
if (!cdev->next) {
cdev->next = newcdev;
return 0;
@@ -57,7 +91,7 @@ int getc (void)
while (1) {
if (!cdev)
cdev = first_console;
- if (cdev->flags & CONSOLE_STDIN && cdev->tstc(cdev))
+ if (cdev->f_active & CONSOLE_STDIN && cdev->tstc(cdev))
return cdev->getc(cdev);
cdev = cdev->next;
}
@@ -77,7 +111,7 @@ int tstc(void)
struct console_device *cdev = first_console;
while (cdev) {
- if (cdev->flags & CONSOLE_STDIN && cdev->tstc(cdev))
+ if (cdev->f_active & CONSOLE_STDIN && cdev->tstc(cdev))
return 1;
cdev = cdev->next;
}
@@ -90,7 +124,7 @@ void console_putc(unsigned int ch, char c)
struct console_device *cdev = first_console;
while (cdev) {
- if (cdev->flags & ch)
+ if (cdev->f_active & ch)
cdev->putc(cdev, c);
cdev = cdev->next;
}
@@ -112,12 +146,14 @@ void console_puts(unsigned int ch, const char *str)
struct console_device *cdev = first_console;
while (cdev) {
- if (cdev->flags & ch) {
+ if (cdev->f_active & ch) {
const char *s = str;
while (*s) {
cdev->putc(cdev, *s);
- if (*s++ == '\n')
+ if (*s == '\n') {
cdev->putc(cdev, '\r');
+ }
+ s++;
}
}
cdev = cdev->next;
diff --git a/common/startup.c b/common/startup.c
index 7a1fe9ed1e..c731672b30 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -140,12 +140,6 @@ void start_uboot (void)
run_command("exec /env/init", 0);
}
-// run_command("eth0.ip=172.0.0.2", 0);
-// run_command("eth0.mac=80:81:82:83:84:85", 0);
-// run_command("eth0.serverip=172.0.0.1", 0);
-// run_command("eth0.gateway=172.0.0.1", 0);
-// run_command("eth0.netmask=255.255.255.0", 0);
-
/* main_loop() can return to retry autoboot, if so just run it again. */
for (;;) {
main_loop ();
diff --git a/drivers/serial/linux_console.c b/drivers/serial/linux_console.c
index a7f9e8b12e..eab2f5c3be 100644
--- a/drivers/serial/linux_console.c
+++ b/drivers/serial/linux_console.c
@@ -7,27 +7,40 @@
static void linux_console_putc(struct console_device *cdev, char c)
{
- linux_putc(c);
+ struct device_d *dev = cdev->dev;
+ struct linux_console_data *d = dev->platform_data;
+
+ linux_write(d->stdoutfd, &c, 1);
}
static int linux_console_tstc(struct console_device *cdev)
{
- return linux_tstc();
+ struct device_d *dev = cdev->dev;
+ struct linux_console_data *d = dev->platform_data;
+
+ return linux_tstc(d->stdinfd);
}
static int linux_console_getc(struct console_device *cdev)
{
- return linux_getc();
+ struct device_d *dev = cdev->dev;
+ struct linux_console_data *d = dev->platform_data;
+ char c;
+
+ linux_read(d->stdinfd, &c, 1);
+
+ return c;
}
static int linux_console_probe(struct device_d *dev)
{
struct console_device *cdev;
+ struct linux_console_data *data = dev->platform_data;
cdev = malloc(sizeof(struct console_device));
dev->type_data = cdev;
cdev->dev = dev;
- cdev->flags = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
+ cdev->f_caps = data->flags;
cdev->tstc = linux_console_tstc;
cdev->putc = linux_console_putc;
cdev->getc = linux_console_getc;
@@ -37,33 +50,15 @@ static int linux_console_probe(struct device_d *dev)
return 0;
}
-
static struct driver_d linux_console_driver = {
.name = "console",
.probe = linux_console_probe,
.type = DEVICE_TYPE_CONSOLE,
};
-static struct device_d linux_console_device = {
- .name = "console",
- .id = "cs0",
- .type = DEVICE_TYPE_CONSOLE,
-};
-
-#if 0
-static struct device_d linux_console_device1 = {
- .name = "console",
- .id = "cs1",
- .type = DEVICE_TYPE_CONSOLE,
-};
-#endif
-
static int console_init(void)
{
- register_driver(&linux_console_driver);
- register_device(&linux_console_device);
-// register_device(&linux_console_device1);
- return 0;
+ return register_driver(&linux_console_driver);
}
console_initcall(console_init);
diff --git a/include/asm-linux/arch-linux/linux.h b/include/asm-linux/arch-linux/linux.h
index 401914e7fa..09376413e9 100644
--- a/include/asm-linux/arch-linux/linux.h
+++ b/include/asm-linux/arch-linux/linux.h
@@ -10,6 +10,14 @@ ssize_t linux_write(int fd, const void *buf, size_t count);
off_t linux_lseek(int fildes, off_t offset);
int linux_getc (void);
void linux_putc (const char c);
-int linux_tstc(void);
+int linux_tstc(int fd);
+
+int u_boot_register_console(char *name_template, int stdinfd, int stdoutfd);
+
+struct linux_console_data {
+ int stdinfd;
+ int stdoutfd;
+ unsigned int flags;
+};
#endif /* __ASM_ARCH_LINUX_H */
diff --git a/include/common.h b/include/common.h
index b81eb5b3d0..ac29e0667e 100644
--- a/include/common.h
+++ b/include/common.h
@@ -30,12 +30,6 @@
#undef _LINUX_CONFIG_H
#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
-typedef unsigned char uchar;
-typedef volatile unsigned long vu_long;
-typedef volatile unsigned short vu_short;
-typedef volatile unsigned char vu_char;
-typedef unsigned long IPaddr_t;
-
#include <config.h>
#include <linux/bitops.h>
#include <linux/types.h>
diff --git a/include/console.h b/include/console.h
index 4b0f93b4c1..7553756fbd 100644
--- a/include/console.h
+++ b/include/console.h
@@ -24,17 +24,25 @@
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
+#include <param.h>
+
#define CONSOLE_STDIN (1 << 0)
#define CONSOLE_STDOUT (1 << 1)
#define CONSOLE_STDERR (1 << 2)
struct console_device {
struct device_d *dev;
- unsigned long flags;
+
int (*tstc)(struct console_device *cdev);
void (*putc)(struct console_device *cdev, char c);
int (*getc)(struct console_device *cdev);
struct console_device *next;
+
+ unsigned char f_caps;
+ unsigned char f_active;
+
+ struct param_d active_param;
+ char active[4];
};
int console_register(struct console_device *cdev);
diff --git a/include/linux/types.h b/include/linux/types.h
index df4808fcdf..5e9213614d 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -86,7 +86,7 @@ typedef unsigned int u_int;
typedef unsigned long u_long;
/* sysv */
-typedef unsigned char unchar;
+typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
diff --git a/include/net.h b/include/net.h
index a2e11850a3..7bc92ce838 100644
--- a/include/net.h
+++ b/include/net.h
@@ -12,7 +12,7 @@
#ifndef __NET_H__
#define __NET_H__
-#include <common.h>
+#include <linux/types.h>
#include <param.h>
#include <asm/byteorder.h> /* for nton* / ntoh* stuff */
diff --git a/include/param.h b/include/param.h
index f69ced29ae..fe4468ed2c 100644
--- a/include/param.h
+++ b/include/param.h
@@ -1,14 +1,17 @@
#ifndef PARAM_H
#define PARAM_H
+#include <linux/types.h>
+
#define PARAM_FLAG_RO (1 << 0)
struct device_d;
+typedef unsigned long IPaddr_t;
struct param_d {
char* (*get)(struct device_d *, struct param_d *param);
int (*set)(struct device_d *, struct param_d *param, const char *val);
- ulong flags;
+ unsigned int flags;
char *name;
struct param_d *next;
char *value;
diff --git a/net/net.c b/net/net.c
index 24767eac93..795264519a 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1587,7 +1587,7 @@ int string_to_enet_addr(const char *str, char *enetaddr)
ulong reg;
char *e;
- if (strlen(str) != 17)
+ if (!str || strlen(str) != 17)
return -1;
if (str[2] != ':' || str[5] != ':' || str[8] != ':' ||