From cbeba372def25a957f5d8942f01fbde6cdc03704 Mon Sep 17 00:00:00 2001
From: Reza Alizadeh Majd <r.majd@pantherx.org>
Date: Sun, 28 Aug 2022 12:34:46 +0430
Subject: [PATCH] bootloader: extlinux: support for optional FDTDIR
There are situations that u-boot doesn't have to load from the device tree.
some provide the device tree using a vendor bootloader (like what raspberry-pi
does) or with an external bootloader that chainloads the u-boot (what Asahi
does for m1n1 bootloader).
Unfortunately we couldn't find any reliable document to enforce u-boot to pass
the device tree via `extlinux.conf`, however during our tests, we found that
removing the `FDTDIR` line from the `extlinux.conf` tend us to do so.
There is also no reliable way to guess if u-boot bootloader should load device
tree or not on a specific hardware. in addition, there are hardware that can
be booted with both firmware device tree on some kernels and with special
device tree on other (modified) kernels.
the following changes provided to define an optional parameter in <bootloader>
record, called <device-tree-support?> which by default is set to #t to keep
the current behavior unchanged. if this paramter is set to #f, the FDTDIR line
will be discarded from the <extlinux.conf> and u-boot doesn't load the device
tree automatically.
* gnu/bootloader.scm (<bootloader>)[device-tree-support?]: new field.
* gnu/bootloader/extlinux.scm (extlinux-configuration-file): add FDTDIR line
based on bootloader <device-tree-support?> field of <bootloader>.
* doc/guix.texi (Bootloader Configuration)[bootloader]: Add note about
bootloader's optional FDTDIR support.
---
doc/guix.texi | 9 +++++++++
gnu/bootloader.scm | 6 +++++-
gnu/bootloader/extlinux.scm | 13 +++++++++++--
3 files changed, 25 insertions(+), 3 deletions(-)
@@ -36814,6 +36814,15 @@ modules. In particular, @code{(gnu bootloader u-boot)} contains definitions
of bootloaders for a wide range of ARM and AArch64 systems, using the
@uref{https://www.denx.de/wiki/U-Boot/, U-Boot bootloader}.
+@quotation Note
+There are situations when @code{u-boot} shouldn't load the device tree from
+the file system. because it is either unnecessary for the platform being used
+or has already been loaded into RAM earlier in the boot process. in such cases
+you can set the @code{device-tree-support?} field of the @code{bootloader}
+record to @code{#f}. setting this flag to @code{#f} removes the @code{FDTDIR}
+from the @file{/boot/extlinux/extlinux.conf}.
+@end quotation
+
@vindex grub-efi-bootloader
@code{grub-efi-bootloader} allows to boot on modern systems using the
@dfn{Unified Extensible Firmware Interface} (UEFI). This is what you should
@@ -4,6 +4,7 @@
;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
;;; Copyright © 2019, 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2022 Reza Alizadeh Majd <r.majd@pantherx.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -54,6 +55,7 @@ (define-module (gnu bootloader)
bootloader-disk-image-installer
bootloader-configuration-file
bootloader-configuration-file-generator
+ bootloader-device-tree-support?
bootloader-configuration
bootloader-configuration?
@@ -172,7 +174,9 @@ (define-record-type* <bootloader>
(disk-image-installer bootloader-disk-image-installer
(default #f))
(configuration-file bootloader-configuration-file)
- (configuration-file-generator bootloader-configuration-file-generator))
+ (configuration-file-generator bootloader-configuration-file-generator)
+ (device-tree-support? bootloader-device-tree-support?
+ (default #t)))
;;;
@@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 David Craven <david@craven.ch>
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2022 Reza Alizadeh Majd <r.majd@pantherx.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -38,6 +39,10 @@ (define* (extlinux-configuration-file config entries
(define all-entries
(append entries (bootloader-configuration-menu-entries config)))
+ (define with-fdtdir?
+ (let ((bootloader (bootloader-configuration-bootloader config)))
+ (bootloader-device-tree-support? bootloader)))
+
(define (menu-entry->gexp entry)
(let ((label (menu-entry-label entry))
(kernel (menu-entry-linux entry))
@@ -46,12 +51,16 @@ (define (menu-entry->gexp entry)
#~(format port "LABEL ~a
MENU LABEL ~a
KERNEL ~a
- FDTDIR ~a/lib/dtbs
+ ~a
INITRD ~a
APPEND ~a
~%"
#$label #$label
- #$kernel (dirname #$kernel) #$initrd
+ #$kernel
+ (if #$with-fdtdir?
+ (string-append "FDTDIR " (dirname #$kernel) "/lib/dtbs")
+ "")
+ #$initrd
(string-join (list #$@kernel-arguments)))))
(define builder
--
2.37.1