archlinux-s390x/patches/mkinitcpio-s390x-base-hook.patch

141 lines
5.8 KiB
Diff
Raw Normal View History

2025-06-01 08:31:36 -04:00
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-2.0-only
# Modified for s390x cross-architecture support
build() {
local applet
2025-06-02 09:21:38 -04:00
echo "=== S390X BASE HOOK STARTING ==="
2025-06-01 08:31:36 -04:00
# Use s390x busybox binary if available (cross-architecture support)
2025-06-02 09:21:38 -04:00
if [[ -f "/work/boot/busybox-s390x-static" ]]; then
2025-06-01 08:31:36 -04:00
echo "Using s390x static busybox binary"
2025-06-02 09:21:38 -04:00
add_file "/work/boot/busybox-s390x-static" "/usr/bin/busybox" 755
2025-06-01 08:31:36 -04:00
# Create symlinks for busybox applets (using a known list since we can't execute cross-arch binary)
local busybox_applets=(
"[" "[[" "ash" "awk" "basename" "cat" "chgrp" "chmod" "chown" "cp" "cut"
"date" "dd" "df" "dirname" "dmesg" "du" "echo" "env" "expr" "false"
"find" "grep" "head" "hostname" "id" "kill" "ln" "ls" "mkdir" "mknod"
"mktemp" "mount" "mv" "printf" "ps" "pwd" "readlink" "rm" "rmdir"
2025-06-02 09:21:38 -04:00
"sed" "sh" "sleep" "sort" "stat" "switch_root" "tail" "tar" "test" "touch" "tr"
2025-06-01 08:31:36 -04:00
"true" "umount" "uname" "uniq" "wc" "which" "whoami" "xargs"
)
for applet in "${busybox_applets[@]}"; do
add_symlink "/usr/bin/$applet" busybox
done
2025-06-02 09:21:38 -04:00
# Manually add switch_root symlink (critical for root filesystem switching)
add_symlink "/usr/bin/switch_root" busybox
elif [[ -f "/work/boot/busybox-s390x-native" ]]; then
2025-06-01 08:31:36 -04:00
echo "Using s390x busybox binary"
2025-06-02 09:21:38 -04:00
add_file "/work/boot/busybox-s390x-native" "/usr/bin/busybox" 755
2025-06-01 08:31:36 -04:00
# Create symlinks for busybox applets (using a known list since we can't execute cross-arch binary)
local busybox_applets=(
"[" "[[" "ash" "awk" "basename" "cat" "chgrp" "chmod" "chown" "cp" "cut"
"date" "dd" "df" "dirname" "dmesg" "du" "echo" "env" "expr" "false"
"find" "grep" "head" "hostname" "id" "kill" "ln" "ls" "mkdir" "mknod"
"mktemp" "mount" "mv" "printf" "ps" "pwd" "readlink" "rm" "rmdir"
2025-06-02 09:21:38 -04:00
"sed" "sh" "sleep" "sort" "stat" "switch_root" "tail" "tar" "test" "touch" "tr"
2025-06-01 08:31:36 -04:00
"true" "umount" "uname" "uniq" "wc" "which" "whoami" "xargs"
)
for applet in "${busybox_applets[@]}"; do
add_symlink "/usr/bin/$applet" busybox
done
2025-06-02 09:21:38 -04:00
# Manually add switch_root symlink (critical for root filesystem switching)
add_symlink "/usr/bin/switch_root" busybox
2025-06-01 08:31:36 -04:00
else
echo "Warning: s390x busybox not found, using system busybox (may cause architecture mismatch)"
# Try to find busybox in various locations
if [[ -f /usr/lib/initcpio/busybox ]]; then
add_binary /usr/lib/initcpio/busybox /bin/busybox
elif [[ -f /usr/bin/busybox ]]; then
add_binary /usr/bin/busybox /bin/busybox
elif [[ -f /bin/busybox ]]; then
add_binary /bin/busybox /bin/busybox
else
echo "ERROR: No busybox binary found!"
return 1
fi
# Get applet list from the binary we found
for applet in $(busybox --list 2>/dev/null || echo "sh ash"); do
add_symlink "/usr/bin/$applet" busybox
done
fi
# Add kmod with applet symlinks (if available)
if type -P kmod >/dev/null 2>&1; then
echo "Adding kmod utilities..."
add_binary kmod
for applet in {dep,ins,rm,ls}mod mod{probe,info}; do
add_symlink "/usr/bin/$applet" kmod
done
else
echo "Warning: kmod not found, module utilities will not be available"
fi
# Check for additional utilities (may not be available in cross-compile environment)
2025-06-02 09:21:38 -04:00
# IMPORTANT: Skip mount/umount as they should come from busybox to avoid arch mismatch
for binary in blkid switch_root; do
2025-06-01 08:31:36 -04:00
if type -P "$binary" >/dev/null 2>&1; then
echo "Adding $binary"
add_binary "$binary"
else
echo "Warning: $binary not found, skipping (functionality may be limited)"
fi
done
2025-06-02 09:21:38 -04:00
# Ensure switch_root symlink exists (critical for root filesystem switching)
echo "Ensuring switch_root symlink..."
add_symlink "/usr/bin/switch_root" busybox
2025-06-01 08:31:36 -04:00
# Always add init files
echo "Adding init files..."
2025-06-02 09:21:38 -04:00
# Check both lib and lib64 locations for init files
if [[ -f /usr/lib/initcpio/init_functions ]]; then
add_file "/usr/lib/initcpio/init_functions" "/init_functions" 644
elif [[ -f /usr/lib64/initcpio/init_functions ]]; then
add_file "/usr/lib64/initcpio/init_functions" "/init_functions" 644
else
echo "ERROR: init_functions not found in /usr/lib/initcpio or /usr/lib64/initcpio"
return 1
fi
# Use standard Arch init but patch the switch_root call
echo "Patching standard init script for s390x..."
# Copy the standard init and patch it
if [[ -f /usr/lib/initcpio/init ]]; then
cp /usr/lib/initcpio/init /tmp/s390x_init
elif [[ -f /usr/lib64/initcpio/init ]]; then
cp /usr/lib64/initcpio/init /tmp/s390x_init
else
echo "ERROR: Standard init not found"
return 1
fi
# Patch the switch_root line to use busybox
sed -i 's|/usr/bin/switch_root|/usr/bin/busybox switch_root|g' /tmp/s390x_init
# Add debug break when udevadm fails - use a more aggressive replacement
sed -i 's|udevadm settle|echo ":: udevadm not available, dropping to shell"; /bin/sh|g' /tmp/s390x_init
# Add the patched init script to the initramfs
add_file "/tmp/s390x_init" "/init" 755
echo "✓ Standard Arch init patched for s390x (switch_root -> busybox switch_root)"
echo "=== S390X BASE HOOK COMPLETED ==="
2025-06-01 08:31:36 -04:00
}
help() {
cat <<HELPEOF
This hook provides crucial runtime necessities for booting. This is a modified
version with s390x cross-architecture support. DO NOT remove this hook unless
you know what you're doing.
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et: