summaryrefslogtreecommitdiff
path: root/pcr/bbb-gadgets
diff options
context:
space:
mode:
Diffstat (limited to 'pcr/bbb-gadgets')
-rw-r--r--pcr/bbb-gadgets/LICENSE17
-rw-r--r--pcr/bbb-gadgets/PKGBUILD30
-rw-r--r--pcr/bbb-gadgets/dhcpd-usb0.conf4
-rwxr-xr-xpcr/bbb-gadgets/g-ether-load.sh71
-rw-r--r--pcr/bbb-gadgets/network-gadget-init.service11
-rw-r--r--pcr/bbb-gadgets/storage-gadget-init.service10
6 files changed, 143 insertions, 0 deletions
diff --git a/pcr/bbb-gadgets/LICENSE b/pcr/bbb-gadgets/LICENSE
new file mode 100644
index 000000000..fb950dc69
--- /dev/null
+++ b/pcr/bbb-gadgets/LICENSE
@@ -0,0 +1,17 @@
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/pcr/bbb-gadgets/PKGBUILD b/pcr/bbb-gadgets/PKGBUILD
new file mode 100644
index 000000000..4affed078
--- /dev/null
+++ b/pcr/bbb-gadgets/PKGBUILD
@@ -0,0 +1,30 @@
+# Contributor (Arch) : Brice Waegeneire < brice dot wge at gmail dot com >
+# Maintainer (Parabola) : Aurélien DESBRIÈRES <aurelien@hackers.camp>
+
+pkgname=bbb-gadgets
+pkgver=20130905
+pkgrel=3
+pkgdesc="Units to initialize usb gadgets for the BeagleBone Black"
+arch=('any')
+url="http://www.beagleboard.org/"
+license=('MIT')
+makedepends=('git')
+depends=('bash' 'systemd' 'dhcp' 'devmem')
+backup=('etc/dhcpd-usb0.conf')
+source=('dhcpd-usb0.conf'
+ 'g-ether-load.sh'
+ 'LICENSE'
+ 'network-gadget-init.service'
+ 'storage-gadget-init.service')
+
+package() {
+ install -d $pkgdir/usr/lib/systemd/system
+ install -m 0644 $srcdir/*.service $pkgdir/usr/lib/systemd/system
+
+ install -D -m 0644 $srcdir/dhcpd-usb0.conf $pkgdir/etc/dhcpd-usb0.conf
+
+ install -D -m 0755 $srcdir/g-ether-load.sh $pkgdir/usr/bin/g-ether-load.sh
+
+ install -D -m 0644 $srcdir/LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
+}
+
diff --git a/pcr/bbb-gadgets/dhcpd-usb0.conf b/pcr/bbb-gadgets/dhcpd-usb0.conf
new file mode 100644
index 000000000..935477523
--- /dev/null
+++ b/pcr/bbb-gadgets/dhcpd-usb0.conf
@@ -0,0 +1,4 @@
+subnet 192.168.7.0 netmask 255.255.255.0 {
+ range 192.168.7.1 192.168.7.1;
+}
+
diff --git a/pcr/bbb-gadgets/g-ether-load.sh b/pcr/bbb-gadgets/g-ether-load.sh
new file mode 100755
index 000000000..e4f39079d
--- /dev/null
+++ b/pcr/bbb-gadgets/g-ether-load.sh
@@ -0,0 +1,71 @@
+#!/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}
+}
+
+mac_address="/proc/device-tree/ocp/ethernet@4a100000/slave@4a100300/mac-address"
+if [ -f ${mac_address} ] ; then
+ DEV_ADDR=$(hexdump -v -e '1/1 "%02X" ":"' ${mac_address} | sed 's/.$//')
+else
+ 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}")
+fi
+
+SERIAL_NUMBER=$(hexdump -e '8/1 "%c"' /sys/bus/i2c/devices/0-0050/eeprom -s 14 -n 2)-$(hexdump -e '8/1 "%c"' /sys/bus/i2c/devices/0-0050/eeprom -s 16 -n 12)
+ISBLACK=$(hexdump -e '8/1 "%c"' /sys/bus/i2c/devices/0-0050/eeprom -s 8 -n 4)
+
+BLACK=""
+
+if [ "${ISBLACK}" = "BBBK" ] ; then
+ BLACK="Black"
+fi
+
+if [ "${ISBLACK}" = "BNLT" ] ; then
+ BLACK="Black"
+fi
+
+modprobe g_multi file=/dev/mmcblk0p1 cdrom=0 stall=0 removable=1 nofua=1 iSerialNumber=${SERIAL_NUMBER} iManufacturer=Circuitco iProduct=BeagleBone${BLACK} host_addr=${DEV_ADDR}
+
+sleep 1
+
+/usr/bin/ifconfig usb0 192.168.7.2 netmask 255.255.255.252
+/usr/bin/route add default gw 192.168.7.1
+
+/usr/bin/dhcpd -4 -q -cf /etc/dhcpd-usb0.conf usb0
diff --git a/pcr/bbb-gadgets/network-gadget-init.service b/pcr/bbb-gadgets/network-gadget-init.service
new file mode 100644
index 000000000..47573a1ec
--- /dev/null
+++ b/pcr/bbb-gadgets/network-gadget-init.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Start USB Ethernet gadget
+Conflicts=storage-gadget-init.service
+
+[Service]
+RemainAfterExit=yes
+ExecStart=/usr/bin/g-ether-load.sh
+ExecStop=/usr/bin/rmmod g_ether
+
+[Install]
+WantedBy=basic.target
diff --git a/pcr/bbb-gadgets/storage-gadget-init.service b/pcr/bbb-gadgets/storage-gadget-init.service
new file mode 100644
index 000000000..8c2a30c12
--- /dev/null
+++ b/pcr/bbb-gadgets/storage-gadget-init.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Start usb mass storage gadget
+After=dev-mmcblk0p1.device
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/g-ether-load.sh
+
+[Install]
+WantedBy=basic.target