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 | |
| 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>
9 files changed, 117 insertions, 3 deletions
diff --git a/recipes-ti/beagleboard/gadget-init.bb b/recipes-ti/beagleboard/gadget-init.bb index ee51586f..defef63b 100644 --- a/recipes-ti/beagleboard/gadget-init.bb +++ b/recipes-ti/beagleboard/gadget-init.bb | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | DESCRIPTION = "Units to initialize usb gadgets" | 1 | DESCRIPTION = "Units to initialize usb gadgets" |
| 2 | 2 | ||
| 3 | PR = "r3" | 3 | PR = "r8" |
| 4 | 4 | ||
| 5 | LICENSE = "MIT" | 5 | LICENSE = "MIT" |
| 6 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58" | 6 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58" |
| @@ -9,13 +9,21 @@ COMPATIBLE_MACHINE = "(ti33x)" | |||
| 9 | PACKAGE_ARCH = "${MACHINE_ARCH}" | 9 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 10 | 10 | ||
| 11 | SRC_URI = "file://storage-gadget-init.service \ | 11 | SRC_URI = "file://storage-gadget-init.service \ |
| 12 | file://network-gadget-init.service \ | ||
| 13 | file://udhcpd.service \ | ||
| 14 | file://udhcpd.conf \ | ||
| 12 | file://99-hokey-pokey.rules \ | 15 | file://99-hokey-pokey.rules \ |
| 13 | file://hokey-pokey.sh \ | 16 | file://hokey-pokey.sh \ |
| 17 | file://bone-gmass-eject.rules \ | ||
| 18 | file://g-storage-reinsert.sh \ | ||
| 19 | file://g-ether-start-service.sh \ | ||
| 20 | file://g-ether-load.sh \ | ||
| 14 | " | 21 | " |
| 15 | 22 | ||
| 16 | do_install() { | 23 | do_install() { |
| 17 | install -d ${D}${base_libdir}/systemd/system/basic.target.wants | 24 | install -d ${D}${base_libdir}/systemd/system/basic.target.wants |
| 18 | install -m 0644 ${WORKDIR}/*.service ${D}${base_libdir}/systemd/system | 25 | install -m 0644 ${WORKDIR}/*.service ${D}${base_libdir}/systemd/system |
| 26 | |||
| 19 | for i in ${WORKDIR}/*.service ; do | 27 | for i in ${WORKDIR}/*.service ; do |
| 20 | install -m 0644 $i ${D}${base_libdir}/systemd/system | 28 | install -m 0644 $i ${D}${base_libdir}/systemd/system |
| 21 | ln -sf ../$(basename $i) ${D}${base_libdir}/systemd/system/basic.target.wants/ | 29 | ln -sf ../$(basename $i) ${D}${base_libdir}/systemd/system/basic.target.wants/ |
| @@ -23,10 +31,27 @@ do_install() { | |||
| 23 | 31 | ||
| 24 | install -d ${D}${sysconfdir}/udev/rules.d | 32 | install -d ${D}${sysconfdir}/udev/rules.d |
| 25 | install -m 0644 ${WORKDIR}/*.rules ${D}${sysconfdir}/udev/rules.d | 33 | install -m 0644 ${WORKDIR}/*.rules ${D}${sysconfdir}/udev/rules.d |
| 34 | install -m 0644 ${WORKDIR}/*.conf ${D}${sysconfdir} | ||
| 26 | 35 | ||
| 27 | install -d ${D}${bindir} | 36 | install -d ${D}${bindir} |
| 28 | install -m 0755 ${WORKDIR}/*.sh ${D}${bindir} | 37 | install -m 0755 ${WORKDIR}/*.sh ${D}${bindir} |
| 29 | |||
| 30 | } | 38 | } |
| 31 | 39 | ||
| 32 | FILES_${PN} = "${base_libdir}/systemd ${sysconfdir} ${bindir}" | 40 | PACKAGES =+ "${PN}-storage ${PN}-network ${PN}-udhcpd" |
| 41 | |||
| 42 | FILES_${PN} = "${sysconfdir}/udev/rules.d/99-hokey-pokey.rules \ | ||
| 43 | ${bindir}/hokey-pokey.sh \" | ||
| 44 | |||
| 45 | FILES_${PN}-storage = "${base_libdir}/systemd/system/storage-gadget-init.service \ | ||
| 46 | ${base_libdir}/systemd/system/basic.target.wants/storage-gadget-init.service \ | ||
| 47 | ${bindir}/g-storage-reinsert.sh \ | ||
| 48 | ${sysconfdir}/udev/rules.d/bone-gmass-eject.rules" | ||
| 49 | |||
| 50 | FILES_${PN}-network = "${base_libdir}/systemd/system/network-gadget-init.service \ | ||
| 51 | ${bindir}/g-ether-load.sh \ | ||
| 52 | ${bindir}/g-ether-start-service.sh" | ||
| 53 | |||
| 54 | FILES_${PN}-udhcpd = "${base_libdir}/systemd/system/udhcpd.service \ | ||
| 55 | ${sysconfdir}/udhcpd.conf" | ||
| 56 | |||
| 57 | 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 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 | ||
