public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] Replace references to extern console_buffer with a function call
@ 2008-08-15 19:49 Peter Tyser
  2008-08-15 20:05 ` Wolfgang Denk
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Tyser @ 2008-08-15 19:49 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
---
 board/amcc/canyonlands/bootstrap.c |    2 +-
 board/amcc/katmai/cmd_katmai.c     |    2 +-
 board/amcc/sequoia/cmd_sequoia.c   |    2 +-
 board/amcc/yucca/cmd_yucca.c       |    2 +-
 board/eltec/bab7xx/misc.c          |    2 +-
 board/eltec/elppc/misc.c           |    2 +-
 board/eltec/mhpc/mhpc.c            |    4 +---
 board/hymod/input.c                |    7 ++++---
 common/cmd_bedbug.c                |    3 ++-
 common/cmd_dcr.c                   |    2 +-
 common/cmd_i2c.c                   |    2 +-
 common/cmd_mem.c                   |    2 +-
 common/cmd_nvedit.c                |    2 +-
 common/cmd_pci.c                   |    2 +-
 common/console.c                   |    7 +++++++
 common/hush.c                      |    2 +-
 common/main.c                      |    8 +++-----
 include/common.h                   |    1 +
 lib_arm/board.c                    |    2 +-
 lib_ppc/board.c                    |    2 +-
 20 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/board/amcc/canyonlands/bootstrap.c b/board/amcc/canyonlands/bootstrap.c
index 1d125b6..a853d62 100644
--- a/board/amcc/canyonlands/bootstrap.c
+++ b/board/amcc/canyonlands/bootstrap.c
@@ -84,7 +84,7 @@ static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
 	u8 *buf, b_nand;
 	int x, y, nbytes, selcfg;
-	extern char console_buffer[];
+	char *console_buffer = console_buffer_addr();
 
 	if (argc < 2) {
 		printf("Usage:\n%s\n", cmdtp->usage);
diff --git a/board/amcc/katmai/cmd_katmai.c b/board/amcc/katmai/cmd_katmai.c
index 703d225..b395b89 100644
--- a/board/amcc/katmai/cmd_katmai.c
+++ b/board/amcc/katmai/cmd_katmai.c
@@ -35,7 +35,7 @@ static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	uchar	chip;
 	ulong	data;
 	int	nbytes;
-	extern char console_buffer[];
+	char	*console_buffer = console_buffer_addr();
 
 	char sysClock[4];
 	char cpuClock[4];
diff --git a/board/amcc/sequoia/cmd_sequoia.c b/board/amcc/sequoia/cmd_sequoia.c
index 6b9043a..5f29c10 100644
--- a/board/amcc/sequoia/cmd_sequoia.c
+++ b/board/amcc/sequoia/cmd_sequoia.c
@@ -125,7 +125,7 @@ static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
 	u8 *buf, bNAND;
 	int x, y, nbytes, selcfg;
-	extern char console_buffer[];
+	char *console_buffer = console_buffer_addr();
 
 	if (argc < 2) {
 		printf("Usage:\n%s\n", cmdtp->usage);
diff --git a/board/amcc/yucca/cmd_yucca.c b/board/amcc/yucca/cmd_yucca.c
index e698b20..43a67c8 100644
--- a/board/amcc/yucca/cmd_yucca.c
+++ b/board/amcc/yucca/cmd_yucca.c
@@ -53,7 +53,7 @@ static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
 	uchar	chip;
 	ulong	data;
 	int	nbytes;
-	extern char console_buffer[];
+	char	*console_buffer = console_buffer_addr();
 
 	char sysClock[4];
 	char cpuClock[4];
diff --git a/board/eltec/bab7xx/misc.c b/board/eltec/bab7xx/misc.c
index 6a24807..6973a49 100644
--- a/board/eltec/bab7xx/misc.c
+++ b/board/eltec/bab7xx/misc.c
@@ -31,7 +31,6 @@
 #include "srom.h"
 
 /* imports  */
-extern char console_buffer[CFG_CBSIZE];
 extern int l2_cache_enable (int l2control);
 extern void *nvram_read (void *dest, const short src, size_t count);
 extern void nvram_write (short dest, const void *src, size_t count);
@@ -63,6 +62,7 @@ int misc_init_r (void)
     char buf[256];
     char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
 	     0, 0, 0, 0, 10, 11, 12, 13, 14, 15 };
+    char *console_buffer = console_buffer_addr();
     pci_dev_t bdf;
 
     char sromSYM[] = {
diff --git a/board/eltec/elppc/misc.c b/board/eltec/elppc/misc.c
index 5fb20ae..eb4c8e7 100644
--- a/board/eltec/elppc/misc.c
+++ b/board/eltec/elppc/misc.c
@@ -29,7 +29,6 @@
 #include "srom.h"
 
 /* imports  */
-extern char console_buffer[CFG_CBSIZE];
 extern int l2_cache_enable (int l2control);
 extern int eepro100_write_eeprom (struct eth_device *dev, int location,
 				  int addr_len, unsigned short data);
@@ -74,6 +73,7 @@ int misc_init_r (void)
 	char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
 		0, 0, 0, 0, 10, 11, 12, 13, 14, 15
 	};
+	char *console_buffer = console_buffer_addr();
 
 	/* Clock setting for MPC107 i2c */
 	mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b);
diff --git a/board/eltec/mhpc/mhpc.c b/board/eltec/mhpc/mhpc.c
index 3666791..c0f1f79 100644
--- a/board/eltec/mhpc/mhpc.c
+++ b/board/eltec/mhpc/mhpc.c
@@ -35,9 +35,6 @@
 #include "mpc8xx.h"
 #include <video_fb.h>
 
-/* imports from common/main.c */
-extern char console_buffer[CFG_CBSIZE];
-
 extern void eeprom_init (void);
 extern int eeprom_read (unsigned dev_addr, unsigned offset,
 			unsigned char *buffer, unsigned cnt);
@@ -157,6 +154,7 @@ int misc_init_r (void)
 	char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
 		0, 0, 0, 0, 10, 11, 12, 13, 14, 15
 	};
+	char *console_buffer = console_buffer_addr();
 	int i;
 
 	/* check revision data */
diff --git a/board/hymod/input.c b/board/hymod/input.c
index 63aa13c..9a751ed 100644
--- a/board/hymod/input.c
+++ b/board/hymod/input.c
@@ -23,12 +23,11 @@
 
 #include <common.h>
 
-/* imports from common/main.c */
-extern char console_buffer[CFG_CBSIZE];
-
 int
 hymod_get_serno (const char *prompt)
 {
+	char *console_buffer = console_buffer_addr();
+
 	for (;;) {
 		int n, serno;
 		char *p;
@@ -58,6 +57,8 @@ hymod_get_serno (const char *prompt)
 int
 hymod_get_ethaddr (void)
 {
+	char *console_buffer = console_buffer_addr();
+
 	for (;;) {
 		int n;
 
diff --git a/common/cmd_bedbug.c b/common/cmd_bedbug.c
index 94f7e08..6dcd267 100644
--- a/common/cmd_bedbug.c
+++ b/common/cmd_bedbug.c
@@ -19,7 +19,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 extern void show_regs __P ((struct pt_regs *));
 extern int run_command __P ((const char *, int));
-extern char console_buffer[];
 
 ulong dis_last_addr = 0;	/* Last address disassembled   */
 ulong dis_last_len = 20;	/* Default disassembler length */
@@ -125,6 +124,7 @@ int do_bedbug_asm (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 	unsigned long instr;	/* Machine code for text        */
 	char prompt[15];	/* Prompt string for user input */
 	int asm_err;		/* Error code from the assembler */
+	char *console_buffer = console_buffer_addr();
 
 	/* -------------------------------------------------- */
 	int rcode = 0;
@@ -219,6 +219,7 @@ void bedbug_main_loop (unsigned long addr, struct pt_regs *regs)
 	int rc = 0;		/* Result from run_command */
 	char prompt_str[20];	/* Prompt string          */
 	static char lastcommand[CFG_CBSIZE] = { 0 };	/* previous command */
+	char *console_buffer = console_buffer_addr();
 	/* -------------------------------------------------- */
 
 	if (bug_ctx.clear)
diff --git a/common/cmd_dcr.c b/common/cmd_dcr.c
index 439d07a..a6d2322 100644
--- a/common/cmd_dcr.c
+++ b/common/cmd_dcr.c
@@ -70,7 +70,7 @@ int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 
 	/* DCR's value */
 	int nbytes;
-	extern char console_buffer[];
+	char *console_buffer = console_buffer_addr();
 
 	/* Validate arguments */
 	if (argc < 2) {
diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
index 91bf25b..1f32646 100644
--- a/common/cmd_i2c.c
+++ b/common/cmd_i2c.c
@@ -418,7 +418,7 @@ mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[])
 	int	size = 1;
 	int	nbytes;
 	int	j;
-	extern char console_buffer[];
+	char	*console_buffer = console_buffer_addr();
 
 	if (argc != 3) {
 		printf ("Usage:\n%s\n", cmdtp->usage);
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 2606986..f3299bd 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -1012,7 +1012,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[])
 {
 	ulong	addr, i;
 	int	nbytes, size;
-	extern char console_buffer[];
+	char	*console_buffer = console_buffer_addr();
 
 	if (argc != 2) {
 		printf ("Usage:\n%s\n", cmdtp->usage);
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 7089706..0dc5790 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -416,7 +416,7 @@ int do_setenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 #if defined(CONFIG_CMD_ASKENV)
 int do_askenv ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	extern char console_buffer[CFG_CBSIZE];
+	char *console_buffer = console_buffer_addr();
 	char message[CFG_CBSIZE];
 	int size = CFG_CBSIZE - 1;
 	int len;
diff --git a/common/cmd_pci.c b/common/cmd_pci.c
index 8968701..bc4afb8 100644
--- a/common/cmd_pci.c
+++ b/common/cmd_pci.c
@@ -405,7 +405,7 @@ pci_cfg_modify (pci_dev_t bdf, ulong addr, ulong size, ulong value, int incrflag
 {
 	ulong	i;
 	int	nbytes;
-	extern char console_buffer[];
+	char	*console_buffer = console_buffer_addr();
 	uint	val4;
 	ushort  val2;
 	u_char	val1;
diff --git a/common/console.c b/common/console.c
index 1b095b1..daf0180 100644
--- a/common/console.c
+++ b/common/console.c
@@ -33,6 +33,8 @@ DECLARE_GLOBAL_DATA_PTR;
 int console_changed = 0;
 #endif
 
+static char console_buffer[CFG_CBSIZE];	/* console I/O buffer */
+
 #ifdef CFG_CONSOLE_IS_IN_ENV
 /*
  * if overwrite_console returns 1, the stdin, stderr and stdout
@@ -286,6 +288,11 @@ void clear_ctrlc (void)
 	ctrlc_was_pressed = 0;
 }
 
+char * console_buffer_addr(void)
+{
+	return console_buffer;
+}
+
 #ifdef CONFIG_MODEM_SUPPORT_DEBUG
 char	screen[1024];
 char *cursor = screen;
diff --git a/common/hush.c b/common/hush.c
index 75c18ce..9bcf62f 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1019,7 +1019,7 @@ static void get_user_input(struct in_str *i)
 	fflush(stdout);
 	i->p = the_command;
 #else
-	extern char console_buffer[CFG_CBSIZE];
+	char *console_buffer = console_buffer_addr();
 	int n;
 	static char the_command[CFG_CBSIZE];
 
diff --git a/common/main.c b/common/main.c
index 187ef8a..92c0394 100644
--- a/common/main.c
+++ b/common/main.c
@@ -65,8 +65,6 @@ static int abortboot(int);
 
 #undef DEBUG_PARSER
 
-char        console_buffer[CFG_CBSIZE];		/* console I/O buffer	*/
-
 static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen);
 static char erase_seq[] = "\b \b";		/* erase sequence	*/
 static char   tab_seq[] = "        ";		/* used to expand TABs	*/
@@ -445,7 +443,7 @@ void main_loop (void)
 
 		flag = 0;	/* assume no special flags for now */
 		if (len > 0)
-			strcpy (lastcommand, console_buffer);
+			strcpy (lastcommand, console_buffer_addr());
 		else if (len == 0)
 			flag |= CMD_FLAG_REPEAT;
 #ifdef CONFIG_BOOT_RETRY_TIME
@@ -928,7 +926,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
  */
 int readline (const char *const prompt)
 {
-	return readline_into_buffer(prompt, console_buffer);
+	return readline_into_buffer(prompt, console_buffer_addr());
 }
 
 
@@ -1036,7 +1034,7 @@ int readline_into_buffer (const char *const prompt, char * buffer)
 #ifdef CONFIG_AUTO_COMPLETE
 					/* if auto completion triggered just continue */
 					*p = '\0';
-					if (cmd_auto_complete(prompt, console_buffer, &n, &col)) {
+					if (cmd_auto_complete(prompt, console_buffer_addr(), &n, &col)) {
 						p = p_buf + n;	/* reset */
 						continue;
 					}
diff --git a/include/common.h b/include/common.h
index 06ed278..69f5af4 100644
--- a/include/common.h
+++ b/include/common.h
@@ -628,6 +628,7 @@ int	ctrlc (void);
 int	had_ctrlc (void);	/* have we had a Control-C since last clear? */
 void	clear_ctrlc (void);	/* clear the Control-C condition */
 int	disable_ctrlc (int);	/* 1 to disable, 0 to enable Control-C detect */
+char	*console_buffer_addr(void);
 
 /*
  * STDIO based functions (can always be used)
diff --git a/lib_arm/board.c b/lib_arm/board.c
index a093860..1f5409b 100644
--- a/lib_arm/board.c
+++ b/lib_arm/board.c
@@ -506,7 +506,7 @@ int mdm_init (void)
 	char env_str[16];
 	char *init_str;
 	int i;
-	extern char console_buffer[];
+	char *console_buffer = console_buffer_addr();
 	extern void enable_putc(void);
 	extern int hwflow_onoff(int);
 
diff --git a/lib_ppc/board.c b/lib_ppc/board.c
index 71a70db..262b972 100644
--- a/lib_ppc/board.c
+++ b/lib_ppc/board.c
@@ -1238,7 +1238,7 @@ int mdm_init (void)
 	char env_str[16];
 	char *init_str;
 	int i;
-	extern char console_buffer[];
+	char *console_buffer = console_buffer_addr();
 	extern void enable_putc(void);
 	extern int hwflow_onoff(int);
 
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] Replace references to extern console_buffer with a function call
  2008-08-15 19:49 [U-Boot] [PATCH] Replace references to extern console_buffer with a function call Peter Tyser
@ 2008-08-15 20:05 ` Wolfgang Denk
  2008-08-15 20:25   ` Peter Tyser
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfgang Denk @ 2008-08-15 20:05 UTC (permalink / raw)
  To: u-boot

Dear Peter Tyser,

what is the purpose of this patch? As far as I can see we gain
nothing, but we lose on memory footpint.  I guess there is some
problem you're trying to fix, but you did not mention it?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The use of COBOL cripples the mind; its teaching  should,  therefore,
be regarded as a criminal offence.
          -- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] Replace references to extern console_buffer with a function call
  2008-08-15 20:05 ` Wolfgang Denk
