Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPi zero Support for USB Gadget Mode (pi shows up as keyboard, disk, net, camera etc) #1212

Closed
hh opened this issue Dec 3, 2015 · 90 comments

Comments

@hh
Copy link

hh commented Dec 3, 2015

Having a $5 usb gadget that could function as a combination of anything in https://github.com/torvalds/linux/tree/master/drivers/usb/gadget/function would be pretty grand.

Think about your phone, how it works to connect a micro-B to charge and connect to it as a gadget to your computer, then when you connect a micro-A cable you plug mice, keyboard, and thumb drives into your phone.

As a usb host, you can plug a phone into it (just like you do your dekstop or laptop) and flash it. Format a usb drive, or bootstrap embedded devices like intel edison.

As a usb gadet, you can plug it into a computer and have it show up as a usb keyboard, disk, network, and other interesting things. (send some keystrokes to hit F12, and boot to a usb installation disk).

I'm looking to see if we can't get the RPi zero to function as both.

It looks like it may have worked at one point: #881 (comment)

I just wanted to gauge the interest.

@imbens
Copy link

imbens commented Dec 4, 2015

That would also allow you to code on the Pi Zero with only a single cable (for power and network) to a PC.

@harjoc
Copy link

harjoc commented Dec 4, 2015

Apparently the data pins on the port used for power aren't connnected to the SoC:

http://raspberrypi.stackexchange.com/questions/8587/can-you-transfer-data-through-the-microusb

@hh
Copy link
Author

hh commented Dec 5, 2015

I'm not talking about using the port that is for power only.

This is specifically for the second usb micro port on the RPi zero that does have the data pins connected (you usually use an OTG cable to connect to it in host mode). I'm wanting to use that same port in gadget mode.

@hh
Copy link
Author

hh commented Dec 5, 2015

It looks like the RPi can be powered over that second port (the one we want to use in gadget mode). So @imbens idea for allowing us to code with a single cable seems valid.

@hh
Copy link
Author

hh commented Dec 5, 2015

For most OTG supported ports, it depends on what you plug into it that decides if the port is in host mode or gadget mode. We just need to get confirmation that the RPi zero port is wired the same way for the port that has it's usb data pins connected (not the one dedicated to power).

"A device with a micro-A plug inserted becomes an OTG A-device, and a device with a micro-B plug inserted becomes a B-device. The type of plug inserted is detected by the state of the pin ID ."

The RPi zero USB_OTGID pin should be grounded by the cable when using a micro-A / OTG cable and is hopefully left floating otherwise. That way we can the more common micro-B cable for providing power and connecting the usb data pins to a computer.

Here is a RPi zero mechanical diagram, that shows the two usb micro ports for the RPi zero in bottom right:

image

I couldn't find wiring schematics for RPi zero, so I pulled these from the RPi A

This is the usb micro port used for power: (no data pins)

image

This is the RPi-A USB-A port (note that the USB_OTGID pin on the usb controller is grounded). On the RPi zero, this connector is a micro-b port, and shouldn't have the USB_OTGID pin grounded, as that is usually done by the cable to distinguish between OTG/Host mode and usb gadget mode.

image

I suspect that if we connect a normal usb A to Micro-B cable that doesn't ground out the USB_OTGID pin on the RPi zero, that we can accomplish the correct physical connections without any modifications, but we may need the kernel changes mentioned in this comment on #881

@hh hh changed the title Support for USB Gadget Mode (pi shows up as keyboard, disk, net, camera etc) RPi zero Support for USB Gadget Mode (pi shows up as keyboard, disk, net, camera etc) Dec 5, 2015
@hh
Copy link
Author

hh commented Dec 5, 2015

@ladyada provides a really nice picture of the port in questions:

RPi zero photo from ladyada

We want to use the USB micro port on the left, not the POWER IN port on the right.

@lurch
Copy link
Contributor

lurch commented Dec 14, 2015

I agree it would be great to see this working.

I don't have a PiZero myself yet, and this doesn't directly relate to the linux driver mentioned here (so apologies if this is slightly off-topic) but I experimented earlier in the year (or maybe it was last year) and was able to get https://github.com/raspberrypi/tools/tree/master/usbboot to work with a Raspberry Pi Model A, when either no SD card was inserted, or when start.elf (I think - or maybe it was bootcode.bin) was renamed. I.e. if I logged into the Model A over the serial terminal, renamed /boot/start.elf on the SD card, ran rpiboot on my PC and used the serial terminal to reboot the Pi, then I was able to access the Model A's SD card on the PC as a MassStorageDevice.

