>From 29b903186c1c7bbcdbc8be549ad0c544985aac2c Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Mon, 4 Mar 2019 09:52:49 -0500 Subject: [PATCH] wip! Add support for ASUS C201. --- gnu/bootloader/depthcharge.scm | 107 ++++++++++++++++++++++++++++ gnu/local.mk | 1 + gnu/packages/bootloaders.scm | 10 +-- gnu/packages/linux.scm | 108 ++++++++++++++++++++++++++++- gnu/system/examples/asus-c201.tmpl | 60 ++++++++++++++++ 5 files changed, 276 insertions(+), 10 deletions(-) create mode 100644 gnu/bootloader/depthcharge.scm create mode 100644 gnu/system/examples/asus-c201.tmpl diff --git a/gnu/bootloader/depthcharge.scm b/gnu/bootloader/depthcharge.scm new file mode 100644 index 0000000000..58cc3f3932 --- /dev/null +++ b/gnu/bootloader/depthcharge.scm @@ -0,0 +1,107 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Timothy Sample +;;; +;;; 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 bootloader depthcharge) + #:use-module (gnu bootloader extlinux) + #:use-module (gnu bootloader) + #:use-module (gnu packages bootloaders) + #:use-module (guix gexp) + #:use-module (guix utils) + #:use-module (ice-9 match) + #:export (depthcharge-bootloader)) + +(define (signed-kernel kernel kernel-arguments initrd) + (define builder + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils) + (ice-9 binary-ports) + (rnrs bytevectors)) + (set-path-environment-variable "PATH" '("bin") (list #$dtc)) + + ;; TODO: These files have to be writable, so we copy them. + ;; This can probably be fixed by using a ".its" file, just + ;; be careful not to break initrd loading. + (copy-file #$kernel "zImage") + (chmod "zImage" #o755) + (copy-file (string-append (dirname #$kernel) "/lib/dtbs/" + "rk3288-veyron-speedy.dtb") + "rk3288-veyron-speedy.dtb") + (chmod "rk3288-veyron-speedy.dtb" #o644) + (copy-file #$initrd "initrd") + (chmod "initrd" #o644) + + (invoke (string-append #$u-boot-tools "/bin/mkimage") + "-D" "-I dts -O dtb -p 2048" + "-f" "auto" + "-A" "arm" + "-O" "linux" + "-T" "kernel" + "-C" "None" + "-d" "zImage" + "-a" "0" + "-b" "rk3288-veyron-speedy.dtb" + "-i" "initrd" + "image.itb") + (call-with-output-file "bootloader.bin" + (lambda (port) + (put-bytevector port (make-bytevector 512 0)))) + (with-output-to-file "kernel-arguments" + (lambda () + (display (string-join (list address@hidden))))) + (invoke (string-append #$vboot-utils "/bin/vbutil_kernel") + "--pack" #$output + "--version" "1" + "--vmlinuz" "image.itb" + "--arch" "arm" + "--keyblock" (string-append #$vboot-utils + "/share/vboot-utils/devkeys/" + "kernel.keyblock") + "--signprivate" (string-append #$vboot-utils + "/share/vboot-utils/devkeys/" + "kernel_data_key.vbprivk") + "--config" "kernel-arguments" + "--bootloader" "bootloader.bin")))) + (computed-file "vmlinux.kpart" builder)) + +(define* (depthcharge-configuration-file config entries + #:key + (system (%current-system)) + (old-entries '())) + (match entries + ((entry) + (let ((kernel (menu-entry-linux entry)) + (kernel-arguments (menu-entry-linux-arguments entry)) + (initrd (menu-entry-initrd entry))) + ;; XXX: Make this a symlink. + (signed-kernel kernel kernel-arguments initrd))) + (_ (error "Too many bootloader menu entries!")))) + +(define install-depthcharge + #~(lambda (bootloader device mount-point) + (let ((kpart (string-append mount-point + "/boot/depthcharge/vmlinux.kpart"))) + (write-file-on-device kpart (stat:size (stat kpart)) device 0)))) + +(define depthcharge-bootloader + (bootloader + (name 'depthcharge) + (package #f) + (installer install-depthcharge) + (configuration-file "/boot/depthcharge/vmlinux.kpart") + (configuration-file-generator depthcharge-configuration-file))) diff --git a/gnu/local.mk b/gnu/local.mk index 974195b4bb..b387d9318d 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -46,6 +46,7 @@ GNU_SYSTEM_MODULES = \ %D%/bootloader/grub.scm \ %D%/bootloader/extlinux.scm \ %D%/bootloader/u-boot.scm \ + %D%/bootloader/depthcharge.scm \ %D%/ci.scm \ %D%/packages.scm \ %D%/packages/abduco.scm \ diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm index b0617f452a..a1bad19551 100644 --- a/gnu/packages/bootloaders.scm +++ b/gnu/packages/bootloaders.scm @@ -474,15 +474,7 @@ def test_ctrl_c")) "tools/env/fw_printenv" "tools/sunxi-spl-image-builder")) #t))) - (delete 'check) - (add-after 'install 'check - (lambda* (#:key make-flags test-target #:allow-other-keys) - (apply invoke "make" "mrproper" make-flags) - (setenv "SDL_VIDEODRIVER" "dummy") - (setenv "PAGER" "cat") - (apply invoke "make" test-target make-flags) - (symlink "build-sandbox_spl" "sandbox") - (invoke "test/image/test-imagetools.sh")))))) + (delete 'check)))) (description "U-Boot is a bootloader used mostly for ARM boards. It also initializes the boards (RAM etc). This package provides its board-independent tools."))) diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm index 1976e24cba..2d8db1dbce 100644 --- a/gnu/packages/linux.scm +++ b/gnu/packages/linux.scm @@ -32,6 +32,7 @@ ;;; Copyright © 2018 Manuel Graf ;;; Copyright © 2018 Pierre Langlois ;;; Copyright © 2018 Vasile Dumitrascu +;;; Copyright © 2019 Timothy Sample ;;; ;;; This file is part of GNU Guix. ;;; @@ -117,6 +118,7 @@ #:use-module (guix build-system python) #:use-module (guix build-system trivial) #:use-module (guix download) + #:use-module (guix gexp) #:use-module (guix git-download) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix packages) @@ -324,7 +326,7 @@ for ARCH and optionally VARIANT, or #f if there is no such configuration." #:variant (version-major+minor version))) (#f ;no config for this platform '()) - ((? string? config) + ((or (? string? config) (? struct? config)) `(("kconfig" ,config)))))) (arguments `(#:modules ((guix build gnu-build-system) @@ -509,6 +511,110 @@ It has been modified to remove all non-free binary blobs.") #:extra-version "arm-omap2plus")) +;;; +;;; PrawnOS +;;; + +(define prawn-os + (package + (name "prawn-os") + (version "0.07-alpha") + (source (origin + (method url-fetch) + (uri (string-append "https://github.com/SolidHal/" + "PrawnOS/archive/v" version ".tar.gz")) + (file-name (string-append "prawn-os-" version ".tar.gz")) + (sha256 + (base32 + "17gcmabykb3ykj1k2w3c4zydvhx8mgvvg2b4fb8ck67l8vp2ifnh")))) + (build-system trivial-build-system) + (arguments + `(#:modules ((guix build utils)) + #:builder + (begin + (use-modules (guix build utils)) + (set-path-environment-variable + "PATH" '("bin") (list (assoc-ref %build-inputs "gzip") + (assoc-ref %build-inputs "tar"))) + (mkdir %output) + (invoke "tar" "xvf" (assoc-ref %build-inputs "source") + "-C" %output "--strip-components=1") + #t))) + (native-inputs + `(("gzip" ,gzip) + ("tar" ,tar))) + (home-page "https://github.com/SolidHal/PrawnOS") + (synopsis "Libre Debian adapted for Asus C201 Chromebooks") + (description "This package provides the source code for the +PrawnOS build scripts. PrawnOS is a freedom-respecting Debian +derivative adapted for Asus C201 Chromebooks.") + (license license:gpl2))) + +(define* (prawn-os-config arch #:key variant) + (computed-file + "prawn-os-config" + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (copy-file (string-append #$prawn-os + "/resources/BuildResources/config") + #$output) + (substitute* #$output + ;; With this set, building fails because we do + ;; not have software float stubs in glibc. + (("CONFIG_KERNEL_MODE_NEON=y") + "# CONFIG_KERNEL_MODE_NEON is not set") + ;; We need to support the precious "boot to + ;; Guile" feature! + (("# CONFIG_BLK_DEV_INITRD is not set") + ((lambda (x) (string-join x "\n")) + '("CONFIG_BLK_DEV_INITRD=y" + "CONFIG_RD_GZIP=y" + "CONFIG_RD_BZIP2=y" + "CONFIG_RD_LZMA=y" + "CONFIG_RD_XZ=y" + "CONFIG_RD_LZO=y" + "CONFIG_RD_LZ4=y"))) + (("# CONFIG_BLK_DEV_RAM is not set") + ((lambda (x) (string-join x "\n")) + '("CONFIG_BLK_DEV_RAM=m" + "CONFIG_BLK_DEV_RAM_COUNT=16")))) + ;; Append Guix's extra configuration options. + (let ((port (open-file ".config" "a"))) + (display #$(config->string %default-extra-linux-options) port) + (close-port port)))))) + +(define (prawn-os-patch path) + (match (string-split path #\/) + ((type name) + (computed-file + name + #~(copy-file (string-append #$prawn-os "/resources/BuildResources/" + "patches-tested/" #$path) + #$output))))) + +(define prawn-os-patches + (map prawn-os-patch + '("kernel/rockchip-dwc2-usb-partial-power-down.patch" + "kernel/0002-Do-not-force-GUID-partition-with-gpt-command-line-op.patch" + "kernel/Added-a-second-reset-when-having-an-issue-reading-th.patch" + "kernel/reverse-do-not-use-bulk-on-EP3-and-EP4.patch" + "kernel/Don-t-try-to-flush-cache-on-reset.patch" + "kernel/0001-block-partitions-efi-Add-support-for-IGNOREME-GPT-si.patch" + "DTS/0025-ARM-DTSI-rk3288-Add-the-appropriate-clock-references.patch" + "DTS/0007-RK3288-DTSI-rk3288-Add-missing-SPI2-pinctrl.patch" + "DTS/0006-ARM-DTSI-rk3288-Missing-GRF-handles.patch"))) + +(define-public linux-libre-prawn-os + (let ((version "4.17.19") + (hash "0fa9n7p03y46k73gjiq1w6mfdlgshyqsf49dxgsidmc8r9b0x7c9") + (supported-systems '("armhf-linux"))) + (make-linux-libre version hash supported-systems + #:configuration-file prawn-os-config + #:patches prawn-os-patches + #:extra-version "prawn-os"))) + + ;;; ;;; Pluggable authentication modules (PAM). ;;; diff --git a/gnu/system/examples/asus-c201.tmpl b/gnu/system/examples/asus-c201.tmpl new file mode 100644 index 0000000000..dabdfd36ce --- /dev/null +++ b/gnu/system/examples/asus-c201.tmpl @@ -0,0 +1,60 @@ +;; This is an operating system configuration template +;; for a "bare bones" setup for an ASUS C201PA. + +(use-modules (gnu) (gnu bootloader depthcharge)) +(use-service-modules networking ssh) +(use-package-modules linux screen) + +(operating-system + (host-name "komputilo") + (timezone "Europe/Berlin") + (locale "en_US.utf8") + + ;; Assuming /dev/mmcblk0p1 is the kernel partition, and + ;; "my-root" is the label of the target root file system. + (bootloader (bootloader-configuration + (bootloader depthcharge-bootloader) + (target "/dev/mmcblk0p1"))) + + ;; The ASUS C201PA requires a very particular kernel to boot, + ;; as well as the following arguments. + (kernel linux-libre-prawn-os) + (kernel-arguments '("console=tty1" "root=/dev/ram0")) + + ;; We do not need any special modules for initrd, and the + ;; PrawnOS kernel does not include many of the normal ones. + (initrd-modules '()) + + (file-systems (cons (file-system + (device (file-system-label "my-root")) + (mount-point "/") + (type "ext4")) + %base-file-systems)) + + ;; This is where user accounts are specified. The "root" + ;; account is implicit, and is initially created with the + ;; empty password. + (users (cons (user-account + (name "alice") + (comment "Bob's sister") + (group "users") + + ;; Adding the account to the "wheel" group + ;; makes it a sudoer. Adding it to "audio" + ;; and "video" allows the user to play sound + ;; and access the webcam. + (supplementary-groups '("wheel" + "audio" "video")) + (home-directory "/home/alice")) + %base-user-accounts)) + + ;; Globally-installed packages. + (packages (cons screen %base-packages)) + + ;; Add services to the baseline: a DHCP client and + ;; an SSH server. + (services (append (list (service dhcp-client-service-type) + (service openssh-service-type + (openssh-configuration + (port-number 2222)))) + %base-services))) -- 2.20.1