@ 2008-08-15 20:25   ` Peter Tyser
  2008-08-15 21:35     ` Wolfgang Denk
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Tyser @ 2008-08-15 20:25 UTC (permalink / raw)
  To: u-boot

> what is the purpose of this patch? As far as I can see we gain
> nothing, but we lose on memory footpint.  I guess there is some
> problem you're trying to fix, but you did not mention it?

I've added a basic "debug serial console" which relies on this patch.
The debug console is a simple command prompt which allows the user to
issue commands before relocating to SDRAM.  We've found this feature
very useful for operations such as initially programming SPD data,
debugging hardware issues (SDRAM/I2C).  I'll submit the debug console
patches shortly.

I'm not sure if the debug console will be accepted to mainline, but I
think this patch alone is an improvement over the current implementation
of using a global string and multiple external console_buffer
references.  I've always thought global variables should be avoided if
there is a reasonable alternative

Best,
Peter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] Replace references to extern console_buffer with a function call
  2008-08-15 20:25   ` Peter Tyser
@ 2008-08-15 21:35     ` Wolfgang Denk
  2008-08-15 22:27       ` Peter Tyser
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfgang Denk @ 2008-08-15 21:35 UTC (permalink / raw)
  To: u-boot

Dear Peter Tyser,

In message <1218831956.1273.114.camel@localhost.localdomain> you wrote:
> > what is the purpose of this patch? As far as I can see we gain
> > nothing, but we lose on memory footpint.  I guess there is some
> > problem you're trying to fix, but you did not mention it?
> 
> I've added a basic "debug serial console" which relies on this patch.
> The debug console is a simple command prompt which allows the user to
> issue commands before relocating to SDRAM.  We've found this feature
> very useful for operations such as initially programming SPD data,
> debugging hardware issues (SDRAM/I2C).  I'll submit the debug console
> patches shortly.

OK, I think what you're trying to do.

> I'm not sure if the debug console will be accepted to mainline, but I
> think this patch alone is an improvement over the current implementation

Frankly, I don't think so - it just makes the code bigger for no good
use to 99.9% of the users.

> of using a global string and multiple external console_buffer
> references.  I've always thought global variables should be avoided if
> there is a reasonable alternative

But this is a boot loader, and size matters.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Lady Nancy Astor:
    "Winston, if you were my husband, I'd put poison in your coffee."
Winston Churchill:
    "Nancy, if you were my wife, I'd drink it."

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] Replace references to extern console_buffer with a function call
  2008-08-15 21:35     ` Wolfgang Denk