@lurch
Copy link
Contributor

lurch commented Dec 14, 2015

I've just been playing around in GIMP with the lovely hi-res images from https://learn.adafruit.com/introducing-the-raspberry-pi-zero by following the traces across the top and bottom sides of the PCB :-)
It looks like the USB_OTGID pin connects from the MicroUSB to the SOC, and also connects to PP40 on the underside of the board.
And the 5V from the "PWR IN" MicroUSB port is connected to the 5V on the "USB" MicroUSB port via the black component with a yellow circle on it - which might be a zero-ohm resistor?

@macmpi
Copy link

macmpi commented Dec 14, 2015

Any chance we could then use Chromecast Ethernet Adapter (https://store.google.com/product/ethernet_adapter_for_chromecast) to both charge & get RJ45 socket in one cable then? That would be great solution for RPi zero
Usure it would require additional driver though: can't tell which chipset it is using.

@lurch
Copy link
Contributor

lurch commented Dec 15, 2015

Any chance we could then use Chromecast Ethernet Adapter

Interesting idea. I did a bit of googling and found https://productforums.google.com/forum/#!topic/chromecast/xo_NDh5CZA8 which says "the Chromecast kernel includes only one driver (asix.ko / USB_NET_AX8817X)" so that's obviously the driver needed for the official chromecast adaptor, and the asix.ko driver is already well supported on Linux.

@macmpi
Copy link

macmpi commented Dec 15, 2015

Well, that's what I initially thought but there might be some more subtle consideration on that adapter. I used AX8817X dongles and Y OTG cable to charge/ethernet both Chromecast and some Android tablets, all sharing the same well known driver indeed.
I then bought the Chromecast Ethernet Adapter for the same, but it does only work with Chromecast for some mysterious reason...(other chipset, wierd cabling? ...)
Would love to see it working with Pi Zero, as it would provide elegant solution for that tiny board.
I hope this effort will bring it closer: I do not intend to hijack the thread more with this.

@procount
Copy link

Anyone seen this post from Dom about gadget mode on the PiZero on the forum?
https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=127003&p=850028&hilit=pi+zero+gadget#p850028
It provides a bit of insight about what is necessary.

@hh
Copy link
Author

hh commented Dec 16, 2015

From Dom's post:

On Pi Zero the OTG line is used and makes the linux driver choose
host/gadget mode. However as most people want host mode, and
non-OTG cables make the Pi Zero boot in gadget mode, we ignore this.

Looks like at some point it was decided to force the port into host mode,
because the original Pi only had a host port. Would it make sense at this
point to just revert this commit globally:

gusbcfg.b.force_host_mode = 1

to

gusbcfg.b.force_host_mode = 0

Anyone want to compile and test this?

Yes, in theory USB OTG and using the Pi Zero as a host or gadget is possible
(just as it is on model A and CM). Not sure if anyone has got that working?

I'm still trying to get one to test with.

However that is not sufficient. The USB driver hasn't been tested in gadget mode
by us for about 3 years, and certainly some of the FIQ stuff doesn't work with gadget
mode. Some some hacking would be needed (starting with disabling the fiq) to make
this work. Volunteers are welcome!

Looking forward to some momentum here.

@lurch
Copy link
Contributor

lurch commented Dec 16, 2015

Would it make sense at this point to just revert this commit globally:

Based on @popcornmix 's commit comment of "Force host mode to fix incorrect compute module boards" and looking at the compute module schematics it sounds like some (lots?) of people have made modules for the CM to plug into, and I'm guessing they forgot to ground the USB_OTGID pin but they actually wanted the USB to be in host mode, so the driver was modified to always only support host mode (since due to the FIQ stuff it currently doesn't support gadget mode anyway); which saves people having to create another iteration of their CM host PCBs, or always using a custom-compiled kernel.

Well that's my best guess anyway ;-)

@notro
Copy link
Contributor

notro commented Dec 16, 2015

The mainline dwc2 driver which does work on the Pi in host mode, has otg mode as well. Maybe worth trying. I haven't got an A or Zero so I can't try it myself.

This config change:

CONFIG_USB_DWC2=y

which also enables this:

CONFIG_USB_DWC2_HOST=y

coupled with this overlay

/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2835";

    fragment@0 {
        target = <&usb>;
        __overlay__ {
            compatible = "brcm,bcm2835-usb";
            reg = <0x7e980000 0x10000>;
            interrupts = <1 9>;
        };
    };
};

will switch to using the dwc2 driver in host mode.

Enabling CONFIG_USB_GADGET seems to be necessary to to enable otg mode in the dwc2 driver.
From drivers/usb/dwc2/Kconfig:

choice
        bool "DWC2 Mode Selection"
        default USB_DWC2_DUAL_ROLE if (USB && USB_GADGET)
        default USB_DWC2_HOST if (USB && !USB_GADGET)
        default USB_DWC2_PERIPHERAL if (!USB && USB_GADGET)

The next step seems to be to set the dr_mode DT property to otg (see binding doc).

The reason we are currently using dwc_otg instead of dwc2, is that it can use a non-maskable fiq interrupt to increase throughput, but lowered throughput probably isn't such an issue in otg mode.

https://www.kernel.org/doc/Documentation/devicetree/bindings/usb/dwc2.txt
http://lxr.free-electrons.com/source/drivers/usb/dwc2/

@toddtreece
Copy link

@notro thanks for the info!

i'm pretty new to working with device trees, but i thought i would give it a shot. i tried it with USB_DWC2_DUAL_ROLE enabled, but i am still not having any luck. i'm not sure what to use for the clocks parameter. this is the overlay i compiled and enabled:

/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2835";

    fragment@0 {
        target = <&usb>;
        #address-cells = <1>;
        #size-cells = <1>;
        __overlay__ {
            compatible = "brcm,bcm2835-usb";
            reg = <0x7e980000 0x10000>;
            interrupts = <1 9>;
            dr_mode = "otg";
            clocks = <&clk_core>;
            clock-names = "otg";
        };
    };
};

