HowTo: Support both BIOS and UEFI with Xorg Graphics Drivers on FreeBSD

Before starting X, however you plan to do that on your system, you may run this script at boot time by putting it under /usr/local/etc/rc.d/whatever.sh. Make sure you mark it as executable with chmod +x /usr/local/etc/rc.d/whatever.sh.

Here's the script contents for whatever.sh:
Code:
#!/bin/sh
if [ `uname -m` = "arm64" ]; then
    if [ -r '/usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf.bak' ]; then
        su -l root -c "mv -f /usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf.bak /usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf";
    fi;
    if [ -r '/usr/local/etc/X11/xorg.conf.d/xorg-bios.conf' ]; then
        su -l root -c "mv -f /usr/local/etc/X11/xorg.conf.d/xorg-bios.conf /usr/local/etc/X11/xorg.conf.d/xorg-bios.conf.bak";
    fi;
else
    if [ `/sbin/sysctl machdep.bootmethod | /usr/bin/awk -F' ' '{print $2}'` = BIOS ]; then
        if [ -r '/usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf' ]; then
            su -l root -c "mv -f /usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf /usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf.bak";
        fi;
        if [ -r '/usr/local/etc/X11/xorg.conf.d/xorg-bios.conf.bak' ]; then
        su -l root -c "mv -f /usr/local/etc/X11/xorg.conf.d/xorg-bios.conf.bak /usr/local/etc/X11/xorg.conf.d/xorg-bios.conf";
        fi;
    else
        if [ `/sbin/sysctl machdep.bootmethod | /usr/bin/awk -F' ' '{print $2}'` = UEFI ]; then
            if [ -r '/usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf.bak' ]; then
                su -l root -c "mv -f /usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf.bak /usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf";
            fi;
            if [ -r '/usr/local/etc/X11/xorg.conf.d/xorg-bios.conf' ]; then
                su -l root -c "mv -f /usr/local/etc/X11/xorg.conf.d/xorg-bios.conf /usr/local/etc/X11/xorg.conf.d/xorg-bios.conf.bak";
            fi;
        fi;
    fi;
fi;

As root, install the scfb driver with:
pkg install xf86-video-scfb

Minimal /usr/local/etc/X11/xorg.conf.d/xorg-uefi.conf:
Code:
Section    "Device"
    Identifier    "Card0"
    Driver        "scfb"
EndSection

Minimal /usr/local/etc/X11/xorg.conf.d/xorg-bios.conf:
Code:
Section    "Device"
    Identifier    "Card0"
    Driver        "vesa"
EndSection

This automates the process, so that, for example: live and usb installed systems can detect what driver to use based on the boot partition type in use on boot. Addtional uname -m checks are necessary if you wish to support more than amd64/i386 and arm64 devices.
 
Last edited:
Back
Top