unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: ng0 <ng0@pragmatique.xyz>
To: Leo Famulari <leo@famulari.name>
Cc: 26875@debbugs.gnu.org
Subject: bug#26875: Non-graphical (and other types) of GRUB interfaces
Date: Thu, 11 May 2017 07:46:36 +0000	[thread overview]
Message-ID: <20170511074636.pupingletbo6b3a7@abyayala> (raw)
In-Reply-To: <20170511073626.GA4698@jasmine>

Leo Famulari transcribed 9.9K bytes:
> This patch exposes the GRUB configuration options that control where and
> how the user interface is presented. Generally, you can use it to put
> the GRUB menu on a serial port, get a text-only menu on the kernel
> console, or even use Morse code on the PC speaker (untested!).
> 
> You can use it like this, for example:
> 
> (bootloader (grub-configuration
>             (device "/dev/sda")
>             (terminal-outputs '(gfxterm console))
>             (terminal-inputs '(serial console usb_keyboard))
>             (serial-speed 115200)
>             (serial-unit 0)))
> 
> Since this offers new ways to break your system, the patch sets up some
> input validation. Hopefully it's enough.
> 
> The general idea came from this conversation:
> 
> https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00053.html
> 
> Your feedback?

Without testing it, this looks like it could fix the use of GuixSD
on IN-Berlin e.V. servers. At least the options are given, like
talked about in a level above this subthread.

> From 21ed0a8f364ce3cb784c0752e28600e8e786e295 Mon Sep 17 00:00:00 2001
> From: Leo Famulari <leo@famulari.name>
> Date: Thu, 11 May 2017 03:12:44 -0400
> Subject: [PATCH] system: grub: Expose GRUB's interactive interface settings.
> 
> * gnu/system/grub.scm (<grub-configuration>): Add new fields
> terminal-outputs, terminal-inputs, serial-unit, and serial-speed.
> (grub-setup-io, setup-gfxterm): New procedures.
> * doc/guix.texi (GRUB Configuration): Document the new fields.
> ---
>  doc/guix.texi       | 20 +++++++++++
>  gnu/system/grub.scm | 99 ++++++++++++++++++++++++++++++++++++++++++++---------
>  2 files changed, 102 insertions(+), 17 deletions(-)
> 
> diff --git a/doc/guix.texi b/doc/guix.texi
> index 81aa957c6..a1f7fdee6 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -15223,6 +15223,26 @@ The @code{grub-theme} object describing the theme to use.
>  
>  @item @code{grub} (default: @code{grub})
>  The GRUB package to use.
> +
> +@item @code{terminal-outputs} (default: @code{'gfxterm})
> +The output terminals used for the GRUB boot menu, as a list of symbols.
> +These values are accepted: console, serial, serial_{0-3}, gfxterm,
> +vga_text, mda_text, morse, spkmodem
> +
> +@item @code{terminal-inputs} (default: @code{'()})
> +The input terminals used for the GRUB boot menu, as a list of symbols.
> +The default is the native platform terminal as determined by GRUB at
> +run-time.  These values are accepted: console, serial, serial_{0-3},
> +at_keyboard, usb_keyboard.
> +
> +@item @code{serial-unit} (default: @code{#f})
> +The serial unit used by GRUB, as an integer from 0 to 3.  The default
> +value is chosen by GRUB at run-time; currently GRUB chooses 0, which
> +corresponds to COM1.
> +
> +@item @code{serial-speed} (default: @code{#f})
> +The speed of the serial interface, as an integer.  The default value is
> +chosen by GRUB at run-time; currently GRUB chooses 9600bps.
>  @end table
>  
>  @end deftp
> diff --git a/gnu/system/grub.scm b/gnu/system/grub.scm
> index 58096429f..b5b8c8c8a 100644
> --- a/gnu/system/grub.scm
> +++ b/gnu/system/grub.scm
> @@ -1,6 +1,7 @@
>  ;;; GNU Guix --- Functional package management for GNU
>  ;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
>  ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
> +;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -108,17 +109,25 @@ denoting a file name."
>  (define-record-type* <grub-configuration>
>    grub-configuration make-grub-configuration
>    grub-configuration?
> -  (grub            grub-configuration-grub           ; package
> -                   (default (@ (gnu packages bootloaders) grub)))
> -  (device          grub-configuration-device)        ; string
> -  (menu-entries    grub-configuration-menu-entries   ; list
> -                   (default '()))
> -  (default-entry   grub-configuration-default-entry  ; integer
> -                   (default 0))
> -  (timeout         grub-configuration-timeout        ; integer
> -                   (default 5))
> -  (theme           grub-configuration-theme          ; <grub-theme>
> -                   (default %default-theme)))
> +  (grub             grub-configuration-grub             ; package
> +                    (default (@ (gnu packages bootloaders) grub)))
> +  (device           grub-configuration-device)          ; string
> +  (menu-entries     grub-configuration-menu-entries     ; list
> +                    (default '()))
> +  (default-entry    grub-configuration-default-entry    ; integer
> +                    (default 0))
> +  (timeout          grub-configuration-timeout          ; integer
> +                    (default 5))
> +  (theme            grub-configuration-theme            ; <grub-theme>
> +                    (default %default-theme))
> +  (terminal-outputs grub-configuration-terminal-outputs ; list of symbols
> +                    (default '(gfxterm)))
> +  (terminal-inputs  grub-configuration-terminal-inputs  ; list of symbols
> +                    (default '()))
> +  (serial-unit      grub-configuration-serial-unit      ; integer | #f
> +                    (default #f))
> +  (serial-speed     grub-configuration-serial-speed     ; integer | #f
> +                    (default #f)))
>  
>  (define-record-type* <menu-entry>
>    menu-entry make-menu-entry
> @@ -199,11 +208,16 @@ system string---e.g., \"x86_64-linux\"."
>      insmod vbe
>      insmod vga
>    fi
> -
> -  terminal_output gfxterm
>  "
>          ""))
>  
> +  (define (setup-gfxterm config font-file)
> +    (if (memq 'gfxterm (grub-configuration-terminal-outputs config))
> +      #~(format #f "if loadfont ~a; then
> +  setup_gfxterm
> +fi~%" #$font-file)
> +      ""))
> +
>    (define (theme-colors type)
>      (let* ((theme  (grub-configuration-theme config))
>             (colors (type theme)))
> @@ -222,9 +236,8 @@ function setup_gfxterm {~a}
>  # Set 'root' to the partition that contains /gnu/store.
>  ~a
>  
> -if loadfont ~a; then
> -  setup_gfxterm
> -fi
> +~a
> +~a
>  
>  insmod png
>  if background_image ~a; then
> @@ -236,7 +249,8 @@ else
>  fi~%"
>                             #$setup-gfxterm-body
>                             #$(grub-root-search store-device font-file)
> -                           #$font-file
> +                           #$(grub-setup-io config)
> +                           #$(setup-gfxterm config font-file)
>  
>                             #$(strip-mount-point store-mount-point image)
>                             #$(theme-colors grub-theme-color-normal)
> @@ -247,6 +261,57 @@ fi~%"
>  ;;; Configuration file.
>  ;;;
>  
> +(define (grub-setup-io config)
> +  "Return GRUB commands to configure the input / output interfaces.  The result
> +is a string that can be inserted in grub.cfg."
> +  (let* ((symbols->string (lambda (list)
> +                           (string-join (map symbol->string list) " ")))
> +         (outputs (grub-configuration-terminal-outputs config))
> +         (inputs (grub-configuration-terminal-inputs config))
> +         (unit (grub-configuration-serial-unit config))
> +         (speed (grub-configuration-serial-speed config))
> +
> +         ;; Respectively, GRUB_TERMINAL_OUTPUT and GRUB_TERMINAL_INPUT,
> +         ;; as documented in GRUB manual section "Simple Configuration
> +         ;; Handling".
> +         (valid-outputs '(console serial serial_0 serial_1 serial_2 serial_3
> +                          gfxterm vga_text mda_text morse spkmodem))
> +         (valid-inputs '(console serial serial_0 serial_1 serial_2 serial_3
> +                         at_keyboard usb_keyboard))
> +
> +         (io (string-append
> +               "terminal_output "
> +               (symbols->string
> +                 (map
> +                   (lambda (output)
> +                     (if (memq output valid-outputs) output #f)) outputs)) "\n"
> +               (if (null? inputs)
> +                 ""
> +                 (string-append
> +                   "terminal_input "
> +                   (symbols->string
> +                     (map
> +                       (lambda (input)
> +                         (if (memq input valid-inputs) input #f)) inputs)) "\n"))
> +               ;; UNIT and SPEED are arguments to the same GRUB command
> +               ;; ("serial"), so we process them together.
> +               (if (or unit speed)
> +                 (string-append
> +                   "serial"
> +                   (if unit
> +                     ;; COM ports 0 through 3
> +                     (if (and (exact-integer? unit) (<= unit 3) (>= unit 0))
> +                       (string-append " --unit=" (number->string unit))
> +                       #f)
> +                     "")
> +                   (if speed
> +                     (if (exact-integer? speed)
> +                       (string-append " --speed=" (number->string speed))
> +                       #f)
> +                     ""))
> +                 ""))))
> +    (format #f "~a" io)))
> +
>  (define (grub-root-search device file)
>    "Return the GRUB 'search' command to look for DEVICE, which contains FILE,
>  a gexp.  The result is a gexp that can be inserted in the grub.cfg-generation
> -- 
> 2.13.0
> 




-- 
https://pragmatique.xyz
PGP: https://people.pragmatique.xyz/ng0/

  reply	other threads:[~2017-05-11  7:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-11  7:36 bug#26875: Non-graphical (and other types) of GRUB interfaces Leo Famulari
2017-05-11  7:46 ` ng0 [this message]
2017-05-13  5:15   ` Leo Famulari
2017-05-13  5:21 ` bug#26875: [v2] system: grub: Expose GRUB's interactive interface settings Leo Famulari
2017-05-13 13:51   ` Ludovic Courtès
2017-05-13 16:40     ` Leo Famulari
2017-05-14  7:38     ` Mathieu Othacehe
2017-05-14 18:17       ` Leo Famulari
2017-05-15  9:36 ` bug#26875: Non-graphical (and other types) of GRUB interfaces Brendan Tildesley
2017-05-15 18:04   ` Leo Famulari
2017-05-15 20:25   ` Leo Famulari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170511074636.pupingletbo6b3a7@abyayala \
    --to=ng0@pragmatique.xyz \
    --cc=26875@debbugs.gnu.org \
    --cc=leo@famulari.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).