gadget-init: Add network-gadget services and other fixes
authorJoel A Fernandes <joelagnel@ti.com>
Thu, 10 Nov 2011 06:06:35 +0000 (00:06 -0600)
committerKoen Kooi <koen@dominion.thruhere.net>
Thu, 10 Nov 2011 07:23:08 +0000 (08:23 +0100)
* 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>
recipes-ti/beagleboard/gadget-init.bb
recipes-ti/beagleboard/gadget-init/bone-gmass-eject.rules [new file with mode: 0644]
recipes-ti/beagleboard/gadget-init/g-ether-load.sh [new file with mode: 0755]
recipes-ti/beagleboard/gadget-init/g-ether-start-service.sh [new file with mode: 0755]
recipes-ti/beagleboard/gadget-init/g-storage-reinsert.sh [new file with mode: 0755]
recipes-ti/beagleboard/gadget-init/network-gadget-init.service [new file with mode: 0644]
recipes-ti/beagleboard/gadget-init/storage-gadget-init.service
recipes-ti/beagleboard/gadget-init/udhcpd.conf [new file with mode: 0644]
recipes-ti/beagleboard/gadget-init/udhcpd.service [new file with mode: 0644]

index ee51586f32fb73ea7b86d54db99d1579c158d4fc..defef63bca0a9c1fa7ca9b0679296f4912b4bf1c 100644 (file)
@@ -1,6 +1,6 @@
 DESCRIPTION = "Units to initialize usb gadgets"
 
