scripts/xz_wrap.sh

Source file repositories/reference/linux-study-clean/scripts/xz_wrap.sh

File Facts

System
Linux kernel
Corpus path
scripts/xz_wrap.sh
Extension
.sh
Size
3527 bytes
Lines
163
Domain
Support Tooling And Documentation
Bucket
scripts
Inferred role
Support Tooling And Documentation: scripts
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/sh
# SPDX-License-Identifier: 0BSD
#
# This is a wrapper for xz to compress the kernel image using appropriate
# compression options depending on the architecture.
#
# Author: Lasse Collin <lasse.collin@tukaani.org>

# This has specialized settings for the following archs. However,
# XZ-compressed kernel isn't currently supported on every listed arch.
#
#   Arch        Align   Notes
#   arm          2/4    ARM and ARM-Thumb2
#   arm64         4
#   csky          2
#   loongarch     4
#   mips         2/4    MicroMIPS is 2-byte aligned
#   parisc        4
#   powerpc       4     Uses its own wrapper for compressors instead of this.
#   riscv        2/4
#   s390          2
#   sh            2
#   sparc         4
#   x86           1

# A few archs use 2-byte or 4-byte aligned instructions depending on
# the kernel config. This function is used to check if the relevant
# config option is set to "y".
is_enabled()
{
	grep -q "^$1=y$" include/config/auto.conf
}

# XZ_VERSION is needed to disable features that aren't available in
# old XZ Utils versions.
XZ_VERSION=$($XZ --robot --version) || exit
XZ_VERSION=$(printf '%s\n' "$XZ_VERSION" | sed -n 's/^XZ_VERSION=//p')

# Assume that no BCJ filter is available.
BCJ=

# Set the instruction alignment to 1, 2, or 4 bytes.
#
# Set the BCJ filter if one is available.
# It must match the #ifdef usage in lib/decompress_unxz.c.
case $SRCARCH in
	arm)
		if is_enabled CONFIG_THUMB2_KERNEL; then
			ALIGN=2
			BCJ=--armthumb
		else
			ALIGN=4
			BCJ=--arm
		fi
		;;

	arm64)
		ALIGN=4

		# ARM64 filter was added in XZ Utils 5.4.0.
		if [ "$XZ_VERSION" -ge 50040002 ]; then
			BCJ=--arm64
		else
			echo "$0: Upgrading to xz >= 5.4.0" \
				"would enable the ARM64 filter" \
				"for better compression" >&2
		fi
		;;

	csky)

Annotation

Implementation Notes