From mboxrd@z Thu Jan 1 00:00:00 1970 From: Timothy Sample Subject: Guix on the ASUS C201PA Date: Wed, 06 Mar 2019 02:20:51 -0500 Message-ID: <875zswjwoc.fsf@ngyro.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([209.51.188.92]:56908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1QrZ-0003q8-1t for guix-devel@gnu.org; Wed, 06 Mar 2019 02:21:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1QrP-0006c2-P7 for guix-devel@gnu.org; Wed, 06 Mar 2019 02:21:09 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:53073) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1QrL-0006Yg-FH for guix-devel@gnu.org; Wed, 06 Mar 2019 02:21:00 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id EE2A5340C for ; Wed, 6 Mar 2019 02:20:53 -0500 (EST) Received: from mrblack (74-116-186-44.qc.dsl.ebox.net [74.116.186.44]) by mail.messagingengine.com (Postfix) with ESMTPA id CFCDB10310 for ; Wed, 6 Mar 2019 02:20:52 -0500 (EST) 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@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi guix-devel, I was able to get Guix to boot on an ASUS Chromebook C201PA. This model of computer is pretty neat. It=E2=80=99s an ARMv7 (32-bit) machine that ca= n be run with entirely free software. There is even a free graphics driver in the works [1]. I=E2=80=99ve attached a (messy) patch that adds a (hacky) bootloader defini= tion for Depthcharge and a Linux-Libre package that works on the machine (using an unsupported version of Linux-Libre). All those parenthetical comments are supposed to suggest that this work is not really finished. Now that the computer runs Guix, it should be straight-forward (if time consuming) to fix some of these problems and arrive at something nice. The main reason I=E2=80=99m posting this now is that I believe there is some interest in this machine, and so maybe other people are also excited to try it. :) Below are some brief installation instructions, and some details about the patch. To install, you first need to prepare the disk. Gentoo has a good guide [2]. The =E2=80=9Ccgpt=E2=80=9D utility it mentions is provided by t= he =E2=80=9Cvboot-utils=E2=80=9D Guix package. (Also, don=E2=80=99t forget to= make a file system on the second partition before mounting.) After the disk is prepared, use the =E2=80=9Cgnu/system/examples/asus-c201.tmpl=E2=80=9D configuration = template. Be sure that the bootloader and file-system parts point to the right disk. Finally, you should be able to install Guix using the usual =E2=80=9Cguix s= ystem init=E2=80=9D command. To be clear, if you mounted the file system on =E2= =80=9C/mnt=E2=80=9D and copied the configuration template to =E2=80=9Casus-c201.scm=E2=80=9D, y= ou can run ./pre-inst-env guix system init asus-c201.scm /mnt The two things this patch changes to get Guix to boot is the bootloader and kernel. For the bootloader, these machines use Depthcharge. Depthcharge boots a specially packaged and signed kernel image from a specially marked partition. This kernel image is written to the partition directly without a file system. Other than a bit of metadata about which kernel partition to try to boot from (it supports an automatic fallback feature), there is no configuration. Luckily, Guix already has a package for the tools that sign the kernel image and add the partition metadata. In order to make Depthcharge work, I had to bend Guix=E2=80=99s notion of a bootloader a little bit. I use the =E2=80=9Cbootloader-installer=E2=80=9D = procedure to write the kernel image to disk. In order to tell it which kernel to write, I overloaded the =E2=80=9Cconfiguration-file-generator=E2=80=9D to w= rite the kernel to a special =E2=80=9C/boot/depthcharge/vmlinux.kpart=E2=80=9D file,= which the installer procedure can write to disk. This takes advantage of the fact that Guix writes the configuration file before running the installation procedure, which I wouldn=E2=80=99t have assumed had I not read the code. (Which suggests that this is the wrong way to do it!) There may be a way to improve this by bringing U-Boot into the booting process. The next version of U-Boot (to be released in April) will support this machine directly. I haven=E2=80=99t looked at it yet. Alternatively, if using U-Boot directly causes problems, it=E2=80=99s possi= ble that Depthcharge could boot into U-Boot. For the kernel, I tracked down a particularly stable version, configuration, and patchset from a project called PrawnOS [3]. Support for these machines is a little spotty. I was unable to get Debian to boot, and Arch Linux ARM would boot but only most of the time. PrawnOS is a project that targets these machines directly, and provides a Linux-Libre-based system that seems to boot consistently. After some tinkering to make it build with Guix and run Guix=E2=80=99s initrd, I got G= uix to work nicely. (Although it only seems to load the initrd from the Libreboot version of Depthcharge and not the Google one.) Unfortunately, PrawnOS currently uses Linux-Libre 4.17, which is not supported. Work is under way to use 4.19, which is still supported. Arch Linux ARM uses Linux 4.20, but it is not as well tested as PrawnOS on this machine. -- Tim [1] https://panfrost.freedesktop.org/ [2] https://wiki.gentoo.org/index.php?title=3DAsus_Chromebook_C201 [3] https://github.com/SolidHal/PrawnOS --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-wip-Add-support-for-ASUS-C201.patch Content-Transfer-Encoding: quoted-printable Content-Description: Patch for ASUS C201PA >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 =C2=A9 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 #$@kernel-arguments))))) + (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/devke= ys/" + "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 =3D \ %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 =C2=A9 2018 Manuel Graf ;;; Copyright =C2=A9 2018 Pierre Langlois ;;; Copyright =C2=A9 2018 Vasile Dumitrascu +;;; Copyright =C2=A9 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 s= uch configuration." #:variant (version-major+minor version))) (#f ;no config for this plat= form '()) - ((? 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 bl= obs.") #:extra-version "arm-omap2plus")) =20 +;;; +;;; 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=3D1") + #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=3Dy") + "# 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=3Dy" + "CONFIG_RD_GZIP=3Dy" + "CONFIG_RD_BZIP2=3Dy" + "CONFIG_RD_LZMA=3Dy" + "CONFIG_RD_XZ=3Dy" + "CONFIG_RD_LZO=3Dy" + "CONFIG_RD_LZ4=3Dy"))) + (("# CONFIG_BLK_DEV_RAM is not set") + ((lambda (x) (string-join x "\n")) + '("CONFIG_BLK_DEV_RAM=3Dm" + "CONFIG_BLK_DEV_RAM_COUNT=3D16")))) + ;; 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.patc= h" + "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.pa= tch" + "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=3Dtty1" "root=3D/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))) --=20 2.20.1 --=-=-=--