Skip to content

Commit 8d9278f

Browse files
authored
Merge pull request #8 from hkfuertes/fixes
- More robust Led `hotplugs`, now also read for sta0 (client mode) - Simplified ACM: - Only one port - Optional shell - msm89xx/msm8916 feed removed from apk, to remove warning
2 parents 45f9846 + d483436 commit 8d9278f

File tree

5 files changed

+99
-100
lines changed

5 files changed

+99
-100
lines changed

packages/ledcontrol/files/99-wifi-led

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ case "$ACTION" in
66
add)
77
if [ "$DEVICENAME" = "phy0" ]; then
88
sleep 5
9-
if ip link show phy0-ap0 2>/dev/null >/dev/null; then
9+
10+
# Check interface status
11+
ap_status=$(ip link show phy0-ap0 2>/dev/null | grep -c "state UP")
12+
sta_status=$(ip link show phy0-sta0 2>/dev/null | grep -c "state UP")
13+
14+
if [ "$ap_status" -gt 0 ] || [ "$sta_status" -gt 0 ]; then
1015
ledcontrol blue on
11-
logger -t wifi-led "phy0-ap0 exists, blue LED ON"
16+
logger -t wifi-led "phy0 interface UP, blue LED ON"
1217
else
1318
ledcontrol blue off
14-
logger -t wifi-led "phy0-ap0 missing, blue LED OFF"
19+
logger -t wifi-led "No phy0 interface UP, blue LED OFF"
1520
fi
1621
fi
1722
;;

packages/msm8916-usb-gadget/files/msm8916-usb-gadget.conf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ ENABLE_RNDIS=1 # MS-Windows compatible ethernet
1414
ENABLE_ECM=0 # CDC ECM ethernet
1515
ENABLE_NCM=0 # CDC NCM ethernet (Best Performance)
1616
ENABLE_UMS=0 # Mass storage
17-
ENABLE_ACM=0 # Serial console
17+
ENABLE_ACM=1 # Serial console
1818

1919
# UMS Configuration (if enabled)
2020
UMS_IMAGE="/var/lib/msm8916-gadget/usb_mass_storage.img"
2121
UMS_IMAGE_SIZE="512M" # Size to create if image doesn't exist (M/G suffix supported)
2222
UMS_READONLY=0
2323

24-
# ACM Configuration (if enabled)
25-
# NOTE: MSM8916 hardware supports maximum 3 ACM serial ports
26-
ACM_COUNT=1 # Number of Serial ports
27-
ACM_SHELL=1 # Enable shell/login on serial ports (1=shell, 0=raw tty)
24+
# Add shell to ACM
25+
ACM_SHELL=1
2826

2927
# UDC Device (auto-detect if empty)
3028
UDC_DEVICE=""

packages/msm8916-usb-gadget/files/msm8916-usb-gadget.sh

Lines changed: 53 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# /etc/msm8916-usb-gadget.sh
33
# Main script for MSM8916 USB Gadget
44

5-
#SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
6-
#CONFIG_FILE="${SCRIPT_DIR}/msm8916-usb-gadget.conf"
75
CONFIG_FILE="/etc/msm8916-usb-gadget.conf"
86
GADGET_PATH="/sys/kernel/config/usb_gadget/msm8916"
97

@@ -107,42 +105,33 @@ create_storage_image() {
107105
log "Storage image created successfully (raw format)"
108106
}
109107

