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