[gnome-build-meta/valentindavid/riscv64] Add support for RISC-V




commit 37bc8931517261e359e02b2b14bffab0501e79d9
Author: Valentin David <valentin david codethink co uk>
Date:   Wed Apr 21 19:25:25 2021 +0200

    Add support for RISC-V
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-build-meta/-/merge_requests/1112>

 elements/core-deps/eos-updater.bst  |  2 +-
 elements/core-deps/fwupd-efi.bst    |  2 ++
 elements/core-deps/fwupd.bst        |  3 ++-
 elements/core-deps/qemu.bst         |  2 ++
 elements/core-deps/slirp-helper.bst |  2 ++
 elements/freedesktop-sdk.bst        |  2 ++
 elements/iso/eos-installer.bst      |  2 ++
 elements/iso/initramfs.bst          | 17 +++++++-----
 elements/vm/image.bst               |  7 +++--
 elements/vm/toolbox.bst             |  4 ++-
 files/eos-installer/riscv.patch     | 24 +++++++++++++++++
 files/fwupd/riscv64.patch           | 37 ++++++++++++++++++++++++++
 files/slirp-helper/nix-riscv.patch  | 53 +++++++++++++++++++++++++++++++++++++
 files/toolbox/riscv.patch           | 12 +++++++++
 project.conf                        | 12 +++++++++
 15 files changed, 170 insertions(+), 11 deletions(-)
---
diff --git a/elements/core-deps/eos-updater.bst b/elements/core-deps/eos-updater.bst
index c8a900af..645d4120 100644
--- a/elements/core-deps/eos-updater.bst
+++ b/elements/core-deps/eos-updater.bst
@@ -16,7 +16,7 @@ depends:
 build-depends:
 - sdk/gobject-introspection.bst
 - sdk/gtk-doc.bst
-- freedesktop-sdk.bst:components/valgrind.bst
+- freedesktop-sdk.bst:components/valgrind-maybe.bst
 - freedesktop-sdk.bst:public-stacks/buildsystem-meson.bst
 
 variables:
diff --git a/elements/core-deps/fwupd-efi.bst b/elements/core-deps/fwupd-efi.bst
index f14efb39..231b75be 100644
--- a/elements/core-deps/fwupd-efi.bst
+++ b/elements/core-deps/fwupd-efi.bst
@@ -3,6 +3,8 @@ kind: meson
 sources:
 - kind: tar
   url: github_com:fwupd/fwupd-efi/archive/1.0.tar.gz
+- kind: patch
+  path: files/fwupd/riscv64.patch
 
 build-depends:
 - freedesktop-sdk.bst:public-stacks/buildsystem-meson.bst
diff --git a/elements/core-deps/fwupd.bst b/elements/core-deps/fwupd.bst
index 54047aeb..7f5b6205 100644
--- a/elements/core-deps/fwupd.bst
+++ b/elements/core-deps/fwupd.bst
@@ -33,9 +33,10 @@ depends:
 - freedesktop-sdk.bst:components/pycairo.bst
 - freedesktop-sdk.bst:components/python3-pil.bst
 - freedesktop-sdk.bst:components/tpm2-tss.bst
+- freedesktop-sdk.bst:components/gnu-efi-maybe.bst
 
 (?):
-- arch in ["arm", "aarch64", "x86_64", "i686"]:
+- arch in ["arm", "aarch64", "x86_64", "i686", "riscv64"]:
     depends:
       (>):
       - core-deps/fwupd-efi.bst
diff --git a/elements/core-deps/qemu.bst b/elements/core-deps/qemu.bst
index 9db93901..7f25e526 100644
--- a/elements/core-deps/qemu.bst
+++ b/elements/core-deps/qemu.bst
@@ -35,6 +35,8 @@ variables:
       targets: --target-list=arm-softmmu
   - arch == "ppc64le":
       targets: --target-list=ppc64-softmmu
+  - arch == "riscv64":
+      targets: --target-list=riscv64-softmmu
 
   conf-local: >-
     --disable-werror
