Raspberry Pi 4: force video mode at boot

Testig himblick automatic media replication
Testig himblick automatic media replication

This is part of a series of posts on the design and technical steps of creating Himblick, a digital signage box based on the Raspberry Pi 4.

Another surprise hits us at the last moment: if the system boots without an HDMI monitor plugged in, no framebuffer device is ever created, and X will not start, lightdm will give up after some tries, and even if one plugs in a monitor afterwards, it will stay blank until a reboot or some kind of manual intervention.

As a workaround, one can configure the bootloader to force a specific HDMI configuration. This post documents how we did it.


Find out what video mode one needs

We plugged the target monitor into a laptop and ran xrandr to see the selection of video modes:

…
   1920x1080     60.00*+  50.00    59.94    30.00    25.00    24.00    29.97    23.98
   1920x1080i    60.00    50.00    59.94
…

Then we looked up the video mode in the hdmi_mode table, for DMT video modes, in the Video options in config.txt documentation.

Then, since the Raspberry Py 4 has two HDMI outputs, one can append :0 or :1 to each video option to select the output for which it applies.

The resulting bit of config.txt that did the trick for us was this:

# Pretend that a monitor is attached on HDMI0
hdmi_force_hotplug=1:0
# Pretend that the monitor is a monitor and not a TV
hdmi_group=2:0
# Pretend that the monitor has resolution 1920x1080
hdmi_mode=82:0

With that X started, but for some reason it started with different (lower) monitor resolution. Thankfully, a call to xrandr on startup fixed that too, and now everything works as expected whether the system boots with a monitor attached or not.