I want to create a USB gadget with a raspberry pi zero 2W. I’m starting with imitating a webcam I already have to see how much of this I can figure out. I’ve used the online documentation and a couple AI bots to get this far quickly, but I’m hung up on a ln command. It’s telling me “ln: failed to create symbolic link ‘configs/c.1/uvc.usb0’: No such file or directory” when trying to create the link. This makes no sense to me though. I’m trying to create the link, of course it doesn’t exist yet. That’s what that command is supposed to do.

I’ve confirmed this problem in alpine linux and raspbian lite.

Below is the little script I have so far just to create the device:

#!/bin/bash
modprobe libcomposite
cd /sys/kernel/config/usb_gadget/
mkdir -p fauxcam
cd fauxcam
echo 0x046d > idVendor  # Logitech Vendor ID
echo 0x094b > idProduct # Brio 105 Product ID
echo 0x0200 > bcdUSB
echo 0x9914 > bcdDevice
mkdir -p strings/0x409
echo "111111111111" > strings/0x409/serialnumber
echo "Brio 105" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "UVC Configuration" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
mkdir -p functions/uvc.usb0
ln -s functions/uvc.usb0 configs/c.1/
echo "usb0" > UDC
    • muusemuuse@lemm.eeOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 days ago

      no change

      ln: failed to create symbolic link 'configs/c.1/uvc.usb0': No such file or directory
      ./fauxcam-gadget.sh: line 19: echo: write error: Device or resource busy
      
        • muusemuuse@lemm.eeOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          2 days ago

          Looking at those units I noticed something… ExecStart=/usr/bin/ln -s ${GADGET}/functions/uvc.0 ${GADGET}/configs/a.1/

          It’s an a.1 instead of a c.1. Surely it couldn’t be as simple as just using a different letter, could it?

            • muusemuuse@lemm.eeOP
              link
              fedilink
              English
              arrow-up
              1
              ·
              2 days ago

              Once I crack this, I think it could be fun to create a script that could spoof devices plugged into it with the gadget framework. Could save me a lot of trouble creating known-working usb configs down the road. Instead of starting from scratch each time, I would just have to tweak an existing profile.

                • muusemuuse@lemm.eeOP
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  2 days ago

                  Honestly it’s just an idea to suck up time at this point. I do NOT have the skills for this shit, as we can see here. I can correct what ChatGPT gets wrong though and just run with that.

                  • dafta@lemmy.blahaj.zone
                    link
                    fedilink
                    English
                    arrow-up
                    1
                    ·
                    edit-2
                    1 day ago

                    You should definitely try with the systemd-gadgets I linked earlier. It makes all the configuration really easy, you just need to enable the relevant services, so in your case usbgadget-func-uvc.service and gadget-start.service. You also need to copy them beforehand to /etc/systemd/system, including gadget-init.service, and you need to copy gadget to /etc/default/gadget, and the scripts gadget-start.sh and gadget-init.sh to /etc/systemd/scripts. Edit /etc/default/gadget to edit the configs and names of the gadget, and then start gadget-start.service. No need to enable gadget-init.service, it’s called as a dependency from other services.

                    There’s an install script in the repo that you can use as well, setup.sh, and a PKGBUILD so you can create an Arch package. After installing with either method, just change /etc/default/gadget, enable the uvc and gadget start services, and then just start the gadget start service.