@ 2008-08-15 22:27       ` Peter Tyser
  2008-08-16  7:50         ` Wolfgang Denk
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Tyser @ 2008-08-15 22:27 UTC (permalink / raw)
  To: u-boot

> > I'm not sure if the debug console will be accepted to mainline, but
> I
> > think this patch alone is an improvement over the current
> implementation
> 
> Frankly, I don't think so - it just makes the code bigger for no good
> use to 99.9% of the users.
> 
> > of using a global string and multiple external console_buffer
> > references.  I've always thought global variables should be avoided if
> > there is a reasonable alternative
> 
> But this is a boot loader, and size matters.

I had assumed gcc/ld would be smart enough to optimize the function call
away, seeing as there is no conditional code in it.  I just tested, and
the size was increased by 48 bytes for the MPC8548CDS reference board
after applying the patch.  Inlining the console_buffer_addr() didn't get
rid of the 48 bytes of bloat.

I guess this patch's fate will be the same as "[RFC] Add support for
early serial debug console"...

Thanks,
Peter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] Replace references to extern console_buffer with a function call
  2008-08-15 22:27       ` Peter Tyser
@ 2008-08-16  7:50         ` Wolfgang Denk
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Denk @ 2008-08-16  7:50 UTC (permalink / raw)
  To: u-boot

Dear Peter Tyser,

In message <1218839253.1273.148.camel@localhost.localdomain> you wrote:
>
> > But this is a boot loader, and size matters.
> 
> I had assumed gcc/ld would be smart enough to optimize the function call
> away, seeing as there is no conditional code in it.  I just tested, and
> the size was increased by 48 bytes for the MPC8548CDS reference board
> after applying the patch.  Inlining the console_buffer_addr() didn't get
> rid of the 48 bytes of bloat.
> 
> I guess this patch's fate will be the same as "[RFC] Add support for
> early serial debug console"...

Indeed, as this is the only application where the patch is needed.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Fascinating, a totally parochial attitude.
	-- Spock, "Metamorphosis", stardate 3219.8

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-08-16  7:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-15 19:49 [U-Boot] [PATCH] Replace references to extern console_buffer with a function call Peter Tyser
2008-08-15 20:05 ` Wolfgang Denk
2008-08-15 20:25   ` Peter Tyser
2008-08-15 21:35     ` Wolfgang Denk
2008-08-15 22:27       ` Peter Tyser
2008-08-16  7:50         ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox