From mboxrd@z Thu Jan 1 00:00:00 1970 From: Danny Milosavljevic Subject: gnu/system/u-boot.scm Date: Thu, 21 Jul 2016 22:35:01 +0200 Message-ID: <20160721223501.3a989d55@scratchpost.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQKgc-0003Ty-7T for guix-devel@gnu.org; Thu, 21 Jul 2016 16:35:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQKgX-000526-2k for guix-devel@gnu.org; Thu, 21 Jul 2016 16:35:13 -0400 Received: from dd1012.kasserver.com ([85.13.128.8]:51473) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQKgW-00050U-Oj for guix-devel@gnu.org; Thu, 21 Jul 2016 16:35:09 -0400 Received: from localhost (77.118.127.45.wireless.dyn.drei.com [77.118.127.45]) by dd1012.kasserver.com (Postfix) with ESMTPSA id 1598B1CA0223 for ; Thu, 21 Jul 2016 22:35:06 +0200 (CEST) List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel Hi, below is my (untested!) attempt at an u-boot-configuration for use like this (bootloader (u-boot-configuration (device "/dev/sda"))) . It has been copied from gnu/system/grub.cfg and then I s/grub/u-boot/g and = removed all the eyecandy stuff as far as I could. We should end up with U-B= oot showing a boot menu if=20 (1) The file "extlinux.conf" ends up on the first partition in the root if = no partition was marked Active or (2) The file "extlinux.conf" ends up on the partition which was marked Acti= ve using the flag in the MBR/GPT. and if someone installed u-boot-sunxi-with-spl.bin at a special sector usin= g dd or something. NB: I think "device" would better be called "drive" or something. Everythin= g is a device at this point. More important is that it isn't a partition or= a scanner or something :) Now how do I make u-boot-configuration available in my /etc/config.scm ? :) NB: I also researched how to chainload grub and there's https://wiki.linaro= .org/LEG/Engineering/Kernel/GRUBonUBOOT that describes it. Do we want that? NB: menu-entry is unchanged. Might make sense to generalize it and move it = to a common location. ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2013, 2014, 2015, 2016 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2016 Danny Milosavljevic ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu system u-boot) #:use-module (guix store) #:use-module (guix packages) #:use-module (guix derivations) #:use-module (guix records) #:use-module (guix monads) #:use-module (guix gexp) #:use-module (guix download) #:use-module (gnu artwork) #:use-module (gnu system file-systems) #:autoload (gnu packages u-boot) (make-u-boot-package) #:autoload (gnu packages compression) (gzip) #:use-module (ice-9 match) #:use-module (ice-9 regex) #:use-module (srfi srfi-1) #:export (u-boot-configuration u-boot-configuration? u-boot-configuration-device menu-entry menu-entry? u-boot-configuration-file)) ;;; Commentary: ;;; ;;; Configuration of U-Boot. ;;; ;;; Code: (define-record-type* u-boot-configuration make-u-boot-configuration u-boot-configuration? (board u-boot-configuration-board) ; string ; not opt= ional! (u-boot u-boot-configuration-u-boot ; package (default (@ (gnu packages u-boot) (make-u-boot-package b= oard)))) (device u-boot-configuration-device) ; string (menu-entries u-boot-configuration-menu-entries ; list (default '())) (default-entry u-boot-configuration-default-entry ; integer (default 0)) (timeout u-boot-configuration-timeout ; integer (default 5))) (define-record-type* menu-entry make-menu-entry menu-entry? (label menu-entry-label) (linux menu-entry-linux) (linux-arguments menu-entry-linux-arguments (default '())) ; list of string-valued gexps (initrd menu-entry-initrd)) ; file name of the initrd as a g= exp (define (eye-candy config root-fs system port) "dummy" (mlet* %store-monad ((image #f)) (return (and image #~(format #$port ""))))) ;;; ;;; Configuration file. ;;; (define* (u-boot-configuration-file config store-fs entries #:key (system (%current-system)) (old-entries '())) "Return the U-Boot configuration file corresponding to CONFIG, a object, and where the store is available at STORE-FS= , a object. OLD-ENTRIES is taken to be a list of menu entries corresponding to old generations of the system." (define linux-image-name (if (string-prefix? "mips" system) "vmlinuz" "bzImage")) (define all-entries (append entries (u-boot-configuration-menu-entries config))) (define entry->gexp (match-lambda (($ label linux arguments initrd) #~(format port "LABEL ~s MENU LABEL ~a LINUX ~a/~a ~a INITRD ~a FDTDIR . APPEND ~a ~%" #$label #$linux #$linux-image-name #$initrd (string-join (list #$@arguments)))))) (mlet %store-monad ((sugar (eye-candy config store-fs system #~port))) (define builder #~(call-with-output-file #$output (lambda (port) #$sugar (format port " ui menu.c32 DEFAULT ~a TIMEOUT ~a~%" #$(u-boot-configuration-default-entry config) #$(u-boot-configuration-timeout config)) #$@(map entry->gexp all-entries) #$@(if (pair? old-entries) #~((format port "~%") #$@(map entry->gexp old-entries) (format port "~%")) #~())))) (gexp->derivation "extlinux.conf" builder))) ;;; u-boot.scm ends here