From bd89284d59e9cb18e67940e68ce4ab6c3d7fab49 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Thu, 28 May 2026 17:14:37 +0200 Subject: [PATCH] tools/mkrelease: tweak TAR.XZ output for new OTA mechanism Create one XZ block per TAR entry. --- tools/mkrelease.sh | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/tools/mkrelease.sh b/tools/mkrelease.sh index 34359a83a..f4e640521 100755 --- a/tools/mkrelease.sh +++ b/tools/mkrelease.sh @@ -28,6 +28,24 @@ function reverse_entry() { } ' +# shellcheck disable=SC2016 +declare -r AWK_TAR_BLOCKLIST=' +BEGIN { + FS = "[: ]+" + ORS = "" + TAR_BS = 512 + prev_offset = 0 +} +{ + if ($2) + print ($2 - prev_offset) * TAR_BS "," + prev_offset = $2 +} +END { + print 0 +} +' + if [[ "${OSTYPE}" = darwin* ]]; then declare -r READLINK=greadlink declare -r TAR=gtar @@ -306,13 +324,23 @@ case "${format}" in ;; tar.xz) echo "Creating archive: ${output}" - # NOTE: override xz default block size, as otherwise with the size of our - # uncompressed data (< 100 MiB), we never benefit from multi-threading: - # level 9 → 64 MiB dictionary → ×3 default block size = 192 MiB. - # With a block size of 32 MiB, compression with 4 threads is ~2.7 times faster, - # for a final output size increase of just 200 KiB (less than 1%). - "${tar_compress_cmd[@]}" | - xz -9 --block-size=32M ${jobs:+--threads=${jobs}} "${options[@]}" | + # Note: we create one XZ block per TAR entry. + tarfile="${tmpdir}/release.tar" + tarindex="${tarfile}.index" + blocklist="${tmpdir}/release.blocklist" + # Create the initial uncompressed TAR file. + "${tar_compress_cmd[@]}" --file="${tarfile}" + # Find out where each entry starts. + "${TAR}" --block-number --list --file="${tarfile}" >"${tarindex}" + # Generate block list for XZ. + awk "${AWK_TAR_BLOCKLIST}" <"${tarindex}" >"${blocklist}" + # Create the final TAR.XZ file. + # NOTE: we set the block size to a big enough number to + # prevent xz from splitting an entry into multiple blocks. + xz -9 ${jobs:+--threads=${jobs}} \ + --block-size=32M \ + --block-list="$(cat "${blocklist}")" \ + "${options[@]}" --stdout "${tarfile}" | write_to_file "${output}" ;; tar.zst)