1
0
mirror of https://git.yoctoproject.org/meta-ti synced 2026-05-07 20:09:17 +00:00

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>
This commit is contained in:
Joel A Fernandes
2011-11-10 00:06:35 -06:00
committed by Koen Kooi
parent 2cd35f07bf
commit 89c54f502b
9 changed files with 117 additions and 3 deletions
+28 -3
View 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"
@@ -0,0 +1 @@
SUBSYSTEM=="block",ACTION=="change",KERNEL=="mmcblk0p1",RUN+="/usr/bin/g-ether-start-service.sh"
+46
View File
@@ -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}
@@ -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
+4
View File
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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