Lock down console
Two enhancements to lock down uboot to avoid user enter
interactive mode:
1. disable autodelay.
2. ignore ctlr-c completely during boot, so that user can
not use hold ctrl-c from beginning to interrupt to
interactive mode.
The second enhancement is simplified from
http://lists.denx.de/pipermail/u-boot/2014-June/181071.html
for shutdown ctrl-c backdoor.
Change-Id: Iacb8dca644cfa86559d9e46e9fa58dcbf673f88e
diff --git a/common/console.c b/common/console.c
index 3499e70..99f1724 100755
--- a/common/console.c
+++ b/common/console.c
@@ -249,9 +249,18 @@
/* test if ctrl-c was pressed */
static int ctrlc_disabled = 0; /* see disable_ctrl() */
static int ctrlc_was_pressed = 0;
+static int ctrlc_ignore = 1;
+
+#ifdef CONFIG_SYS_CTRLC_IGNORE
+int ignore_ctrlc(int ignore)
+{
+ ctrlc_ignore = ignore;
+}
+#endif
+
int ctrlc (void)
{
- if (!ctrlc_disabled && gd->have_console) {
+ if (!ctrlc_ignore && !ctrlc_disabled && gd->have_console) {
if (tstc ()) {
switch (getc ()) {
case 0x03: /* ^C - Control C */
diff --git a/common/main.c b/common/main.c
index 45a4d26..8bfebae 100755
--- a/common/main.c
+++ b/common/main.c
@@ -371,6 +371,10 @@
install_auto_complete();
#endif
+#ifdef CONFIG_SYS_CTRLC_IGNORE
+ ignore_ctrlc(1);
+#endif
+
#ifdef CONFIG_PREBOOT
if ((p = getenv ("preboot")) != NULL) {
# ifdef CONFIG_AUTOBOOT_KEYED
diff --git a/include/953x.h b/include/953x.h
index 2fa46ec..3fd411e 100755
--- a/include/953x.h
+++ b/include/953x.h
@@ -3489,7 +3489,8 @@
#define CONFIG_MIPS32 1 /* MIPS32 CPU core */
-#define CONFIG_BOOTDELAY 2 /* autoboot after 4 seconds */
+#define CONFIG_BOOTDELAY 0 /* autoboot w/o delay */
+#define CONFIG_SYS_CTRLC_IGNORE 1 /* shutdown ctrl-c backdoor to enter interactive mode */
#define CONFIG_BAUDRATE 115200
#define CFG_BAUDRATE_TABLE {115200}
diff --git a/include/common.h b/include/common.h
index f0c1eac..1cf84e4 100755
--- a/include/common.h
+++ b/include/common.h
@@ -578,6 +578,9 @@
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 */
+#ifdef CONFIG_SYS_CTRLC_IGNORE
+int ignore_ctrlc(int); /* 1 to ignore ctlr-c handling at all, 0 otherwise */
+#endif
/*
* STDIO based functions (can always be used)