Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 1 | Network console |
| 2 | =============== |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 3 | |
| 4 | In U-Boot, we implemented the networked console via the standard |
| 5 | "devices" mechanism, which means that you can switch between the |
| 6 | serial and network input/output devices by adjusting the 'stdin' and |
| 7 | 'stdout' environment variables. To switch to the networked console, |
| 8 | set either of these variables to "nc". Input and output can be |
| 9 | switched independently. |
| 10 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 11 | The default buffer size can be overridden by setting |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 12 | CFG_NETCONSOLE_BUFFER_SIZE. |
Joe Hershberger | 45f4a23 | 2012-07-31 06:09:17 +0000 | [diff] [blame] | 13 | |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 14 | We use an environment variable 'ncip' to set the IP address and the |
| 15 | port of the destination. The format is <ip_addr>:<port>. If <port> is |
| 16 | omitted, the value of 6666 is used. If the env var doesn't exist, the |
| 17 | broadcast address and port 6666 are used. If it is set to an IP |
| 18 | address of 0 (or 0.0.0.0) then no messages are sent to the network. |
Joe Hershberger | d0f5396 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 19 | The source / listening port can be configured separately by setting |
| 20 | the 'ncinport' environment variable and the destination port can be |
Fiona Klute | 4a4161f | 2024-05-18 12:47:05 +0200 | [diff] [blame^] | 21 | configured by setting the 'ncoutport' environment variable. Note that |
| 22 | you need to set up the network interface (e.g. using DHCP) before it |
| 23 | can be used for network console. |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 24 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 25 | For example, if your server IP is 192.168.1.1, you could use:: |
wdenk | fa66e93 | 2005-04-03 14:52:59 +0000 | [diff] [blame] | 26 | |
| 27 | => setenv nc 'setenv stdout nc;setenv stdin nc' |
| 28 | => setenv ncip 192.168.1.1 |
| 29 | => saveenv |
| 30 | => run nc |
| 31 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 32 | On the host side, please use this script to access the console |
wdenk | fa66e93 | 2005-04-03 14:52:59 +0000 | [diff] [blame] | 33 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 34 | .. code-block:: bash |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 35 | |
Mike Frysinger | 9649d11 | 2008-12-09 23:20:31 -0500 | [diff] [blame] | 36 | tools/netconsole <ip> [port] |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 37 | |
Mike Frysinger | 9649d11 | 2008-12-09 23:20:31 -0500 | [diff] [blame] | 38 | The script uses netcat to talk to the board over UDP. It requires you to |
| 39 | specify the target IP address (or host name, assuming DNS is working). The |
| 40 | script can be interrupted by pressing ^T (CTRL-T). |
wdenk | fa66e93 | 2005-04-03 14:52:59 +0000 | [diff] [blame] | 41 | |
Igor Marnat | 6df6690 | 2007-03-21 09:55:01 +0300 | [diff] [blame] | 42 | Be aware that in some distributives (Fedora Core 5 at least) |
| 43 | usage of nc has been changed and -l and -p options are considered |
| 44 | as mutually exclusive. If nc complains about options provided, |
| 45 | you can just remove the -p option from the script. |
| 46 | |
wdenk | b3a4a70 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 47 | It turns out that 'netcat' cannot be used to listen to broadcast |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 48 | packets. We developed our own tool 'ncb' (see tools directory) that |
| 49 | listens to broadcast packets on a given port and dumps them to the |
Mike Frysinger | cb97640 | 2009-09-09 12:20:21 -0400 | [diff] [blame] | 50 | standard output. It will be built when compiling for a board which |
| 51 | has CONFIG_NETCONSOLE defined. If the netconsole script can find it |
| 52 | in PATH or in the same directory, it will be used instead. |
wdenk | fa66e93 | 2005-04-03 14:52:59 +0000 | [diff] [blame] | 53 | |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 54 | For Linux, the network-based console needs special configuration. |
| 55 | Minimally, the host IP address needs to be specified. This can be |
| 56 | done either via the kernel command line, or by passing parameters |
| 57 | while loading the netconsole.o module (when used in a loadable module |
| 58 | configuration). Please refer to Documentation/networking/logging.txt |
| 59 | file for the original Ingo Molnar's documentation on how to pass |
| 60 | parameters to the loadable module. |
| 61 | |
| 62 | The format of the kernel command line parameter (for the static |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 63 | configuration) is as follows |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 64 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 65 | .. code-block:: bash |
| 66 | |
| 67 | netconsole=[src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr] |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 68 | |
| 69 | where |
| 70 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 71 | src-port |
| 72 | source for UDP packets (defaults to 6665) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 73 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 74 | src-ip |
| 75 | source IP to use (defaults to the interface's address) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 76 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 77 | dev |
| 78 | network interface (defaults to eth0) |
| 79 | |
| 80 | tgt-port |
| 81 | port for logging agent (defaults to 6666) |
| 82 | |
| 83 | tgt-ip |
| 84 | IP address for logging agent (this is the required parameter) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 85 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 86 | tgt-macaddr |
| 87 | ethernet MAC address for logging agent (defaults to broadcast) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 88 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 89 | Examples |
| 90 | |
| 91 | .. code-block:: bash |
| 92 | |
| 93 | netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 94 | netconsole=@/,@192.168.3.1/ |
| 95 | |
| 96 | Please note that for the Linux networked console to work, the |
| 97 | ethernet interface has to be up by the time the netconsole driver is |
| 98 | initialized. This means that in case of static kernel configuration, |
| 99 | the respective Ethernet interface has to be brought up using the "IP |
| 100 | Autoconfiguration" kernel feature, which is usually done by defaults |
| 101 | in the ELDK-NFS-based environment. |
| 102 | |
| 103 | To browse the Linux network console output, use the 'netcat' tool invoked |
| 104 | as follows: |
| 105 | |
Heinrich Schuchardt | 1cab1c8 | 2020-12-12 09:37:47 +0100 | [diff] [blame] | 106 | .. code-block:: bash |
| 107 | |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 108 | nc -u -l -p 6666 |
wdenk | b3a4a70 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 109 | |
| 110 | Note that unlike the U-Boot implementation the Linux netconsole is |
| 111 | unidirectional, i. e. you have console output only in Linux. |
Fiona Klute | 4a4161f | 2024-05-18 12:47:05 +0200 | [diff] [blame^] | 112 | |
| 113 | Setup via environment |
| 114 | --------------------- |
| 115 | |
| 116 | If persistent environment is enabled in your U-Boot configuration, you |
| 117 | can configure the network console using the environment. For example: |
| 118 | |
| 119 | .. prompt:: bash => |
| 120 | |
| 121 | env set autoload no |
| 122 | env set hostname "u-boot" |
| 123 | env set bootdelay 5 |
| 124 | env set nc 'dhcp; env set stdout nc; env set stderr nc; env set stdin nc' |
| 125 | env set ncip '192.168.1.1' |
| 126 | env set preboot "${preboot}; run nc;" |
| 127 | env save |
| 128 | reset |
| 129 | |
| 130 | ``autoload no`` tells the ``dhcp`` command to configure the network |
| 131 | interface without trying to load an image. ``hostname "u-boot"`` sets |
| 132 | the hostname to be sent in DHCP requests, so they are easy to |
| 133 | recognize in the DHCP server log. The command in ``nc`` calls ``dhcp`` |
| 134 | to make sure the network interface is set up before enabling |
| 135 | netconsole. |
| 136 | |
| 137 | Adding ``nc`` to ``preboot`` tells U-Boot to activate netconsole |
| 138 | before trying to find any boot options, so you can interact with it if |
| 139 | desired. |
| 140 | |
| 141 | ``env save`` stores the settings persistently, and ``reset`` then |
| 142 | triggers a fresh start that will use the changed settings. |