
Hello,
Working on the POST for mpc834x based board I encountered the following problem: The ctrlc() routine does not work when used from post_hotkeys_pressed(). The value of ctrlc_disabled variable defined as static in the console.c file is lost after code relocation.
By adding the ctrlc_disabled to global data gd structure the problem was solved.
Here is the code changes:
common/console.c | 7 +++---- include/asm-ppc/global_data.h | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/common/console.c b/common/console.c index dc0d13b..101c308 100644 --- a/common/console.c +++ b/common/console.c @@ -400,11 +400,10 @@ void vprintf(const char *fmt, va_list args) }
/* test if ctrl-c was pressed */ -static int ctrlc_disabled = 0; /* see disable_ctrl() */ static int ctrlc_was_pressed = 0; int ctrlc(void) { - if (!ctrlc_disabled && gd->have_console) { + if (!gd->ctrlc_disabled && gd->have_console) { if (tstc()) { switch (getc()) { case 0x03: /* ^C - Control C */ @@ -423,9 +422,9 @@ int ctrlc(void) */ int disable_ctrlc(int disable) { - int prev = ctrlc_disabled; /* save previous state */ + int prev = gd->ctrlc_disabled; /* save previous state */
- ctrlc_disabled = disable; + gd->ctrlc_disabled = disable; return prev; }
diff --git a/include/asm-ppc/global_data.h b/include/asm-ppc/global_data.h index 55e7e20..7b333ef 100644 --- a/include/asm-ppc/global_data.h +++ b/include/asm-ppc/global_data.h @@ -132,7 +132,8 @@ typedef struct global_data { #endif unsigned long env_addr; /* Address of Environment struct */ unsigned long env_valid; /* Checksum of Environment valid? */ - unsigned long have_console; /* serial_init() was called */ + unsigned char have_console; /* serial_init() was called */ + unsigned char ctrlc_disabled; /* Is the <ctrl C> enabled? */ #if defined(CONFIG_SYS_ALLOC_DPRAM) || defined(CONFIG_CPM2) unsigned int dp_alloc_base; unsigned int dp_alloc_top;
My questions are: 1) I tested this change for ppc branch only. There are a number of boards belonging to other CPU architectures that also use ctrlc() call from within the post_hotkeys_pressed(). However, I am not sure they use POST at all. I went through the list and found only one such board with CONFIG_POST defined. Does anybody has objection that this change will be expanded to other CPU architectures also?
2) I wondered why the have_console variable which gets true/false values only allocates 4 bytes in memory. So I changed it to 1 byte. Thus, adding ctrlc_disabled of one byte size also did not change the global_data structure size. Any thoughts? Should it be delivered as separate patch?