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