#!/usr/bin/env bash # SPDX-License-Identifier: GPL-2.0-only # Modified for s390x cross-architecture support build() { local applet echo "=== S390X BASE HOOK STARTING ===" # Use s390x busybox binary if available (cross-architecture support) if [[ -f "/work/boot/busybox-s390x-static" ]]; then echo "Using s390x static busybox binary" add_file "/work/boot/busybox-s390x-static" "/usr/bin/busybox" 755 # 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" "sed" "sh" "sleep" "sort" "stat" "switch_root" "tail" "tar" "test" "touch" "tr" "true" "umount" "uname" "uniq" "wc" "which" "whoami" "xargs" ) for applet in "${busybox_applets[@]}"; do add_symlink "/usr/bin/$applet" busybox done # 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 echo "Using s390x busybox binary" add_file "/work/boot/busybox-s390x-native" "/usr/bin/busybox" 755 # 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" "sed" "sh" "sleep" "sort" "stat" "switch_root" "tail" "tar" "test" "touch" "tr" "true" "umount" "uname" "uniq" "wc" "which" "whoami" "xargs" ) for applet in "${busybox_applets[@]}"; do add_symlink "/usr/bin/$applet" busybox done # Manually add switch_root symlink (critical for root filesystem switching) add_symlink "/usr/bin/switch_root" busybox 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) # IMPORTANT: Skip mount/umount as they should come from busybox to avoid arch mismatch for binary in blkid switch_root; do 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 # Ensure switch_root symlink exists (critical for root filesystem switching) echo "Ensuring switch_root symlink..." add_symlink "/usr/bin/switch_root" busybox # Always add init files echo "Adding init files..." # 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 ===" } help() { cat <