Sunday, February 28, 2016

ASUS RT N12E Bootup

Debugging a problem with a ASUS RT-N12E 300Mbps Wireless N Router, I soldered a pin header to  J15 (next to the ethernet magnetics handling the yellow "LAN" ports).

Pinout is Vcc, GND, Tx, Rx. Vcc is the square pad, Rx and Tx as seen from the N12E soc. Port runs at 38400 bps.

Here's the bootup messages, just in case anyone is interested.

$ cu -l ttyUSB0 -s 38400
Connected.

========== SPI =============
SDRAM CLOCK:156MHZ
 ------------------------- Force into Single IO Mode ------------------------
|No chipID  Sft chipSize blkSize secSize pageSize sdCk opCk      chipName    |
| 0 c22016h  0h  400000h  10000h   1000h     100h   86   39      MX25L3205D/E|
 ----------------------------------------------------------------------------
Set 8196C PHY Patch OK

---RealTek(RTL8196C)at 2013.12.09-17:34+0800 version v1.1f [16bit](390MHz)

####return_addr: 0x05010000, root_bin_offset: 0x050dd012
Jump to image start=0x80500000...
decompressing kernel:
Uncompressing Linux... done, booting the kernel.
done decompressing kernel.
start address: 0x80003600
RTL8192C/RTL8188C driver version 1.6 (2011-07-18)



Probing RTL8186 10/100 NIC-kenel stack size order[2]...
chip name: 8196C, chip revid: 4
NOT YET
eth0 added. vid=9 Member port 0x10...
eth1 added. vid=8 Member port 0x1...
eth2 added. vid=9 Member port 0x2...
eth3 added. vid=9 Member port 0x4...
eth4 added. vid=9 Member port 0x8...
[peth0] added, mapping to [eth1]...
init started: BusyBox v1.13.4 (2014-09-18 18:08:32 CST)

##flash.c free apmib ##
Init Start...
wan_disconnect: option all

##system/sysconf.c free apmib ##

##flash.c free apmib ##
===== Set parameter for BSMI test=====
Init bridge interface...
wait for bridge initialization...
syslog will use 64KB for log(7 rotate, 1 original, 8KB for each)
route: SIOCDELRT: No such process
route: SIOCADDRT: Invalid argument
Init Start...
Init Wlan application...

##flash.c free apmib ##

##flash.c free apmib ##
update wps state to -1

WiFi Simple Config v2.9-wps2.0 (2014.09.18-10:09+0000).

Init Wlan application...

##flash.c free apmib ##

##flash.c free apmib ##
update wps state to -1

WiFi Simple Config v2.9-wps2.0 (2014.09.18-10:09+0000).

Register to wlan0
iwcontrol RegisterPID to (wlan0)
Register to wlan0

##system/sysconf.c free apmib ##
iwcontrol RegisterPID to (wlan0)
Init Firewall Rules....
firewall clean prerouting
firewall add iptables rule
No wan ip currently!
System TZ ENV = GMT-8

##system/sysconf.c free apmib ##
start infosvr
WLAN0_WLAN_DISABLED=0 ##flash.c free apmib ##
sh: ##flash.c: unknown operand
# Start httpd!
Start wanduck!

# <-- :-="" a="" b="" here="" rootshell="" s="">

MemTotal:          11144 kB
MemFree:            5164 kB
Buffers:             224 kB
Cached:             1128 kB
SwapCached:            0 kB
Active:             1672 kB
Inactive:            716 kB
Active(anon):       1036 kB
Inactive(anon):        0 kB
Active(file):        636 kB
Inactive(file):      716 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:          1044 kB
Mapped:              716 kB
Slab:               3064 kB
SReclaimable:        176 kB
SUnreclaim:         2888 kB
PageTables:          164 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:        5572 kB
Committed_AS:       2220 kB
VmallocTotal:    1048404 kB
VmallocUsed:         264 kB
VmallocChunk:    1048136 kB

# cat /proc/cpuinfo
system type : RTL8196C
processor : 0
cpu model : 52481
BogoMIPS : 389.12
tlb_entries : 32
mips16 implemented : yes

# busybox
BusyBox v1.13.4 (2014-09-18 18:08:32 CST) multi-call binary
Copyright (C) 1998-2008 Erik Andersen, Rob Landley, Denys Vlasenko
and others. Licensed under GPLv2.
See source distribution for full notice.

Usage: busybox [function] [arguments]...
   or: function [arguments]...

BusyBox is a multi-call binary that combines many common Unix
utilities into a single executable.  Most people will create a
link to busybox for each function they wish to use and BusyBox
will act like whatever it was invoked as!

Currently defined functions:
arp, ash, bunzip2, bzcat, cat, cp, cut, date, echo, expr, false,
free, grep, gzip, halt, head, hostname, ifconfig, init, ip, kill,
killall, klogd, ln, ls, mkdir, mount, ping, poweroff, ps, reboot,
renice, rm, route, sh, sleep, sync, syslogd, tail, telnetd, top,
true, umount, vconfig, wc, zcip


Sunday, February 21, 2016

Linux/udev: Unbinding from one kernel driver, and rebinding to a different one. Automatically, using udev.

Quite a lot of USB devices claim to be a human interface device, the rationale being that you can access them on Windows without the need to supply your own "proper" driver.

Under Linux, one can easily unbind the usbhid driver from a particular usb device, but this gets tedious after a few dozen times. But there's a workaround using udev and a short script to rebind to a different kernel module.

First, create a udev rule, e.g. in /etc/udev/rules.d/99-rebind-driver.sh:


ACTION=="add", DRIVER=="usbhid", SUBSYSTEMS=="usb",
ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="00de",
RUN+="/usr/local/sbin/rebind_sysfs_driver.sh %p %k /bus/usb/drivers/mcp2210"



(all in one line)

Then use the following small script, stored as /usr/local/sbin/rebind_sysfs_driver.sh to do the actual work:


#!/bin/sh

if [ "$#" != 3 ] ; then
echo "Usage: $0 sysfs_path kernel_name new_driver_path" >&2
echo "" >&2
echo "To be used in udev rules:" >&2
echo "   RUN+=\"$0 %p %k /bus/usb/drivers/mcp2210\"" >&2
echo "which rebinds a particular device to a new driver." >&2
exit 1
fi

set -e
logger -t "$0" "Rebind device $1($2) to driver $3."

cd "/sys$1"
echo "$2" >driver/unbind
sleep 1
echo "$2" >"/sys$3/bind"