From 23b3b2f83e0e9b17c77c177115c64cc46b437625 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Wed, 13 Oct 2010 00:12:33 +0200 Subject: [PATCH] openwrt: add button package to v1 backfire build --- mote/v1/openwrt/.config | 5 +- mote/v1/openwrt/files/etc/config/system | 15 ++++-- mote/v1/openwrt/install.sh | 1 + mote/v1/openwrt/package/button/Makefile | 38 +++++++++++++++ .../openwrt/package/button/src/net_defaults | 17 +++++++ mote/v1/openwrt/package/button/src/net_toggle | 47 +++++++++++++++++++ .../310-hotplug_button_jiffies_calc.patch | 27 +++++++++++ 7 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 mote/v1/openwrt/package/button/Makefile create mode 100755 mote/v1/openwrt/package/button/src/net_defaults create mode 100755 mote/v1/openwrt/package/button/src/net_toggle create mode 100644 mote/v1/openwrt/patches/310-hotplug_button_jiffies_calc.patch diff --git a/mote/v1/openwrt/.config b/mote/v1/openwrt/.config index f71b7c1..2f8f497 100644 --- a/mote/v1/openwrt/.config +++ b/mote/v1/openwrt/.config @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit -# OpenWrt version: Backfire (r23144) -# Mon Oct 4 13:53:08 2010 +# OpenWrt version: Backfire (r23346) +# Tue Oct 12 23:21:15 2010 # CONFIG_HAVE_DOT_CONFIG=y # CONFIG_TARGET_ppc40x is not set @@ -1564,6 +1564,7 @@ CONFIG_MADWIFI_RCA_MINSTREL=y # CONFIG_PACKAGE_fdisk is not set # CONFIG_PACKAGE_sfdisk is not set # CONFIG_PACKAGE_swap-utils is not set +CONFIG_PACKAGE_button=y # CONFIG_PACKAGE_comgt is not set # CONFIG_PACKAGE_dropbearconvert is not set # CONFIG_PACKAGE_fconfig is not set diff --git a/mote/v1/openwrt/files/etc/config/system b/mote/v1/openwrt/files/etc/config/system index 7169c5d..247cb06 100644 --- a/mote/v1/openwrt/files/etc/config/system +++ b/mote/v1/openwrt/files/etc/config/system @@ -6,6 +6,15 @@ config system option version 111 config button - option button reset - option action pressed - option handler '/etc/init.d/network restart' + option button reset + option action released + option handler net_toggle + option min 2 + option max 5 + +config button + option button reset + option action released + option handler net_defaults + option min 10 + option max 30 diff --git a/mote/v1/openwrt/install.sh b/mote/v1/openwrt/install.sh index 7d69af4..f062022 100755 --- a/mote/v1/openwrt/install.sh +++ b/mote/v1/openwrt/install.sh @@ -26,6 +26,7 @@ cp .config $BACKFIRE_PATH cp -r files $BACKFIRE_PATH cp patches/300-set.AR2315_RESET_GPIO.to.6.patch $BACKFIRE_PATH/target/linux/atheros/patches-2.6.30 +cp patches/310-hotplug_button_jiffies_calc.patch $BACKFIRE_PATH/target/linux/atheros/patches-2.6.30 cd $BACKFIRE_PATH patch -p0 < $REPO_PATH/patches/100-disable.console.patch diff --git a/mote/v1/openwrt/package/button/Makefile b/mote/v1/openwrt/package/button/Makefile new file mode 100644 index 0000000..48b5f91 --- /dev/null +++ b/mote/v1/openwrt/package/button/Makefile @@ -0,0 +1,38 @@ +# Copyright (c) 2010 flukso.net + +include $(TOPDIR)/rules.mk + +PKG_NAME:=button +PKG_VERSION:=1.0 +PKG_RELEASE:=1 + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk + +define Package/button + SECTION:=utils + CATEGORY:=Utilities + DEPENDS:= + TITLE:=Button +endef + +define Package/button/description + Helper bash scripts used as a callback for hotplug button events. net_toggle toggles between ethernet and wifi mode. net_defaults reverts all firewall, network and wireless settings to factory defaults. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(CP) ./src/* $(PKG_BUILD_DIR)/ +endef + +define Build/Compile +endef + +define Package/button/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/net_toggle $(1)/usr/sbin/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/net_defaults $(1)/usr/sbin/ +endef + +$(eval $(call BuildPackage,button)) diff --git a/mote/v1/openwrt/package/button/src/net_defaults b/mote/v1/openwrt/package/button/src/net_defaults new file mode 100755 index 0000000..8efb631 --- /dev/null +++ b/mote/v1/openwrt/package/button/src/net_defaults @@ -0,0 +1,17 @@ +#!/bin/sh +# Copyright (c) 2010 flukso.net + +cd /rom/etc/config +cp firewall network wireless /etc/config + +logger 'returning to firewall, network and wireless defaults' + +gpioctl dirout 4 + +for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +do + gpioctl clear 4 + gpioctl set 4 +done + +/etc/init.d/network restart diff --git a/mote/v1/openwrt/package/button/src/net_toggle b/mote/v1/openwrt/package/button/src/net_toggle new file mode 100755 index 0000000..2d45a42 --- /dev/null +++ b/mote/v1/openwrt/package/button/src/net_toggle @@ -0,0 +1,47 @@ +#!/bin/sh +# Copyright (c) 2010 flukso.net + +to_wifi () +{ + uci set firewall.@zone[1].input=REJECT + uci set network.wan.ifname=ath0 + uci set network.lan.ifname=eth0 + uci set wireless.wifi0.disabled=0 + uci set wireless.@wifi-iface[0].network=wan + uci set wireless.@wifi-iface[0].mode=sta + uci commit + logger 'toggled to wifi mode' +} + +to_eth () +{ + uci set firewall.@zone[1].input=ACCEPT + uci set network.wan.ifname=eth0 + uci set network.lan.ifname=ath0 + uci set wireless.wifi0.disabled=1 + uci set wireless.@wifi-iface[0].network=lan + uci set wireless.@wifi-iface[0].mode=ap + uci commit + logger 'toggled to eth mode' +} + + +MODE=$(uci get network.wan.ifname) + +if [ $MODE == eth0 ] +then + to_wifi +elif [ $MODE == ath0 ] +then + to_eth +fi + +gpioctl dirout 4 + +for i in 1 2 3 4 5 +do + gpioctl clear 4 + gpioctl set 4 +done + +/etc/init.d/network restart diff --git a/mote/v1/openwrt/patches/310-hotplug_button_jiffies_calc.patch b/mote/v1/openwrt/patches/310-hotplug_button_jiffies_calc.patch new file mode 100644 index 0000000..5112f19 --- /dev/null +++ b/mote/v1/openwrt/patches/310-hotplug_button_jiffies_calc.patch @@ -0,0 +1,27 @@ +--- a/arch/mips/ar231x/reset.c ++++ b/arch/mips/ar231x/reset.c +@@ -19,6 +19,7 @@ + struct work_struct wq; + int set; + unsigned long jiffies; ++ unsigned long jiffies_prev; + }; + + static struct timer_list rst_button_timer; +@@ -68,7 +69,7 @@ + add_msg(skb, "SUBSYSTEM=button"); + add_msg(skb, "BUTTON=reset"); + add_msg(skb, (event->set ? "ACTION=pressed" : "ACTION=released")); +- sprintf(buf, "SEEN=%ld", (event->jiffies - seen)/HZ); ++ sprintf(buf, "SEEN=%lu", (event->jiffies - event->jiffies_prev)/HZ); + add_msg(skb, buf); + snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum()); + add_msg(skb, buf); +@@ -127,6 +128,7 @@ + no_release_workaround = 0; + + event->jiffies = jiffies; ++ event->jiffies_prev = seen; + + INIT_WORK(&event->wq, hotplug_button); + schedule_work(&event->wq);