Skip to content
Permalink
Browse files
WIP - configurable console
  • Loading branch information
mcb30 committed Feb 28, 2016
1 parent 99b5216 commit a589a0640911918037e2f722e51b0e70718b161b
Showing with 62 additions and 1 deletion.
  1. +37 −0 src/core/serial.c
  2. +12 −1 src/hci/commands/console_cmd.c
  3. +13 −0 src/include/ipxe/console.h
@@ -124,11 +124,48 @@ static int serial_iskey ( void ) {
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 */
struct console_driver serial_console_driver __console_driver = {
.putchar = serial_putchar,
.getchar = serial_getchar,
.iskey = serial_iskey,
.configure = serial_configure,
.usage = CONSOLE_SERIAL,
};

@@ -70,6 +70,12 @@ static struct option_descriptor console_opts[] = {
struct console_options, picture, parse_string ),
OPTION_DESC ( "keep", 'k', no_argument,
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 */
@@ -88,8 +94,13 @@ static int console_exec ( int argc, char **argv ) {
struct image *image = NULL;
int rc;

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

/* 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;

/* Handle background picture, if applicable */
@@ -3,6 +3,7 @@

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

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

/**
@@ -173,6 +180,12 @@ struct console_driver {
/** Default console height */
#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 unsigned int console_width;
extern unsigned int console_height;

0 comments on commit a589a06

Please sign in to comment.