diff mbox series

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

Message ID C744BEF8-07E0-4BD8-A0F6-D5C5B093F28D@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/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Stefan Nov. 29, 2020, 7:04 p.m. UTC
* gnu/packages/raspberry-pi.scm (raspi-config-file, raspi-custom-txt):
  New functions.
  (raspi-config-txt, raspi-bcm27-dtb-txt, raspi-bcm28-dtb-txt
  raspi-u-boot-bootloader-txt): New variables.
---
 gnu/packages/raspberry-pi.scm | 62 +++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

Comments

Stefan Dec. 13, 2020, 1:06 p.m. UTC | #1
Hi Danny!

A friendly ping. :-)


Bye

Stefan
Stefan Dec. 28, 2020, 7:24 p.m. UTC | #2
Hi!

A friendly ping! :-)


Bye

Stefan
Stefan March 27, 2021, 4:40 p.m. UTC | #3
Hi!

Another friendly ping! This patch is meanwhile really getting old, but it is still not forgotten. :-)

<http://issues.guix.gnu.org/44543>


Bye

Stefan
Léo Le Bouter March 27, 2021, 4:47 p.m. UTC | #4
On Sat, 2021-03-27 at 17:40 +0100, Stefan wrote:
> Hi!
> 
> Another friendly ping! This patch is meanwhile really getting old,
> but it is still not forgotten. :-)
> 
> <http://issues.guix.gnu.org/44543>
> 
> 
> Bye
> 
> Stefan

I have a Raspberry Pi 3B+ here at home, how can I test these changes?

I don't feel capable to review this without testing something as a
whole verifying that it works then inspecting these things that make it
work.

Thank you
Stefan March 27, 2021, 7:43 p.m. UTC | #5
Hi Léo!

> I have a Raspberry Pi 3B+ here at home, how can I test these changes?
> 
> I don't feel capable to review this without testing something as a
> whole verifying that it works then inspecting these things that make it
> work.

The support for the Raspberry is still not complete. I’m using mine without an SD card, booting it over TFTP with an NFS root mount.

Installing on an SD card is not tested and certainly not working yet.

