parent
5735a34478
commit
fa668fe184
|
@ -1,3 +1,5 @@
|
|||
obj-y += board.o
|
||||
obj-y += clock.o
|
||||
obj-y += hostfile.o
|
||||
obj-y += console.o
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue