Anders Roxell | 2294035 | 2024-09-11 11:30:58 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # Copyright (C) 2024 Linaro Ltd. |
| 4 | |
| 5 | # shellcheck disable=SC1091 |
| 6 | . ../../lib/sh-test-lib |
| 7 | OUTPUT="$(pwd)/output" |
| 8 | RESULT_FILE="${OUTPUT}/result.txt" |
| 9 | export RESULT_FILE |
| 10 | |
| 11 | ! check_root && error_msg "This script must be run as root" |
| 12 | create_out_dir "${OUTPUT}" |
| 13 | info_msg "Output directory: ${OUTPUT}" |
| 14 | |
| 15 | # CONFIG_USB_GADGET=y |
| 16 | # CONFIG_USB_CONFIGFS=y |
| 17 | # CONFIG_USB_DUMMY_HCD=m |
| 18 | # CONFIG_USB_F_MASS_STORAGE=m |
| 19 | |
| 20 | eval "modprobe dummy_hcd" |
| 21 | check_return "modprobe dummy_hcd" |
| 22 | |
| 23 | #Setup USB Gadget in ConfigFS |
| 24 | mkdir /sys/kernel/config/usb_gadget/g1 |
| 25 | cd /sys/kernel/config/usb_gadget/g1 || exit |
| 26 | echo 0x1d6b > idVendor # Linux Foundation |
| 27 | echo 0x0104 > idProduct # Multifunction Composite Gadget |
| 28 | mkdir strings/0x409 |
| 29 | echo "0123456789" > strings/0x409/serialnumber |
| 30 | echo "My Gadget" > strings/0x409/manufacturer |
| 31 | echo "Test Device" > strings/0x409/product |
| 32 | |
| 33 | eval "dd bs=1M count=16 if=/dev/zero of=/tmp/lun0.img" |
| 34 | check_return "dd bs=1M count=16 if=/dev/zero of=/tmp/lun0.img" |
| 35 | |
| 36 | # Create function and configure endpoint (e.g., mass storage, serial) |
| 37 | mkdir -p functions/mass_storage.0 |
| 38 | |
| 39 | eval "echo /tmp/lun0.img > functions/mass_storage.0/lun.0/file" |
| 40 | check_return "echo /tmp/lun0.img > functions/mass_storage.0/lun.0/file" |
| 41 | |
| 42 | # Bind the gadget to the virtual controller |
| 43 | mkdir configs/c.1 |
| 44 | ln -s functions/mass_storage.0 configs/c.1/ |
| 45 | eval "echo dummy_udc.0 > UDC" |
| 46 | check_return "echo dummy_udc.0 > UDC" |
| 47 | cd - || exit |