raspberrypi / linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
Other
11.1k stars 4.97k forks source link

Raspberry Pi Zero in HID Gadget Mode Cannot Wake Host Computer #3977

Open zwhitchcox opened 3 years ago

zwhitchcox commented 3 years ago

Describe the bug A raspberry pi Zero in HID gadget mode cannot wake host computer.

To reproduce Enable dwc2 driver and reboot:

 echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
sudo shutdown -r now

Load modules:

sudo modprobe libcomposite dwc2

Add keyboard to ConfigFS:

#!/bin/bash
# this is a stripped down version of https://github.com/ckuethe/usbarmory/wiki/USB-Gadgets - I don't claim any rights

modprobe libcomposite
cd /sys/kernel/config/usb_gadget/
mkdir -p g1
cd g1
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409
echo "fedcba9876543210" > strings/0x409/serialnumber
echo "girst" > strings/0x409/manufacturer 
echo "Hardpass" > strings/0x409/product
N="usb0"
mkdir -p functions/hid.$N
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.usb0/report_desc
C=1
mkdir -p configs/c.$C/strings/0x409
echo "Config $C: ECM network" > configs/c.$C/strings/0x409/configuration 
echo 250 > configs/c.$C/MaxPower 
ln -s functions/hid.$N configs/c.$C/
ls /sys/class/udc > UDC

Now, output keys to /dev/hidg0

sudo su
echo -ne "\0\0\x4\0\0\0\0\0" > /dev/hidg0 #press the A-button
echo -ne "\0\0\0\0\0\0\0\0" > /dev/hidg0 #release all keys

When you are plugged in to a host computer that is on, it will output the keys. That works fine.

Next suspend the host computer, and try the same thing:

sudo su
echo -ne "\0\0\x4\0\0\0\0\0" > /dev/hidg0 #press the A-button
echo -ne "\0\0\0\0\0\0\0\0" > /dev/hidg0 #release all keys

You get an error:

bash: echo: write error: Resource temporarily unavailable

Per the kernel gadget documentation, this the remote wakeup functionality is supposed to be handled by the kernel gadget driver.

Expected behaviour When you send keys to the host computer, the gadget driver should send the wakeup signal to the host computer, instead of just failing.

Actual behaviour As mentioned previously, you can't write to the file

System

