Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 |
| 3 | * Gary Jennejohn, DENX Software Engineering GmbH <garyj@denx.de> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Gary Jennejohn | c6dc755 | 2008-11-06 15:04:23 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | U-Boot console multiplexing |
| 9 | =========================== |
| 10 | |
| 11 | HOW CONSOLE MULTIPLEXING WORKS |
| 12 | ------------------------------ |
| 13 | |
| 14 | This functionality is controlled with CONFIG_CONSOLE_MUX in the board |
| 15 | configuration file. |
| 16 | |
| 17 | Two new files, common/iomux.c and include/iomux.h, contain the heart |
| 18 | (iomux_doenv()) of the environment setting implementation. |
| 19 | |
| 20 | iomux_doenv() is called in common/cmd_nvedit.c to handle setenv and in |
| 21 | common/console.c in console_init_r() during bootup to initialize |
| 22 | stdio_devices[]. |
| 23 | |
| 24 | A user can use a comma-separated list of devices to set stdin, stdout |
| 25 | and stderr. For example: "setenv stdin serial,nc". NOTE: No spaces |
| 26 | are allowed around the comma(s)! |
| 27 | |
| 28 | The length of the list is limited by malloc(), since the array used |
| 29 | is allocated and freed dynamically. |
| 30 | |
| 31 | It should be possible to specify any device which console_assign() |
| 32 | finds acceptable, but the code has only been tested with serial and |
| 33 | nc. |
| 34 | |
| 35 | iomux_doenv() prevents multiple use of the same device, e.g. "setenv |
| 36 | stdin nc,nc,serial" will discard the second nc. iomux_doenv() is |
| 37 | not able to modify the environment, however, so that "pri stdin" still |
| 38 | shows "nc,nc,serial". |
| 39 | |
| 40 | The major change in common/console.c was to modify fgetc() to call |
| 41 | the iomux_tstc() routine in a for-loop. iomux_tstc() in turn calls |
| 42 | the tstc() routine for every registered device, but exits immediately |
| 43 | when one of them returns true. fgetc() then calls iomux_getc(), |
| 44 | which calls the corresponding getc() routine. fgetc() hangs in |
| 45 | the for-loop until iomux_tstc() returns true and the input can be |
| 46 | retrieved. |
| 47 | |
| 48 | Thus, a user can type into any device registered for stdin. No effort |
| 49 | has been made to demulitplex simultaneous input from multiple stdin |
| 50 | devices. |
| 51 | |
| 52 | fputc() and fputs() have been modified to call iomux_putc() and |
| 53 | iomux_puts() respectively, which call the corresponding output |
| 54 | routines for every registered device. |
| 55 | |
| 56 | Thus, a user can see the ouput for any device registered for stdout |
| 57 | or stderr on all devices registered for stdout or stderr. As an |
| 58 | example, if stdin=serial,nc and stdout=serial,nc then all output |
| 59 | for serial, e.g. echos of input on serial, will appear on serial and nc. |
| 60 | |
| 61 | Just as with the old console code, this statement is still true: |
| 62 | If not defined in the environment, the first input device is assigned |
| 63 | to the 'stdin' file, the first output one to 'stdout' and 'stderr'. |
| 64 | |
| 65 | If CONFIG_SYS_CONSOLE_IS_IN_ENV is defined then multiple input/output |
| 66 | devices can be set at boot time if defined in the environment. |
| 67 | |
| 68 | CAVEATS |
| 69 | ------- |
| 70 | |
| 71 | Note that common/iomux.c calls console_assign() for every registered |
| 72 | device as it is discovered. This means that the environment settings |
| 73 | for application consoles will be set to the last device in the list. |
| 74 | |
| 75 | On a slow machine, such as MPC852T clocked at 66MHz, the overhead associated |
| 76 | with calling tstc() and then getc() means that copy&paste will normally not |
| 77 | work, even when stdin=stdout=stderr=serial. |
| 78 | On a faster machine, such as a sequoia, cut&paste of longer (about 80 |
| 79 | characters) lines works fine when serial is the only device used. |
| 80 | |
| 81 | Using nc as a stdin device results in even more overhead because nc_tstc() |
| 82 | is quite slow. Even on a sequoia cut&paste does not work on the serial |
| 83 | interface when nc is added to stdin, although there is no character loss using |
| 84 | the ethernet interface for input. In this test case stdin=serial,nc and |
| 85 | stdout=serial. |
| 86 | |
| 87 | In addition, the overhead associated with sending to two devices, when one of |
| 88 | them is nc, also causes problems. Even on a sequoia cut&paste does not work |
| 89 | on the serial interface (stdin=serial) when nc is added to stdout (stdout= |
| 90 | serial,nc). |