the pi would boot, but it won't show up on my OS X machine as a device.

@notro
Copy link
Contributor

notro commented Dec 16, 2015

Do you get anything related to usb in the kernel log: dmesg

@notro
Copy link
Contributor

notro commented Dec 16, 2015

You also need to enable the gadget drivers you want (I have never done this before):
http://lxr.free-electrons.com/source/drivers/usb/gadget/Kconfig (also try enabling the debug options)

http://www.linux-usb.org/gadget/
https://www.kernel.org/doc/Documentation/usb/ (gadget_*.txt)

@toddtreece
Copy link

i think the issue is here:

Dec 16 20:27:16 raspberrypi kernel: [    2.022050] dwc2 20980000.usb: Mode Mismatch Interrupt: currently in Device mode

here's the full log from that boot: https://gist.github.com/toddtreece/88965370a4d84877edf7

@ED6E0F17
Copy link

Thanks for the tip about device tree. The upstream driver seems to be working in host mode, but I get a warning about insufficient fifo memory.

dmesg.txt

@notro
Copy link
Contributor

notro commented Dec 17, 2015

@ED6E0F17 you get the warning in otg mode, right?
Enabling DEBUG will print the fifo sizes used. @P33M can probably tell if they're valid or not.

drivers/usb/dwc2/gadget.c#L3566

int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
{
...
    /* Dump fifo information */
    dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n",
                        hsotg->g_np_g_tx_fifo_sz);
    dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz);
    for (i = 0; i < MAX_EPS_CHANNELS; i++)
        dev_dbg(dev, "Periodic TXFIFO%2d size: %d\n", i,
                        hsotg->g_tx_fifo_sz[i]);

A similar error on rockchip was solved like this: torvalds/linux@ec32bd9

@ladyada
Copy link

ladyada commented Dec 17, 2015

just poking in to say im gonna try compiling this too, cuz why not :)
im working off of https://github.com/raspberrypi/linux/tree/rpi-4.4.y, will edit/post with whatever i find!

@ladyada
Copy link

ladyada commented Dec 18, 2015

