all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Efraim Flashner <efraim@flashner.co.il>
To: guix-devel@gnu.org
Subject: RISCV porting effort
Date: Mon, 7 Jun 2021 10:09:44 +0300	[thread overview]
Message-ID: <YL3GOGK20wL+cWiL@3900XT> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 2946 bytes --]

Last week my HiFive Umatched¹ board came and was quite the object of
interest at the local computer store as I picked up a case, PSU and
graphics card.

Couple of observations about the board first:
It boots very slowly. I think it takes about 5 minutes from power-on to
being able to sign in at TTY1.
It has an NVMe slot which I haven't populated yet.
Ubuntu has an image for the board² which booted up just fine and I'm
using, since I didn't want to spend too long getting Debian to run on
the board.
Upstream u-boot support was merged days ago³ so we should be able to add
support to our u-boot package soon-ish™.

Porting Guix comes with two parts: building the bootstrap-tarballs and
adding support for the new architecture in (gnu packages bootstrap).
Support for riscv was added to GCC with 7.1.0 so I had to bump the
bootstrap GCC to 7 (and adjust some inputs), and guile-2.0.14 didn't
known the endianness of riscv64 so instead of patching it I bumped the
bootstrap guile to 3.0. I uploaded my bootstrap-tarballs to my regular
spot after signing them and switched over to the riscv machine.

Building Guix from sources is much easier thanks to the work of Vagrant,
I was able to apt install most of the dependencies on riscv. The
packaged version of guile-zlib was too old in 21.04 so I built that from
source (0.1.0 is available in Debian experimental), and I also had to
build gnutls from source for the guile-3.0 bindings. I added the riscv
binaries to (gnu packages bootstrap) and temporarily switched the
raw-build function to look for 3.0 guile libraries instead of 2.0.

Where I'm at right now:
Downloading using the daemon (builtin:download) fails currently, it says
it doesn't have permissions to open-file to write downloaded files to
the store.
I haven't built anything using the bootstrap binaries to see if they
actually work yet.


(ins)efraim@unmatched:~$ neofetch --off
efraim@unmatched
----------------
OS: Ubuntu 21.04 riscv64
Host: SiFive HiFive Unmatched A00
Kernel: 5.11.0-1007-generic
Uptime: 3 days, 15 hours, 57 mins
Packages: 782 (dpkg)
Shell: bash 5.1.4
Terminal: /dev/pts/0
CPU: (4)
GPU: NVIDIA GeForce GT 730
Memory: 350MiB / 15995MiB

(ins)efraim@unmatched:~$ lscpu
Architecture:        riscv64
Byte Order:          Little Endian
CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  4
Core(s) per socket:  1
Socket(s):           1
L1d cache:           32 KiB
L1i cache:           32 KiB
L2 cache:            2 MiB


¹https://www.sifive.com/boards/hifive-unmatched
²http://cdimage.ubuntu.com/releases/21.04/release/
³https://source.denx.de/u-boot/u-boot/-/commit/d8729a114e1e98806cffb87d2dca895f99a0170a

-- 
Efraim Flashner   <efraim@flashner.co.il>   אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted

