diff --git a/arch/linux/board/Makefile b/arch/linux/board/Makefile index 6c23dc7..af62aa2 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 b44bdad..2611a1b 100644 --- a/arch/linux/lib/common.c +++ b/arch/linux/lib/common.c @@ -25,9 +25,9 @@ { 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 @@ 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 @@ 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 @@ " -e 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 Register file as a console capable of doing stdout. File can\n" +" be a regular file or a fifo.\n" +" -I 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 @@ 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 @@ } 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 @@ 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 dae6251..d8a0435 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -105,11 +105,6 @@ 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 6978253..2a1e929 100644 --- a/common/Makefile +++ b/common/Makefile @@ -29,7 +29,7 @@ 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 2a22206..ca11a51 100644 --- a/common/console.c +++ b/common/console.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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 @@ 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 @@ 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 @@ 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 @@ 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 7a1fe9e..c731672 100644 --- a/common/startup.c +++ b/common/startup.c @@ -140,12 +140,6 @@ 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 a7f9e8b..eab2f5c 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 @@ 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 401914e..0937641 100644 --- a/include/asm-linux/arch-linux/linux.h +++ b/include/asm-linux/arch-linux/linux.h @@ -10,6 +10,14 @@ 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 b81eb5b..ac29e06 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 #include #include diff --git a/include/console.h b/include/console.h index 4b0f93b..7553756 100644 --- a/include/console.h +++ b/include/console.h @@ -24,17 +24,25 @@ #ifndef _CONSOLE_H_ #define _CONSOLE_H_ +#include + #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 df4808f..5e92136 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -86,7 +86,7 @@ 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 a2e1185..7bc92ce 100644 --- a/include/net.h +++ b/include/net.h @@ -12,7 +12,7 @@ #ifndef __NET_H__ #define __NET_H__ -#include +#include #include #include /* for nton* / ntoh* stuff */ diff --git a/include/param.h b/include/param.h index f69ced2..fe4468e 100644 --- a/include/param.h +++ b/include/param.h @@ -1,14 +1,17 @@ #ifndef PARAM_H #define PARAM_H +#include + #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 24767ea..7952645 100644 --- a/net/net.c +++ b/net/net.c @@ -1587,7 +1587,7 @@ ulong reg; char *e; - if (strlen(str) != 17) + if (!str || strlen(str) != 17) return -1; if (str[2] != ':' || str[5] != ':' || str[8] != ':' ||