[oe-commits] Angus Ainslie : initscripts : add g_ether for persistent MAC addresses on USB networks
GIT User account
git at amethyst.openembedded.net
Tue May 12 20:43:01 UTC 2009
Module: openembedded.git
Branch: fso/milestone5.5
Commit: 7ee9639efc450e29d79c3b0ed225f50891a9a1d6
URL: http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=7ee9639efc450e29d79c3b0ed225f50891a9a1d6
Author: Angus Ainslie <nytowl at openmoko.org>
Date: Tue May 12 14:23:12 2009 -0600
initscripts : add g_ether for persistent MAC addresses on USB networks
---
recipes/initscripts/initscripts-1.0/g_ether.sh | 93 ++++++++++++++++++++++++
recipes/initscripts/initscripts_1.0.bb | 16 ++++-
2 files changed, 108 insertions(+), 1 deletions(-)
diff --git a/recipes/initscripts/initscripts-1.0/g_ether.sh b/recipes/initscripts/initscripts-1.0/g_ether.sh
new file mode 100644
index 0000000..2271fb2
--- /dev/null
+++ b/recipes/initscripts/initscripts-1.0/g_ether.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+# This script runs very early in order to ensure that the USB network comes
+# up at first system boot. It gathers or creates the necessary host and device
+# mac addresses for the g_ether module at first boot, and writes them to the
+# /etc/modprobe.conf/g_ether.conf file.
+#
+# Due to some oddness with udev, it also modprobes g_ether, only on first boot.
+
+# If the g_ether module options file exists, nothing to do.
+
+if [ ! -e /etc/modprobe.d/g_ether.conf ] ; then
+
+# Gather up all g_ether parameters passed in on the kernel command line, and
+# make sure to pass them to the module; this will ensure similar behavior
+# between the module and built-in.
+
+# Begin by searching the command line for the host and dev addrs
+da=`sed -n -e 's|.*g_ether\.dev_addr\=\(..:..:..:..:..:..\).*|\1|p' /proc/cmdline`
+ha=`sed -n -e 's|.*g_ether\.host_addr\=\(..:..:..:..:..:..\).*|\1|p' /proc/cmdline`
+
+# If the device address is missing, try to find it some other way
+if [ -z "$da" ] ; then
+
+ if grep -q '^Hardware.*GTA02$' /proc/cpuinfo ; then
+
+ # Use the "identity" or "factory" partition on the GTA02.
+ # Ok, this is ugly. We run before udev, so we need to rummage about in
+ # /sys to see if we have an identity partition, and create the device
+ # node if it doesn't already exist.
+ if [ ! -e /dev/mtd5ro -a -e /sys/class/mtd/mtd5ro/dev ] ; then
+ majmin=`sed -e 's|:| |' /sys/class/mtd/mtd5ro/dev`
+ mknod /dev/mtd5ro c $majmin
+ fi
+
+ # We should have the device node now.
+ if [ -e /dev/mtd5ro ] ; then
+
+ # The partition is an ext2 filesystem; we probably should mount the
+ # thing using a loopback mount and then read the correct file from it,
+ # but we're running way early in the boot; not only will that be slow,
+ # there's a good chance it may not even work (udev hasn't run yet).
+ da=`strings /dev/mtd5ro | grep ^U: | sed -n -e 's|U:\(..:..:..:..:..:..\).*|\1|p'`
+
+ fi
+
+ fi
+
+ # TODO: add code to compute a static random address for the GTA01.
+ # For now, GTA01 owners should probably set the addresses in their
+ # u-boot environment and pass in on the command line. A reasonable
+ # solution would be to the random prefix range with the last part of
+ # the mac copied from the bluetooth device.
+
+fi
+
+# If have a device address, now we need to sort out the host address. If it
+# is unspecified, or if it is the same as the device address (Qi does this),
+# compute a new address by just incrementing the device address.
+
+if [ -n "$da" ] ; then
+ if [ -z "$ha" -o "$da" = "$ha" ] ; then
+
+ # We need to compute a new address - split the device address into two
+ # part, and increment the second part.
+ pfx=`echo "$da" | sed -n -e 's|\(..:..:..:\)..:..:..|\1|p'`
+ i=`echo "$da" | sed -n -e 's|..:..:..:\(..\):\(..\):\(..\)|0x\1\2\3|p'`
+
+ # Now increment the mac addr
+ i=$(printf %06x $(($i+1)))
+
+ # And glue the parts back together again.
+ i=`echo "$i" | sed -n -e 's|\(..\)\(..\)\(..\)|\1:\2:\3|p'`
+
+ # Assign the computed host address, if this all worked out.
+ [ -n "$i" -a -n "$pfx" ] && ha=$pfx$i
+
+ fi
+fi
+
+# Compute the command-line options themselves
+[ -n "$da" ] && daddr="dev_addr=$da"
+[ -n "$ha" ] && haddr="host_addr=$ha"
+
+# Write the module options file out even if we have no addresses to write,
+# so that we do not need to run again at next boot.
+[ -d /etc/modprobe.d ] || mkdir /etc/modprobe.d
+echo "options g_ether $daddr $haddr" >/etc/modprobe.d/g_ether.conf
+
+# And now, since this is first boot, we need to probe the module
+modprobe g_ether 2>/dev/null || true
+
+fi
diff --git a/recipes/initscripts/initscripts_1.0.bb b/recipes/initscripts/initscripts_1.0.bb
index 133583b..2ad6422 100644
--- a/recipes/initscripts/initscripts_1.0.bb
+++ b/recipes/initscripts/initscripts_1.0.bb
@@ -4,7 +4,7 @@ PRIORITY = "required"
DEPENDS = "makedevs"
RDEPENDS = "makedevs"
LICENSE = "GPL"
-PR = "r112"
+PR = "r113"
SRC_URI = "file://functions \
file://halt \
@@ -35,6 +35,8 @@ SRC_URI = "file://functions \
SRC_URI_append_arm = " file://alignment.sh"
+SRC_URI_append_openmoko = " file://g_ether.sh"
+
KERNEL_VERSION = ""
do_install () {
@@ -77,6 +79,9 @@ do_install () {
if [ "${TARGET_ARCH}" = "arm" ]; then
install -m 0755 ${WORKDIR}/alignment.sh ${D}${sysconfdir}/init.d
fi
+# if [ "${DISTRO}" = "openmoko" ]; then
+# install -m 0755 ${WORKDIR}/g_ether.sh ${D}${sysconfdir}/init.d
+# fi
#
# Install device dependent scripts
#
@@ -122,6 +127,9 @@ do_install () {
if [ "${TARGET_ARCH}" = "arm" ]; then
ln -sf ../init.d/alignment.sh ${D}${sysconfdir}/rcS.d/S06alignment
fi
+# if [ "${DISTRO}" = "openmoko" ]; then
+# ln -sf ../init.d/g_ether.sh ${D}${sysconfdir}/rcS.d/S02g_ether.sh
+# fi
install -m 0755 ${WORKDIR}/device_table.txt ${D}${sysconfdir}/device_table
}
@@ -130,3 +138,9 @@ do_install () {
do_install_append_angstrom () {
rm ${D}${sysconfdir}/init.d/devices ${D}${sysconfdir}/rcS.d/S05devices
}
+
+# Oepnmoko persistent USB networking
+do_install_append_openmoko () {
+ install -m 0755 ${WORKDIR}/g_ether.sh ${D}${sysconfdir}/init.d
+ ln -sf ../init.d/g_ether.sh ${D}${sysconfdir}/rcS.d/S02g_ether.sh
+}
More information about the Openembedded-commits
mailing list