[-- Attachment #1.2: riscv-make-bootstrap.diff --]
[-- Type: text/plain, Size: 4219 bytes --]

diff --git a/gnu/packages/make-bootstrap.scm b/gnu/packages/make-bootstrap.scm
index bf76d5052f..ef6ea52d6e 100644
--- a/gnu/packages/make-bootstrap.scm
+++ b/gnu/packages/make-bootstrap.scm
@@ -94,13 +94,13 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
   (mlambdaq (glibc)
     "Return a variant of GCC that uses the bootstrap variant of GLIBC."
     (package
-      (inherit gcc-5)
+      (inherit gcc-7)
       (outputs '("out")) ;all in one so libgcc_s is easily found
       (inputs
        `( ;; Distinguish the name so we can refer to it below.
          ("bootstrap-libc" ,(glibc-for-bootstrap glibc))
          ("libc:static" ,(glibc-for-bootstrap glibc) "static")
-         ,@(package-inputs gcc-5))))))
+         ,@(package-inputs gcc-7))))))
 
 (define (package-with-relocatable-glibc p)
   "Return a variant of P that uses the libc as defined by
@@ -139,7 +139,7 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                              (cons (search-path-specification
                                     (variable "CROSS_CPLUS_INCLUDE_PATH")
                                     (files '("include")))
-                                   (package-search-paths gcc-5)))))
+                                   (package-search-paths gcc-7)))))
             ("cross-binutils" ,(cross-binutils target))
             ,@(%final-inputs)))
         `(("libc" ,(glibc-for-bootstrap glibc))
@@ -461,11 +461,11 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
 (define %gcc-static
   ;; A statically-linked GCC, with stripped-down functionality.
   (package-with-relocatable-glibc
-   (package (inherit gcc-5)
+   (package (inherit gcc-7)
      (name "gcc-static")
      (outputs '("out"))                           ; all in one
      (arguments
-      (substitute-keyword-arguments (package-arguments gcc-5)
+      (substitute-keyword-arguments (package-arguments gcc-7)
         ((#:modules modules %gnu-build-system-modules)
          `((srfi srfi-1)
            (srfi srfi-26)
@@ -515,8 +515,8 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                 #t))))))
      (inputs
       `(("zlib:static" ,zlib "static")
-        ("isl:static" ,isl-0.18 "static")
-        ,@(package-inputs gcc-5)))
+        ("isl:static" ,isl "static")
+        ,@(package-inputs gcc-7)))
      (native-inputs
       (if (%current-target-system)
           `(;; When doing a Canadian cross, we need GMP/MPFR/MPC both
@@ -529,12 +529,12 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
             ("gmp-native" ,gmp)
             ("mpfr-native" ,mpfr)
             ("mpc-native" ,mpc)
-            ,@(package-native-inputs gcc-5))
-          (package-native-inputs gcc-5))))))
+            ,@(package-native-inputs gcc-7))
+          (package-native-inputs gcc-7))))))
 
 (define %gcc-stripped
   ;; The subset of GCC files needed for bootstrap.
-  (package (inherit gcc-5)
+  (package (inherit gcc-7)
     (name "gcc-stripped")
     (build-system trivial-build-system)
     (source #f)
@@ -869,6 +869,10 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
   ;; A tarball with the statically-linked, relocatable Guile.
   (tarball-package %guile-static-stripped))
 
+(define %guile-3.0-bootstrap-tarball
+  ;; A tarball with the statically-linked, relocatable Guile.
+  (tarball-package %guile-3.0-static-stripped))
+
 (define %mescc-tools-bootstrap-tarball
   ;; A tarball with statically-linked MesCC binary seed.
   (tarball-package %mescc-tools-static-stripped))
@@ -905,7 +909,7 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                                (find-files directory "\\.tar\\."))))
                    %build-inputs)
          #t)))
-    (inputs `(("guile-tarball" ,%guile-bootstrap-tarball)
+    (inputs `(("guile-tarball" ,%guile-3.0-bootstrap-tarball)
               ,@(match (or (%current-target-system) (%current-system))
                   ((or "i686-linux" "x86_64-linux")
                    `(("bootstrap-mescc-tools" ,%mescc-tools-bootstrap-tarball)

[-- Attachment #1.3: riscv-bootstrap.diff --]
[-- Type: text/plain, Size: 8208 bytes --]

diff --git a/gnu/packages/bootstrap.scm b/gnu/packages/bootstrap.scm
index c598cedc0a..091ffb2d5a 100644
--- a/gnu/packages/bootstrap.scm
+++ b/gnu/packages/bootstrap.scm
@@ -133,18 +133,29 @@
      ("tar"
       ,(base32 "150c8948cz8r208g6qgn2dn4f4zs5kpgbpbg6bwag6yw42rapw2l"))
      ("xz"
-      ,(base32 "0v5738idy9pqzcbrjdpxi5c6qs5m78zrpsydmrpx5cfcfzbkxzjh")))))
+      ,(base32 "0v5738idy9pqzcbrjdpxi5c6qs5m78zrpsydmrpx5cfcfzbkxzjh")))
+    ("riscv64-linux"
+     ("bash"
+      ,(base32 "0almlf73k6hbm495kzf4bw1rzsg5qddn7z2rf5l3d1xcapac2hj3"))
+     ("mkdir"
+      ,(base32 "0rg1amdcqfkplcy1608jignl8jq0wqzfkp430mwik3f62959gya6"))
+     ("tar"
+      ,(base32 "17d3x27qhiwk7h6ns0xrvbrq0frxz89mjjh2cdwx2rraq5x6wffm"))
+     ("xz"
+      ,(base32 "0nxn75xf386vdq3igmgm8gnyk4h4x0cm8jv71vlb2jvwxh0cyw1q")))))
 
 (define %bootstrap-executable-base-urls
   ;; This is where the bootstrap executables come from.
   '("https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/bootstrap/"
     "https://alpha.gnu.org/gnu/guix/bootstrap/"
+    "http://flashner.co.il/guix/bootstrap/"
     "http://lilypond.org/janneke/guix/"))
 
 (define (bootstrap-executable-file-name system program)
   "Return the FILE-NAME part of url where PROGRAM can be found for SYSTEM."
   (match system
     ("powerpc64le-linux" (string-append system "/20210106/" program))
+    ("riscv64-linux" (string-append system "/20210606/bin/" program))
     ("i586-gnu" (string-append system "/20200326/" program))
     (_ (string-append system "/" program
                       "?id=44f07d1dc6806e97c4e9ee3e6be883cc59dc666e"))))
@@ -347,6 +358,8 @@ or false to signal an error."
                     "/20200326/guile-static-stripped-2.0.14-i586-pc-gnu.tar.xz")
                    ("powerpc64le-linux"
                     "/20210106/guile-static-stripped-2.0.14-powerpc64le-linux-gnu.tar.xz")
+                   ("riscv64-linux"
+                    "/20210606/guile-3.0.2.tar.xz")
                    (_
                     "/20131110/guile-2.0.9.tar.xz"))))
 
@@ -363,6 +376,8 @@ or false to signal an error."
      (base32 "1mi3brl7l58aww34rawhvja84xc7l1b4hmwdmc36fp9q9mfx0lg5"))
     ("powerpc64le-linux"
      (base32 "1rnyfz5q38jyvxddj617443bnnzql4vw0mxzqpj8wz48wx4bhbq0"))
+    ("riscv64-linux"
+     (base32 "12pqmhsbbp7hh9r1bjdl14l3a4q06plpz6dcks9dysb4czay8p9f"))
     ("aarch64-linux"
      (base32 "1giy2aprjmn5fp9c4s9r125fljw4wv6ixy5739i5bffw4jgr0f9r"))
     ("i586-gnu"
@@ -419,8 +434,8 @@ or false to signal an error."
                     (lambda (p)
                       (format p "\
 #!~a
-export GUILE_SYSTEM_PATH=~a/share/guile/2.0
-export GUILE_SYSTEM_COMPILED_PATH=~a/lib/guile/2.0/ccache
+export GUILE_SYSTEM_PATH=~a/share/guile/3.0
+export GUILE_SYSTEM_COMPILED_PATH=~a/lib/guile/3.0/ccache
 exec -a \"~a0\" ~a \"~a@\"\n"
                               bash out out dollar guile-real dollar)))
                   (chmod guile   #o555)
@@ -435,8 +450,8 @@ cd $out
 ~a -dc < $GUILE_TARBALL | ~a xv
 
 # Use the bootstrap guile to create its own wrapper to set the load path.
-GUILE_SYSTEM_PATH=$out/share/guile/2.0 \
-GUILE_SYSTEM_COMPILED_PATH=$out/lib/guile/2.0/ccache \
+GUILE_SYSTEM_PATH=$out/share/guile/3.0 \
+GUILE_SYSTEM_COMPILED_PATH=$out/lib/guile/3.0/ccache \
 $out/bin/guile -c ~s $out ~a
 
 # Sanity check.
@@ -498,6 +513,8 @@ $out/bin/guile --version~%"
                                              "/20170217/static-binaries.tar.xz")
                                             ("powerpc64le-linux"
                                              "/20210106/static-binaries-0-powerpc64le-linux-gnu.tar.xz")
+                                            ("riscv64-linux"
+                                             "/20210606/static-binaries.tar.xz")
                                             ("i586-gnu"
                                              "/20200326/static-binaries-0-i586-pc-gnu.tar.xz")
                                             (_
@@ -520,6 +537,9 @@ $out/bin/guile --version~%"
                               ("powerpc64le-linux"
                                (base32
                                 "0afs2j9z2d1hjq42myz4iwjh0aqgzf59inifw87x6b6p1z9wv92v"))
+                              ("riscv64-linux"
+                               (base32
+                                "0x0xjlpmyh6rkr51p00gp6pscgl6zjida1rsg8vk3rinyi6rrbkg"))
                               ("i586-gnu"
                                (base32
                                 "17kllqnf3fg79gzy9ansgi801c46yh9c23h4d923plvb0nfm1cfn"))
@@ -573,6 +593,8 @@ $out/bin/guile --version~%"
                                              "/20210106/binutils-static-stripped-2.34-powerpc64le-linux-gnu.tar.xz")
                                             ("i586-gnu"
                                              "/20200326/binutils-static-stripped-2.34-i586-pc-gnu.tar.xz")
+                                            ("riscv64-linux"
+                                             "/20210606/binutils-2.34.tar.xz")
                                             (_
                                              "/20131110/binutils-2.23.2.tar.xz")))
                                      %bootstrap-base-urls))
@@ -593,6 +615,9 @@ $out/bin/guile --version~%"
                               ("powerpc64le-linux"
                                (base32
                                 "1klxy945c61134mzhqzz2gbk8w0n8jq7arwkrvz78d22ff2q0cwz"))
+                              ("riscv64-linux"
+                               (base32
+                                "0n9qf4vbilfmh1lknhw000waakj4q6s50pnjazr5137skm976z5m"))
                               ("i586-gnu"
                                (base32
                                 "11kykv1kmqc5wln57rs4klaqa13hm952smkc57qcsyss21kfjprs"))
@@ -653,6 +678,8 @@ $out/bin/guile --version~%"
                                        "/20210106/glibc-stripped-2.31-powerpc64le-linux-gnu.tar.xz")
                                       ("i586-gnu"
                                        "/20200326/glibc-stripped-2.31-i586-pc-gnu.tar.xz")
+                                      ("riscv64-linux"
+                                       "/20210606/glibc-2.31.tar.xz")
                                       (_
                                        "/20131110/glibc-2.18.tar.xz")))
                                %bootstrap-base-urls))
