fw_filesystem.sh 2.2 KB

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