WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline kmhill

  • Jr. Member
  • **
  • Posts: 64
Working with RasPi-0W and gadgets
« on: November 11, 2017, 03: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

  • Jr. Member
  • **
  • Posts: 64
Re: Working with RasPi-0W and gadgets
« Reply #1 on: November 11, 2017, 03: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

  • Administrator
  • Hero Member
  • *****
  • Posts: 11591
Re: Working with RasPi-0W and gadgets
« Reply #2 on: November 11, 2017, 03: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

  • Jr. Member
  • **
  • Posts: 64
Re: Working with RasPi-0W and gadgets
« Reply #3 on: November 12, 2017, 01:23:46 AM »
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: 14799
Re: Working with RasPi-0W and gadgets
« Reply #4 on: November 12, 2017, 02:13:50 AM »
There's a linux file system driver available for windows - ext2fsd

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Working with RasPi-0W and gadgets
« Reply #5 on: November 12, 2017, 03: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

  • Jr. Member
  • **
  • Posts: 64
Re: Working with RasPi-0W and gadgets
« Reply #6 on: November 14, 2017, 12:13:13 AM »
Thanks all, I have some digging to do...

Offline kmhill

  • Jr. Member
  • **
  • Posts: 64
Re: Working with RasPi-0W and gadgets
« Reply #7 on: November 19, 2017, 01:08:47 AM »
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

  • Jr. Member
  • **
  • Posts: 64
sshfs
« Reply #8 on: November 19, 2017, 05: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

  • Jr. Member
  • **
  • Posts: 64
Re: Working with RasPi-0W and gadgets
« Reply #9 on: November 19, 2017, 10: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


Offline kmhill

  • Jr. Member
  • **
  • Posts: 64
Stuck with ethernet gadgets
« Reply #10 on: November 24, 2017, 04:30:00 PM »
Hi folks, I'm working on g_ether and I'm stuck... I've tried g_multi too and that's no better.

As far as I can see, I'm following the proverbial plan.
  • I have  USB-serial adapter providing communications with my RasPi-0W
  • I have the dwc2 and gadget modules in a .tcz file
  • I have dwc2 enabled in config.txt, in bootlocal.sh I'm using modprobe to load dwc2
At the CLI I load g_ether
  > sudo modprobe g_ether

A call to ifconfig doesn't show the usb0 device yet. So I call ifconfig as follows:
  > sudo ifconfig usb0 192.168.4.2

At this point the usb host shows a new network connection, but it's not reachable.  Back i the host machine:

  > ping 192.168.4.2
  > PING 192.168.4.2 (192.168.4.2) 56(84) bytes of data.
  ^C
  --- 192.168.4.2 ping statistics ---
  4 packets transmitted, 0 received, 100% packet loss, time 2999ms

Any ideas will be appreciated, Krista

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11591
Re: Working with RasPi-0W and gadgets
« Reply #11 on: November 24, 2017, 07:20:44 PM »
Hi kmhill
Quote
sudo ifconfig usb0 192.168.4.2
Shouldn't that be:
Code: [Select]
sudo ifconfig usb0 192.168.4.2 up

Offline kmhill

  • Jr. Member
  • **
  • Posts: 64
Re: Working with RasPi-0W and gadgets
« Reply #12 on: November 24, 2017, 07:43:03 PM »
Thanks Rich, I've seen the command with and without the keyword 'up'. I tried it both ways and found a man page that says that when an IP address is provided that the keyword 'up' is "implicitly specified."

At the moment Win7 network diagnose says that the local area connection doesn't have a valid IP configuration.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Working with RasPi-0W and gadgets
« Reply #13 on: November 25, 2017, 03:46:43 AM »
Did you give it a valid IP configuration? You didn't mention setting up DHCP anywhere, and I think even with usb connections you need to give it the network details. Otherwise it may think that IP is in your local LAN, and the ping goes out the wrong network card.
The only barriers that can stop you are the ones you create yourself.

Offline kmhill

  • Jr. Member
  • **
  • Posts: 64
Re: Working with RasPi-0W and gadgets
« Reply #14 on: November 25, 2017, 01:40:18 PM »
Hi curaga, thanks for your note. By 'it', do you mean the RasPi-0w board?

I don't recall seeing anything in any notes about setting up DHCP. At home I have a DSL wifi/router. I've connected a USB-ethernet dongle to the RasPi-0w with good results, but not the usb-gadget route. At home for the USB host I alternate between using a Win7 netbook as well as a Ubuntu laptop running version 16.04. I've also experimented at my work place, where I have similar systems, with the same results.

I'm at home now and see that the netbook and laptop each have a 192.168.1.xx IP address but that the virtual USB adapter on the netbook has been given 169.254..52.20 as it's IP address.

Side comment 1, I've seen in some notes a reference to a configuration file that I think is used in place of parameters at the command line. I'll have to look up some notes.

Side comment 2, in looking at the dhcp.sh script in TinyCore, I see that it recognizes ethn ports but not usbn named ports. I'm not sure what to make of that.

Krista