@@ -673,6 +700,9 @@ $out/bin/guile --version~%"
                         ("powerpc64le-linux"
                          (base32
                           "1a1df6z8gkaq09md3jy94lixnh20599p58p0s856p10xwjaqr1iz"))
+                        ("riscv64-linux"
+                         (base32
+                          "0162c4yfnz4272c9z03l28dzn5km05r7h06m3s730yiv2disldla"))
                         ("i586-gnu"
                          (base32
                           "14ddm10lpbas8bankmn5bcrlqvz1v5dnn1qjzxb19r57vd2w5952"))
@@ -749,6 +779,8 @@ exec ~a/bin/.gcc-wrapped -B~a/lib \
                                         "/20210106/gcc-stripped-5.5.0-powerpc64le-linux-gnu.tar.xz")
                                        ("i586-gnu"
                                         "/20200326/gcc-stripped-5.5.0-i586-pc-gnu.tar.xz")
+                                       ("riscv64-linux"
+                                        "/20210606/gcc-7.5.0.tar.xz")
                                        (_
                                         "/20131110/gcc-4.8.2.tar.xz")))
                                 %bootstrap-base-urls))
@@ -769,6 +801,9 @@ exec ~a/bin/.gcc-wrapped -B~a/lib \
                          ("powerpc64le-linux"
                           (base32
                            "151kjsai25vz2s667bgzpisx8f281fpl3n9pxz2yrp9jlnadz3m1"))
