Gary Jennejohn | 16a28ef | 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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | U-Boot console multiplexing |
| 25 | =========================== |
| 26 | |
| 27 | HOW CONSOLE MULTIPLEXING WORKS |
| 28 | ------------------------------ |
| 29 | |
| 30 | This functionality is controlled with CONFIG_CONSOLE_MUX in the board |
| 31 | configuration file. |
| 32 | |
| 33 | Two new files, common/iomux.c and include/iomux.h, contain the heart |
| 34 | (iomux_doenv()) of the environment setting implementation. |
| 35 | |
| 36 | iomux_doenv() is called in common/cmd_nvedit.c to handle setenv and in |
| 37 | common/console.c in console_init_r() during bootup to initialize |
| 38 | stdio_devices[]. |
| 39 | |
| 40 | A user can use a comma-separated list of devices to set stdin, stdout |
| 41 | and stderr. For example: "setenv stdin serial,nc". NOTE: No spaces |
| 42 | are allowed around the comma(s)! |
| 43 | |
| 44 | The length of the list is limited by malloc(), since the array used |
| 45 | is allocated and freed dynamically. |
| 46 | |
| 47 | It should be possible to specify any device which console_assign() |
| 48 | finds acceptable, but the code has only been tested with serial and |
| 49 | nc. |
| 50 | |
| 51 | iomux_doenv() prevents multiple use of the same device, e.g. "setenv |
| 52 | stdin nc,nc,serial" will discard the second nc. iomux_doenv() is |
| 53 | not able to modify the environment, however, so that "pri stdin" still |
| 54 | shows "nc,nc,serial". |
| 55 | |
| 56 | The major change in common/console.c was to modify fgetc() to call |
| 57 | the iomux_tstc() routine in a for-loop. iomux_tstc() in turn calls |
| 58 | the tstc() routine for every registered device, but exits immediately |
| 59 | when one of them returns true. fgetc() then calls iomux_getc(), |
| 60 | which calls the corresponding getc() routine. fgetc() hangs in |
| 61 | the for-loop until iomux_tstc() returns true and the input can be |
| 62 | retrieved. |
| 63 | |
| 64 | Thus, a user can type into any device registered for stdin. No effort |
| 65 | has been made to demulitplex simultaneous input from multiple stdin |
| 66 | devices. |
| 67 | |
| 68 | fputc() and fputs() have been modified to call iomux_putc() and |
| 69 | iomux_puts() respectively, which call the corresponding output |
| 70 | routines for every registered device. |
| 71 | |
| 72 | Thus, a user can see the ouput for any device registered for stdout |
| 73 | or stderr on all devices registered for stdout or stderr. As an |
| 74 | example, if stdin=serial,nc and stdout=serial,nc then all output |
| 75 | for serial, e.g. echos of input on serial, will appear on serial and nc. |
| 76 | |
| 77 | Just as with the old console code, this statement is still true: |
| 78 | If not defined in the environment, the first input device is assigned |
| 79 | to the 'stdin' file, the first output one to 'stdout' and 'stderr'. |
| 80 | |
| 81 | If CONFIG_SYS_CONSOLE_IS_IN_ENV is defined then multiple input/output |
| 82 | devices can be set at boot time if defined in the environment. |
| 83 | |
| 84 | CAVEATS |
| 85 | ------- |
| 86 | |
| 87 | Note that common/iomux.c calls console_assign() for every registered |
| 88 | device as it is discovered. This means that the environment settings |
| 89 | for application consoles will be set to the last device in the list. |
| 90 | |
| 91 | On a slow machine, such as MPC852T clocked at 66MHz, the overhead associated |
| 92 | with calling tstc() and then getc() means that copy&paste will normally not |
| 93 | work, even when stdin=stdout=stderr=serial. |
| 94 | On a faster machine, such as a sequoia, cut&paste of longer (about 80 |
| 95 | characters) lines works fine when serial is the only device used. |
| 96 | |
| 97 | Using nc as a stdin device results in even more overhead because nc_tstc() |
| 98 | is quite slow. Even on a sequoia cut&paste does not work on the serial |
| 99 | interface when nc is added to stdin, although there is no character loss using |
| 100 | the ethernet interface for input. In this test case stdin=serial,nc and |
| 101 | stdout=serial. |
| 102 | |
| 103 | In addition, the overhead associated with sending to two devices, when one of |
| 104 | them is nc, also causes problems. Even on a sequoia cut&paste does not work |
| 105 | on the serial interface (stdin=serial) when nc is added to stdout (stdout= |
| 106 | serial,nc). |