all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Guix on the ASUS C201PA
@ 2019-03-06  7:20 Timothy Sample
  2019-03-06  8:59 ` Vagrant Cascadian
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Timothy Sample @ 2019-03-06  7:20 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 4231 bytes --]

Hi guix-devel,

I was able to get Guix to boot on an ASUS Chromebook C201PA.  This model
of computer is pretty neat.  It’s an ARMv7 (32-bit) machine that can be
run with entirely free software.  There is even a free graphics driver
in the works [1].

I’ve attached a (messy) patch that adds a (hacky) bootloader definition
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’m 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 “cgpt” utility it mentions is provided by the
“vboot-utils” Guix package.  (Also, don’t forget to make a file system
on the second partition before mounting.)  After the disk is prepared,
use the “gnu/system/examples/asus-c201.tmpl” 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 “guix system
init” command.  To be clear, if you mounted the file system on “/mnt”
and copied the configuration template to “asus-c201.scm”, you 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’s notion of a
bootloader a little bit.  I use the “bootloader-installer” procedure to
write the kernel image to disk.  In order to tell it which kernel to
write, I overloaded the “configuration-file-generator” to write the
kernel to a special “/boot/depthcharge/vmlinux.kpart” 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’t 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’t looked at it yet.
Alternatively, if using U-Boot directly causes problems, it’s possible
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’s initrd, I got Guix
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=Asus_Chromebook_C201
[3] https://github.com/SolidHal/PrawnOS


[-- Attachment #2: Patch for ASUS C201PA --]
[-- Type: text/x-patch, Size: 15412 bytes --]

From 29b903186c1c7bbcdbc8be549ad0c544985aac2c Mon Sep 17 00:00:00 2001
From: Timothy Sample <samplet@ngyro.com>
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 <samplet@ngyro.com>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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/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 <graf@init.at>
 ;;; Copyright © 2018 Pierre Langlois <pierre.langlois@gmx.com>
 ;;; Copyright © 2018 Vasile Dumitrascu <va511e@yahoo.com>
+;;; Copyright © 2019 Timothy Sample <samplet@ngyro.com>
 ;;;
 ;;; 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"))
 
 \f
+;;;
+;;; 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")))
+
+\f
 ;;;
 ;;; 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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-03-24 18:19 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-06  7:20 Guix on the ASUS C201PA Timothy Sample
2019-03-06  8:59 ` Vagrant Cascadian
2019-03-06 14:33   ` Timothy Sample
2019-03-10  2:42     ` Vagrant Cascadian
2019-03-17  6:47       ` Vagrant Cascadian
2019-03-17 15:20         ` Timothy Sample
2019-03-18  5:38           ` Vagrant Cascadian
2019-03-19  7:22             ` Danny Milosavljevic
2019-03-23 16:33             ` Ludovic Courtès
2019-03-23 19:10               ` Mark H Weaver
2019-03-23 21:04               ` Vagrant Cascadian
2019-03-24 18:19                 ` Vagrant Cascadian
2019-03-06 12:02 ` swedebugia
2019-03-06 15:46 ` mikadoZero
2019-03-15 11:23 ` Ludovic Courtès
2019-03-15 17:39   ` Timothy Sample

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.