r2881 - trunk/src/target/u-boot/patches

laforge at sita.openmoko.org laforge at sita.openmoko.org
Sat Sep 1 11:37:42 CEST 2007


Author: laforge
Date: 2007-09-01 11:37:39 +0200 (Sat, 01 Sep 2007)
New Revision: 2881

Added:
   trunk/src/target/u-boot/patches/uboot-serial_terminal.patch
Log:
* add initial version of serial terminal patch (can be used for passthrough).


Added: trunk/src/target/u-boot/patches/uboot-serial_terminal.patch
===================================================================
--- trunk/src/target/u-boot/patches/uboot-serial_terminal.patch	2007-09-01 09:36:57 UTC (rev 2880)
+++ trunk/src/target/u-boot/patches/uboot-serial_terminal.patch	2007-09-01 09:37:39 UTC (rev 2881)
@@ -0,0 +1,405 @@
+This patch adds a 'cu' like serial terminal command to u-boot
+using which you can access other serial ports from the system console.
+
+Index: u-boot/common/serial.c
+===================================================================
+--- u-boot.orig/common/serial.c
++++ u-boot/common/serial.c
+@@ -59,6 +59,16 @@
+ #else
+ 		return &serial0_device;
+ #endif
++#elif defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440) || defined(CONFIG_S3C2442)
++#if defined(CONFIG_SERIAL1)
++	return &s3c24xx_serial0_device;
++#elif defined(CONFIG_SERIAL2)
++	return &s3c24xx_serial1_device;
++#elif defined(CONFIG_SERIAL3)
++	return &s3c24xx_serial2_device;
++#else
++#error "CONFIG_SERIAL? missing."
++#endif
+ #else
+ #error No default console
+ #endif
+@@ -110,6 +120,13 @@
+ 	serial_register(&eserial4_device);
+ #endif
+ #endif /* CFG_NS16550_SERIAL */
++
++#if defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440) || defined(CONFIG_S3C2442)
++	serial_register(&s3c24xx_serial0_device);
++	serial_register(&s3c24xx_serial1_device);
++	serial_register(&s3c24xx_serial2_device);
++#endif
++
+ 	serial_assign (default_serial_console ()->name);
+ }
+ 
+Index: u-boot/cpu/arm920t/s3c24x0/serial.c
+===================================================================
+--- u-boot.orig/cpu/arm920t/s3c24x0/serial.c
++++ u-boot/cpu/arm920t/s3c24x0/serial.c
+@@ -52,9 +52,40 @@
+ #error "Bad: you didn't configure serial ..."
+ #endif
+ 
+-void serial_setbrg (void)
++#if defined(CONFIG_SERIAL_MULTI)
++#include <serial.h>
++
++/* Multi serial device functions */
++#define DECLARE_S3C_SERIAL_FUNCTIONS(port) \
++    int  s3serial##port##_init (void) {\
++	serial_setbrg_dev(port);\
++	return(0);}\
++    void s3serial##port##_setbrg (void) {\
++	serial_setbrg_dev(port);}\
++    int  s3serial##port##_getc (void) {\
++	return serial_getc_dev(port);}\
++    int  s3serial##port##_tstc (void) {\
++	return serial_tstc_dev(port);}\
++    void s3serial##port##_putc (const char c) {\
++	serial_putc_dev(port, c);}\
++    void s3serial##port##_puts (const char *s) {\
++	serial_puts_dev(port, s);}
++
++#define INIT_S3C_SERIAL_STRUCTURE(port,name,bus) {\
++	name,\
++	bus,\
++	s3serial##port##_init,\
++	s3serial##port##_setbrg,\
++	s3serial##port##_getc,\
++	s3serial##port##_tstc,\
++	s3serial##port##_putc,\
++	s3serial##port##_puts, }
++
++#endif /* CONFIG_SERIAL_MULTI */
++
++void _serial_setbrg(const int dev_index)
+ {
+-	S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR);
++	S3C24X0_UART * const uart = S3C24X0_GetBase_UART(dev_index);
+ 	int i;
+ 	unsigned int reg = 0;
+ 
+@@ -78,7 +109,20 @@
+ #endif
+ 	for (i = 0; i < 100; i++);
+ }
++#if defined(CONFIG_SERIAL_MULTI)
++static inline void
++serial_setbrg_dev(unsigned int dev_index)
++{
++	_serial_setbrg(dev_index);
++}
++#else
++void serial_setbrg(void)
++{
++	_serial_setbrg(UART_NR);
++}
++#endif
+ 
++#if !defined(CONFIG_SERIAL_MULTI)
+ /*
+  * Initialise the serial port with the given baudrate. The settings
+  * are always 8 data bits, no parity, 1 stop bit, no start bits.
+@@ -90,21 +134,33 @@
+ 
+ 	return (0);
+ }
++#endif
+ 
+ /*
+  * Read a single byte from the serial port. Returns 1 on success, 0
+  * otherwise. When the function is succesfull, the character read is
+  * written into its argument c.
+  */
+-int serial_getc (void)
++int _serial_getc (const int dev_index)
+ {
+-	S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR);
++	S3C24X0_UART * const uart = S3C24X0_GetBase_UART(dev_index);
+ 
+ 	/* wait for character to arrive */
+ 	while (!(uart->UTRSTAT & 0x1));
+ 
+ 	return uart->URXH & 0xff;
+ }
++#if defined(CONFIG_SERIAL_MULTI)
++static inline int serial_getc_dev(unsigned int dev_index)
++{
++	return _serial_getc(dev_index);
++}
++#else
++int serial_getc (void)
++{
++	return _serial_getc(UART_NR);
++}
++#endif
+ 
+ #ifdef CONFIG_HWFLOW
+ static int hwflow = 0; /* turned off by default */
+@@ -142,9 +198,9 @@
+ /*
+  * Output a single byte to the serial port.
+  */
+-void serial_putc (const char c)
++void _serial_putc (const char c, const int dev_index)
+ {
+-	S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR);
++	S3C24X0_UART * const uart = S3C24X0_GetBase_UART(dev_index);
+ #ifdef CONFIG_MODEM_SUPPORT
+ 	if (be_quiet)
+ 		return;
+@@ -165,24 +221,73 @@
+ 	if (c == '\n')
+ 		serial_putc ('\r');
+ }
++#if defined(CONFIG_SERIAL_MULTI)
++static inline void serial_putc_dev(unsigned int dev_index, const char c)
++{
++	_serial_putc(c, dev_index);
++}
++#else
++void serial_putc(const char c)
++{
++	_serial_putc(c, UART_NR);
++}
++#endif
++
+ 
+ /*
+  * Test whether a character is in the RX buffer
+  */
+-int serial_tstc (void)
++int _serial_tstc(const int dev_index)
+ {
+-	S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR);
++	S3C24X0_UART * const uart = S3C24X0_GetBase_UART(dev_index);
+ 
+ 	return uart->UTRSTAT & 0x1;
+ }
++#if defined(CONFIG_SERIAL_MULTI)
++static inline int
++serial_tstc_dev(unsigned int dev_index)
++{
++	return _serial_tstc(dev_index);
++}
++#else
++int serial_tstc(void)
++{
++	return _serial_tstc(UART_NR);
++}
++#endif
+ 
+-void
+-serial_puts (const char *s)
++void _serial_puts(const char *s, const int dev_index)
+ {
+ 	while (*s) {
+-		serial_putc (*s++);
++		_serial_putc (*s++, dev_index);
+ 	}
+ }
++#if defined(CONFIG_SERIAL_MULTI)
++static inline void
++serial_puts_dev(int dev_index, const char *s)
++{
++	_serial_puts(s, dev_index);
++}
++#else
++void
++serial_puts (const char *s)
++{
++	_serial_puts(s, UART_NR);
++}
++#endif
++
++#if defined(CONFIG_SERIAL_MULTI)
++DECLARE_S3C_SERIAL_FUNCTIONS(0);
++struct serial_device s3c24xx_serial0_device =
++	INIT_S3C_SERIAL_STRUCTURE(0, "s3ser0", "S3UART1");
++DECLARE_S3C_SERIAL_FUNCTIONS(1);
++struct serial_device s3c24xx_serial1_device =
++	INIT_S3C_SERIAL_STRUCTURE(1, "s3ser1", "S3UART2");
++DECLARE_S3C_SERIAL_FUNCTIONS(2);
++struct serial_device s3c24xx_serial2_device =
++	INIT_S3C_SERIAL_STRUCTURE(2, "s3ser2", "S3UART3");
++
++#endif /* CONFIG_SERIAL_MULTI */
+ 
+ #endif /* defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) ||
+ 	  defined(CONFIG_S3C2440) || defined (CONFIG_S3C2442) ||
+Index: u-boot/include/configs/neo1973_gta02.h
+===================================================================
+--- u-boot.orig/include/configs/neo1973_gta02.h
++++ u-boot/include/configs/neo1973_gta02.h
+@@ -61,7 +61,8 @@
+ /*
+  * select serial console configuration
+  */
+-#define CONFIG_SERIAL3          1	/* we use SERIAL 1 on GTA01 */
++#define CONFIG_SERIAL3          1	/* we use SERIAL 3 on GTA02 */
++#define CONFIG_SERIAL_MULTI	1
+ 
+ /* allow to overwrite serial and ethaddr */
+ #define CONFIG_ENV_OVERWRITE
+@@ -104,6 +105,7 @@
+ #define CONFIG_CMD_FAT
+ #define CONFIG_CMD_EXT2
+ #define CONFIG_CMD_LICENSE
++#define CONFIG_CMD_TERMINAL
+ 
+ #define CONFIG_BOOTDELAY	3
+ #define CONFIG_BOOTARGS    	""
+Index: u-boot/include/serial.h
+===================================================================
+--- u-boot.orig/include/serial.h
++++ u-boot/include/serial.h
+@@ -35,6 +35,11 @@
+ 
+ #endif
+ 
++#if defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440) || defined(CONFIG_S3C2442)
++extern struct serial_device s3c24xx_serial0_device;
++extern struct serial_device s3c24xx_serial1_device;
++extern struct serial_device s3c24xx_serial2_device;
++#endif
+ 
+ extern void serial_initialize(void);
+ extern void serial_devices_init(void);
+Index: u-boot/lib_arm/board.c
+===================================================================
+--- u-boot.orig/lib_arm/board.c
++++ u-boot/lib_arm/board.c
+@@ -345,6 +345,10 @@
+ #endif
+ 	}
+ 
++#ifdef CONFIG_SERIAL_MULTI
++	serial_initialize();
++#endif
++
+ 	devices_init ();	/* get the devices list going. */
+ 
+ #ifdef CONFIG_CMC_PU2
+Index: u-boot/common/Makefile
+===================================================================
+--- u-boot.orig/common/Makefile
++++ u-boot/common/Makefile
+@@ -39,7 +39,7 @@
+ 	  cmd_nand.o cmd_net.o cmd_nvedit.o \
+ 	  cmd_pci.o cmd_pcmcia.o cmd_portio.o \
+ 	  cmd_reginfo.o cmd_reiser.o cmd_sata.o cmd_scsi.o cmd_spi.o \
+-	  cmd_universe.o cmd_usb.o cmd_vfd.o \
++	  cmd_terminal.o cmd_universe.o cmd_usb.o cmd_vfd.o \
+ 	  command.o console.o cyclon2.o devices.o dlmalloc.o docecc.o \
+ 	  environment.o env_common.o \
+ 	  env_nand.o env_dataflash.o env_flash.o env_eeprom.o \
+Index: u-boot/common/cmd_terminal.c
+===================================================================
+--- /dev/null
++++ u-boot/common/cmd_terminal.c
+@@ -0,0 +1,101 @@
++/*
++ * (C) Copyright 2007 OpenMoko, Inc.
++ * Written by Harald Welte <laforge at openmoko.org>
++ *
++ * See file CREDITS for list of people who contributed to this
++ * project.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation; either version 2 of
++ * the License, or (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ * MA 02111-1307 USA
++ */
++
++/*
++ * Boot support
++ */
++#include <common.h>
++#include <command.h>
++#include <devices.h>
++
++#if defined(CONFIG_CMD_TERMINAL)
++
++int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[])
++{
++	int i, l;
++	int last_tilde = 0;
++	device_t *dev = NULL;
++
++	if (argc < 1)
++		return -1;
++
++	/* Scan for selected output/input device */
++	for (i = 1; i <= ListNumItems (devlist); i++) {
++		device_t *tmp = ListGetPtrToItem (devlist, i);
++		if (!strcmp(tmp->name, argv[1])) {
++			dev = tmp;
++			break;
++		}
++	}
++	if (!dev)
++		return -1;
++
++	serial_reinit_all();
++	printf("Entering terminal mode for port %s\n", dev->name);
++	puts("Use '~.' to leave the terminal and get back to u-boot\n");
++
++	while (1) {
++		int c;
++
++		/* read from console and display on serial port */
++		if (stdio_devices[0]->tstc()) {
++			c = stdio_devices[0]->getc();
++			if (last_tilde == 1) {
++				if (c == '.') {
++					putc(c);
++					break;
++				} else {
++					last_tilde = 0;
++					/* write the delayed tilde */
++					dev->putc('~');
++					/* fall-through to print current
++					 * character */
++				}
++			}
++			if (c == '~') {
++				last_tilde = 1;
++				puts("[u-boot]");
++				putc(c);
++			}
++			dev->putc(c);
++		}
++
++		/* read from serial port and display on console */
++		if (dev->tstc()) {
++			c = dev->getc();
++			putc(c);
++		}
++	}
++	return 0;
++}
++
++
++/***************************************************/
++
++U_BOOT_CMD(
++	terminal,	3,	1,	do_terminal,
++	"terminal - start terminal emulator\n",
++	""
++);
++
++#endif /* CONFIG_CMD_TERMINAL */





More information about the commitlog mailing list