diff mbox series

[bug#44543] gnu: raspberry-pi: Add helpers for config.txt file generation.

Message ID D5EFD887-3EDE-43E7-A461-97827D00F9B1@vodafonemail.de
State Accepted
Headers show
Series [bug#44543] gnu: raspberry-pi: Add helpers for config.txt file generation. | expand

Checks

Context Check Description
cbaines/submitting builds success
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job

Commit Message

Stefan Nov. 9, 2020, 11:53 p.m. UTC
* gnu/packages/raspberry-pi.scm (raspi-config-file, raspi-custom.txt):
  New functions.
  (raspi-config.txt, raspi-u-boot-bootloader.txt, raspi-kernel.txt):
  New variables.
---
 gnu/packages/raspberry-pi.scm | 44 +++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

Comments

Danny Milosavljevic Nov. 16, 2020, 9:32 a.m. UTC | #1
I'm waiting for Ludo to comment about the dots in the variable names.
(Apparently, to be forward-compatible with literal pairs, dots in variable names are not nice to use)

It would be nice to also have some clients of that stuff in that file.

I.e. actually boot the raspberry pi using some chainloader config.

Otherwise it's hard to say whether this is a good API.  When the API is actually
used it's much easier to say.
Stefan Nov. 16, 2020, 10:38 a.m. UTC | #2
Hi Danny!

> It would be nice to also have some clients of that stuff in that file.
> 
> I.e. actually boot the raspberry pi using some chainloader config.
> 
> Otherwise it's hard to say whether this is a good API.  When the API is actually
> used it's much easier to say.

There will be more patches to come, then there will be a use of these functions.

The firmware blob using these files can’t be handled by Guix, this will have to be left as an exercise. But could I add a skeleton for it? Maybe something like this (but better using the copy-build-system): 

(define (raspi-firmware url version hash)
  (package
   (build-system trivial-build-system)
   (arguments
    '(#:modules
      ((guix build utils))
      #:builder (begin
                  (use-modules (guix build utils))
                  (let* ((source (assoc-ref %build-inputs "source"))
                         (out (assoc-ref %outputs "out"))
                         (boot (string-append out "/boot"))
                         (opt (string-append out "/opt")))
                    (mkdir-p boot)
                    (copy-recursively (string-append source "/boot") boot)
                    (delete-file (string-append boot "/kernel.img"))
                    (delete-file (string-append boot "/kernel7.img"))
                    (delete-file (string-append boot "/kernel7l.img"))
                    (delete-file (string-append boot "/kernel8.img"))
                    (mkdir-p opt)
                    (copy-recursively (string-append source "/opt") opt)
                    (delete-file-recursively (string-append opt "/vc/src"))
                    #t))))
…))

Further steps will be some functionality to modify the U-Boot configuration (done with Kconfig) and to have a specific U-Boot package.

Then I’ll care for a kernel.

The board will only boot if all of this is in place.

This is how I use it all currently (left out kernel, kernel-arguments, initrd-modules):

(operating-system
  (bootloader 
    (bootloader-configuration
      (bootloader (bootloader-chain
                   (list (file-append raspi-firmware "/boot/")
                         (file-append u-boot-rpi-3 "/libexec/u-boot.bin")
                         raspi-config.txt
                         raspi-u-boot-bootloader.txt
                         ;; Additional configurations to use.
                         (raspi-custom.txt '("disable_overscan=1"
                                             "hdmi_force_hotplug=1"
                                             "audio=on"
                                             "dtoverlay=gpio-ir"
                                             "dtoverlay=disable-wifi"
                                             "dtoverlay=vc4-fkms-v3d,cma-64")))
                   grub-efi-netboot-bootloader 
                   #:installer (install-grub-efi-netboot "efi/boot")
                   #:copy-files? #t))
      (theme
        (grub-theme
          (resolution 
            '(1920 . 1080))
             (image (file-append %artwork-repository "/grub/GuixSD-fully-black-16-9.svg"))))
      (target "/boot")
      (keyboard-layout keyboard-layout)))
…)

The above bootloader-chain could certainly be added to Guix, but leaving out the raspi-firmware and the raspi-custom.txt – maybe as a function to allow adding an own raspi-custom.txt. If someone copies the firmware by hand onto an SD card, then such a bootloader provided as e.g. raspi-grub-bootloader would work.


Bye

Stefan
Danny Milosavljevic Nov. 16, 2020, 2:01 p.m. UTC | #3
Hi Stefan,

thanks!

On Mon, 16 Nov 2020 11:38:19 +0100
Stefan <stefan-guix@vodafonemail.de> wrote:

> The firmware blob using these files can’t be handled by Guix, this will have to be left as an exercise. But could I add a skeleton for it? Maybe something like this (but better using the copy-build-system): 

There is a free software Raspberry VC firmware on
https://github.com/librerpi/rpi-open-firmware/ (currently cannot handle graphics
and USB and lots of other important things--but it DOES boot) and development
is ongoing.

We can just package that free software firmware and use it.

I've already started packaging it for Guix.

> (operating-system
>   (bootloader 
>     (bootloader-configuration
>       (bootloader (bootloader-chain
>                    (list (file-append raspi-firmware "/boot/")
>                          (file-append u-boot-rpi-3 "/libexec/u-boot.bin")
>                          raspi-config.txt
>                          raspi-u-boot-bootloader.txt
>                          ;; Additional configurations to use.
>                          (raspi-custom.txt '("disable_overscan=1"
>                                              "hdmi_force_hotplug=1"
>                                              "audio=on"
>                                              "dtoverlay=gpio-ir"
>                                              "dtoverlay=disable-wifi"
>                                              "dtoverlay=vc4-fkms-v3d,cma-64")))
>                    grub-efi-netboot-bootloader 
>                    #:installer (install-grub-efi-netboot "efi/boot")
>                    #:copy-files? #t))

I advice to add a user-level function for a free software Raspberry Pi 3 efi
netboot bootloader to Guix (and a non-efi-netboot one, too, maybe).

Something like

(define (raspi-3-efi-netboot-bootloader efi-boot custom-text)
  (bootloader-chain like you do above custom-text))

I don't think that it's reasonable to expect the user to use bootloader-chain
by himself (it's not user-friendly to have to do that).

> The above bootloader-chain could certainly be added to Guix, but leaving out the raspi-firmware and the raspi-custom.txt – maybe as a function to allow adding an own raspi-custom.txt. If someone copies the firmware by hand onto an SD card, then such a bootloader provided as e.g. raspi-grub-bootloader would work.

Yeah.
diff mbox series

Patch

diff --git a/gnu/packages/raspberry-pi.scm b/gnu/packages/raspberry-pi.scm
index 7700c26d06..af3998c4d6 100644
--- a/gnu/packages/raspberry-pi.scm
+++ b/gnu/packages/raspberry-pi.scm
@@ -235,3 +235,47 @@  Raspberry Pi.  Note: It does not work on Raspberry Pi 1.")
                (install-file "arm64.bin" libexec)
                #t))))))))
     (supported-systems '("aarch64-linux"))))
+
+(define-public (raspi-config-file name content)
+  "Creates a configuration file like config.txt for the Raspberry Pi firmware.
+CONTENT can be a list of strings, which are concatenated with a newline
+character.  Alternatively CONTENT can be a string with the full file content."
+  (plain-file
+   name
+   (if (list? content)
+       (string-join content "\n" 'suffix)
+       content)))
+
+(define-public raspi-config.txt
+  ;; Creates a config.txt to start the ARM cores up in 64-bit mode if necessary
+  ;; and to include bootloader.txt, kernel.txt, and a custom.txt, each with
+  ;; separate configurations for the Raspberry Pi firmware.
+  (raspi-config-file
+   "config.txt"
+   `("# See https://www.raspberrypi.org/documentation/configuration/config-txt/README.md for details."
+     ""
+     ,(string-append "arm_64bit=" (if (target-aarch64?) "1" "0"))
+     "include bootloader.txt"
+     "include kernel.txt"
+     "include custom.txt")))
+
+(define-public raspi-u-boot-bootloader.txt
+  ;; Creates a bootloader.txt file to be included by the config.txt to load the
+  ;; U-Boot bootloader.
+  (raspi-config-file
+   "bootloader.txt"
+   "kernel=u-boot.bin"))
+
+(define-public raspi-kernel.txt
+  ;; Creates a kernel.txt to be included by the config.txt to ensure that
+  ;; upstream kernel and device tree files can be used.
+  (raspi-config-file
+   "kernel.txt"
+   '("dtoverlay=upstream"
+     "upstream_kernel=1")))
+
+(define-public (raspi-custom.txt content)
+  "Creates a custom.txt to be included by the config.txt.  CONTENT can be a list
+of strings, which are concatenated with a newline character.  Alternatively
+CONTENT can be a string with the full file content."
+  (raspi-config-file "custom.txt" content))