Switching USB DWC3 controller from host to device mode - usb

I need to use an embedded Linux platform as a USB device in order to stream audio and video from a smartphone. The platform has a USB A receptacle and doesn't support OTG (USB_ID pin is not connected on the host controller).
Now I try to switch from host to device mode using DWC3 controller and the debugfs interface. Therefore I activated DWC3 controller in the kernel configuration and set it to "Dual Role Mode". After mounting the file system I checked the current mode in /sys/kernel/debug/xxxxxxxx.usb3/mode with cat mode and got host as expected. But unfortunately I can't write device to the mode file. After entering the command echo device > mode it remains host and does not change. Does anyone know what could be causing it?

I know that this used to work out of the box, but with the kernel version I'm using in an embedded platform (5.4.0) it doesn't. In order to make it work I had to patch around a bug in the kernel:
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index bf1a7a9da..a78990664 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
## -110,9 +110,6 ## static void __dwc3_set_mode(struct work_struct *work)
unsigned long flags;
int ret;
- if (dwc->dr_mode != USB_DR_MODE_OTG)
- return;
-
if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
dwc3_otg_update(dwc, 0);
## -192,6 +189,12 ## void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
dwc->desired_dr_role = mode;
spin_unlock_irqrestore(&dwc->lock, flags);
+ if (dwc->dr_mode != USB_DR_MODE_OTG)
+ {
+ __dwc3_set_mode(&dwc->drd_work);
+ return;
+ }
+
queue_work(system_freezable_wq, &dwc->drd_work);
}
After applying the above patch, rebooting to the new kernel, and running:
echo "host" | sudo tee /sys/kernel/debug/*.usb3/mode
I was able to switch modes like I expect (note: I had *.dwc3 instead of *.usb3 in the above command).

Related

Why won't chrony sync to GPS when serial data flows through socat?

I'm using gpsd to sync time to a GPS. When I connect my GPS to /dev/ttyUSB0, and tell gpsd to listen on that port, chrony is happy to use it as a time source.
gpsd -D 5 -N -n /dev/ttyUSB0
However, as soon as I try and pipe that data through socat (which is how it needs to work in our production system), chrony won't use it as a source. This is the case even though gpsd, cgps, and gpsmon all seem perfectly happy with the GPS data they are getting.
Here's my socat:
socat -d -d pty,rawer,echo=0,link=/tmp/ttyVSP0 /dev/ttyUSB0,b4800
(my gpsd command is the same as above but with /tmp/ttyVSP0 as the port to listen to in this case).
I'm using chronyc sources to confirm when GPS is a chrony source.
My refclock line in my /etc/chrony/chrony.conf looks like this:
refclock SHM 0 refid GPS
pty ports are prevented from talking to ntp (and thus, chrony) by an early return meant to prevent code from being executed during testing.
void ntpshm_link_activate(struct gps_device_t *session)
/* set up ntpshm storage for a session */
{
/* don't talk to NTP when we're running inside the test harness */
if (session->sourcetype == source_pty)
return;
if (session->sourcetype != source_pps ) {
/* allocate a shared-memory segment for "NMEA" time data */
session->shm_clock = ntpshm_alloc(session->context);
if (session->shm_clock == NULL) {
gpsd_log(&session->context->errout, LOG_WARN,
"NTP: ntpshm_alloc() failed\n");
return;
}
}
Discovered thanks to this bug report

Jenkins: configure slave node address dynamically using command or groovy script

I have kinda ssh slave build jenkins setup.
Jenkins server connect to Mac slave thru ssh. build ios apps there. two remote nodes are configured in Jenkins connected to the Mac.
The Mac has dhcp.
Every time my mac starts I want to run a script that tell the Jenkin server to configure the node's IP address pointing to the dhcp address that the mac receives. Since its dhcp it changes always.
Is possible to configure such? using shell script or perl ...
e.g. http://jenkins-server:8080/computer/mac-slave-enterprise/configure
is the node config url. If its possible to setup by sending host=10.1.2.100 & Submit=Save or something like this?
I found it is possible run Groovy script at
http://jenkins/script
or from mac command line or sh script,
$ curl -d "script=<your_script_here>" http://jenkins/script
I tried to get some info with this code but no luck, seems I have create SSLLauncher, but lost in how to grab a launcher things. There is no direct setHost or setLauncher thing.
following the tutorial at,
https://wiki.jenkins-ci.org/display/JENKINS/Display+Information+About+Nodes
but cannot set the host address.
println("node desc launcher = " + aSlave.getComputer().getLauncher());
//println("node desc launcher = " + aSlave.getComputer().getLauncher().setHost("10.11.51.70"));
println("node launcher host = " + aSlave.getComputer().getLauncher().getHost());
hudson.plugins.sshslaves.SSHLauncher ssl = aSlave.getComputer().getLauncher();
int port = ssl.getPort();
String userName, password, privateKey;
userName = ssl.getUsername();
password = ssl.getPassword();
privateKey = ssl.getPrivatekey();
println("user: "+userName + ", pwd: "+password + ", key: "+privateKey);
// all these values returns null.
Another way would be to just delete the node and recreate it.
Here is some groovy on how to delete it from here:
for (aSlave in hudson.model.Hudson.instance.slaves) {
if (aSlave.name == "MySlaveToDelete") {
println('====================');
println('Name: ' + aSlave.name);
println('Shutting down node!!!!');
aSlave.getComputer().setTemporarilyOffline(true,null);
aSlave.getComputer().doDoDelete();
}
And here is how to create one (source):
import jenkins.model.*
import hudson.model.*
import hudson.slaves.*
Jenkins.instance.addNode(new DumbSlave("test-script","test slave description","C:\\Jenkins","1",Node.Mode.NORMAL,"test-slave-label",new JNLPLauncher(),new RetentionStrategy.Always(),new LinkedList()))

VxWorks boot hang (starting at 0x100000)

I'm trying to boot VxWorks 6.3 on a Wind River SBC83XX PowerQUICC II Pro. I'm using Wind River Workbench as my IDE. I configured the kernel, built it, and attempted to run it, but it hangs on Starting at 0x100000 with no further output.
Here is the output of the terminal after typing # at the prompt:
boot device : mottsec
unit number : 0
processor number : 0
host name : XXXXXXXXXXX
file name : C:\WindRiver\workspace\vxworks-dev\default\vxWorks
inet on ethernet (e) : 69.88.163.22:ffffff00
host inet (h) : 69.88.163.21
gateway inet (g) : 69.88.163.1
user (u) : XXXXXXXXX
ftp password (pw) : XXXXXXXX
flags (f) : 0x0
Attaching interface lo0... done
Attached IPv4 interface to mottsec unit 0
Loading... 1838288
Starting at 0x100000...
Any suggestions would be greatly appreciated; I need this working for a college class on a tight schedule.
Many things could be wrong.
The first thing I would do is check the RAM size. If it exceed the amount on the board, this might happen.
Is the serial port & shell configured? I would suggest adding the standalone shell bundle.
If the symbol table is compiled as standalone, this can sometimes occur based on other configurations.
Compile the symbol table into the image.
In Work Bench:
Kernel Configuration -> CTRL+F, search "built-in symbol table", -> include it.

tftp retry timeout exceeded

My issue is retry count exceeds when I download kernel image to Econa processor board (Econa is ARM based processor) via TFTP as shown below
CNS3000 # tftp 0x4000000 bootpImage.cns3420.uclibc
MAC PORT 0 : Initialize bcm53115M
MAC PORT 2 : Initialize RTL8211
TFTP from server 192.168.0.219; our IP address is 192.168.0.112
Filename 'bootpImage.cns3420.uclibc'.
Load address: 0x4000000
Loading: T T T T T T T T T T
Retry count exceeded; starting again
Following are the points which may help you in finding the cause of this error.
Ping response is OK
CNS3000 # ping 192.168.0.219
MAC PORT 0 : Initialize bcm53115M
MAC PORT 2 : Initialize RTL8211
host 192.168.0.219 is alive
When I tried to verify TFTP is running, I tried as shown below. It seems TFTP server is working. I placed a small file in /tftpboot:
# echo "Hello, embedded world" > /tftpboot/hello.txt"
Then I did localhost
# tftp localhost
tftp> get hello.txt
Received 23 bytes in 0.1 seconds
tftp> quit
Please note that there is no firewall or SELinux on my machine.
Please verify location of these files are OK. I have placed kernel image file bootpImage.cns3420.uclibc in /tftpbootTFTP service file is located in /etc/xinetd.d/tftp.
My TFTP service file is:
service tftp
{
socket_type =dgram
protocol=udp
wait=yes
user=root
server=/usr/sbin/in.tftpd
server_args=-s /tftpboot -b 512
disable=no
per_source=11
cps=100 2
flags=ipv4
}
printenv response in U-boot is:
CNS3000 # printenv
bootargs=root=/dev/mtdblock0 mem=256M console=ttyS0
baudrate=38400
ethaddr=00:53:43:4F:54:54
netmask=255.255.0.0
tftp_bsize=512
udp_frag_size=512
mmc_init=mmcinit
loading=fatload mmc 0 0x4000000 bootpimage-82511
running=go 0x4000000
bootcmd=run mmc_init;run loading;run running
serverip=192.168.0.219
ipaddr=192.168.0.112
bootdelay=5
port=1
bootfile=/tftpboot/bootpImage.cns3420.uclibcl
stdin=serial
stdout=serial
stderr=serial
verify=n
Environment size: 437/4092 bytes
Regards
Waqas
Loading: T T T T T T T T T T
Means there is no transfer at all; this can be caused by wrong interface setting i.e.
u-boot is configured for 100Mbit full duplex, and you try to connect via half duplex or 10Mbit (or some mix of it). Another point is the MTU size, should be 1500 (u-boot cannot handle packet fragmentation)
Hint for windows/vmware users:
tftp timeouts from u-boot are caused by windows ip-forwarding.
1) If you have a home network : switch it of.
2) You are running Routing and Remote Access service : shut down service
3) check registry for ip forwarding:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\IPEnableRouter
set value to 0 (and maybe reboot)

how to syslog-ng to remote facility

i have a host running syslog-ng. it does all it's stuff locally fine (creating log files etc). however, i would like to forward ALL of it's logs to a remote machine - specifically to one facility on the remote machine (local4). i tried playing around with rewrite (set-facility) and templates within the destination (syntax errors) - but to no avail.
destination remote_server {
udp(\"172.18.192.8\" port (514));
udp(\"172.18.192.9\" port (514));
};
rewrite r_local4 {
set-facility(local4);
};
filter f_alllogs {
level (debug...emerg);
};
log {
source(local);
filter(f_alllogs);
rewrite(r_local4)
destination(remote_server);
};
AFAIK, currently it is not possible to modify the facility of a message in syslog-ng.
Is there a special reason you want to do it?