static void cfe_console_write(struct console *cons, const char *str,
		       unsigned int count)
{
	int i, last, written;

	for (i=0, last=0; i<count; i++) {
		if (!str[i])
			/* XXXKW can/should this ever happen? */
			return;
		if (str[i] == '\n') {
			do {
				written = cfe_write(cfe_cons_handle, &str[last], i-last);
				if (written < 0)
					;
				last += written;
			} while (last < i);
			while (cfe_write(cfe_cons_handle, "\r", 1) <= 0)
				;
		}
	}
	if (last != count) {
		do {
			written = cfe_write(cfe_cons_handle, &str[last], count-last);
			if (written < 0)
				;
			last += written;
		} while (last < count);
	}

}
Example #2
0
int console_write(unsigned char *buffer,int length)
{
    int res;

#if !CFG_MINIMAL_SIZE
    /*
     * Buffer text if requested
     */
    if (console_buffer_flg) {
	console_save(buffer,length);
	return length;
	}
#endif

    /*
     * Do nothing if no console
     */

    if (console_handle == -1) return -1;

    /*
     * Write text to device
     */

    for (;;) {
	res = cfe_write(console_handle,buffer,length);
	if (res < 0) break;
	buffer += res;
	length -= res;
	if (length == 0) break;
	}

    if (res < 0) return -1;
    return 0;			 
}
Example #3
0
void prom_putchar(char c)
{
	int ret;

	while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)
		;
}
Example #4
0
int
cfenet_put(struct iodesc *desc, void *pkt, size_t len)
{

    cfe_write(booted_dev_fd,pkt,len);

    return len;
}
Example #5
0
static int ui_cmd_settime(ui_cmdline_t *cmd,int argc,char *argv[])
{
    char *line;
    char *p;
    int hr,min,sec;
    int fd;
    uint8_t buf[12];
    int res=0;

    if ((line = cmd_getarg(cmd,0)) == NULL) {
        return ui_showusage(cmd);
    }

    /* convert colons to spaces for the gettoken routine */
    while ((p = strchr(line,':'))) *p = ' ';

    /* parse and check command-line args */
    hr = -1;
    min = -1;
    sec = -1;

    p = gettoken(&line);
    if (p) hr = atoi(p);
    p = gettoken(&line);
    if (p) min = atoi(p);
    p = gettoken(&line);
    if (p) sec = atoi(p);

    if ((hr < 0) || (hr > 23) ||
            (min < 0) || (min >= 60) ||
            (sec < 0) || (sec >= 60)) {
        return ui_showusage(cmd);
    }

    /*
     * hour-minute-second-month-day-year1-year2-(time/date flag)
     * time/date flag (offset 7) is used to let device know what
     * is being set.
     */
    buf[0] = hr;
    buf[1] = min;
    buf[2] = sec;
    buf[7] = 0x00;	/*SET_TIME = 0x00, SET_DATE = 0x01*/

    fd = cfe_open("clock0");
    if (fd < 0) {
        ui_showerror(fd,"could not open clock device");
        return fd;
    }

    res = cfe_write(fd,buf,8);
    if (res < 0) {
        ui_showerror(res,"could not set time");
    }
    cfe_close(fd);
    return 0;
}
Example #6
0
static void
cfe_cnputc(struct consdev *cp, int c)
{
	char cbuf;

	if (c == '\n')
		cfe_cnputc(cp, '\r');

	cbuf = c;
	while (cfe_write(conhandle, &cbuf, 1) == 0)
		continue;
}
Example #7
0
File: cfe.c Project: aircross/ray
int cfe_vprintk(const char *fmt, va_list args)
{
	static char buffer[1024];
	static DEFINE_SPINLOCK(lock);
	static const char pfx[] = "CFE-console: ";
	static const size_t pfx_len = sizeof(pfx) - 1;
	unsigned long flags;
	int len, cnt, pos;
	int handle;
	int res;

	if (!cfe_present())
		return -ENODEV;

	spin_lock_irqsave(&lock, flags);
	handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
	if (CFE_ISERR(handle)) {
		len = -EIO;
		goto out;
	}
	strcpy(buffer, pfx);
	len = vscnprintf(buffer + pfx_len,
			 sizeof(buffer) - pfx_len - 2,
			 fmt, args);
	len += pfx_len;
	/* The CFE console requires CR-LF line-ends.
	 * Add a CR, if we only terminate lines with a LF.
	 * This does only fix CR-LF at the end of the string.
	 * So for multiple lines, use multiple cfe_vprintk calls.
	 */
	if (len > 1 &&
	    buffer[len - 1] == '\n' && buffer[len - 2] != '\r') {
		buffer[len - 1] = '\r';
		buffer[len] = '\n';
		len += 1;
	}
	cnt = len;
	pos = 0;
	while (cnt > 0) {
		res = cfe_write(handle, buffer + pos, len - pos);
		if (CFE_ISERR(res)) {
			len = -EIO;
			goto out;
		}
		cnt -= res;
		pos += res;
	}
out:
	spin_unlock_irqrestore(&lock, flags);

	return len;
}
Example #8
0
File: cfe.c Project: behnaaz/jerl
int
outbyte (char c)
{
  int res;

  do
    {
      res = cfe_write (cfe_conshandle, &c, 1);
    }
  while (res == 0);
  if (c == '\n')
    outbyte ('\r');
  return 0;
}
Example #9
0
static void
bcm_cfe_eputc(int c)
{
	unsigned char	ch;
	int		handle;

	ch = (unsigned char) c;

	/* bcm_get_platform() cannot be used here, as we may be called
	 * from bcm_init_platform_data(). */
	if ((handle = bcm_platform_data.cfe_console) < 0)
		return;

	if (ch == '\n')
		early_putc('\r');

	while ((cfe_write(handle, &ch, 1)) == 0)
		continue;
}
Example #10
0
void __init cfe_die(char *fmt, ...)
{
	char msg[128];
	va_list ap;
	int handle;
	unsigned int count;

	va_start(ap, fmt);
	vsprintf(msg, fmt, ap);
	strcat(msg, "\r\n");

	if (cfe_seal != CFE_EPTSEAL)
		goto no_cfe;

	/* disable XKS01 so that CFE can access the registers */

#if defined(CONFIG_BMIPS4380)
	__write_32bit_c0_register($22, 3,
		__read_32bit_c0_register($22, 3) & ~BIT(12));
#elif defined(CONFIG_BMIPS5000)
	__write_32bit_c0_register($22, 5,
		__read_32bit_c0_register($22, 5) & ~BIT(8));
#endif

	handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
	if (handle < 0)
		goto no_cfe;

	cfe_write(handle, msg, strlen(msg));

	for (count = 0; count < 0x7fffffff; count++)
		mb();
	cfe_exit(0, 1);
	while (1)
		;

no_cfe:
	/* probably won't print anywhere useful */
	printk(KERN_ERR "%s", msg);
	BUG();

	va_end(ap);
}
Example #11
0
static void
cfe_tty_outwakeup(struct tty *tp)
{
	int len, written, rc;
	u_char buf[CFEBURSTLEN];

	for (;;) {
		len = ttydisc_getc(tp, buf, sizeof buf);
		if (len == 0)
			break;

		written = 0;
		while (written < len) {
			rc = cfe_write(conhandle, &buf[written], len - written);
			if (rc < 0)
				break;
			written += rc;
		}
	}
}
Example #12
0
static void console_flushbuffer(void)
{
    msgqueue_t *msg;
    char *buffer;
    int length;
    int res;

    /*
     * Remove console messages from the queue 
     */

    while ((msg = (msgqueue_t *) q_deqnext(&console_msgq))) {

	buffer = msg->data;
	length = msg->len;
	res = 0;

	/*
	 * Write each message to the console 
	 */

	for (;;) {
	    res = cfe_write(console_handle,buffer,length);
	    if (res < 0) break;
	    buffer += res;
	    length -= res;
	    if (length == 0) break;
	    }

	/*
	 * Free the storage
	 */

	KFREE(msg);
	}
}
Example #13
0
File: prom.c Project: janfj/dd-wrt
void prom_putchar(char c)
{
    while (cfe_write(cfe_cons_handle, &c, 1) == 0)
        ;
}
Example #14
0
static int ui_cmd_config1250(ui_cmdline_t *cmd,int argc,char *argv[])
{
    char *tok;
    int fh;
    uint8_t *base;
    int len;
    int res;

    tok = cmd_getarg(cmd, 0);
    if (!tok) {
	return ui_showusage(cmd);
	}

    if (argc > 1) {
	char *fname;
	cfe_loadargs_t *la = &cfe_loadargs;
	int res;
    
	fname = cmd_getarg(cmd, 1);
	if (!fname) {
	    return ui_showusage(cmd);
	    }

	/* Get the file using tftp and read it into a known location. */

	/* (From ui_flash.c):
         * We can't allocate the space from the heap to store the 
	 * file to download, because the heap may not be big enough.
	 * So, grab some unallocated memory at the 1MB line (we could
	 * also calculate something, but this will do for now).
	 * We assume the downloadable file will be no bigger than 4MB.
	 */

	/* Fill out the loadargs */

	la->la_flags = LOADFLG_NOISY;

	la->la_device = (char *) net_getparam(NET_DEVNAME);
	la->la_filesys = "tftp";
	la->la_filename = fname;

	/* Temporary: use a fixed memory buffer. */
	la->la_address = KERNADDR(FILE_STAGING_BUFFER);
	la->la_maxsize = FILE_STAGING_BUFFER_SIZE;;
	la->la_flags |= LOADFLG_SPECADDR;

	la->la_options = NULL;

	xprintf("Loader:raw Filesys:%s Dev:%s File:%s Options:%s\n",
		la->la_filesys, la->la_device, la->la_filename, la->la_options);

	res = cfe_load_program("raw", la);
	if (res < 0) {
	    xprintf("Could not load %s\n", fname);
	    return res;
	    }

	base = (uint8_t *)(la->la_address);
	len = res;
	}
    else {
	/* This code casts a function pointer to a byte pointer, which is
	   suspect in ANSI C but appears to work with the gnu MIPS tool
	   chain.  Changing the externs to, e.g., uint8_t * does not work
	   with PIC code (generates relocation errors). */

	base = (uint8_t *)download_start;
	len  = (uint8_t *)download_end - (uint8_t *)download_start;
	}
    xprintf("PCI download: base %p len %d\n", base, len);

    fh = cfe_open(tok);
    if (fh < 0) {
	xprintf("Could not open device: %s\n", cfe_errortext(fh));
	return fh;
	}

    res = cfe_write(fh, base, len);
    if (res != 0) {
	xprintf("Could not download device: %s\n", cfe_errortext(res));
	}

    cfe_close(fh);

    return res;
}
Example #15
0
static int ui_cmd_setdate(ui_cmdline_t *cmd,int argc,char *argv[])
{
    char *line;
    char *p;
    int dt,mo,yr,y2k;
    int fd;
    uint8_t buf[12];
    int res=0;

    if ((line = cmd_getarg(cmd,0)) == NULL) {
        return ui_showusage(cmd);
    }

    /* convert colons to spaces for the gettoken routine */

    while ((p = strchr(line,'/'))) *p = ' ';

    /* parse and check command-line args */

    dt = -1;
    mo = -1;
    yr = -1;

    p = gettoken(&line);
    if (p) mo = atoi(p);
    p = gettoken(&line);
    if (p) dt = atoi(p);
    p = gettoken(&line);
    if (p) yr = atoi(p);

    if ((mo <= 0) || (mo > 12) ||
            (dt <= 0) || (dt > 31) ||
            (yr < 1900) || (yr > 2099)) {
        return ui_showusage(cmd);
    }

    y2k = (yr >= 2000) ? 0x20 : 0x19;
    yr %= 100;

    /*
     * hour-minute-second-month-day-year1-year2-(time/date flag)
     * time/date flag (offset 7) is used to let device know what
     * is being set.
     */
    buf[3] = mo;
    buf[4] = dt;
    buf[5] = yr;
    buf[6] = y2k;
    buf[7] = 0x01; 	/*SET_TIME = 0x00, SET_DATE = 0x01*/

    fd = cfe_open("clock0");
    if (fd < 0) {
        ui_showerror(fd,"could not open clock device");
        return fd;
    }

    res = cfe_write(fd,buf,8);
    if (res < 0) {
        ui_showerror(res,"could not set date");
    }

    cfe_close(fd);
    return 0;
}
Example #16
0
void cfe_console_print(char *str)
{
	if (cfe_console_handle != -1) {
		cfe_write(cfe_console_handle, str, strlen(str));
	}
}