@ED6E0F17 hey i tried just the default arch/arm/rpi_defconfig in the 4.4.0-rc5 branch and couldnt get the kernel to boot, just rainbowscreen. im compiling for the zero (BCM2708) and saw you're compiling for BCM2709 - but are you using the default defconfig?

@ED6E0F17
Copy link

@notro - that looks like the right fix for fifo sizes. The warning occurs on loading the driver, but it is coming from the gadget driver.

@ladyada - I am working from a heavily modified config, but from defconfig you will need to enable the Upstream driver, and disable the Downstream driver, and also patch the device tree.

DT patch:
patch.txt

My rpi-4.4 config:
config.txt

@notro
Copy link
Contributor

notro commented Dec 18, 2015

I have used otg mode on a B+ with some intrumentation to look at the fifo sizes. The board never comes fully up, but I do get the numbers. @P33M can you have a look?

[    0.000000] Linux version 4.4.0-rc5+ (pi@raspi2) (gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) ) #3 PREEMPT Fri Dec 18 20:36:34 CET 2015

[    2.359432] dwc2 20980000.usb: NonPeriodic TXFIFO size: 1024
[    2.365268] dwc2 20980000.usb: RXFIFO size: 2048
[    2.370075] dwc2 20980000.usb: Periodic TXFIFO 0 size: 0
[    2.375530] dwc2 20980000.usb: Periodic TXFIFO 1 size: 256
[    2.381208] dwc2 20980000.usb: Periodic TXFIFO 2 size: 256
[    2.386891] dwc2 20980000.usb: Periodic TXFIFO 3 size: 256
[    2.392518] dwc2 20980000.usb: Periodic TXFIFO 4 size: 256
[    2.398183] dwc2 20980000.usb: Periodic TXFIFO 5 size: 768
[    2.403813] dwc2 20980000.usb: Periodic TXFIFO 6 size: 768
[    2.409482] dwc2 20980000.usb: Periodic TXFIFO 7 size: 768
[    2.419758] dwc2 20980000.usb: Periodic TXFIFO 8 size: 768
[    2.430063] dwc2 20980000.usb: Periodic TXFIFO 9 size: 0
[    2.440137] dwc2 20980000.usb: Periodic TXFIFO10 size: 0
[    2.450151] dwc2 20980000.usb: Periodic TXFIFO11 size: 0
[    2.460074] dwc2 20980000.usb: Periodic TXFIFO12 size: 0
[    2.469798] dwc2 20980000.usb: Periodic TXFIFO13 size: 0
[    2.479572] dwc2 20980000.usb: Periodic TXFIFO14 size: 0
[    2.489276] dwc2 20980000.usb: Periodic TXFIFO15 size: 0
[    2.536754] dwc2 20980000.usb: resetting core
[    2.545373] dwc2 20980000.usb: reset successful

(the 4080 number is hsotg->fifo_mem)
[    2.554109] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM
[    2.565613] dwc2 20980000.usb: GRXFSIZ=0x00001000, GNPTXFSIZ=0x00201000

[    2.576598] dwc2_hsotg_init_fifo(): hsotg->fifo_mem=4080 (0xff0)

(addr = hsotg->g_rx_fifo_sz + hsotg->g_np_g_tx_fifo_sz == 2048 + 1024 == 3072)

[    2.586691] addr=3072 (0xc00), hsotg->g_tx_fifo_sz[1]=256
[    2.596327] addr=3328 (0xd00), hsotg->g_tx_fifo_sz[2]=256
[    2.605928] addr=3584 (0xe00), hsotg->g_tx_fifo_sz[3]=256

[    2.615489] ------------[ cut here ]------------
[    2.624272] WARNING: CPU: 0 PID: 1 at drivers/usb/dwc2/gadget.c:215 dwc2_hsotg_init_fifo+0x1a8/0x23c()
[    2.637788] insufficient fifo memory
[    2.641291] Modules linked in:
[    2.652782] CPU: 0 PID: 1 Comm: swapper Not tainted 4.4.0-rc5+ #3
[    2.663120] Hardware name: BCM2708

