Tiny Core Base > Raspberry Pi
USB gadget kernel module with RPi zero
pieric:
Hi all,
I have a problem getting mass storage mode to work. I went for putting all required kernel modules in extensions (dwc2 & gadget) and modprobing them upon boot.
As far as I can tell all dependencies are present and g_ether works perfectly fine.
However if I run:
--- Code: ---sudo dd if=/dev/zero of=/tmp/usb.img bs=1M count=10 #Without any fs, just for testing
sudo modprobe g_mass_storage file=/tmp/usb.img stall=0
--- End code ---
I get following error:
--- Code: ---modprobe: can't load module g_mass_storage (kernel.tclocal(drivers/usb/gadget/legacy/g_mass_storage.ko): Invalid argument
--- End code ---
Same with g_multi. Also with params "removable=1", "ro=0" I get above error. dmesg shows
--- Code: ---LUN: removable file: (no medium)
no file given for LUN0
g_mass_storage 20980000.usb: failed to start g_mass_storage: -22
--- End code ---
Any hints apreciated.
I run latest piCore release 12.0, untouched kernel on a pi zero, non W.
BR
Eric
pieric:
Hi,
solved. Needed to put required parameters in /etc/modprobe.d/g_mass_storage.conf. Did that by:
--- Code: ---sudo mkdir /etc/modprobe.d
echo "options g_mass_storage file=/mnt/mmcblk0p2/piusb.img removable=1 ro=0 stall=0 iSerialNumber=123456"
--- End code ---
This is what I did to get it running on piZero with piCore12.0*:
* Extensions squashfs-tools and optionally nano need to be in place. I loaded them on demand.
* Existing wifi is an advantage - otherwise detour by card reader/pendrive
Enable dwc2 overlay
--- Code: ---sudo mount /dev/mmcblk0p1
sudo echo dtoverlay=dwc2 >> /mnt/mmcblk0p1/config.txt #In my case the very end of the file was section [all].
sudo umount /dev/mmcblk0p1
--- End code ---
Create module extensions and make them load at start
--- Code: ---mkdir -p /tmp/dwc2/package/usr/local/lib/modules/5.4.51-piCore/kernel/drivers/usb
mkdir -p /tmp/gadget/package/usr/local/lib/modules/5.4.51-piCore/kernel/drivers/usb
cd /tmp
wget http://tinycorelinux.net/12.x/armv6/releases/RPi/src/kernel/modules-5.4.51-piCore.tar.xz
tar xf modules-5.4.51-piCore.tar.xz
cp -a lib/modules/5.4.51-piCore/kernel/drivers/usb/dwc2 /tmp/dwc2/package/usr/local/lib/modules/5.4.51-piCore/kernel/drivers/usb
cp -a lib/modules/5.4.51-piCore/kernel/drivers/usb/gadget /tmp/gadget/package/usr/local/lib/modules/5.4.51-piCore/kernel/drivers/usb
mksquashfs /tmp/dwc2/package/ /tmp/dwc2-5.4.51-piCore.tcz
mksquashfs /tmp/gadget/package /tmp/gadget-5.4.51-piCore.tcz
cp /tmp/dwc2-5.4.51-piCore.tcz /mnt/mmcblk0p2/tce/optional/
cp /tmp/gadget-5.4.51-piCore.tcz /mnt/mmcblk0p2/tce/optional/
chmod 664 /mnt/mmcblk0p2/tce/optional/dwc2-5.4.51-piCore.tcz
chmod 664 /mnt/mmcblk0p2/tce/optional/gadget-5.4.51-piCore.tcz
sudo echo "dwc2-5.4.51-piCore.tcz" >> /mnt/mmcblk0p2/tce/onboot.lst
sudo echo "gadget-5.4.51-piCore.tcz" >> /mnt/mmcblk0p2/tce/onboot.lst
--- End code ---
As I understand, neither is it required to add modules.dep, nor is it needed to run depmod -a, since tinycore does that automatically when kernel modules are included in an extension.
Create container file for a quick test
--- Code: ---sudo dd if=/dev/zero of=/mnt/mmcblk0p2/piusb.img bs=1M count=1024 #Create container of file 1GB size
--- End code ---
Modify bootlocal.sh to load kernel modules on start (Did that with nano)
Added follwoing in "Load modules..." section, where an out-commented "/sbin/modprobe i2c-dev" used to be
--- Code: ---/sbin/modprobe dwc2 #Load dwc2 module
sleep 5 #Make sure enumeration on host works properly
--- End code ---
Added follwoing below for g_ether mode*
--- Code: ---/sbin/modprobe g_ether stall=0 #Load g_ether module which will be RNDIS by default
/sbin/ifconfig usb0 192.168.100.2 up #Bring up usb0 ethernet device and assign fixed IP
--- End code ---
Added follwoing below for g_mass_storage mode*
--- Code: ---sudo mkdir /etc/modprobe.d #Create folder for module configs
#Create config for g_mass_storage to shair container file in read+write mode
echo "options g_mass_storage file=/mnt/mmcblk0p2/piusb.img removable=1 ro=0 stall=0 iSerialNumber=123456" > /etc/modprobe.d/g_mass_storage.conf
/sbin/modprobe g_mass_storage #Load g_mass_storage module
--- End code ---
*Only load either g_ether or g_mass_storage.
Commit changes and reboot
--- Code: ---filetool.sh -b
sudo reboot
--- End code ---
ladnar:
pieric newbie puts my newbie to shame. I'll have to reasd him again to try to absorb some of it. Two months ago I found some random bits of advice on mass storage mode, but clearly not though to help. Glad he fixed it himself.
Anyway, its been two months since I flogged this particular pi horse, and I am ready to give it another try. October 4th Rich gave me the answer, but I made the mistake of trying to extend my mmcblkp02 partition, and some error got me stuck with a larger partition but a filesytem that didn't expand to fill it. At least, I think that is what the error said / meant.
I have new microSD cards, and I will just start fresh. If anybody knows why I would get that error, let me know, becuase I am about to try the "readme" advice again, on a fresh card with a fresh OS, on a pi zero.
"1) Start fdisk partitioning tool as root:
sudo fdisk -u /dev/mmcblk0
Now list partitions with 'p' command and write down the starting and
ending sectors of the second partition.
2) Delete second partition with 'd' than recreate it with 'n' command.
Use the same starting sector as deleted had and provide end
sectore or size greater than deleted had having enough free space
for Mounted Mode. When finished, exit fdisk with 'w' command. Now
partition size increased but file system size is not yet changed.
3) Reboot piCore. It is necessary to make Kernel aware of changes.
4) After reboot expand file system to the new partition boundaries with
typing the following command as root:
resize2fs /dev/mmcblk0p2
Now you are ready to use the bigger partition."
If I recall correctly, the "resize2fs" command spit an error at me. I will try again tonight, and do as Rich said in his post, to get my USB gadget working and get the modules automatically loaded on each fresh boot. Probably get TC.tcz GUI extension put on there too. And of course, my hobbyhorse of the MSSAID, artifical intelligence folders, for my raspbery pi cluster computer.
creitzel:
--- Quote from: pieric on October 22, 2020, 04:28:56 PM ---Hi,
solved. Needed to put required parameters in /etc/modprobe.d/g_mass_storage.conf.
...
--- End quote ---
Hi pieric,
I'm trying to replicate your steps on piCore 13.1. Most of your steps seem to have worked for me, except for loading the dwc2 module, and the ifconfig step.
when I reboot, dwc2 doesn't get loaded, and if I try to do "modprobe dwc2" myself from a command line, I get:
--- Code: ---modprobe: can't load module dwc2 (kernel.tclocal/drivers/usb/dwc2/dwc2.ko): unknown symbol in module, or unknown parameter
--- End code ---
I've checked, and the module is being loaded into the filesystem where it should, based on my tcz, so the os can find it. Do you know if anything has changed in this module in 13.1?
The ifconfig line is failing with
--- Code: ---ifconfig: SIOCSIFADDR: No such device
--- End code ---
I'm assuming this is happening because the dwc2 module isn't being loaded. Presumably, it creates the "usb0" device?
Oh, and one last thing, when I reboot with these changes, my usb keyboard that is plugged into a usb hub on the pi (wired via gpio), no longer seems to work. Is this to be expected?
I'm not quite sure where to go from here.
Thanks in advance for any help you can give me,
Chris
Rich:
Hi creitzel
I think you may be missing:
--- Code: ---kernel/drivers/usb/gadget/udc/udc-core.ko
--- End code ---
What does this return:
--- Code: ---modinfo dwc2
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version