Serial console com port change

Started by user1234, November 16, 2023, 03:22:59 PM

Previous topic - Next topic
It is possible to specify which serial port to use? e.g. /dev/ttyu1

My board has two serial ports and I can see the console on /dev/ttyu0 but not /dev/ttyu1.
I would like to use /dev/ttyu1 if possible.

November 16, 2023, 03:57:28 PM #1 Last Edit: November 16, 2023, 04:47:46 PM by meyergru
It depends on what you try to achieve.

First you should look if both serial ports are being recognized by examining the output of "dmesg | fgrep uart".

FreeBSD has some kernel parameters in /boot/loader.conf, namely:

# dynamically generated console settings follow
comconsole_speed="115200"
boot_multicons="YES"
boot_serial="YES"
#kern.vty
console="efi,comconsole"


However, OpnSense creates that file via rc.loader. Essentially, those settings are created from System->Settings->Administration->Console. I assume you have "Serial Console" (i.e. "comconsole") active there. Normally, the kernel decides by itself which serial device to use as the console and chooses the first one per default.

This can be changed by the uart flags, see "man uart" and this page, which also explains how to set ports if they are non-standard. Again, this should be done in the "Tuneables" section in OpnSense, not in the FreeBSD files themselves.

Also, there is /etc/ttys, where you can configure your serial ports as terminals. Usually, the first four serials are defined to be enabled if the kernel uses the for a console (onifconsole), but you can configure to use them if they exist at all by "onifexists":

# The 'dialup' keyword identifies dialin lines to login, fingerd etc.
ttyu0   "/usr/libexec/getty 3wire.115200"       vt100   onifconsole secure
ttyu1   "/usr/libexec/getty 3wire.115200"       vt100   onifconsole secure
ttyu2   "/usr/libexec/getty 3wire.115200"       vt100   onifconsole secure
ttyu3   "/usr/libexec/getty 3wire.115200"       vt100   onifconsole secure


So, in short:

1. Determine if all ports are detected and potentially correct this.
2. If you want to use ttyu1 as kernel console port, disable ttyu0 via uart flags and enable ttyu0. This will handle the switch of the terminal part automatically.
3. If you only want ttyu1 as an additional terminal, specify "onifexists" in /etc/ttys.

Intel N100, 4 x I226-V, 16 GByte, 256 GByte NVME, ZTE F6005

1100 down / 770 up, Bufferbloat A

Thanks that is really useful.
Ideally I would like to add ttyu1 as an additional console so this would be edit the /etc/ttys file to be "onifexists".

My follow up question is how do I make the /etc/ttys file persistent, can this be set via the opnsense interface?

Thanks

By changing /etc/ttys, you will get just two terminals. I do not know if it is at all possible to have two kernel serial consoles. The specification allows for a serial and another EFI console, but I do not know if two serial ports would work through uart flags. The man page says the flag 10 tells this is a "potential system console", I would think that the kernel decides for one only.
Intel N100, 4 x I226-V, 16 GByte, 256 GByte NVME, ZTE F6005

1100 down / 770 up, Bufferbloat A

I have tried a number of different things now but nothing seems to work.
I have tried adding hint.uart.0.disabled=1 to disable the first uart.

Also tried hint.uart.1.flags=0x10 but no luck.

Strangely when I test the serial port via echo "test" > /dev/ttyu1 it hangs and does not send. Doing this on /dev/ttyu0 works fine.

I know the hardware works as I booted into an Ubuntu live image and both serial ports work on there.

Any ideas?

Comparing the two ports using stty -a -f /dev/ttyu0 shows the difference between the ports is ttyu0 has "clocal" and ttyu1 has "-clocal"

November 21, 2023, 09:17:39 PM #6 Last Edit: November 21, 2023, 09:20:15 PM by meyergru
Yes, quoting myself:

Quote from: meyergru on November 16, 2023, 03:57:28 PM
This can be changed by the uart flags, see "man uart" and this page, which also explains how to set ports if they are non-standard. Again, this should be done in the "Tuneables" section in OpnSense, not in the FreeBSD files themselves.

There are some default ISA port numbers on which the first four serial ports reside and which the kernels tests, but sometimes they are different, like on Supermicro mainboards. You have to find out which port number your second serial port is on.

Intel N100, 4 x I226-V, 16 GByte, 256 GByte NVME, ZTE F6005

1100 down / 770 up, Bufferbloat A