diff --git a/elements/core-deps/slirp-helper.bst b/elements/core-deps/slirp-helper.bst
index 6d93de1a..224c2850 100644
--- a/elements/core-deps/slirp-helper.bst
+++ b/elements/core-deps/slirp-helper.bst
@@ -14,6 +14,8 @@ sources:
 - kind: tar
   url: https://static.crates.io/crates/libslirp/libslirp-4.3.0.crate
 - kind: cargo
+- kind: patch
+  path: files/slirp-helper/nix-riscv.patch
 
 config:
   install-commands:
diff --git a/elements/freedesktop-sdk.bst b/elements/freedesktop-sdk.bst
index d9b9e9f3..021ffcef 100644
--- a/elements/freedesktop-sdk.bst
+++ b/elements/freedesktop-sdk.bst
@@ -14,3 +14,5 @@ config:
         bootstrap_build_arch: 'aarch64'
     - arch == "ppc64le":
         bootstrap_build_arch: "ppc64le"
+    - arch == "riscv64":
+        bootstrap_build_arch: "x86_64"
diff --git a/elements/iso/eos-installer.bst b/elements/iso/eos-installer.bst
index d12659fe..628eb496 100644
--- a/elements/iso/eos-installer.bst
+++ b/elements/iso/eos-installer.bst
@@ -21,6 +21,8 @@ sources:
   path: files/eos-installer/remove-branding.patch
 - kind: patch
   path: files/eos-installer/remove-endless-support.patch
+- kind: patch
+  path: files/eos-installer/riscv.patch
 
 depends:
 - freedesktop-sdk.bst:bootstrap-import.bst
diff --git a/elements/iso/initramfs.bst b/elements/iso/initramfs.bst
index cb18f242..e1a15582 100644
--- a/elements/iso/initramfs.bst
+++ b/elements/iso/initramfs.bst
@@ -40,12 +40,10 @@ config:
        --noboot >/dev/null
 
   - |
-    dracut -v --uefi \
-           --uefi-stub /usr/lib/systemd/boot/efi/linux%{efi-arch}.efi.stub \
-           --kernel-image "/boot/vmlinuz" \
-           --no-machineid \
+    dracut -v --no-machineid \
+           --kernel-image /boot/vmlinuz \
            --kver "$(ls -1 /usr/lib/modules | head -n1)" \
-           --kernel-cmdline 'rw quiet splash root=live:LABEL=%{installer-volume-id}' \
+           --kernel-cmdline 'rw quiet splash root=live:LABEL=%{installer-volume-id} console=tty0' \
            --add dmsquash-live \
            --add plymouth \
            --install grep \
@@ -69,6 +67,13 @@ config:
     EOF
 
   - |
-    rm -f /boot/vmlinuz
     rm -f /boot/System.map
 
+  - |
+    cat <<EOF >/boot/loader/entries/gnome-os-installer.conf
+    title GNOME OS Installer
+    version 1
+    options rw quiet splash root=live:LABEL=%{installer-volume-id} console=tty0
+    linux /vmlinuz
+    initrd /initramfs-$(ls -1 /lib/modules | head -n1).img
+    EOF
diff --git a/elements/vm/image.bst b/elements/vm/image.bst
index f13331ae..97edcfc5 100644
--- a/elements/vm/image.bst
+++ b/elements/vm/image.bst
@@ -17,6 +17,8 @@ variables:
       linux-root: 69DAD710-2CE4-4E3C-B16C-21A1D49ABED3
   - arch == "aarch64":
       linux-root: B921B045-1DF0-41C3-AF44-4C6F280D3FAE
+  - arch == "riscv64":
+      linux-root: 72EC70A6-CF74-40E6-BD49-4BDA08E8F224
 
   sysroot: "/sysroot"
 
@@ -56,7 +58,8 @@ config:
   - |
     ostree admin deploy --os="gnome-os" \
          --sysroot="%{sysroot}" %{ostree-branch} \
-         --karg="rw" --karg="quiet" --karg="splash"
+         --karg="rw" --karg="quiet" --karg="splash" \
+         --karg="console=tty0"
 
   - |
     ostree admin set-origin --sysroot="%{sysroot}" \
