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.
8 DIR
=/sys
/devices
/virtual
/misc
/test_firmware
13 if [ ! -d $DIR ]; then
14 echo "$0: $DIR not present"
15 echo "You must have the following enabled in your kernel:"
21 trap "test_modprobe" EXIT
23 if [ ! -d $DIR ]; then
24 modprobe test_firmware
27 # CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/
28 # These days most distros enable CONFIG_FW_LOADER_USER_HELPER but disable
29 # CONFIG_FW_LOADER_USER_HELPER_FALLBACK. We use /sys/class/firmware/ as an
30 # indicator for CONFIG_FW_LOADER_USER_HELPER.
31 HAS_FW_LOADER_USER_HELPER
=$
(if [ -d /sys
/class
/firmware
/ ]; then echo yes; else echo no
; fi)
33 if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
34 OLD_TIMEOUT
=$
(cat /sys
/class
/firmware
/timeout
)
37 OLD_FWPATH
=$
(cat /sys
/module
/firmware_class
/parameters
/path
)
40 FW
="$FWPATH/test-firmware.bin"
44 if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
45 echo "$OLD_TIMEOUT" >/sys
/class
/firmware
/timeout
47 echo -n "$OLD_PATH" >/sys
/module
/firmware_class
/parameters
/path
52 trap "test_finish" EXIT
54 if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
55 # Turn down the timeout so failures don't take so long.
56 echo 1 >/sys
/class
/firmware
/timeout
59 # Set the kernel search path.
60 echo -n "$FWPATH" >/sys
/module
/firmware_class
/parameters
/path
62 # This is an unlikely real-world firmware content. :)
63 echo "ABCD0123" >"$FW"
65 NAME
=$
(basename "$FW")
67 if printf '\000' >"$DIR"/trigger_request
2> /dev
/null
; then
68 echo "$0: empty filename should not succeed" >&2
72 if printf '\000' >"$DIR"/trigger_async_request
2> /dev
/null
; then
73 echo "$0: empty filename should not succeed (async)" >&2
77 # Request a firmware that doesn't exist, it should fail.
78 if echo -n "nope-$NAME" >"$DIR"/trigger_request
2> /dev
/null
; then
79 echo "$0: firmware shouldn't have loaded" >&2
82 if diff -q "$FW" /dev
/test_firmware
>/dev
/null
; then
83 echo "$0: firmware was not expected to match" >&2
86 if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
87 echo "$0: timeout works"
91 # This should succeed via kernel load or will fail after 1 second after
92 # being handed over to the user helper, which won't find the fw either.
93 if ! echo -n "$NAME" >"$DIR"/trigger_request
; then
94 echo "$0: could not trigger request" >&2
98 # Verify the contents are what we expect.
99 if ! diff -q "$FW" /dev
/test_firmware
>/dev
/null
; then
100 echo "$0: firmware was not loaded" >&2
103 echo "$0: filesystem loading works"
106 # Try the asynchronous version too
107 if ! echo -n "$NAME" >"$DIR"/trigger_async_request
; then
108 echo "$0: could not trigger async request" >&2
112 # Verify the contents are what we expect.
113 if ! diff -q "$FW" /dev
/test_firmware
>/dev
/null
; then
114 echo "$0: firmware was not loaded (async)" >&2
117 echo "$0: async filesystem loading works"
120 ### Batched requests tests
121 test_config_present
()
123 if [ ! -f $DIR/reset ]; then
124 echo "Configuration triggers not present, ignoring test"
133 # name: test-firmware.bin
140 release_all_firmware
()
142 echo 1 > $DIR/release_all_firmware
147 echo -n $1 > $DIR/config_name
150 config_set_sync_direct
()
152 echo 1 > $DIR/config_sync_direct
155 config_unset_sync_direct
()
157 echo 0 > $DIR/config_sync_direct
162 echo 1 > $DIR/config_send_uevent
165 config_unset_uevent
()
167 echo 0 > $DIR/config_send_uevent
170 config_trigger_sync
()
172 echo -n 1 > $DIR/trigger_batched_requests
2>/dev
/null
175 config_trigger_async
()
177 echo -n 1 > $DIR/trigger_batched_requests_async
2> /dev
/null
180 config_set_read_fw_idx
()
182 echo -n $1 > $DIR/config_read_fw_idx
2> /dev
/null
187 for i
in $
(seq 0 3); do
188 config_set_read_fw_idx
$i
189 # Verify the contents are what we expect.
190 # -Z required for now -- check for yourself, md5sum
191 # on $FW and DIR/read_firmware will yield the same. Even
192 # cmp agrees, so something is off.
193 if ! diff -q -Z "$FW" $DIR/read_firmware
2>/dev
/null
; then
194 echo "request #$i: firmware was not loaded" >&2
200 read_firmwares_expect_nofile
()
202 for i
in $
(seq 0 3); do
203 config_set_read_fw_idx
$i
204 # Ensures contents differ
205 if diff -q -Z "$FW" $DIR/read_firmware
2>/dev
/null
; then
206 echo "request $i: file was not expected to match" >&2
212 test_batched_request_firmware_nofile
()
214 echo -n "Batched request_firmware() nofile try #$1: "
216 config_set_name nope-test-firmware.bin
218 read_firmwares_expect_nofile
223 test_batched_request_firmware_direct_nofile
()
225 echo -n "Batched request_firmware_direct() nofile try #$1: "
227 config_set_name nope-test-firmware.bin
228 config_set_sync_direct
234 test_request_firmware_nowait_uevent_nofile
()
236 echo -n "Batched request_firmware_nowait(uevent=true) nofile try #$1: "
238 config_set_name nope-test-firmware.bin
244 test_wait_and_cancel_custom_load
()
246 if [ "$HAS_FW_LOADER_USER_HELPER" != "yes" ]; then
251 while [ ! -e "$DIR"/"$name"/loading
]; do
253 timeout
=$
(( $timeout - 1 ))
254 if [ "$timeout" -eq 0 ]; then
255 echo "firmware interface never appeared:" >&2
256 echo "$DIR/$name/loading" >&2
260 echo -1 >"$DIR"/"$name"/loading
263 test_request_firmware_nowait_custom_nofile
()
265 echo -n "Batched request_firmware_nowait(uevent=false) nofile try #$1: "
267 config_set_name nope-test-firmware.bin
268 config_trigger_async
&
269 test_wait_and_cancel_custom_load nope-test-firmware.bin
275 test_batched_request_firmware
()
277 echo -n "Batched request_firmware() try #$1: "
285 test_batched_request_firmware_direct
()
287 echo -n "Batched request_firmware_direct() try #$1: "
289 config_set_sync_direct
295 test_request_firmware_nowait_uevent
()
297 echo -n "Batched request_firmware_nowait(uevent=true) try #$1: "
304 test_request_firmware_nowait_custom
()
306 echo -n "Batched request_firmware_nowait(uevent=false) try #$1: "
313 # Only continue if batched request triggers are present on the
314 # test-firmware driver
317 # test with the file present
319 echo "Testing with the file present..."
320 for i
in $
(seq 1 5); do
321 test_batched_request_firmware
$i
324 for i
in $
(seq 1 5); do
325 test_batched_request_firmware_direct
$i
328 for i
in $
(seq 1 5); do
329 test_request_firmware_nowait_uevent
$i
332 for i
in $
(seq 1 5); do
333 test_request_firmware_nowait_custom
$i
336 # Test for file not found, errors are expected, the failure would be
337 # a hung task, which would require a hard reset.
339 echo "Testing with the file missing..."
340 for i
in $
(seq 1 5); do
341 test_batched_request_firmware_nofile
$i
344 for i
in $
(seq 1 5); do
345 test_batched_request_firmware_direct_nofile
$i
348 for i
in $
(seq 1 5); do
349 test_request_firmware_nowait_uevent_nofile
$i
352 for i
in $
(seq 1 5); do
353 test_request_firmware_nowait_custom_nofile
$i