Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: kmhill on November 11, 2017, 12:15:53 PM

Title: Working with RasPi-0W and gadgets
Post by: kmhill 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
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill 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.
Title: Re: Working with RasPi-0W and gadgets
Post by: Rich 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
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill 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 (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.
Title: Re: Working with RasPi-0W and gadgets
Post by: Juanito on November 11, 2017, 11:13:50 PM
There's a linux file system driver available for windows - ext2fsd
Title: Re: Working with RasPi-0W and gadgets
Post by: curaga 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.
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on November 13, 2017, 09:13:13 PM
Thanks all, I have some digging to do...
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill 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
Title: sshfs
Post by: kmhill 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
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill 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 (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/ (https://www.kernel.org/doc/Documentation/usb/)


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

Title: Stuck with ethernet gadgets
Post by: kmhill on November 24, 2017, 01: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.
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
Title: Re: Working with RasPi-0W and gadgets
Post by: Rich on November 24, 2017, 04: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
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on November 24, 2017, 04: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.
Title: Re: Working with RasPi-0W and gadgets
Post by: curaga on November 25, 2017, 12: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.
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on November 25, 2017, 10:40:18 AM
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
Title: Re: Working with RasPi-0W and gadgets
Post by: Rich on November 25, 2017, 11:32:51 AM
Hi kmhill
This is the basic script used by Tinycore to create a static IP:
Code: [Select]
#!/bin/sh
pkill udhcpc
ifconfig eth0 192.168.1.30 netmask 255.255.255.0 broadcast 192.168.1.255 up
route add default gw 192.168.1.1
echo nameserver 68.237.161.12 > /etc/resolv.conf
echo nameserver 71.243.0.12 >> /etc/resolv.conf
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on November 25, 2017, 01:10:09 PM
Thanks Rich for the reference. I saved that as startusb.sh, then changed the reference to eth0 to usb0. In trying to run the code I received:

> sudo sh startusb.sh
route: SIOCADDRT: File exists

So I commented out the call to route. I'm not sure what's supposed to happen at this point that might be different.
Title: Re: Working with RasPi-0W and gadgets
Post by: curaga on November 26, 2017, 03:08:16 AM
You said you gave the raspi the IP address 192.168.4.2. You need to give the host an IP address on the same network, on the host's usb interface, so that they can communicate.
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on November 26, 2017, 09:53:53 PM
Thanks for your note curaga. I think I missed out on how to do that... On the Win7 netbook I did find a setting for the virtual adapter IP address, but despite that the results were the same. I'll try again with another Win7 machine. Not sure how to do that on Ubuntu Linux. Any pointers, please?
Title: Re: Working with RasPi-0W and gadgets
Post by: Rich on November 27, 2017, 05:29:34 AM
Hi kmhill
If the machines you are using to communicate with the PI have a 192.168.1.xx IP address then the PI should also have a 192.168.1.xx
IP address.

> sudo sh startusb.sh
route: SIOCADDRT: File exists
That's harmless. It means that routing information already exists.

Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on November 27, 2017, 03:41:26 PM
Hi Rich;

Here's a puzzle, I've connected the Pi to a Win7 machine, I've gone into the network and sharing center and assigned the virtual adapter the IP value 192.168.1.20, then when I open a Win7 CLI and try to ping that IP address, ping says the network is not reachable. Then for the status I see that the virtual adapter has an IP address like 169.254.130.13. Ping does respond with the 169.254 address.

I'm at work, the IP address for the Win7 ethernet adapter looks like 137.49.xx.xx, so I don't know where the 169.254 address came from...

Krista

Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on November 27, 2017, 03:56:33 PM
Just came across a reference to a Win feature called "Automatic Private IP Addressing," or APIPA... One site says that having a 169.254.x.x IP address, "is almost as good as having no IP address."
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on November 27, 2017, 05:31:26 PM
Just made some sense of Win7 Internet Connection Sharing (ICS). The help page describes it as being similar to IP masquerading, in that one machine called the ICS host provides a connection to the Internet and a second network adapter on the host serves a private network.

In this case the USB host machine serves as the ICS host and the virtual adapter connects to the private network, which is just point-to-point to the RasPi-0W. The help page say that there should not be a DHCP server, which is fine in this case.

I don't fully understand things and I'm a bit suspicious, but so far so good...

Krista
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on November 27, 2017, 06:24:12 PM
Just to add, by the prior comment, "there should not be a DHCP server" I meant to say is that there should not be a DHCP server inside the private network.
Title: Re: Working with RasPi-0W and gadgets
Post by: kmhill on December 03, 2017, 07:07:40 PM
Hello folks, I'm just checking in.

I'm finding that setting up a connection between Win7 and a RasPi-0W using Internet Connection Sharing is fairly solid. For the USB host I'm using the default IP 192.168.137.1 with netmask 255.255.255.0 and assign a static IP address 192.168.137.2 to the RasPi-0W.

I suspect that having a randomly selected MAC address is causing some issues as the connection with the ethernet LAN and rest of the world is somewhat iffy. When the connection is there, the RasPi-0W can access the TinyCore repository, which is nice. Quite often Win7 makes a new network, I'm not sure what that's about. Two times I noticed that if I unshare the ethernet adapter and then reshare it, the external connection is restored.

Please, any ideas will be appreciated.
Krista