One of my next patches will be several u-boot packages for different Raspberry models. To build them I need to do changes to the defconfig file of u-boot. Therefore another ticket is pending, which eases defconfig modifications (<http://issues.guix.gnu.org/45046>, and I hope this can also be used to modify Linux). When that one is done, then I will send that next patch to add the u-boot packages. 

My bootloader currently looks like this, but I’m using already further modifications, mainly for GRUB, so this will not work for you, but you can get an impression of the final intended use of all patches:

  (bootloader
    (bootloader-configuration
      (target "/boot")
      (bootloader (efi-bootloader-chain
                   grub-efi-netboot-removable-bootloader
                   ;; Packages needed to boot the Raspberry.
                   #:packages (list raspberrypi-firmware 
                                    u-boot-rpi-efi-64)
                   ;; Additional files for configuration.
                   #:files (list ;; Detects 32 or 64 bit, includes other txt files.
                                 raspi-config-txt
                                 ;; Use the downstream device tree (upstream is bcm28).
                                 raspi-bcm27-dtb-txt
                                 ;; This is the next boot stage.
                                 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")))))))

Your bootloader configuration would need to look like this, and you may get it running from an SD card:

  (bootloader
    (bootloader-configuration
      (target "/boot")
      (bootloader
        (efi-bootloader-chain
          (list (file-append firmware "/boot/")
                (file-append u-boot-my-scb "/libexec/u-boot.bin")
                raspi-config-txt
                raspi-bcm27-dtb-txt
                raspi-u-boot-bootloader-txt)
          grub-efi-netboot-bootloader
          #:installer
           (chain-efi-bootloader-installer (install-grub-efi-netboot "efi/boot")))))

So you need to provide firmware and u-boot (still) yourself. As a short cut you may omit both (file-append …) functions and copy both parts by hand from some other distribution, maybe openSUSE – this is basically how I got started.

If you mount an ext4-partition of an SD card to e.g. /my-target/ and the FAT partition to /my-target/boot, then you may try a ‘guix system init … /my-target’.

If this succeeds, then it may be possible that adding the file /my-target/boot/efi/boot/grub.cfg with this content gets you to a system booting from an SD card:

search --file /boot/grub/grub.cfg
configfile /boot/grub/grub.cfg

But this is all untested, it certainly fails. :-)

At least – regarding this patch – I can ensure that the three config files as used in these bootloader examples are properly generated working.
 

Bye

Stefan
Léo Le Bouter March 27, 2021, 7:51 p.m. UTC | #6
On Sat, 2021-03-27 at 20:43 +0100, Stefan wrote:
> Hi Léo!
> 
> > I have a Raspberry Pi 3B+ here at home, how can I test these
> > changes?
> > 
> > I don't feel capable to review this without testing something as a
> > whole verifying that it works then inspecting these things that
> > make it
> > work.
> 
> The support for the Raspberry is still not complete. I’m using mine
> without an SD card, booting it over TFTP with an NFS root mount.
> 
> Installing on an SD card is not tested and certainly not working yet.
> 
> One of my next patches will be several u-boot packages for different
> Raspberry models. To build them I need to do changes to the defconfig
> file of u-boot. Therefore another ticket is pending, which eases
> defconfig modifications (<http://issues.guix.gnu.org/45046>;, and I
> hope this can also be used to modify Linux). When that one is done,
> then I will send that next patch to add the u-boot packages. 
> 
> My bootloader currently looks like this, but I’m using already
> further modifications, mainly for GRUB, so this will not work for
> you, but you can get an impression of the final intended use of all
> patches:
> 
>   (bootloader
>     (bootloader-configuration
>       (target "/boot")
>       (bootloader (efi-bootloader-chain
>                    grub-efi-netboot-removable-bootloader
>                    ;; Packages needed to boot the Raspberry.
>                    #:packages (list raspberrypi-firmware 
>                                     u-boot-rpi-efi-64)
>                    ;; Additional files for configuration.
>                    #:files (list ;; Detects 32 or 64 bit, includes
> other txt files.
>                                  raspi-config-txt
>                                  ;; Use the downstream device tree
> (upstream is bcm28).
>                                  raspi-bcm27-dtb-txt
>                                  ;; This is the next boot stage.
>                                  raspi-u-boot-bootloader-txt 
>                                  ;; Additional configurations to use.
>                                  (raspi-custom-txt
> '("disable_overscan=1"
>                                                      "hdmi_force_hotp
> lug=1"
>                                                      "audio=on"
>                                                      "dtoverlay=gpio-
> ir"
>                                                      "dtoverlay=disab
> le-wifi"
>                                                      "dtoverlay=vc4-
> fkms-v3d,cma-64")))))))
> 
> Your bootloader configuration would need to look like this, and you
> may get it running from an SD card:
> 
>   (bootloader
>     (bootloader-configuration
>       (target "/boot")
>       (bootloader
>         (efi-bootloader-chain
>           (list (file-append firmware "/boot/")
>                 (file-append u-boot-my-scb "/libexec/u-boot.bin")
>                 raspi-config-txt
>                 raspi-bcm27-dtb-txt
>                 raspi-u-boot-bootloader-txt)
>           grub-efi-netboot-bootloader
>           #:installer
>            (chain-efi-bootloader-installer (install-grub-efi-netboot
> "efi/boot")))))
> 
> So you need to provide firmware and u-boot (still) yourself. As a
> short cut you may omit both (file-append …) functions and copy both
> parts by hand from some other distribution, maybe openSUSE – this is
> basically how I got started.
> 
> If you mount an ext4-partition of an SD card to e.g. /my-target/ and
> the FAT partition to /my-target/boot, then you may try a ‘guix system
> init … /my-target’.
> 
> If this succeeds, then it may be possible that adding the file /my-
> target/boot/efi/boot/grub.cfg with this content gets you to a system
> booting from an SD card:
> 
> search --file /boot/grub/grub.cfg
> configfile /boot/grub/grub.cfg
> 
> But this is all untested, it certainly fails. :-)
> 
> At least – regarding this patch – I can ensure that the three config
> files as used in these bootloader examples are properly generated
> working.
>  
> 
> Bye
> 
> Stefan

Thanks for all your work!

I would prefer if you opened one single bug with all the changes so I
can test the whole thing, right now I don't feel at ease reviewing
things like this. How can I be sure what you are submitting is the
right abstraction for your future work? Are you sure that abstraction
will be right for your future patches? If anything needs to be changed
I feel like one big patchset about Raspberry Pi 3B+ support will be
easier to review (at least for me).

Léo
diff mbox series

Patch

diff --git a/gnu/packages/raspberry-pi.scm b/gnu/packages/raspberry-pi.scm
index cdea392fc7..b189ec2f4e 100644
--- a/gnu/packages/raspberry-pi.scm
+++ b/gnu/packages/raspberry-pi.scm
@@ -235,3 +235,65 @@  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)
+  "Create 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-file name content)
+  "Create 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
+  ;; Create a config.txt to start the ARM cores up in 64-bit mode if necessary
+  ;; and to include a dtb.txt, bootloader.txt, and a custom.txt, each with
+  ;; separated 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 dtb.txt"
+     "include bootloader.txt"
+     "include custom.txt")))
+
+(define-public raspi-bcm27-dtb-txt
+  ;; Create a dtb.txt to be included by the config.txt to ensure that the
+  ;; downstream device tree files bcm27*.dtb will be used.
+  (raspi-config-file
+   "dtb.txt"
+   "upstream_kernel=0"))
+
+(define-public raspi-bcm28-dtb-txt
+  ;; Create a dtb.txt to be included by the config.txt to ensure that the
+  ;; upstream device tree files bcm28*.dtb will be used.
+  ;; This also implies the use of the dtoverlay=upstream.
+  (raspi-config-file
+   "dtb.txt"
+   "upstream_kernel=1"))
+
+(define-public raspi-u-boot-bootloader-txt
+  ;; Create a bootloader.txt file to be included by the config.txt to load the
+  ;; U-Boot bootloader.
+  (raspi-config-file
+   "bootloader.txt"
+   '("dtoverlay=upstream"
+     "kernel=u-boot.bin")))
+
+(define-public (raspi-custom-txt content)
+  "Create a custom.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."
+  (raspi-config-file "custom.txt" content))