1#!/bin/sh 2# This validates that the kernel will load firmware out of its list of 3# firmware locations on disk. Since the user helper does similar work, 4# we reset the custom load directory to a location the user helper doesn't 5# know so we can be sure we're not accidentally testing the user helper. 6set -e 7 8modprobe test_firmware 9 10DIR=/sys/devices/virtual/misc/test_firmware 11 12OLD_TIMEOUT=$(cat /sys/class/firmware/timeout) 13OLD_FWPATH=$(cat /sys/module/firmware_class/parameters/path) 14 15FWPATH=$(mktemp -d) 16FW="$FWPATH/test-firmware.bin" 17 18test_finish() 19{ 20 echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout 21 echo -n "$OLD_PATH" >/sys/module/firmware_class/parameters/path 22 rm -f "$FW" 23 rmdir "$FWPATH" 24} 25 26trap "test_finish" EXIT 27 28# Turn down the timeout so failures don't take so long. 29echo 1 >/sys/class/firmware/timeout 30# Set the kernel search path. 31echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path 32 33# This is an unlikely real-world firmware content. :) 34echo "ABCD0123" >"$FW" 35 36NAME=$(basename "$FW") 37 38# Request a firmware that doesn't exist, it should fail. 39echo -n "nope-$NAME" >"$DIR"/trigger_request 40if diff -q "$FW" /dev/test_firmware >/dev/null ; then 41 echo "$0: firmware was not expected to match" >&2 42 exit 1 43else 44 echo "$0: timeout works" 45fi 46 47# This should succeed via kernel load or will fail after 1 second after 48# being handed over to the user helper, which won't find the fw either. 49if ! echo -n "$NAME" >"$DIR"/trigger_request ; then 50 echo "$0: could not trigger request" >&2 51 exit 1 52fi 53 54# Verify the contents are what we expect. 55if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then 56 echo "$0: firmware was not loaded" >&2 57 exit 1 58else 59 echo "$0: filesystem loading works" 60fi 61 62exit 0 63