diff options
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/sandbox/cpu/os.c | 13 | ||||
| -rw-r--r-- | arch/sandbox/cpu/start.c | 28 | ||||
| -rw-r--r-- | arch/sandbox/include/asm/state.h | 24 | 
3 files changed, 59 insertions, 6 deletions
| diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 52e1096f3..9de71bb2b 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -104,21 +104,22 @@ void os_exit(int exit_code)  /* Restore tty state when we exit */  static struct termios orig_term; +static bool term_setup;  static void os_fd_restore(void)  { -	tcsetattr(0, TCSANOW, &orig_term); +	if (term_setup) +		tcsetattr(0, TCSANOW, &orig_term);  }  /* Put tty into raw mode so <tab> and <ctrl+c> work */ -void os_tty_raw(int fd) +void os_tty_raw(int fd, bool allow_sigs)  { -	static int setup = 0;  	struct termios term; -	if (setup) +	if (term_setup)  		return; -	setup = 1; +	term_setup = true;  	/* If not a tty, don't complain */  	if (tcgetattr(fd, &orig_term)) @@ -128,7 +129,7 @@ void os_tty_raw(int fd)  	term.c_iflag = IGNBRK | IGNPAR;  	term.c_oflag = OPOST | ONLCR;  	term.c_cflag = CS8 | CREAD | CLOCAL; -	term.c_lflag = 0; +	term.c_lflag = allow_sigs ? ISIG : 0;  	if (tcsetattr(fd, TCSANOW, &term))  		return; diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 4d5569e64..36dfc0a40 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -184,6 +184,34 @@ static int sandbox_cmdline_cb_show_lcd(struct sandbox_state *state,  SANDBOX_CMDLINE_OPT_SHORT(show_lcd, 'l', 0,  			  "Show the sandbox LCD display"); +static const char *term_args[STATE_TERM_COUNT] = { +	"raw-with-sigs", +	"raw", +	"cooked", +}; + +static int sandbox_cmdline_cb_terminal(struct sandbox_state *state, +				       const char *arg) +{ +	int i; + +	for (i = 0; i < STATE_TERM_COUNT; i++) { +		if (!strcmp(arg, term_args[i])) { +			state->term_raw = i; +			return 0; +		} +	} + +	printf("Unknown terminal setting '%s' (", arg); +	for (i = 0; i < STATE_TERM_COUNT; i++) +		printf("%s%s", i ? ", " : "", term_args[i]); +	puts(")\n"); + +	return 1; +} +SANDBOX_CMDLINE_OPT_SHORT(terminal, 't', 1, +			  "Set terminal to raw/cooked mode"); +  int main(int argc, char *argv[])  {  	struct sandbox_state *state; diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index 895b3a4ec..56bd9a07b 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -17,6 +17,29 @@ enum exit_type_id {  	STATE_EXIT_POWER_OFF,  }; +/** + * Selects the behavior of the serial terminal. + * + * If Ctrl-C is processed by U-Boot, then the only way to quit sandbox is with + * the 'reset' command, or equivalent. + * + * If the terminal is cooked, then Ctrl-C will terminate U-Boot, and the + * command line will not be quite such a faithful emulation. + * + * Options are: + * + *	raw-with-sigs		- Raw, but allow signals (Ctrl-C will quit) + *	raw			- Terminal is always raw + *	cooked			- Terminal is always cooked + */ +enum state_terminal_raw { +	STATE_TERM_RAW_WITH_SIGS,	/* Default */ +	STATE_TERM_RAW, +	STATE_TERM_COOKED, + +	STATE_TERM_COUNT, +}; +  struct sandbox_spi_info {  	const char *spec;  	const struct sandbox_spi_emu_ops *ops; @@ -42,6 +65,7 @@ struct sandbox_state {  	bool write_state;		/* Write sandbox state on exit */  	bool ignore_missing_state_on_read;	/* No error if state missing */  	bool show_lcd;			/* Show LCD on start-up */ +	enum state_terminal_raw term_raw;	/* Terminal raw/cooked */  	/* Pointer to information for each SPI bus/cs */  	struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS] |