GUIDE.md: step-by-step for others (compatibility check, backup, build, four install methods, settings, recording, Wi-Fi, updates, restore, troubleshooting). IMAGE_CONTENTS.md: partition-by-partition audit of what the build changes and where every input comes from. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
18 KiB
What the RTSP image contains: partition-by-partition audit
This lists everything toolkit/variants/rtsp.sh puts into out/camera_flash_rtsp.bin:
what was kept from stock, what was removed or added, where each added file comes from,
and how the camera boots. It was checked against the build output (stock APP compared with
the built APP, and every other partition cmp'd against stock).
Status: the RTSP stream, Wi-Fi, SSH and repartitioning are confirmed working on hardware. These features are built but not yet tested on the device: 2304×1296 with the 24 MB ION heap, RTSP Digest auth,
fwupdate/ota.sh, the U-Boot SD updater,wifi-set,wifi.txtand SD recording. The recorder's muxer, rotation, size limits and pre-roll were verified in a host simulation.
1. Partition map (8 MiB SPI-NOR, ZB25VQ64)
| Partition | Offset | Size | Contents | vs. stock |
|---|---|---|---|---|
| UBOOT | 0x000000 | 200K | U-Boot 2019.10 (Anyka V4.0.27) | identical |
| ENV | 0x032000 | 4K | U-Boot environment | 4 variables changed in the full image: mtdparts (this layout), bootcmd (SD updater), sdscript, ht_fw_version (build id, see SD-only install). Everything else, e.g. ethaddr, is kept from your dump. Partition flashing never writes ENV; there you set the same values by hand once |
| ENVBK | 0x033000 | 4K | vendor env backup | same as ENV |
| DTB | 0x034000 | 64K | device tree | modified: ION heap 18 MB → 24 MB (see §3) |
| KERNEL | 0x044000 | 1536K | Linux 4.4.302-cip94 uImage | identical |
| ROOTFS | 0x1c4000 | 1008K | squashfs / (busybox, uClibc-ng 1.0.31, init scripts) |
identical |
| CONFIG | 0x2c0000 | 256K | jffs2 /etc/config (per-device data, see §5) |
identical |
| APP | 0x300000 | 2944K (stock: 13312K) | squashfs /usr |
rebuilt (see §4) |
| DATA | 0x5e0000 | 2176K | jffs2 /data, new |
new, empty on first flash |
The DTB has no partition table. The kernel gets the layout from U-Boot's mtdparts
variable, which is why moving to this layout is a single setenv mtdparts … ; saveenv.
The rootfs is not modified at all. Every change is in APP, which /etc/init.d/rc.local
runs through /usr/sbin/main.sh, plus the DTB, four U-Boot variables and the new DATA
partition. The env is rewritten by toolkit/env-patch.py: it parses the stock env, sets the
variables, and recomputes the CRC32.
Build outputs (staged in sdcard/ on every build): full.bin = the whole chip
(out/camera_flash_rtsp.bin), plus app.bin, dtb.bin, data.bin, env.bin,
sd-install-backup/ and sd-install-direct/ (SD-only installs for stock cameras) and MD5SUMS.
Writing full.bin resets DATA (camcfg settings, SSH host keys, overlay). Restoring the
original dump therefore restores the camera completely.
2. Boot flow
U-Boot bootcmd
├─ (if you set it up) SD card: camupdate.env → `sf update` the listed images
└─ boot_normal: kernel + DTB, root=/dev/mtdblock5 (squashfs)
rootfs /etc/init.d/rcS → rc.local
├─ mounts /usr (APP squashfs), /etc/config (CONFIG jffs2)
└─ /usr/sbin/main.sh (stock script; one line changed)
├─ syslogd/klogd, RTC, i2c, PWM, ADC, PCM, keys, ION, LEDs
├─ mmc + exfat modules, sensor + ISP + venc modules (sensor_driver.sh)
└─ /usr/sbin/local_bootstrap.sh & (replaces `service.sh start`, the Tuya launcher)
1. mount DATA → /data, bind-mount everything under /data/overlay over / (`rw` helper)
2. root shell on the serial console (ttySAK0)
3. SD card → /mnt/sd; camupdate.env → camupdate.done; wifi.txt → wifi-set
3b. optional 2nd SD partition → /mnt/sd2
4. USB host + cfg80211 + ATBM6x6x Wi-Fi → wifi-connect (with fallback chain)
4b. TZ from /data/timezone or /usr/local/timezone; ntpd (pool.ntp.org or /data/ntp_server)
5. /etc/config/shadow from /usr/local/root.hash (first boot only)
6. dropbear SSH :22 (host keys in /data/dropbear)
6b. `camcfg boot`: /etc/config/rtsp.ini = /usr/local/rtsp.ini + /data/camcfg.conf overrides
7. RTSP server :554 + SD recorder (same process), supervised (restarted if it exits;
the timezone is re-read on each start)
8. ONVIF, only if binaries exist in /data/onvif
Log: /tmp/local_bootstrap.log. RTSP log: /tmp/rtsp.log (previous run in /tmp/rtsp.log.1).
3. DTB change
| Node | Stock | Built |
|---|---|---|
/reserved-memory/dma_reserved@0x81400000 reg/size |
0x1200000 (18 MB) | 0x1800000 (24 MB) |
/ion/dma_reserved_heap size |
0x1200000 | 0x1800000 |
- Why: at 2304×1296 the capture buffers (2×4.5 MB + 2×0.35 MB) plus the encoder pool (5.8 MB) don't fit in 18 MB. The Tuya app got by because it shared buffers between capture and the encoder; the SDK sample doesn't.
- Cost: Linux has about 35 MB instead of 41 MB of the 64 MB RAM.
- Patch method: values are changed in place with
fdtput, so the blob size stays exactly 0xe351. That matters because U-Boot reads a fixeddtb_size=e351. The blob is then re-padded with 0xFF to 64K. - Build setting:
ION_MB=(18 = stock).
4. APP (/usr): exactly what changed
Removed (≈ 6.8 MB)
| File | Why |
|---|---|
bin/anyka_ipc (5.8 MB) |
Tuya cloud and video app |
bin/msgserver, bin/cmdserver, bin/system_upgrade |
Tuya IPC and OTA daemons |
local/model_0x0A000000_V1.1.0.bin (432K) |
NPU human-detection model, used only by anyka_ipc |
local/ak_font_16.bin (260K) |
OSD font, unused (needed to make APP fit) |
share/*.mp3 (25 files) |
Tuya voice prompts |
Modified
| File | Change |
|---|---|
sbin/main.sh |
service.sh start & → /usr/sbin/local_bootstrap.sh & |
modules/ak_venc_adapter.ko |
stock V2.0.13 → V2.0.16 (OpenIPC anyka-osdrv; same vermagic 4.4.302-cip94 mod_unload ARMv5). The stock one lacks an ioctl that libmpi_venc V3.0.02 needs |
modules/ak_venc_bridge.ko |
→ 2.0.08 (OpenIPC anyka-osdrv), paired with the above |
Added
| Path (on camera) | What | Source / how it's built |
|---|---|---|
/usr/lib/lib{plat_*,mpi_venc,mpi_aenc,app_its,app_video,rtsp_server,ak*}.so (23 libs) |
Anyka media SDK runtime | prebuilt, from public Link-WQS/ANYKA_130L_SDK platform/lib |
/usr/bin/ak_rtsp_server_sample |
RTSP server, /vs0 main and /vs1 sub |
rebuilt from SDK source (toolkit/src/rtsp_sample), patched to read [auth] and [server] from the ini, plus the SD recorder (ak_record.c, see below) and a per-stream enc_level key. The main ring buffer is 2 → 4 MB for 8 Mbps. Built with Bootlin armv5 uClibc 2018.11 (uClibc-ng 1.0.30, older than the camera's 1.0.31, so ABI-safe); its strings match the prebuilt binary exactly except for one log line. PREBUILT_RTSP=1 uses the original binary |
/usr/local/firstboot/ |
env.bin, envbk.bin, dtb.bin, version: applied on the first boot after a direct SD-only install |
build |
/usr/local/timezone |
POSIX TZ string (TIMEZONE=, default UTC0) |
generated |
/usr/local/rtsp.ini |
stream settings: 2304×1296 at 15 fps, 8 Mbps H.264, enc_level 50 (level 5.0; the sample hardcoded 30); sub 640×360 at 15 fps; [auth] admin/ROOT_PW |
generated from the SDK ini |
/usr/sbin/dropbearmulti + dropbear, dropbearkey, scp links |
SSH server | dropbear 2026.94, static musl, Bootlin armv5 musl 2026.08 |
/usr/sbin/mtdflash |
verified flash writer: per 4K block, skip if identical, else erase, write and read back (3 tries); size-checks every image before writing; refuses UBOOT/ENV without -f |
toolkit/src/mtdflash.c, static musl |
/usr/sbin/fwupdate |
maps file names to partitions, runs mtdflash from /tmp, stops RTSP and ONVIF, reboots |
toolkit/blobs/fwupdate/ |
/usr/sbin/wifi-set, wifi-mkconf, wifi-connect |
change Wi-Fi at runtime; fallback chain | toolkit/blobs/wifi/ |
/usr/sbin/camcfg |
settings CLI: validates values, stores only overrides in /data/camcfg.conf, merges them over /usr/local/rtsp.ini into /etc/config/rtsp.ini, writes /data/onvif.conf (synced size and login), /data/timezone, /data/ntp_server; restarts the stream |
toolkit/blobs/camcfg/ (tested with busybox sh/awk on the host) |
/usr/local/wpa_default.conf |
build-time default network (SSID hex-encoded) | from WIFI_SSID/WIFI_PSK; omitted if WIFI_SSID= |
/usr/local/root.hash |
MD5-crypt hash of ROOT_PW |
openssl passwd -1 |
/usr/sbin/local_bootstrap.sh |
boot script (§2) | generated by rtsp.sh |
/usr/sbin/rw |
rw /path/file: makes a read-only file editable and persistent through /data/overlay |
generated |
/usr/local/onvif/{onvif.conf,start_onvif.sh} |
ONVIF scaffolding; resolution and login filled in at build time | toolkit/blobs/onvif/ |
Kept from stock and used: busybox applets (/usr/bin, /usr/sbin links into /bin/busybox),
wpa_supplicant/wpa_cli, wifi_driver.sh, sensor_driver.sh, ISP tuning
/usr/local/isp_sc3332.conf, all other kernel modules.
The SD recorder (toolkit/src/rtsp_sample/ak_record.c)
Runs inside the RTSP server process as three threads:
- reader: registers as one more reader on the encoder's ring buffer (like an RTSP
client), copies frames into a RAM queue (
queue_max_kb, default 4 MB). It never waits on the SD card, so streaming is unaffected. If the card is too slow it drops frames until the next keyframe. - writer: writes its own MPEG-TS muxer output (PAT/PMT, H.264 or HEVC PES with PTS and
PCR). Continuous files rotate on the first keyframe after
segment_seconds. Motion clips start with an in-RAM pre-roll that always begins on a keyframe. After each file it deletes the oldest files until the folder is under its quota (*_percentof its filesystem or*_max_mb) and the card keepsmin_free_mbfree. It writes only to a real disk filesystem, never/, tmpfs or jffs2, so a missing card doesn't fill RAM. - motion: polls
ak_vpss_md_get_stat()(hardware 3DNR motion statistics, 32×24 grid) at 10 Hz. A cell counts as moving if it's abovemotion_threshold(by default derived frommotion_sensitivity, using the SDK's filter range). Motion fires whenmotion_min_cellscells move formotion_trigger_frameschecks in a row. It writes/tmp/motionand runsmotion_hook start|stop.
Video only: audio isn't recorded.
SD-card-only install (stock U-Boot ht_recover_fw.conf)
Reverse-engineered from stock U-Boot (loaded at 0x80dffa00; Thumb code around 0x80e01ffc). It runs at every boot before autoboot:
fs_set_blk_dev("mmc", "0", FAT), then read the first 80 bytes ofht_recover_fw.confto 0x82000000.- Header:
char magic[8]="HT_FW",u32 type,u32 kernel_size,u32 rootfs_size,u32 usrfs_size,u32 check_bundle,char bundle[36],char version[16](little-endian). - If
check_bundle≠ 0, envht_fw_bundlemust equalbundle. If envht_fw_versionequalsversion, nothing happens ("version is the same"). Stock env has noht_fw_version. - The decimal digits of
typeselect the files: unitsuImage→ 0x44000–0x1c3fff, tensroot.sqsh4→ 0x1c4000–0x2bffff, hundredsusr.sqsh4→ 0x300000–0x7fffff. Each file is read whole and must be exactly the size given in the header. The whole region is erased, then the file is written. - After
usr.sqsh4:setenv ht_fw_version <version>; saveenv, then a normal boot.
The build id (FWVER, default cr<date>) goes into every header as version and into the
image's env as ht_fw_version, so a camera never re-applies its own install.
sd-install-backup/ (type 10, rootfs region):
-
U-Boot writes
root.sqsh4. That's the stock rootfs from the build's dump, with/etc/init.d/camerarev-install.shadded.rc.localruns it instead ofmain.sh, and doesn't mount CONFIG, so the backup stays pristine. -
U-Boot only saves
ht_fw_versionafter ausr.sqsh4write. So with type 10, U-Boot keeps re-writing the installer at every power-on until the installer itself writes the final env. That is what makes every step before it restartable. -
The installer (
toolkit/blobs/sdinstall/camerarev-install.sh), with the stock layout still active:- Loads the mmc drivers from the still-original APP and mounts the card.
- Unless the card already has a backup: reads every MTD to
original-backup/.full.bin= UBOOT…APP concatenated (8 MiB). The ROOTFS region is taken fromcamerarev/rootfs.bin(the dump's stock rootfs), because the region now holds the installer, which is kept asROOTFS.installer.bin. UBOOT and KERNEL are compared withcamerarev/ref.md5, and the result goes intoREADME.txt. md5sum -c camerarev/MD5SUMS, then copies the files to RAM and checks them again.mtdflash -f -r APP usr.sqsh4 DTB dtb.bin ROOTFS rootfs.bin ENVBK envbk.bin ENV env.bin: ENV goes last, then a reboot.
A host simulation built fake MTDs from a real dump, with the ROOTFS region replaced by the installer, and ran the script under busybox. The resulting
full.binwas byte-identical to the original dump. Reruns kept the backup, and a corrupted file aborted the install before any write.
sd-install-direct/ (type 100, APP region): U-Boot writes usr.sqsh4 (APP padded to
0x2e0000 + empty DATA = exactly the 5 MiB region). APP carries
/usr/local/firstboot/{env,envbk,dtb}.bin. On a boot where /proc/mtd has no DATA
partition (still the stock layout), the boot script:
- backs up every partition except APP to
SD:/original-backup/ - writes DTB, ENVBK and ENV with
mtdflash -f -rand reboots
Cameras installed any other way already have DATA, so this never runs on them.
Where third-party inputs come from (none are in the git repo)
| Input | Source (pinned commit, checked against toolkit/deps.sha256) |
Fetched by |
|---|---|---|
23 SDK .so, ak_rtsp_server_sample, rtsp.ini, RTSP sample sources + 48 headers |
Link-WQS/ANYKA_130L_SDK @ 3480d02 |
fetch-deps.sh |
ak_venc_adapter.ko, ak_venc_bridge.ko |
OpenIPC/firmware @ 9e6a052 general/package/anyka-osdrv-ak3918av130/files/kmod |
fetch-deps.sh |
| armv5 musl 2026.08-1, armv5 uClibc 2018.11-1 toolchains | toolchains.bootlin.com | fetch-deps.sh |
| dropbear 2026.94 source | matt.ucc.asn.au/dropbear | build-deps.sh |
stock APP / rootfs trees (src/app, src/rootfs) |
your dump | extract-src.sh (called by the variants) |
Built from source by build-deps.sh: mtdflash (src/mtdflash.c), dropbearmulti, and the
RTSP server (upstream sample + patches/rtsp_sample.patch + src/rtsp_sample/ak_record.c).
5. Per-device data: don't share built images
These partitions are copied from your own dump and are unique to each camera:
- CONFIG contains
tuya_user.db,tuya_enckey.db,_ht_encrypt.binand_ht_encrypt_bak.bin(the device's Tuya identity and keys), plus_ht_hw_settings.ini,_ht_sw_settings.iniand apasswd. After first boot it also holds/etc/config/shadow(your root hash). - ENV contains
ethaddr(MAC address) and, after setup, yourmtdparts/bootcmd. - APP contains your Wi-Fi password (
wpa_default.conf), your root password hash, and your RTSP/ONVIF password in plain text (rtsp.ini,onvif.conf).
So out/camera_flash_rtsp.bin and parts/rtsp/app.bin are private. Don't publish them,
and don't flash one camera's full image onto another. Everyone builds from their own dump
(see GUIDE.md). The partition-level flash method (APP, DTB, DATA only) never
touches CONFIG, ENV or UBOOT.
6. Security posture
| Item | State |
|---|---|
| Tuya cloud | gone (no binaries, nothing contacts it) |
| SSH | dropbear :22, root password login (default anyka; change it with passwd) |
| Telnet | not started |
| RTSP | Digest auth, default admin / root password; set with RTSP_USER/RTSP_PASS or edit [auth] |
| ONVIF | not shipped; when added it uses the same user and password |
| Serial console | unauthenticated root shell, kept on purpose as the recovery path. Needs physical access (case open) |
| U-Boot | Ctrl+C prompt open; with the SD updater set up, anyone with the card slot can reflash. That's the price of no-serial recovery |
7. Known gaps and limits
- Frame rate: the stock ISP tuning caps it at 15 fps (
frame_rate=15inisp_sc3332.conf). The sensor can do 25. Raising it means editing that binary config. - Clock: busybox
ntpdsyncs the time at boot and the RTC is written a minute later. Without internet, the time comes from the RTC, which may be wrong. - No hardware watchdog is fed (the Tuya app did that). Not needed so far.
- ONVIF: busybox on this rootfs has no
httpd, sostart_onvif.shexpects one at/data/onvif/httpd(for example a static busybox), in addition to the onvif_simple_server binaries. - Space: APP is 2848K of 2944K. New features should go on
/data(≈2 MB) or the SD card. - Vendor recovery paths don't work and aren't used: rootfs
system_recover.shonly runs when APP is missing, but the SD drivers it needs are in APP. U-Boot'sht_recover_fw.confhas an undocumented format.
8. Build settings (environment variables for variants/rtsp.sh)
| Var | Default | Effect |
|---|---|---|
WIFI_SSID, WIFI_PSK |
required | baked default network; WIFI_SSID= (empty) = none, configure through SD wifi.txt |
ROOT_PW |
anyka |
root password (SSH and serial passwd) |
RTSP_USER, RTSP_PASS |
admin, $ROOT_PW |
RTSP and ONVIF login; RTSP_USER= disables auth |
MAIN_W, MAIN_H, MAIN_FPS, MAIN_KBPS, MAIN_CODEC |
2304, 1296, 15, 8000, h.264 | main stream; h.265 is supported by the encoder, driver and RTSP library |
ION_MB |
24 | video memory reserved in the DTB |
PREBUILT_RTSP |
0 | 1 = original SDK binary (no auth, no recording) |
REC_MODE, REC_STREAM |
both, 0 | recording mode, recorded stream |
REC_CONT_PERCENT, REC_MOTION_PERCENT |
70, 25 | how the card is split (all [record] keys: GUIDE.md §6a) |
TIMEZONE |
UTC0 |
POSIX TZ string |