-PR = "r3"
+PR = "r8"
 
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
@@ -9,13 +9,21 @@ COMPATIBLE_MACHINE = "(ti33x)"
 PACKAGE_ARCH = "${MACHINE_ARCH}"
 
 SRC_URI = "file://storage-gadget-init.service \
+           file://network-gadget-init.service \
+           file://udhcpd.service \
+           file://udhcpd.conf \
            file://99-hokey-pokey.rules \
            file://hokey-pokey.sh \
+           file://bone-gmass-eject.rules \
+           file://g-storage-reinsert.sh \
+           file://g-ether-start-service.sh \
+           file://g-ether-load.sh \
           "
 
 do_install() {
        install -d ${D}${base_libdir}/systemd/system/basic.target.wants
        install -m 0644 ${WORKDIR}/*.service ${D}${base_libdir}/systemd/system
+
        for i in ${WORKDIR}/*.service ; do
                install -m 0644 $i ${D}${base_libdir}/systemd/system
                ln -sf ../$(basename $i) ${D}${base_libdir}/systemd/system/basic.target.wants/
@@ -23,10 +31,27 @@ do_install() {
 
        install -d ${D}${sysconfdir}/udev/rules.d
        install -m 0644 ${WORKDIR}/*.rules ${D}${sysconfdir}/udev/rules.d
+       install -m 0644 ${WORKDIR}/*.conf ${D}${sysconfdir}
 
        install -d ${D}${bindir}
        install -m 0755 ${WORKDIR}/*.sh ${D}${bindir}
-
 }
 
-FILES_${PN} = "${base_libdir}/systemd ${sysconfdir} ${bindir}"
+PACKAGES =+ "${PN}-storage ${PN}-network ${PN}-udhcpd"
+
+FILES_${PN} = "${sysconfdir}/udev/rules.d/99-hokey-pokey.rules \
+               ${bindir}/hokey-pokey.sh \"
+
+FILES_${PN}-storage = "${base_libdir}/systemd/system/storage-gadget-init.service \
+                       ${base_libdir}/systemd/system/basic.target.wants/storage-gadget-init.service \
+                       ${bindir}/g-storage-reinsert.sh \
+                       ${sysconfdir}/udev/rules.d/bone-gmass-eject.rules"
+
+FILES_${PN}-network = "${base_libdir}/systemd/system/network-gadget-init.service \
+                       ${bindir}/g-ether-load.sh \
+                       ${bindir}/g-ether-start-service.sh"
+
+FILES_${PN}-udhcpd = "${base_libdir}/systemd/system/udhcpd.service \
+                      ${sysconfdir}/udhcpd.conf"
+
+RRECOMMENDS_${PN} = "${PN}-storage ${PN}-network ${PN}-udhcpd"
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 (file)
index 0000000..ee6f93e
--- /dev/null
@@ -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 (executable)
index 0000000..f940064
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+function get_devmem()
+{
+       /usr/bin/devmem2 $1 | grep ": " | cut -d ":" -f 2|cut -d "x" -f 2
+}
+
+function hex_to_mac_addr()
+{
+       addr=$1
+       n=0
+       mac_addr=$(echo ${addr} | while read -r -n2 c; do 
+               if [ ! -z "$c" ]; then
+                       if [ $n -ne 0 ] ; then
+                               echo -n ":${c}"
+                       else
+                               echo -n "${c}"
+                       fi
+               fi
+               n=$(($n+1))
+       done)
+       echo ${mac_addr}
+}
+
+function reverse_bytes()
+{
+       addr=$1
+       New_addr=$(echo ${addr} | while read -r -n2 c; do 
+               if [ ! -z "$c" ]; then
+                       New_addr=${c}${New_addr}
+               else echo
+                       echo ${New_addr}
+               fi
+       done)
+       echo ${New_addr}
+}
+
+DEVMEM_ADDR_LO=$(get_devmem 0x44e10638|bc)
+DEVMEM_ADDR_LO=$(reverse_bytes ${DEVMEM_ADDR_LO})
+
+DEVMEM_ADDR_HI=$(get_devmem 0x44e1063C)
+DEVMEM_ADDR_HI=$(reverse_bytes ${DEVMEM_ADDR_HI})
+
+DEV_ADDR=$(hex_to_mac_addr "${DEVMEM_ADDR_HI}${DEVMEM_ADDR_LO}")
+
+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 (executable)
index 0000000..2db16c2
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+if [ -a /sys/devices/platform/omap/ti81xx-usbss/musb-hdrc.0/gadget/lun0/file ]
+then
+       x=$(cat /sys/devices/platform/omap/ti81xx-usbss/musb-hdrc.0/gadget/lun0/file)
+       if [ -z "$x" ]
+       then
+               /bin/systemctl stop storage-gadget-init.service
+               /bin/systemctl start network-gadget-init.service
+               /bin/systemctl start udhcpd.service
+       fi
+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 (executable)
index 0000000..d358640
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+/bin/systemctl stop storage-gadget-init.service
+/bin/systemctl stop network-gadget-init.service
+/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 (file)
index 0000000..979d8aa
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Description=Start USB Ethernet gadget
+Conflicts=storage-gadget-init.service
+
+[Service]
+RemainAfterExit=yes
+ExecStart=/usr/bin/g-ether-load.sh
+ExecStartPost=/sbin/ifconfig usb0 192.168.7.2 netmask 255.255.255.252
+ExecStop=/sbin/rmmod g_ether
index 2fe48e15ee71f6f6e3fa23892aa22ad2294f4933..9a8513e8a3f332608d4be4ec3030f17fa034ff42 100644 (file)
@@ -3,7 +3,9 @@ Description=Start usb mass storage gadget
 After=dev-mmcblk0p1.device
 
 [Service]
+RemainAfterExit=yes
 ExecStart=/sbin/modprobe g_mass_storage file=/dev/mmcblk0p1 cdrom=0 stall=0 removable=1 nofua=1
+ExecStop=/sbin/rmmod g_mass_storage
 
 [Install]
 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 (file)
index 0000000..3bcf00f
--- /dev/null
@@ -0,0 +1,5 @@
+start      192.168.7.1
+end        192.168.7.1
+interface  usb0
+max_leases 1
+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 (file)
index 0000000..f076673
--- /dev/null
@@ -0,0 +1,11 @@
+[Unit]
+Description=DHCP server for USB0 network gadget
+After=sys-devices-platform-omap-ti81xx\x2dusbss-musb\x2dhdrc.0-gadget-net-usb0.device
+
+[Service]
+ExecStart=/usr/sbin/udhcpd -f -S /etc/udhcpd.conf
+ExecStop=/bin/kill -TERM $MAINPID
+KillSignal=SIGINT
+
+[Install]
+WantedBy=basic.target