Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftest/kho: update generation of initrd

Use nolibc include directory rather than include a cumulative nolibc.h on
the compiler command line and replace use of 'sudo cpio' with
usr/gen_init_cpio.

While on it fix spelling of KHO_FINALIZE

Link: https://lkml.kernel.org/r/20250811082510.4154080-4-rppt@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Cc: Alexander Graf <graf@amazon.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Changyuan Lyu <changyuanl@google.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Pratyush Yadav <pratyush@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Mike Rapoport (Microsoft) and committed by
Andrew Morton
801295be 950c31e8

+18 -21
+4 -9
tools/testing/selftests/kho/init.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 - #ifndef NOLIBC 4 - #include <errno.h> 5 3 #include <stdio.h> 6 4 #include <unistd.h> 7 5 #include <fcntl.h> 8 - #include <syscall.h> 6 + #include <sys/syscall.h> 9 7 #include <sys/mount.h> 10 8 #include <sys/reboot.h> 11 - #endif 9 + #include <linux/kexec.h> 12 10 13 11 /* from arch/x86/include/asm/setup.h */ 14 12 #define COMMAND_LINE_SIZE 2048 15 13 16 - /* from include/linux/kexex.h */ 17 - #define KEXEC_FILE_NO_INITRAMFS 0x00000004 18 - 19 - #define KHO_FINILIZE "/debugfs/kho/out/finalize" 14 + #define KHO_FINALIZE "/debugfs/kho/out/finalize" 20 15 #define KERNEL_IMAGE "/kernel" 21 16 22 17 static int mount_filesystems(void) ··· 27 32 const char enable[] = "1"; 28 33 int fd; 29 34 30 - fd = open(KHO_FINILIZE, O_RDWR); 35 + fd = open(KHO_FINALIZE, O_RDWR); 31 36 if (fd < 0) 32 37 return -1; 33 38
+14 -12
tools/testing/selftests/kho/vmtest.sh
··· 10 10 11 11 tmp_dir=$(mktemp -d /tmp/kho-test.XXXXXXXX) 12 12 headers_dir="$tmp_dir/usr" 13 - initrd_dir="$tmp_dir/initrd" 14 13 initrd="$tmp_dir/initrd.cpio" 15 14 16 15 source "$test_dir/../kselftest/ktap_helpers.sh" ··· 80 81 function mkinitrd() { 81 82 local kernel=$1 82 83 83 - mkdir -p "$initrd_dir"/{dev,debugfs,proc} 84 - sudo mknod "$initrd_dir/dev/console" c 5 1 84 + "$CROSS_COMPILE"gcc -s -static -Os -nostdinc -nostdlib \ 85 + -fno-asynchronous-unwind-tables -fno-ident \ 86 + -I "$headers_dir/include" \ 87 + -I "$kernel_dir/tools/include/nolibc" \ 88 + -o "$tmp_dir/init" "$test_dir/init.c" 85 89 86 - "$CROSS_COMPILE"gcc -s -static -Os -nostdinc -I"$headers_dir/include" \ 87 - -fno-asynchronous-unwind-tables -fno-ident -nostdlib \ 88 - -include "$test_dir/../../../include/nolibc/nolibc.h" \ 89 - -o "$initrd_dir/init" "$test_dir/init.c" \ 90 + cat > "$tmp_dir/cpio_list" <<EOF 91 + dir /dev 0755 0 0 92 + dir /proc 0755 0 0 93 + dir /debugfs 0755 0 0 94 + nod /dev/console 0600 0 0 c 5 1 95 + file /init $tmp_dir/init 0755 0 0 96 + file /kernel $kernel 0644 0 0 97 + EOF 90 98 91 - cp "$kernel" "$initrd_dir/kernel" 92 - 93 - pushd "$initrd_dir" &>/dev/null 94 - find . | cpio -H newc --create > "$initrd" 2>/dev/null 95 - popd &>/dev/null 99 + "$build_dir/usr/gen_init_cpio" "$tmp_dir/cpio_list" > "$initrd" 96 100 } 97 101 98 102 function run_qemu() {