@@ -74,7 +77,7 @@ config:
   - |
     get_size() {
       size=$(($(du --apparent-size -B 512 -s "${1}" | cut -f1)/2))
-      echo $((${size}+(${size}/10)))k
+      echo $((${size}+(${size}/5)))k
     }
 
     cat > %{install-root}/genimage.cfg <<EOF
diff --git a/elements/vm/toolbox.bst b/elements/vm/toolbox.bst
index f35a6ac0..8f8ba057 100644
--- a/elements/vm/toolbox.bst
+++ b/elements/vm/toolbox.bst
@@ -80,9 +80,11 @@ sources:
   directory: 'src/vendor/golang.org/x/crypto'
 - kind: git_tag
   url: https://github.com/golang/sys.git
-  track: 953cdadca894
+  track: 66c3f260301c
   track-tags: false
   directory: 'src/vendor/golang.org/x/sys'
+- kind: patch
+  path: files/toolbox/riscv.patch
 
 build-depends:
 - freedesktop-sdk.bst:components/systemd.bst
diff --git a/files/eos-installer/riscv.patch b/files/eos-installer/riscv.patch
new file mode 100644
index 00000000..8629104e
--- /dev/null
+++ b/files/eos-installer/riscv.patch
@@ -0,0 +1,24 @@
+diff --git a/gnome-image-installer/util/gpt.c b/gnome-image-installer/util/gpt.c
+index 8d23cf6a..3982ef5a 100644
+--- a/gnome-image-installer/util/gpt.c
++++ b/gnome-image-installer/util/gpt.c
+@@ -9,6 +9,8 @@ static uint8_t GPT_GUID_LINUX_ROOTFS1[] = {0x40, 0x95, 0x47, 0x44, 0x97, 0xf2, 0
+ static uint8_t GPT_GUID_LINUX_ROOTFS2[] = {0xe3, 0xbc, 0x68, 0x4f, 0xcd, 0xe8, 0xb1, 0x4d, 0x96, 0xe7, 
0xfb, 0xca, 0xf9, 0x84, 0xb7, 0x09};
+ static uint8_t GPT_GUID_LINUX_ROOTFS3[] = {0x10, 0xd7, 0xda, 0x69, 0xe4, 0x2c, 0x3c, 0x4e, 0xb1, 0x6c, 
0x21, 0xa1, 0xd4, 0x9a, 0xbe, 0xd3};
+ static uint8_t GPT_GUID_LINUX_ROOTFS4[] = {0x45, 0xb0, 0x21, 0xb9, 0xf0, 0x1d, 0xc3, 0x41, 0xaf, 0x44, 
0x4c, 0x6f, 0x28, 0x0d, 0x3f, 0xae};
++static uint8_t GPT_GUID_LINUX_ROOTFS5[] = {0xa6, 0x70, 0xec, 0x72, 0x74, 0xcf, 0xe6, 0x40, 0xbd, 0x49, 
0x4b, 0xda, 0x08, 0xe8, 0xf2, 0x24};
++static uint8_t GPT_GUID_LINUX_ROOTFS6[] = {0xfe, 0xa7, 0xd5, 0x60, 0x7d, 0x8e, 0x5c, 0x43, 0xb7, 0x14, 
0x3d, 0xd8, 0x16, 0x21, 0x44, 0xe1};
+ 
+ uint8_t is_nth_flag_set(uint64_t flags, uint8_t n)
+ {
+@@ -234,7 +236,9 @@ int is_eos_gpt_valid(struct ptable *pt, uint64_t *size)
+           || memcmp(&pt->partitions[i].type_guid, GPT_GUID_LINUX_ROOTFS1, 16)==0
+           || memcmp(&pt->partitions[i].type_guid, GPT_GUID_LINUX_ROOTFS2, 16)==0
+           || memcmp(&pt->partitions[i].type_guid, GPT_GUID_LINUX_ROOTFS3, 16)==0
+-          || memcmp(&pt->partitions[i].type_guid, GPT_GUID_LINUX_ROOTFS4, 16)==0) {
++          || memcmp(&pt->partitions[i].type_guid, GPT_GUID_LINUX_ROOTFS4, 16)==0
++          || memcmp(&pt->partitions[i].type_guid, GPT_GUID_LINUX_ROOTFS5, 16)==0
++          || memcmp(&pt->partitions[i].type_guid, GPT_GUID_LINUX_ROOTFS6, 16)==0) {
+         // invalid third partition GUID
+         uint64_t flags = 0;
+         memcpy(&flags, pt->partitions[i].attributes, 8);
diff --git a/files/fwupd/riscv64.patch b/files/fwupd/riscv64.patch
new file mode 100644
index 00000000..98753d98
--- /dev/null
+++ b/files/fwupd/riscv64.patch
@@ -0,0 +1,37 @@
+diff -ur fwupd-efi.old/efi/generate_binary.py fwupd-efi/efi/generate_binary.py
+--- fwupd-efi.old/efi/generate_binary.py       2021-05-06 09:53:05.958282422 +0200
++++ fwupd-efi/efi/generate_binary.py   2021-05-06 10:11:29.776318357 +0200
+@@ -36,7 +36,7 @@
+ 
+     # aarch64 and arm32 don't have an EFI capable objcopy
+     # Use 'binary' instead, and add required symbols manually
+-    if args.arch in ["aarch64", "arm"]:
++    if args.arch in ["aarch64", "arm", "riscv64"]:
+         argv.extend(["-O", "binary"])
+     else:
+         argv.extend(["--target", "efi-app-{}".format(args.arch)])
+diff -ur fwupd-efi.old/efi/meson.build fwupd-efi/efi/meson.build
+--- fwupd-efi.old/efi/meson.build      2021-05-06 09:53:05.958282422 +0200
++++ fwupd-efi/efi/meson.build  2021-05-06 10:02:17.272254312 +0200
+@@ -73,7 +73,7 @@
+ endif
+ 
+ # is the system crt0 for arm and aarch64 new enough to know about SBAT?
+-if host_cpu == 'aarch64' or host_cpu == 'arm'
++if host_cpu == 'aarch64' or host_cpu == 'arm' or host_cpu == 'riscv64'
+   if get_option('efi_sbat_distro_id') != ''
+     arch_crt_source = 'crt0-efi-@0@.S'.format(gnu_efi_path_arch)
+     cmd = run_command('grep', '-q', 'sbat', join_paths(efi_crtdir, arch_crt_source))
+diff -ur fwupd-efi.old/meson.build fwupd-efi/meson.build
+--- fwupd-efi.old/meson.build  2021-05-06 09:53:05.957282421 +0200
++++ fwupd-efi/meson.build      2021-05-06 10:02:01.552224910 +0200
+@@ -105,6 +105,9 @@
+ elif host_cpu == 'aarch64'
+         EFI_MACHINE_TYPE_NAME = 'aa64'
+         gnu_efi_arch = 'aarch64'
++elif host_cpu == 'riscv64'
++        EFI_MACHINE_TYPE_NAME = 'riscv64'
++        gnu_efi_arch = 'riscv64'
+ else
+         EFI_MACHINE_TYPE_NAME = ''
+         gnu_efi_arch = ''
diff --git a/files/slirp-helper/nix-riscv.patch b/files/slirp-helper/nix-riscv.patch
new file mode 100644
index 00000000..3b83f7d8
--- /dev/null
+++ b/files/slirp-helper/nix-riscv.patch
@@ -0,0 +1,53 @@
+diff -ru slirp-helper.old/crates/nix-0.17.0/src/sys/ptrace/linux.rs 
slirp-helper/crates/nix-0.17.0/src/sys/ptrace/linux.rs
+--- slirp-helper.old/crates/nix-0.17.0/src/sys/ptrace/linux.rs 2020-02-03 17:25:40.000000000 +0100
++++ slirp-helper/crates/nix-0.17.0/src/sys/ptrace/linux.rs     2021-04-19 15:50:19.553193749 +0200
+@@ -46,7 +46,6 @@
+                                                target_arch = "mips",
+                                                target_arch = "mips64",
+                                                target_arch = "x86_64",
+-                                               target_arch = "riscv64",
+                                                target_pointer_width = "32"))))]
+         PTRACE_GETREGS,
+         #[cfg(any(all(target_os = "android", target_pointer_width = "32"),
+@@ -54,7 +53,6 @@
+                                                target_arch = "mips",
+                                                target_arch = "mips64",
+                                                target_arch = "x86_64",
+-                                               target_arch = "riscv64",
+                                                target_pointer_width = "32"))))]
+         PTRACE_SETREGS,
+         #[cfg(any(all(target_os = "android", target_pointer_width = "32"),
+@@ -62,7 +60,6 @@
+                                                target_arch = "mips",
+                                                target_arch = "mips64",
+                                                target_arch = "x86_64",
+-                                               target_arch = "riscv64",
+                                                target_pointer_width = "32"))))]
+         PTRACE_GETFPREGS,
+         #[cfg(any(all(target_os = "android", target_pointer_width = "32"),
+@@ -70,7 +67,6 @@
+                                                target_arch = "mips",
+                                                target_arch = "mips64",
+                                                target_arch = "x86_64",
+-                                               target_arch = "riscv64",
+                                                target_pointer_width = "32"))))]
+         PTRACE_SETFPREGS,
+         PTRACE_ATTACH,
+@@ -79,15 +75,13 @@
+                                            target_arch = "mips",
+                                            target_arch = "mips64",
+                                            target_arch = "x86",
+-                                           target_arch = "x86_64",
+-                                           target_arch = "riscv64")))]
++                                           target_arch = "x86_64")))]
+         PTRACE_GETFPXREGS,
+         #[cfg(all(target_os = "linux", any(target_env = "musl",
+                                            target_arch = "mips",
+                                            target_arch = "mips64",
+                                            target_arch = "x86",
+-                                           target_arch = "x86_64",
+-                                           target_arch = "riscv64")))]
++                                           target_arch = "x86_64")))]
+         PTRACE_SETFPXREGS,
+         PTRACE_SYSCALL,
+         PTRACE_SETOPTIONS,
diff --git a/files/toolbox/riscv.patch b/files/toolbox/riscv.patch
new file mode 100644
index 00000000..ece7fd57
--- /dev/null
+++ b/files/toolbox/riscv.patch
@@ -0,0 +1,12 @@
+diff -x .git -ur toolbox.old/src/libc-wrappers/libc-wrappers.c toolbox/src/libc-wrappers/libc-wrappers.c
+--- toolbox.old/src/libc-wrappers/libc-wrappers.c      2021-02-23 19:57:46.648985862 +0100
++++ toolbox/src/libc-wrappers/libc-wrappers.c  2021-04-19 15:55:57.421788023 +0200
+@@ -30,6 +30,8 @@
+ __asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.2");
+ #elif defined __x86_64__
+ __asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.2.5");
++#elif defined __riscv
++__asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.32");
+ #else
+ #error "Please specify symbol version for pthread_sigmask"
+ #endif
diff --git a/project.conf b/project.conf
index 769c4560..96538f72 100644
--- a/project.conf
+++ b/project.conf
@@ -35,6 +35,7 @@ options:
     - i686
     - x86_64
     - ppc64le
