Implement 0010 RPM/L2/WCD/UART deep-standby, Adreno 304 ICC/SMMU fixes, and C11 autostart daemons
- patches/kernel/0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch and device DTS/DTB files (nokia-{argon,beatles,beatles-cover,coconut,sparkler,leo}): vMPM APSS RPM sleep, L2 SAW2 collapse, WCD-digital runtime PM, PM8909 LDO seeding, ttyMSM0 disable, dynamic msm_gpu gfx-mem BIMC interconnect scaling (mas_oxili), and qcom_iommu context restore + atomic TLB flush on resume.
- Replace Python/shell autostart loops with compiled C11 ARM ELF daemons (bananarchy-dsds, bananarchy-modemmonitor, bananarchy-soundmonitor, bananarchy-notifmonitor, bananarchy-run-aligned, bananarchy-session-loop) plus scripts/test-dsds-daemon.py.
- Update scripts/check-rebuild.sh, CHANGELOG.md, BATTERY-OPTIMIZATION-ANALYSIS.md, MANUAL.md, README.md, and AGENTS.md with verified a1114 (carbonara) image/archive pins and guards.
This commit is contained in:
1 parent
96c66bf0c6
commit
2ae4ef34a2
86 files changed
+99754
-94563
No files matched your search
@@ -101,12 +101,16 @@ if command -v docker >/dev/null 2>&1; then
|
||||
echo " -> Missing prebuilt kernel modules or DTBs; running scripts/build-kernel-audio.sh..."
|
||||
"$BASE_DIR/scripts/build-kernel-audio.sh"
|
||||
fi
|
||||
if [ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-lid" ] || \
|
||||
[ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle" ] || \
|
||||
[ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-volume-keys" ]; then
|
||||
echo " -> Missing compiled idle daemons; running scripts/build-bananarchy-daemons.sh..."
|
||||
"$BASE_DIR/scripts/build-bananarchy-daemons.sh"
|
||||
fi
|
||||
for _req_daemon in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys \
|
||||
bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor \
|
||||
bananarchy-notifmonitor bananarchy-run-aligned \
|
||||
bananarchy-session-loop; do
|
||||
if [ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/$_req_daemon" ]; then
|
||||
echo " -> Missing compiled daemons; running scripts/build-bananarchy-daemons.sh..."
|
||||
"$BASE_DIR/scripts/build-bananarchy-daemons.sh"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ ! -f "$BASE_DIR/prebuilt/bantam/bantam" ]; then
|
||||
echo " -> Missing prebuilt bantam binary; running scripts/build-bantam.sh..."
|
||||
"$BASE_DIR/scripts/build-bantam.sh"
|
||||
@@ -119,7 +123,10 @@ cp -af "$BASE_DIR/overlay/rootfs/." "$TARGET_ROOTFS/"
|
||||
rm -f "$TARGET_ROOTFS/usr/bin/bananarchy-lid.py" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-cover-idle.py" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-volume-keys.py"
|
||||
for daemon in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys; do
|
||||
for daemon in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys \
|
||||
bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor \
|
||||
bananarchy-notifmonitor bananarchy-run-aligned \
|
||||
bananarchy-session-loop; do
|
||||
cp -af "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/$daemon" \
|
||||
"$TARGET_ROOTFS/usr/bin/$daemon"
|
||||
chmod 0755 "$TARGET_ROOTFS/usr/bin/$daemon"
|
||||
@@ -177,6 +184,7 @@ chown 0:0 "$TARGET_ROOTFS/etc/chrony/chrony.conf" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-bt-scan.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-bt-le-enable.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-dpm.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/sxmo_run_aligned.sh" \
|
||||
"$TARGET_ROOTFS/etc/init.d/bananarchy-time-sync" \
|
||||
"$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh" \
|
||||
"$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/20-bananarchy-time-sync.sh" \
|
||||
@@ -203,6 +211,7 @@ chmod 0755 "$TARGET_ROOTFS/usr/bin/bananarchy-idle-blank.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-bt-scan.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-bt-le-enable.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-dpm.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/sxmo_run_aligned.sh" \
|
||||
"$TARGET_ROOTFS/etc/init.d/bananarchy-time-sync" \
|
||||
"$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh" \
|
||||
"$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/20-bananarchy-time-sync.sh" \
|
||||
|
||||
@@ -6,7 +6,7 @@ BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
SRC_DIR="$BASE_DIR/src/bananarchy-daemons"
|
||||
PREBUILT="$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin"
|
||||
OVERLAY="$BASE_DIR/overlay/rootfs/usr/bin"
|
||||
NAMES="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys"
|
||||
NAMES="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor bananarchy-notifmonitor bananarchy-run-aligned bananarchy-session-loop"
|
||||
|
||||
check_artifacts() {
|
||||
for name in $NAMES; do
|
||||
@@ -58,19 +58,20 @@ EOF
|
||||
musl-dev-armv7 linux-headers >/dev/null
|
||||
mkdir -p /bananarchy/prebuilt/bananarchy-daemons/usr/bin \
|
||||
/bananarchy/overlay/rootfs/usr/bin
|
||||
for name in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys; do
|
||||
for name in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys \
|
||||
bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor \
|
||||
bananarchy-notifmonitor bananarchy-run-aligned \
|
||||
bananarchy-session-loop; do
|
||||
armv7-alpine-linux-musleabihf-gcc -std=c11 -O2 -Wall -Wextra -Werror -s \
|
||||
-I/bananarchy/src/bananarchy-daemons \
|
||||
-o "/bananarchy/prebuilt/bananarchy-daemons/usr/bin/$name" \
|
||||
"/bananarchy/src/bananarchy-daemons/$name.c"
|
||||
cp -a "/bananarchy/prebuilt/bananarchy-daemons/usr/bin/$name" \
|
||||
"/bananarchy/overlay/rootfs/usr/bin/$name"
|
||||
chown "$HOST_UID:$HOST_GID" \
|
||||
"/bananarchy/overlay/rootfs/usr/bin/$name"
|
||||
echo "[+] built $name"
|
||||
done
|
||||
chown -R "$HOST_UID:$HOST_GID" \
|
||||
/bananarchy/prebuilt/bananarchy-daemons \
|
||||
/bananarchy/overlay/rootfs/usr/bin/bananarchy-lid \
|
||||
/bananarchy/overlay/rootfs/usr/bin/bananarchy-cover-idle \
|
||||
/bananarchy/overlay/rootfs/usr/bin/bananarchy-volume-keys
|
||||
chown -R "$HOST_UID:$HOST_GID" /bananarchy/prebuilt/bananarchy-daemons
|
||||
'
|
||||
check_artifacts
|
||||
@@ -90,10 +90,15 @@ EOF
|
||||
echo "[2h/5] Applying MSM8909 deep-standby RPM clock, USB PHY, Wi-Fi BET/offload, and DDR patch..."
|
||||
patch -p1 < /bananarchy/patches/kernel/0009-msm8909-deep-standby-rpm-usb-wifi-ddr.patch
|
||||
fi
|
||||
if ! grep -q "qcom_mpm_enter_sleep" drivers/irqchip/irq-qcom-mpm.c 2>/dev/null; then
|
||||
echo "[2i/5] Applying MSM8909 RPM LPM, BIMC/WCD/LDO cleanup, and UART disable patch..."
|
||||
patch -p1 < /bananarchy/patches/kernel/0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch
|
||||
fi
|
||||
if [ ! -f include/config/auto.conf ] || \
|
||||
! grep -q "CONFIG_NETFILTER_XT_MATCH_OWNER=m" .config 2>/dev/null || \
|
||||
! grep -q "CONFIG_INTERCONNECT_QCOM_MSM8909=y" .config 2>/dev/null || \
|
||||
! grep -q "CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT=y" .config 2>/dev/null; then
|
||||
! grep -q "CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT=y" .config 2>/dev/null || \
|
||||
! grep -q "CONFIG_QCOM_RPM_MASTER_STATS=y" .config 2>/dev/null; then
|
||||
echo "[3/5] Preparing kernel configuration..."
|
||||
cp /bananarchy/patches/kernel/config-bananarchy-msm8909.armv7 .config
|
||||
make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- olddefconfig
|
||||
@@ -129,6 +134,8 @@ EOF
|
||||
patch -p1 < /bananarchy/patches/kernel/0008-msm8909-standby-power-icc-wifi-usb-panel.patch
|
||||
echo "[2h/5] Applying MSM8909 deep-standby RPM clock, USB PHY, Wi-Fi BET/offload, and DDR patch..."
|
||||
patch -p1 < /bananarchy/patches/kernel/0009-msm8909-deep-standby-rpm-usb-wifi-ddr.patch
|
||||
echo "[2i/5] Applying MSM8909 RPM LPM, BIMC/WCD/LDO cleanup, and UART disable patch..."
|
||||
patch -p1 < /bananarchy/patches/kernel/0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch
|
||||
|
||||
echo "[3/5] Preparing kernel configuration and Module.symvers..."
|
||||
cp /bananarchy/patches/kernel/config-bananarchy-msm8909.armv7 .config
|
||||
|
||||
@@ -339,6 +339,9 @@ for cmdline_file in "$BASE_DIR"/devices/*/kernel-cmdline.conf \
|
||||
if grep -qxF 'earlycon' "$cmdline_file"; then
|
||||
fail "$(basename "$cmdline_file") still contains earlycon"
|
||||
fi
|
||||
if grep -qF 'console=ttyMSM0' "$cmdline_file"; then
|
||||
fail "$(basename "$cmdline_file") still contains console=ttyMSM0"
|
||||
fi
|
||||
done
|
||||
# A pre-existing rootfs/ build tree is reused by rebuild-image.sh, so its
|
||||
# copies of the device cmdline fragments must stay in sync with the overlay.
|
||||
@@ -347,6 +350,9 @@ for cmdline_file in "$BASE_DIR"/rootfs/usr/lib/kernel-cmdline.d/50-device-*.conf
|
||||
if grep -qxF 'earlycon' "$cmdline_file"; then
|
||||
fail "rootfs/usr/lib/kernel-cmdline.d/$(basename "$cmdline_file") still contains earlycon"
|
||||
fi
|
||||
if grep -qF 'console=ttyMSM0' "$cmdline_file"; then
|
||||
fail "rootfs/usr/lib/kernel-cmdline.d/$(basename "$cmdline_file") still contains console=ttyMSM0"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "[check] BusyBox applet symlinks..."
|
||||
@@ -372,9 +378,9 @@ fi
|
||||
|
||||
echo "[check] Known-good flashable image set..."
|
||||
for pair in \
|
||||
"f4c8921a674944b2687b2d7bcb52e6f3cb81ad5997fddac969949305c0479c60 images/bananarchy-nokia-argon.img" \
|
||||
"fd29593b30008b65b7b30b867824ce3f3f4e1f70cda4f012dde1a2c14dd316ba images/bananarchy-nokia-beatles.img" \
|
||||
"d6cb9d5f13bc00815c4fcde5cf32b92ce9d7873683d3cec8b1346a53801ea08a images/boot-bananarchy-nokia-beatles.img" \
|
||||
"77a1201a2a93a076a8dd9a6f11c8ceb5f69b94b2ca7abb3dfeba5354b83c034c images/bananarchy-nokia-argon.img" \
|
||||
"c027c3151f3cf45e7a067beed77d77ff4a1954ababda6f1a2eba5a02b2414b24 images/bananarchy-nokia-beatles.img" \
|
||||
"5a7a391aff3fc8fc95b07b532eedce1ee17991574fb45ca4359c0504aeb82324 images/boot-bananarchy-nokia-beatles.img" \
|
||||
"b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do
|
||||
set -- $pair
|
||||
want=$1
|
||||
@@ -388,7 +394,7 @@ for pair in \
|
||||
done
|
||||
|
||||
echo "[check] Compiled idle daemons..."
|
||||
DAEMONS="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys"
|
||||
DAEMONS="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor bananarchy-notifmonitor bananarchy-run-aligned bananarchy-session-loop"
|
||||
for daemon in $DAEMONS; do
|
||||
for artifact in "prebuilt/bananarchy-daemons/usr/bin/$daemon" \
|
||||
"overlay/rootfs/usr/bin/$daemon"; do
|
||||
@@ -413,7 +419,13 @@ fi
|
||||
for src in src/bananarchy-daemons/common.h \
|
||||
src/bananarchy-daemons/bananarchy-lid.c \
|
||||
src/bananarchy-daemons/bananarchy-cover-idle.c \
|
||||
src/bananarchy-daemons/bananarchy-volume-keys.c; do
|
||||
src/bananarchy-daemons/bananarchy-volume-keys.c \
|
||||
src/bananarchy-daemons/bananarchy-dsds.c \
|
||||
src/bananarchy-daemons/bananarchy-modemmonitor.c \
|
||||
src/bananarchy-daemons/bananarchy-soundmonitor.c \
|
||||
src/bananarchy-daemons/bananarchy-notifmonitor.c \
|
||||
src/bananarchy-daemons/bananarchy-run-aligned.c \
|
||||
src/bananarchy-daemons/bananarchy-session-loop.c; do
|
||||
if [ ! -f "$BASE_DIR/$src" ]; then
|
||||
fail "missing C daemon source: $src"
|
||||
fi
|
||||
@@ -1196,21 +1208,61 @@ for dts in \
|
||||
! grep -qF 'qcom,msm8909-pcnoc' "$dts" || \
|
||||
! grep -qF 'qcom,msm8909-snoc' "$dts" || \
|
||||
! grep -qF 'interconnects = <0xa0 0x00 0xa0 0x06>;' "$dts" || \
|
||||
! grep -qF 'interconnects = <0xa0 0x01 0xa0 0x06>;' "$dts" || \
|
||||
! grep -qF 'interconnect-names = "gfx-mem";' "$dts" || \
|
||||
! grep -qF 'opp-peak-kBps = <0x25800>;' "$dts"; then
|
||||
fail "${dts#"$BASE_DIR/"} is missing MSM8909 interconnect/OPP bandwidth nodes or 0x25800 floor"
|
||||
fail "${dts#"$BASE_DIR/"} is missing MSM8909 interconnect/GPU-BIMC/OPP bandwidth nodes or 0x25800 floor"
|
||||
fi
|
||||
done
|
||||
if ! grep -qxF 'MODEM_DRX_MODE=6' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
|
||||
! grep -qxF 'DSDS_SECONDARY_MODE=active' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
|
||||
! grep -qxF 'CPU_RPM_SLEEP=1' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
|
||||
! grep -qxF 'CPU_L2_SLEEP=1' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
|
||||
! grep -qxF 'WIFI_SCREEN_OFF_IPV6_MUTE=1' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
|
||||
! grep -qxF 'WIFI_STANDBY_RAT=keep' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
|
||||
! grep -qF 'if [ "$port" = "all" ]; then' "$BASE_DIR/overlay/rootfs/usr/libexec/msm-modem-uim-selection" || \
|
||||
! grep -qF 'def screen_is_idle():' "$BASE_DIR/overlay/rootfs/usr/libexec/msm-modem-uim-selection" || \
|
||||
! grep -qF 'exec /usr/bin/bananarchy-dsds' "$BASE_DIR/overlay/rootfs/usr/libexec/msm-modem-uim-selection" || \
|
||||
grep -qF 'dsds-daemon <<' "$BASE_DIR/overlay/rootfs/usr/libexec/msm-modem-uim-selection" || \
|
||||
! grep -qF 'screen_is_idle(' "$BASE_DIR/src/bananarchy-daemons/bananarchy-dsds.c" || \
|
||||
! grep -qF 'ExecStart=/usr/bin/bananarchy-modemmonitor' "$BASE_DIR/overlay/rootfs/usr/share/superd/services/sxmo_modemmonitor.service" || \
|
||||
! grep -qF 'ExecStart=/usr/bin/bananarchy-soundmonitor' "$BASE_DIR/overlay/rootfs/usr/share/superd/services/sxmo_soundmonitor.service" || \
|
||||
! grep -qF 'ExecStart=/usr/bin/bananarchy-notifmonitor' "$BASE_DIR/overlay/rootfs/usr/share/superd/services/sxmo_notificationmonitor.service" || \
|
||||
! grep -qF 'exec /usr/bin/bananarchy-run-aligned' "$BASE_DIR/overlay/rootfs/usr/bin/sxmo_run_aligned.sh" || \
|
||||
! grep -qF 'exec /usr/bin/bananarchy-session-loop' "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-x11-session.sh" || \
|
||||
! grep -qF 'for dev in /dev/wwan0at*;' "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-power-policy.sh" || \
|
||||
! grep -qF 'modem-ready) modem_ready ;;' "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-power-policy.sh" || \
|
||||
! grep -qF '/usr/bin/bananarchy-power-policy.sh modem-ready' "$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_modem.sh" || \
|
||||
! grep -qF 'WIFI_OFFLOAD_PATH=/sys/module/wcn36xx/parameters/screen_off_offload' \
|
||||
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-display-power-sync" || \
|
||||
! grep -qF 'SPM_SCREEN_OFF_PATH=/sys/module/cpuidle_qcom_spm/parameters/screen_off' \
|
||||
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-display-power-sync"; then
|
||||
fail "userspace DSDS DRX, dsds-daemon dark-screen gate, or wcn36xx screen_off_offload sync is missing"
|
||||
fail "userspace DSDS DRX, compiled C daemons, CPU/L2/Wi-Fi power policy, or wcn36xx screen_off_offload sync is missing"
|
||||
fi
|
||||
if [ ! -f "$BASE_DIR/patches/kernel/0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch" ] || \
|
||||
! grep -qF '0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch' "$BASE_DIR/scripts/build-kernel-audio.sh" || \
|
||||
! grep -qxF 'CONFIG_QCOM_RPM_MASTER_STATS=y' "$BASE_DIR/patches/kernel/config-bananarchy-msm8909.armv7" || \
|
||||
! grep -qxF 'CONFIG_QCOM_RPM_MASTER_STATS=y' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/kernel-config" || \
|
||||
! grep -q ' qcom_mpm_enter_sleep$' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/System.map" || \
|
||||
! grep -q ' spm_get_l2_device$' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/System.map" || \
|
||||
! grep -q ' qcom_msm8909_gdsc_is_active$' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/System.map" || \
|
||||
! grep -q ' qcom_iommu_resume$' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/System.map"; then
|
||||
fail "deep-standby kernel patch 0010, RPM master stats config, or vMPM/L2-SAW/IOMMU symbols are missing"
|
||||
fi
|
||||
for dts in \
|
||||
"$BASE_DIR/devices/nokia-argon/qcom-msm8905-nokia-argon.dts" \
|
||||
"$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts" \
|
||||
"$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts" \
|
||||
"$BASE_DIR/devices/nokia-tough/qcom-msm8905-nokia-coconut.dts" \
|
||||
"$BASE_DIR/devices/nokia-sparkler/qcom-msm8909-nokia-sparkler.dts" \
|
||||
"$BASE_DIR/devices/nokia-sparkler/qcom-msm8909-nokia-leo.dts"; do
|
||||
if ! grep -qF 'compatible = "qcom,mpm";' "$dts" || \
|
||||
! grep -qF 'qcom,msm8909-saw2-v3.0-scu' "$dts" || \
|
||||
! grep -qF 'compatible = "qcom,msm8916-rpm-stats";' "$dts" || \
|
||||
! grep -qF 'compatible = "qcom,rpm-master-stats";' "$dts" || \
|
||||
grep -qF 'stdout-path = "serial0";' "$dts"; then
|
||||
fail "${dts#"$BASE_DIR/"} is missing vMPM/L2-SAW/RPM-stats nodes or still exposes serial0 console"
|
||||
fi
|
||||
done
|
||||
if ! grep -qF -- '--dpm-open-port=' "$BASE_DIR/overlay/rootfs/etc/init.d/msm8909-modem-wwan-port" || \
|
||||
grep -qF '_need_dpm' "$BASE_DIR/overlay/rootfs/etc/init.d/msm8909-modem-wwan-port" || \
|
||||
grep -qF 'bananarchy-dpm.sh close' "$BASE_DIR/overlay/rootfs/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh" || \
|
||||
|
||||
Executable
+143
@@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host selftest for the compiled C DSDS and session daemons."""
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
SRC_DIR = os.path.join(BASE_DIR, "src", "bananarchy-daemons")
|
||||
|
||||
|
||||
def encode_gsm7_with_fill(text, udh=b""):
|
||||
septets = []
|
||||
ext_map = {
|
||||
"\f": 0x0A, "^": 0x14, "{": 0x28, "}": 0x29, "\\": 0x2F,
|
||||
"[": 0x3C, "~": 0x3D, "]": 0x3E, "|": 0x40, "\u20ac": 0x65,
|
||||
}
|
||||
basic = (
|
||||
"@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n\u00d8\u00f8\r\u00c5\u00e5"
|
||||
"\u0394_\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\x1b\u00c6\u00e6\u00df\u00c9"
|
||||
" !\"#\u00a4%&'()*+,-./0123456789:;<=>?"
|
||||
"\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c4\u00d6\u00d1\u00dc\u00a7"
|
||||
"\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1\u00fc\u00e0"
|
||||
)
|
||||
for ch in text:
|
||||
if ch in ext_map:
|
||||
septets.append(0x1B)
|
||||
septets.append(ext_map[ch])
|
||||
else:
|
||||
septets.append(basic.index(ch))
|
||||
fill_bits = (7 - ((len(udh) * 8) % 7)) % 7 if udh else 0
|
||||
start_septet = ((len(udh) * 8) + fill_bits) // 7
|
||||
udl = start_septet + len(septets)
|
||||
packed_len = (udl * 7 + 7) // 8
|
||||
buf = bytearray(max(len(udh), packed_len))
|
||||
buf[:len(udh)] = udh
|
||||
for idx, val in enumerate(septets):
|
||||
sidx = start_septet + idx
|
||||
bit_off = sidx * 7
|
||||
bidx = bit_off // 8
|
||||
sh = bit_off % 8
|
||||
buf[bidx] |= (val << sh) & 0xFF
|
||||
if sh > 1:
|
||||
buf[bidx + 1] |= (val >> (8 - sh)) & 0xFF
|
||||
return udl, bytes(buf)
|
||||
|
||||
|
||||
def build_deliver_pdu(oa_digits, oa_ton_npi, oa_bytes, dcs, udl, ud,
|
||||
udh=False, smsc=b"\x00"):
|
||||
fo = 0x40 if udh else 0x00
|
||||
scts = bytes([0x62, 0x11, 0x31, 0x61, 0x03, 0x00, 0x08])
|
||||
tpdu = bytearray([fo, oa_digits, oa_ton_npi]) + oa_bytes + bytes([0x00, dcs]) + scts + bytes([udl]) + ud
|
||||
return (smsc + bytes(tpdu)).hex()
|
||||
|
||||
|
||||
class DsdsDaemonTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.tmpdir = tempfile.TemporaryDirectory()
|
||||
cls.bin = os.path.join(cls.tmpdir.name, "dsds_selftest")
|
||||
subprocess.run(
|
||||
[
|
||||
"gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
|
||||
"-DBANANARCHY_DSDS_SELFTEST",
|
||||
"-I", SRC_DIR,
|
||||
"-o", cls.bin,
|
||||
os.path.join(SRC_DIR, "bananarchy-dsds.c"),
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.tmpdir.cleanup()
|
||||
|
||||
def test_all_c_daemons_host_compile_cleanly(self):
|
||||
for name in [
|
||||
"bananarchy-dsds.c",
|
||||
"bananarchy-modemmonitor.c",
|
||||
"bananarchy-soundmonitor.c",
|
||||
"bananarchy-notifmonitor.c",
|
||||
"bananarchy-run-aligned.c",
|
||||
"bananarchy-session-loop.c",
|
||||
]:
|
||||
out = os.path.join(self.tmpdir.name, name + ".bin")
|
||||
subprocess.run(
|
||||
[
|
||||
"gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
|
||||
"-I", SRC_DIR, "-o", out, os.path.join(SRC_DIR, name),
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
def test_gsm7_and_ext_and_international_oa(self):
|
||||
udl, ud = encode_gsm7_with_fill("Price: 10\u20ac [ok]")
|
||||
# +358401234567 -> 12 digits, TON=1 NPI=1 (0x91)
|
||||
oa = bytes.fromhex("534810325476")
|
||||
pdu = build_deliver_pdu(12, 0x91, oa, 0x00, udl, ud)
|
||||
res = subprocess.run([self.bin, pdu], capture_output=True, text=True, check=True)
|
||||
self.assertIn("DELIVER\t2\t+358401234567\tPrice: 10\u20ac [ok]\n", res.stdout)
|
||||
|
||||
def test_alphanumeric_sender_and_ucs2_surrogate(self):
|
||||
# Alphanumeric "Nokia" (5 chars -> 35 bits -> 9 hex digits rounded up = 9 nibbles)
|
||||
_, oa = encode_gsm7_with_fill("Nokia")
|
||||
oa_digits = (len("Nokia") * 7 + 3) // 4
|
||||
payload = "Hi \U0001F34C".encode("utf-16-be")
|
||||
pdu = "tpdu:" + build_deliver_pdu(
|
||||
oa_digits, 0xD0, oa, 0x08, len(payload), payload, smsc=b""
|
||||
)
|
||||
res = subprocess.run([self.bin, pdu], capture_output=True, text=True, check=True)
|
||||
self.assertIn("DELIVER\t2\tNokia\tHi \U0001F34C\n", res.stdout)
|
||||
|
||||
def test_multipart_csms_out_of_order_and_dedup(self):
|
||||
oa = bytes.fromhex("534810325476")
|
||||
udh1 = bytes([0x05, 0x00, 0x03, 0x2A, 0x02, 0x01])
|
||||
udh2 = bytes([0x06, 0x08, 0x04, 0x00, 0x2A, 0x02, 0x02])
|
||||
# Use matching 8-bit CSMS ref 0x2A across both parts
|
||||
udh2_8 = bytes([0x05, 0x00, 0x03, 0x2A, 0x02, 0x02])
|
||||
u1, d1 = encode_gsm7_with_fill("Hello ", udh1)
|
||||
u2, d2 = encode_gsm7_with_fill("World!", udh2_8)
|
||||
pdu1 = build_deliver_pdu(12, 0x91, oa, 0x00, u1, d1, udh=True)
|
||||
pdu2 = build_deliver_pdu(12, 0x91, oa, 0x00, u2, d2, udh=True)
|
||||
res = subprocess.run(
|
||||
[self.bin, pdu2, pdu1, pdu1],
|
||||
capture_output=True, text=True, check=True,
|
||||
)
|
||||
delivers = [ln for ln in res.stdout.splitlines() if ln.startswith("DELIVER\t")]
|
||||
self.assertEqual(delivers, ["DELIVER\t2\t+358401234567\tHello World!"])
|
||||
|
||||
# Also verify 16-bit CSMS UDH IEI 0x08 in UCS-2
|
||||
udh16_1 = bytes([0x06, 0x08, 0x04, 0x12, 0x34, 0x02, 0x01])
|
||||
udh16_2 = bytes([0x06, 0x08, 0x04, 0x12, 0x34, 0x02, 0x02])
|
||||
p1 = udh16_1 + "One ".encode("utf-16-be")
|
||||
p2 = udh16_2 + "Two".encode("utf-16-be")
|
||||
q1 = build_deliver_pdu(12, 0x91, oa, 0x08, len(p1), p1, udh=True)
|
||||
q2 = build_deliver_pdu(12, 0x91, oa, 0x08, len(p2), p2, udh=True)
|
||||
_ = udh2
|
||||
res2 = subprocess.run([self.bin, q1, q2], capture_output=True, text=True, check=True)
|
||||
self.assertIn("DELIVER\t2\t+358401234567\tOne Two\n", res2.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user