From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8iep-0008KU-Mg for guix-patches@gnu.org; Thu, 11 May 2017 03:37:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8iek-0004CE-KG for guix-patches@gnu.org; Thu, 11 May 2017 03:37:07 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:34872) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d8iek-0004C2-Fd for guix-patches@gnu.org; Thu, 11 May 2017 03:37:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d8iek-0003wh-6F for guix-patches@gnu.org; Thu, 11 May 2017 03:37:02 -0400 Subject: bug#26875: Non-graphical (and other types) of GRUB interfaces Resent-Message-ID: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8ieM-0008H2-6N for guix-patches@gnu.org; Thu, 11 May 2017 03:36:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8ieH-0003yf-84 for guix-patches@gnu.org; Thu, 11 May 2017 03:36:38 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:38395) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d8ieG-0003xr-Th for guix-patches@gnu.org; Thu, 11 May 2017 03:36:33 -0400 Received: from localhost (c-73-165-108-70.hsd1.pa.comcast.net [73.165.108.70]) by mail.messagingengine.com (Postfix) with ESMTPA id CE2C37E2B0 for ; Thu, 11 May 2017 03:36:31 -0400 (EDT) Date: Thu, 11 May 2017 03:36:26 -0400 From: Leo Famulari Message-ID: <20170511073626.GA4698@jasmine> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="OwLcNYc0lM97+oe1" Content-Disposition: inline List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 26875@debbugs.gnu.org --OwLcNYc0lM97+oe1 Content-Type: multipart/mixed; boundary="5vNYLRcllDrimb99" Content-Disposition: inline --5vNYLRcllDrimb99 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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? --5vNYLRcllDrimb99 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="0001-system-grub-Expose-GRUB-s-interactive-interface-sett.patch" Content-Transfer-Encoding: quoted-printable =46rom 21ed0a8f364ce3cb784c0752e28600e8e786e295 Mon Sep 17 00:00:00 2001 =46rom: Leo Famulari Date: Thu, 11 May 2017 03:12:44 -0400 Subject: [PATCH] system: grub: Expose GRUB's interactive interface settings. * gnu/system/grub.scm (): 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. =20 @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 =20 @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 =A9 2013, 2014, 2015, 2016, 2017 Ludovic Court=E8s ;;; Copyright =A9 2016 Chris Marusich +;;; Copyright =A9 2017 Leo Famulari ;;; ;;; This file is part of GNU Guix. ;;; @@ -108,17 +109,25 @@ denoting a file name." (define-record-type* 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 ; - (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 ; + (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))) =20 (define-record-type* menu-entry make-menu-entry @@ -199,11 +208,16 @@ system string---e.g., \"x86_64-linux\"." insmod vbe insmod vga fi - - terminal_output gfxterm " "")) =20 + (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 =20 -if loadfont ~a; then - setup_gfxterm -fi +~a +~a =20 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) =20 #$(strip-mount-point store-mount-point image) #$(theme-colors grub-theme-color-normal) @@ -247,6 +261,57 @@ fi~%" ;;; Configuration file. ;;; =20 +(define (grub-setup-io config) + "Return GRUB commands to configure the input / output interfaces. The r= esult +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) (<=3D unit 3) (>=3D un= it 0)) + (string-append " --unit=3D" (number->string unit)) + #f) + "") + (if speed + (if (exact-integer? speed) + (string-append " --speed=3D" (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 FIL= E, a gexp. The result is a gexp that can be inserted in the grub.cfg-generat= ion --=20 2.13.0 --5vNYLRcllDrimb99-- --OwLcNYc0lM97+oe1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEsFFZSPHn08G5gDigJkb6MLrKfwgFAlkUFHcACgkQJkb6MLrK fwiZSw/+NkF5ps8OvDTIqY8kzkFXxt24p6/nhbdR+4BtEqQFnBDA5WEQwyVfnA5s h7IPYevBh+js6PypLTIFuVxtruFiD2RMgceho4H4bbm4FFEztQV+ZtVGelHHizIj Xwc/0fykt1v3SHZ3IjMcXqC+8OoAxE77lZzds38zkinqIDN0JWAaXWIeqmiQMiXc mTBeV6wgl1bTKZLrT721V52yvqy9+l41F//NOe/u2xJq6Uplc+UQ07VMZWFxKbK0 SuAecAtWJGoDIsQs/EdhXapl6sCJ2b9o0nWWA3wptv6Zta/ASsB9NJjNn0fqIfdy M48suxfDv3Fyg0rK5INpLS+1ITC3hTD4dvmy/lH0ZkkAQ4eFYp4Wbo0KQqBKS89j TEvdKtHtwLIGDyOqAt3PX0aSI62aUKio0Piv4NiIRtuCXQRwymq45GTsDwZD9FOZ vd7wPhR+sT4roQEw/uaqejfTWSBOTvfGS8PZmuMiZp3f+ZlZ+ae6LaCif3kFfn63 yunFigN5CN1oXwo4OqtEUYVHG5cNPIu18BpiqRPvvZ+TMY5jlq85YZP0135y4tL/ cRz5fCjTEkF3r4zgOb04uUeuz7sCqjuCIXF6R3b1nmJAGepP6G3Y0c0R0senYkkk jZgh6clMVmrAnBVjf3q8iN6zIGHDT2lkw9+D+qNWef2AHM2/Ef8= =il5T -----END PGP SIGNATURE----- --OwLcNYc0lM97+oe1--