This article is rather short that only mentions the script that is needed to make an iMX93EVK act as a USB mass storage device so that whenever you connect your iMX device to a windows/linux system via USB, it should get enumerated something like a usb drive.
The storage that is used in this example is mmc so the expectation is that you have inserted a mmc card in the slot.
Below is the script:-
#!/bin/sh
# This composite gadget include function:
# - MASS STORAGE
#
# Exit status is 0 for PASS, nonzero for FAIL
#
STATUS=0
# Check if there is udc available, if not, return fail
UDC_DIR=/sys/class/udc
if test "$(ls -A "$UDC_DIR")"; then
echo "The available udc:"
for entry in "$UDC_DIR"/*
do
echo "$entry"
done
else
STATUS=1
echo "No udc available!"
exit $STATUS;
fi
id=1;
udc_name=ci_hdrc.0
#back_file=/dev/mmcblk1
back_file=/tmp/lun0.img
mkdir /sys/kernel/config/usb_gadget/g$id
cd /sys/kernel/config/usb_gadget/g$id
# Use NXP VID, i.MX8QXP PID
echo 0x1fc9 > idVendor
echo 0x12cf > idProduct
mkdir strings/0x409
echo 123456ABCDEF > strings/0x409/serialnumber
echo NXP > strings/0x409/manufacturer
echo "NXP iMX USB Composite Gadget" > strings/0x409/product
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo 5 > configs/c.1/MaxPower
echo 0xc0 > configs/c.1/bmAttributes
mkdir functions/mass_storage.1
echo $back_file > functions/mass_storage.1/lun.0/file
ln -s functions/mass_storage.1 configs/c.1/
echo $udc_name > UDC
First execute the script.
After that insert the g_mass_storage module in the kernel by executing :-
modprobe g_mass_storage file=/dev/mmcblk1 removable=1
In the dmesg output, you will see something like below:-
After that you can connect a C type USB cable to the USB1 port of imx93evk and the other end to any USB ports of a laptop. The moment it is connected, you would be able to see a USB drive similar to what you get when we connect a pen-drive.
The simple following three lines work with i.MX93 evk.
modprobe usbcore
modprobe usb_f_mass_storage
modprobe g_mass_storage file=/dev/mmcblk0 removable=1
@hustdage yeah I didn't try via inserting usbcore and usb_f_mass_storage module. I will give it a try. Thanks for the info