diff --git a/docs/rgb10max2.md b/docs/rgb10max2.md new file mode 100644 index 0000000..fc054cd --- /dev/null +++ b/docs/rgb10max2.md @@ -0,0 +1,186 @@ +# the powkiddy rgb10 max 2 + +this is what it took to run andr36oid on the powkiddy rgb10 max 2, a 2021 rk3326 +handheld that shares the odroid go super's board design but, unlike the og super, +ships with an internal wifi module. the port itself is small: a device tree, a +boot.ini line, a boot service. getting wifi to work was the interesting part and +needed something no device tree can express, explained further down. + +status: every feature listed here was verified on hardware. wifi works with no +cables attached, on every cold boot. + +## the console + +- rockchip rk3326, 1 gb ram, no emmc (sd card only) +- 5 inch 854 x 480 ips, mipi dsi panel `elida,kd50t048a`, portrait panel used + landscape, 2 lanes +- buttons on the odroid go super map (amux adc), plus start/select on gpio2 and + l1/r1 on gpio3 +- wifi + bluetooth: one realtek rtl8723bu combo module (`0bda:b720`), + usb, sitting behind a genesys `05e3:0608` hub on the dwc2 usb bus. 2.4 ghz + only: 802.11n, no 5 ghz, no wpa3 (see known limits) +- two usb-c ports: one marked power (charge only, no data lines), one marked + otg (data, wired to the same dwc2 bus as the internal hub) + +## the profile + +the flasher reads console profiles from `BOOT/andr36oid-profiles.txt`; nothing +in this repo needs a new console. add one line and the matching folder: + +```text +Devices/RGB10MAX2|RGB10 Max 2|Powkiddy RGB10 Max 2| +``` + +`BOOT/Devices/RGB10MAX2/` holds the same file set every r36s-derived profile +uses, built for this console: + +- `rk3326-r36s-android.dtb` - the device tree described below +- `logo.bmp` - the boot logo +- `rg351mp-uboot.dtb`, `rg351p-uboot.dtb`, `rg351v-uboot.dtb` and the matching + `*-kernel.dtb` files - the u-boot and kernel copies the bootloader picks from + by board revision; the og super family uses the same names + +the console identifies as `hwrev=v10-go3`, so the bootloader boots the +`rk3326-odroidgo3` path. the top-level files on BOOT are replaced with the +profile's files as usual. + +## boot.ini + +two lines matter on this console: + +```text +setenv android "... androidboot.sf_orientation=ORIENTATION_270" +setenv bootrootfs "... usbcore.autosuspend=-1" +``` + +the panel is portrait and mounted landscape, so surfaceflinger needs the +orientation hint. `usbcore.autosuspend=-1` keeps the internal hub's usb port +awake; with autosuspend left on, the hub can idle off and wifi drops for a +moment during boot. + +## the device tree + +`docs/rgb10max2/rk3326-rgb10max2-android.dts` is the full source. it includes +`rk3326-r36s-android.dtsi` from the kernel tree and changes only these things: + +- panel to `elida,kd50t048a` with the init sequence and timing from the stock + go3 device tree, plus the 251 level backlight +- `invert-absrx` on the joypad and the amux channels made explicit +- leds: no vibrator, charge led on gpio0 pb5 +- battery: design capacity 4000, charger values from the go3 tree +- the charger's dc detect (gpio0 pb3) stays exactly as in the base tree. it is + what lets the charger enable the charge path, and stock leaves it alone +- the dwc2 otg controller runs `dr_mode = "host"` with the phy port **disabled** + (see the wifi section for why). the otg connector still works as a plain + usb-c host port for devices; android's usb *device* modes need the phy port + enabled and are outside this configuration + +build it exactly like the other andr36oid device trees: + +```sh +cpp -nostdinc -I include -I arch/arm64/boot/dts/rockchip -undef -D__DTS__ \ + -x assembler-with-cpp rk3326-rgb10max2-android.dts -o out.dts +dtc -@ -I dts -O dtb -o rk3326-r36s-android.dtb out.dts +``` + +the `-undef` matters: the kernel's `linux` builtin macro mangles `linux,code`. + +## wifi power: the rk817 latch, and why the phy port stays disabled + +the internal hub and the wifi dongle sit on the dwc2 bus, and their 5 v is the +otg port's vbus net, fed by the rk817 otg rail. on this board the rail behaves +as a pmic-side latch: kernel writes to the otg enable register (charger, +regulator, phy vbus supply) never reach it - the kernel register cache reads +back "on" (`reg_b4=47 otg5v=1`) while the hardware register reads `0x07` and no +power appears. a raw i2c write of `0xB4 = 0x47` from linux flips it, the hub +powers from the battery and the wifi module comes up. the latch survives warm +reboots but resets on a cold power-off, so the boot service writes it on every +cold boot. + +the stock firmware ships the same topology: dwc2 runs phyless with the otg **phy +port disabled**. that one detail is load-bearing twice: + +- dwc2: keeping `phys = <&u2phy_otg>` while the port is disabled makes the phy + lookup defer until the u2phy driver is up (utmi clock on) and then return + -ENODEV, so dwc2 probes phyless with the clock running. removing the `phys` + property outright instead makes dwc2 probe before that clock exists and its + core soft reset hangs with "GRSTCTL_CSFTRST timeout" +- charger: if the phy port is enabled it fires EXTCON_USB_VBUS_EN, the charger + sets `otg_in` and then **disables its own plug/plug-out interrupts**. a + charger plugged in afterwards is never detected and charging stops until + reboot. with the phy port disabled the charger never hears about otg, keeps + its plug detection, and charges normally + +result, verified on hardware: charging and wifi run together. with a charger in +the power port its 5 v feeds the shared net, so the hub enumerates before the +latch is even needed; on battery the boot service arms the latch. a 30 s +watchdog re-arms the latch whenever the hub drops. + +`docs/rgb10max2/service/` does this at boot, in this order: + +1. preload `rtl8xxxu.ko` so the dongle binds the moment it enumerates +2. pin runtime pm on the usb controllers +3. if the hub is not enumerated: write `0xB4 = 0x47` with `rk817tool`. if that + does not take, unbind the charger, write again, rebind, and write once more if + rebinding killed it +4. after boot: disable wifi power save and set the ma regdomain with `wifitool`, + then open adb over tcp +5. keep a small root command loop alive (the flasher's servicing hook, optional + for a release build) + +`docs/rgb10max2/tools/rk817tool.c` is a static aarch64 binary that reads and +writes rk817 registers over `/dev/i2c-0` (address 0x20). +`docs/rgb10max2/tools/wifitool.c` is a static aarch64 nl80211 helper (no libnl) +for power save and the regulatory domain, because the image ships no `iw`. + +## the boot black screen, and the service fix + +the kernel draws the boot logo, but when surfaceflinger/hwc take over the drm +master the crtc is never enabled for the android framebuffer: the panel stays +black while android keeps believing the screen is on (the display manager logs +no state change for the whole boot). a screencap shows the launcher fully +composed, so only the panel scanout is dead. the first vop modeset happens only +when a sleep/wake cycle forces displaypowercontroller to disable and re-enable +the display. + +the service therefore runs that cycle automatically right after +`sys.boot_completed`: two `input keyevent KEYCODE_POWER` events 1.5 s apart. +verified on hardware: the wake fires (`WAKE_REASON_POWER_BUTTON`), the display +manager logs "built-in screen, on", and the launcher appears with no button +press. `fb0/blank` does not drive dpms on this kernel and the drm sysfs `dpms` +node is read-only, so the key-event cycle is the only working trigger from +userspace. + +also set `debug.sf.nobootanimation=1` in `/vendor/build.prop` (the image ships +`0`; `/system` is erofs and not writable): the animation renders into the dead +panel anyway, and disabling it shortens boot by roughly 10 s +(enable_screen 52->48 s, boot-animation-done 63->51 s on measured boots). + +## what works + +- display, orientation, touch-less ui, all buttons and both sticks +- **screen comes up by itself after boot** (auto sleep/wake cycle; no button) +- wifi from battery on every cold boot (latch written by the boot service), + wpa2-psk networks including mixed wpa/wpa2 tkip ones +- bluetooth (the same combo module exposes hci0) +- **charging and wifi at the same time** - stock parity (verified live: + battery charging at +869 mA with wlan0 connected) +- the otg port as a plain usb-c host port; the power port charges +- battery percentage + +## known limits + +- 2.4 ghz only. no 5 ghz networks, by hardware +- wpa3-only and wpa2/wpa3 transition networks that require pmf do not connect: + the `rtl8xxxu` driver has no sae or management frame protection support. a + wpa2-only access point (or forcing a wpa2 psk config) works +- weak links: the module's antenna is small. the ap can drop the client with + "missing acks" below roughly -75 dbm; keeping wifi power save off helps + +## evidence + +the port was validated against the stock firmware's own kernel log from the same +unit (retrooz, kernel 4.4.189), which shows the same hub and dongle enumerating +on dwc2 in ~10 s, and against live adb sessions on android 11 where unplugging +the otg cable dropped the hub in under 3 s and plugging it back restored it. the +pmic behaviour above was measured with raw i2c reads on the running console. diff --git a/docs/rgb10max2/build-rgb10max2-image.sh b/docs/rgb10max2/build-rgb10max2-image.sh new file mode 100755 index 0000000..b506ce7 --- /dev/null +++ b/docs/rgb10max2/build-rgb10max2-image.sh @@ -0,0 +1,171 @@ +#!/bin/bash +# build-rgb10max2-image.sh — full reproducible builder for the Powkiddy +# RGB10 Max 2 andr36oid image. Takes ANY andr36oid base image (official +# release or a previous master) and applies EVERYTHING the port needs: +# +# BOOT (p1): RGB10MAX2 device profile (DTB, logo, u-boot/kernel dtbs), +# profiles.txt line, boot.ini orientation + autosuspend lines +# vendor (p8): diag.sh (current service), zz-diag.rc, rk817tool, wifitool, +# debug.sf.nobootanimation=1 in /vendor/build.prop +# +# Nothing else is touched: /data (Wi-Fi, apps, tailscale auth) is per-install +# and migrates via migrate-console-state.sh after first boot. +# +# Usage: +# build-rgb10max2-image.sh [-o ] +# build-rgb10max2-image.sh --download [-o ] # fetch official release +# +# Idempotent: running it on an already-patched image just refreshes files. +set -euo pipefail + +HERE="$(cd "$(dirname "$0")" && pwd)" +PROFILE_DIR="$(cd "$HERE/../device-work/boot-profile/RGB10MAX2" && pwd)" +SERVICE_DIR="$HERE/../device-work/diag-v11" +BIN_DIR="$HERE/../device-work/bin" +TOP_FILES="rk3326-r36s-android.dtb logo.bmp rg351mp-uboot.dtb rg351p-uboot.dtb rg351v-uboot.dtb rg351mp-kernel.dtb rg351p-kernel.dtb rg351v-kernel.dtb" +WORK="$(mktemp -d)" +LO="" + +cleanup() { + umount "$WORK/boot" 2>/dev/null + umount "$WORK/vendor" 2>/dev/null + [ -n "${VLO:-}" ] && losetup -d "$VLO" 2>/dev/null + rm -rf "$WORK" +} +trap cleanup EXIT + +die() { echo "build: $*" >&2; exit 1; } +need() { command -v "$1" >/dev/null || die "'$1' is required"; } + +for f in $TOP_FILES; do [ -f "$PROFILE_DIR/$f" ] || die "profile file missing: $PROFILE_DIR/$f" +done +[ -f "$SERVICE_DIR/diag.sh" ] || die "diag.sh missing" +[ -f "$BIN_DIR/rk817tool" ] && [ -f "$BIN_DIR/wifitool" ] && [ -f "$BIN_DIR/zz-diag.rc" ] || \ + die "compiled tools missing in device-work/bin/ (rk817tool, wifitool, zz-diag.rc)" + +case "${1:-}" in + --download) + need curl + URL=$(curl -s https://api.github.com/repos/andr36oid/releases/releases/latest \ + | grep -oE '"browser_download_url": *"[^"]*rk3326\.img\.xz"' | head -1 | cut -d'"' -f4) + [ -n "$URL" ] || die "no rk3326 release image found" + echo "Downloading $URL" + curl -L "$URL" -o "$WORK/base.img.xz" + BASE="$WORK/base.img.xz" + ;; + *.img|*.img.xz) BASE="${1:?usage: $0 [--download] [-o out.img]}"; [ -f "$BASE" ] || die "no such image: $BASE" ;; + *) die "usage: $0 | --download [-o out.img]" ;; +esac +OUT="${3:-}"; [ "${2:-}" = "-o" ] && OUT="${3:-}" +OUT="${OUT:-${BASE%.*}-rgb10max2-master.img}" +OUT="${OUT%.img}.img" + +# --- prepare a writable copy ------------------------------------------------- +need xz; need losetup; need mount; need debugfs; need mkfs.vfat; need mdir; need mcopy +if [ "${BASE##*.}" = "xz" ]; then + echo "Decompressing base image…" + xz -dk -c "$BASE" > "$WORK/base.img" +else + cp --sparse=always "$BASE" "$WORK/base.img" +fi +IMG="$WORK/base.img" + +# --- mount BOOT (p1) and vendor (p8) via offsets (no partition scan needed) --- +fdisk -l "$IMG" > "$WORK/fdisk.txt" || die "fdisk failed on the image" +START1=$(awk '/^'[[:space:]]*'?img1|img1/' "$WORK/fdisk.txt" | awk '{print $2}') +# robust parse: find lines with p1..p8 (sfdisk-style numbering by position) +get_start() { awk -v n="$1" '$1 ~ ("img" n "$") {print $2}' "$WORK/fdisk.txt" | head -1; } +get_size() { awk -v n="$1" '$1 ~ ("img" n "$") {print $4}' "$WORK/fdisk.txt" | head -1; } +S1=$(get_start 1); SZ8=$(get_size 8) +[ -n "$S1" ] || { grep -n "img1\b" "$WORK/fdisk.txt" | head -3; die "could not parse p1 start from fdisk output"; } +OFF1=$((S1 * 512)) +mkdir -p "$WORK/boot" "$WORK/vendor" +mount -t vfat -o loop,offset=$OFF1 "$IMG" "$WORK/boot" || die "p1 vfat mount failed" +[ -f "$WORK/boot/boot.ini" ] || die "p1 has no boot.ini — not an andr36oid image?" +if [ -n "$SZ8" ]; then + OFF8=$(get_start 8); OFF8=$((OFF8 * 512)); SZ8B=$((SZ8 * 512)) + LO8=$(losetup -f --show -o $OFF8 --sizelimit $SZ8B "$IMG") + e2fsck -fp "$LO8" >/dev/null 2>&1 || true # fresh images carry a dirty ext4 journal + mount -t ext4 "$LO8" "$WORK/vendor" 2>/dev/null || { losetup -d "$LO8"; die "p8 ext4 mount failed — partition layout differs"; } + VLO="$LO8" +else + die "could not parse p8 from fdisk output" +fi + +# --- BOOT: rebuild via mtools (kernel vfat writes proved flaky on sparse backing) --- +mkdir -p "$WORK/boot-orig" +MIDX="$IMG@@$OFF1" +# 1. pull the entire official BOOT content out (mtools = no kernel involvement) +mcopy -s -i "$MIDX" ::/ "$WORK/boot-orig"/ || die "mtools read of official BOOT failed" +[ -f "$WORK/boot-orig/boot.ini" ] || die "official BOOT extraction incomplete" + +# 2. apply our changes on the local copy +mkdir -p "$WORK/boot-orig/Backup-stock" +for f in $TOP_FILES; do + [ -f "$WORK/boot-orig/$f" ] && cp "$WORK/boot-orig/$f" "$WORK/boot-orig/Backup-stock/" + cp "$PROFILE_DIR/$f" "$WORK/boot-orig/$f" +done +mkdir -p "$WORK/boot-orig/Devices/RGB10MAX2" +rm -rf "$WORK/boot-orig/Devices/RGB10MAX2"; mkdir -p "$WORK/boot-orig/Devices/RGB10MAX2" +for f in $TOP_FILES; do cp "$PROFILE_DIR/$f" "$WORK/boot-orig/Devices/RGB10MAX2/$f"; done +cp "$WORK/boot-orig/boot.ini" "$WORK/boot-orig/Devices/RGB10MAX2/boot.ini" +grep -q "^Devices/RGB10MAX2|" "$WORK/boot-orig/andr36oid-profiles.txt" 2>/dev/null || \ + printf 'Devices/RGB10MAX2|RGB10 Max 2|Powkiddy RGB10 Max 2|\n' >> "$WORK/boot-orig/andr36oid-profiles.txt" +grep -q "sf_orientation=ORIENTATION_270" "$WORK/boot-orig/boot.ini" || \ + sed -i 's/setenv bootargs /setenv bootargs androidboot.sf_orientation=ORIENTATION_270 usbcore.autosuspend=-1 /' "$WORK/boot-orig/boot.ini" +grep -q "ORIENTATION_270" "$WORK/boot-orig/boot.ini" || die "boot.ini orientation edit failed" + +# 3. fresh vfat, everything copied back in with mtools (proven sequence) +rm -f "$WORK/boot-vfat.img" +mkfs.vfat -n BOOT -C "$WORK/boot-vfat.img" 262144 # 256 MiB in 1KB blocks +for D in Devices Experimental Image Panels Backup-stock; do mmd -i "$WORK/boot-vfat.img" "::$D"; done +mcopy -s -i "$WORK/boot-vfat.img" "$WORK/boot-orig/Devices/"* ::/Devices/ +for D in Experimental Panels Backup-stock; do mcopy -s -i "$WORK/boot-vfat.img" "$WORK/boot-orig/$D/"* "::/$D/"; done +if ls "$WORK/boot-orig/Image/"* >/dev/null 2>&1; then mcopy -s -i "$WORK/boot-vfat.img" "$WORK/boot-orig/Image/"* ::/Image/; fi +mcopy -i "$WORK/boot-vfat.img" "$WORK/boot-orig/"*.txt ::/ +for f in $TOP_FILES boot.ini boot.ini-android logo.bmp logo_kernel.bmp make-report.txt; do + [ -f "$WORK/boot-orig/$f" ] && mcopy -i "$WORK/boot-vfat.img" "$WORK/boot-orig/$f" ::/ +done +mdir -i "$WORK/boot-vfat.img" ::/ >/dev/null || die "fresh vfat verification failed" + +# 4. splice the fresh vfat into the image at p1 +dd if="$WORK/boot-vfat.img" of="$IMG" bs=512 seek=$S1 conv=notrunc status=none +grep -q "ORIENTATION_270" "$IMG" || die "boot.ini orientation did not reach the image" +grep -q "usbcore.autosuspend=-1" "$IMG" || die "boot.ini autosuspend did not reach the image" +grep -q "RGB10MAX2" "$IMG" || die "profile files did not reach the image" +mdir -i "$IMG@@$OFF1" ::/boot.ini >/dev/null 2>&1 || die "mtools post-verify failed" +echo "BOOT: rebuilt via mtools, verified." + +# --- vendor: service + tools + build.prop ------------------------------------ +install -m 750 "$SERVICE_DIR/diag.sh" "$WORK/vendor/etc/diag.sh" +install -m 644 "$BIN_DIR/zz-diag.rc" "$WORK/vendor/etc/init/zz-diag.rc" +install -m 755 "$BIN_DIR/rk817tool" "$WORK/vendor/etc/rk817tool" +install -m 755 "$BIN_DIR/wifitool" "$WORK/vendor/etc/wifitool" +grep -q "nobootanimation" "$WORK/vendor/build.prop" && \ + sed -i 's/^debug.sf.nobootanimation=.*/debug.sf.nobootanimation=1/' "$WORK/vendor/build.prop" || \ + echo "debug.sf.nobootanimation=1" >> "$WORK/vendor/build.prop" +grep -q "debug.sf.nobootanimation=1" "$WORK/vendor/build.prop" || die "build.prop knob failed" +echo "vendor: diag.sh + tools + build.prop installed." + +sync -f "$WORK/boot" 2>/dev/null || sync +umount "$WORK/boot" || die "BOOT unmount failed (busy) — aborting instead of losing writes" +sync -f "$WORK/vendor" 2>/dev/null || sync +umount "$WORK/vendor" || die "vendor unmount failed (busy) — aborting instead of losing writes" +losetup -d "$VLO" 2>/dev/null || true + +# --- verify the writes are IN THE IMAGE FILE (raw grep, no mount games) ------ +grep -q "ORIENTATION_270" "$IMG" || die "boot.ini orientation did not reach the image" +grep -q "usbcore.autosuspend=-1" "$IMG" || die "boot.ini autosuspend did not reach the image" +grep -q "RGB10MAX2" "$IMG" || die "profile files did not reach the image" +grep -q "nobootanimation=1" "$IMG" || die "vendor build.prop did not reach the image" +echo "image-level verification passed." + +# --- finalize ----------------------------------------------------------------- +mv "$IMG" "$OUT" +sync +echo +echo "DONE: $OUT (apparent $(du -h --apparent-size "$OUT" | cut -f1))" +echo "md5: $(md5sum "$OUT" | cut -d' ' -f1)" +echo +echo "Flash to the new card, boot once, then migrate state:" +echo " migrate-console-state.sh --adb (tailscale auth, no re-login)" diff --git a/docs/rgb10max2/migrate-console-state.sh b/docs/rgb10max2/migrate-console-state.sh new file mode 100755 index 0000000..e57ecb7 --- /dev/null +++ b/docs/rgb10max2/migrate-console-state.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# migrate-console-state.sh — move per-install state from the test console to a +# freshly built+flashed card. Run AFTER the new card has booted once with +# adb-on-TCP reachable (the boot service opens adb automatically). +# +# What it migrates: +# - tailscale authentication (ts/state/tailscaled.state) — no re-login +# - (optional) full ts state incl. caches +# +# Usage: +# migrate-console-state.sh --adb # from dist/essentials.tgz +# migrate-console-state.sh --adb --full # full ts state (bigger) +# migrate-console-state.sh --file --adb +set -euo pipefail +HERE="$(cd "$(dirname "$0")" && pwd)" +DIST="$HERE/../dist" + +ADB_IP=""; KIT="" +while [ $# -gt 0 ]; do + case "$1" in + --adb) ADB_IP="$2"; shift 2 ;; + --full) KIT="$DIST/state-kit.tgz"; shift ;; + --file) KIT="$2"; shift 2 ;; + *) echo "unknown arg $1"; exit 1 ;; + esac +done +[ -n "$ADB_IP" ] || { echo "usage: $0 --adb [--full] [--file kit.tgz]"; exit 1; } +[ -n "$KIT" ] || KIT="$DIST/essentials.tgz" +[ -f "$KIT" ] || { echo "kit missing: $KIT (run the console-side backup first)"; exit 1; } + +adb connect "$ADB_IP:5555" >/dev/null +ST=$(adb devices | grep "$ADB_IP" | awk '{print $2}') +[ "$ST" = "device" ] || { echo "device not online ($ST)"; exit 1; } + +echo "pushing $KIT" +adb push "$KIT" /data/local/tmp/migrate.tgz >/dev/null +adb shell 'cat > /data/local/tmp/cmd.in << "EOF" +{ +mkdir -p /data/local/tmp/ts/state +tar xzf /data/local/tmp/migrate.tgz -C /data/local/tmp +rm -f /data/local/tmp/migrate.tgz +pkill -f tailscaled 2>/dev/null; sleep 1 +nohup /data/local/tmp/ts/tailscaled --statedir=/data/local/tmp/ts/state --socket=/data/local/tmp/ts/tailscaled.sock --tun=tun0 > /data/local/tmp/ts/tsd.log 2>&1 & +sleep 4 +/data/local/tmp/ts/tailscale --socket=/data/local/tmp/ts/tailscaled.sock ip -4 +} > /data/local/tmp/cmd.out 2>&1 +chmod 666 /data/local/tmp/cmd.out +EOF +echo pushed' +sleep 10 +adb shell 'cat /data/local/tmp/cmd.out' +echo +echo "If a 100.x.y.z IP printed above, tailscale migrated — no re-login needed." diff --git a/docs/rgb10max2/rk3326-rgb10max2-android.dts b/docs/rgb10max2/rk3326-rgb10max2-android.dts new file mode 100644 index 0000000..125a62e --- /dev/null +++ b/docs/rgb10max2/rk3326-rgb10max2-android.dts @@ -0,0 +1,402 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Powkiddy RGB10 Max 2 for andr36oid. + * + * Board evidence (user's card, RetroOZ 0.60, /opt/.retrooz/device = + * rgb10max2native): RetroOZ boots hwrev=v10-go3 with + * rk3326-odroidgo3-linux.dtb ("Machine model: Hardkernel ODROID-GO3"), + * i.e. an ODROID-GO-Super-class board: + * - elida,kd50t048a 5" panel, MIPI DSI, 2 data lanes, 480x854 portrait + * used landscape (854x480), backlight pwm1 40000 ns, 251 levels + * - odroidgo3-joypad amux sticks, same mux pins as the R36S base + * (gpio3 PB3/PB0/PB5, saradc ch1), right stick via amux-channel-mapping + * - volume keys gpio2 PA0/PA1 (as in the base dtsi) + * - RK817 PMIC, 4000 mAh battery, charge LED gpio0 PB5, no vibrator, + * no gpio status LED beyond the base heartbeat + * - Wi-Fi: internal Realtek RTL8723BU on the internal USB bus + * (idVendor 0bda idProduct b720 behind a Genesys 05e3:0608 hub); + * &sdio stays off, nothing lives on SDIO. + * + * Everything else (CPU, power, USB, Android glue, ramoops, fixes) comes + * from rk3326-r36s-android.dtsi, same as R46H/R50S and the other boards. + */ + +/dts-v1/; +#include "rk3326-r36s-android.dtsi" + +/ { + model = "Powkiddy RGB10 Max 2"; + + backlight: backlight { + pwms = <&pwm1 0 40000 0>; + brightness-levels = < + 0 1 2 3 4 5 6 7 + 8 9 10 11 12 13 14 15 + 16 17 18 19 20 21 22 23 + 24 25 26 27 28 29 30 31 + 32 33 34 35 36 37 38 39 + 40 41 42 43 44 45 46 47 + 48 49 50 51 52 53 54 55 + 56 57 58 59 60 61 62 63 + 64 65 66 67 68 69 70 71 + 72 73 74 75 76 77 78 79 + 80 81 82 83 84 85 86 87 + 88 89 90 91 92 93 94 95 + 96 97 98 99 100 101 102 103 + 104 105 106 107 108 109 110 111 + 112 113 114 115 116 117 118 119 + 120 121 122 123 124 125 126 127 + 128 129 130 131 132 133 134 135 + 136 137 138 139 140 141 142 143 + 144 145 146 147 148 149 150 151 + 152 153 154 155 156 157 158 159 + 160 161 162 163 164 165 166 167 + 168 169 170 171 172 173 174 175 + 176 177 178 179 180 181 182 183 + 184 185 186 187 188 189 190 191 + 192 193 194 195 196 197 198 199 + 200 201 202 203 204 205 206 207 + 208 209 210 211 212 213 214 215 + 216 217 218 219 220 221 222 223 + 224 225 226 227 228 229 230 231 + 232 233 234 235 236 237 238 239 + 240 241 242 243 244 245 246 247 + 248 249 250>; + default-brightness-level = <125>; + }; +}; + +&leds { + /delete-node/ vibrator; + + /* Charge LED: no driver reads the old chg_led_gpio property */ + charge { + label = "charge"; + gpios = <&gpio0 RK_PB5 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "battery-charging"; + }; +}; + +&joypad { + /* RGB10 Max 2 sticks: go3 wiring, right stick X inverted as well */ + invert-absrx; + /* no Fn button on this console; Android offers a stand-in */ + andr36oid,missing-buttons = "fn"; + /* explicit amux channel assignments as in the go3 DTB */ + /* this board's mux wiring differs from the R36S on the right stick: + * mux ch0 = right stick X, ch1 = right stick Y (the R36S has them the + * other way around). The odroidgo3 driver reads the axis list in the + * order RY,RX,Y,X -> amux-channel-mapping sends ABS_RY to ch1, + * ABS_RX to ch0. ch1 raw reads +Y with reversed polarity relative to + * what games expect: invert-absrx yes, invert-absry no, verified + * verified on hardware. */ + amux-channel-mapping = <1 0 2 3>; + + /* + * Button map: the go3 (ODROID-GO Super) layout, ported verbatim from + * the RGB10 Max 2's own rk3326-odroidgo3-linux.dtb (RetroOZ boots it + * on this very unit). The R36S dtsi base differs in key codes (arrows + * vs BTN_DPAD_*, A/B swapped) and misses six aux/shoulder buttons on + * gpio2 PA4-PA7 / gpio3, so the whole sw set is replaced. + */ + /delete-node/ sw1; + /delete-node/ sw2; + /delete-node/ sw3; + /delete-node/ sw4; + /delete-node/ sw5; + /delete-node/ sw6; + /delete-node/ sw7; + /delete-node/ sw8; + /delete-node/ sw11; + /delete-node/ sw12; + /delete-node/ sw13; + /delete-node/ sw15; + /delete-node/ sw16; + /delete-node/ sw19; + /delete-node/ sw20; + /delete-node/ sw21; + /delete-node/ sw22; + + sw1 { + gpios = <&gpio1 RK_PB4 GPIO_ACTIVE_LOW>; + label = "GPIO DPAD-UP"; + linux,code = <103>; /* KEY_UP - the .kl maps arrows to DPAD */ + }; + sw2 { + gpios = <&gpio1 RK_PB5 GPIO_ACTIVE_LOW>; + label = "GPIO DPAD-DOWN"; + linux,code = <108>; /* KEY_DOWN */ + }; + sw3 { + gpios = <&gpio1 RK_PB6 GPIO_ACTIVE_LOW>; + label = "GPIO DPAD-LEFT"; + linux,code = <105>; /* KEY_LEFT */ + }; + sw4 { + gpios = <&gpio1 RK_PB7 GPIO_ACTIVE_LOW>; + label = "GPIO DPAD-RIGHT"; + linux,code = <106>; /* KEY_RIGHT */ + }; + sw5 { + gpios = <&gpio1 RK_PA2 GPIO_ACTIVE_LOW>; + label = "GPIO KEY BTN-A"; + linux,code = <304>; /* BTN_SOUTH -> BUTTON_A */ + }; + sw6 { + gpios = <&gpio1 RK_PA5 GPIO_ACTIVE_LOW>; + label = "GPIO BTN-B"; + linux,code = <305>; /* BTN_EAST -> BUTTON_B */ + }; + sw7 { + gpios = <&gpio1 RK_PA6 GPIO_ACTIVE_LOW>; + label = "GPIO BTN-Y"; + linux,code = <308>; /* BTN_WEST -> BUTTON_Y */ + }; + sw8 { + gpios = <&gpio1 RK_PA7 GPIO_ACTIVE_LOW>; + label = "GPIO BTN-X"; + linux,code = <307>; /* BTN_NORTH -> BUTTON_X */ + }; + sw9 { + gpios = <&gpio2 RK_PA2 GPIO_ACTIVE_LOW>; + label = "GPIO START"; + linux,code = <315>; /* BUTTON_START */ + }; + sw10 { + gpios = <&gpio2 RK_PA3 GPIO_ACTIVE_LOW>; + label = "GPIO SELECT"; + linux,code = <314>; /* BUTTON_SELECT */ + }; + sw11 { + gpios = <&gpio2 RK_PA4 GPIO_ACTIVE_LOW>; + label = "GPIO L3"; + linux,code = <0x13d>; /* BTN_THUMBL (left stick push) */ + }; + sw12 { + gpios = <&gpio2 RK_PA5 GPIO_ACTIVE_LOW>; + label = "GPIO R3"; + linux,code = <0x13e>; /* BTN_THUMBR (right stick push) */ + }; + sw13 { + gpios = <&gpio2 RK_PA6 GPIO_ACTIVE_LOW>; + label = "GPIO TOP-LEFT2"; + linux,code = <0x138>; /* BTN_TL2 (L2) */ + }; + sw14 { + gpios = <&gpio2 RK_PA7 GPIO_ACTIVE_LOW>; + label = "GPIO TOP-RIGHT2"; + linux,code = <0x139>; /* BTN_TR2 (R2) */ + }; + sw15 { + gpios = <&gpio3 RK_PB1 GPIO_ACTIVE_LOW>; + label = "GPIO F1"; + linux,code = <0x2c0>; /* BTN_TRIGGER_HAPPY1 */ + }; + sw16 { + gpios = <&gpio3 RK_PB2 GPIO_ACTIVE_LOW>; + label = "GPIO TOP-LEFT"; + linux,code = <0x136>; /* BTN_TL (L1) */ + }; + sw17 { + gpios = <&gpio3 RK_PB4 GPIO_ACTIVE_LOW>; + label = "GPIO F2"; + linux,code = <0x2c1>; /* BTN_TRIGGER_HAPPY2 */ + }; + sw18 { + gpios = <&gpio3 RK_PB7 GPIO_ACTIVE_LOW>; + label = "GPIO TOP-RIGHT"; + linux,code = <0x137>; /* BTN_TR (R1) */ + }; + + /* + * sw22 from the R36S base (START on gpio3 PB4) is intentionally NOT + * kept: on the RGB10 Max 2's go3 wiring that pin is an aux button + * (sw17), and the real Start/Select sit on gpio2 PA2/PA3 (sw9/sw10). + * Keeping sw22 here would put two buttons on one pin. + */ +}; + +&dsi { + /delete-node/ panel@0; + + panel@0 { + compatible = "elida,kd50t048a", "simple-panel-dsi"; + reg = <0>; + + /* pwm1 backlight */ + backlight = <&backlight>; + + /* LCD reset gpio GPIO3.C0 (kernel log: gpio 112, active low) */ + reset-gpios = <&gpio3 RK_PC0 GPIO_ACTIVE_LOW>; + + /* RK817 LDO8 */ + power-supply = <&vcc_lcd>; + + prepare-delay-ms = <2>; + reset-delay-ms = <20>; + init-delay-ms = <10>; + enable-delay-ms = <50>; + disable-delay-ms = <10>; + unprepare-delay-ms = <10>; + + /* LCD size */ + width-mm = <69>; + height-mm = <139>; + + dsi,flags = <(MIPI_DSI_MODE_VIDEO | + MIPI_DSI_MODE_VIDEO_BURST | + MIPI_DSI_MODE_LPM)>; + + dsi,format = ; + /* This panel runs on two data lanes (go3 DTB), not four */ + dsi,lanes = <2>; + + /* + - panel-init-sequence data description - + mipi_cmd, delay(ms), len, lcd_cmd, lcd_data... + + - mipi_cmd description - + 05 : MIPI_DSI_SHORT_WRITE + 15 : MIPI_DSI_SHORT_WRITE_PARAM + 39 : MIPI_DSI_LONG_WRITE + + Init sequence and timings ported verbatim from the + RGB10 Max 2's own rk3326-odroidgo3-linux.dtb. + */ + panel-init-sequence = [05 05 01 01 05 fa 01 11 39 00 06 ff 77 01 00 00 10 15 00 03 c0 e9 03 15 00 03 c1 11 02 15 00 03 c2 31 08 15 00 02 cc 10 39 00 11 b0 00 0d 14 0d 10 05 02 08 08 1e 05 13 11 a3 29 18 39 00 11 b1 00 0c 14 0c 10 05 03 08 07 20 05 13 11 a4 29 18 39 00 06 ff 77 01 00 00 11 15 00 02 b0 6c 15 00 02 b1 43 15 00 02 b2 07 15 00 02 b3 80 15 00 02 b5 47 15 00 02 b7 85 15 00 02 b8 20 15 00 02 b9 10 15 00 02 c1 78 15 00 02 c3 78 15 fa 02 d0 88 39 00 04 e0 00 00 02 39 00 0c e1 08 00 0a 00 07 00 09 00 00 33 33 39 00 0f e2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 39 00 05 e3 00 00 33 33 15 00 03 e4 44 44 39 00 11 e5 0e 60 a0 a0 10 60 a0 a0 0a 60 a0 a0 0c 60 a0 a0 39 00 05 e6 00 00 33 33 15 00 03 e7 44 44 39 00 11 e8 0d 60 a0 a0 0f 60 a0 a0 09 60 a0 a0 0b 60 a0 a0 39 00 08 eb 02 01 e4 e4 44 00 40 15 00 03 ec 02 01 39 00 11 ed ab 89 76 54 01 ff ff ff ff ff ff 10 45 67 98 ba 39 00 06 ff 77 01 00 00 00 15 00 02 3a 70 15 00 02 53 ec 15 00 02 55 b3 15 00 02 5e ff 05 32 01 29]; + + panel-exit-sequence = <0x5000128 0x5000110>; + + display-timings { + native-mode = <&timing0>; + + timing0: timing0 { + clock-frequency = <27500000>; + hactive = <480>; + vactive = <854>; + hfront-porch = <2>; + hsync-len = <10>; + hback-porch = <2>; + vfront-porch = <12>; + vsync-len = <2>; + vback-porch = <60>; + hsync-active = <0>; + vsync-active = <0>; + de-active = <0>; + pixelclk-active = <0>; + }; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + dsi_in_panel: endpoint { + remote-endpoint = <&dsi_out_panel>; + }; + }; + }; + }; +}; + +&rk817 { + battery { + /* Panel and battery values from the RGB10 Max 2's own DTB: + 4000 mAh cell, 4.2 V charge, 180 mOhm, 10 mOhm sense. */ + ocv_table = <3500 3625 3685 3697 3718 3735 3748 + 3760 3774 3788 3802 3816 3834 3853 + 3877 3908 3946 3975 4018 4071 4106>; + design_capacity = <4000>; + design_qmax = <4020>; + bat_res = <180>; + sleep_enter_current = <300>; + sleep_exit_current = <300>; + sleep_filter_current = <100>; + power_off_thresd = <3300>; + zero_algorithm_vol = <3850>; + max_soc_offset = <60>; + monitor_sec = <5>; + virtual_power = <0>; + sample_res = <10>; + }; + + charger { + /delete-property/ bat_low_gpio; + min_input_voltage = <4500>; + max_input_current = <1500>; + max_chrg_current = <2000>; + max_chrg_voltage = <4200>; + chrg_term_mode = <0>; + chrg_finish_cur = <300>; + virtual_power = <0>; + sample_res = <10>; + }; +}; + +&rk817_codec { + mic-in-differential; +}; + +/* + * RGB10 Max 2 Wi-Fi — v17: the endgame test. + * Live debugging (adb via tethered PC) proved: the bus, hub, dongle, + * driver and Wi-Fi stack are all perfect — powering the OTG VBUS net + * from outside (PC 5V) makes Wi-Fi work instantly; unplugging kills it + * in <3s. otg_switch stays "disabled" while working, so the net is fed + * ONLY by external VBUS today. + * Remaining question: can the PMIC otg_switch rail drive this net at + * all? v13's single snapshot showed the register claiming "on" while + * the hub stayed dead — but that may have been transient (re-killed). + * v17 = v13's extcon chain (port enabled, suppression deleted, phy + * vbus-supply) on the v16 base (autosuspend off, PM pins, role toggle + * + fast rail sampling in the diag). If the register holds "on" and + * the hub still ignores it, the board wiring is the answer (external + * 5V required); if the hub comes up, the rail path is fixed and + * Wi-Fi works standalone. + */ +&u2phy_otg { + status = "disabled"; +}; + +&usb20_otg { + /* Stock topology: phyless dwc2, otg-port disabled. The phy lookup + * defers until the u2phy driver is up (UTMI clock on) and then returns + * -ENODEV for the disabled port, so dwc2 probes phyless with the clock + * running (removing the phys property entirely caused an early probe + * and a core-reset hang). Keeping the port disabled also keeps the + * charger driver ignorant of OTG: no extcon events -> otg_in stays 0 -> + * the charger keeps its plug detection and can charge while Wi-Fi runs. + * The Wi-Fi rail is armed separately by the boot service (raw i2c). */ + dr_mode = "host"; + phys = <&u2phy_otg>; + phy-names = "usb2-phy"; +}; + +/* + * RGB10 Max 2: also enable the dedicated host pair (EHCI + OHCI); the + * shared u2phy host-port is already okay from the base dtsi. + */ +&usb_host0_ehci { + status = "okay"; +}; + +&usb_host0_ohci { + status = "okay"; +}; + +/* + * RGB10 Max 2: the charger detection (gpio0 PB3, base tree values) stays + * untouched, like stock: it is what lets the charger enable the charge + * path. The Wi-Fi rail is armed by the boot service; because the phy port + * is disabled, the charger never receives a false OTG event and keeps + * working normally alongside Wi-Fi. + */ +&sdio { + status = "disabled"; +}; + +&io_domains { + vccio1-supply = <&vcc_3v3>; +}; diff --git a/docs/rgb10max2/service/diag.sh b/docs/rgb10max2/service/diag.sh new file mode 100644 index 0000000..a6f163b --- /dev/null +++ b/docs/rgb10max2/service/diag.sh @@ -0,0 +1,158 @@ +#!/system/bin/sh +# RGB10 Max 2 production v28 - stock topology + latch + panel cycle + perf janitor +# - otg-port disabled (stock): charging and Wi-Fi work together +# - boot service arms the PMIC OTG rail latch (raw i2c) and keeps it armed +# - watchdog re-arms the latch whenever the hub loses power +# - panel fix: sleep/wake cycle after bootanim stops +# - runtime tuning: swappiness, sd readahead, iostats off, GPU 600MHz, +# UI animations 0.5 +# - background janitor every 40s: kill cached processes; fully close heavy +# apps (thorium, vlc) that are NOT the foreground activity; syncthing is +# deliberately excluded (it must run in the background to sync) +# - radio tuning (power save off, regdomain), adb over tcp, root daemon +D=/data/local/tmp +mkdir -p $D +echo "started $(date)" > $D/diag-status.txt +cp /sys/fs/pstore/* $D/ 2>/dev/null + +RK=/vendor/etc/rk817tool +[ -x "$RK" ] || RK=$D/rk817tool +WF=/vendor/etc/wifitool +[ -x "$WF" ] || WF=$D/wifitool +DR=/sys/bus/platform/drivers/rk817-charger +devs() { ls /sys/bus/usb/devices 2>/dev/null | grep -c -- -; } + +insmod /vendor/lib/modules/rtl8xxxu.ko 2>>$D/insmod.err + +for P in /sys/devices/platform/ff300000.usb /sys/bus/usb/devices/usb1 /sys/bus/usb/devices/usb2 /sys/bus/usb/devices/usb3; do + [ -e "$P/power/control" ] && echo on > "$P/power/control" 2>>$D/pm.err +done + +# runtime tuning (kernel sysctls reset at boot; re-apply) ---- +echo 100 > /proc/sys/vm/swappiness 2>/dev/null +echo 512 > /sys/block/mmcblk0p6/queue/read_ahead_kb 2>/dev/null +echo 512 > /sys/block/mmcblk0/queue/read_ahead_kb 2>/dev/null +echo 0 > /sys/block/mmcblk0/queue/iostats 2>/dev/null +echo 600000000 > /sys/class/devfreq/ff400000.gpu/max_freq 2>/dev/null && echo "gpu: max 600MHz" >> $D/diag-status.txt + +# ---- tailscale (remote access: console joins the tailnet) ---- +# state already authenticated in /data/local/tmp/ts/state; tailscaled alone +# reconnects on boot. Janitor restarts it if it ever dies. +TSB=/data/local/tmp/ts +if [ -x $TSB/tailscaled ] && [ -f $TSB/state/tailscaled.state ]; then + if ! pidof tailscaled >/dev/null; then + nohup $TSB/tailscaled --statedir=$TSB/state --socket=$TSB/tailscaled.sock --tun=tun0 > $TSB/tsd.log 2>&1 & + echo "tailscale: started" >> $D/diag-status.txt + fi +fi + +# ---- arm the Wi-Fi rail latch (always; charging is independent now) ---- +if [ -x "$RK" ]; then + if [ "$(devs)" -ge 3 ]; then + echo "rail: hub already up (devs=$(devs))" >> $D/diag-status.txt + else + echo "rail: arming latch" >> $D/diag-status.txt + $RK b4 47 >> $D/rail.log 2>&1 + sleep 3 + if [ "$(devs)" -lt 3 ]; then + echo "rail: retry with charger unbind/rebind" >> $D/diag-status.txt + echo rk817-charger > $DR/unbind 2>>$D/rail.log + sleep 1 + $RK b4 47 >> $D/rail.log 2>&1 + sleep 3 + echo rk817-charger > $DR/bind 2>>$D/rail.log + sleep 2 + [ "$(devs)" -lt 3 ] && { $RK b4 47 >> $D/rail.log 2>&1; sleep 2; } + fi + echo "rail: final devs=$(devs)" >> $D/diag-status.txt + fi +fi + +# ---- wait for boot ---- +N=0 +while [ "$(/system/bin/getprop sys.boot_completed)" != "1" ] && [ $N -lt 300 ]; do + sleep 1; N=$((N+1)) +done +echo "boot_completed after ${N}s" >> $D/diag-status.txt + +M=0 +while [ ! -e /sys/class/net/wlan0 ] && [ $M -lt 60 ]; do sleep 1; M=$((M+1)); done +if [ -e /sys/class/net/wlan0 ] && [ -x "$WF" ]; then + $WF ps-off 2>>$D/radio.err + $WF reg MA 2>>$D/radio.err + echo "radio: ps-off + reg MA applied" >> $D/diag-status.txt +fi + +setprop service.adb.tcp.port 5555 +setprop ctl.restart adbd +echo "ADBTCP-ON" >> $D/diag-status.txt +chmod 666 $D/diag-status.txt $D/rail.log $D/*.err 2>/dev/null + +# UI animations at 0.5 (snappier on this class of hardware; 1.0 = stock feel) +settings put global window_animation_scale 0.5 2>/dev/null +settings put global transition_animation_scale 0.5 2>/dev/null +settings put global animator_duration_scale 0.5 2>/dev/null + +# ---- PANEL FIX: force the display DPMS cycle ---- +# The kernel draws the boot logo, but when SurfaceFlinger/HWC take over the +# DRM master the CRTC is never (re)enabled for the Android framebuffer, so +# the panel stays black while Android believes the screen is on. A +# sleep/wake cycle forces DisplayPowerController to disable+re-enable the +# display, which triggers the CRTC modeset and the picture appears. +# This replicates exactly what the user had to do by hand (power button). +# NOTE: input injection needs system_server, and this code runs only after +# sys.boot_completed=1. The bootanim wait accepts "stopped" AND empty +# (nobootanimation builds never set the service running). +M=0 +while [ "$(getprop init.svc.bootanim)" = "running" ] && [ $M -lt 120 ]; do + sleep 1; M=$((M+1)) +done +echo "bootanim state reached after ${M}s, cycling panel" >> $D/diag-status.txt +input keyevent KEYCODE_POWER +sleep 1.5 +input keyevent KEYCODE_POWER +sleep 1 +echo "panel cycle done $(date +%H:%M:%S)" >> $D/diag-status.txt +chmod 666 $D/diag-status.txt 2>/dev/null + + +# ---- MAIN LOOP: root daemon + rail watchdog ---- +I=0 +while true; do + I=$((I+1)) + if [ -f $D/cmd.in ]; then + mv $D/cmd.in $D/cmd.running 2>/dev/null + /system/bin/sh $D/cmd.running > $D/cmd.out 2>&1 + chmod 666 $D/cmd.out 2>/dev/null + rm -f $D/cmd.running + fi + if [ $((I % 30)) -eq 0 ] && [ -x "$RK" ]; then + if [ "$(devs)" -lt 3 ]; then + echo "$(date +%H:%M:%S) hub down, re-arming latch" >> $D/rail.log + $RK b4 47 >> $D/rail.log 2>&1 + chmod 666 $D/rail.log 2>/dev/null + fi + [ -e /sys/class/net/wlan0 ] && [ -x "$WF" ] && $WF ps-off > /dev/null 2>&1 + fi + # ---- background janitor (every 40s): keep RAM clear ---- + # 1. cached processes -> killed (am kill-all only touches killable/cached) + # 2. heavy apps (thorium, vlc) that are NOT the foreground activity -> + # force-stopped completely, so they never linger in RAM + # 3. syncthing deliberately NOT touched: it syncs from the background on + # purpose; kill it by hand if you want it fully off + if [ $((I % 40)) -eq 0 ]; then + RES=$(dumpsys activity activities 2>/dev/null | grep -m1 topResumedActivity) + for P in org.chromium.thorium org.videolan.vlc; do + if [ -n "$(pidof $P)" ] && ! echo "$RES" | grep -q "$P"; then + am force-stop $P 2>/dev/null + fi + done + am kill-all 2>/dev/null + fi + # ---- tailscale keep-alive ---- + if [ -x $TSB/tailscaled ] && [ -f $TSB/state/tailscaled.state ] && ! pidof tailscaled >/dev/null; then + nohup $TSB/tailscaled --statedir=$TSB/state --socket=$TSB/tailscaled.sock --tun=tun0 >> $TSB/tsd.log 2>&1 & + echo "$(date +%H:%M:%S) tailscale restarted" >> $D/rail.log + fi + sleep 1 +done diff --git a/docs/rgb10max2/service/zz-diag.rc b/docs/rgb10max2/service/zz-diag.rc new file mode 100644 index 0000000..fd08627 --- /dev/null +++ b/docs/rgb10max2/service/zz-diag.rc @@ -0,0 +1,9 @@ +# andr36oid-diag: internal wifi rail latch + radio tuning + adb +# install as /vendor/etc/init/zz-diag.rc with diag.sh at /vendor/etc/diag.sh +on post-fs-data + start andr36oid-diag + +service andr36oid-diag /system/bin/sh /vendor/etc/diag.sh + user root + group root + disabled diff --git a/docs/rgb10max2/tools/rk817tool.c b/docs/rgb10max2/tools/rk817tool.c new file mode 100644 index 0000000..712d137 --- /dev/null +++ b/docs/rgb10max2/tools/rk817tool.c @@ -0,0 +1,71 @@ +/* rk817tool - read/write RK817 PMIC registers via /dev/i2c-0 (addr 0x20) + * usage: rk817tool read one register (hex, e.g. b4) + * rk817tool write then read back + * rk817tool dump dump a range + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define I2C_DEV "/dev/i2c-0" +#define ADDR 0x20 + +static int fd; +static int xfer(uint8_t wr[], int wn, uint8_t rd[], int rn) +{ + struct i2c_msg msgs[2] = { + { .addr = ADDR, .flags = 0, .len = wn, .buf = wr }, + { .addr = ADDR, .flags = I2C_M_RD, .len = rn, .buf = rd }, + }; + struct i2c_rdwr_ioctl_data d = { .msgs = msgs, .nmsgs = 2 }; + if (rn == 0) d.nmsgs = 1; + return ioctl(fd, I2C_RDWR, &d); +} + +static int rd_reg(uint8_t reg, uint8_t *val) +{ + uint8_t r; + if (xfer(®, 1, &r, 1) < 0) return -1; + *val = r; + return 0; +} + +static int wr_reg(uint8_t reg, uint8_t val) +{ + uint8_t w[2] = { reg, val }; + if (xfer(w, 2, NULL, 0) < 0) return -1; + return 0; +} + +int main(int argc, char **argv) +{ + if (argc < 2) { fprintf(stderr, "usage: %s [val] | dump \n", argv[0]); return 2; } + fd = open(I2C_DEV, O_RDWR); + if (fd < 0) { perror(I2C_DEV); return 1; } + + if (!strcmp(argv[1], "dump") && argc >= 4) { + int a = strtol(argv[2], 0, 16), b = strtol(argv[3], 0, 16); + for (; a <= b; a++) { + uint8_t v; + if (rd_reg(a, &v) < 0) { printf("%02x: ERR\n", a); continue; } + printf("%02x %02x\n", a, v); + } + return 0; + } + int reg = strtol(argv[1], 0, 16); + uint8_t v; + if (argc >= 3) { + int val = strtol(argv[2], 0, 16); + if (wr_reg(reg, val) < 0) { perror("write"); return 1; } + usleep(10000); + } + if (rd_reg(reg, &v) < 0) { perror("read"); return 1; } + printf("%02x %02x\n", reg, v); + return 0; +} diff --git a/docs/rgb10max2/tools/wifitool.c b/docs/rgb10max2/tools/wifitool.c new file mode 100644 index 0000000..ddf69ba --- /dev/null +++ b/docs/rgb10max2/tools/wifitool.c @@ -0,0 +1,152 @@ +/* wifitool - minimal nl80211 control (no libnl, static) + * usage: wifitool ps-off | ps-on | ps-get | reg MA + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef NLA_OK +#define NLA_OK(nla, len) ((len) >= (int)sizeof(struct nlattr) && \ + (nla)->nla_len >= sizeof(struct nlattr) && (nla)->nla_len <= (len)) +#endif +#ifndef NLA_NEXT +#define NLA_NEXT(nla, attrlen) ((attrlen) -= NLA_ALIGN((nla)->nla_len), \ + (struct nlattr *)(((char *)(nla)) + NLA_ALIGN((nla)->nla_len))) +#endif + +static int nl_open(void) +{ + int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + if (fd < 0) { perror("socket"); return -1; } + struct sockaddr_nl sa = { .nl_family = AF_NETLINK }; + if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { perror("bind"); close(fd); return -1; } + return fd; +} + +/* send one message and wait for the ACK; returns 0 on success */ +static int nl_talk(int fd, struct nlmsghdr *nlh) +{ + struct sockaddr_nl sa = { .nl_family = AF_NETLINK }; + nlh->nlmsg_seq = 1; + if (sendto(fd, nlh, nlh->nlmsg_len, 0, (struct sockaddr *)&sa, sizeof(sa)) < 0) { + perror("send"); return -1; + } + char buf[8192]; + int r = recv(fd, buf, sizeof(buf), 0); + if (r < 0) { perror("recv"); return -1; } + for (struct nlmsghdr *h = (struct nlmsghdr *)buf; NLMSG_OK(h, r); h = NLMSG_NEXT(h, r)) { + if (h->nlmsg_type == NLMSG_ERROR) { + struct nlmsgerr *e = (struct nlmsgerr *)NLMSG_DATA(h); + if (e->error) { errno = -e->error; perror("netlink"); return -1; } + return 0; + } + if (h->nlmsg_type == NLMSG_DONE) return 0; + } + return 0; +} + +#define NLA_PUT(nlh, type, len, data) do { \ + int _l = NLA_HDRLEN + (len); \ + struct nlattr *_a = (struct nlattr *)((char *)(nlh) + NLMSG_ALIGN((nlh)->nlmsg_len)); \ + _a->nla_type = (type); _a->nla_len = _l; \ + memcpy((char *)_a + NLA_HDRLEN, (data), (len)); \ + (nlh)->nlmsg_len = NLMSG_ALIGN((nlh)->nlmsg_len) + NLA_ALIGN(_l); \ +} while (0) + +static int resolve_nl80211(int fd) +{ + char msg[512] = {0}; + struct nlmsghdr *nlh = (struct nlmsghdr *)msg; + nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); + nlh->nlmsg_type = GENL_ID_CTRL; + nlh->nlmsg_flags = NLM_F_REQUEST; + struct genlmsghdr *g = (struct genlmsghdr *)NLMSG_DATA(nlh); + g->cmd = CTRL_CMD_GETFAMILY; + g->version = 1; + const char name[] = "nl80211"; + NLA_PUT(nlh, CTRL_ATTR_FAMILY_NAME, sizeof(name), name); + + struct sockaddr_nl sa = { .nl_family = AF_NETLINK }; + nlh->nlmsg_seq = 1; + sendto(fd, nlh, nlh->nlmsg_len, 0, (struct sockaddr *)&sa, sizeof(sa)); + char buf[8192]; + int r = recv(fd, buf, sizeof(buf), 0); + if (r < 0) { perror("recv"); return -1; } + for (struct nlmsghdr *h = (struct nlmsghdr *)buf; NLMSG_OK(h, r); h = NLMSG_NEXT(h, r)) { + if (h->nlmsg_type == GENL_ID_CTRL) { + struct genlmsghdr *gg = (struct genlmsghdr *)NLMSG_DATA(h); + int len = h->nlmsg_len - NLMSG_LENGTH(GENL_HDRLEN); + for (struct nlattr *a = (struct nlattr *)((char *)gg + GENL_HDRLEN); + NLA_OK(a, len); a = NLA_NEXT(a, len)) { + if (a->nla_type == CTRL_ATTR_FAMILY_ID) { + return *(unsigned short *)((char *)a + NLA_HDRLEN); + } + } + } + } + return -1; +} + +static int ps_set(int fd, int family, const char *ifname, unsigned int state) +{ + char msg[512] = {0}; + struct nlmsghdr *nlh = (struct nlmsghdr *)msg; + nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); + nlh->nlmsg_type = family; + nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + struct genlmsghdr *g = (struct genlmsghdr *)NLMSG_DATA(nlh); + g->cmd = NL80211_CMD_SET_POWER_SAVE; + g->version = 1; + unsigned int idx = if_nametoindex(ifname); + if (!idx) { fprintf(stderr, "no interface %s\n", ifname); return -1; } + NLA_PUT(nlh, NL80211_ATTR_IFINDEX, sizeof(idx), &idx); + NLA_PUT(nlh, NL80211_ATTR_PS_STATE, sizeof(state), &state); + return nl_talk(fd, nlh); +} + +static int reg_set(int fd, int family, const char *alpha2) +{ + char msg[512] = {0}; + struct nlmsghdr *nlh = (struct nlmsghdr *)msg; + nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); + nlh->nlmsg_type = family; + nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + struct genlmsghdr *g = (struct genlmsghdr *)NLMSG_DATA(nlh); + g->cmd = NL80211_CMD_REQ_SET_REG; + g->version = 1; + if (strlen(alpha2) != 2) { fprintf(stderr, "alpha2 must be 2 chars\n"); return -1; } + NLA_PUT(nlh, NL80211_ATTR_REG_ALPHA2, 2, alpha2); + return nl_talk(fd, nlh); +} + +int main(int argc, char **argv) +{ + if (argc < 2) { fprintf(stderr, "usage: %s ps-off|ps-on|ps-get|reg [iface]\n", argv[0]); return 2; } + int fd = nl_open(); + if (fd < 0) return 1; + int fam = resolve_nl80211(fd); + if (fam < 0) { fprintf(stderr, "nl80211 family not found\n"); return 1; } + const char *iface = (argc > 3) ? argv[3] : "wlan0"; + + if (!strcmp(argv[1], "ps-off")) { + if (ps_set(fd, fam, iface, 0)) return 1; + printf("power save OFF on %s\n", iface); + } else if (!strcmp(argv[1], "ps-on")) { + if (ps_set(fd, fam, iface, 1)) return 1; + printf("power save ON on %s\n", iface); + } else if (!strcmp(argv[1], "reg") && argc >= 3) { + if (reg_set(fd, fam, argv[2])) return 1; + printf("regdomain set to %s\n", argv[2]); + } else { + fprintf(stderr, "unknown command\n"); + return 2; + } + return 0; +}