+    - riscv64
   toolbox:
     type: bool
     default: false
@@ -117,6 +118,16 @@ environment:
       CFLAGS: "%{flags_ppc64le}"
       CXXFLAGS: "%{flags_ppc64le}"
       LDFLAGS: "%{ldflags_defaults}"
+  - arch == "riscv64":
+      CFLAGS: "%{flags_riscv64}"
+      CXXFLAGS: "%{flags_riscv64}"
+      LDFLAGS: "%{ldflags_defaults}"
+      G_SLICE: always-malloc
+
+(?):
+- arch == "riscv64":
+    environment-nocache:
+    - G_SLICE
 
 # Some overrides to element configuration based on type
 #
@@ -319,6 +330,7 @@ variables:
   flags_aarch64: "%{common_flags} -fasynchronous-unwind-tables -fstack-clash-protection %{local_flags}"
   flags_arm: "%{common_flags} %{local_flags}"
   flags_ppc64le: "%{common_flags} -mcpu=power9 -mtune=power9 %{local_flags}"
+  flags_riscv64: "%{common_flags} -fasynchronous-unwind-tables -fstack-clash-protection %{local_flags}"
   ldflags_defaults: "-Wl,-z,relro,-z,now -Wl,--as-needed -L%{libdir}"
   local_flags: ''
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]