[    2.733156] [<c045bea4>] (dwc2_hsotg_init_fifo) from [<c045bfe4>] (dwc2_hsotg_init+0xac/0x110)
[    2.746312] [<c045bfe4>] (dwc2_hsotg_init) from [<c045f91c>] (dwc2_gadget_init+0x3c0/0x890)
[    2.759225] [<c045f91c>] (dwc2_gadget_init) from [<c0451604>] (dwc2_driver_probe+0x254/0x2e4)
[    2.772314] [<c0451604>] (dwc2_driver_probe) from [<c03b3008>] (platform_drv_probe+0x44/0x7c)

[    2.944490] ---[ end trace bf843f4c4ca2ef38 ]---

[    2.954026] addr=3840 (0xf00), hsotg->g_tx_fifo_sz[4]=256
[    2.964436] addr=4096 (0x1000), hsotg->g_tx_fifo_sz[5]=768
[    2.974923] addr=4864 (0x1300), hsotg->g_tx_fifo_sz[6]=768
[    2.985261] addr=5632 (0x1600), hsotg->g_tx_fifo_sz[7]=768
[    2.995696] addr=6400 (0x1900), hsotg->g_tx_fifo_sz[8]=768

@toddtreece
Copy link

@notro i just realized i was tweaking bcmrpi_defconfig to test dwc2. should i be using bcm2835_defconfig?

@notro
Copy link
Contributor

notro commented Dec 18, 2015

No, we're using bcmrpi_defconfig.

@toddtreece
Copy link

@notro ok. thanks

@ED6E0F17
Copy link