+                         ("riscv64-linux"
+                          (base32
+                           "0w1gm1pz3nsfxi5s14sd4nlwcbwq7709lma6csgm8gm6l6x5m7pn"))
                          ("i586-gnu"
                           (base32
                            "1j2zc58wzil71a34h7c70sd68dmqvcscrw3rmn2whq79vd70zvv5"))

[-- Attachment #1.4: bootstrap-guix-without-packaging.md --]
[-- Type: text/plain, Size: 2082 bytes --]

We want to build guix from source but not create native packages for all the dependencies. Therefore we will use [GNU Stow](https://www.gnu.org/software/stow/) to install the files to `/usr/local/stow` and then symlink them to `/usr/local`.

http://cdimage.ubuntu.com/releases/21.04/release/
For this, on Ubuntu 21.04, we need to install some packages:

```shell
sudo apt update
sudo apt install git stow autoconf autopoint make g++ gettext pkg-config po4a texinfo help2man guile-3.0 guile-3.0-dev libtasn1-6-dev guile-git guile-json guile-sqlite3 guile-gcrypt guile-lzlib
```

We need to compile gnutls from source to build the guile3.0 bindings

(make took 38 minutes)
```shell
cd /usr/local/src
wget https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6/gnutls-3.6.16.tar.xz
wget https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6/gnutls-3.6.16.tar.xz.sig
gpg --verify gnutls-3.6.16.tar.xz.sig
tar xf ../gnutls-3.6.16.tar.xz
cd gnutls-3.6.16
./configure --with-included-libtasn1 \
        --with-included-unistring \
        --without-p11-kit \
        --disable-dependency-tracking \
        --with-guile-site-dir=/usr/local/share/guile/site/3.0 \
        --with-guile-site-ccache-dir=/usr/local/lib/guile/3.0/site-ccache \
        --with-guile-extension-dir=/usr/local/lib/guile/3.0/extensions
make
sudo make install prefix=/usr/local/stow/gnutls-3.6.16
cd /usr/local/stow
sudo stow gnutls-3.6.16
```

guile-zlib is actually too old, so we build it from source
(make took 43 seconds)
```shell
cd /usr/local/src
git clone https://notabug.org/guile-zlib/guile-zlib
cd guile-zlib
git checkout v0.1.0
autoreconf -vfi
GUILE_LOAD_PATH=/usr/local/share/guile/site/3.0:$GUILE_LOAD_PATH ./configure
make
sudo make install prefix=/usr/local/stow/guile-zlib-0.1.0
ct /usr/local/stow
sudo stow guile-zlib-0.1.0
```

Then we can get started with Guix itself
```shell
git clone https://git.savannah.gnu.org/git/guix.git
cd guix
./bootstrap
GUILE_LOAD_PATH=/usr/local/share/guile/site/3.0:$GUILE_LOAD_PATH ./configure --with-courage
GUILE_LOAD_PATH=/usr/local/share/guile/site/3.0:$GUILE_LOAD_PATH make
```

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply	other threads:[~2021-06-07  7:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07  7:09 Efraim Flashner [this message]
2021-06-07 15:37 ` RISCV porting effort Christopher Lemmer Webber
2021-06-08 13:43 ` Ludovic Courtès
2021-06-08 22:28   ` Gabriel Wicki
2021-06-10 13:22     ` Efraim Flashner
2021-06-11 21:07     ` Ludovic Courtès
2021-06-10 13:20   ` Efraim Flashner
2021-06-11 22:07     ` Ludovic Courtès
2021-06-18 13:05     ` RISCV porting effort (now in stock @mouser) Gabriel Wicki
2021-06-11 11:16 ` RISCV porting effort Efraim Flashner
2021-06-13 17:24 ` Vagrant Cascadian
2021-06-14  7:27   ` Efraim Flashner
2021-06-15  1:00     ` Vagrant Cascadian
2021-06-15 12:37       ` Efraim Flashner
2021-06-13 21:21 ` Christopher Baines
2021-06-20 15:37   ` Ludovic Courtès
2022-06-16  1:46     ` Pjotr Prins
2022-06-16 18:12       ` Maxim Cournoyer
2022-06-17 16:08       ` Ludovic Courtès
2022-06-17 22:52         ` Pjotr Prins
2022-06-20  7:45           ` Pjotr Prins
2022-06-22 13:37             ` Ludovic Courtès
2022-06-22 15:19               ` Ekaitz Zarraga
2022-06-28  8:54                 ` Efraim Flashner
2022-06-30 12:01                   ` Ludovic Courtès
2022-07-03  9:07                     ` Efraim Flashner
2022-06-24  6:37               ` Pjotr Prins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YL3GOGK20wL+cWiL@3900XT \
    --to=efraim@flashner.co.il \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.