Skip to content

Commit

Permalink
WIP - configurable console
Browse files Browse the repository at this point in the history
  • Loading branch information
mcb30 committed Feb 28, 2016
1 parent 99b5216 commit a589a06
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/core/serial.c
Expand Up @@ -124,11 +124,48 @@ static int serial_iskey ( void ) {
return uart_data_ready ( &serial_console ); return uart_data_ready ( &serial_console );
} }


/**
* Configure serial console
*
* @v config Console configuration, or NULL to leave unchanged
* @ret rc Return status code
*/
static int serial_configure ( struct console_configuration *config ) {
int rc;

/* Do nothing unless we have a serial configuration to apply */
if ( ( ! config ) || ( ! config->port ) )
return 0;

/* Flush console, if applicable */
if ( serial_console.base )
uart_flush ( &serial_console );

/* Select UART */
if ( ( rc = uart_select ( &serial_console, config->port ) ) != 0 ) {
DBG ( "Could not select UART %d: %s\n",
config->port, strerror ( rc ) );
return rc;
}

/* Initialise UART */
if ( ( rc = uart_init ( &serial_console, config->speed,
config->lcr ) ) != 0 ) {
DBG ( "Could not initialise UART %d baud %d LCR %#02x: %s\n",
config->port, config->speed, config->lcr,
strerror ( rc ) );
return rc;
}

return 0;
}

/** Serial console */ /** Serial console */
struct console_driver serial_console_driver __console_driver = { struct console_driver serial_console_driver __console_driver = {
.putchar = serial_putchar, .putchar = serial_putchar,
.getchar = serial_getchar, .getchar = serial_getchar,
.iskey = serial_iskey, .iskey = serial_iskey,
.configure = serial_configure,
.usage = CONSOLE_SERIAL, .usage = CONSOLE_SERIAL,
}; };


Expand Down
13 changes: 12 additions & 1 deletion src/hci/commands/console_cmd.c
Expand Up @@ -70,6 +70,12 @@ static struct option_descriptor console_opts[] = {
struct console_options, picture, parse_string ), struct console_options, picture, parse_string ),
OPTION_DESC ( "keep", 'k', no_argument, OPTION_DESC ( "keep", 'k', no_argument,
struct console_options, keep, parse_flag ), struct console_options, keep, parse_flag ),
OPTION_DESC ( "port", 'o', required_argument,
struct console_options, config.port, parse_integer ),
OPTION_DESC ( "speed", 's', required_argument,
struct console_options, config.speed, parse_integer ),
OPTION_DESC ( "lcr", 'c', required_argument,
struct console_options, config.lcr, parse_integer ),
}; };


/** "console" command descriptor */ /** "console" command descriptor */
Expand All @@ -88,8 +94,13 @@ static int console_exec ( int argc, char **argv ) {
struct image *image = NULL; struct image *image = NULL;
int rc; int rc;


/* Initialise options */
memset ( &opts, 0, sizeof ( opts ) );
opts.config.speed = CONSOLE_DEFAULT_SPEED;
opts.config.lcr = CONSOLE_DEFAULT_LCR;

/* Parse options */ /* Parse options */
if ( ( rc = parse_options ( argc, argv, &console_cmd, &opts ) ) != 0 ) if ( ( rc = reparse_options ( argc, argv, &console_cmd, &opts ) ) != 0 )
goto err_parse; goto err_parse;


/* Handle background picture, if applicable */ /* Handle background picture, if applicable */
Expand Down
13 changes: 13 additions & 0 deletions src/include/ipxe/console.h
Expand Up @@ -3,6 +3,7 @@


#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <ipxe/uart.h>
#include <ipxe/tables.h> #include <ipxe/tables.h>


/** @file /** @file
Expand Down Expand Up @@ -38,6 +39,12 @@ struct console_configuration {
unsigned int bottom; unsigned int bottom;
/** Background picture, if any */ /** Background picture, if any */
struct pixel_buffer *pixbuf; struct pixel_buffer *pixbuf;
/** Port number */
unsigned int port;
/** Speed */
unsigned int speed;
/** Line control register */
unsigned int lcr;
}; };


/** /**
Expand Down Expand Up @@ -173,6 +180,12 @@ struct console_driver {
/** Default console height */ /** Default console height */
#define CONSOLE_DEFAULT_HEIGHT 25 #define CONSOLE_DEFAULT_HEIGHT 25


/** Default console speed */
#define CONSOLE_DEFAULT_SPEED UART_MAX_BAUD

/** Default console line control register value */
#define CONSOLE_DEFAULT_LCR UART_LCR_8N1

extern int console_usage; extern int console_usage;
extern unsigned int console_width; extern unsigned int console_width;
extern unsigned int console_height; extern unsigned int console_height;
Expand Down

0 comments on commit a589a06

Please sign in to comment.