1*83d290c5STom RiniSPDX-License-Identifier: GPL-2.0+ 216a28ef2SGary Jennejohn/* 316a28ef2SGary Jennejohn * (C) Copyright 2008 416a28ef2SGary Jennejohn * Gary Jennejohn, DENX Software Engineering GmbH <garyj@denx.de> 516a28ef2SGary Jennejohn */ 616a28ef2SGary Jennejohn 716a28ef2SGary JennejohnU-Boot console multiplexing 816a28ef2SGary Jennejohn=========================== 916a28ef2SGary Jennejohn 1016a28ef2SGary JennejohnHOW CONSOLE MULTIPLEXING WORKS 1116a28ef2SGary Jennejohn------------------------------ 1216a28ef2SGary Jennejohn 1316a28ef2SGary JennejohnThis functionality is controlled with CONFIG_CONSOLE_MUX in the board 1416a28ef2SGary Jennejohnconfiguration file. 1516a28ef2SGary Jennejohn 1616a28ef2SGary JennejohnTwo new files, common/iomux.c and include/iomux.h, contain the heart 1716a28ef2SGary Jennejohn(iomux_doenv()) of the environment setting implementation. 1816a28ef2SGary Jennejohn 1916a28ef2SGary Jennejohniomux_doenv() is called in common/cmd_nvedit.c to handle setenv and in 2016a28ef2SGary Jennejohncommon/console.c in console_init_r() during bootup to initialize 2116a28ef2SGary Jennejohnstdio_devices[]. 2216a28ef2SGary Jennejohn 2316a28ef2SGary JennejohnA user can use a comma-separated list of devices to set stdin, stdout 2416a28ef2SGary Jennejohnand stderr. For example: "setenv stdin serial,nc". NOTE: No spaces 2516a28ef2SGary Jennejohnare allowed around the comma(s)! 2616a28ef2SGary Jennejohn 2716a28ef2SGary JennejohnThe length of the list is limited by malloc(), since the array used 2816a28ef2SGary Jennejohnis allocated and freed dynamically. 2916a28ef2SGary Jennejohn 3016a28ef2SGary JennejohnIt should be possible to specify any device which console_assign() 3116a28ef2SGary Jennejohnfinds acceptable, but the code has only been tested with serial and 3216a28ef2SGary Jennejohnnc. 3316a28ef2SGary Jennejohn 3416a28ef2SGary Jennejohniomux_doenv() prevents multiple use of the same device, e.g. "setenv 3516a28ef2SGary Jennejohnstdin nc,nc,serial" will discard the second nc. iomux_doenv() is 3616a28ef2SGary Jennejohnnot able to modify the environment, however, so that "pri stdin" still 3716a28ef2SGary Jennejohnshows "nc,nc,serial". 3816a28ef2SGary Jennejohn 3916a28ef2SGary JennejohnThe major change in common/console.c was to modify fgetc() to call 4016a28ef2SGary Jennejohnthe iomux_tstc() routine in a for-loop. iomux_tstc() in turn calls 4116a28ef2SGary Jennejohnthe tstc() routine for every registered device, but exits immediately 4216a28ef2SGary Jennejohnwhen one of them returns true. fgetc() then calls iomux_getc(), 4316a28ef2SGary Jennejohnwhich calls the corresponding getc() routine. fgetc() hangs in 4416a28ef2SGary Jennejohnthe for-loop until iomux_tstc() returns true and the input can be 4516a28ef2SGary Jennejohnretrieved. 4616a28ef2SGary Jennejohn 4716a28ef2SGary JennejohnThus, a user can type into any device registered for stdin. No effort 4816a28ef2SGary Jennejohnhas been made to demulitplex simultaneous input from multiple stdin 4916a28ef2SGary Jennejohndevices. 5016a28ef2SGary Jennejohn 5116a28ef2SGary Jennejohnfputc() and fputs() have been modified to call iomux_putc() and 5216a28ef2SGary Jennejohniomux_puts() respectively, which call the corresponding output 5316a28ef2SGary Jennejohnroutines for every registered device. 5416a28ef2SGary Jennejohn 5516a28ef2SGary JennejohnThus, a user can see the ouput for any device registered for stdout 5616a28ef2SGary Jennejohnor stderr on all devices registered for stdout or stderr. As an 5716a28ef2SGary Jennejohnexample, if stdin=serial,nc and stdout=serial,nc then all output 5816a28ef2SGary Jennejohnfor serial, e.g. echos of input on serial, will appear on serial and nc. 5916a28ef2SGary Jennejohn 6016a28ef2SGary JennejohnJust as with the old console code, this statement is still true: 6116a28ef2SGary JennejohnIf not defined in the environment, the first input device is assigned 6216a28ef2SGary Jennejohnto the 'stdin' file, the first output one to 'stdout' and 'stderr'. 6316a28ef2SGary Jennejohn 6416a28ef2SGary JennejohnIf CONFIG_SYS_CONSOLE_IS_IN_ENV is defined then multiple input/output 6516a28ef2SGary Jennejohndevices can be set at boot time if defined in the environment. 6616a28ef2SGary Jennejohn 6716a28ef2SGary JennejohnCAVEATS 6816a28ef2SGary Jennejohn------- 6916a28ef2SGary Jennejohn 7016a28ef2SGary JennejohnNote that common/iomux.c calls console_assign() for every registered 7116a28ef2SGary Jennejohndevice as it is discovered. This means that the environment settings 7216a28ef2SGary Jennejohnfor application consoles will be set to the last device in the list. 7316a28ef2SGary Jennejohn 7416a28ef2SGary JennejohnOn a slow machine, such as MPC852T clocked at 66MHz, the overhead associated 7516a28ef2SGary Jennejohnwith calling tstc() and then getc() means that copy&paste will normally not 7616a28ef2SGary Jennejohnwork, even when stdin=stdout=stderr=serial. 7716a28ef2SGary JennejohnOn a faster machine, such as a sequoia, cut&paste of longer (about 80 7816a28ef2SGary Jennejohncharacters) lines works fine when serial is the only device used. 7916a28ef2SGary Jennejohn 8016a28ef2SGary JennejohnUsing nc as a stdin device results in even more overhead because nc_tstc() 8116a28ef2SGary Jennejohnis quite slow. Even on a sequoia cut&paste does not work on the serial 8216a28ef2SGary Jennejohninterface when nc is added to stdin, although there is no character loss using 8316a28ef2SGary Jennejohnthe ethernet interface for input. In this test case stdin=serial,nc and 8416a28ef2SGary Jennejohnstdout=serial. 8516a28ef2SGary Jennejohn 8616a28ef2SGary JennejohnIn addition, the overhead associated with sending to two devices, when one of 8716a28ef2SGary Jennejohnthem is nc, also causes problems. Even on a sequoia cut&paste does not work 8816a28ef2SGary Jennejohnon the serial interface (stdin=serial) when nc is added to stdout (stdout= 8916a28ef2SGary Jennejohnserial,nc). 90