tools/testing/selftests/kexec/kexec_common_lib.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/kexec/kexec_common_lib.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/kexec/kexec_common_lib.sh
Extension
.sh
Size
5284 bytes
Lines
220
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
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: GPL-2.0
#
# Kselftest framework defines: ksft_pass=0, ksft_fail=1, ksft_skip=4

VERBOSE="${VERBOSE:-1}"
IKCONFIG="/tmp/config-`uname -r`"
KERNEL_IMAGE="/boot/vmlinuz-`uname -r`"
SECURITYFS=$(grep "securityfs" /proc/mounts | awk '{print $2}')

log_info()
{
	[ $VERBOSE -ne 0 ] && echo "[INFO] $1"
}

# The ksefltest framework requirement returns 0 for PASS.
log_pass()
{
	[ $VERBOSE -ne 0 ] && echo "$1 [PASS]"
	exit 0
}

# The ksefltest framework requirement returns 1 for FAIL.
log_fail()
{
	[ $VERBOSE -ne 0 ] && echo "$1 [FAIL]"
	exit 1
}

# The ksefltest framework requirement returns 4 for SKIP.
log_skip()
{
	[ $VERBOSE -ne 0 ] && echo "$1"
	exit 4
}

# Check efivar SecureBoot-$(the UUID) and SetupMode-$(the UUID).
# (Based on kdump-lib.sh)
get_efivarfs_secureboot_mode()
{
	local efivarfs="/sys/firmware/efi/efivars"
	local secure_boot_file=""
	local setup_mode_file=""
	local secureboot_mode=0
	local setup_mode=0

	# Make sure that efivar_fs is mounted in the normal location
	if ! grep -q "^\S\+ $efivarfs efivarfs" /proc/mounts; then
		log_info "efivars is not mounted on $efivarfs"
		return 0;
	fi
	secure_boot_file=$(find "$efivarfs" -name SecureBoot-* 2>/dev/null)
	setup_mode_file=$(find "$efivarfs" -name SetupMode-* 2>/dev/null)
	if [ -f "$secure_boot_file" ] && [ -f "$setup_mode_file" ]; then
		secureboot_mode=$(hexdump -v -e '/1 "%d\ "' \
			"$secure_boot_file"|cut -d' ' -f 5)
		setup_mode=$(hexdump -v -e '/1 "%d\ "' \
			"$setup_mode_file"|cut -d' ' -f 5)

		if [ $secureboot_mode -eq 1 ] && [ $setup_mode -eq 0 ]; then
			log_info "secure boot mode enabled (CONFIG_EFIVAR_FS)"
			return 1;
		fi
	fi
	return 0;
}

# On powerpc platform, check device-tree property
# /proc/device-tree/ibm,secureboot/os-secureboot-enforcing
# to detect secureboot state.

Annotation

Implementation Notes