@notro : I don`t know if the gadget fifos should sum to 1024 or 4096, but it is coming up in gadget mode on model A with this device tree :
dtpatch.txt

I need to make up a cable before I test further.

@mindforger
Copy link

soooo if i were going to desolder the 0ohm in this picture right above the printing "PWR IN"
https://learn.adafruit.com/assets/28756
the data port should not have an vcc connection, only ground and should be safe?

but will it work without a vcc connection?

@Ferroin
Copy link
Contributor

Ferroin commented Apr 11, 2016

For what it's worth, I actually have run a Pi 1 Model B fully stable from USB ports on a computer before. They were USB 3.0 ports designed for charging phones (which is part of the USB 3.0 standard, and they can source 2A at 5V usually, occasionally up to 2.1A), which are becoming more and more common these days.

The other problem with running from a PC USB port is that they aren't consistent (just like the USB PSU's). I've seen some that can run a Pi just fine, perfectly stable, 100% load 24/7 for weeks with no issues. I've also seen some that are so strictly compliant with the USB standards (which require devices to draw minimum current until they negotiate higher power consumption) that you can't even hope to boot a Pi powered from them. Most fall somewhere in-between, and start to lose voltage once you get to around 450mA of current draw, but will still let you draw the full 500mA without negotiation (because there are so many USB 'gadgets' that make no data connection and just use the port as a power source).

@mindforger
Copy link

i was lucky to have bought a y-cable as i thought this could be usefull .. now it is, i only have to connect both ends when powering it from the PC and 2 seperate wire when powering it from the PSU while connected to the PC

@Ferroin
Copy link
Contributor

Ferroin commented Apr 11, 2016

Tying the grounds together can be dangerous as well. The computer should have protection to handle this, but some don't, and I'm almost certain the Pi doesn't. Unless the devices are electrically grounded to the same ground plane, they will almost certainly have variance in voltage (usually it's millivolts, but sometimes it's more, and that can be problematic). This is why so many standards for communications require a ground line in addition to the data lines.

@NicoHood
Copy link

As I said this will kill your device and/or PC X_x
Also Y Cables are bad practice in general too.

Edit: Desoldering the 0 ohm could be an idea though. But this would break usb host devices without a powered hub. But a powered hub should be used anyways. So can anyone verify that this 0ohm really connects those 2 vccs together?

@mindforger
Copy link

i measured it with two usb cable and there are several guides in the web stating the same, and also which parts you would have to add to make the OTG regulator part working

also i want to work headless with it, just the data port as an easy access ssh via network in parallel with mass storage for easy file transfer from my laptop or tablet (if i get the driver working) ... hope the next batch of rpi zeros will be deployed soon and i get a hold of one or two more -.-

@NicoHood
Copy link

What have you tested? That the lines are correctly separated if you remove the resistor?
I don't get the OTG question. OTG is a 5th pin that is grounded by the OTG cable and has nothing to do with the power supply.

Assumed you broke the resistor and it works as described:
As Device:
It is self powered

As Host:
Use an active hub.

@mindforger
Copy link

i desoldered the resistor and the data port Vcc wasn't connected anymore
in fact i did not find any part (so far) of the board that was connected to the USB data port's Vcc
it looks to me that it is completely isolated then

with this rsistorsize and pad distance you can easily bridge it back with just some solder if required

with OTG regulator i mean the left out parts right above the resistor bridge, if you just google it for a second you get the part list containing everythign you need to make the data port a real OTG port with power limitation and short circuit and overcurrent protection, but you also only get the very limited power supply of around 40mA or so, so you still need to use an active hub rendering the whole circuit a bit useless ... or i miss the technical benefit or this circuit in this particular case

@NicoHood
Copy link

That sounds nice, if the regulator can detect vcc inputs via usb and then safely disconnects the pis vcc. It would at least work to connect an usb stick (as this is the original intention of otg for smartphones etc). I could not find anything online. It would be highly appreciated if you could post further information on that. It'd be also cool to know what the other unused, exposed pads (on the bottom) do.

@mindforger
Copy link

the pads for the connector at the bottom is a jtag interface (J5).. but guess what the site i got my info from is missing or offline, i can't find it anymore XD
the other pads are several testing points
https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=89522
https://docs.google.com/spreadsheets/d/15kHcow993d_2CS6rZxQMq0wAWlgWNaHU_go1Hyf08ck/edit#gid=0

but the heck i don't find the site anymore for the regulator

just found another intersting source
http://hackaday.com/2015/04/06/more-power-for-raspberry-pi-usb-ports/

looks like exactly the same circuit and also named U13

@fantom-x
Copy link

fantom-x commented Jun 6, 2016

I have managed to make Pi Zero work with Windows as an USB Ethernet gadget: I can ssh into it and then from the Pi I can access the internet. I am having much less luck making this work with Ubuntu 16.04: I can SSH into it alright, but it just does not want to connect to the Internet. Is there a way to make it work with Ubuntu just like it works with Windows?

@lurch
Copy link
Contributor

lurch commented Jun 6, 2016

@lurch
Copy link
Contributor

lurch commented Jun 6, 2016

...and looks like some of the info is out of date, but there's also https://help.ubuntu.com/community/Internet/ConnectionSharing

@mindforger
Copy link

DISREGARD MY POST ABOVE when using the 1.3 version with camera connector you can not disconnect em anymore, they are now connected by a pretty fat line

@fantom-x
Copy link

fantom-x commented Jun 6, 2016

@lurch, thank for the suggestions. Here is how I made it work:

  1. NetworkManager in Ubuntu creates a new connection "Wired Connection 1" or another number: on IPv4 tab chose "Link-Local Only". Once a connection is established, the pi can be accessed by ssh [email protected]
  2. Use ifconfig to get the address of this new connection 169.254.X.X; in my case it was 169.254.202.41
  3. On the host run echo 1 > /proc/sys/net/ipv4/ip_forward
  4. On the host run iptables -t nat -A POSTROUTING -s 169.254.0.0/16 -o br0 -j MASQUERADE. Replace br0 with your interface name.
  5. SSH into pi and add a default route: route add default gw 169.254.202.41 usb0. The gateway is the IP address of the host link (see item 2 above)

After that was done, I was able to ping my router and google servers by IP.

@fantom-x
Copy link

fantom-x commented Jun 7, 2016

Anyone knows how to make DNS work in Pi Zero when it is connected to a Ubuntu PC? I can ping any website from the pi, but cannot figure out how to make name resolution work...

Update: my firewall (ufw) was blocking routed packets.

@lurch
Copy link
Contributor

lurch commented Jun 7, 2016

Anyone knows how to make DNS work in Pi Zero when it is connected to a Ubuntu PC?

I don't know if it's the "proper" way, but I was able to get name resolution working by finding out the IP address of my router's DNS server (I got this from the "Network Manager -> Connection Information" dialog on Ubuntu, and in my case it's 192.168.2.1) and on the Pi Zero (over the SSH connection) I did
echo "nameserver 192.168.2.1" | sudo resolvconf -a usb0
and I can then successfully run apt-get update etc. :-)

@lurch
Copy link
Contributor

lurch commented Jun 8, 2016

I've knocked up a simple script to automatically setup internet access for a USB-network-connected PiZero:
https://gist.github.com/lurch/ad939bbce48064cffdb215268eac9f62

@fantom-x
Copy link

fantom-x commented Jun 8, 2016

@lurch, once you ssh into the gadget for the first time you can use arp -n to get your host's IP address. In this case your script could become a one liner...

@hex007
Copy link

hex007 commented Jun 22, 2016

@lurch Have you tested the script. I am unable to get it to run even when i follow all instructions on your blog post and from your script

  1. Flashed Jesse lite

  2. Edited 2 files in boot partition

  3. from ubuntu 15.10 x64:

    a. Changed the connection to link-local only
    b. Interface is called: enx96fcc47029dc (strange name)
    c. Pi connected. Can ssh successfully
    d. echo 1 > /proc/sys/net/ipv4/ip_forward
    e. sudo iptables -t nat -A POSTROUTING -s 169.254.0.0/16 -o br0 -j MASQUERADE
    f. SSH into Pi

  4. From pi:

    a.sudo route add default gw 169.254.9.197 usb0; echo \"nameserver 192.168.0.1\" | sudo resolvconf -a usb0
    b. ping 8.8..8.8 ---> nothing, all packets dropped

Am i missing some step?

@lurch
Copy link
Contributor

lurch commented Jun 22, 2016

I only tested on Ubuntu 14.04, but I can see a couple of small errors in what you've done above:

  1. I assume you did step 3d as the root user?
  2. Your iptables command should probably be using eth0 or wlan0 rather than br0
  3. In step 4a make sure you're giving the IP address of the PC-side of the USB-network connection and not the IP address of the Pi-side of the USB-network connection
  4. If running the commands directly on the Pi itself, you don't want to escape the quotes, so change it to echo "nameserver 192.168.0.1" | sudo resolvconf -a usb0

BTW I'm actually a different Andrew than @gbaman (who wrote the blog article) ;-)
As you'll see in one of my comments on http://blog.gbaman.info/?p=791 I recommend configuring the Zero to assign static MAC addresses to both sides of the USB-network device, so that you don't have to keep reconfiguring the PC-side network device every time you reboot the Zero. My script makes no 'permanent' changes, so you need to run it each time you reboot your PC or Pi Zero.

@Ruffio
Copy link

Ruffio commented Aug 17, 2016

@hh has your issue been resolved? If so, please close this issue. Thanks.

@hh
Copy link
Author

hh commented Aug 17, 2016

@ladyada do you have info on the kernel you used for https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/serial-gadget

Do you know if any patches required for it to work were merged into any branches under https://github.com/raspberrypi/linux ?

@gbaman
Copy link

gbaman commented Aug 17, 2016

@hh that method described in the Adafruit guide is rather old and long out of date now. Raspbian now ships with all you need. Plus, is now even possible to configure everything needed by editing just config.txt and cmdline.txt on the FAT32 partition using another computer without the Pi ever being booted. Wrote it all up a while back after stumbling across the cmdline.txt parameter - http://blog.gbaman.info/?p=791

@hh
Copy link
Author

hh commented Aug 17, 2016

Beautiful! Thanks @gbaman and everyone else! (I still haven't gotten any pizero's yet)

@hh hh closed this as completed Aug 17, 2016
@ladyada
Copy link

ladyada commented Aug 22, 2016

hey cool @gbaman thx for the notice! the guide has been updated :)
https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget
(serial gadget still requires a tiny bit of commands to kick off the getty service)

@MrHamel
Copy link

MrHamel commented Sep 5, 2016

Can someone test and tell me the performance of the mass storage capability? According to the Tizen documentation, it does support ISO mounting and I'd like to weigh out my options. Thanks!

popcornmix pushed a commit that referenced this issue Dec 21, 2018
[ Upstream commit 0b8d907 ]

Fix wraparound bug which could lead to memory exhaustion when adding an
x.x.x.x-255.255.255.255 range to any hash:*net* types.

Fixes Netfilter's bugzilla id #1212, reported by Thomas Schwark.

Fixes: 48596a8 ("netfilter: ipset: Fix adding an IPv4 range containing more than 2^31 addresses")
Signed-off-by: Jozsef Kadlecsik <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests