This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/PROCESSOR-SDK-AM335X: USB Ethernet gadget and UDHCPD

Part Number: PROCESSOR-SDK-AM335X
Other Parts Discussed in Thread: AM3352, TPS65217

Tool/software: Linux

Dear community,

I'm struggling with getting USB gadget to work. I'm using Buildroot to build Linux (official kernel 4.9 provided by TI) and all other stuff. I figured out the TI SDK uses Busybox to provide udhcpd so I also added this program to my Busybox. Only to clarification I added RNDIS as the kernel module. I'm able to modprobe g_ether and ever manually start udhcpd. I'm just looking for way to make the USB ethernet connection to PC automatically at startup.

After more investigation of prepared TI rootfs (tisdk-rootfs-image-am335x-evm.tar.xz) I found sh script which is used to start dhcp server in /etc/init.d/busybox-udhcp. I also found service for usb gadget /lib/systemd/system/gadget-init.service which wants busybox-udhcp.service but I cannot find where the busybox-udhcp.service is created.

I have several questions about this issue. I know TI uses Yocto to build SDK, fs and all other. I chose Buildroot because it looked more strait forward. 

Could anybody help me with this?

Does the busybox-udhcp.service has something to do with okpg manager?

Is there automated way to start and use the Busybox programs instead manually creating all configuration and sh scripts?

