From fdf21dccbab633957d3f46ce79f6f037f51229ad Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Wed, 30 Oct 2024 19:38:59 +0800 Subject: [PATCH 1/4] drm-panic: kernel: Enable SimpleDRM Currently on a LFS system booted via legacy BIOS (intead of UEFI), the users can make two different configurations: 1. The DRM driver for the GPU is built as a module. Then before the module is loaded (i.e. the root fs is properly mounted) the kernel messages are displayed via the VGA console. 2. The DRM driver for the GPU is built into the kernel image. Then the kernel messages are displayed via the DRM-emulated framebuffer console since a very early stage (before the root fs is properly mounted). When the system is booted via UEFI, we use SimpleDRM on the EFI framebuffer for displaying kernel messages, thus it's always the case 2. Both are not good for diagnostic in case the root fs cannot be mounted properly (it's very frequent on lfs-support): - With 1 the VGA console can only fit 80x24 characters, so the relevent information is often flushed away. - With 2 the panic message is often displayed improperly when a DRM driver is running. The "DRM panic" feature introduced since Linux 6.11 (but it'll only become usable for LFS since Linux 6.12) can fix the case 2, while case 1 just cannot be fixed. So start to make LFS booted via legacy BIOS to use method 2 now, then we can enable DRM panic and fix this long-standing issue. --- chapter10/kernel.xml | 4 ++-- chapter10/kernel/kernel.version | 2 +- chapter10/kernel/systemd.toml | 14 +++++--------- chapter10/kernel/systemd.xml | 10 +++++----- chapter10/kernel/sysv.toml | 14 +++++--------- chapter10/kernel/sysv.xml | 11 ++++++----- 6 files changed, 24 insertions(+), 31 deletions(-) diff --git a/chapter10/kernel.xml b/chapter10/kernel.xml index 4eb87a17b..8155f735c 100644 --- a/chapter10/kernel.xml +++ b/chapter10/kernel.xml @@ -282,8 +282,8 @@ These are needed to display the Linux console on a GPU driven by a DRI (Direct Rendering Infrastructure) driver. - If (Direct Rendering Manager) is - enabled, you should enable these two options as well or you'll see + As (Direct Rendering Manager) is + enabled, we should enable these two options as well or we'll see a blank screen once the DRI driver is loaded. diff --git a/chapter10/kernel/kernel.version b/chapter10/kernel/kernel.version index 22cb9e553..ff61e1868 100644 --- a/chapter10/kernel/kernel.version +++ b/chapter10/kernel/kernel.version @@ -1 +1 @@ -6.10.2 +6.12.1 diff --git a/chapter10/kernel/systemd.toml b/chapter10/kernel/systemd.toml index bfe7a1b40..649df88d4 100644 --- a/chapter10/kernel/systemd.toml +++ b/chapter10/kernel/systemd.toml @@ -13,7 +13,11 @@ STACKPROTECTOR_STRONG='*' UEVENT_HELPER=' ' DEVTMPFS='*' DEVTMPFS_MOUNT='*' -DRM=' *M' +SYSFB_SIMPLEFB='*' +DRM='*' +DRM_FBDEV_EMULATION='*' +DRM_SIMPLEDRM='*' +FRAMEBUFFER_CONSOLE='*' NET='*' INET='*' IPV6='*' @@ -30,11 +34,3 @@ revision='systemd' [RT_GROUP_SCHED] value = ' ' comment = 'This may cause some systemd features malfunction' - -[DRM_FBDEV_EMULATION] -value = ' *' -comment = 'If [DRM] is selected as * or M, this must be selected' - -[FRAMEBUFFER_CONSOLE] -value = ' *' -comment = 'If [DRM] is selected as * or M, this must be selected' diff --git a/chapter10/kernel/systemd.xml b/chapter10/kernel/systemd.xml index a03c67402..beff1eb2d 100644 --- a/chapter10/kernel/systemd.xml +++ b/chapter10/kernel/systemd.xml @@ -42,15 +42,15 @@ ... [FW_LOADER_USER_HELPER] Firmware Drivers ---> [*] Export DMI identification via sysfs to userspace [DMIID] + [*] Mark VGA/VBE/EFI FB as generic system framebuffer [SYSFB_SIMPLEFB] Graphics support ---> - < /*/M> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) ---> + <*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) ---> ... [DRM] - # If [DRM] is selected as * or M, this must be selected: - [ /*] Enable legacy fbdev support for your modesetting driver + [*] Enable legacy fbdev support for your modesetting driver ... [DRM_FBDEV_EMULATION] + <*> Simple framebuffer driver [DRM_SIMPLEDRM] Console display driver support ---> - # If [DRM] is selected as * or M, this must be selected: - [ /*] Framebuffer Console support [FRAMEBUFFER_CONSOLE] + [*] Framebuffer Console support [FRAMEBUFFER_CONSOLE] File systems ---> [*] Inotify support for userspace [INOTIFY_USER] diff --git a/chapter10/kernel/sysv.toml b/chapter10/kernel/sysv.toml index 3f8d2e93c..5f6812821 100644 --- a/chapter10/kernel/sysv.toml +++ b/chapter10/kernel/sysv.toml @@ -12,14 +12,10 @@ STACKPROTECTOR_STRONG='*' UEVENT_HELPER=' ' DEVTMPFS='*' DEVTMPFS_MOUNT='*' -DRM=' *M' +SYSFB_SIMPLEFB='*' +DRM='*' +DRM_FBDEV_EMULATION='*' +DRM_SIMPLEDRM='*' +FRAMEBUFFER_CONSOLE='*' revision='sysv' - -[DRM_FBDEV_EMULATION] -value = ' *' -comment = 'If [DRM] is selected as * or M, this must be selected' - -[FRAMEBUFFER_CONSOLE] -value = ' *' -comment = 'If [DRM] is selected as * or M, this must be selected' diff --git a/chapter10/kernel/sysv.xml b/chapter10/kernel/sysv.xml index 451898a21..0c1d05e5a 100644 --- a/chapter10/kernel/sysv.xml +++ b/chapter10/kernel/sysv.xml @@ -28,12 +28,13 @@ [*] Maintain a devtmpfs filesystem to mount at /dev [DEVTMPFS] [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs ... [DEVTMPFS_MOUNT] + Firmware Drivers ---> + [*] Mark VGA/VBE/EFI FB as generic system framebuffer [SYSFB_SIMPLEFB] Graphics support ---> - < /*/M> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) ---> + <*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) ---> ... [DRM] - # If [DRM] is selected as * or M, this must be selected: - [ /*] Enable legacy fbdev support for your modesetting driver + [*] Enable legacy fbdev support for your modesetting driver ... [DRM_FBDEV_EMULATION] + <*> Simple framebuffer driver [DRM_SIMPLEDRM] Console display driver support ---> - # If [DRM] is selected as * or M, this must be selected: - [ /*] Framebuffer Console support [FRAMEBUFFER_CONSOLE] + [*] Framebuffer Console support [FRAMEBUFFER_CONSOLE] From 33c17d128bdf1f3a10e086b2b13a1ec655bcf7ed Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Wed, 30 Oct 2024 19:59:56 +0800 Subject: [PATCH 2/4] drm-panic: grub: Set up the VESA framebuffer for the kernel In the previous commit we've enabled the kernel to use the SimpleDRM driver on the VESA framebuffer. Now provide the VESA framebuffer to the kernel. --- chapter10/grub.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/chapter10/grub.xml b/chapter10/grub.xml index 1706ccb3c..00be1d6c0 100644 --- a/chapter10/grub.xml +++ b/chapter10/grub.xml @@ -135,6 +135,7 @@ set timeout=5 insmod part_gpt insmod ext2 set root=(hd0,2) +set gfxpayload=1024x768x32 menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" { linux /boot/vmlinuz-&linux-version;-lfs-&version; root=/dev/sda2 ro @@ -159,6 +160,14 @@ EOF be needed with some rare configurations. + + The set gfxpayload=1024x768x32 command sets the + resolution and color depth of the VESA framebuffer to be passed to the + kernel. It's necessary for the kernel SimpleDRM driver to use the + VESA framebuffer. You can use a different resolution or color depth + value which better suits for your monitor. + + From GRUB's perspective, the kernel files are relative to the partition used. If you used a separate /boot partition, remove /boot from the above From 2349341e3e641bb87b879d5547fc4c4a6275e713 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Sun, 1 Dec 2024 17:30:51 +0800 Subject: [PATCH 3/4] drm-panic: kernel: Enable DRM_PANIC Since the previous commit, we've ensured the kernel displaying via DRM even in the early stage. Now enable DRM_PANIC so the kernel will correctly show the last lines of the kernel messages in case a panic happens. Tested with an incorrect root= line in 3 configurations: - A QEMU VM booted via BIOS - A real machine booted via BIOS - A real machine booted via UEFI And in all configurations the panic message is correctly dumped. In 1024x768 we can get 48 lines (twice of 24 lines in VGA console). --- chapter10/kernel/systemd.toml | 2 ++ chapter10/kernel/systemd.xml | 7 +++++-- chapter10/kernel/sysv.toml | 2 ++ chapter10/kernel/sysv.xml | 7 +++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/chapter10/kernel/systemd.toml b/chapter10/kernel/systemd.toml index 649df88d4..387a74b66 100644 --- a/chapter10/kernel/systemd.toml +++ b/chapter10/kernel/systemd.toml @@ -15,6 +15,8 @@ DEVTMPFS='*' DEVTMPFS_MOUNT='*' SYSFB_SIMPLEFB='*' DRM='*' +DRM_PANIC='*' +DRM_PANIC_SCREEN='kmsg' DRM_FBDEV_EMULATION='*' DRM_SIMPLEDRM='*' FRAMEBUFFER_CONSOLE='*' diff --git a/chapter10/kernel/systemd.xml b/chapter10/kernel/systemd.xml index beff1eb2d..0525fbd0a 100644 --- a/chapter10/kernel/systemd.xml +++ b/chapter10/kernel/systemd.xml @@ -46,9 +46,12 @@ Graphics support ---> <*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) ---> ... [DRM] - [*] Enable legacy fbdev support for your modesetting driver + [*] Display a user-friendly message when a kernel panic occurs + ... [DRM_PANIC] + (kmsg) Panic screen formatter [DRM_PANIC_SCREEN] + [*] Enable legacy fbdev support for your modesetting driver ... [DRM_FBDEV_EMULATION] - <*> Simple framebuffer driver [DRM_SIMPLEDRM] + <*> Simple framebuffer driver [DRM_SIMPLEDRM] Console display driver support ---> [*] Framebuffer Console support [FRAMEBUFFER_CONSOLE] diff --git a/chapter10/kernel/sysv.toml b/chapter10/kernel/sysv.toml index 5f6812821..c8267a303 100644 --- a/chapter10/kernel/sysv.toml +++ b/chapter10/kernel/sysv.toml @@ -14,6 +14,8 @@ DEVTMPFS='*' DEVTMPFS_MOUNT='*' SYSFB_SIMPLEFB='*' DRM='*' +DRM_PANIC='*' +DRM_PANIC_SCREEN='kmsg' DRM_FBDEV_EMULATION='*' DRM_SIMPLEDRM='*' FRAMEBUFFER_CONSOLE='*' diff --git a/chapter10/kernel/sysv.xml b/chapter10/kernel/sysv.xml index 0c1d05e5a..f90164d65 100644 --- a/chapter10/kernel/sysv.xml +++ b/chapter10/kernel/sysv.xml @@ -33,8 +33,11 @@ Graphics support ---> <*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) ---> ... [DRM] - [*] Enable legacy fbdev support for your modesetting driver + [*] Display a user-friendly message when a kernel panic occurs + ... [DRM_PANIC] + (kmsg) Panic screen formatter [DRM_PANIC_SCREEN] + [*] Enable legacy fbdev support for your modesetting driver ... [DRM_FBDEV_EMULATION] - <*> Simple framebuffer driver [DRM_SIMPLEDRM] + <*> Simple framebuffer driver [DRM_SIMPLEDRM] Console display driver support ---> [*] Framebuffer Console support [FRAMEBUFFER_CONSOLE] From 5ee35073fbe1229ed984514c6ac1496c5224e20c Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Wed, 30 Oct 2024 20:51:59 +0800 Subject: [PATCH 4/4] drm-panic: kernel: Explain DRM panic settings --- chapter10/kernel.xml | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/chapter10/kernel.xml b/chapter10/kernel.xml index 8155f735c..e078e136d 100644 --- a/chapter10/kernel.xml +++ b/chapter10/kernel.xml @@ -272,6 +272,71 @@ + + + + Display a user-friendly message when a kernel panic occurs + + + + This will make the kernel correctly display the message + in case a kernel panic happens and a running DRM driver + supports to do so. Without this, it would be more + difficult to diagnose a panic: if no DRM driver is running, + we'd be on the VGA console which can only hold 24 lines and + the relevent kernel message is often flushed away; if a DRM + driver is running, the display is often completely messed up + on panic. As of Linux-6.12, none of the dedicated drivers for + mainstream GPU models really supports this, but it's supported by + the Simple framebuffer driver which runs on the + VESA (or EFI) framebuffer before the dedicated GPU driver is + loaded. If the dedicated GPU driver is built as a module + (instead of a part of the kernel image) and no initramfs is + used, this functionality will work just fine before the root + file system is mounted and it's already enough for providing + information about most LFS configuration errors causing a + panic (for example, an incorrect root= + setting in ). + + + + + + + Panic screen formatter + + + + Set this kmsg to make sure the last + kernel messages lines are displayed when a kernel panic happens. + The default, user, would make the kernel show + only a user friendly panic message which is not + helpful on diagnostic. The third choice, + qr_code, would make the kernel to compress + the last kernel message lines into a QR code and display it. + The QR code can hold more message lines than plain text and it + can be decoded with an external device (like a smart phone). + But it requires a Rust compiler that LFS does not provide. + + + + + + + Mark VGA/VBE/EFI FB as generic system framebuffer + and + Simple framebuffer driver + + + These allow to use the VESA framebuffer (or the EFI + framebuffer if booting the LFS system via UEFI) as a DRM device. + The VESA framebuffer will be set up by GRUB (or the EFI + framebuffer will be set up by the UEFI firmware), so the DRM panic + handler can function before the GPU-specific DRM driver is + loaded. + + +