raspinfo ``` System Information ------------------ Raspberry Pi Zero W Rev 1.1 PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" NAME="Raspbian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" Raspberry Pi reference 2020-08-20 Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 9a3a10bf1019ebb2d59053564dc6b90068bad27d, stage2 Linux raspberrypi 5.4.51+ #1333 Mon Aug 10 16:38:02 BST 2020 armv6l GNU/Linux Revision : 9000c1 Serial : 0000000050a70373 Model : Raspberry Pi Zero W Rev 1.1 Throttled flag : throttled=0x0 Camera : supported=0 detected=0 Videocore information --------------------- Aug 19 2020 17:40:36 Copyright (c) 2012 Broadcom version e90cba19a98a0d1f2ef086b9cafcbca00778f094 (clean) (release) (start_cd) alloc failures: 0 compactions: 0 legacy block fails: 0 Filesystem information ---------------------- Filesystem 1K-blocks Used Available Use% Mounted on /dev/root 30485636 7499856 21715764 26% / devtmpfs 212620 0 212620 0% /dev tmpfs 245632 0 245632 0% /dev/shm tmpfs 245632 6548 239084 3% /run tmpfs 5120 4 5116 1% /run/lock tmpfs 245632 0 245632 0% /sys/fs/cgroup /dev/mmcblk0p1 258095 54603 203492 22% /boot tmpfs 49124 0 49124 0% /run/user/1000 /dev/mapper/loop0p1 40862 6016 34846 15% /mnt/loop0p1 /dev/mapper/loop0p2 1353296 585912 677068 47% /mnt/loop0p2 /dev/mapper/loop0p3 3003 29 2689 2% /mnt/loop0p3 Filename Type Size Used Priority /var/swap file 102396 4352 -2 Package version information --------------------------- raspberrypi-ui-mods: Installed: (none) raspberrypi-sys-mods: Installed: 20200812 openbox: Installed: (none) lxpanel: Installed: (none) pcmanfm: Installed: (none) rpd-plym-splash: Installed: (none) Networking Information ---------------------- lo: flags=73 mtu 65536 inet x.x.x.x netmask x.x.x.x inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 5 bytes 472 (472.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 5 bytes 472 (472.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlan0: flags=4163 mtu 1500 inet x.x.x.x netmask x.x.x.x broadcast x.x.x.x inet6 y.y.y.y.y.y.y.y prefixlen 64 scopeid 0x0 inet6 y::y.y.y.y prefixlen 64 scopeid 0x20 ether m.m.m.m txqueuelen 1000 (Ethernet) RX packets 1509525 bytes 2058560384 (1.9 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 146110 bytes 14886970 (14.1 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 USB Information --------------- /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc2/1p, 480M config.txt ---------- aphy_params_current=547 arm_freq=1000 arm_freq_min=700 audio_pwm_mode=514 config_hdmi_boost=5 core_freq=400 disable_auto_turbo=1 disable_commandline_tags=2 display_hdmi_rotate=-1 display_lcd_rotate=-1 dphy_params_current=547 enable_tvout=1 force_eeprom_read=1 force_pwm_open=1 framebuffer_depth=16 framebuffer_ignore_alpha=1 framebuffer_swap=1 gpu_freq=300 ignore_lcd=1 init_uart_clock=0x2dc6c00 over_voltage_avs=0x249f0 pause_burst_frames=1 program_serial_random=1 sdram_freq=450 total_mem=512 hdmi_force_cec_address:0=65535 hdmi_force_cec_address:1=65535 hdmi_pixel_freq_limit:0=0x9a7ec80 device_tree=- overlay_prefix=overlays/ hdmi_cvt:0= hdmi_cvt:1= hdmi_edid_filename:0= hdmi_edid_filename:1= hdmi_timings:0= hdmi_timings:1= cmdline.txt ----------- coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_headphones=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbdepth=16 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:A7:03:73 vc_mem.mem_base=0x1fa00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles raspi-gpio settings ------------------- BANK0 (GPIO 0 to 27): GPIO 0: level=1 fsel=0 func=INPUT GPIO 1: level=1 fsel=0 func=INPUT GPIO 2: level=1 fsel=4 alt=0 func=SDA1 GPIO 3: level=1 fsel=4 alt=0 func=SCL1 GPIO 4: level=1 fsel=0 func=INPUT GPIO 5: level=1 fsel=0 func=INPUT GPIO 6: level=1 fsel=0 func=INPUT GPIO 7: level=1 fsel=1 func=OUTPUT GPIO 8: level=1 fsel=1 func=OUTPUT GPIO 9: level=0 fsel=4 alt=0 func=SPI0_MISO GPIO 10: level=0 fsel=4 alt=0 func=SPI0_MOSI GPIO 11: level=0 fsel=4 alt=0 func=SPI0_SCLK GPIO 12: level=0 fsel=0 func=INPUT GPIO 13: level=0 fsel=0 func=INPUT GPIO 14: level=0 fsel=0 func=INPUT GPIO 15: level=1 fsel=0 func=INPUT GPIO 16: level=0 fsel=0 func=INPUT GPIO 17: level=0 fsel=0 func=INPUT GPIO 18: level=0 fsel=0 func=INPUT GPIO 19: level=0 fsel=0 func=INPUT GPIO 20: level=0 fsel=0 func=INPUT GPIO 21: level=1 fsel=0 func=INPUT GPIO 22: level=0 fsel=0 func=INPUT GPIO 23: level=0 fsel=0 func=INPUT GPIO 24: level=0 fsel=0 func=INPUT GPIO 25: level=0 fsel=0 func=INPUT GPIO 26: level=0 fsel=0 func=INPUT GPIO 27: level=0 fsel=0 func=INPUT BANK1 (GPIO 28 to 45): GPIO 28: level=1 fsel=0 func=INPUT GPIO 29: level=1 fsel=0 func=INPUT GPIO 30: level=0 fsel=7 alt=3 func=CTS0 GPIO 31: level=0 fsel=7 alt=3 func=RTS0 GPIO 32: level=1 fsel=7 alt=3 func=TXD0 GPIO 33: level=1 fsel=7 alt=3 func=RXD0 GPIO 34: level=1 fsel=7 alt=3 func=SD1_CLK GPIO 35: level=1 fsel=7 alt=3 func=SD1_CMD GPIO 36: level=1 fsel=7 alt=3 func=SD1_DAT0 GPIO 37: level=1 fsel=7 alt=3 func=SD1_DAT1 GPIO 38: level=1 fsel=7 alt=3 func=SD1_DAT2 GPIO 39: level=1 fsel=7 alt=3 func=SD1_DAT3 GPIO 40: level=0 fsel=1 func=OUTPUT GPIO 41: level=1 fsel=1 func=OUTPUT GPIO 42: level=0 fsel=0 func=INPUT GPIO 43: level=1 fsel=4 alt=0 func=GPCLK2 GPIO 44: level=0 fsel=1 func=OUTPUT GPIO 45: level=1 fsel=1 func=OUTPUT BANK2 (GPIO 46 to 53): GPIO 46: level=1 fsel=0 func=INPUT GPIO 47: level=0 fsel=1 func=OUTPUT GPIO 48: level=0 fsel=4 alt=0 func=SD0_CLK GPIO 49: level=1 fsel=4 alt=0 func=SD0_CMD GPIO 50: level=1 fsel=4 alt=0 func=SD0_DAT0 GPIO 51: level=1 fsel=4 alt=0 func=SD0_DAT1 GPIO 52: level=1 fsel=4 alt=0 func=SD0_DAT2 GPIO 53: level=1 fsel=4 alt=0 func=SD0_DAT3 vcdbg log messages ------------------ Unable to determine the value of __LOG_START Unable to read logging_header from 0x00000000 dmesg log --------- [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 5.4.51+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1333 Mon Aug 10 16:38:02 BST 2020 [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache [ 0.000000] OF: fdt: Machine model: Raspberry Pi Zero W Rev 1.1 [ 0.000000] Memory policy: Data cache writeback [ 0.000000] Reserved memory: created CMA memory pool at 0x1ac00000, size 64 MiB [ 0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool [ 0.000000] On node 0 totalpages: 126976 [ 0.000000] Normal zone: 1116 pages used for memmap [ 0.000000] Normal zone: 0 pages reserved [ 0.000000] Normal zone: 126976 pages, LIFO batch:31 [ 0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768 [ 0.000000] pcpu-alloc: [0] 0 [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 125860 [ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_headphones=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbdepth=16 bcm2708_fb.fbswap=1 smsc95xx.macaddr=m.m.m.m vc_mem.mem_base=0x1fa00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles [ 0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes, linear) [ 0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes, linear) [ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off [ 0.000000] Memory: 425240K/507904K available (7579K kernel code, 702K rwdata, 2404K rodata, 492K init, 800K bss, 17128K reserved, 65536K cma-reserved) [ 0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1 [ 0.000000] ftrace: allocating 26696 entries in 53 pages [ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16 [ 0.000000] random: get_random_bytes called from start_kernel+0x2a8/0x4dc with crng_init=0 [ 0.000025] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns [ 0.000076] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns [ 0.000189] bcm2835: system timer (irq = 27) [ 0.000808] Console: colour dummy device 80x30 [ 0.000848] printk: console [tty1] enabled [ 0.000924] Calibrating delay loop... 697.95 BogoMIPS (lpj=3489792) [ 0.050357] pid_max: default: 32768 minimum: 301 [ 0.050939] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear) [ 0.050970] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear) [ 0.052948] Disabling memory control group subsystem [ 0.053168] CPU: Testing write buffer coherency: ok [ 0.054860] Setting up static identity map for 0x8200 - 0x8238 [ 0.056041] devtmpfs: initialized [ 0.069390] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5 [ 0.069851] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns [ 0.069894] futex hash table entries: 256 (order: -1, 3072 bytes, linear) [ 0.078672] pinctrl core: initialized pinctrl subsystem [ 0.080823] NET: Registered protocol family 16 [ 0.085668] DMA: preallocated 1024 KiB pool for atomic coherent allocations [ 0.094041] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers. [ 0.094064] hw-breakpoint: maximum watchpoint size is 4 bytes. [ 0.094250] Serial: AMBA PL011 UART driver [ 0.098069] bcm2835-mbox 2000b880.mailbox: mailbox enabled [ 0.120837] raspberrypi-firmware soc:firmware: Attached to firmware from 2020-08-19 17:40, variant start_cd [ 0.130864] raspberrypi-firmware soc:firmware: Firmware hash is e90cba19a98a0d1f2ef086b9cafcbca00778f094 [ 0.195000] bcm2835-dma 20007000.dma: DMA legacy API manager, dmachans=0x1 [ 0.198219] SCSI subsystem initialized [ 0.198533] usbcore: registered new interface driver usbfs [ 0.198650] usbcore: registered new interface driver hub [ 0.198922] usbcore: registered new device driver usb [ 0.202081] clocksource: Switched to clocksource timer [ 1.461714] VFS: Disk quotas dquot_6.6.0 [ 1.461866] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes) [ 1.462391] FS-Cache: Loaded [ 1.462789] CacheFiles: Loaded [ 1.483304] thermal_sys: Registered thermal governor 'step_wise' [ 1.484038] NET: Registered protocol family 2 [ 1.485558] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear) [ 1.485625] TCP established hash table entries: 4096 (order: 2, 16384 bytes, linear) [ 1.485718] TCP bind hash table entries: 4096 (order: 2, 16384 bytes, linear) [ 1.485819] TCP: Hash tables configured (established 4096 bind 4096) [ 1.486007] UDP hash table entries: 256 (order: 0, 4096 bytes, linear) [ 1.486050] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear) [ 1.486529] NET: Registered protocol family 1 [ 1.487915] RPC: Registered named UNIX socket transport module. [ 1.487935] RPC: Registered udp transport module. [ 1.487947] RPC: Registered tcp transport module. [ 1.487958] RPC: Registered tcp NFSv4.1 backchannel transport module. [ 1.489729] hw perfevents: no irqs for PMU, sampling events not supported [ 1.489805] hw perfevents: enabled with armv6_1176 PMU driver, 3 counters available [ 1.495039] Initialise system trusted keyrings [ 1.495551] workingset: timestamp_bits=14 max_order=17 bucket_order=3 [ 1.513122] FS-Cache: Netfs 'nfs' registered for caching [ 1.514770] NFS: Registering the id_resolver key type [ 1.514838] Key type id_resolver registered [ 1.514852] Key type id_legacy registered [ 1.514923] nfs4filelayout_init: NFSv4 File Layout Driver Registering... [ 1.517329] Key type asymmetric registered [ 1.517353] Asymmetric key parser 'x509' registered [ 1.517450] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 249) [ 1.517470] io scheduler mq-deadline registered [ 1.517484] io scheduler kyber registered [ 1.521116] bcm2708_fb soc:fb: FB found 1 display(s) [ 1.527208] Console: switching to colour frame buffer device 82x26 [ 1.530670] bcm2708_fb soc:fb: Registered framebuffer for display 0, size 656x416 [ 1.539651] bcm2835-rng 20104000.rng: hwrng registered [ 1.540344] vc-mem: phys_addr:0x00000000 mem_base=0x1fa00000 mem_size:0x20000000(512 MiB) [ 1.541680] vc-sm: Videocore shared memory driver [ 1.542680] gpiomem-bcm2835 20200000.gpiomem: Initialised: Registers at 0x20200000 [ 1.565265] brd: module loaded [ 1.581258] loop: module loaded [ 1.583619] Loading iSCSI transport class v2.0-870. [ 1.584766] usbcore: registered new interface driver smsc95xx [ 1.584808] dwc_otg: version 3.00a 10-AUG-2012 (platform bus) [ 1.585110] dwc_otg: FIQ enabled [ 1.585125] dwc_otg: NAK holdoff enabled [ 1.585137] dwc_otg: FIQ split-transaction FSM enabled [ 1.585159] Module dwc_common_port init [ 1.585722] usbcore: registered new interface driver usb-storage [ 1.586206] mousedev: PS/2 mouse device common for all mice [ 1.588276] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer [ 1.588820] bcm2835-cpufreq: min=700000 max=1000000 [ 1.590372] sdhci: Secure Digital Host Controller Interface driver [ 1.590390] sdhci: Copyright(c) Pierre Ossman [ 1.591265] mmc-bcm2835 20300000.mmcnr: could not get clk, deferring probe [ 1.592433] sdhost-bcm2835 20202000.mmc: could not get clk, deferring probe [ 1.592801] sdhci-pltfm: SDHCI platform and OF driver helper [ 1.593684] ledtrig-cpu: registered to indicate activity on CPUs [ 1.594165] hidraw: raw HID events driver (C) Jiri Kosina [ 1.594472] usbcore: registered new interface driver usbhid [ 1.594488] usbhid: USB HID core driver [ 1.596056] vchiq: vchiq_init_state: slot_zero = (ptrval) [ 1.598249] [vc_sm_connected_init]: start [ 1.602208] vc_vchi_sm_init: failed to open VCHI service (-1) [ 1.602227] [vc_sm_connected_init]: failed to initialize shared memory service [ 1.602571] [vc_sm_connected_init]: end - returning -1 [ 1.605592] Initializing XFRM netlink socket [ 1.605684] NET: Registered protocol family 17 [ 1.605898] Key type dns_resolver registered [ 1.607443] registered taskstats version 1 [ 1.607482] Loading compiled-in X.509 certificates [ 1.623818] uart-pl011 20201000.serial: cts_event_workaround enabled [ 1.624004] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2 [ 1.627079] bcm2835-power bcm2835-power: Broadcom BCM2835 power domains driver [ 1.629302] mmc-bcm2835 20300000.mmcnr: mmc_debug:0 mmc_debug2:0 [ 1.629328] mmc-bcm2835 20300000.mmcnr: DMA channel allocated [ 1.658201] sdhost: log_buf @ (ptrval) (5ad10000) [ 1.689891] random: fast init done [ 1.696046] mmc1: queuing unknown CIS tuple 0x80 (2 bytes) [ 1.697859] mmc1: queuing unknown CIS tuple 0x80 (3 bytes) [ 1.699669] mmc1: queuing unknown CIS tuple 0x80 (3 bytes) [ 1.702904] mmc1: queuing unknown CIS tuple 0x80 (7 bytes) [ 1.707831] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1) [ 1.711421] of_cfs_init [ 1.711650] of_cfs_init: OK [ 1.734510] Waiting for root device /dev/mmcblk0p2... [ 1.770414] mmc0: host does not support reading read-only switch, assuming write-enable [ 1.773278] mmc0: new high speed SDHC card at address 0001 [ 1.775325] mmcblk0: mmc0:0001 GB1QT 29.8 GiB [ 1.779331] mmcblk0: p1 p2 [ 1.810229] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null) [ 1.810362] VFS: Mounted root (ext4 filesystem) readonly on device 179:2. [ 1.820774] devtmpfs: mounted [ 1.829003] Freeing unused kernel memory: 492K [ 1.829023] This architecture does not have kernel memory protection. [ 1.829037] Run /sbin/init as init process [ 1.846315] mmc1: new high speed SDIO card at address 0001 [ 2.658438] systemd[1]: System time before build time, advancing clock. [ 2.827465] NET: Registered protocol family 10 [ 2.829820] Segment Routing with IPv6 [ 2.885094] systemd[1]: systemd 241 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid) [ 2.887270] systemd[1]: Detected architecture arm. [ 2.897206] systemd[1]: Set hostname to . [ 5.714013] random: systemd: uninitialized urandom read (16 bytes read) [ 5.740947] random: systemd: uninitialized urandom read (16 bytes read) [ 5.751388] systemd[1]: Listening on Syslog Socket. [ 5.752953] random: systemd: uninitialized urandom read (16 bytes read) [ 5.753739] systemd[1]: Started Dispatch Password Requests to Console Directory Watch. [ 5.755270] systemd[1]: Listening on udev Kernel Socket. [ 5.759463] systemd[1]: Created slice User and Session Slice. [ 5.761142] systemd[1]: Listening on fsck to fsckd communication Socket. [ 5.763222] systemd[1]: Listening on udev Control Socket. [ 5.810088] systemd[1]: Condition check resulted in Journal Audit Socket being skipped. [ 6.904669] dwc2 20980000.usb: 20980000.usb supply vusb_d not found, using dummy regulator [ 6.904915] dwc2 20980000.usb: 20980000.usb supply vusb_a not found, using dummy regulator [ 7.122385] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM [ 7.123433] dwc2 20980000.usb: DWC OTG Controller [ 7.123508] dwc2 20980000.usb: new USB bus registered, assigned bus number 1 [ 7.123614] dwc2 20980000.usb: irq 33, io mem 0x20980000 [ 7.124253] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.04 [ 7.124279] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 7.124299] usb usb1: Product: DWC OTG Controller [ 7.124318] usb usb1: Manufacturer: Linux 5.4.51+ dwc2_hsotg [ 7.124335] usb usb1: SerialNumber: 20980000.usb [ 7.125740] hub 1-0:1.0: USB hub found [ 7.125881] hub 1-0:1.0: 1 port detected [ 8.082709] systemd[1]: Started Apply Kernel Variables. [ 8.531443] systemd[1]: Started Journal Service. [ 9.669493] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null) [ 10.334162] systemd-journald[85]: Received request to flush runtime journal from PID 1 [ 12.799676] vc_sm_cma: module is from the staging directory, the quality is unknown, you have been warned. [ 12.811165] mc: Linux media interface: v0.10 [ 12.845884] bcm2835_vc_sm_cma_probe: Videocore shared memory driver [ 12.845920] [vc_sm_connected_init]: start [ 12.893747] vc_sm_cma_vchi_init: failed to open VCHI service (-1) [ 12.893769] [vc_sm_connected_init]: failed to initialize shared memory service [ 13.041130] videodev: Linux video capture interface: v2.00 [ 13.141733] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned. [ 13.145598] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned. [ 13.147513] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned. [ 13.162866] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned. [ 13.168839] bcm2835_v4l2: module is from the staging directory, the quality is unknown, you have been warned. [ 13.187155] bcm2835_isp: module is from the staging directory, the quality is unknown, you have been warned. [ 13.261727] bcm2835_audio bcm2835_audio: card created with 8 channels [ 13.267387] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1) [ 13.268532] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1) [ 13.285457] bcm2835_codec: module is from the staging directory, the quality is unknown, you have been warned. [ 13.352746] bcm2835_mmal_vchiq: Failed to open VCHI service connection (status=-1) [ 15.121159] cfg80211: Loading compiled-in X.509 certificates for regulatory database [ 15.567816] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7' [ 16.082596] brcmfmac: F1 signature read @0x18000000=0x1541a9a6 [ 16.099809] brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac43430-sdio for chip BCM43430/1 [ 16.100308] usbcore: registered new interface driver brcmfmac [ 16.123943] brcmfmac mmc1:0001:1: Direct firmware load for brcm/brcmfmac43430-sdio.raspberrypi,model-zero-w.txt failed with error -2 [ 16.395757] brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac43430-sdio for chip BCM43430/1 [ 16.395959] brcmfmac: brcmf_c_process_clm_blob: no clm_blob available (err=-2), device may have limited channels available [ 16.397267] brcmfmac: brcmf_c_preinit_dcmds: Firmware: BCM43430/1 wl0: Oct 22 2019 01:59:28 version 7.45.98.94 (r723000 CY) FWID 01-3b33decd [ 24.980860] 8021q: 802.1Q VLAN Support v1.8 [ 25.203785] uart-pl011 20201000.serial: no DMA platform data [ 25.928446] random: crng init done [ 25.928479] random: 7 urandom warning(s) missed due to ratelimiting [ 27.217331] Adding 102396k swap on /var/swap. Priority:-2 extents:2 across:307200k SSFS [ 27.746282] brcmfmac: brcmf_cfg80211_set_power_mgmt: power save enabled [ 29.471812] Bluetooth: Core ver 2.22 [ 29.471967] NET: Registered protocol family 31 [ 29.471979] Bluetooth: HCI device and connection manager initialized [ 29.472010] Bluetooth: HCI socket layer initialized [ 29.472029] Bluetooth: L2CAP socket layer initialized [ 29.476393] Bluetooth: SCO socket layer initialized [ 29.491930] Bluetooth: HCI UART driver ver 2.3 [ 29.491952] Bluetooth: HCI UART protocol H4 registered [ 29.492191] Bluetooth: HCI UART protocol Three-wire (H5) registered [ 29.497715] Bluetooth: HCI UART protocol Broadcom registered [ 29.554132] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready [ 30.368216] Bluetooth: BNEP (Ethernet Emulation) ver 1.3 [ 30.368235] Bluetooth: BNEP filters: protocol multicast [ 30.368267] Bluetooth: BNEP socket layer initialized [ 31.394240] ICMPv6: process `dhcpcd' is using deprecated sysctl (syscall) net.ipv6.neigh.wlan0.retrans_time - use net.ipv6.neigh.wlan0.retrans_time_ms instead [ 53.812511] using random self ethernet address [ 53.812543] using random host ethernet address [ 53.814823] usb0: HOST MAC m.m.m.m [ 53.816488] usb0: MAC m.m.m.m [ 53.816568] using random self ethernet address [ 53.816583] using random host ethernet address [ 53.816696] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008 [ 53.816710] g_ether gadget: g_ether ready [ 53.816731] dwc2 20980000.usb: bound driver g_ether [ 149.882304] dwc2 20980000.usb: new device is high-speed [ 149.907837] dwc2 20980000.usb: new address 1 [ 149.910319] g_ether gadget: high-speed config #2: RNDIS [ 149.910681] IPv6: ADDRCONF(NETDEV_CHANGE): usb0: link becomes ready [ 160.892236] dwc2 20980000.usb: new device is high-speed [ 161.019949] dwc2 20980000.usb: new device is high-speed [ 161.092758] dwc2 20980000.usb: new address 1 [ 161.114043] g_ether gadget: high-speed config #1: CDC Ethernet (ECM) [ 183.294614] dwc2 20980000.usb: new device is high-speed [ 183.320075] dwc2 20980000.usb: new address 1 [ 183.322522] g_ether gadget: high-speed config #2: RNDIS [ 198.047901] dwc2 20980000.usb: new device is high-speed [ 198.073405] dwc2 20980000.usb: new address 1 [ 198.075872] g_ether gadget: high-speed config #2: RNDIS [ 199.655224] dwc2 20980000.usb: new device is high-speed [ 199.680684] dwc2 20980000.usb: new address 1 [ 199.683121] g_ether gadget: high-speed config #2: RNDIS [ 200.380059] dwc2 20980000.usb: new device is high-speed [ 200.405473] dwc2 20980000.usb: new address 1 [ 200.407920] g_ether gadget: high-speed config #2: RNDIS [ 216.384821] dwc2 20980000.usb: new device is high-speed [ 216.410352] dwc2 20980000.usb: new address 1 [ 216.412803] g_ether gadget: high-speed config #2: RNDIS [ 220.373140] dwc2 20980000.usb: new device is high-speed [ 220.398690] dwc2 20980000.usb: new address 1 [ 220.401155] g_ether gadget: high-speed config #2: RNDIS [ 221.069903] dwc2 20980000.usb: new device is high-speed [ 221.095331] dwc2 20980000.usb: new address 1 [ 221.097685] g_ether gadget: high-speed config #2: RNDIS [ 1017.378601] g_serial gadget: Gadget Serial v2.4 [ 1017.378630] g_serial gadget: g_serial ready [ 1017.378660] dwc2 20980000.usb: bound driver g_serial [ 1326.669766] dwc2 20980000.usb: new device is high-speed [ 1326.797747] dwc2 20980000.usb: new device is high-speed [ 1326.870746] dwc2 20980000.usb: new address 5 [ 1326.892941] g_serial gadget: high-speed config #2: CDC ACM config [ 1636.517458] dwc2 20980000.usb: new device is high-speed [ 1636.645493] dwc2 20980000.usb: new device is high-speed [ 1636.718508] dwc2 20980000.usb: new address 7 [ 1636.743224] g_serial gadget: high-speed config #2: CDC ACM config [ 2164.273235] dwc2 20980000.usb: new device is high-speed [ 2164.298710] dwc2 20980000.usb: new address 2 [ 2164.301160] g_serial gadget: high-speed config #2: CDC ACM config [ 9144.314611] dwc2 20980000.usb: new device is high-speed [ 9144.340096] dwc2 20980000.usb: new address 2 [ 9144.342551] g_serial gadget: high-speed config #2: CDC ACM config [ 9157.086402] dwc2 20980000.usb: new device is high-speed [ 9157.218148] dwc2 20980000.usb: new device is high-speed [ 9157.291268] dwc2 20980000.usb: new address 2 [ 9157.313584] g_serial gadget: high-speed config #2: CDC ACM config [ 9300.208066] dwc2 20980000.usb: new device is high-speed [ 9300.233478] dwc2 20980000.usb: new address 2 [ 9300.235988] g_serial gadget: high-speed config #2: CDC ACM config [ 9548.533463] ISOFS: Unable to identify CD-ROM format. [10823.903599] F2FS-fs (loop0): Magic Mismatch, valid(0xf2f52010) - read(0x0) [10823.903620] F2FS-fs (loop0): Can't find valid F2FS filesystem in 1th superblock [10823.903875] F2FS-fs (loop0): Magic Mismatch, valid(0xf2f52010) - read(0x0) [10823.903892] F2FS-fs (loop0): Can't find valid F2FS filesystem in 2th superblock [11732.299332] device-mapper: ioctl: 4.41.0-ioctl (2019-09-16) initialised: dm-devel@redhat.com [11881.718558] EXT4-fs (dm-1): mounted filesystem with ordered data mode. Opts: (null) [11882.281807] EXT4-fs (dm-2): mounted filesystem with ordered data mode. Opts: (null) [11882.281865] ext4 filesystem being mounted at /mnt/loop0p3 supports timestamps until 2038 (0x7fffffff) [11882.843214] EXT4-fs (dm-3): unable to read superblock [11882.843601] EXT4-fs (dm-3): unable to read superblock [11882.843886] EXT4-fs (dm-3): unable to read superblock [11882.848726] F2FS-fs (dm-3): Unable to read 1th superblock [11882.848765] F2FS-fs (dm-3): Unable to read 2th superblock [11883.334460] F2FS-fs (dm-4): Magic Mismatch, valid(0xf2f52010) - read(0x0) [11883.334482] F2FS-fs (dm-4): Can't find valid F2FS filesystem in 1th superblock [11883.334727] F2FS-fs (dm-4): Magic Mismatch, valid(0xf2f52010) - read(0x0) [11883.334743] F2FS-fs (dm-4): Can't find valid F2FS filesystem in 2th superblock [11883.841823] F2FS-fs (dm-5): Magic Mismatch, valid(0xf2f52010) - read(0x0) [11883.841845] F2FS-fs (dm-5): Can't find valid F2FS filesystem in 1th superblock [11883.842084] F2FS-fs (dm-5): Magic Mismatch, valid(0xf2f52010) - read(0x0) [11883.842101] F2FS-fs (dm-5): Can't find valid F2FS filesystem in 2th superblock [29000.141885] dwc2 20980000.usb: new device is high-speed [29000.167391] dwc2 20980000.usb: new address 2 [29000.169900] g_serial gadget: high-speed config #2: CDC ACM config [29012.794013] dwc2 20980000.usb: new device is high-speed [29012.918648] dwc2 20980000.usb: new device is high-speed [29012.995716] dwc2 20980000.usb: new address 2 [29013.017068] g_serial gadget: high-speed config #2: CDC ACM config [84094.719502] ISO 9660 Extensions: Microsoft Joliet Level 3 [84094.720104] ISO 9660 Extensions: Microsoft Joliet Level 3 [84094.849313] ISO 9660 Extensions: RRIP_1991A [93498.858921] dwc2 20980000.usb: bound driver configfs-gadget [93499.058641] dwc2 20980000.usb: new device is high-speed [93499.186818] dwc2 20980000.usb: new device is high-speed [93499.259699] dwc2 20980000.usb: new address 4 [93499.282541] configfs-gadget gadget: high-speed config #1: c [93683.240849] configfs-gadget gadget: usb_ep_queue error on int endpoint -11 [93683.248992] configfs-gadget gadget: usb_ep_queue error on int endpoint -11 ```
crotoc commented 3 years ago

