]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftest/kho: update generation of initrd
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Mon, 11 Aug 2025 08:25:10 +0000 (11:25 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Sep 2025 00:24:50 +0000 (17:24 -0700)
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>
tools/testing/selftests/kho/init.c
tools/testing/selftests/kho/vmtest.sh

index 8034e24c6bf6e1af3bae6359cd4b90960f20c23b..6d9e91d55d688b7b2f18f0b4a3dd8178bba078e8 100644 (file)
@@ -1,22 +1,17 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#ifndef NOLIBC
-#include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <syscall.h>
+#include <sys/syscall.h>
 #include <sys/mount.h>
 #include <sys/reboot.h>
-#endif
+#include <linux/kexec.h>
 
 /* from arch/x86/include/asm/setup.h */
 #define COMMAND_LINE_SIZE      2048
 
-/* from include/linux/kexex.h */
-#define KEXEC_FILE_NO_INITRAMFS        0x00000004
-
-#define KHO_FINILIZE "/debugfs/kho/out/finalize"
+#define KHO_FINALIZE "/debugfs/kho/out/finalize"
 #define KERNEL_IMAGE "/kernel"
 
 static int mount_filesystems(void)
@@ -32,7 +27,7 @@ static int kho_enable(void)
        const char enable[] = "1";
        int fd;
 
-       fd = open(KHO_FINILIZE, O_RDWR);
+       fd = open(KHO_FINALIZE, O_RDWR);
        if (fd < 0)
                return -1;
 
index ec70a17bd476ce863f4fd42548e64c7b69277cf4..3f6c17166846707c4cd7c6af33e6b29aadc89f4e 100755 (executable)
@@ -10,7 +10,6 @@ kernel_dir=$(realpath "$test_dir/../../../..")
 
 tmp_dir=$(mktemp -d /tmp/kho-test.XXXXXXXX)
 headers_dir="$tmp_dir/usr"
-initrd_dir="$tmp_dir/initrd"
 initrd="$tmp_dir/initrd.cpio"
 
 source "$test_dir/../kselftest/ktap_helpers.sh"
@@ -81,19 +80,22 @@ EOF
 function mkinitrd() {
        local kernel=$1
 
-       mkdir -p "$initrd_dir"/{dev,debugfs,proc}
-       sudo mknod "$initrd_dir/dev/console" c 5 1
-
-       "$CROSS_COMPILE"gcc -s -static -Os -nostdinc -I"$headers_dir/include" \
-                       -fno-asynchronous-unwind-tables -fno-ident -nostdlib \
-                       -include "$test_dir/../../../include/nolibc/nolibc.h" \
-                       -o "$initrd_dir/init" "$test_dir/init.c" \
-
-       cp "$kernel" "$initrd_dir/kernel"
+       "$CROSS_COMPILE"gcc -s -static -Os -nostdinc -nostdlib \
+                       -fno-asynchronous-unwind-tables -fno-ident \
+                       -I "$headers_dir/include" \
+                       -I "$kernel_dir/tools/include/nolibc" \
+                       -o "$tmp_dir/init" "$test_dir/init.c"
+
+       cat > "$tmp_dir/cpio_list" <<EOF
+dir /dev 0755 0 0
+dir /proc 0755 0 0
+dir /debugfs 0755 0 0
+nod /dev/console 0600 0 0 c 5 1
+file /init $tmp_dir/init 0755 0 0
+file /kernel $kernel 0644 0 0
+EOF
 
-       pushd "$initrd_dir" &>/dev/null
-       find . | cpio -H newc --create > "$initrd" 2>/dev/null
-       popd &>/dev/null
+       "$build_dir/usr/gen_init_cpio" "$tmp_dir/cpio_list" > "$initrd"
 }
 
 function run_qemu() {