Skip to content

Commit

Permalink
wifi enabler & factory reset
Browse files Browse the repository at this point in the history
  • Loading branch information
vk496 committed Oct 22, 2018
1 parent 29fceb6 commit afe68c4
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 3 deletions.
19 changes: 19 additions & 0 deletions target/linux/ath79/base-files/etc/rc.button/BTN_1
@@ -0,0 +1,19 @@
#!/bin/sh

. /lib/functions.sh

reset_sdcard() { #Not sure what really do. Check
logger Resetting the SD card reader
echo "0" > /sys/class/gpio/gpio18/value
echo "1" > /sys/class/gpio/gpio18/value
}



board=$(board_name)

case "$board" in
zsun,sdreader)
reset_sdcard
;;
esac
23 changes: 23 additions & 0 deletions target/linux/ath79/base-files/lib/preinit/50_failsafe_wipe
@@ -0,0 +1,23 @@
#!/bin/sh

erase_all() {
echo "Doing a factory reset."
mount_root
firstboot -y
sleep 10
reboot -f
}

failsafe_wipe() {
. /lib/functions.sh

board=$(board_name)

case "$board" in
zsun,sdreader)
erase_all
;;
esac
}

boot_hook_add failsafe failsafe_wipe
51 changes: 51 additions & 0 deletions target/linux/ath79/base-files/lib/preinit/79_enable_wifi
@@ -0,0 +1,51 @@
#!/bin/sh
# Some devices can be only accesed by wifi (zsun for example). To avoid enable wifi automatically, we will do it based on a file presence inside external device


enable_all_wifi_ifaces() {
for entry in $(uci show wireless | grep -E '@wifi-iface\[\d+\]\.device'); do # list all wifi devices
dev=$(echo $entry| sed -nre 's/.*\[(\d+)\].*/\1/p'); #get the asociated number
uci set wireless.@wifi-iface[$dev].disabled='0'
done

uci commit wireless
wifi
}

generic_wifi_on() {

mount_tmp=$(mktemp -d)

for partition in $(cat /proc/partitions | grep -v block | awk '{print $4}' | grep '\d'); do
#No beauty way to determine fs type. Let's try and see what will happen
mount /dev/$partition $mount_tmp
if [ $? -eq 0 ]; then
#mounted!
if [ -f $mount_tmp/openwrt_wireless ]; then
#File available. Let's turn on the wifi

enable_all_wifi_ifaces

rm $mount_tmp/openwrt_wireless
fi
umount /dev/$partition
fi
done

rmdir $mount_tmp

}

enable_wifi() {
. /lib/functions.sh

board=$(board_name)

case "$board" in
zsun,sdreader)
generic_wifi_on
;;
esac
}

boot_hook_add preinit_mount_root enable_wifi
5 changes: 3 additions & 2 deletions target/linux/ath79/dts/ar9331_zsun_sdreader.dts
Expand Up @@ -37,9 +37,10 @@

reset {
label = "zsun,sdreader:reset";
linux,code = <KEY_RESTART>;
linux,input-type = <EV_KEY>;
linux,code = <BTN_1>;
gpios = <&gpio 22 GPIO_ACTIVE_LOW>;
debounce-interval = <60>; // Check
debounce-interval = <60>;
};
};

Expand Down
2 changes: 1 addition & 1 deletion target/linux/ath79/image/generic.mk
Expand Up @@ -345,7 +345,7 @@ TARGET_DEVICES += wd_mynet-wifi-rangeextender
define Device/zsun_sdreader
ATH_SOC := ar9331
DEVICE_TITLE := Zsun WiFi SD Card reader
DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-usb-storage
DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-usb-storage kmod-fs-vfat
IMAGE_SIZE := 16128k
endef
TARGET_DEVICES += zsun_sdreader

0 comments on commit afe68c4

Please sign in to comment.