Have you found a solution for this? Thanks!

ThomasLeister commented 3 years ago

I have run into the same issue a few days ago ... but still after hours of research I couldn't get it working :(

mdevaev commented 3 years ago

I'm fixing it now but I need some information from RPi devs.

@pelwell I'm sorry to bother you, but it seems that dwc2 has a problem with correctly determining the capabilities of the controller (or maybe not). dwc2 considers that the flag hw->hibernation = !!(hwcfg4 & GHWCFG4_HIBER) is 0 on RPi. Is it correct? I tried to force the parameter p->power = DWC2_POWER_DOWN_PARAM_HIBERNATION here and apparently everything works, I was able to wakeup the host (with some other improvements, but the key point was this flag). Is it really 0 or is it actually supported on broadcom and it's lying?

PS: Maybe related with #3151

mdevaev commented 3 years ago

I used the USB protocol analyzer to make sure that it works. Yes, the host really switch the interface in suspend and then using dwc2_gadget_exit_hibernation(*, 1, 0), host immediately wakeups. On the other hand, do I understand correctly the purpose of this function that it should be called by RPi if RPi wants to wakeup the host? The description says that it is initiated by the host, but it has a rem_wakeup parameter that indicates if it is initiated by the device (RPi).

I also found that this code is sufficient to make wakeup work with echo 1 > /sys/devices/platform/soc/fe980000.usb/udc/fe980000.usb/srp. This works in a similar way in dwc3.

