usb gadget does not work with armbian

  • the Device Tree of the tinker os image
    • gotten by: using nixpkgs.mkbootimg-osm0sis on /dev/loop0p4 (losetup -Pf TinkerBoard2Debian.img)… and then nixpkgs.binwalk with nixpkgs.dtc to extract it from “the second stage (loop0p4-second)”
      usb@fe800000 {
                compatible = "rockchip,rk3399-dwc3";
                #address-cells = <0x02>;
                #size-cells = <0x02>;
                ranges;
                clocks = <0x08 0x81 0x08 0x83 0x08 0xf6 0x08 0xf8 0x08 0x
f4 0x08 0xf9>;
                clock-names = "ref_clk", "suspend_clk", "bus_clk", "aclk_
usb3_rksoc_axi_perf", "aclk_usb3", "grf_clk";
                status = "okay";
                phandle = <0x108>;

                usb@fe800000 {
                        compatible = "snps,dwc3";
                        reg = <0x00 0xfe800000 0x00 0x100000>;
                        interrupts = <0x00 0x69 0x04 0x00>;
                        clocks = <0x08 0x81 0x08 0xf6 0x08 0x83>;
                        clock-names = "ref", "bus_early", "suspend";
                        resets = <0x08 0x125>;
                        reset-names = "usb3-otg";
                        dr_mode = "otg";
                        phys = <0x35 0x36>;
                        phy-names = "usb2-phy", "usb3-phy";
                        phy_type = "utmi_wide";
                        snps,dis_enblslpm_quirk;
                        snps,dis-u1-entry-quirk;
                        snps,dis-u2-entry-quirk;
                        snps,dis-u2-freeclk-exists-quirk;
                        snps,dis_u2_susphy_quirk;
                        snps,dis-del-phy-power-chg-quirk;
                        snps,dis-tx-ipgap-linecheck-quirk;
                        snps,parkmode-disable-hs-quirk;
                        snps,parkmode-disable-ss-quirk;
                        power-domains = <0x1f 0x18>;
                        status = "okay";
                        usb-role-switch;
                        phandle = <0x109>;

                        port {
                                #address-cells = <0x01>;
                                #size-cells = <0x00>;

                                endpoint@0 {
                                        reg = <0x00>;
                                        remote-endpoint = <0x37>;
                                        phandle = <0x98>;
                                };

                                endpoint@1 {
                                        reg = <0x01>;
                                        remote-endpoint = <0x38>;
                                        phandle = <0x9c>;
                                };
                        };
                };
        };
        usb@fe800000 {
                compatible = "rockchip,rk3399-dwc3";
                #address-cells = <0x02>;
                #size-cells = <0x02>;
                ranges;
                clocks = <0x08 0x81 0x08 0x83 0x08 0xf6 0x08 0xf8 0x08 0x
f4 0x08 0xf9>;
                clock-names = "ref_clk", "suspend_clk", "bus_clk", "aclk_
usb3_rksoc_axi_perf", "aclk_usb3", "grf_clk";
                resets = <0x08 0x125>;
                reset-names = "usb3-otg";
                status = "okay";
                phandle = <0xcc>;

                usb@fe800000 {
                        compatible = "snps,dwc3";
                        reg = <0x00 0xfe800000 0x00 0x100000>;
                        interrupts = <0x00 0x69 0x04 0x00>;
                        clocks = <0x08 0x81 0x08 0xf6 0x08 0x83>;
                        clock-names = "ref", "bus_early", "suspend";
                        dr_mode = "host";
                        phys = <0x2e 0x2f>;
                        phy-names = "usb2-phy", "usb3-phy";
                        phy_type = "utmi_wide";
                        snps,dis_enblslpm_quirk;
                        snps,dis-u2-freeclk-exists-quirk;
                        snps,dis_u2_susphy_quirk;
                        snps,dis-del-phy-power-chg-quirk;
                        snps,dis-tx-ipgap-linecheck-quirk;
                        snps,xhci-trb-ent-quirk;
                        power-domains = <0x1e 0x18>;
                        status = "okay";
                        phandle = <0xcd>;
                };
        };
  • so with TinkerOS the usb gadget does just work… so I will use that for now. (meaning no fancy netword)

  • /root/here/disk.img created with dd and formated with gparted to contain an Efi boot Partition

  • script to setup the usb gadget:

#!/usr/bin/env bash

# mount configfs
! findmnt /sys/kernel/config && mount -t configfs none /sys/kernel/config
# load libcomposite module
modprobe libcomposite
# create a gadget
mkdir -p /sys/kernel/config/usb_gadget/g1
# cd to its configfs node
cd /sys/kernel/config/usb_gadget/g1

# configure it (vid/pid can be anything if USB Class is used for driver compat)
echo 0xabcd > idVendor
echo 0x1234 > idProduct

# configure its serial/mfg/product
mkdir strings/0x409
echo myserial > strings/0x409/serialnumber
echo mymfg > strings/0x409/manufacturer
echo myproduct > strings/0x409/product

# create configs
mkdir configs/c.1
#mkdir configs/c.2
mkdir configs/c.3

# configure them with attributes if needed
echo 120 > configs/c.1/MaxPower
#echo 120 > configs/c.2/MaxPower
#echo 120 > configs/c.2/MaxPower

# ensure function is loaded
modprobe usb_f_mass_storage
# create the function (name must match a usb_f_<name> module such as 'acm')
mkdir -p functions/mass_storage.0
# create backing store(s): in this example 2 LUN's 16MB each
#dd bs=1M count=16 if=/dev/zero of=/tmp/lun0.img # 16MB
#dd bs=1M count=16 if=/dev/zero of=/tmp/lun1.img # 16MB
# associate with partitions
mkdir -p functions/mass_storage.0/lun.0
echo /root/here/disk.img > functions/mass_storage.0/lun.0/file
#mkdir functions/mass_storage.0/lun.1
#echo /tmp/lun1.img > functions/mass_storage.0/lun.1/file
# associate function with config
ln -fs functions/mass_storage.0 configs/c.1
# enable gadget by binding it to a UDC from /sys/class/udc
echo fe800000.usb > UDC
# to unbind it: echo "" > UDC; sleep 1; rm -rf /sys/kernel/config/usb_gadget/g1
  • i had to disable some adb service stuff… which normally uses the gadget