fw_filesystem.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.
  6. set -e
  7. modprobe test_firmware
  8. DIR=/sys/devices/virtual/misc/test_firmware
  9. OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
  10. OLD_FWPATH=$(cat /sys/module/firmware_class/parameters/path)
  11. FWPATH=$(mktemp -d)
  12. FW="$FWPATH/test-firmware.bin"
  13. test_finish()
  14. {
  15. echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
  16. echo -n "$OLD_PATH" >/sys/module/firmware_class/parameters/path
  17. rm -f "$FW"
  18. rmdir "$FWPATH"
  19. }
  20. trap "test_finish" EXIT
  21. # Turn down the timeout so failures don't take so long.
  22. echo 1 >/sys/class/firmware/timeout
  23. # Set the kernel search path.
  24. echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path
  25. # This is an unlikely real-world firmware content. :)
  26. echo "ABCD0123" >"$FW"
  27. NAME=$(basename "$FW")
  28. # Request a firmware that doesn't exist, it should fail.
  29. echo -n "nope-$NAME" >"$DIR"/trigger_request
  30. if diff -q "$FW" /dev/test_firmware >/dev/null ; then
  31. echo "$0: firmware was not expected to match" >&2
  32. exit 1
  33. else
  34. echo "$0: timeout works"
  35. fi
  36. # This should succeed via kernel load or will fail after 1 second after
  37. # being handed over to the user helper, which won't find the fw either.
  38. if ! echo -n "$NAME" >"$DIR"/trigger_request ; then
  39. echo "$0: could not trigger request" >&2
  40. exit 1
  41. fi
  42. # Verify the contents are what we expect.
  43. if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then
  44. echo "$0: firmware was not loaded" >&2
  45. exit 1
  46. else
  47. echo "$0: filesystem loading works"
  48. fi
  49. exit 0