The second question is related to this: should I send a wakeup signal using dwc2_hsotg_wakeup and then wait for this event to be processed using dwc2_gadget_exit_hibernation as a callback?

static int dwc2_hsotg_wakeup(struct usb_gadget *gadget)
{
        struct dwc2_hsotg *hsotg = to_hsotg(gadget);
        struct dwc2_dregs_backup *dr = &hsotg->dr_backup;
        u32 dctl;
        unsigned long flags;

        spin_lock_irqsave(&hsotg->lock, flags);

        dwc2_writel(hsotg, dr->dctl | DCTL_RMTWKUPSIG, DCTL);
        mdelay(12);
        dctl = dwc2_readl(hsotg, DCTL);
        dctl &= ~DCTL_RMTWKUPSIG;
        dwc2_writel(hsotg, dctl, DCTL);
        spin_unlock_irqrestore(&hsotg->lock, flags);

        return 0;
}

static const struct usb_gadget_ops dwc2_hsotg_gadget_ops = {
        .get_frame      = dwc2_hsotg_gadget_getframe,
        .set_selfpowered        = dwc2_hsotg_set_selfpowered,
        .udc_start              = dwc2_hsotg_udc_start,
        .udc_stop               = dwc2_hsotg_udc_stop,
        .pullup                 = dwc2_hsotg_pullup,
        .vbus_session           = dwc2_hsotg_vbus_session,
        .vbus_draw              = dwc2_hsotg_vbus_draw,
        .wakeup                 = dwc2_hsotg_wakeup, // <------------------------------------------------
};
crotoc commented 3 years ago

