diff options
author | Joel A Fernandes <joelagnel@ti.com> | 2011-11-10 00:06:35 -0600 |
---|---|---|
committer | Koen Kooi <koen@dominion.thruhere.net> | 2011-11-10 08:23:08 +0100 |
commit | 89c54f502b38ec21e79056a5510f77836d013e81 (patch) | |
tree | 8679cbdb468fdf5abfa55bc63b537d174f2205d1 /recipes-ti/beagleboard/gadget-init | |
parent | 2cd35f07bfcb6ea76f329d6f278a7d7e98c5d79a (diff) | |
download | meta-ti-89c54f502b38ec21e79056a5510f77836d013e81.tar.gz |
gadget-init: Add network-gadget services and other fixes
* Add rule to start network-gadget when mass storage is ejected
* Add network-gadget-init service and scripts to switch to g_ether
* Add DHCP service / conf
* Update to storage-gadget: rmmod on stop
v2 changes:
* Fix g-ether MAC address by reading from mac_id
* Split into multiple packages
Signed-off-by: Joel A Fernandes <joelagnel@ti.com>
Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
Diffstat (limited to 'recipes-ti/beagleboard/gadget-init')
8 files changed, 89 insertions, 0 deletions
diff --git a/recipes-ti/beagleboard/gadget-init/bone-gmass-eject.rules b/recipes-ti/beagleboard/gadget-init/bone-gmass-eject.rules new file mode 100644 index 00000000..ee6f93e2 --- /dev/null +++ b/recipes-ti/beagleboard/gadget-init/bone-gmass-eject.rules | |||
@@ -0,0 +1 @@ | |||
SUBSYSTEM=="block",ACTION=="change",KERNEL=="mmcblk0p1",RUN+="/usr/bin/g-ether-start-service.sh" | |||
diff --git a/recipes-ti/beagleboard/gadget-init/g-ether-load.sh b/recipes-ti/beagleboard/gadget-init/g-ether-load.sh new file mode 100755 index 00000000..f9400649 --- /dev/null +++ b/recipes-ti/beagleboard/gadget-init/g-ether-load.sh | |||
@@ -0,0 +1,46 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | function get_devmem() | ||
4 | { | ||
5 | /usr/bin/devmem2 $1 | grep ": " | cut -d ":" -f 2|cut -d "x" -f 2 | ||
6 | } | ||
7 | |||
8 | function hex_to_mac_addr() | ||
9 | { | ||
10 | addr=$1 | ||
11 | n=0 | ||
12 | mac_addr=$(echo ${addr} | while read -r -n2 c; do | ||
13 | if [ ! -z "$c" ]; then | ||
14 | if [ $n -ne 0 ] ; then | ||
15 | echo -n ":${c}" | ||
16 | else | ||
17 | echo -n "${c}" | ||
18 | fi | ||
19 | fi | ||
20 | n=$(($n+1)) | ||
21 | done) | ||
22 | echo ${mac_addr} | ||
23 | } | ||
24 | |||
25 | function reverse_bytes() | ||
26 | { | ||
27 | addr=$1 | ||
28 | New_addr=$(echo ${addr} | while read -r -n2 c; do | ||
29 | if [ ! -z "$c" ]; then | ||
30 | New_addr=${c}${New_addr} | ||
31 | else echo | ||
32 | echo ${New_addr} | ||
33 | fi | ||
34 | done) | ||
35 | echo ${New_addr} | ||
36 | } | ||
37 | |||
38 | DEVMEM_ADDR_LO=$(get_devmem 0x44e10638|bc) | ||
39 | DEVMEM_ADDR_LO=$(reverse_bytes ${DEVMEM_ADDR_LO}) | ||
40 | |||
41 | DEVMEM_ADDR_HI=$(get_devmem 0x44e1063C) | ||
42 | DEVMEM_ADDR_HI=$(reverse_bytes ${DEVMEM_ADDR_HI}) | ||
43 | |||
44 | DEV_ADDR=$(hex_to_mac_addr "${DEVMEM_ADDR_HI}${DEVMEM_ADDR_LO}") | ||
45 | |||
46 | modprobe g_ether host_addr=${DEV_ADDR} | ||
diff --git a/recipes-ti/beagleboard/gadget-init/g-ether-start-service.sh b/recipes-ti/beagleboard/gadget-init/g-ether-start-service.sh new file mode 100755 index 00000000..2db16c26 --- /dev/null +++ b/recipes-ti/beagleboard/gadget-init/g-ether-start-service.sh | |||
@@ -0,0 +1,11 @@ | |||
1 | #!/bin/sh | ||
2 | if [ -a /sys/devices/platform/omap/ti81xx-usbss/musb-hdrc.0/gadget/lun0/file ] | ||
3 | then | ||
4 | x=$(cat /sys/devices/platform/omap/ti81xx-usbss/musb-hdrc.0/gadget/lun0/file) | ||
5 | if [ -z "$x" ] | ||
6 | then | ||
7 | /bin/systemctl stop storage-gadget-init.service | ||
8 | /bin/systemctl start network-gadget-init.service | ||
9 | /bin/systemctl start udhcpd.service | ||
10 | fi | ||
11 | fi | ||
diff --git a/recipes-ti/beagleboard/gadget-init/g-storage-reinsert.sh b/recipes-ti/beagleboard/gadget-init/g-storage-reinsert.sh new file mode 100755 index 00000000..d358640a --- /dev/null +++ b/recipes-ti/beagleboard/gadget-init/g-storage-reinsert.sh | |||
@@ -0,0 +1,4 @@ | |||
1 | #!/bin/sh | ||
2 | /bin/systemctl stop storage-gadget-init.service | ||
3 | /bin/systemctl stop network-gadget-init.service | ||
4 | /bin/systemctl start storage-gadget-init.service | ||
diff --git a/recipes-ti/beagleboard/gadget-init/network-gadget-init.service b/recipes-ti/beagleboard/gadget-init/network-gadget-init.service new file mode 100644 index 00000000..979d8aa4 --- /dev/null +++ b/recipes-ti/beagleboard/gadget-init/network-gadget-init.service | |||
@@ -0,0 +1,9 @@ | |||
1 | [Unit] | ||
2 | Description=Start USB Ethernet gadget | ||
3 | Conflicts=storage-gadget-init.service | ||
4 | |||
5 | [Service] | ||
6 | RemainAfterExit=yes | ||
7 | ExecStart=/usr/bin/g-ether-load.sh | ||
8 | ExecStartPost=/sbin/ifconfig usb0 192.168.7.2 netmask 255.255.255.252 | ||
9 | ExecStop=/sbin/rmmod g_ether | ||
diff --git a/recipes-ti/beagleboard/gadget-init/storage-gadget-init.service b/recipes-ti/beagleboard/gadget-init/storage-gadget-init.service index 2fe48e15..9a8513e8 100644 --- a/recipes-ti/beagleboard/gadget-init/storage-gadget-init.service +++ b/recipes-ti/beagleboard/gadget-init/storage-gadget-init.service | |||
@@ -3,7 +3,9 @@ Description=Start usb mass storage gadget | |||
3 | After=dev-mmcblk0p1.device | 3 | After=dev-mmcblk0p1.device |
4 | 4 | ||
5 | [Service] | 5 | [Service] |
6 | RemainAfterExit=yes | ||
6 | ExecStart=/sbin/modprobe g_mass_storage file=/dev/mmcblk0p1 cdrom=0 stall=0 removable=1 nofua=1 | 7 | ExecStart=/sbin/modprobe g_mass_storage file=/dev/mmcblk0p1 cdrom=0 stall=0 removable=1 nofua=1 |
8 | ExecStop=/sbin/rmmod g_mass_storage | ||
7 | 9 | ||
8 | [Install] | 10 | [Install] |
9 | WantedBy=basic.target | 11 | WantedBy=basic.target |
diff --git a/recipes-ti/beagleboard/gadget-init/udhcpd.conf b/recipes-ti/beagleboard/gadget-init/udhcpd.conf new file mode 100644 index 00000000..3bcf00f0 --- /dev/null +++ b/recipes-ti/beagleboard/gadget-init/udhcpd.conf | |||
@@ -0,0 +1,5 @@ | |||
1 | start 192.168.7.1 | ||
2 | end 192.168.7.1 | ||
3 | interface usb0 | ||
4 | max_leases 1 | ||
5 | option subnet 255.255.255.252 | ||
diff --git a/recipes-ti/beagleboard/gadget-init/udhcpd.service b/recipes-ti/beagleboard/gadget-init/udhcpd.service new file mode 100644 index 00000000..f0766733 --- /dev/null +++ b/recipes-ti/beagleboard/gadget-init/udhcpd.service | |||
@@ -0,0 +1,11 @@ | |||
1 | [Unit] | ||
2 | Description=DHCP server for USB0 network gadget | ||
3 | After=sys-devices-platform-omap-ti81xx\x2dusbss-musb\x2dhdrc.0-gadget-net-usb0.device | ||
4 | |||
5 | [Service] | ||
6 | ExecStart=/usr/sbin/udhcpd -f -S /etc/udhcpd.conf | ||
7 | ExecStop=/bin/kill -TERM $MAINPID | ||
8 | KillSignal=SIGINT | ||
9 | |||
10 | [Install] | ||
11 | WantedBy=basic.target | ||