110-
setup_serial_consoles() {
111-
if [ "${ENABLE_ACM}" != "1" ]; then
112-
return
113-
fi
108+
manage_serial_shell() {
109+
local inittab_line="ttyGS0::askfirst:/usr/libexec/login.sh"
114110

115-
# Check if shell is enabled
116-
if [ "${ACM_SHELL:-0}" != "1" ]; then
117-
log "Serial ports configured as raw TTY (no shell)"
118-
return
111+
# First, always remove any existing ttyGS0 line
112+
if grep -q "ttyGS0" /etc/inittab 2>/dev/null; then
113+
log "Removing existing ttyGS0 line from inittab"
114+
sed -i "/ttyGS0/d" /etc/inittab
119115
fi
120116

121-
log "Configuring serial console shells"
122-
123-
# Wait for devices to appear
124-
sleep 2
125-
126-
acm_count="${ACM_COUNT:-1}"
127-
for i in $(seq 0 $((acm_count - 1))); do
128-
if [ -c "/dev/ttyGS${i}" ]; then
129-
log "Starting console shell on ttyGS${i}"
130-
# Check if already in inittab
131-
if ! grep -q "ttyGS${i}" /etc/inittab 2>/dev/null; then
132-
echo "ttyGS${i}::askfirst:/usr/libexec/login.sh" >> /etc/inittab
133-
fi
134-
else
135-
log "Warning: /dev/ttyGS${i} not found yet"
136-
fi
137-
done
117+
# Then add it back only if ACM is enabled AND shell is requested
118+
if [ "${ENABLE_ACM}" = "1" ] && [ "${ACM_SHELL:-0}" = "1" ]; then
119+
log "Adding serial shell to inittab"
120+
echo "${inittab_line}" >> /etc/inittab
121+
fi
138122

139-
# Reload procd to pick up changes
140-
killall -HUP procd 2>/dev/null || true
123+
# Reload procd to apply changes
124+
kill -HUP 1 2>/dev/null
141125
}
142126

127+
143128
setup_gadget() {
144129
log "Setting up USB gadget"
145130

131+
# Check and manage serial shell configuration BEFORE setting up gadget
132+
# This handles cases where device rebooted with different ACM_SHELL setting
133+
manage_serial_shell
134+
146135
# Load required modules
147136
modprobe libcomposite
148137

@@ -207,18 +196,13 @@ setup_gadget() {
207196
has_wakeup=1
208197
fi
209198

210-
# ACM Serial ports
199+
# ACM Serial port (single port)
211200
if [ "${ENABLE_ACM}" = "1" ]; then
212-
log "Enabling ACM serial (${ACM_COUNT:-1} ports)"
213-
214-
# Create multiple ACM ports if requested
215-
acm_count="${ACM_COUNT:-1}"
216-
for i in $(seq 0 $((acm_count - 1))); do
217-
cfg_str="${cfg_str}+ACM"
218-
mkdir -p functions/acm.GS${i}
219-
# Link directly to config
220-
ln -sf functions/acm.GS${i} "${cfg}"
221-
done
201+
log "Enabling ACM serial"
202+
cfg_str="${cfg_str}+ACM"
203+
204+
mkdir -p functions/acm.GS0
205+
ln -sf functions/acm.GS0 "${cfg}"
222206
fi
223207

224208
# ECM
@@ -276,8 +260,19 @@ setup_gadget() {
276260
log "Using UDC: ${udc}"
277261
echo "${udc}" > UDC || error "Failed to enable UDC"
278262

279-
# Configure serial console shells (only if ACM_SHELL=1)
280-
setup_serial_consoles
263+
# Wait for ttyGS0 to appear if ACM is enabled (to confirm device is ready)
264+
if [ "${ENABLE_ACM}" = "1" ]; then
265+
log "Waiting for ttyGS0 device..."
266+
# Wait for device to appear (max 10 seconds)
267+
for i in $(seq 1 10); do
268+
[ -c "/dev/ttyGS0" ] && break
269+
sleep 1
270+
done
271+
272+
if [ ! -c "/dev/ttyGS0" ]; then
273+
log "Warning: /dev/ttyGS0 not found after waiting"
274+
fi
275+
fi
281276

282277
# Configure network interfaces via UCI
283278
setup_network
@@ -293,21 +288,21 @@ setup_network() {
293288
if [ "${ENABLE_RNDIS}" = "1" ] && [ -f functions/rndis.usb0/ifname ]; then
294289
rndis_if="$(cat functions/rndis.usb0/ifname)"
295290
log "Adding ${rndis_if} to LAN"
296-
uci del_list network.@device[0].ports="${rndis_if}"
291+
uci del_list network.@device[0].ports="${rndis_if}" 2>/dev/null
297292
uci add_list network.@device[0].ports="${rndis_if}"
298293
fi
299294

300295
if [ "${ENABLE_ECM}" = "1" ] && [ -f functions/ecm.usb0/ifname ]; then
301296
ecm_if="$(cat functions/ecm.usb0/ifname)"
302297
log "Adding ${ecm_if} to LAN"
303-
uci del_list network.@device[0].ports="${ecm_if}"
298+
uci del_list network.@device[0].ports="${ecm_if}" 2>/dev/null
304299
uci add_list network.@device[0].ports="${ecm_if}"
305300
fi
306301

307302
if [ "${ENABLE_NCM}" = "1" ] && [ -f functions/ncm.usb0/ifname ]; then
308303
ncm_if="$(cat functions/ncm.usb0/ifname)"
309304
log "Adding ${ncm_if} to LAN"
310-
uci del_list network.@device[0].ports="${ncm_if}"
305+
uci del_list network.@device[0].ports="${ncm_if}" 2>/dev/null
311306
uci add_list network.@device[0].ports="${ncm_if}"
312307
fi
313308

@@ -318,6 +313,10 @@ setup_network() {
318313
teardown_gadget() {
319314
log "Tearing down USB gadget"
320315

316+
# Check inittab status and clean up if needed BEFORE tearing down
317+
# This ensures proper cleanup even if device is being shut down
318+
manage_serial_shell
319+
321320
# Check if configfs is mounted
322321
if ! mountpoint -q /sys/kernel/config; then
323322
log "Configfs not mounted, nothing to tear down"
@@ -341,20 +340,11 @@ teardown_gadget() {
341340
# Disable gadget
342341
echo "" > UDC || true
343342

344-
# Remove serial consoles from inittab (if shell was enabled)
345-
if [ "${ENABLE_ACM}" = "1" ] && [ "${ACM_SHELL:-0}" = "1" ]; then
346-
acm_count="${ACM_COUNT:-1}"
347-
for i in $(seq 0 $((acm_count - 1))); do
348-
sed -i "/ttyGS${i}/d" /etc/inittab 2>/dev/null || true
349-
done
350-
killall -HUP procd 2>/dev/null || true
351-
fi
352-
353343
# Remove network interfaces from LAN
354344
for func in functions/*/ifname; do
355345
if [ -f "${func}" ]; then
356346
iface="$(cat "${func}")"
357-
uci del_list network.@device[0].ports="${iface}"
347+
uci del_list network.@device[0].ports="${iface}" 2>/dev/null
358348
fi
359349
done
360350

@@ -390,19 +380,16 @@ status() {
390380
# Show serial console status
391381
if [ "${ENABLE_ACM}" = "1" ]; then
392382
echo ""
393-
echo "Serial consoles:"
394-
acm_count="${ACM_COUNT:-1}"
395-
for i in $(seq 0 $((acm_count - 1))); do
396-
if [ -c "/dev/ttyGS${i}" ]; then
397-
if [ "${ACM_SHELL:-0}" = "1" ]; then
398-
echo " /dev/ttyGS${i} - available (with shell)"
399-
else
400-
echo " /dev/ttyGS${i} - available (raw TTY)"
401-
fi
383+
echo "Serial console:"
384+
if [ -c "/dev/ttyGS0" ]; then
385+
if [ "${ACM_SHELL:-0}" = "1" ]; then
386+
echo " /dev/ttyGS0 - available (with shell)"
402387
else
403-
echo " /dev/ttyGS${i} - not found"
388+
echo " /dev/ttyGS0 - available (raw TTY)"
404389
fi
405-
done
390+
else
391+
echo " /dev/ttyGS0 - not found"
392+
fi
406393
fi
407394
return 0
408395
else

packages/uz801-tweaks/Makefile

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#
2-
# Copyright (C) 2020-2022 HandsomeMod Project
3-
#
4-
# This is free software, licensed under the GNU General Public License v3.
5-
#
6-
#
1+
72
include $(TOPDIR)/rules.mk
83

94
PKG_NAME:=uz801-tweaks
@@ -14,10 +9,15 @@ PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
149
include $(INCLUDE_DIR)/package.mk
1510

1611
define Package/$(PKG_NAME)
17-
SECTION:=Utilities
18-
CATEGORY:=Utilities
19-
TITLE:=Defaults Setting For uz801v3
20-
DEPENDS:=+PACKAGE_luci:luci-proto-modemmanager
12+
SECTION:=Utilities
13+
CATEGORY:=Utilities
14+
TITLE:=Defaults Setting For uz801v3
15+
DEPENDS:=+PACKAGE_luci:luci-proto-modemmanager
16+
endef
17+
18+
# (Opcional) Descripción
19+
define Package/$(PKG_NAME)/description
20+
Tweaks y defaults para uz801v3, incluyendo limpieza de feeds APK problemáticos.
2121
endef
2222

2323
define Build/Configure
@@ -26,12 +26,27 @@ endef
2626
define Build/Compile
2727
endef
2828

29-
define Package/$(PKG_NAME)/install
29+
# Instala ficheros de configuración y payload que ya tenías
30+
define Package/$(PKG_NAME)/install
3031
$(INSTALL_DIR) $(1)/etc/uci-defaults
3132
$(INSTALL_BIN) ./files/uci_defaults $(1)/etc/uci-defaults/99-default-config
3233

3334
$(INSTALL_DIR) $(1)/root/
3435
$(INSTALL_BIN) ./files/luci-app-tailscale*.apk $(1)/root/
35-
endef
36+
endef
37+
38+
define Package/$(PKG_NAME)/postinst
39+
#!/bin/sh
40+
set -e
41+
FILE="/etc/apk/repositories.d/distfeeds.list"
42+
ROOT="$${IPKG_INSTROOT:-/}"
43+
TARGET_FILE="$$ROOT$$FILE"
44+
45+
if [ -f "$$TARGET_FILE" ]; then
46+
sed -i '\|/targets/msm89xx/msm8916/packages|d' "$$TARGET_FILE" || true
47+
fi
48+
49+
exit 0
50+
endef
3651

3752
$(eval $(call BuildPackage,$(PKG_NAME)))

readme.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Modern version of OpenWrt working on UZ801v3:
1414
- Modem Working
1515
- ModemManager not showing Rx/Tx in Luci
1616
- Wifi Working
17-
- USB gadget working (NCM, RNDIS, MASS, ACM tested!)
18-
- No shell attached to ACM, just pure raw Serial (/dev/ttyGS0)
17+
- USB gadget working (NCM, RNDIS, MASS, ACM Shell)
18+
- Edit [/etc/msm8916-usb-gadget.conf](packages/msm8916-usb-gadget/files/msm8916-usb-gadget.conf) to manage modes.
1919
- TUN installed
2020
- Wireguard Installed
2121
- `hotplug.d` scripts to manage leds, only on/off if iface, no blinking:
@@ -24,13 +24,10 @@ Modern version of OpenWrt working on UZ801v3:
2424
- Modem Led: [packages/ledcontrol/files/99-wifi-led](packages/ledcontrol/files/99-wifi-led)
2525
- Firmware is dumped on first boot from modem/persist partition:
2626
- Uses the binaries/firmware from the own device.
27-
- __This might imply that a port for other devices would be easier... but I have not tested it as I only have this device.___
28-
- Leaves the `luci-app-tailscale` package in `/root` ready to be installed with:
29-
30-
```
31-
apk add --allow-untrusted /root/luci-app-tailscale*.apk
32-
```
33-
> It is not auto installed as it will install `tailscale` that is a heavy package and not everyone is using tailscale.
27+
- Leaves the `luci-app-tailscale` package in `/root` ready to be installed:
28+
- It is not auto installed as it will install `tailscale` that is a heavy package and not everyone is using tailscale.
29+
- `apk add --allow-untrusted /root/luci-app-tailscale*.apk`
30+
3431

3532
### How to build OpenWrt
3633
Docker is required!
@@ -82,16 +79,13 @@ Once you have selected your region, you'll find folders typically representing T
8279
3. Reboot the device.
8380

8481
### Future:
85-
- ACM gadget not working!
86-
- Also test Shell
8782
- Custom package server for msm89xx/msm8916
8883
- 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.
84+
- Feed: `https://downloads.openwrt.org/snapshots/targets/msm89xx/msm8916/packages/packages.adb` has been removed from distfeeds file.
8985
- Investigate `lpac` and eSIM.
90-
- Convert led `hotplugs` into triggers
9186
- Reboot to edl/bootloader from linux/luci.
9287
- Swap? Zram?... expand ram with eMMC?
93-
- Remove unused feed:
94-
- _WARNING: updating and opening https://downloads.openwrt.org/snapshots/targets/msm89xx/msm8916/packages/packages.adb: unexpected end of file_
88+
- usb-gadget: HOST_MODE flag, to not enter gadget mode.
9589

9690
## Credits
9791
- @ghosthgy https://github.com/ghosthgy/openwrt-msm8916

0 commit comments

Comments
 (0)