Can not understand what you described. Don't know how to help as well. Sorry!

mdevaev commented 3 years ago

Interesting results. If I force the hibernate flag, then everything is fine for a while, but after 15 minutes the kernel starts to freeze. I probably shouldn't do this.

The second approach - my naive implementation of dwc2_hsotg_wakeup() - gives an interesting effect. It is able to wake up the host, but after that the hid gadget stops working until I reconnect the USB (but it can still send wakeup signal). I suppose this is due to the fact that I do not reset some other flags.

mdevaev commented 3 years ago

Okay, I'm stupid. dr->dctl has invalid value in dwc2_hsotg_wakeup() when hibernation=0 (not forced to 1). I'll try to use dwc2_set_bit/dwc2_cleat_bit later.

But the question remains why the kernel freezes when hibernation=1.

mdevaev commented 3 years ago

dwc2_set_bit/dwc2_cleat_bit is not working. Same result.

pelwell commented 3 years ago

I doubt it will be easy to obtain from Broadcom the Verilog that makes up the DWC OTG controller to discover definitively which features have been enabled, but it shouldn't be necessary. The purpose of the HWCFG<n> registers is to record those settings in a way that can be interrogated by the driver, and they are likely to have been populated automatically by the configuration software that came with the IP from the supplier.

Until you demonstrate that hibernation works properly I see no reason to not believe that it doesn't.

