Skip to content

Interactive console

hwn console is a small serial terminal, in the spirit of miniterm and picocom, with one thing they do not do by default: it keeps a session log you can attach to a report. It is pure Python, works on Linux, macOS and Windows, and talks to anything hwntools can open: a serial port, a pyserial URL, a ser2net bridge (tcp:HOST:PORT) or the simulator.

$ hwn console /dev/ttyUSB0 -b 115200 --log session.log --timestamps
$ hwn console COM3 -b 115200                           # Windows
$ hwn console tcp:10.0.0.5:3001 --log session.log      # ser2net
$ hwn console /dev/ttyUSB0 -b auto                     # run autobaud, then connect
$ hwn console --sim                                    # a simulated U-Boot, no hardware

Serial ports need pip install "hwntools[serial]"; --sim and tcp: need nothing extra.

Keys

Every key goes to the target as soon as you press it, including Ctrl-C (to stop U-Boot's autoboot or interrupt a command) and Ctrl-Z. The console itself listens to two keys:

Keys Action
Ctrl-] quit
Ctrl-T then b send a BREAK (serial ports only; some consoles use it for magic SysRq)
Ctrl-T then h toggle the hex view: received bytes are shown as hex, 16 per row
Ctrl-T then e toggle local echo (for targets that do not echo what you type)
Ctrl-T then Ctrl-T / Ctrl-] send that key to the target
Ctrl-T then ? list the keys

Enter sends a carriage return (--eol cr, what most consoles expect); use --eol lf or --eol crlf for targets that want something else. --echo and --hex start with local echo or the hex view switched on.

Session log

--log FILE appends everything the target sends to FILE, byte for byte. Each session is framed by a header and a footer line, and existing content is never overwritten, so one file can collect a whole engagement. With --timestamps (-t) every line starts with the local time it began:

session.log (excerpt)
--- hwn console: simulated U-Boot (--sim), started 2026-12-05 16:06:36.133 ---
[2026-12-05 16:06:36.134] Hit any key to stop autoboot:  5
[2026-12-05 16:06:36.134] => printenv bootargs
[2026-12-05 16:06:36.134] bootargs=console=ttyS0,115200 root=/dev/mtdblock3 rootfstype=squashfs
[2026-12-05 16:06:36.134] => md.b 80000000 20
[2026-12-05 16:06:36.134] 80000000: 27 05 19 56 68 77 6e 74 6f 6f 6c 73 20 73 69 6d    '..Vhwntools sim
[2026-12-05 16:06:36.134] 80000010: 75 6c 61 74 65 64 20 72 6f 75 74 65 72 00 00 00    ulated router...
[2026-12-05 16:06:36.134] =>
--- hwn console: closed 2026-12-05 16:06:36.691 ---

What you type is not logged separately: consoles echo it back, so it appears in the log as the target printed it (passwords typed at a Password: prompt are not echoed, and so not logged). The hex view only changes the screen; the log always holds the raw bytes.

Try it with the simulator

hwn console --sim connects to the same simulated U-Boot used throughout Learn. Press any key within five seconds to stop the autoboot countdown, then try printenv, version or md.b 80000000 40.

Input does not have to come from the keyboard. When standard input is a pipe, its bytes are typed for you and the console exits once the input ends and the target has gone quiet, which makes quick captures scriptable:

$ printf '\rprintenv bootargs\rmd.b 80000000 20\r' | hwn console --sim --log session.log -t
[*] Simulated U-Boot: press a key within 5 s to stop autoboot, Ctrl-] to quit
[*] Logging received data to session.log


U-Boot 2020.04 (Mar 12 2024 - 10:21:07 +0000)

CPU:   Simulated ARMv7 @ 800 MHz
DRAM:  128 MiB
SF: Detected w25q128 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
In:    serial
Out:   serial
Err:   serial
Net:   eth0
Hit any key to stop autoboot:  5
=> printenv bootargs
bootargs=console=ttyS0,115200 root=/dev/mtdblock3 rootfstype=squashfs
=> md.b 80000000 20
80000000: 27 05 19 56 68 77 6e 74 6f 6f 6c 73 20 73 69 6d    '..Vhwntools sim
80000010: 75 6c 61 74 65 64 20 72 6f 75 74 65 72 00 00 00    ulated router...
=>

For anything longer than a few commands, write a script with tubes and UBoot instead.

From Python

The console works on any tube:

from hwntools import serial
from hwntools.console import Console

with serial("/dev/ttyUSB0", 115200) as io:
    io.sendline(b"")                         # script the first steps...
    io.recvuntil(b"login: ")
    Console(io, log_path="session.log", timestamps=True).run()   # ...then take over by hand

Unlike Tube.interactive(), which sends whole lines from a cooked terminal, Console puts the terminal in raw mode, so line editing happens on the target (as with any serial terminal) and control keys reach it.

See the API reference for all options.