U-Boot has no fatwrite, so full-flash backups go to a raw slot on the card (mmc write at block 0x400000, past a 1 GiB FAT32 partition) with double reads, cmp.b and crc32 checks. Restore with sf update or the classic mmc read + sf erase + sf write, plus single-partition flashing from FAT files. Cross-referenced from the backup and restore sections. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
27 KiB
Guide: local RTSP firmware for AK3918AV130 / SC3332 Tuya cameras
This turns a cheap Tuya "2K" Wi-Fi camera into a local-only camera: no cloud and no app. You get a password-protected RTSP stream at the sensor's full 2304×1296, continuous and motion recording to the SD card, SSH access, Wi-Fi settings you can change without reflashing, and firmware updates over Wi-Fi or from an SD card.
You may not have to open the camera at all: a stock camera can be installed from the SD card alone (§5a). Otherwise you open it once, for the first install. After that, every update and recovery happens over Wi-Fi or the SD card slot.
Status: RTSP, Wi-Fi, SSH and repartitioning are confirmed on hardware. Full resolution (24 MB ION heap), RTSP auth, over-the-air updates, the SD updater,
wifi-set/wifi.txtand SD recording are built but not yet confirmed on a device. The recorder's file writing, rotation, size limits and motion pre-roll were checked in a host simulation (all output decodes with ffmpeg). Motion detection itself only runs on the camera. Report back if you try them. What's in the image, file by file: IMAGE_CONTENTS.md.
0. Does this apply to my camera?
Known camera: this was developed on the LSC Smart Connect outdoor camera ("Inteligentná vonkajšia kamera LSC Smart Connect") sold by Action, article 3225728: https://www.action.com/sk-sk/p/3225728/inteligentna-vonkajsia-kamera-lsc-smart-connect/. Listed specs: "2K" image quality, app-controlled, Wi-Fi 2.4 GHz and 5 GHz, mains powered, 25.95 € (at the time of writing). The "2K" is real: the sensor is an SC3332 with 2304×1296 native resolution, which this firmware streams in full. Only 2.4 GHz Wi-Fi has been confirmed with this firmware so far; 5 GHz is untested. Other Tuya/LSC cameras with the same board may work too, but check the table below, because retailers change the hardware inside without renaming the product.
All of the following must be true. Check them in the serial boot log (§2):
| Check | Expected |
|---|---|
| U-Boot banner | U-Boot 2019.10.0-V4.0.27, Model: EVB_CBD_AK3918AV130 |
| Flash | SF: Detected ZB25VQ64 … total 8 MiB |
| RAM | DRAM: 64 MiB |
| Kernel | Linux version 4.4.302-cip94 |
| Sensor | sc3332 Probed success |
| Wi-Fi | ATBM6x6x (USB) |
A different sensor, flash size or kernel means stop. The modules and libraries won't match.
1. What you need
- A Linux PC with
squashfs-tools,mtd-utils,device-tree-compiler(fdtput/fdtdump),openssl,python3. Addflashromif you use a programmer. - A 3.3 V USB-serial adapter (no 5 V!), connected to the board's TX/RX/GND pads at 115200 8N1. Needed for the first install.
- Optional: a CH341A programmer with a SOIC-8 clip, for the easiest backup and restore.
- A microSD card, FAT32.
- This repository (the
toolkit/directory).
2. Open it, connect serial, stop U-Boot
- Open the case and find the UART pads (usually labelled TX/RX/GND near the SoC). Connect adapter RX→board TX and TX→board RX, plus GND. Don't connect VCC.
picocom -b 115200 /dev/ttyUSB0(or screen or minicom), then power the camera.- Press Ctrl+C repeatedly while it boots until you get the
=>prompt. - Run
printenvand save the output. You'll want your originalmtdpartsandbootcmd.
3. Back up your flash (mandatory)
Your backup is the only way back to stock, and the build uses your own device-specific partitions (Tuya keys, MAC address). Never use someone else's dump.
With a programmer (camera unpowered, clip on the flash chip):
flashrom -p ch341a_spi -r dump1.bin
flashrom -p ch341a_spi -r dump2.bin
cmp dump1.bin dump2.bin && cp dump1.bin camera_flash.bin # the two reads must be identical
Serial only, from the U-Boot prompt (works even if Linux won't boot): read the whole flash
into RAM twice, compare, and write it raw to the SD card. Then copy it off with dd on a PC.
Exact commands: §11.1.
No programmer and no serial: use the SD-only install with backup (§5a). It saves the complete 8 MiB to the card automatically before changing anything.
Serial, from a Linux root shell: boot to a root shell over serial (README.md §2: init=/bin/sh
plus the mounts shown there), then copy every partition to the SD card:
insmod /usr/modules/mmc_core.ko; insmod /usr/modules/mmc_block.ko; insmod /usr/modules/ak_mci.ko
mount -t vfat /dev/mmcblk0p1 /mnt || mount -t vfat /dev/mmcblk0 /mnt
for i in 0 1 2 3 4 5 6 7; do cat /dev/mtd$i > /mnt/mtd$i.bin; done; sync; umount /mnt
On the PC, join them in order: cat mtd0.bin mtd1.bin … mtd7.bin > camera_flash.bin.
The result must be exactly 8388608 bytes.
Keep camera_flash.bin somewhere safe.
4. Build your image
cd toolkit
./fetch-deps.sh # once: SDK libs, OpenIPC modules, toolchains
./build-deps.sh # once: mtdflash, dropbear, RTSP server (from source)
./split.sh ../camera_flash.bin parts/stock # carve your dump into partitions
WIFI_SSID='YourNetwork' WIFI_PSK='YourWifiPassword' \
ROOT_PW='choose-a-root-password' RTSP_PASS='choose-a-stream-password' \
./variants/rtsp.sh
- Output, collected in
sdcard/next totoolkit/(STAGE_DIR=to change). Every build refreshes all of them:full.bin: the whole 8 MiB chipapp.bin,dtb.bin,data.bin,env.bin,MD5SUMS: single partitionssd-install-backup/,sd-install-direct/: SD-card-only installs for stock cameras (§5a)
full.binalready has the right U-Boot settings (partition layout + SD-updatebootcmd) baked in, so flashing it whole needs no typing at the U-Boot prompt.- To leave Wi-Fi out of the image and set it from the SD card instead, use
WIFI_SSID=(empty) and see §7. - All build settings are listed in IMAGE_CONTENTS.md §8. Almost all of them can be changed
later over SSH with
camcfg(§6b), without rebuilding. - These files contain your passwords and your camera's keys. Don't share them.
5. First install
Pick one. All of them end in the same firmware and layout.
| Method | Needs | Writes | Backup of the original | Section |
|---|---|---|---|---|
| Programmer | CH341A + clip | whole chip (full.bin) |
your own dump (§3) | §5 |
| Serial + SD | UART adapter, SD card | DTB, APP, DATA + U-Boot settings typed by hand | your own dump (§3) | §5 |
| SD only, with backup | SD card | U-Boot writes an installer, which dumps the full 8 MiB to the card, then installs | full 8 MiB, made automatically | §5a |
| SD only, direct | SD card | U-Boot writes APP+DATA itself; first boot writes DTB + settings | everything except the original APP | §5a |
Already installed? Use updates (§8), never an install method again: they reset DATA.
With a programmer it's one command, with no serial and no U-Boot typing:
flashrom -p ch341a_spi -w sdcard/full.bin
full.bin also resets DATA to empty. That doesn't matter on a first install, but don't use it
later just to update: your camcfg settings and SSH host keys live there. Use §8 instead.
Without a programmer: copy app.bin, data.bin and dtb.bin from sdcard/ to the root of
the FAT32 card. Insert it, power on, stop at => (Ctrl+C), then:
mmc dev 0
fatls mmc 0
sf probe 0
fatload mmc 0 ${loadaddr} dtb.bin
sf erase 0x34000 0x10000
sf write ${loadaddr} 0x34000 ${filesize}
fatload mmc 0 ${loadaddr} app.bin
sf erase 0x300000 0x2e0000
sf write ${loadaddr} 0x300000 ${filesize}
fatload mmc 0 ${loadaddr} data.bin
sf erase 0x5e0000 0x220000
sf write ${loadaddr} 0x5e0000 ${filesize}
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),2944k@0x300000(APP),2176k@0x5e0000(DATA)'
setenv sdscript version
setenv bootcmd 'mmc dev 0; mw.b ${loadaddr} 0 0x1000; fatload mmc 0 ${loadaddr} camupdate.env; env import -t ${loadaddr} 0x1000; run sdscript; setenv sdscript version; run boot_normal'
saveenv
reset
Notes:
- If
fatls mmc 0shows nothing, the card has a partition table. Usemmc 0:1everywhere. - The new
bootcmdchecks the SD card for an update file before every boot. That's what makes recovery possible later without serial (§8). With no card, or no file, it just boots. - Writing only DTB, APP and DATA never touches U-Boot, so U-Boot always stays reachable.
Check it worked: watch the serial log. The camera should join Wi-Fi and print its IP.
You can also get a shell on the serial console and run cat /tmp/local_bootstrap.log.
You can close the case now.
5a. Install with only an SD card (stock camera, no opening, no serial)
The stock U-Boot has a hidden factory-recovery feature. At every power-on it looks for
ht_recover_fw.conf on a FAT32 SD card. If the file is valid and its build id is new, it
writes the firmware next to it into flash, then boots. The build makes two ready-to-copy sets:
sd-install-backup/ (recommended) |
sd-install-direct/ |
|
|---|---|---|
| U-Boot writes | a temporary installer rootfs (1 MiB) | the final APP + DATA (5 MiB) |
| Then | the installer, with the original APP still intact, dumps all 8 MiB to the card, then writes APP+DATA, DTB, the stock rootfs and the U-Boot settings, and reboots | the new firmware's first boot backs up the rest, writes DTB + U-Boot settings, and reboots |
| Backup on the card | original-backup/full.bin: the complete chip; restore stock with flashrom -w full.bin |
partitions except APP (the Tuya firmware is gone) |
| Most of the work done by | Linux (our installer) | U-Boot itself (fewest steps outside U-Boot) |
Steps (both):
- Format a microSD card as FAT32. Copy the contents of the chosen folder to its root.
For the backup variant that's
ht_recover_fw.conf,root.sqsh4and thecamerarev/folder; for direct,ht_recover_fw.confandusr.sqsh4. Card size: at least 64 MB (the backup needs 8 MiB). Optional: add awifi.txt(§7). - Insert it into the powered-off camera and power on. Wait about 5 minutes without cutting power. The camera reboots by itself when done.
- Find it in your router's DHCP list and continue with §6. Keep the card's
original-backup/folder somewhere safe: it has your camera's keys.
What to expect in detail (backup variant): about 20 s of U-Boot writing, then the installer:
- backup: about 30 s; writes
original-backup/with MD5SUMS and a README - check: verifies
camerarev/MD5SUMSand copies everything to RAM - write: about 2 minutes of flash writes, then a reboot
The log is in camerarev-install.log on the card. If anything is wrong (card not FAT32, a corrupt
file), it stops before writing anything and the camera stays stock. Fix the card and
power-cycle to retry.
Notes:
- Power loss: at any point before the very last step (the U-Boot settings), the next power-on simply runs the install again. An existing backup is kept, never overwritten.
- Leaving the card in is harmless: the install saves its build id, so U-Boot skips it from then on.
- Don't reuse an install set: don't put a newer
sd-install-*set on an installed camera. It would reinstall and reset DATA. For updates use §8. - Which dump the build needs: a dump of this camera model (§3–§4): yours, or one you
trust from an identical camera.
- Neither variant ever writes U-Boot, the kernel or CONFIG, so your device keys stay.
- The U-Boot settings come from the dump the build used (its unused MAC address included).
- The backup variant writes back the stock rootfs from that dump. Its
README.txtsays whether your U-Boot and kernel are identical to that dump, which tells you the rootfs infull.binmatches yours too.
- Check the model first: see §0. Without serial you can't see the boot log, so you're relying on the camera being the same model and firmware as the dump.
6. Using the camera
| What | How |
|---|---|
| Main stream (2304×1296) | rtsp://admin:<RTSP_PASS>@<camera-ip>/vs0 |
| Substream (640×360) | rtsp://admin:<RTSP_PASS>@<camera-ip>/vs1 |
| Shell | ssh root@<camera-ip> (password ROOT_PW) |
| Change any setting | camcfg (§6b) |
| Status at a glance | camcfg status |
| Change root password | camcfg password (or passwd) |
| Restart the stream | camcfg apply, or killall ak_rtsp_server_sample (it restarts in 5 s) |
| Edit any other read-only file permanently | rw /path/to/file, then edit it, then reboot |
| Logs | /tmp/local_bootstrap.log, /tmp/rtsp.log |
VLC, ffmpeg, Frigate, Home Assistant, Blue Iris and similar tools all work with these URLs. Find the IP in your router's DHCP list.
6b. Settings: camcfg
camcfg changes every setting over SSH: streams, login, recording, time and Wi-Fi. It checks
every value before saving, applies the change (the stream restarts in about 5–10 s), and keeps
ONVIF in sync. Your changes are stored separately from the firmware defaults
(/data/camcfg.conf), so they survive reboots and firmware updates, and new defaults from an
update still apply to everything you didn't change.
camcfg show # everything; * marks what you changed
camcfg show record # one section
camcfg get main.bitrate
camcfg set main.bitrate=6000 # several at once is fine:
camcfg set main.codec=h265 main.bitrate=4500 main.resolution=2304x1296
camcfg set rtsp.password=NewStreamPass
camcfg set record.continuous_percent=60 record.motion_percent=35
camcfg set system.timezone=CET-1CEST,M3.5.0,M10.5.0/3
camcfg unset main.bitrate # back to the firmware default
camcfg reset # drop all your changes
camcfg keys # every key and its allowed values
camcfg export # your changes as text (no password)
camcfg wifi "Network" "Password" now # = wifi-set (§7)
camcfg status # IP, Wi-Fi signal, stream, recorder, SD usage
Add -n after the command (camcfg set -n …) to save without restarting the stream.
If any value is invalid, nothing is saved.
To copy settings to another camera:
ssh root@cam1 camcfg export | grep -v '^#' | xargs ssh root@cam2 camcfg set.
| Key | Values | Default |
|---|---|---|
main.codec / sub.codec |
h264, h265 (both supported by the hardware; check your player handles H.265) |
h264 |
main.resolution / sub.resolution |
WxH, multiples of 8, max 2304x1296 / 1280x720 |
2304x1296 / 640x360 |
main.bitrate / sub.bitrate |
kbps, 256–16000 / 64–4000 | 8000 / 400 |
main.fps / sub.fps |
1–25 (the stock ISP tuning caps it at 15) | 15 |
main.level / sub.level |
encoder level 10–62 (50 = 5.0) | 50 / 30 |
rtsp.user, rtsp.password |
stream and ONVIF login; empty user = no authentication | admin / root password at build |
rtsp.port |
1–65535 | 554 |
audio.code_type, audio.sample_rate |
aac/g711a/g711u, 8000/16000 |
aac, 16000 |
record.* |
all recording keys from §6a | see §6a |
system.timezone |
POSIX TZ: UTC0, CET-1CEST,M3.5.0,M10.5.0/3, EST5EDT,M3.2.0,M11.1.0, … |
UTC0 |
system.ntp |
NTP server | pool.ntp.org |
main.* is short for video0.* and sub.* for video1.*; bitrate, codec, level are
short for target_kbps, code_type, enc_level. The full names work too
(camcfg set video0.target_kbps=6000).
Rough guide for the main stream: H.264 6–8 Mbps, or H.265 4–5 Mbps, for good detail. Each viewer uses that much Wi-Fi.
6a. Recording to the SD card
With a FAT32 or exFAT card inserted, the camera records by default in two loops that share the card:
| Folder | What | Default share of the card |
|---|---|---|
rec/continuous/YYYYMMDD/HHMMSS.ts |
everything, 1-minute files; oldest deleted when full | 70% |
rec/motion/YYYYMMDD/HHMMSS.ts |
motion clips, starting 5 s before the motion and ending 10 s after it | 25% |
At least 200 MB always stays free. Files are MPEG-TS: VLC plays them directly, and
ffmpeg -i x.ts -c copy x.mp4 converts one without re-encoding. Copy them off with
scp root@<ip>:/mnt/sd/rec/motion/… or by reading the card on a PC.
Settings: camcfg set record.KEY=VALUE, e.g.
camcfg set record.mode=motion record.motion_sensitivity=70 (§6b).
Key (record.…) |
Meaning |
|---|---|
mode |
off, continuous, motion or both |
stream |
0 main (2304×1296, ~3.6 GB/hour at 8 Mbps H.264, ~2 GB/hour at 4.5 Mbps H.265), 1 substream (much smaller) |
continuous_percent, motion_percent |
the split: share of the card each loop may use |
continuous_max_mb, motion_max_mb |
fixed sizes instead (if > 0 they override the percent) |
continuous_path, motion_path |
where each loop writes. For two real partitions, create a 2nd partition on the card (mounted at /mnt/sd2) and set motion_path = /mnt/sd2/motion |
min_free_mb |
free space always kept |
segment_seconds |
length of continuous files |
motion_pre_seconds, motion_post_seconds, motion_clip_max_seconds |
how much before and after the motion each clip covers, and maximum clip length |
motion_sensitivity |
0–100 (higher = more sensitive) |
motion_threshold, motion_min_cells, motion_trigger_frames |
fine tuning: per-cell level, how many of the 32×24 grid cells must move, for how many checks in a row (10 checks per second) |
motion_debug |
1 logs the motion level every second in /tmp/rtsp.log, for tuning |
motion_hook |
a script called with start/stop on motion (default /data/motion_hook.sh, if it exists). Use it for MQTT or a webhook |
The current motion state is also in /tmp/motion (1 <time> or 0 <time>).
Build-time defaults: REC_MODE, REC_STREAM, REC_CONT_PERCENT, REC_MOTION_PERCENT.
Clock: recordings are named by date and time. The camera syncs time with NTP
(camcfg set system.ntp=…, default pool.ntp.org). The timezone is UTC unless you set it with
camcfg set system.timezone=CET-1CEST,M3.5.0,M10.5.0/3, or build with TIMEZONE=….
Not recorded yet: audio.
7. Change Wi-Fi without reflashing
Over SSH (while the camera is still online):
wifi-set "NewNetwork" "NewPassword" # used from the next boot
wifi-set "NewNetwork" "NewPassword" now # switch now (your SSH session will drop)
wifi-set --show # what's configured / connected
If the new network doesn't connect within about 40 s, the camera switches back to the previous one. At boot it tries the new network, then the previous one, then the network built into the image.
From the SD card (camera offline, new router, or no Wi-Fi was built in): create a file
wifi.txt on the card:
SSID=NewNetwork
PASSWORD=NewPassword
Insert the card and power-cycle. The camera saves the network, deletes wifi.txt (so the
password doesn't stay on the card) and leaves a wifi.txt.applied note.
8. Updating firmware (no serial)
Over Wi-Fi (normal case): rebuild (§4), then from toolkit/:
./ota.sh <camera-ip> parts/rtsp/app.bin # add parts/rtsp/dtb.bin etc. if changed
It uploads to the camera's RAM, checks the md5, and writes with read-back verification of every block. Then it reboots. It only writes blocks that changed, and it refuses to touch U-Boot.
From the SD card (if Linux no longer boots, e.g. after a bad APP):
./make-sd-update.sh /path/to/mounted/sdcard parts/rtsp/app.bin parts/rtsp/dtb.bin
Insert the card and power on. U-Boot flashes the images before Linux starts. After a good
boot, Linux renames camupdate.env to camupdate.done so the update doesn't run again.
The first install (§5) must have set the new bootcmd.
9. Restore stock
- Programmer:
flashrom -p ch341a_spi -w camera_flash.bin - Serial + SD: copy your
camera_flash.binto the card. At=>:mmc dev 0; fatload mmc 0 ${loadaddr} camera_flash.bin; sf probe 0; sf erase 0 0x800000; sf write ${loadaddr} 0 0x800000; reset. This rewrites U-Boot too, so don't cut power during it. - Serial + SD, raw backup from §11.1: restore it with §11.2.
- SD only, with backup:
original-backup/full.binfrom §5a is a complete image. Write it with a programmer, or put it on the card and use the serial command above.
10. Troubleshooting
| Symptom | Cause / fix |
|---|---|
Venc [0] Create DMA Pool failed in /tmp/rtsp.log |
The DTB with the 24 MB heap isn't flashed. Flash dtb.bin, or lower [video0] to 1920×1080 |
venc_adaper_ioctl … not found |
The stock venc module is loaded; APP from this build is missing |
wlan0 missing |
Wi-Fi modules failed to load (check /tmp/local_bootstrap.log) |
| Camera never joins Wi-Fi | Use SD wifi.txt (§7). 2.4 GHz is confirmed (5 GHz is advertised but untested); password must be 8–63 characters |
| Stream asks for a password you don't know | camcfg set rtsp.password=… over SSH (or rebuild with RTSP_PASS) |
| Frame rate stuck at 15 | The stock ISP tuning caps it (IMAGE_CONTENTS.md §7) |
| Nothing recorded | Card must be FAT32/exFAT. grep record /tmp/rtsp.log. The recorder refuses to write anywhere that isn't the card |
| Too many or too few motion clips | camcfg set record.motion_debug=1, watch the levels with tail -f /tmp/rtsp.log, then adjust record.motion_sensitivity or record.motion_threshold/record.motion_min_cells (and set motion_debug=0 again) |
SD too slow: queue full in the log |
Use a faster card (U1/V10 or better), or record the substream |
| Recording times are wrong | No NTP yet (no internet?), or set the timezone (§6a) |
| SSH unreachable and Wi-Fi fine | Serial shell → cat /tmp/local_bootstrap.log; or SD update (§8) |
| Bad settings, stream won't start | camcfg reset (or camcfg unset KEY); check /tmp/rtsp.log |
| Boot loops after an update | SD update with known-good images (§8); last resort: serial + §5 |
11. Serial + SD card reference (U-Boot prompt)
Everything here runs at the => prompt (§2) and needs no working Linux. That makes it the
fallback for any camera whose U-Boot still starts. Commands available in this U-Boot:
mmc read/write, fatload, fatls, sf probe/read/write/erase/update, cmp, crc32.
It has no fatwrite, so backups go to a raw area of the card instead of a file.
These commands are taken from this U-Boot's own command list and the layout above, but
haven't been run on a camera yet. Read the output of each step before the next.
Prepare a card once (any card of 4 GB or more; this erases it). On a Linux PC, where
/dev/sdX is the card (check with lsblk, because a wrong device is destroyed):
sudo parted -s /dev/sdX mklabel msdos mkpart primary fat32 1MiB 1GiB
sudo mkfs.vfat -F 32 /dev/sdX1
That gives you a normal 1 GiB FAT32 partition for files (mmc 0:1 in U-Boot) and leaves the
space from 2 GiB on unused. That free space is the raw backup slot: block 0x400000,
0x4000 blocks of 512 bytes = 8 MiB.
RAM buffers used below: 0x80008000 (${loadaddr}) and 0x82000000. Both have room for
8 MiB clear of U-Boot and its device tree.
11.1 Back up the whole flash to the card
sf probe 0
sf read 0x80008000 0 0x800000
sf read 0x82000000 0 0x800000
cmp.b 0x80008000 0x82000000 0x800000
crc32 0x80008000 0x800000
mmc dev 0
mmc write 0x80008000 0x400000 0x4000
mmc read 0x82000000 0x400000 0x4000
cmp.b 0x80008000 0x82000000 0x800000
- The first
cmp.b, of two flash reads, must reportTotal of 8388608 byte(s) were the same. - Write down the
crc32value. - The second
cmp.bmust also be all the same. That one proves the card write.
On the PC:
sudo dd if=/dev/sdX of=camera_flash.bin bs=512 skip=$((0x400000)) count=$((0x4000))
python3 -c "import zlib,sys; print('%08x' % zlib.crc32(open(sys.argv[1],'rb').read()))" camera_flash.bin
The printed value must equal U-Boot's crc32.
11.2 Restore the whole flash from the card
On the PC, put the image in the raw slot:
sudo dd if=camera_flash.bin of=/dev/sdX bs=512 seek=$((0x400000)) conv=fsync
At =>:
mmc dev 0
mmc read 0x82000000 0x400000 0x4000
crc32 0x82000000 0x800000
sf probe 0
sf update 0x82000000 0 0x800000
sf read 0x80008000 0 0x800000
cmp.b 0x80008000 0x82000000 0x800000
reset
- Check that
crc32matches the image's value beforesf update. sf updateonly rewrites sectors that differ, which is faster and leaves the U-Boot sectors alone if they're unchanged. Don't cut power while it runs: if U-Boot itself is being rewritten, an interrupted write needs a programmer.- A file works too: copy
camera_flash.binto the FAT partition, thenfatload mmc 0:1 0x82000000 camera_flash.binreplaces themmc readline.
The same with mmc read + sf erase + sf write (the classic sequence; it writes
every sector, so it's slower than sf update, but it's the simplest to reason about):
mmc dev 0
mmc read 0x82000000 0x400000 0x4000
crc32 0x82000000 0x800000
sf probe 0
sf erase 0 0x800000
sf write 0x82000000 0 0x800000
sf read 0x80008000 0 0x800000
cmp.b 0x80008000 0x82000000 0x800000
reset
sf write can only clear bits, so the sf erase of the same range must come first. Erase
and write sizes must be multiples of the 4 KiB erase block (0x800000 is). Between
sf erase and the end of sf write, the camera has no U-Boot, so a power cut there
needs a programmer.
Single partition from the raw slot: add the partition offset in 512-byte blocks to the slot. Example, only APP, from a full image in the raw slot (stock layout, APP = 0x300000):
mmc read 0x82000000 0x401800 0x2800
sf erase 0x300000 0x500000
sf write 0x82000000 0x300000 0x500000
0x401800 = 0x400000 + 0x300000/512; 0x2800 blocks = 5 MiB.
11.3 Flash single partitions from files on the card
Copy the files from sdcard/ to the FAT partition. Use mmc 0:1 with the card prepared
above; use mmc 0 for a card formatted without a partition table. Then for each file:
mmc dev 0
sf probe 0
fatload mmc 0:1 ${loadaddr} app.bin
sf update ${loadaddr} 0x300000 ${filesize}
| File | Offset | Slot |
|---|---|---|
dtb.bin |
0x34000 |
64K |
kernel.bin |
0x44000 |
1536K |
rootfs.bin |
0x1c4000 |
1008K |
app.bin |
0x300000 |
2944K (this firmware's layout) |
data.bin |
0x5e0000 |
2176K |
env.bin |
0x32000 |
4K (also write it at 0x33000, ENVBK) |
sf update erases as needed, so no separate sf erase is needed. ${filesize} is set by
fatload; check it matches the file before writing. Writing env.bin replaces the U-Boot
settings with the build's (layout, SD updater, build id). Run reset when done.
Credits
The Anyka SDK runtime and RTSP sample come from the public Link-WQS/ANYKA_130L_SDK. The
venc kernel modules come from OpenIPC anyka-osdrv. Bootlin toolchains; dropbear.