Subject: [bug#31416] [PATCH 2/4] bootloader: install-u-boot: Automatically select the correct installer.

From: [email-masked] (Ludovic Courtès)
Date: Sun, 13 May 2018 11:31:23 +0200

Danny Milosavljevic <[email-masked]> skribis:

> * gnu/bootloader/u-boot.scm (install-u-boot): Automatically select the correct
> installer.
> ---
>  gnu/bootloader/u-boot.scm | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm
> index bc8f98f32..e0941c961 100644
> --- a/gnu/bootloader/u-boot.scm
> +++ b/gnu/bootloader/u-boot.scm
> @@ -41,7 +41,24 @@
>  (define install-u-boot
>    #~(lambda (bootloader device mount-point)
>        (if bootloader
> -        (error "Failed to install U-Boot"))))
> +        (let* ((config-file-name (string-append bootloader "/libexec/.config"))
> +               (soc (call-with-input-file config-file-name
> +                                          (let loop ((line (read-line port)))
> +                                            (if (not (eof-object? line))
> +                                                (let ((match
> +                                                       (string-match
> +                                                        "^CONFIG_SYS_SOC=\"([^\"]*)\""
> +                                                        line)))
> +                                                  (if match
> +                                                      (match:substring match 1)
> +                                                      (loop (read-line port))))
> +                                                #f)))))
> +          (match soc
> +           ("am33xx" (install-beaglebone-black-u-boot bootloader device mount-point))
> +           ("mx6" (install-imx-u-boot bootloader device mount-point))
> +           ("sunxi" (install-allwinner-u-boot bootloader device mount-point))
> +           (_ (error "Failed to install U-Boot (no installation method found)"
> +                     soc)))))))

Hmm ‘install-beaglebone-black-u-boot’ & co are not in the same stage
AFAICS; are you missing #$ escapes here?

Also we’re probably missing (ice-9 rdelim) and (ice-9 regex) as in the
build stage.

Last, isn’t it a bit hacky?  :-)  Previously every <bootloader> would
contain its installation method, so this was unambiguous, but now we’re
back to guessing what installation method to use.

Ludo’.