linux-firmware.lore.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Emil Velikov via B4 Relay <devnull+emil.l.velikov.gmail.com@kernel.org>
To: linux-firmware@kernel.org
Cc: Josh Boyer <jwboyer@kernel.org>, Adam Sampson <ats@offog.org>,
	 David Woodhouse <dwmw2@infradead.org>,
	 Emil Velikov <emil.l.velikov@gmail.com>
Subject: [PATCH RESEND v2 16/16] Makefile, copy-firmware: support xz/zstd compressed firmware
Date: Wed, 01 Mar 2023 18:56:30 +0000	[thread overview]
Message-ID: <20230301-fixes-and-compression-v2-16-e2b71974e842@gmail.com> (raw)
In-Reply-To: <20230301-fixes-and-compression-v2-0-e2b71974e842@gmail.com>

From: Emil Velikov <emil.l.velikov@gmail.com>

The kernel has supported compressed firmware for quite some time. So
let's add a couple of targets to produce that. In practical terms this
means it we'll use ~5x times less space on disk.

Reportedly the amd ucode, needs to be uncompressed _within_ the
initrd in order to work. Using compressed ucode in late load just works.
Ideally this will be addressed by the initrd generators, but considering
the files are tiny in size let's skip the compression.

v2
 - commit message, skip compression for files annotated as Raw

Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 Makefile         |  8 ++++++++
 WHENCE           |  5 +++++
 copy-firmware.sh | 38 ++++++++++++++++++++++++++++++++++----
 3 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 83a0ec6..50a4c29 100644
--- a/Makefile
+++ b/Makefile
@@ -11,3 +11,11 @@ check:
 install:
 	install -d $(DESTDIR)$(FIRMWAREDIR)
 	./copy-firmware.sh $(DESTDIR)$(FIRMWAREDIR)
+
+install-xz:
+	install -d $(DESTDIR)$(FIRMWAREDIR)
+	./copy-firmware.sh --xz $(DESTDIR)$(FIRMWAREDIR)
+
+install-zst:
+	install -d $(DESTDIR)$(FIRMWAREDIR)
+	./copy-firmware.sh --zstd $(DESTDIR)$(FIRMWAREDIR)
diff --git a/WHENCE b/WHENCE
index bce94c5..6e44afa 100644
--- a/WHENCE
+++ b/WHENCE
@@ -3878,14 +3878,19 @@ License: Redistributable. See LICENSE.amd-sev for details
 Driver: microcode_amd - AMD CPU Microcode Update Driver for Linux
 
 File: amd-ucode/microcode_amd.bin
+Raw: amd-ucode/microcode_amd.bin
 Version: 2013-07-10
 File: amd-ucode/microcode_amd_fam15h.bin
+Raw: amd-ucode/microcode_amd_fam15h.bin
 Version: 2018-05-24
 File: amd-ucode/microcode_amd_fam16h.bin
+Raw: amd-ucode/microcode_amd_fam16h.bin
 Version: 2014-10-28
 File: amd-ucode/microcode_amd_fam17h.bin
+Raw: amd-ucode/microcode_amd_fam17h.bin
 Version: 2022-04-08
 File: amd-ucode/microcode_amd_fam19h.bin
+Raw: amd-ucode/microcode_amd_fam19h.bin
 Version: 2023-01-31
 File: amd-ucode/README
 
diff --git a/copy-firmware.sh b/copy-firmware.sh
index a52b847..6da9111 100755
--- a/copy-firmware.sh
+++ b/copy-firmware.sh
@@ -5,6 +5,9 @@
 #
 
 verbose=:
+# shellcheck disable=SC2209
+compress=cat
+compext=
 
 while test $# -gt 0; do
     case $1 in
@@ -14,6 +17,28 @@ while test $# -gt 0; do
             shift
             ;;
 
+        --xz)
+            if test "$compext" == ".zst"; then
+                echo "ERROR: cannot mix XZ and ZSTD compression"
+                exit 1
+            fi
+            compress="xz --compress --quiet --stdout --check=crc32"
+            compext=".xz"
+            shift
+            ;;
+
+        --zstd)
+            if test "$compext" == ".xz"; then
+                echo "ERROR: cannot mix XZ and ZSTD compression"
+                exit 1
+            fi
+            # shellcheck disable=SC2209
+            verbose=echo
+            compress="zstd --compress --quiet --stdout"
+            compext=".zst"
+            shift
+            ;;
+
         *)
             if test "x$destdir" != "x"; then
                 echo "ERROR: unknown command-line options: $*"
@@ -28,16 +53,21 @@ done
 
 # shellcheck disable=SC2162
 grep '^File:' WHENCE | sed -e 's/^File: *//g' | while read f; do
