Changeset c3c57b1 in rtems


Ignore:
Timestamp:
Mar 10, 2016, 4:33:27 PM (3 years ago)
Author:
Joel Sherrill <joel@…>
Branches:
master
Children:
36627387
Parents:
f770fcb
Message:

pc386: Improve boot command arguments for console/printk device selection

This patch adds the "--printk=" boot command line argument to specify
the printk() device. It also enhances the "--console=" boot command
line argument to match any device configured in the console device
table. The arguments are parsed as early as possible so they take
effect early. Currently, this is immediately after PCI initialization.

Location:
c/src/lib/libbsp
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/i386/pc386/console/console_select.c

    rf770fcb rc3c57b1  
    44 * @ingroup Console
    55 *
    6  * @brief Generic libchip console select
     6 * @brief pc397 console select
    77 *
    88 * This file contains a routine to select the console based upon a number
     
    1111
    1212/*
    13  *  COPYRIGHT (c) 2011-2012.
     13 *  COPYRIGHT (c) 2011-2012, 2016.
    1414 *  On-Line Applications Research Corporation (OAR).
    1515 *
     
    7878}
    7979
     80static bool bsp_find_console_entry(
     81  const char                *match,
     82  size_t                     length,
     83  rtems_device_minor_number *match_minor
     84)
     85{
     86  rtems_device_minor_number  minor;
     87  const char                *name;
     88
     89  for (minor=0; minor < Console_Port_Count ; minor++) {
     90    console_tbl  *cptr = Console_Port_Tbl[minor];
     91
     92    /*
     93     * Console table entries include /dev/ prefix, device names passed
     94     * in on command line do not.
     95     */
     96    name = cptr->sDeviceName  + sizeof("/dev");
     97    if ( !strncmp( name, match, length ) ) {
     98      *match_minor = minor;
     99      return true;
     100    }
     101  }
     102
     103  return false;
     104}
     105
     106static bool parse_printk_or_console(
     107  const char                *param,
     108  rtems_device_minor_number *minor_out
     109)
     110{
     111  static const char *opt;
     112  char               working[64] = "";
     113  char              *p;
     114
     115  /*
     116   * Check the command line for the type of mode the console is.
     117   */
     118  opt = bsp_cmdline_arg(param);
     119  if ( !opt ) {
     120    return false;
     121  }
     122
     123  /*
     124   * bsp_cmdline_arg() returns pointer to a string. It may not be the
     125   * last string on the command line.
     126   */
     127  strncpy( working, opt, sizeof(working) );
     128  p = strchr( working, ' ' );
     129  if ( p ) {
     130    *p = '\0';
     131  }
     132
     133  const char                *comma;
     134  size_t                     length = NAME_MAX;
     135  rtems_device_minor_number  minor;
     136  char                      *option = working;
     137
     138  /*
     139   * Only match up to a comma or NULL
     140   */
     141  comma = strchr (option, ',');
     142
     143  if ( comma ) {
     144    length = comma - option;
     145  }
     146
     147  option += strnlen(param, 32);
     148
     149  if ( !bsp_find_console_entry( option, length, &minor ) ) {
     150    return false;
     151  }
     152
     153  *minor_out = minor;
     154  if (comma) {
     155    console_tbl *conscfg;
     156
     157    comma += 1;
     158    conscfg = &Console_Configuration_Ports[minor];
     159    if (strncmp (option, "115200", sizeof ("115200") - 1) == 0)
     160      conscfg->pDeviceParams = (void *)115200;
     161    else if (strncmp (option, "57600", sizeof ("57600") - 1) == 0)
     162      conscfg->pDeviceParams = (void *)57600;
     163    else if (strncmp (option, "38400", sizeof ("38400") - 1) == 0)
     164      conscfg->pDeviceParams = (void *)38400;
     165    else if (strncmp (option, "19200", sizeof ("19200") - 1) == 0)
     166      conscfg->pDeviceParams = (void *)19200;
     167    else if (strncmp (option, "9600", sizeof ("9600") - 1) == 0)
     168      conscfg->pDeviceParams = (void *)9600;
     169    else if (strncmp (option, "4800", sizeof ("4800") - 1) == 0)
     170      conscfg->pDeviceParams = (void *)4800;
     171  }
     172
     173  return true;
     174}
     175
     176/*
     177 * Helper to retrieve device name
     178 */
     179static inline const char *get_name(
     180  rtems_device_minor_number  minor
     181)
     182{
     183  return Console_Port_Tbl[minor]->sDeviceName;
     184}
     185
     186/*
     187 * Parse the arguments early so the printk and console ports are
     188 * set appropriately.
     189 */
     190void pc386_parse_console_arguments(void)
     191{
     192  rtems_device_minor_number  minor;
     193
     194  /*
     195   * The console device driver must have its data structures initialized
     196   * before we can iterate the table of devices for names.
     197   */
     198  console_initialize_data();
     199
     200  /*
     201   * Assume that if only --console is specified, that printk() should
     202   * follow that selection by default.
     203   */
     204  if ( parse_printk_or_console( "--console=", &minor ) ) {
     205    Console_Port_Minor = minor;
     206    BSPPrintkPort = minor;
     207  }
     208
     209  /*
     210   * But if explicitly specified, attempt to honor it.
     211   */
     212  if ( parse_printk_or_console( "--printk=",  &minor ) ) {
     213    BSPPrintkPort = minor;
     214  }
     215
     216#if 0
     217  printk( "Console device: %s\n", get_name(Console_Port_Minor) );
     218  printk( "printk device:  %s\n", get_name(BSPPrintkPort) );
     219#endif
     220}
     221
     222/*
     223 *  This handles the selection of the console after the devices are
     224 *  initialized.
     225 */
    80226void bsp_console_select(void)
    81227{
    82   static const char* opt;
    83 
    84   /*
    85    * Check the command line for the type of mode the console is.
    86    */
    87   opt = bsp_cmdline_arg ("--console=");
    88 
    89   if (opt) {
    90     const char* comma;
    91 
    92     opt += sizeof ("--console=") - 1;
    93     if (strncmp (opt, "console", sizeof ("console") - 1) == 0) {
    94       Console_Port_Minor = BSP_CONSOLE_VGA;
    95       BSPPrintkPort      = BSP_CONSOLE_VGA;
    96     } else if (strncmp (opt, "com1", sizeof ("com1") - 1) == 0) {
    97       Console_Port_Minor = BSP_CONSOLE_COM1;
    98       BSPPrintkPort      = BSP_CONSOLE_COM1;
    99     } else if (strncmp (opt, "com2", sizeof ("com2") - 1) == 0) {
    100       Console_Port_Minor = BSP_CONSOLE_COM2;
    101       BSPPrintkPort      = BSP_CONSOLE_COM2;
    102     }
    103 
    104     comma = strchr (opt, ',');
    105 
    106     if (comma) {
    107       console_tbl *conscfg;
    108 
    109       comma += 1;
    110       conscfg = &Console_Configuration_Ports[Console_Port_Minor];
    111       if (strncmp (opt, "115200", sizeof ("115200") - 1) == 0)
    112         conscfg->pDeviceParams = (void *)115200;
    113       else if (strncmp (opt, "57600", sizeof ("57600") - 1) == 0)
    114         conscfg->pDeviceParams = (void *)57600;
    115       else if (strncmp (opt, "38400", sizeof ("38400") - 1) == 0)
    116         conscfg->pDeviceParams = (void *)38400;
    117       else if (strncmp (opt, "19200", sizeof ("19200") - 1) == 0)
    118         conscfg->pDeviceParams = (void *)19200;
    119       else if (strncmp (opt, "9600", sizeof ("9600") - 1) == 0)
    120         conscfg->pDeviceParams = (void *)9600;
    121       else if (strncmp (opt, "4800", sizeof ("4800") - 1) == 0)
    122         conscfg->pDeviceParams = (void *)4800;
    123     }
    124   }
    125 
    126228  #ifdef RTEMS_RUNTIME_CONSOLE_SELECT
    127229    if ( BSP_runtime_console_select )
     
    146248    printk(
    147249      "Error finding %s setting console to first available\n",
    148       Console_Port_Tbl[Console_Port_Minor]->sDeviceName
     250      get_name(Console_Port_Minor)
    149251    );
    150252    Console_Port_Minor = bsp_First_Available_Device();
  • c/src/lib/libbsp/i386/pc386/include/bsp.h

    rf770fcb rc3c57b1  
    283283const pci_config_access_functions *pci_io_initialize(void);
    284284
     285/*
     286 * Helper to parse boot command line arguments related to the console driver
     287 */
     288void pc386_parse_console_arguments(void);
     289
     290
    285291#ifdef __cplusplus
    286292}
  • c/src/lib/libbsp/i386/pc386/startup/bspstart.c

    rf770fcb rc3c57b1  
    108108  bsp_pci_initialize_helper();
    109109
     110  /*
     111   * Figure out where printk() and console IO is to be directed.
     112   * Do this after the PCI bus is initialized so we have a chance
     113   * for those devices to be added to the set in the console driver.
     114   * In general, Do it as early as possible so printk() has a chance
     115   * to work early on devices found via PCI probe.
     116   */
     117  pc386_parse_console_arguments();
     118
    110119#if (BSP_IS_EDISON == 0)
    111120  Clock_driver_install_handler();
  • c/src/lib/libbsp/shared/console.c

    rf770fcb rc3c57b1  
    3535
    3636/*
    37  *  console_initialize_pointers
     37 *  console_initialize_data
    3838 *
    3939 *  This method is used to initialize the table of pointers to the
    4040 *  serial port configuration structure entries.
    4141 */
    42 static void console_initialize_pointers(void)
     42void console_initialize_data(void)
    4343{
    4444  int i;
     
    7070  int  i;
    7171
    72   console_initialize_pointers();
     72  console_initialize_data();
    7373
    7474  /*
     
    253253   */
    254254  if ( ! Console_Port_Tbl ) {
    255     console_initialize_pointers();
     255    console_initialize_data();
    256256    Console_Port_Data  = calloc( Console_Port_Count, sizeof( console_data ) );
    257257    if ( Console_Port_Data == NULL ) {
  • c/src/lib/libbsp/shared/console_private.h

    rf770fcb rc3c57b1  
    88
    99/*
    10  *  COPYRIGHT (c) 1989-2011.
     10 *  COPYRIGHT (c) 1989-2011, 2016.
    1111 *  On-Line Applications Research Corporation (OAR).
    1212 *
     
    5959
    6060/**
     61 *  @brief console_initialize_data
     62 *
     63 *  This must be called before dynamic registration of devices can occur.
     64 *  It is normally called as a side-effect of @a console_initialize() but
     65 *  if a probe and dynamic registration occurs before that, then this method
     66 *  should be explicitly invoked.
     67 */
     68void console_initialize_data(void);
     69
     70/**
    6171 *  @brief console_register_devices
    6272 *
Note: See TracChangeset for help on using the changeset viewer.