WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Working with RasPi-0W and gadgets  (Read 283 times)

Offline kmhill

  • WikiUser
  • *
  • Posts: 33
Working with RasPi-0W and gadgets
« on: November 11, 2017, 12:15:53 PM »
Hello folks;

I'm making progress in getting USB gadgets working with the RasPi-0W  that I have. Prior discussion in the forum was a help to get me started, thanks folks. To start, it's necessary to have some modules installed. The following outlines my process that led to a .tcz file. Perhaps the .tcz could be added to the repo?

I downloaded the module file 4.9.22-piCore_modules.tar.xz from the following URL:
http://tinycorelinux.net/9.x/armv6/releases/RPi/src/kernel/

I used 7zip on Windows to uncompress the .xz file to a directory which contained the resulting  .tar file. I then moved the resulting .tar file to my RasPi-0W in a new directory /mnt/mmcblk0p2/local and untarred it there.

> tar -xf 4.9.22-piCore_modules.tar

The needed modules are the directories dwc2 and gadget. I use the find command. The gadget directory is in the same directory as dwc2

> find . -name dwc2

I followed the outline in the "Into the Core" book, chapter 14, to assemble dwc2 and gadget into a .tcz file that I gave the following name:
modules-dwc2-gadget-4.9.22-piCore.tcz.

With the .tcz file made, I used the following to verify that dwc2 and gadget load to where they belong.

> tce-load -i ./modules-dwc2-gadget-4.9.22-piCore

This is a good opportunity to update the module list and make it persistent

> sudo depmod
> filetool.sh -b

Offline kmhill

  • WikiUser
  • *
  • Posts: 33
Re: Working with RasPi-0W and gadgets
« Reply #1 on: November 11, 2017, 12:24:21 PM »
Next, as described elsewhere, copy the .tcz file to /mnt/mmblk02/tce/optional and insert into the end of the onboot.lst file the name of the .tcz file. I next rebooted to make sure that dwc2 and gadget are loaded where they belong.

Offline Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 5470
Re: Working with RasPi-0W and gadgets
« Reply #2 on: November 11, 2017, 12:46:52 PM »
Hi kmhill
The following outlines my process that led to a .tcz file. Perhaps the .tcz could be added to the repo?
Extensions are always welcome. This Wiki contains guidelines for extension submission:
http://wiki.tinycorelinux.net/wiki:creating_extensions

Offline kmhill

  • WikiUser
  • *
  • Posts: 33
Re: Working with RasPi-0W and gadgets
« Reply #3 on: November 11, 2017, 10:23:46 PM »
There's some preparation to do before inserting code into config.txt, to activate dwc2. The following note points that out.
http://forum.tinycorelinux.net/index.php/topic,20195.msg126432.html#msg126432

It's my plan to load g_multi which will mount a directory from the RasPi-0W to the host machine and also tunnel a serial COM port as well as IP through the USB cable. Regarding what to mount, the same message, above, outlines of how to make and format an image file to use. Elsewhere I've seen a partition on the SD card used. I don't know what I like better.

I'd want a file system that gets mounted to be  shared, so it's immediately accessible from both the RasPi-0W and the host machine, but I noticed some delay. I was experimenting with the image file approach and found that edits were not immediately visible on the other side. Perhaps an option can be used to remove such delay.

Also, does anyone know, for Windows to access the system on the RasPi-0W, is a Linux file system a non-choice? I'm guessing not, but I'm curious.

Thanks Rich for the reference.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9607
Re: Working with RasPi-0W and gadgets
« Reply #4 on: November 11, 2017, 11:13:50 PM »
There's a linux file system driver available for windows - ext2fsd

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 9612
Re: Working with RasPi-0W and gadgets
« Reply #5 on: November 12, 2017, 12:11:49 AM »
The module list doesn't need to be backed up, it is regenerated upon every load of an extension with modules.
The only barriers that can stop you are the ones you create yourself.

Offline kmhill

  • WikiUser
  • *
  • Posts: 33
Re: Working with RasPi-0W and gadgets
« Reply #6 on: November 13, 2017, 09:13:13 PM »
Thanks all, I have some digging to do...

Offline kmhill

  • WikiUser
  • *
  • Posts: 33
Re: Working with RasPi-0W and gadgets
« Reply #7 on: November 18, 2017, 10:08:47 PM »
Hi folks, I found a warning in the mass-storage.txt gadget notes posted on kernel.org
https://www.kernel.org/doc/Documentation/usb/mass-storage.txt

Quote
*BEWARE* that if a file is used as a backing storage, it may not be modified by any other process.  This is because the host assumes the data does not change without its knowledge.  It may be read, but (if the logical unit is writable) due to buffering on the host side, the contents are not well defined.

I found another similar warning at linux-usb.org
http://www.linux-usb.org/gadget/file_storage.html

Quote
AN IMPORTANT WARNING! While MSG is running and the gadget is connected to a USB host, that USB host will use the backing storage as a private disk drive. It will not expect to see any changes in the backing storage other than the ones it makes. Extraneous changes are liable to corrupt the filesystem and may even crash the host. Only one system (normally, the USB host) may write to the backing storage, and if one system is writing that data, no other should be reading it. The only safe way to share the backing storage between the host and the gadget's operating system at the same time is to make it read-only on both sides.

Please, can anyone share any comments?
Krista

Offline kmhill

  • WikiUser
  • *
  • Posts: 33
sshfs
« Reply #8 on: November 19, 2017, 02:29:06 PM »
Hello folks, regarding files, I think I have a plan-B. Some time ago I came across sshfs which makes use of ssh programs to provide a sense or appearance of having a remote file system mounted. I just did a simple experiment between two machines running Ubuntu. So far things look good.

So now I'm back to IP and USB.

Krista

Offline kmhill

  • WikiUser
  • *
  • Posts: 33
Re: Working with RasPi-0W and gadgets
« Reply #9 on: November 19, 2017, 07:13:03 PM »
Okay, so far I have the RasPi-0W system configured as described above. I'm able to make use of the virtual COM port and see a file system being mounted on my Win7 machine. The problem is that in using g_multi I'm not getting IP communications.

Once the RasPi-0W system is booted I've been using the CLI. The file store.bin is an image file. The serialtty_GS0.sh file is modified, as the virtual COM port shows up as /dev/ttyGS0
http://forum.tinycorelinux.net/index.php/topic,20195.msg126432.html#msg126432

> sudo modprobe dwc2
> sudo modprobe g_multi file=/home/tc/store.bin
> sudo sh /opt/serialtty_GS0.sh &
> sudo /sbin/ifconfig usb0 192.168.100.2 up
> sudo /usr/local/etc/init.d/openssh start

In the Win7 network and sharing center I can see a local area network gadget, but I'm not able to ping from either side. Any input will be appreciated.

The following is some background... To get Win7 to recognize the virtual COM port and virtual ethernet, I downloaded the following .inf files from the following URL. Later, when Win7 tries to make connections, go to the device manager and update the respective drivers. Be careful to not let your browser append a .txt extension.
https://www.kernel.org/doc/Documentation/usb/

  • linux-cdc-acm.inf
  • linux.inf

To communicate with the RasPi-0W I've been using USB-COM port adapter to connect to GPIO pins. I've been using TeraTerm on Win7.

In the RasPi-0W I had inserted into the last line of config.txt

dtoverlay=dwc2

Thanks in advance,
Krista