antenna-select: simple VoCore antenna control scripts

The antenna-select package is used to enable and disable the second
antenna on Morse Micro evaluation kits based on the VoCore module,
or other platforms using the MT7603 2.4 GHz Wi-Fi block.
This commit is contained in:
Morse Micro 2024-09-17 21:49:53 +10:00 committed by Arien Judge
parent fd1bff76d1
commit dcf3a8d43e
3 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,36 @@
#
# Copyright 2022 Morse Micro
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=antenna-select
PKG_RELEASE=1
PKG_MAINTAINER:=Morse Micro <info@morsemicro.com>
include $(INCLUDE_DIR)/package.mk
define Package/antenna-select
SECTION:=Utilities
CATEGORY:=Utilities
TITLE:=VoCore2 Antenna Selector script (defaults 2nd antenna)
DEPENDS:= +kmod-mtd-rw +@BUSYBOX_CONFIG_XXD
endef
define Build/Compile
endef
define Package/antenna-select/install
$(INSTALL_DIR) $(1)/sbin
$(INSTALL_BIN) ./files/sbin/antenna-select $(1)/sbin/
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/etc/init.d/antenna-select $(1)/etc/init.d/antenna-select
endef
$(eval $(call BuildPackage,antenna-select))

View File

@ -0,0 +1,10 @@
#!/bin/sh /etc/rc.common
#
# Copyright (C) 2021-2022 Morse Micro Pty Ltd. All rights reserved.
#
START=01
boot() {
/sbin/antenna-select 2
}

View File

@ -0,0 +1,38 @@
#!/bin/sh
target_byte=52
tempfile=/tmp/mtd2
change_byte() {
dd if=$1 of=/tmp/cbtmpf bs=1 count=$2;
echo -ne "\x$3" >> /tmp/cbtmpf;
let "pos=$2+1";
dd if=$1 of=/tmp/cbtmpf bs=1 skip=$pos seek=$pos
mv /tmp/cbtmpf $1
}
cp /dev/mtd2 $tempfile
current_value=$(xxd -p -l 1 -s $target_byte $tempfile)
if [ "$1" = "1" ]; then
desired_value=11
elif [ "$1" = "2" ]; then
desired_value=22
else
exit 1
fi
if [ $desired_value = $current_value ]; then
echo "the desired antenna is already selected."
exit 0
else
echo "switching the antenna byte from $current_value to $desired_value"
fi
change_byte $tempfile $target_byte $desired_value
insmod mtd-rw i_want_a_brick=1
mtd -e factory write $tempfile factory
rmmod mtd-rw
rm $tempfile
wifi