Rasperry Pi looses serial after boot (VGA is OK)

Hi folks,

I built my first rpi4 image and it is working great. NixOS is amazing.

The only problem is that when I connect serial via GPIO pins as I always do, and turn rpi4 on, I can get serial output:

...
mmc0 is current device
Scanning mmc 0:2...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
------------------------------------------------------------
1:      NixOS - Default
Enter choice: 1:        NixOS - Default
Retrieving file: /boot/extlinux/../nixos/qx2n5ahf5syck3gnzxd93k1wf99q20w5-initrd-linux-6.1.57-initrd
Retrieving file: /boot/extlinux/../nixos/74j767inpgxk1r4f81jsxpq5xbfzg1bg-linux-6.1.57-Image
append: init=/nix/store/jrxq6hi57ycgiygs5mcsy6d5a5d89axm-nixos-system-rpi-23.05.20231013.898cb20/init console=tty0 console=ttyS0,115200n8 consoleblank=0 systemd.show_status=1 nohibernate loglevel=7
Retrieving file: /boot/extlinux/../nixos/74j767inpgxk1r4f81jsxpq5xbfzg1bg-linux-6.1.57-dtbs/broadcom/bcm2711-rpi-4-b.dtb
Moving Image from 0x80000 to 0x200000, end=3a70000
...
Starting kernel ...

And then I loose serial - just VGA (over HDMI) from that point on.

You can see that my configuration has serial configured since in append: I have console=tty0 console=ttyS0,115200n8 which in my opinion should give me serial as the primary output and VGA as the secondary - exactly as I would like to have…

Could you please tell me what am I missing there?

Thank you.

Honda

Hi,

try with console=ttyAMA0,115200n8

Hi @sorki

Thank you for the tip. I finally had time to test it:

append: init=/nix/store/13admkv4m557q1v1wzai6j3r5y4l0vqa-nixos-system-rpi-23.05.20231013.898cb20/init console=tty0 console=ttyAMA0,115200n8 consoleblank=0 systemd.show_status=1 nohibernate loglevel=7

But it behaves the same. Serial works at the beginning of the boot and then it stops.

Hmm, I’ve recently learned there are two UARTs on Pi3+ (mini UART and full PL011 UART), check out for example pi 3 - How do I make serial work on the Raspberry Pi3 (PiZeroW, Pi4 or later models) - Raspberry Pi Stack Exchange

I would try adding all the variants to command line, like console=ttyS0,115200n8 console=ttyS1,115200n8 console=ttyAMA0,115200n8 console=ttyAMA1,115200n8 to see if it helps. If not you might need to fiddle with device tree overlays to disable Bluetooth (or use another UART / pins).

I would test it but I don’t have a Pi4 at hand currently (it will arrive with Pi5 during this or next month).

I didn’t know that but serial works both with Ubuntu Server and Raspbian so the problem is in my configuration.

console=ttyS0,115200n8 console=ttyS1,115200n8 console=ttyAMA0,115200n8 console=ttyAMA1,115200n8

Yeah, already tried all options. I think the problem is that the config.boot.kernelParams tell the bootloader to output on serial but I’m missing something that tells the system when it is up and running also to output to serial…

boot.kernelParams are passed from generated extlinux configuration to Linux kernel. U-Boot starts first and enables a serial (or all of them I don’t know exactly tbh), then it loads /boot/extlinux/extlinux.conf which contains a kernel command line specified in boot.kernelParams - this is all that is typically needed to get serial output on console(s) and later a login prompt. (This is a simplified view of the boot sequence but the rest is not really relevant for us).

So you actually correctly instruct kernel (not bootloader) and this should “just” work, but… :slight_smile:

There are 3 stages where serial might be enabled:

  • Post - server and embedded motherboards can enable serial in BIOS / firmware so it is possible to see messages / jump to ncurses-like BIOS config
  • Bootloader (Grub, U-Boot)
  • Running OS via systemd-getty-generator and that is likely the problem

Example

  • AWS (serial only)
# ps aux | grep getty
root         678  0.0  0.0   5528   244 ttyS0    Ss+  06:49   0:00 agetty --login-program /nix/store/gabb48czg1lbr1j9np7wqgi27viar4wx-shadow-4.13/bin/login ttyS0 --keep-baud
root         940  0.0  0.0   6476  2544 pts/0    S+   06:50   0:00 grep getty
  • My laptop (VGA only)
# ps aux | grep getty
root       14462  0.0  0.0   5532   252 tty1     Ss+  Oct19   0:00 agetty --login-program /nix/store/1h05v36iy2ilx6lvp28nvb396k38qxjy-shadow-4.13/bin/login --noclear --keep-baud tty1 115200,38400,9600 linux
root      548582  0.0  0.0 222572  2644 pts/0    S+   06:52   0:00 grep getty
  • My server (both)
# ps aux | grep getty
root        8402  0.0  0.0   5532   260 tty1     Ss+  06:54   0:00 agetty --login-program /nix/store/1h05v36iy2ilx6lvp28nvb396k38qxjy-shadow-4.13/bin/login --noclear --keep-baud tty1 115200,38400,9600 linux
root        8441  0.0  0.0   5532   252 ttyS0    Ss+  06:54   0:00 agetty --login-program /nix/store/1h05v36iy2ilx6lvp28nvb396k38qxjy-shadow-4.13/bin/login ttyS0 --keep-baud vt220
root        9039  0.0  0.0 222572  2660 pts/0    S+   07:00   0:00 grep getty
1 Like