As you could notice I'm pretty new in Linux world so I will be grateful if you can provide any materials I should study.

  • Filip,

    I didn't check the systemd scripts in the TI Processor SDK rootfs, but here are a few basic pointers to get usb-ethernet working on am335x with a host pc. You have many ways to automate the configurations after you understand the fundamental requirements, systemd or sysv scripting.

    - once loaded g_ether driver and connected the am335x usb peripheral port to a usb host port, it creates usbX(typically it is usb0) network interface on both am335x and the host pc. You can find them using 'ifcongfig -a' command on both am335x and host pc.

    - typically you run the dhcp server (dhcpd) on the pc, not am335x.

    - the host pc has to assign an ip address to the host side usbX interface, the ip address has to be in the network which configured in the dhcp server. Then the dhcp client on am335x side should be able to get an ip address for usbX interface on am335x through dhcp request. Now the network connection is created.
  • Dear Bin,

    yes I completely understand that. So could you suggest any of that ways how to automate the configuration?

    I don't think the DHCP server is usually on host PC. For example BeagleBone runs DHCP server so the host PC gets IP address from BB via the usb0. (192.168.7.0 255.255.255.252 network for 2 devices). Even in TI SDK the am335x runs udhcp.

    Do you use systemd and usb gadget or dhcp server on target machine? Could you provide some real examples?

    Many thanks
  • Filip,

    As I mentioned, you can write your own systemd or sysv script to automate this, after you understand the pointers I listed above and you can manually create the network connection. Unfortunately I don't have such automation examples. I am the one to support USB subsystem, I typically use manual configurations to verify all these type of USB usecases. But there is plenty of information on Internet showing how to configure dhcp servers and how to use usb-ethernet gadget.

    Of cause you can run dhcp server on am335x and dhcp client on host PC, that is perfectly fine. You just need to swap some of the information in my first response to make it applicable for dhcpd on am335x and dhcpc on host PC.
  • Hello Bin,

    I have still no progress. Now I went away from dhcp and I only want to configure the interface right. This is my setup:

    /etc/systemd/system/gadget-init.service (it is enabled. So it is loaded on boot)
    ---------------------------------------------------------------------
    [Unit]
    Description=Start USB gadget
    Requires=dev-mmcblk0p2.device

    After=dev-mmcblk0p2.device

    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=/usr/bin/gadget-init.sh
    ExecStop=/sbin/rmmod g_multi

    [Install]
    WantedBy=basic.target



    /usr/bin/gadget-init.sh
    ---------------------------------------------------------------------
    #!/bin/sh

    # Based off:
    # github.com/.../am335x_evm.sh

    # Assume some defaults
    SERIAL_NUMBER="1234BBBK5678"
    PRODUCT="am335x_evm"
    manufacturer="ti.com"

    # Read serial numberfrom the eerpom
    eeprom="/sys/bus/i2c/devices/0-0050/eeprom"
    if [ -f ${eeprom} ] ; then
    SERIAL_NUMBER=$(hexdump -e '8/1 "%c"' ${eeprom} -n 28 | cut -b 17-28)
    PRODUCT="BeagleBoneBlack"
    manufacturer="BeagleBoard.org"
    fi

    echo "SERIAL_NUMBER = ${SERIAL_NUMBER}"
    echo "PRODUCT = ${PRODUCT}"

    #save location of MAC address, otherwise exit
    mac_address="/proc/device-tree/ocp/ethernet@4a100000/slave@4a100300/mac-address"
    [ -r "$mac_address" ] || exit 0

    #save MAC address as address of this device
    dev_addr=$(/usr/bin/hexdump -v -e '5/1 "%02X:" 1/1 "%02X"' "$mac_address")
    echo "dev_addr = ${dev_addr}"

    #define static MAC for host PC. Swap last digit to 0
    host_addr="${dev_addr:0:-1}0"
    echo "host_addr = ${host_addr}"

    # Set the g_multi parameters (read-write, removable)
    g_defaults="cdrom=0 ro=0 stall=0 removable=1 nofua=1"
    g_product="iSerialNumber=${SERIAL_NUMBER} iManufacturer=${manufacturer} iProduct=${PRODUCT}"
    g_network="dev_addr=${dev_addr} host_addr=${host_addr}"
    g_storage="file=/dev/mmcblk0p2"

    #start g_multi module. It starts usb0 interface and mounts rootfs as removable device
    modprobe g_multi ${g_storage} ${g_defaults} ${g_product} ${g_network}

    # Bring up the USB network interface
    ifup usb0



    /etc/network/interfaces
    ---------------------------------------------------------------------
    iface usb0 inet static
    address 192.168.7.2
    netmask 255.255.255.252


    here is my console prompt with some additional info after boot:

    Starting kernel ...

    [ 0.000000] Booting Linux on physical CPU 0x0
    [ 0.000000] Linux version 4.9.59 (filip@filip-ThinkPad-Edge-E330) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11) ) #1 PREEMPT Wed 8
    [ 0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d
    [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
    [ 0.000000] OF: fdt:Machine model: TI AM335x BeagleBone Black
    [ 0.000000] efi: Getting EFI parameters from FDT:
    [ 0.000000] efi: UEFI not found.
    [ 0.000000] cma: Reserved 48 MiB at 0x9d000000
    [ 0.000000] Memory policy: Data cache writeback
    [ 0.000000] CPU: All CPU(s) started in SVC mode.
    [ 0.000000] AM335X ES2.1 (sgx neon)
    [ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 129920
    [ 0.000000] Kernel command line: console=ttyO0,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait
    [ 0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
    [ 0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
    [ 0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
    [ 0.000000] Memory: 457972K/524288K available (7168K kernel code, 281K rwdata, 2368K rodata, 1024K init, 280K bss, 17164K reserved, 4915)
    [ 0.000000] Virtual kernel memory layout:
    [ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB)
    [ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
    [ 0.000000] vmalloc : 0xe0800000 - 0xff800000 ( 496 MB)
    [ 0.000000] lowmem : 0xc0000000 - 0xe0000000 ( 512 MB)
    [ 0.000000] pkmap : 0xbfe00000 - 0xc0000000 ( 2 MB)
    [ 0.000000] modules : 0xbf000000 - 0xbfe00000 ( 14 MB)
    [ 0.000000] .text : 0xc0008000 - 0xc0800000 (8160 kB)
    [ 0.000000] .init : 0xc0b00000 - 0xc0c00000 (1024 kB)
    [ 0.000000] .data : 0xc0c00000 - 0xc0c465e8 ( 282 kB)
    [ 0.000000] .bss : 0xc0c465e8 - 0xc0c8c834 ( 281 kB)
    [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
    [ 0.000000] Preemptible hierarchical RCU implementation.
    [ 0.000000] Build-time adjustment of leaf fanout to 32.
    [ 0.000000] NR_IRQS:16 nr_irqs:16 16
    [ 0.000000] IRQ: Found an INTC at 0xfa200000 (revision 5.0) with 128 interrupts
    [ 0.000000] OMAP clockevent source: timer2 at 24000000 Hz
    [ 0.000014] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
    [ 0.000031] clocksource: timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
    [ 0.000039] OMAP clocksource: timer1 at 24000000 Hz
    [ 0.000187] clocksource_probe: no matching clocksources found
    [ 0.000355] Console: colour dummy device 80x30
    [ 0.000380] WARNING: Your 'console=ttyO0' has been replaced by 'ttyS0'
    [ 0.000385] This ensures that you still see kernel messages. Please
    [ 0.000390] update your kernel commandline.
    [ 0.000412] Calibrating delay loop... 996.14 BogoMIPS (lpj=4980736)
    [ 0.089248] pid_max: default: 32768 minimum: 301
    [ 0.089361] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
    [ 0.089371] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
    [ 0.090078] CPU: Testing write buffer coherency: ok
    [ 0.090417] Setting up static identity map for 0x80100000 - 0x80100060
    [ 0.091150] EFI services will not be available.
    [ 0.092301] devtmpfs: initialized
    [ 0.102161] VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 3
    [ 0.102486] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
    [ 0.102509] futex hash table entries: 256 (order: -1, 3072 bytes)
    [ 0.106024] pinctrl core: initialized pinctrl subsystem
    [ 0.107128] NET: Registered protocol family 16
    [ 0.108787] DMA: preallocated 256 KiB pool for atomic coherent allocations
    [ 0.199242] cpuidle: using governor ladder
    [ 0.229229] cpuidle: using governor menu
    [ 0.234527] OMAP GPIO hardware version 0.1
    [ 0.247892] No ATAGs?
    [ 0.247916] hw-breakpoint: debug architecture 0x4 unsupported.
    [ 0.286342] edma 49000000.edma: TI EDMA DMA engine driver
    [ 0.289132] omap_i2c 44e0b000.i2c: could not find pctldev for node /ocp/l4_wkup@44c00000/scm@210000/pinmux@800/pinmux_i2c0_pins, deferrie
    [ 0.289188] omap_i2c 4819c000.i2c: could not find pctldev for node /ocp/l4_wkup@44c00000/scm@210000/pinmux@800/pinmux_i2c2_pins, deferrie
    [ 0.289438] media: Linux media interface: v0.10
    [ 0.289490] Linux video capture interface: v2.00
    [ 0.289528] pps_core: LinuxPPS API ver. 1 registered
    [ 0.289534] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
    [ 0.289554] PTP clock support registered
    [ 0.289599] EDAC MC: Ver: 3.0.0
    [ 0.290580] omap-mailbox 480c8000.mailbox: omap mailbox rev 0x400
    [ 0.290875] Advanced Linux Sound Architecture Driver Initialized.
    [ 0.291983] clocksource: Switched to clocksource timer1
    [ 0.300888] NET: Registered protocol family 2
    [ 0.301559] TCP established hash table entries: 4096 (order: 2, 16384 bytes)
    [ 0.301605] TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
    [ 0.301642] TCP: Hash tables configured (established 4096 bind 4096)
    [ 0.301705] UDP hash table entries: 256 (order: 0, 4096 bytes)
    [ 0.301720] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
    [ 0.301837] NET: Registered protocol family 1
    [ 0.302283] RPC: Registered named UNIX socket transport module.
    [ 0.302294] RPC: Registered udp transport module.
    [ 0.302299] RPC: Registered tcp transport module.
    [ 0.302304] RPC: Registered tcp NFSv4.1 backchannel transport module.
    [ 0.303118] hw perfevents: enabled with armv7_cortex_a8 PMU driver, 5 counters available
    [ 0.305181] workingset: timestamp_bits=14 max_order=17 bucket_order=3
    [ 0.311658] squashfs: version 4.0 (2009/01/31) Phillip Lougher
    [ 0.312662] NFS: Registering the id_resolver key type
    [ 0.312705] Key type id_resolver registered
    [ 0.312712] Key type id_legacy registered
    [ 0.312754] ntfs: driver 2.1.32 [Flags: R/O].
    [ 0.314418] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 246)
    [ 0.314434] io scheduler noop registered
    [ 0.314441] io scheduler deadline registered
    [ 0.314583] io scheduler cfq registered (default)
    [ 0.315755] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568
    [ 0.369244] Serial: 8250/16550 driver, 10 ports, IRQ sharing disabled
    [ 0.372586] 44e09000.serial: ttyS0 at MMIO 0x44e09000 (irq = 158, base_baud = 3000000) is a 8250
    [ 0.961150] console [ttyS0] enabled
    [ 0.966211] omap_rng 48310000.rng: OMAP Random Number Generator ver. 20
    [ 0.973028] [drm] Initialized
    [ 0.988095] brd: module loaded
    [ 0.996835] loop: module loaded
    [ 1.001888] libphy: Fixed MDIO Bus: probed
    [ 1.072057] davinci_mdio 4a101000.mdio: davinci mdio revision 1.6
    [ 1.078192] davinci_mdio 4a101000.mdio: no live phy, scanning all
    [ 1.084642] davinci_mdio: probe of 4a101000.mdio failed with error -5
    [ 1.091664] cpsw 4a100000.ethernet: Detected MACID = 50:65:83:d5:08:dc
    [ 1.098367] cpsw 4a100000.ethernet: device node lookup for pps timer failed
    [ 1.105405] cpsw 4a100000.ethernet: cpts: overflow check period 500 (jiffies)
    [ 1.114248] mousedev: PS/2 mouse device common for all mice
    [ 1.120311] i2c /dev entries driver
    [ 1.125527] cpuidle: enable-method property 'ti,am3352' found operations
    [ 1.133212] omap_hsmmc 48060000.mmc: Got CD GPIO
    [ 1.237432] mmc0: host does not support reading read-only switch, assuming write-enable
    [ 1.245570] mmc0: new SDHC card at address 0001
    [ 1.250705] mmcblk0: mmc0:0001 SD 7.38 GiB
    [ 1.256203] ledtrig-cpu: registered to indicate activity on CPUs
    [ 1.264888] NET: Registered protocol family 10
    [ 1.265965] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
    [ 1.266655] NET: Registered protocol family 17
    [ 1.266902] Key type dns_resolver registered
    [ 1.267126] omap_voltage_late_init: Voltage driver support not added
    [ 1.299147] mmcblk0: p1 p2
    [ 1.335985] random: fast init done
    [ 1.343125] tps65217 0-0024: TPS65217 ID 0xe version 1.2
    [ 1.349018] at24 0-0050: 32768 byte 24c256 EEPROM, writable, 1 bytes/write
    [ 1.376440] mmc1: new high speed MMC card at address 0001
    [ 1.382547] mmcblk1: mmc1:0001 S10004 3.56 GiB
    [ 1.387326] mmcblk1boot0: mmc1:0001 S10004 partition 1 4.00 MiB
    [ 1.393539] mmcblk1boot1: mmc1:0001 S10004 partition 2 4.00 MiB
    [ 1.400608] mmcblk1: p1
    [ 1.494327] tda998x 0-0070: found TDA19988
    [ 1.499635] tilcdc 4830e000.lcdc: bound 0-0070 (ops tda998x_ops)
    [ 1.505731] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
    [ 1.512390] [drm] No driver support for vblank timestamp query.
    [ 1.518640] tilcdc 4830e000.lcdc: No connectors reported connected with modes
    [ 1.525847] [drm] Cannot find any crtc or sizes - going 1024x768
    [ 1.539950] Console: switching to colour frame buffer device 128x48
    [ 1.551232] tilcdc 4830e000.lcdc: fb0: frame buffer device
    [ 1.582686] omap_i2c 44e0b000.i2c: bus 0 rev0.11 at 400 kHz
    [ 1.702814] omap_i2c 4819c000.i2c: bus 2 rev0.11 at 100 kHz
    [ 1.710348] hctosys: unable to open rtc device (rtc0)
    [ 1.716027] ALSA device list:
    [ 1.719015] No soundcards found.
    [ 1.731257] EXT4-fs (mmcblk0p2): warning: mounting fs with errors, running e2fsck is recommended
    [ 1.742667] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
    [ 1.750861] VFS: Mounted root (ext4 filesystem) on device 179:2.
    [ 1.758603] devtmpfs: mounted
    [ 1.763125] Freeing unused kernel memory: 1024K
    [ 2.153714] systemd[1]: System time before build time, advancing clock.
    [ 2.195580] cgroup: cgroup2: unknown option "nsdelegate"
    [ 2.234201] systemd[1]: systemd 236 running in system mode. (-PAM -AUDIT -SELINUX -IMA -APPARMOR -SMACK +SYSVINIT +UTMP -LIBCRYPTSETUP -)
    [ 2.255907] systemd[1]: Detected architecture arm.

    Welcome to Buildroot 2018.02-git!

    [ 2.293433] systemd[1]: Set hostname to <prusa_pro>.
    [ 2.747395] systemd[1]: File /usr/lib/systemd/system/systemd-journald.service:35 configures an IP firewall (IPAddressDeny=any), but the .
    [ 2.765054] systemd[1]: Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewal)
    [ 2.956192] systemd[1]: Configuration file /etc/systemd/system/gadget-init.service is marked executable. Please remove executable permis.
    [ 3.007345] systemd[1]: System is tainted: var-run-bad
    [ 3.024172] systemd[1]: Created slice System Slice.
    [ OK ] Created slice System Slice.
    [ 3.052428] systemd[1]: Reached target Remote File Systems.
    [ OK ] Reached target Remote File Systems.
    [ 3.082264] systemd[1]: Reached target Swap.
    [ OK ] Reached target Swap.
    [ OK ] Listening on udev Control Socket.
    [ OK ] Listening on Network Service Netlink Socket.
    [ OK ] Started Dispatch Password Requests to Console Directory Watch.
    Mounting Kernel Debug File System...
    [ OK ] Listening on Journal Socket (/dev/log).
    [ OK ] Listening on /dev/initctl Compatibility Named Pipe.
    Mounting Temporary Directory (/tmp)...
    [ OK ] Listening on Journal Socket.
    Mounting Kernel Configuration File System...
    Starting Remount Root and Kernel File Systems...
    [ OK ] Created slice system-serial\x2dgetty.slice.
    [ 3.497004] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
    Starting Create Static Device Nodes in /dev...
    [ OK ] Listening on udev Kernel Socket.
    Starting udev Coldplug all Devices...
    Starting Apply Kernel Variables...
    Starting Journal Service...
    Mounting POSIX Message Queue File System...
    [ OK ] Started Forward Password Requests to Wall Directory Watch.
    [ OK ] Reached target Paths.
    [ OK ] Reached target Slices.
    [ OK ] Mounted Kernel Debug File System.
    [ OK ] Mounted Kernel Configuration File System.
    [ OK ] Mounted POSIX Message Queue File System.
    [ OK ] Mounted Temporary Directory (/tmp).
    [ OK ] Started Remount Root and Kernel File Systems.
    [ OK ] Started Create Static Device Nodes in /dev.
    [ OK ] Started Apply Kernel Variables.
    [ OK ] Reached target Local File Systems (Pre).
    Starting Rebuild Hardware Database...
    [ OK ] Reached target Local File Systems.
    Starting Rebuild Journal Catalog...
    [ OK ] Started Journal Service.
    Starting Flush Journal to Persistent Storage...
    [ 4.184710] systemd-journald[96]: Received request to flush runtime journal from PID 1
    [ OK ] Started Rebuild Journal Catalog.
    [ 4.238334] systemd-journald[96]: File /var/log/journal/cfc70d28f96846dcb211049fecd8e8a4/system.journal corrupted or uncleanly shut down.
    [ OK ] Started Flush Journal to Persistent Storage.
    Starting Create Volatile Files and Directories...
    [ OK ] Started Create Volatile Files and Directories.
    Starting Update UTMP about System Boot/Shutdown...
    Starting Network Time Synchronization...
    [ OK ] Started Update UTMP about System Boot/Shutdown.
    [ OK ] Started Network Time Synchronization.
    [ OK ] Reached target System Time Synchronized.
    [ OK ] Started udev Coldplug all Devices.
    [ OK ] Started Rebuild Hardware Database.
    Starting Update is Completed...
    Starting udev Kernel Device Manager...
    [ OK ] Started Update is Completed.
    [ OK ] Started udev Kernel Device Manager.
    Starting Network Service...
    [ OK ] Reached target System Initialization.
    [ OK ] Listening on D-Bus System Message Bus Socket.
    [ OK ] Reached target Sockets.
    [ OK ] Reached target Basic System.
    [ OK ] Started Daily Cleanup of Temporary Directories.
    [ OK ] Reached target Timers.
    [ OK ] Started D-Bus System Message Bus.
    [ OK ] Started Network Service.
    [ 8.855124] systemd-journald[96]: File /var/log/journal/cfc70d28f96846dcb211049fecd8e8a4/user-1005.journal corrupted or uncleanly shut d.
    [ OK ] Reached target Network.
    Starting Network Name Resolution...
    [ OK ] Found device /dev/ttyS0.
    [ OK ] Started Serial Getty on ttyS0.
    [ 9.130477] omap_wdt: OMAP Watchdog Timer Rev 0x01: initial timeout 60 sec
    [ 9.186768] omap_rtc 44e3e000.rtc: already running
    [ 9.220757] omap_rtc 44e3e000.rtc: rtc core: registered 44e3e000.rtc as rtc0
    [ 9.578480] systemd-journald[96]: File /var/log/journal/cfc70d28f96846dcb211049fecd8e8a4/user-1006.journal corrupted or uncleanly shut d.
    [ OK ] Started Network Name Resolution.
    [ 9.778336] omap-sham 53100000.sham: hw accel on OMAP rev 4.3
    [ 9.863042] wkup_m3_ipc 44e11324.wkup_m3_ipc: could not get rproc handle
    [ 9.871026] remoteproc remoteproc0: wkup_m3 is available
    [ 9.901275] wkup_m3_ipc 44e11324.wkup_m3_ipc: could not get rproc handle
    [ 9.903495] omap-aes 53500000.aes: OMAP AES hw accel rev: 3.2
    [ 9.904521] wkup_m3_ipc 44e11324.wkup_m3_ipc: could not get rproc handle
    [ 9.904754] omap-aes 53500000.aes: will run requests pump with realtime priority
    [ 9.906489] PM: Cannot get wkup_m3_ipc handle
    [ 9.918550] wkup_m3_ipc 44e11324.wkup_m3_ipc: could not get rproc handle
    [ 9.918771] PM: Cannot get wkup_m3_ipc handle
    [ 9.990445] asoc-simple-card sound: hdmi-hifi.0 <-> 48038000.mcasp mapping ok
    [ 9.996562] wkup_m3_ipc 44e11324.wkup_m3_ipc: could not get rproc handle
    [ 9.996788] PM: Cannot get wkup_m3_ipc handle
    [ OK ] Reached target Host and Network Name Lookups.
    [ 10.299807] remoteproc remoteproc0: powering up wkup_m3
    [ 10.305596] PM: Cannot get wkup_m3_ipc handle
    Starting Start USB gadget...
    [ 10.393630] remoteproc remoteproc0: Booting fw image am335x-pm-firmware.elf, size 224344
    [ 10.431013] remoteproc remoteproc0: remote processor wkup_m3 is now up
    [ 10.431039] wkup_m3_ipc 44e11324.wkup_m3_ipc: CM3 Firmware Version = 0x192
    [ 10.825118] udc-core: couldn't find an available UDC - added [g_multi] to list of pending drivers
    [ OK ] Started Start USB gadget.
    [ 12.056941] PM: bootloader does not support rtc-only!
    [ 12.071893] usbcore: registered new interface driver usbfs
    [ 12.071958] usbcore: registered new interface driver hub
    [ 12.077297] 47401300.usb-phy supply vcc not found, using dummy regulator
    [ 12.077837] 47401b00.usb-phy supply vcc not found, using dummy regulator
    [ 12.112322] usbcore: registered new device driver usb
    [ 12.187041] using random self ethernet address
    [ 12.187047] using random host ethernet address
    [ 12.187062] using host ethernet address: 50:65:83:D5:08:D0
    [ 12.187077] using self ethernet address: 50:65:83:D5:08:DE
    [ 12.187078] using random self ethernet address
    [ 12.187081] using random host ethernet address
    [ 12.187092] using host ethernet address: 50:65:83:D5:08:D0
    [ 12.193843] using self ethernet address: 50:65:83:D5:08:DE
    [ 12.193845] usb0: HOST MAC 50:65:83:d5:08:d0
    [ 12.195108] usb0: MAC 50:65:83:d5:08:de
    [ 12.236681] Mass Storage Function, version: 2009/09/11
    [ 12.236690] LUN: removable file: (no medium)
    [ 12.236894] LUN: removable file: /dev/mmcblk0p2
    [ 12.236898] Number of LUNs=1
    [ 12.248643] g_multi gadget: Multifunction Composite Gadget
    [ 12.248652] g_multi gadget: g_multi ready
    [ 12.266745] musb-hdrc musb-hdrc.1: MUSB HDRC host driver
    [ 12.266779] musb-hdrc musb-hdrc.1: new USB bus registered, assigned bus number 1
    [ 12.275035] ti-pruss 4a300000.pruss: creating PRU cores and other child platform devices
    [ 12.276496] irq: no irq domain found for /ocp/pruss_soc_bus@4a326000/pruss@4a300000/intc@4a320000 !
    [ 12.277022] irq: no irq domain found for /ocp/pruss_soc_bus@4a326000/pruss@4a300000/intc@4a320000 !
    [ 12.290657] hub 1-0:1.0: USB hub found
    [ 12.292157] hub 1-0:1.0: 1 port detected
    [ 12.454073] remoteproc remoteproc1: 4a334000.pru0 is available
    [ 12.454145] pru-rproc 4a334000.pru0: PRU rproc node /ocp/pruss_soc_bus@4a326000/pruss@4a300000/pru@4a334000 probed successfully
    [ 12.454518] remoteproc remoteproc2: 4a338000.pru1 is available
    [ 12.454569] pru-rproc 4a338000.pru1: PRU rproc node /ocp/pruss_soc_bus@4a326000/pruss@4a300000/pru@4a338000 probed successfully
    [ 13.207448] g_multi gadget: high-speed config #2: Multifunction with CDC ECM
    [ OK ] Reached target Sound Card.

    Welcome to Buildroot
    prusa_pro login: root
    Password:

    prusa_pro:~# systemctl status systemd-networkd.service
    ��● systemd-networkd.service - Network Service
    Loaded: loaded (/usr/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
    Active: active (running) since Thu 2017-12-14 22:10:03 UTC; 3min 10s ago
    Docs: man:systemd-networkd.service(8)
    Main PID: 118 (systemd-network)
    Status: "Processing requests..."
    Tasks: 1 (limit: 4915)
    CGroup: /system.slice/systemd-networkd.service
    ��└��─118 /usr/lib/systemd/systemd-networkd

    Dec 14 22:10:03 prusa_pro systemd[1]: Starting Network Service...
    Dec 14 22:10:03 prusa_pro systemd-networkd[118]: Enumeration completed
    Dec 14 22:10:03 prusa_pro systemd[1]: Started Network Service.

    prusa_pro:~# systemctl status gadget-init.service
    ��● gadget-init.service - Start USB gadget
    Loaded: loaded (/etc/systemd/system/gadget-init.service; enabled; vendor preset: enabled)
    Active: active (exited) since Thu 2017-12-14 22:10:05 UTC; 3min 47s ago
    Process: 151 ExecStart=/usr/bin/gadget-init.sh (code=exited, status=0/SUCCESS)
    Main PID: 151 (code=exited, status=0/SUCCESS)

    Dec 14 22:10:05 prusa_pro systemd[1]: Starting Start USB gadget...
    Dec 14 22:10:05 prusa_pro gadget-init.sh[151]: SERIAL_NUMBER = 1650BBWG0826
    Dec 14 22:10:05 prusa_pro gadget-init.sh[151]: PRODUCT = BeagleBoneBlack
    Dec 14 22:10:05 prusa_pro gadget-init.sh[151]: dev_addr = 50:65:83:D5:08:DE
    Dec 14 22:10:05 prusa_pro gadget-init.sh[151]: host_addr = 50:65:83:D5:08:D0
    Dec 14 22:10:05 prusa_pro gadget-init.sh[151]: ifup: interface usb0 already configured
    Dec 14 22:10:05 prusa_pro systemd[1]: Started Start USB gadget.

    prusa_pro:~# ifconfig
    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:65536 Metric:1
    RX packets:160 errors:0 dropped:0 overruns:0 frame:0
    TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1
    RX bytes:12160 (11.8 KiB) TX bytes:12160 (11.8 KiB)

    prusa_pro:~# ifconfig usb0
    usb0 Link encap:Ethernet HWaddr 50:65:83:D5:08:DE
    BROADCAST MULTICAST MTU:1500 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

    prusa_pro:~# ifup usb0
    ifup: interface usb0 already configured

    prusa_pro:~# ifdown usb0
    prusa_pro:~# ifup usb0
    prusa_pro:~# ifconfig
    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:65536 Metric:1
    RX packets:160 errors:0 dropped:0 overruns:0 frame:0
    TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1
    RX bytes:12160 (11.8 KiB) TX bytes:12160 (11.8 KiB)

    usb0 Link encap:Ethernet HWaddr 50:65:83:D5:08:DE
    inet addr:192.168.7.2 Bcast:0.0.0.0 Mask:255.255.255.252
    inet6 addr: fe80::5265:83ff:fed5:8de/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:18 errors:0 dropped:0 overruns:0 frame:0
    TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:2932 (2.8 KiB) TX bytes:1290 (1.2 KiB)




    What am I missing? Why the ifup usb0 in gadget-init.sh doesn't work?

    I tried to run gadget-init.service before systemd-networkd.service but it didn't work.

    Thanks
  • I also tried to set interface down and up again in gadget-init.sh but I got this error:

    prusa_pro:~# systemctl status gadget-init.service
    ��● gadget-init.service - Start USB gadget
    Loaded: loaded (/etc/systemd/system/gadget-init.service; enabled; vendor preset: enabled)
    Active: failed (Result: exit-code) since Thu 2017-12-14 22:10:07 UTC; 14s ago
    Process: 149 ExecStart=/usr/bin/gadget-init.sh (code=exited, status=1/FAILURE)
    Main PID: 149 (code=exited, status=1/FAILURE)

    Dec 14 22:10:06 prusa_pro gadget-init.sh[149]: PRODUCT = BeagleBoneBlack
    Dec 14 22:10:06 prusa_pro gadget-init.sh[149]: dev_addr = 50:65:83:D5:08:DE
    Dec 14 22:10:06 prusa_pro gadget-init.sh[149]: host_addr = 50:65:83:D5:08:D0
    Dec 14 22:10:06 prusa_pro gadget-init.sh[149]: ip: can't find device 'usb0'
    Dec 14 22:10:06 prusa_pro gadget-init.sh[149]: ip: SIOCGIFFLAGS: No such device
    Dec 14 22:10:07 prusa_pro gadget-init.sh[149]: ip: can't find device 'usb0'
    Dec 14 22:10:07 prusa_pro gadget-init.sh[149]: ip: SIOCGIFFLAGS: No such device
    Dec 14 22:10:07 prusa_pro systemd[1]: gadget-init.service: Main process exited, code=exited, status=1/FAILURE
    Dec 14 22:10:07 prusa_pro systemd[1]: gadget-init.service: Failed with result 'exit-code'.
    Dec 14 22:10:07 prusa_pro systemd[1]: Failed to start Start USB gadget.
  • Filip Kotoucek said:
    What am I missing? Why the ifup usb0 in gadget-init.sh doesn't work?

    gadget-init.sh only load g_multi module, the usb0 interface is only created when both the musb controller drivers and g_multi drivers are loaded. From the kernel boot log you provided we can tell gadget-init.sh is loaded before musb drivers are loaded, so the usb0 interface doesn't exist yet when gadget-init.sh finishes, so you cannot do ifup usb0 in gadget-init.sh.

    FYI, in my setup, I don't use systemd for this purpose. Instead I use a udev rule to detect usb0 interface then trigger a shell script to set its ip address. Of cause I do this on the host pc, because I run dhcp server on the pc.

  • Filip Kotoucek said:
    I also tried to set interface down and up again in gadget-init.sh but I got this error:
    ...
    Dec 14 22:10:06 prusa_pro gadget-init.sh[149]: ip: can't find device 'usb0'

    As I explained in my previous post, usb0 interface doesn't exist yet.

  • Im getting still same error.

    ifup: interface usb0 already configured

    Now I have udev rule in /etc/udev/rules.d/10-local.rules
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1d6b", ATTRS{idProduct}=="0002", RUN+="/bin/sh /usr/bin/gadget-init.sh"


    this is output.

    [ 2.283362] systemd[1]: Set hostname to <prusa_pro>.
    [ 2.738099] systemd[1]: File /usr/lib/systemd/system/systemd-journald.service:35 configures an IP firewall (IPAddressDeny=any), but the .
    [ 2.755792] systemd[1]: Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewal)
    [ 2.973375] systemd[1]: System is tainted: var-run-bad
    [ 2.989710] systemd[1]: Created slice System Slice.
    [ OK ] Created slice System Slice.
    [ 3.022825] systemd[1]: Started Forward Password Requests to Wall Directory Watch.
    [ OK ] Started Forward Password Requests to Wall Directory Watch.
    [ 3.067355] systemd[1]: Mounting POSIX Message Queue File System...
    Mounting POSIX Message Queue File System...
    [ 3.103291] systemd[1]: Listening on Journal Socket.
    [ OK ] Listening on Journal Socket.
    Starting Create Static Device Nodes in /dev...
    [ OK ] Listening on udev Kernel Socket.
    [ OK ] Reached target Remote File Systems.
    [ OK ] Listening on udev Control Socket.
    Starting udev Coldplug all Devices...
    [ OK ] Listening on Journal Socket (/dev/log).
    [ OK ] Listening on /dev/initctl Compatibility Named Pipe.
    Starting Apply Kernel Variables...
    [ OK ] Reached target Slices.
    [ OK ] Started Dispatch Password Requests to Console Directory Watch.
    Mounting Kernel Debug File System...
    [ OK ] Reached target Swap.
    Mounting Kernel Configuration File System...
    [ OK ] Reached target Paths.
    [ OK ] Listening on Network Service Netlink Socket.
    Starting Journal Service...
    [ OK ] Created slice system-serial\x2dgetty.slice.
    Mounting Temporary Directory (/tmp)...
    Starting Remount Root and Kernel File Systems...
    [ OK ] Mounted Kernel Debug File System.
    [ 3.774079] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
    [ OK ] Mounted Kernel Configuration File System.
    [ OK ] Mounted POSIX Message Queue File System.
    [ OK ] Mounted Temporary Directory (/tmp).
    [ OK ] Started Journal Service.
    [ OK ] Started Create Static Device Nodes in /dev.
    [ OK ] Started Apply Kernel Variables.
    [ OK ] Started Remount Root and Kernel File Systems.
    Starting Rebuild Hardware Database...
    [ OK ] Reached target Local File Systems (Pre).
    Starting Flush Journal to Persistent Storage...
    [ OK ] Reached target Local File Systems.
    Starting Rebuild Journal Catalog...
    [ 4.287260] systemd-journald[95]: Received request to flush runtime journal from PID 1
    [ 4.331701] systemd-journald[95]: File /var/log/journal/695011d4e9d149be8c1fd175ca793cd9/system.journal corrupted or uncleanly shut down.
    [ OK ] Started Rebuild Journal Catalog.
    [ OK ] Started Flush Journal to Persistent Storage.
    Starting Create Volatile Files and Directories...
    [ OK ] Started Create Volatile Files and Directories.
    Starting Update UTMP about System Boot/Shutdown...
    Starting Network Time Synchronization...
    [ OK ] Started Update UTMP about System Boot/Shutdown.
    [ OK ] Started Network Time Synchronization.
    [ OK ] Reached target System Time Synchronized.
    [ OK ] Started udev Coldplug all Devices.
    [ OK ] Started Rebuild Hardware Database.
    Starting Update is Completed...
    Starting udev Kernel Device Manager...
    [ OK ] Started Update is Completed.
    [ OK ] Started udev Kernel Device Manager.
    Starting Network Service...
    [ OK ] Reached target System Initialization.
    [ OK ] Started Daily Cleanup of Temporary Directories.
    [ OK ] Reached target Timers.
    [ OK ] Listening on D-Bus System Message Bus Socket.
    [ OK ] Reached target Sockets.
    [ OK ] Reached target Basic System.
    [ OK ] Started D-Bus System Message Bus.
    [ OK ] Started Network Service.
    [ 9.494994] systemd-journald[95]: File /var/log/journal/695011d4e9d149be8c1fd175ca793cd9/user-1005.journal corrupted or uncleanly shut d.
    [ OK ] Reached target Network.
    Starting Network Name Resolution...
    [ OK ] Found device /dev/ttyS0.
    [ 9.680646] omap_wdt: OMAP Watchdog Timer Rev 0x01: initial timeout 60 sec
    [ OK ] Started Serial Getty on ttyS0.
    [ 9.753654] omap_rtc 44e3e000.rtc: already running
    [ 9.804857] omap_rtc 44e3e000.rtc: rtc core: registered 44e3e000.rtc as rtc0
    [ 10.275611] omap-sham 53100000.sham: hw accel on OMAP rev 4.3
    [ 10.322420] systemd-journald[95]: File /var/log/journal/695011d4e9d149be8c1fd175ca793cd9/user-1006.journal corrupted or uncleanly shut d.
    [ 10.405785] wkup_m3_ipc 44e11324.wkup_m3_ipc: could not get rproc handle
    [ 10.411173] remoteproc remoteproc0: wkup_m3 is available
    [ 10.416744] remoteproc remoteproc0: powering up wkup_m3
    [ 10.419876] PM: Cannot get wkup_m3_ipc handle
    [ 10.433881] remoteproc remoteproc0: Booting fw image am335x-pm-firmware.elf, size 224344
    [ 10.434142] remoteproc remoteproc0: remote processor wkup_m3 is now up
    [ 10.434171] wkup_m3_ipc 44e11324.wkup_m3_ipc: CM3 Firmware Version = 0x192
    [ 10.451709] omap-aes 53500000.aes: OMAP AES hw accel rev: 3.2
    [ 10.452508] PM: bootloader does not support rtc-only!
    [ 10.456096] omap-aes 53500000.aes: will run requests pump with realtime priority
    [ 10.523243] asoc-simple-card sound: hdmi-hifi.0 <-> 48038000.mcasp mapping ok
    [ OK ] Started Network Name Resolution.
    [ OK ] Reached target Host and Network Name Lookups.
    [ 12.393106] 47401300.usb-phy supply vcc not found, using dummy regulator
    [ 12.448585] usbcore: registered new interface driver usbfs
    [ 12.455527] 47401b00.usb-phy supply vcc not found, using dummy regulator
    [ 12.500889] usbcore: registered new interface driver hub
    [ 12.561833] ti-pruss 4a300000.pruss: creating PRU cores and other child platform devices
    [ 12.567404] irq: no irq domain found for /ocp/pruss_soc_bus@4a326000/pruss@4a300000/intc@4a320000 !
    [ 12.567919] irq: no irq domain found for /ocp/pruss_soc_bus@4a326000/pruss@4a300000/intc@4a320000 !
    [ 12.673802] remoteproc remoteproc1: 4a334000.pru0 is available
    [ 12.673889] pru-rproc 4a334000.pru0: PRU rproc node /ocp/pruss_soc_bus@4a326000/pruss@4a300000/pru@4a334000 probed successfully
    [ 12.686027] remoteproc remoteproc2: 4a338000.pru1 is available
    [ 12.686089] pru-rproc 4a338000.pru1: PRU rproc node /ocp/pruss_soc_bus@4a326000/pruss@4a300000/pru@4a338000 probed successfully
    [ 12.774544] usbcore: registered new device driver usb
    [ 12.850293] musb-hdrc musb-hdrc.1: MUSB HDRC host driver
    [ 12.872523] musb-hdrc musb-hdrc.1: new USB bus registered, assigned bus number 1
    [ 12.885267] hub 1-0:1.0: USB hub found
    [ 12.902391] hub 1-0:1.0: 1 port detected
    [ 13.293027] using random self ethernet address
    [ 13.297513] using random host ethernet address
    [ 13.301979] using host ethernet address: 50:65:83:D5:08:D0[ 13.322316] using self ethernet address: 50:65:83:D5:08:DE
    [ 13.327892] using random self ethernet address
    [ 13.342194] using random host ethernet address
    [ 13.346692] using host ethernet address: 50:65:83:D5:08:D0[ 13.362531] using self ethernet address: 50:65:83:D5:08:DE
    [ 13.385163] usb0: HOST MAC 50:65:83:d5:08:d0
    [ 13.395439] usb0: MAC 50:65:83:d5:08:de
    [ 13.440766] Mass Storage Function, version: 2009/09/11
    [ 13.452308] LUN: removable file: (no medium)
    [ 13.456907] LUN: removable file: /dev/mmcblk0p2
    [ 13.461459] Number of LUNs=1
    [ 13.492809] g_multi gadget: Multifunction Composite Gadget
    [ 13.498350] g_multi gadget: g_multi ready
    [ OK ] Reached target Sound Card.
    [ 13.970521] g_multi gadget: high-speed config #2: Multifunction with CDC ECM

    prusa_pro:~# ifconfig
    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:65536 Metric:1
    RX packets:160 errors:0 dropped:0 overruns:0 frame:0
    TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1
    RX bytes:12160 (11.8 KiB) TX bytes:12160 (11.8 KiB)

    prusa_pro:~# ifconfig usb0
    usb0 Link encap:Ethernet HWaddr 50:65:83:D5:08:DE
    BROADCAST MULTICAST MTU:1500 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

    prusa_pro:~# ifup usb0
    ifup: interface usb0 already configured
    prusa_pro:~# ifdown usb0
    prusa_pro:~# ifup usb0
    prusa_pro:~# ifconfig
    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:65536 Metric:1
    RX packets:160 errors:0 dropped:0 overruns:0 frame:0
    TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1
    RX bytes:12160 (11.8 KiB) TX bytes:12160 (11.8 KiB)

    usb0 Link encap:Ethernet HWaddr 50:65:83:D5:08:DE
    inet addr:192.168.7.2 Bcast:0.0.0.0 Mask:255.255.255.252
    inet6 addr: fe80::5265:83ff:fed5:8de/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:29 errors:0 dropped:0 overruns:0 frame:0
    TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:4736 (4.6 KiB) TX bytes:1430 (1.3 KiB)
  • Hi.

    I just want to post an update. I got the usb ethernet working. The issue seemed to be as Bin Liu posted. The MUSB controller driver was not configured yet so the g_ether (g_multi) was not able to finnish configuration.

    This is my setup now:

    # cat /etc/udev/rules.d
    ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="1d6b", ATTRS{idProduct}=="0002", RUN+="/bin/systemctl start usb-ethernet.service"
    ACTION=="remove", SUBSYSTEM=="usb", ATTRS{idVendor}=="1d6b", ATTRS{idProduct}=="0002", RUN+="/bin/systemctl stop usb-ethernet.service"



    # cat /etc/systemd/system/usb-ethernet.service
    [Unit]
    Description=Start USB gadget
    Requires=dev-mmcblk0p2.device
    #Wants=serial-getty@ttyS0.service
    Wants=udhcpd.service

    After=dev-mmcblk0p2.device
    #Before=serial-getty@ttyS0.service
    Before=udhcpd.service

    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=/usr/bin/usb-ethernet.sh
    #ExecStopPre=/bin/systemctl stop serial-getty@ttyGS0.service
    ExecStop=/sbin/rmmod g_multi

    [Install]
    WantedBy=basic.target



    # cat /etc/systemd/system/udhcpd.service
    [Unit]
    Description=DHCP server for USB0 network gadget

    [Service]
    ExecStart=/usr/sbin/udhcpd -f -S /etc/udhcpd.conf
    ExecStop=/bin/kill -TERM $MAINPID
    KillSignal=SIGINT

    [Install]
    RequiredBy=usb-ethernet.service



    # cat /etc/network/interfaces
    iface usb0 inet static
    address 192.168.7.2
    netmask 255.255.255.252

    post-up route add default gw 192.168.7.1 usb0



    All works fine now.
  • Filip,

    Glad the issue is solved. Thanks for posting the solution details, I am sure it will benefit others who have the similar requirements.