Fix RISC-V gzip compressed kernels

This commit is contained in:
Richard W.M. Jones 2023-11-10 11:03:54 +00:00
parent 6f9f7bfc2e
commit 2417d4becf
14 changed files with 165 additions and 23 deletions

View File

@ -1,7 +1,7 @@
From 86fd6f3e86ab99d54a22b475aecccfc19bdff07e Mon Sep 17 00:00:00 2001 From 86fd6f3e86ab99d54a22b475aecccfc19bdff07e Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 21 Jan 2023 09:38:55 +0000 Date: Sat, 21 Jan 2023 09:38:55 +0000
Subject: [PATCH 01/10] rpm: New RPM database location in /usr/lib/sysimage/rpm Subject: [PATCH 01/13] rpm: New RPM database location in /usr/lib/sysimage/rpm
A few years ago the RPM database was moved from /var to /usr. This is A few years ago the RPM database was moved from /var to /usr. This is
now feeding through to Linux distros. now feeding through to Linux distros.
@ -46,5 +46,5 @@ index 85557fe..2c199c1 100644
(* Return the best provider of a particular RPM requirement. (* Return the best provider of a particular RPM requirement.
* *
-- --
2.37.3 2.42.0

View File

@ -1,7 +1,7 @@
From f8774efbe02d3651cde449333cf108e79adba48c Mon Sep 17 00:00:00 2001 From f8774efbe02d3651cde449333cf108e79adba48c Mon Sep 17 00:00:00 2001
From: Kate <kit.ty.kate@disroot.org> From: Kate <kit.ty.kate@disroot.org>
Date: Wed, 16 Nov 2022 19:30:01 +0000 Date: Wed, 16 Nov 2022 19:30:01 +0000
Subject: [PATCH 02/10] Add support for OCaml 5.0 Subject: [PATCH 02/13] Add support for OCaml 5.0
--- ---
src/mode_build.ml | 4 ++-- src/mode_build.ml | 4 ++--
@ -94,5 +94,5 @@ index 521d49e..ae99294 100644
let xs = uniq ~cmp xs in let xs = uniq ~cmp xs in
xs xs
-- --
2.37.3 2.42.0

View File

@ -1,7 +1,7 @@
From 3efe663421d94376694f292ca1fcf2732a82149f Mon Sep 17 00:00:00 2001 From 3efe663421d94376694f292ca1fcf2732a82149f Mon Sep 17 00:00:00 2001
From: Kate <kit.ty.kate@disroot.org> From: Kate <kit.ty.kate@disroot.org>
Date: Wed, 16 Nov 2022 19:59:36 +0000 Date: Wed, 16 Nov 2022 19:59:36 +0000
Subject: [PATCH 03/10] Restore compatibility with OCaml < 4.07 Subject: [PATCH 03/13] Restore compatibility with OCaml < 4.07
--- ---
src/mode_build.ml | 6 ++++-- src/mode_build.ml | 6 ++++--
@ -121,5 +121,5 @@ index ae99294..1dc4310 100644
let xs = uniq ~cmp xs in let xs = uniq ~cmp xs in
xs xs
-- --
2.37.3 2.42.0

View File

@ -1,7 +1,7 @@
From 92d5d7e8c27088fa3fb8e5e6e9c5b8d3209053d6 Mon Sep 17 00:00:00 2001 From 92d5d7e8c27088fa3fb8e5e6e9c5b8d3209053d6 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 30 May 2023 09:12:14 +0100 Date: Tue, 30 May 2023 09:12:14 +0100
Subject: [PATCH 04/10] rpm: Detect dnf5 and omit missing options Subject: [PATCH 04/13] rpm: Detect dnf5 and omit missing options
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2209412 Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2209412
--- ---
@ -54,5 +54,5 @@ index 2c199c1..3e803c6 100644
let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in
List.map ( List.map (
-- --
2.37.3 2.42.0

View File

@ -1,7 +1,7 @@
From 057ea99a3211057d2cb2c9971afe56e0a85e0f78 Mon Sep 17 00:00:00 2001 From 057ea99a3211057d2cb2c9971afe56e0a85e0f78 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 31 May 2023 12:52:13 +0100 Date: Wed, 31 May 2023 12:52:13 +0100
Subject: [PATCH 05/10] rpm: Use dnf --config instead of -c Subject: [PATCH 05/13] rpm: Use dnf --config instead of -c
dnf5 does not support -c. dnf4 supports either. dnf5 does not support -c. dnf4 supports either.
@ -24,5 +24,5 @@ index 3e803c6..e94f35f 100644
(quote tdir) (quote tdir)
(quoted_list rpms) in (quoted_list rpms) in
-- --
2.37.3 2.42.0

View File

@ -1,7 +1,7 @@
From 8dd37da1b5979842b0db44b44655eeaf621f7ac9 Mon Sep 17 00:00:00 2001 From 8dd37da1b5979842b0db44b44655eeaf621f7ac9 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 12 Jun 2023 12:51:56 +0100 Date: Mon, 12 Jun 2023 12:51:56 +0100
Subject: [PATCH 06/10] src: Improved debugging of the supermin if-newer Subject: [PATCH 06/13] src: Improved debugging of the supermin if-newer
calculation calculation
Also I expanded the code to make it easier to read. There is no Also I expanded the code to make it easier to read. There is no
@ -52,5 +52,5 @@ index d49c1e8..c30c73c 100644
printf "supermin: if-newer: output does not need rebuilding\n%!"; printf "supermin: if-newer: output does not need rebuilding\n%!";
exit 0 exit 0
-- --
2.37.3 2.42.0

View File

@ -1,7 +1,7 @@
From 8c38641042e274a713a18daf7fc85584ca0fc9bb Mon Sep 17 00:00:00 2001 From 8c38641042e274a713a18daf7fc85584ca0fc9bb Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 12 Jun 2023 13:02:37 +0100 Date: Mon, 12 Jun 2023 13:02:37 +0100
Subject: [PATCH 07/10] src: Fix --if-newer --copy-kernel Subject: [PATCH 07/13] src: Fix --if-newer --copy-kernel
We previously copied the kernel into the appliance using 'cp -p' which We previously copied the kernel into the appliance using 'cp -p' which
preserves the datestamps of the installed kernel. This can confuse preserves the datestamps of the installed kernel. This can confuse
@ -35,5 +35,5 @@ index c592703..6d2e699 100644
run_command cmd run_command cmd
) )
-- --
2.37.3 2.42.0

View File

@ -1,7 +1,7 @@
From 2f3eae350aa89b8067201a8bb24ff830d0fd919c Mon Sep 17 00:00:00 2001 From 2f3eae350aa89b8067201a8bb24ff830d0fd919c Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 22 Jun 2023 08:35:51 +0100 Date: Thu, 22 Jun 2023 08:35:51 +0100
Subject: [PATCH 08/10] rpm: Reenable disable_excludes for dnf5 Subject: [PATCH 08/13] rpm: Reenable disable_excludes for dnf5
Updates: commit 92d5d7e8c27088fa3fb8e5e6e9c5b8d3209053d6 Updates: commit 92d5d7e8c27088fa3fb8e5e6e9c5b8d3209053d6
Thanks: Jan Kolarik Thanks: Jan Kolarik
@ -25,5 +25,5 @@ index e94f35f..783d1bb 100644
(quoted_list rpms) in (quoted_list rpms) in
run_command cmd run_command cmd
-- --
2.37.3 2.42.0

View File

@ -0,0 +1,26 @@
From 4b3922feb65150f3423d0877038c5ba6e16d910c Mon Sep 17 00:00:00 2001
From: Simon Fischer <1522981+Fischer-Simon@users.noreply.github.com>
Date: Wed, 12 Jul 2023 17:10:53 +0200
Subject: [PATCH 09/13] src/format_ext2_kernel.ml: Fix kernel filtering for
aarch64 architecture
Add appropriate globs for arm based kernels. The file names end in -arm64 but the architecture is named aarch64.
---
src/format_ext2_kernel.ml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml
index 6d2e699..4589552 100644
--- a/src/format_ext2_kernel.ml
+++ b/src/format_ext2_kernel.ml
@@ -187,6 +187,7 @@ and patt_of_cpu host_cpu =
| "amd64" | "x86_64" -> ["amd64"; "x86_64"]
| "parisc" | "parisc64" -> ["hppa"; "hppa64"]
| "ppc64el" -> ["powerpc64le"]
+ | "aarch64" -> ["aarch64"; "arm64"]
| _ when host_cpu.[0] = 'i' && host_cpu.[2] = '8' && host_cpu.[3] = '6' -> ["?86"]
| _ when String.length host_cpu >= 5 && String.sub host_cpu 0 5 = "armv7" -> ["armmp"]
| _ -> [host_cpu]
--
2.42.0

View File

@ -1,7 +1,7 @@
From dc80dbbef60d5d81a7d4321683a8c7305dc04972 Mon Sep 17 00:00:00 2001 From dc80dbbef60d5d81a7d4321683a8c7305dc04972 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 12 Jul 2023 22:37:58 +0100 Date: Wed, 12 Jul 2023 22:37:58 +0100
Subject: [PATCH 09/10] ocamlc: Use -output-complete-exe instead of -custom Subject: [PATCH 10/13] ocamlc: Use -output-complete-exe instead of -custom
This prevents bytecode executables from being broken by strip and This prevents bytecode executables from being broken by strip and
similar tools. Note this is incompatible with OCaml < 4.10 (so breaks similar tools. Note this is incompatible with OCaml < 4.10 (so breaks
@ -29,5 +29,5 @@ index 5b07e5d..5a1c671 100644
OBJECTS = $(XOBJECTS) OBJECTS = $(XOBJECTS)
BEST = opt BEST = opt
-- --
2.37.3 2.42.0

View File

@ -1,7 +1,7 @@
From 59a8ffc40db94a38879d9c923520e0bd70ffa271 Mon Sep 17 00:00:00 2001 From 59a8ffc40db94a38879d9c923520e0bd70ffa271 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 12 Jul 2023 22:51:43 +0100 Date: Wed, 12 Jul 2023 22:51:43 +0100
Subject: [PATCH 10/10] ocamlc: Only supply -output-complete-exe to final link Subject: [PATCH 11/13] ocamlc: Only supply -output-complete-exe to final link
Add a separate variable to store link flags, and use that to supply Add a separate variable to store link flags, and use that to supply
-output-complete-exe. Apparently ocamlc ignores -custom in the wrong -output-complete-exe. Apparently ocamlc ignores -custom in the wrong
@ -38,5 +38,5 @@ index 5a1c671..1268aa5 100644
.mli.cmi: .mli.cmi:
-- --
2.37.3 2.42.0

View File

@ -0,0 +1,36 @@
From 9a0d078dc35fde7a715666bce6c765ed5fe5e916 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 10 Nov 2023 08:55:25 +0000
Subject: [PATCH 12/13] src/format_ext2_kernel.ml: Rename function file ->
kernel
No change, just rename the function.
---
src/format_ext2_kernel.ml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml
index 4589552..36514c6 100644
--- a/src/format_ext2_kernel.ml
+++ b/src/format_ext2_kernel.ml
@@ -54,7 +54,7 @@ let rec build_kernel debug host_cpu copy_kernel kernel =
printf "supermin: kernel: modpath %s\n%!" modpath;
);
- copy_or_symlink_file copy_kernel kernel_file kernel;
+ copy_or_symlink_kernel copy_kernel kernel_file kernel;
(kernel_version, modpath)
@@ -308,7 +308,7 @@ and read_string chan offset len =
really_input chan buf 0 len;
Bytes.to_string buf
-and copy_or_symlink_file copy_kernel src dest =
+and copy_or_symlink_kernel copy_kernel src dest =
if not copy_kernel then
symlink src dest
else (
--
2.42.0

View File

@ -0,0 +1,72 @@
From 5230e2c3cd07e82bd6431e871e239f7056bf25ad Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 10 Nov 2023 10:20:49 +0000
Subject: [PATCH 13/13] src: Uncompress kernel on RISC-V
---
src/format_ext2_kernel.ml | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml
index 36514c6..09a3f21 100644
--- a/src/format_ext2_kernel.ml
+++ b/src/format_ext2_kernel.ml
@@ -25,6 +25,20 @@ open Ext2fs
open Fnmatch
open Glob
+(* Similar but not the same as get_file_type in mode_build. There
+ * is a case for deriving a common base utility. XXX
+ *)
+type compression_type = GZip | Uncompressed
+let get_compression_type file =
+ let chan = open_in file in
+ let buf = Bytes.create 512 in
+ let len = input chan buf 0 (Bytes.length buf) in
+ close_in chan;
+ let buf = Bytes.to_string buf in
+ if len >= 3 && buf.[0] = '\x1f' && buf.[1] = '\x8b' && buf.[2] = '\x08'
+ then GZip
+ else Uncompressed (* or other unknown compression type *)
+
let rec build_kernel debug host_cpu copy_kernel kernel =
(* Locate the kernel.
* SUPERMIN_* environment variables override everything. If those
@@ -54,7 +68,19 @@ let rec build_kernel debug host_cpu copy_kernel kernel =
printf "supermin: kernel: modpath %s\n%!" modpath;
);
- copy_or_symlink_kernel copy_kernel kernel_file kernel;
+ (* RISC-V relies on the bootloader or firmware to uncompress the
+ * kernel and doesn't have a concept of self-extracting kernels.
+ * On Arm which is similar, qemu -kernel will automatically uncompress
+ * the kernel, but qemu-system-riscv won't do that and the code is a
+ * big mess so I don't fancy fixing it. So we have to detect that
+ * case here and uncompress the kernel.
+ *)
+ let kernel_compression_type = get_compression_type kernel_file in
+ if string_prefix "riscv" host_cpu && kernel_compression_type <> Uncompressed
+ then
+ copy_and_uncompress_kernel kernel_compression_type kernel_file kernel
+ else
+ copy_or_symlink_kernel copy_kernel kernel_file kernel;
(kernel_version, modpath)
@@ -308,6 +334,13 @@ and read_string chan offset len =
really_input chan buf 0 len;
Bytes.to_string buf
+and copy_and_uncompress_kernel compression_type src dest =
+ let cmd =
+ match compression_type with
+ | GZip -> sprintf "zcat %s > %s" (quote src) (quote dest)
+ | Uncompressed -> sprintf "cp %s %s" (quote src) (quote dest) in
+ run_command cmd
+
and copy_or_symlink_kernel copy_kernel src dest =
if not copy_kernel then
symlink src dest
--
2.42.0

View File

@ -38,7 +38,7 @@ ExcludeArch: %{ix86}
Summary: Tool for creating supermin appliances Summary: Tool for creating supermin appliances
Name: supermin Name: supermin
Version: 5.3.3 Version: 5.3.3
Release: 16%{?dist} Release: 17%{?dist}
License: GPL-2.0-or-later License: GPL-2.0-or-later
ExclusiveArch: %{kernel_arches} ExclusiveArch: %{kernel_arches}
@ -67,9 +67,14 @@ Patch: 0006-src-Improved-debugging-of-the-supermin-if-newer-calc.patch
Patch: 0007-src-Fix-if-newer-copy-kernel.patch Patch: 0007-src-Fix-if-newer-copy-kernel.patch
# Reenable disable_excludes for dnf5 # Reenable disable_excludes for dnf5
Patch: 0008-rpm-Reenable-disable_excludes-for-dnf5.patch Patch: 0008-rpm-Reenable-disable_excludes-for-dnf5.patch
# Fix kernel filtering on aarch64
Patch: 0009-src-format_ext2_kernel.ml-Fix-kernel-filtering-for-a.patch
# Fix bytecode builds so they resist stripping # Fix bytecode builds so they resist stripping
Patch: 0009-ocamlc-Use-output-complete-exe-instead-of-custom.patch Patch: 0010-ocamlc-Use-output-complete-exe-instead-of-custom.patch
Patch: 0010-ocamlc-Only-supply-output-complete-exe-to-final-link.patch Patch: 0011-ocamlc-Only-supply-output-complete-exe-to-final-link.patch
# Fix RISC-V gzip compressed kernels
Patch: 0012-src-format_ext2_kernel.ml-Rename-function-file-kerne.patch
Patch: 0013-src-Uncompress-kernel-on-RISC-V.patch
BuildRequires: gcc BuildRequires: gcc
BuildRequires: make BuildRequires: make
@ -224,6 +229,9 @@ make check || {
%changelog %changelog
* Fri Nov 10 2023 Richard W.M. Jones <rjones@redhat.com> - 5.3.3-17
- Fix RISC-V gzip compressed kernels
* Thu Oct 05 2023 Richard W.M. Jones <rjones@redhat.com> - 5.3.3-16 * Thu Oct 05 2023 Richard W.M. Jones <rjones@redhat.com> - 5.3.3-16
- OCaml 5.1 rebuild for Fedora 40 - OCaml 5.1 rebuild for Fedora 40