From dc1112a6d232e22d9b73f8929f16f885e98f146a Mon Sep 17 00:00:00 2001 From: Miguel Fuertes Date: Sat, 4 Oct 2025 19:01:23 +0200 Subject: [PATCH] Leds + ACM Shell + feed removal --- packages/ledcontrol/files/99-wifi-led | 11 +- .../files/msm8916-usb-gadget.conf | 8 +- .../files/msm8916-usb-gadget.sh | 117 ++++++++---------- packages/uz801-tweaks/Makefile | 39 ++++-- readme.md | 21 ++-- 5 files changed, 97 insertions(+), 99 deletions(-) diff --git a/packages/ledcontrol/files/99-wifi-led b/packages/ledcontrol/files/99-wifi-led index fb634b1..28f2d5e 100644 --- a/packages/ledcontrol/files/99-wifi-led +++ b/packages/ledcontrol/files/99-wifi-led @@ -6,12 +6,17 @@ case "$ACTION" in add) if [ "$DEVICENAME" = "phy0" ]; then sleep 5 - if ip link show phy0-ap0 2>/dev/null >/dev/null; then + + # Check interface status + ap_status=$(ip link show phy0-ap0 2>/dev/null | grep -c "state UP") + sta_status=$(ip link show phy0-sta0 2>/dev/null | grep -c "state UP") + + if [ "$ap_status" -gt 0 ] || [ "$sta_status" -gt 0 ]; then ledcontrol blue on - logger -t wifi-led "phy0-ap0 exists, blue LED ON" + logger -t wifi-led "phy0 interface UP, blue LED ON" else ledcontrol blue off - logger -t wifi-led "phy0-ap0 missing, blue LED OFF" + logger -t wifi-led "No phy0 interface UP, blue LED OFF" fi fi ;; diff --git a/packages/msm8916-usb-gadget/files/msm8916-usb-gadget.conf b/packages/msm8916-usb-gadget/files/msm8916-usb-gadget.conf index e16e36e..3319c2d 100644 --- a/packages/msm8916-usb-gadget/files/msm8916-usb-gadget.conf +++ b/packages/msm8916-usb-gadget/files/msm8916-usb-gadget.conf @@ -14,17 +14,15 @@ ENABLE_RNDIS=1 # MS-Windows compatible ethernet ENABLE_ECM=0 # CDC ECM ethernet ENABLE_NCM=0 # CDC NCM ethernet (Best Performance) ENABLE_UMS=0 # Mass storage -ENABLE_ACM=0 # Serial console +ENABLE_ACM=1 # Serial console # UMS Configuration (if enabled) UMS_IMAGE="/var/lib/msm8916-gadget/usb_mass_storage.img" UMS_IMAGE_SIZE="512M" # Size to create if image doesn't exist (M/G suffix supported) UMS_READONLY=0 -# ACM Configuration (if enabled) -# NOTE: MSM8916 hardware supports maximum 3 ACM serial ports -ACM_COUNT=1 # Number of Serial ports -ACM_SHELL=1 # Enable shell/login on serial ports (1=shell, 0=raw tty) +# Add shell to ACM +ACM_SHELL=1 # UDC Device (auto-detect if empty) UDC_DEVICE="" diff --git a/packages/msm8916-usb-gadget/files/msm8916-usb-gadget.sh b/packages/msm8916-usb-gadget/files/msm8916-usb-gadget.sh index 795c86c..978aeda 100644 --- a/packages/msm8916-usb-gadget/files/msm8916-usb-gadget.sh +++ b/packages/msm8916-usb-gadget/files/msm8916-usb-gadget.sh @@ -2,8 +2,6 @@ # /etc/msm8916-usb-gadget.sh # Main script for MSM8916 USB Gadget -#SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" -#CONFIG_FILE="${SCRIPT_DIR}/msm8916-usb-gadget.conf" CONFIG_FILE="/etc/msm8916-usb-gadget.conf" GADGET_PATH="/sys/kernel/config/usb_gadget/msm8916" @@ -107,42 +105,33 @@ create_storage_image() { log "Storage image created successfully (raw format)" } -setup_serial_consoles() { - if [ "${ENABLE_ACM}" != "1" ]; then - return +manage_serial_shell() { + local inittab_line="ttyGS0::askfirst:/usr/libexec/login.sh" + + # First, always remove any existing ttyGS0 line + if grep -q "ttyGS0" /etc/inittab 2>/dev/null; then + log "Removing existing ttyGS0 line from inittab" + sed -i "/ttyGS0/d" /etc/inittab fi - # Check if shell is enabled - if [ "${ACM_SHELL:-0}" != "1" ]; then - log "Serial ports configured as raw TTY (no shell)" - return + # Then add it back only if ACM is enabled AND shell is requested + if [ "${ENABLE_ACM}" = "1" ] && [ "${ACM_SHELL:-0}" = "1" ]; then + log "Adding serial shell to inittab" + echo "${inittab_line}" >> /etc/inittab fi - log "Configuring serial console shells" - - # Wait for devices to appear - sleep 2 - - acm_count="${ACM_COUNT:-1}" - for i in $(seq 0 $((acm_count - 1))); do - if [ -c "/dev/ttyGS${i}" ]; then - log "Starting console shell on ttyGS${i}" - # Check if already in inittab - if ! grep -q "ttyGS${i}" /etc/inittab 2>/dev/null; then - echo "ttyGS${i}::askfirst:/usr/libexec/login.sh" >> /etc/inittab - fi - else - log "Warning: /dev/ttyGS${i} not found yet" - fi - done - - # Reload procd to pick up changes - killall -HUP procd 2>/dev/null || true + # Reload procd to apply changes + kill -HUP 1 2>/dev/null } + setup_gadget() { log "Setting up USB gadget" + # Check and manage serial shell configuration BEFORE setting up gadget + # This handles cases where device rebooted with different ACM_SHELL setting + manage_serial_shell + # Load required modules modprobe libcomposite @@ -207,18 +196,13 @@ setup_gadget() { has_wakeup=1 fi - # ACM Serial ports + # ACM Serial port (single port) if [ "${ENABLE_ACM}" = "1" ]; then - log "Enabling ACM serial (${ACM_COUNT:-1} ports)" + log "Enabling ACM serial" + cfg_str="${cfg_str}+ACM" - # Create multiple ACM ports if requested - acm_count="${ACM_COUNT:-1}" - for i in $(seq 0 $((acm_count - 1))); do - cfg_str="${cfg_str}+ACM" - mkdir -p functions/acm.GS${i} - # Link directly to config - ln -sf functions/acm.GS${i} "${cfg}" - done + mkdir -p functions/acm.GS0 + ln -sf functions/acm.GS0 "${cfg}" fi # ECM @@ -276,8 +260,19 @@ setup_gadget() { log "Using UDC: ${udc}" echo "${udc}" > UDC || error "Failed to enable UDC" - # Configure serial console shells (only if ACM_SHELL=1) - setup_serial_consoles + # Wait for ttyGS0 to appear if ACM is enabled (to confirm device is ready) + if [ "${ENABLE_ACM}" = "1" ]; then + log "Waiting for ttyGS0 device..." + # Wait for device to appear (max 10 seconds) + for i in $(seq 1 10); do + [ -c "/dev/ttyGS0" ] && break + sleep 1 + done + + if [ ! -c "/dev/ttyGS0" ]; then + log "Warning: /dev/ttyGS0 not found after waiting" + fi + fi # Configure network interfaces via UCI setup_network @@ -293,21 +288,21 @@ setup_network() { if [ "${ENABLE_RNDIS}" = "1" ] && [ -f functions/rndis.usb0/ifname ]; then rndis_if="$(cat functions/rndis.usb0/ifname)" log "Adding ${rndis_if} to LAN" - uci del_list network.@device[0].ports="${rndis_if}" + uci del_list network.@device[0].ports="${rndis_if}" 2>/dev/null uci add_list network.@device[0].ports="${rndis_if}" fi if [ "${ENABLE_ECM}" = "1" ] && [ -f functions/ecm.usb0/ifname ]; then ecm_if="$(cat functions/ecm.usb0/ifname)" log "Adding ${ecm_if} to LAN" - uci del_list network.@device[0].ports="${ecm_if}" + uci del_list network.@device[0].ports="${ecm_if}" 2>/dev/null uci add_list network.@device[0].ports="${ecm_if}" fi if [ "${ENABLE_NCM}" = "1" ] && [ -f functions/ncm.usb0/ifname ]; then ncm_if="$(cat functions/ncm.usb0/ifname)" log "Adding ${ncm_if} to LAN" - uci del_list network.@device[0].ports="${ncm_if}" + uci del_list network.@device[0].ports="${ncm_if}" 2>/dev/null uci add_list network.@device[0].ports="${ncm_if}" fi @@ -318,6 +313,10 @@ setup_network() { teardown_gadget() { log "Tearing down USB gadget" + # Check inittab status and clean up if needed BEFORE tearing down + # This ensures proper cleanup even if device is being shut down + manage_serial_shell + # Check if configfs is mounted if ! mountpoint -q /sys/kernel/config; then log "Configfs not mounted, nothing to tear down" @@ -341,20 +340,11 @@ teardown_gadget() { # Disable gadget echo "" > UDC || true - # Remove serial consoles from inittab (if shell was enabled) - if [ "${ENABLE_ACM}" = "1" ] && [ "${ACM_SHELL:-0}" = "1" ]; then - acm_count="${ACM_COUNT:-1}" - for i in $(seq 0 $((acm_count - 1))); do - sed -i "/ttyGS${i}/d" /etc/inittab 2>/dev/null || true - done - killall -HUP procd 2>/dev/null || true - fi - # Remove network interfaces from LAN for func in functions/*/ifname; do if [ -f "${func}" ]; then iface="$(cat "${func}")" - uci del_list network.@device[0].ports="${iface}" + uci del_list network.@device[0].ports="${iface}" 2>/dev/null fi done @@ -390,19 +380,16 @@ status() { # Show serial console status if [ "${ENABLE_ACM}" = "1" ]; then echo "" - echo "Serial consoles:" - acm_count="${ACM_COUNT:-1}" - for i in $(seq 0 $((acm_count - 1))); do - if [ -c "/dev/ttyGS${i}" ]; then - if [ "${ACM_SHELL:-0}" = "1" ]; then - echo " /dev/ttyGS${i} - available (with shell)" - else - echo " /dev/ttyGS${i} - available (raw TTY)" - fi + echo "Serial console:" + if [ -c "/dev/ttyGS0" ]; then + if [ "${ACM_SHELL:-0}" = "1" ]; then + echo " /dev/ttyGS0 - available (with shell)" else - echo " /dev/ttyGS${i} - not found" + echo " /dev/ttyGS0 - available (raw TTY)" fi - done + else + echo " /dev/ttyGS0 - not found" + fi fi return 0 else diff --git a/packages/uz801-tweaks/Makefile b/packages/uz801-tweaks/Makefile index a1f20ee..d8e1078 100644 --- a/packages/uz801-tweaks/Makefile +++ b/packages/uz801-tweaks/Makefile @@ -1,9 +1,4 @@ -# -# Copyright (C) 2020-2022 HandsomeMod Project -# -# This is free software, licensed under the GNU General Public License v3. -# -# + include $(TOPDIR)/rules.mk PKG_NAME:=uz801-tweaks @@ -14,10 +9,15 @@ PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) include $(INCLUDE_DIR)/package.mk define Package/$(PKG_NAME) - SECTION:=Utilities - CATEGORY:=Utilities - TITLE:=Defaults Setting For uz801v3 - DEPENDS:=+PACKAGE_luci:luci-proto-modemmanager + SECTION:=Utilities + CATEGORY:=Utilities + TITLE:=Defaults Setting For uz801v3 + DEPENDS:=+PACKAGE_luci:luci-proto-modemmanager +endef + +# (Opcional) Descripción +define Package/$(PKG_NAME)/description +Tweaks y defaults para uz801v3, incluyendo limpieza de feeds APK problemáticos. endef define Build/Configure @@ -26,12 +26,27 @@ endef define Build/Compile endef -define Package/$(PKG_NAME)/install +# Instala ficheros de configuración y payload que ya tenías +define Package/$(PKG_NAME)/install $(INSTALL_DIR) $(1)/etc/uci-defaults $(INSTALL_BIN) ./files/uci_defaults $(1)/etc/uci-defaults/99-default-config $(INSTALL_DIR) $(1)/root/ $(INSTALL_BIN) ./files/luci-app-tailscale*.apk $(1)/root/ -endef +endef + +define Package/$(PKG_NAME)/postinst +#!/bin/sh +set -e +FILE="/etc/apk/repositories.d/distfeeds.list" +ROOT="$${IPKG_INSTROOT:-/}" +TARGET_FILE="$$ROOT$$FILE" + +if [ -f "$$TARGET_FILE" ]; then + sed -i '\|/targets/msm89xx/msm8916/packages|d' "$$TARGET_FILE" || true +fi + +exit 0 +endef $(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/readme.md b/readme.md index d84f8ba..18e62ea 100644 --- a/readme.md +++ b/readme.md @@ -14,8 +14,8 @@ Modern version of OpenWrt working on UZ801v3: - Modem Working - ModemManager not showing Rx/Tx in Luci - Wifi Working -- USB gadget working (NCM, RNDIS, MASS, ACM tested!) - - No shell attached to ACM, just pure raw Serial (/dev/ttyGS0) +- USB gadget working (NCM, RNDIS, MASS, ACM Shell) + - Edit [/etc/msm8916-usb-gadget.conf](packages/msm8916-usb-gadget/files/msm8916-usb-gadget.conf) to manage modes. - TUN installed - Wireguard Installed - `hotplug.d` scripts to manage leds, only on/off if iface, no blinking: @@ -24,13 +24,10 @@ Modern version of OpenWrt working on UZ801v3: - Modem Led: [packages/ledcontrol/files/99-wifi-led](packages/ledcontrol/files/99-wifi-led) - Firmware is dumped on first boot from modem/persist partition: - Uses the binaries/firmware from the own device. - - __This might imply that a port for other devices would be easier... but I have not tested it as I only have this device.___ -- Leaves the `luci-app-tailscale` package in `/root` ready to be installed with: - - ``` - apk add --allow-untrusted /root/luci-app-tailscale*.apk - ``` - > It is not auto installed as it will install `tailscale` that is a heavy package and not everyone is using tailscale. +- Leaves the `luci-app-tailscale` package in `/root` ready to be installed: + - It is not auto installed as it will install `tailscale` that is a heavy package and not everyone is using tailscale. + - `apk add --allow-untrusted /root/luci-app-tailscale*.apk` + ### How to build OpenWrt Docker is required! @@ -82,16 +79,12 @@ Once you have selected your region, you'll find folders typically representing T 3. Reboot the device. ### Future: -- ACM gadget not working! - - Also test Shell - Custom package server for msm89xx/msm8916 - Any target specific module not present might require to be built from sources. This repo can be used to do that, run `make menuconfig` before `make -j$(nproc)` and select it from the menu. + - Feed: `https://downloads.openwrt.org/snapshots/targets/msm89xx/msm8916/packages/packages.adb` has been removed from distfeeds file. - Investigate `lpac` and eSIM. -- Convert led `hotplugs` into triggers - Reboot to edl/bootloader from linux/luci. - Swap? Zram?... expand ram with eMMC? -- Remove unused feed: - - _WARNING: updating and opening https://downloads.openwrt.org/snapshots/targets/msm89xx/msm8916/packages/packages.adb: unexpected end of file_ ## Credits - @ghosthgy https://github.com/ghosthgy/openwrt-msm8916