mdevaev commented 3 years ago

@pelwell I think so. My experiments show that this partially works, but eventually leads to a freeze. It seems that either this feature is partially implemented in IP (but not enough to work), or in the case of RPi, something special is required to work properly.

What confuses me is that even without forcing this value, suspend works correctly. That is, I see how the host puts the port to suspend state, then wakes it up (I use a second keyboard for this), and the RPi USB gadget continues to work perfectly again, no matter how many times this cycle occurs.

Do I understand correctly that in the case of RPi, suspend is implemented in hardware and it does not require additional processing from the driver?

pelwell commented 3 years ago

I don't know.

mdevaev commented 3 years ago

Okay, anyway, thanks for the information. I will continue to investigate and maybe find out something.

karn862 commented 3 years ago

Here's a workaround that works for me (on a pi zero w) : https://github.com/karn862/linux/commit/bbb6ccfac814f23930512ec05c0393ac1f593291. I'm calling a modified version of the dwc2_gadget_exit_hibernate function to exit the usb suspend state instead (since we're not hibernated).

I hope this can be helpful in finding a real fix, or at least be a temporary solution for anyone else missing this feature.

I've bought the pi zero w for the sole purpose of using the remote wakeup, so this is good enough for me. I haven't done any extensive testing, but it survives multiple suspend - wakeup sequences, and i can still inject keys in the hidg device afterwards.

Oposum01 commented 3 years ago

Here's a workaround that works for me (on a pi zero w) : karn862@bbb6ccf. I'm calling a modified version of the dwc2_gadget_exit_hibernate function to exit the usb suspend state instead (since we're not hibernated).

I'm still getting the "echo: write error: Resource temporarily unavailable" message, but can confirm the workaround works for me too! I'm now able to "remote-wakeup" and unlock my host system (iPad Pro 2021) with the RPi zero. Thank you very much.

jlian commented 2 years ago

Very little information on this subject on the internet. Aside from this thread I found this post in Japanese http://www.dt8.jp/cgi-bin/adiary/adiary.cgi/0583. Looking at the Google Translate version, it seems the person was able to solve the problem.

They modified two files which I've replicated to my own fork here https://github.com/jlian/linux/compare/raspberrypi:linux:rpi-5.15.y...patch-1. Most importantly, they add dwc2_hsotg_wakeup in gadget.c just like above from @mdevaev and it looks very similar.

static int dwc2_hsotg_wakeup(struct usb_gadget *gadget)
{
       u32 dctl;
       struct dwc2_dregs_backup *dr;
       struct dwc2_hsotg *dev;
       unsigned long flags;
       dev = container_of(gadget, struct dwc2_hsotg, gadget);
       dr = &dev->dr_backup;

       spin_lock_irqsave(&dev->lock, flags);
       udelay(10);

       /* Start Remote Wakeup Signaling */
       dwc2_writel(dr->dctl | DCTL_RMTWKUPSIG, dev->regs + DCTL);
       mdelay(12);
       dctl = dwc2_readl(dev->regs + DCTL);
       dctl &= ~DCTL_RMTWKUPSIG;
       dwc2_writel(dctl, dev->regs + DCTL);

       spin_unlock_irqrestore(&dev->lock, flags);

       return 0;
}

I can't speak Japanese, don't understand most of this, nor have I tried this myself (looks like I'll have compile the kernel?). But I thought this information might be helpful to folks on this thread 😅.

mdevaev commented 2 years ago

@jlian It will not work :) In 5.15 dwc2 started performing clock gating and it broke the patch. The good news is that I figured out how to fix it the right way: https://github.com/pikvm/packages/blob/master/packages/linux-rpi-pikvm/1003-remote-wakeup.patch

jlian commented 2 years ago

Oh wow, I'm glad that I made the comment to learn about the actual fix!

@mdevaev is this also fixed in the upstream Linux kernel? Do you have any pointers on how I might apply your patch if I'm using https://github.com/homebridge/homebridge-raspbian-image?

mdevaev commented 2 years ago

This patch is suitable for upstream 5.15. But I haven't used homebridge since I'm building kernels for Arch.

jlian commented 2 years ago

@mdevaev I applied your patch, compiled the kernel, and put onto my Raspberry Pi 4 (notes https://github.com/jlian/linux-kernel-cross-compile). Unfortunately it didn't seem to fix it for me. I'm pretty (?) sure that I did the patching/compilation correctly, but it's my first time doing so and I'm not even sure how to check that my Pi is using the patched kernel or not.

Below command writes "whatup" if the computer is awake. With a sleeping computer it errors out like before.

pi@homebridge:~ $ echo -ne "\0\0\x1a\x0b\x04\x17\x18\x13" > /dev/hidg0 &&   echo -ne "\0\0\0\0\0\0\0\0" > /dev/hidg0
-bash: echo: write error: Resource temporarily unavailable

EDIT: I also did echo 0xa0 > configs/c.1/bmAttributes following this post https://www.rmedgar.com/blog/using-rpi-zero-as-keyboard-setup-and-device-definition/ and still it doesn't fix it. I checked that it's applied by

pi@homebridge:~ $ cat /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes 
0xa0
mdevaev commented 2 years ago

You need to enable wakeup_on_write in the driver: echo 1 > /sys/kernel/config/usb_gadget/GADGET/functions/hid.usb0/wakeup_on_write

jlian commented 2 years ago

Whoa! It worked! Thanks so much @mdevaev ! I hope the patch gets included in the official kernel soon 🥇

mdevaev commented 2 years ago

Ur welcome. I haven't sent it yet as it slightly duplicates the existing code. When I have time, I will try to put it in order. The good news is that I will be maintaining it in my repository anyway.

seamusdemora commented 2 years ago

@mdevaev - a bit off-topic reply here, but: awesome project - a KVM from a Raspberry Pi!

mdevaev commented 2 years ago

Thanks)

crotoc commented 2 years ago

Hey guys, thanks for the great solution. Can this be applied to Pi zero?

mdevaev commented 2 years ago

Patch - yes. PiKVM - you need zero2 at least.

crotoc commented 2 years ago

Patch - yes. PiKVM - you need zero2 at least.

Thanks! What I want is connecting pi 0 to usb and acts as a keyboard. Then connect to wifi. I would like to connect it through ssh and wake up my computer. Can you tell me whether this is able to work? :)

mdevaev commented 2 years ago

Yea, why not.

crotoc commented 2 years ago

Awesome! Unluckily, zero 2 wifi is out of stock everywhere..... I returned mine because it didn't work when I found this thread one year ago

pelwell commented 2 years ago

@mdevaev GIve us a poke when your final patch makes it upstream and we'll back-port it.

mdevaev commented 2 years ago

@pelwell okay!

Bendbk commented 1 year ago

You need to enable wakeup_on_write in the driver: echo 1 > /sys/kernel/config/usb_gadget/GADGET/functions/hid.usb0/wakeup_on_write

Hello, I'm trying to apply this after having recompiled Linux with the patch, but I have a message error saying that device or ressource is busy... any idea where I'm doing wrong ? Thanks a lot !

Bendbk commented 1 year ago

My bad I did it the wrong way (trying to change the value after configuration is just a bad idea ^^).

It works 100% (when you don't forgot the right bmAttributes)

afsluit commented 10 months ago

Is there any other way to wake up the host via gadget mode besides this patch? I'd be fine with having to check whether the write was successful and then sending the signal if it wasn't. There really isn't much documentation on this specific topic out there.

mdevaev commented 10 months ago

No. You need to affect the USB at a low level, this is impossible without a patch.

Dan-Essin commented 5 months ago

I struggled with this for a month with my zero and it never worked so, this is way off topic, but if the goal is to wake up the computer rather than to do it with an rpi at all cost there is a solution. Since this solution requires a zero2, some $$ need to be spent. An alternative is to spend $ on a pico w. Circuitpython version 9 includes wakeup support. I have it running using mosquitto_sub on the pico to triger the hid functions. Then I just publish a message from where I am working and the machine connected to the pico wakes up. I have two of them so I just change the topic to the machine name and the one I want wakes up. I have a short powershell script that prompts for machine name and runs the pub command. I can post the code if mentioning a pico in this thread doesn't offend anyone

aidatorajiro commented 5 months ago

I built some utility tool to build and deploy modified kernel

https://github.com/aidatorajiro/rpizero-linux-build

ysleman commented 4 months ago

I built some utility tool to build and deploy modified kernel

https://github.com/aidatorajiro/rpizero-linux-build

Can i build it on raspbian for rpi4 , like how do i do it do i need to run it like normal and burn it into sdcard or what ?