-    $verbose "copying file $f"
     install -d "$destdir/$(dirname "$f")"
-    cp "$f" "$destdir/$f"
+    $verbose "copying/compressing file $f$compext"
+    if test "$compress" != "cat" && grep -q "^Raw: $f\$" WHENCE; then
+        $verbose "compression will be skipped for file $f"
+        cat "$f" > "$destdir/$f"
+    else
+        $compress "$f" > "$destdir/$f$compext"
+    fi
 done
 
 # shellcheck disable=SC2162
 grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read f d; do
-    $verbose "creating link $f -> $d"
     install -d "$destdir/$(dirname "$f")"
-    ln -s "$d" "$destdir/$f"
+    $verbose "creating link $f$compext -> $d$compext"
+    ln -s "$d$compext" "$destdir/$f$compext"
 done
 
 exit 0

-- 
2.39.2


  parent reply	other threads:[~2023-03-01 18:56 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-01 18:56 [PATCH RESEND v2 00/16] Misc fixes, sanity checks and xz/zstd compression Emil Velikov via B4 Relay
2023-03-01 18:56 ` [PATCH RESEND v2 01/16] WHENCE: remove trailing white space Emil Velikov via B4 Relay
2023-03-07 14:53   ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 02/16] WHENCE: remove unnecessary filename quotation Emil Velikov via B4 Relay
2023-03-07 14:56   ` Josh Boyer
2023-03-07 17:53     ` Emil Velikov
2023-03-07 18:01       ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 03/16] check_whence, WHENCE, copy-firmware: escape filenames with spaces Emil Velikov via B4 Relay
2023-03-07 14:58   ` Josh Boyer
2023-03-07 17:30     ` Emil Velikov
2023-03-07 18:00       ` Josh Boyer
2023-03-07 20:48         ` Emil Velikov
2023-03-01 18:56 ` [PATCH RESEND v2 04/16] WHENCE: remove duplicate File entries Emil Velikov via B4 Relay
2023-03-07 15:01   ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 05/16] WHENCE: comment out duplicate MediaTek firmware Emil Velikov via B4 Relay
2023-03-07 15:02   ` Josh Boyer
2023-03-07 17:19     ` Emil Velikov
2023-03-07 18:08       ` Josh Boyer
2023-03-07 20:57         ` Emil Velikov
2023-03-10 12:42           ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 06/16] check_whence: error on duplicate file entries Emil Velikov via B4 Relay
2023-03-07 18:12   ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 07/16] check_whence: error on directory listed as File Emil Velikov via B4 Relay
2023-03-13 20:24   ` Emil Velikov
2023-03-21 10:31     ` Emil Velikov
2023-03-29 14:47       ` Emil Velikov
2023-03-01 18:56 ` [PATCH RESEND v2 08/16] copy-firmware: remove non-applicable file presence test Emil Velikov via B4 Relay
2023-05-08 12:39   ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 09/16] check_whence: error if File: is actually a link Emil Velikov via B4 Relay
2023-05-08 12:41   ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 10/16] check_whence: error if symlinks are in-tree Emil Velikov via B4 Relay
2023-05-08 12:45   ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 11/16] copy-firmware: remove unreachable symlink workarounds Emil Velikov via B4 Relay
2023-03-01 18:56 ` [PATCH RESEND v2 12/16] copy-firmware: quote deskdir to prevent word splitting Emil Velikov via B4 Relay
2023-05-08 12:47   ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 13/16] copy-firmware: tweak sed invocation Emil Velikov via B4 Relay
2023-05-08 12:48   ` Josh Boyer
2023-03-01 18:56 ` [PATCH RESEND v2 14/16] copy-firmware: quote the output of dirname Emil Velikov via B4 Relay
2023-03-01 18:56 ` [PATCH RESEND v2 15/16] copy-firmware: silence the last shellcheck warnings Emil Velikov via B4 Relay
2023-03-01 18:56 ` Emil Velikov via B4 Relay [this message]
2023-03-06 14:23   ` [PATCH RESEND v2 16/16] Makefile, copy-firmware: support xz/zstd compressed firmware Emil Velikov
2023-05-08 12:51 ` [PATCH RESEND v2 00/16] Misc fixes, sanity checks and xz/zstd compression Josh Boyer
2023-05-20 11:05   ` Emil Velikov

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=20230301-fixes-and-compression-v2-16-e2b71974e842@gmail.com \
    --to=devnull+emil.l.velikov.gmail.com@kernel.org \
    --cc=ats@offog.org \
    --cc=dwmw2@infradead.org \
    --cc=emil.l.velikov@gmail.com \
    --cc=jwboyer@kernel.org \
    --cc=linux-firmware@kernel.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).