# De-Tuya-ing the AK3918AV130 camera
> **Start with [GUIDE.md](GUIDE.md)**: the step-by-step install guide for the RTSP firmware.
> [IMAGE_CONTENTS.md](IMAGE_CONTENTS.md) documents exactly what the image contains.
> This README holds the original research notes (rooting, layout, the telnet and local images).
>
> Camera: **LSC Smart Connect outdoor camera** from Action (article 3225728,
> ).
> Advertised: 2K, Wi-Fi 2.4 + 5 GHz, mains powered, 25.95 €.
Working notes + toolkit for rooting and converting a Tuya Anyka camera to local
control. Everything here is derived from a flash dump of the camera (`camera_flash.bin`,
not included: it holds per-device keys).
---
## 1. What the camera is
| | |
|---|---|
| SoC | **Anyka AK3918AV130** (ARMv5, 960 MHz) — board `EVB_CBD_AK3918AV130_V1.0.0` |
| RAM / Flash | 64 MiB DRAM / **8 MiB SPI-NOR** (Zetta ZB25VQ64, 4 KiB erase) |
| Bootloader | U-Boot 2019.10.0 — **Ctrl+C at power-on drops to the `=>` prompt** |
| Kernel | Linux 4.4.302, console `ttySAK0 @ 115200 8N1` |
| Userland | BusyBox, Anyka SDK V1.05.06; app = Tuya (`cmdserver`/`msgserver`, `tuya_*.db`) |
| Sensor | SmartSens **SC3332** (MIPI) |
| Wi-Fi | **AltoBeam ATBM6x6x** USB (fullmac, `wlan0`); `ak_eth.ko` exists but `net_mode=0` → **wired disabled** |
| Status | Bought new, **never paired with Tuya** → no account binding, clean factory config |
### Why there is no shell out of the box (three deliberate locks)
1. `etc/inittab`: the serial `getty` line is **commented out** → no login on UART.
2. `usr/sbin/main.sh`: `#/usr/sbin/telnetd &` is **commented out** → no telnet.
3. `usr/sbin/service.sh`: **deletes `/etc/config/shadow` every boot** → you can't just set a root password.
U-Boot is wide open, so none of that matters.
### Flash / MTD layout (8 MiB)
```
mtd0 UBOOT 200K @0x000000 mtd4 KERNEL 1536K @0x044000 (xz, zImage+appended DTB)
mtd1 ENV 4K @0x032000 mtd5 ROOTFS 1008K @0x1c4000 squashfs-xz, ro -> /
mtd2 ENVBK 4K @0x033000 mtd6 CONFIG 256K @0x2c0000 jffs2, rw -> /etc/config
mtd3 DTB 64K @0x034000 mtd7 APP ~5120K @0x300000 squashfs-xz, ro -> /usr
```
> The stock `mtdparts` string claims `APP=13312K`, but the chip is only 8 MiB, so
> APP is physically clamped to **5120 K** (0x300000 → end of flash). CONFIG is the
> **only runtime-writable** partition.
---
## 2. Phase 1 — Root shell over serial, right now (no flashing, reversible)
At the `=>` prompt, bypass init and drop straight to a root shell. **Do not `saveenv`**
— a power-cycle restores normal boot.
```
setenv bootargs 'console=ttySAK0,115200n8 root=/dev/mtdblock5 rootfstype=squashfs init=/bin/sh mtdparts=spi-nor:200K@0x0(UBOOT),4K@0x32000(ENV),4K@0x33000(ENVBK),64K@0x34000(DTB),1536K@0x44000(KERNEL),1008K@0x1c4000(ROOTFS),256K@0x2c0000(CONFIG),13312K@0x300000(APP) mem=64M memsize=64M'
run read_kernel
run read_dtb
bootm ${loadaddr}
```
You land at `#` as root (PID 1). Bring up the basics:
```sh
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t squashfs /dev/mtdblock7 /usr # APP: all tools live here
mount -t jffs2 /dev/mtdblock6 /etc/config
export PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin
```
---
## 3. Phase 2 — Join your Wi-Fi (from that shell)
All stock tools are present (`wpa_supplicant`, `wpa_cli`, `udhcpc` + its `default.script`).
```sh
insmod /usr/modules/cfg80211.ko # load first if the next line complains
/usr/sbin/wifi_driver.sh sta # insmods ATBM6x6x_wifi_usb.ko, brings up wlan0
cat > /tmp/wpa_supplicant.conf <<'EOF'
ctrl_interface=/var/run/wpa_supplicant
update_config=1
network={
scan_ssid=1
ssid="YourNetwork"
psk="YourPassword"
}
EOF
wpa_supplicant -B -iwlan0 -Dnl80211 -c /tmp/wpa_supplicant.conf
wpa_cli -iwlan0 status # wait for wpa_state=COMPLETED
udhcpc -i wlan0 # DHCP lease
ifconfig wlan0 # confirm IP
```
Static fallback if DHCP misbehaves:
`ifconfig wlan0 192.168.x.y netmask 255.255.255.0 && route add default gw 192.168.x.1`
---
## 4. Phase 3 — Telnet (volatile)
Once on the network:
```sh
telnetd -l /bin/sh # passwordless root shell on :23 (shadow is wiped each boot, so no login)
```
`telnet ` from your PC → root. Gone on reboot. For persistence, flash the
patched image below.
---
## 5. The patched image (persistent telnet + Wi-Fi + "edit any file")
**`toolkit/out/camera_flash_telnet.bin`** — identical to your dump except the APP
partition, which now:
- auto-loads the Wi-Fi driver and **connects to your AP** (`WIFI_SSID`/`WIFI_PSK`, baked in at build),
- runs **`telnetd -l /bin/sh`** (passwordless root on :23),
- spawns a **root shell on the serial console** every boot (no U-Boot dance needed),
- applies a **writable overlay** (see §6),
- does **not** start the Tuya daemons (clean local base; it won't stream video — that comes with OpenIPC/Majestic later).
Change the baked-in Wi-Fi creds and rebuild:
```sh
cd toolkit
WIFI_SSID='MyNet' WIFI_PSK='MyPass' ./variants/telnet.sh
```
You can also override creds at runtime without reflashing by dropping a
`wpa_supplicant.conf` into `/etc/config/` (CONFIG survives reboots).
> ⚠️ No hardware watchdog is petted in this image (the Tuya service that did it is
> disabled). If the board resets ~once a minute during boot, U-Boot armed the WDT:
> add `[ -e /dev/watchdog ] && watchdog -t 5 /dev/watchdog` near the top of
> `local_bootstrap.sh` and rebuild.
---
## 5.5 Tuya-free image with a real writable partition (`local` variant)
`toolkit/out/camera_flash_local.bin` goes further than the telnet image: it **removes
the Tuya app layer** (`anyka_ipc` 5.8M, `msgserver`, `cmdserver`, `system_upgrade`, the
NPU AI model, and the voice/siren MP3s), which shrinks APP from 4772K → **2076K**. The
freed space becomes a **2944K writable jffs2 `DATA` partition**. All kernel modules,
Wi-Fi, ISP and video-encoder drivers are **kept**, so the hardware stays fully usable.
Behaviour on boot: same as the telnet image (Wi-Fi auto-join, `telnetd -l /bin/sh`,
serial root shell) but the writable overlay is backed by the big `DATA` partition
(mounted at `/data`), so `rw ` has ~2.9 MB to work with instead of ~200 K.
Build it:
```sh
cd toolkit
WIFI_SSID='MyNet' WIFI_PSK='MyPass' ./variants/local.sh
```
**Required one-time U-Boot step** (the repartition). The DTB has no partition table —
partitions come from the kernel cmdline `mtdparts` in the U-Boot env — so after flashing,
break to `=>` and run **once**:
```
setenv mtdparts 'mtdparts=spi-nor:200k@0x0(UBOOT),4k@0x32000(ENV),4k@0x33000(ENVBK),64k@0x34000(DTB),1536k@0x44000(KERNEL),1008k@0x1c4000(ROOTFS),256k@0x2c0000(CONFIG),2176k@0x300000(APP),2944k@0x520000(DATA)'
saveenv
reset
```
`boot_normal` rebuilds `bootargs` from `${mtdparts}` on every boot, so this is all that's
needed; the kernel now exposes `DATA` as **mtd8** (`/dev/mtdblock8`). It's reversible —
`setenv` it back (or restore the original dump). Until you run it, the image still boots
and gives telnet (it just falls back to the small CONFIG overlay).
> New NOR layout:
> ```
> APP stripped squashfs 2176K @0x300000 (Tuya-free, drivers kept)
> DATA jffs2 writable 2944K @0x520000 (empty, pre-formatted — your space)
> ```
> The empty DATA image is built byte-for-byte like `flash_erase -j` (a 4 K cleanmarker
> per block), so it mounts clean on first boot.
---
## 6. "Edit any file" — why it's an overlay, not a full JFFS2
**Full JFFS2 does not fit on this 8 MiB chip** (measured, not estimated):
| | JFFS2 (real `mkfs.jffs2`) | Partition room | Verdict |
|---|---|---|---|
| ROOTFS | 1576 K | 1008 K | ❌ +568 K |
| APP | 7232 K | 5120 K | ❌ +2112 K |
| Both pooled | 8808 K | 6128 K (all free space) | ❌ **+2680 K** |
The stock firmware only fits because squashfs-xz compresses ~2.6×. The kernel also
has **no overlayfs and no aufs** (checked the decompressed kernel — only squashfs,
jffs2, tmpfs, ramfs). So the writable mechanism is **jffs2 (CONFIG) + bind-mounts**:
- On boot, every file under **`/etc/config/overlay/`** is bind-mounted over its
real path. This lets you **replace/edit any existing file**, persistently.
- New files can be added freely in already-writable dirs (`/etc/config`, `/data`, `/var`, `/tmp`).
- Helper on the device: **`rw /abs/path/file`** copies the file into the overlay and
binds it immediately, so you can then edit it in place.
```sh
# on the camera:
rw /usr/sbin/main.sh # make it writable+persistent
vi /usr/sbin/main.sh # edit; survives reboot via the overlay
```
**Budget: ~200 K** of persistent edit space (CONFIG is 256 K, ~50 K already used).
Plenty for scripts/configs; not enough to swap large binaries. For real writable
space you must free flash — see §8.
---
## 7. The build toolkit (`toolkit/`)
Parts-based: the image is split into partitions, each editable, then reassembled.
```
toolkit/
layout.conf stock partition table (name / offset / size / kind / file)
layout-local.conf repartitioned map (Tuya-free APP + writable DATA)
parts/stock/ raw stock partitions, carved from your dump (prefilled)
parts/telnet/ the telnet variant's parts
parts/local/ the Tuya-free variant's parts (incl. empty DATA jffs2)
src/rootfs/ stock ROOTFS tree (editable)
src/app/ stock APP tree (editable)
split.sh full image -> parts//
repack-fs.sh a src tree -> squashfs (default) or jffs2 partition file
build-image.sh parts/ -> 8 MiB image (LAYOUT= to override map)
variants/telnet.sh telnet+wifi+overlay image (stock layout)
variants/local.sh Tuya-free + writable DATA image (repartitioned)
out/ finished images
```
Common operations:
```sh
cd toolkit
# re-carve parts from any image
./split.sh /path/to/some_dump.bin parts/stock
# edit files under src/rootfs or src/app, then repack one partition:
./repack-fs.sh src/app parts/stock/app.bin $((0x500000)) squashfs
# (last arg can be 'jffs2' instead, if it fits the slot)
# reassemble a full image from a parts set:
./build-image.sh parts/stock out/my_image.bin
# one-shot telnet build (reads stock parts, patches app):
WIFI_SSID='MyNet' WIFI_PSK='MyPass' ./variants/telnet.sh
```
Integrity guarantee: `build-image.sh parts/stock` reproduces your original dump
**byte-for-byte** (verified), so the pipeline is lossless.
---
## 8. Flashing
**Keep `camera_flash.bin` (your original dump) as the restore image.**
### A. External SPI programmer (recommended — the way you dumped it)
Clip onto the ZB25VQ64 (power the chip from the programmer, board off):
```sh
flashrom -p ch341a_spi -w toolkit/out/camera_flash_telnet.bin # adjust -p for your programmer
# restore anytime:
flashrom -p ch341a_spi -w camera_flash.bin
```
The whole image is written, but only APP differs, so it's safe and simple.
### B. Serial (no programmer) — Y-modem a single partition from U-Boot
At the `=>` prompt (≈8 min for APP at 115200):
```
loady 0x80008000 # then send toolkit/parts/telnet/app.bin from your terminal
sf probe
sf erase 0x300000 0x500000
sf write 0x80008000 0x300000 ${filesize}
reset
```
> U-Boot TFTP (`update`) only works if the board actually has an Ethernet PHY; this
> is a Wi-Fi model, so use the programmer or Y-modem.
---
## 9. Going fully local: OpenIPC
The reference — **`DavidL54/OpenIPC-firmware-Anyka`** — has a Buildroot defconfig for
**your exact SoC** (`ak3918av130_lite_defconfig`: Majestic streamer/RTSP, Dropbear SSH,
`wpa_supplicant`), reusing the stock Anyka kernel/DTB/U-Boot + the proprietary
`ANYKA_OSDRV_AK3918AV130` SDK blob.
But it's an **experimental research port**: a public checkout **cannot build a complete
image yet**, it ships **no one-command installer**, and it needs the private
`AnyCloud39AV130_SDK_V1.03`. It also uses a **different NOR layout** than your camera.
→ Full build + flashing procedure, layout differences, safe-install checklist and
recovery are in **[`OPENIPC.md`](OPENIPC.md)**.
Recommended order: flash `camera_flash_local.bin` now (works today) → build OpenIPC with
its toolchain+SDK → assemble & flash an OpenIPC image with this toolkit, keeping stock
U-Boot/kernel/DTB.
---
## 10. File map
```
camera_flash.bin original dump (restore image — keep it)
bootinfo.txt / bootlog.txt serial captures (U-Boot env + boot log)
extractions/ binwalk output (rootfs/app/config trees, kernel)
BUILD_AND_INSTALL.md step-by-step: build an image, flash, repartition, ONVIF
OPENIPC.md OpenIPC build + flashing guide
RTSP.md local RTSP (+ONVIF) via the public Anyka SDK
toolkit/ build system (see §7)
layout*.conf stock / local / rtsp flash maps
variants/telnet.sh|local.sh|rtsp.sh image builders
blobs/anyka-rtsp/ SDK RTSP runtime (23 .so + server binary + rtsp.ini)
out/camera_flash_telnet.bin persistent telnet + wifi + overlay (stock layout)
out/camera_flash_local.bin Tuya-free + 2.9M writable DATA (repartitioned)
out/camera_flash_rtsp.bin Tuya-free + RTSP server (rtsp://ip/vs0,/vs1) + DATA
```
> **RTSP/ONVIF:** `camera_flash_rtsp.bin` bundles the public Anyka SDK's own RTSP server
> (H.264 `rtsp:///vs0` main + `/vs1` sub, port 554) — assembled from ABI-matched
> public binaries, **not yet hardware-tested**. ONVIF is a documented add-on. See
> **[`RTSP.md`](RTSP.md)**.