Docs: serial + SD backup, restore and flashing reference
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>
This commit is contained in:
@@ -76,7 +76,14 @@ flashrom -p ch341a_spi -r dump2.bin
|
|||||||
cmp dump1.bin dump2.bin && cp dump1.bin camera_flash.bin # the two reads must be identical
|
cmp dump1.bin dump2.bin && cp dump1.bin camera_flash.bin # the two reads must be identical
|
||||||
```
|
```
|
||||||
|
|
||||||
**Without a programmer:** boot to a root shell over serial (README.md §2: `init=/bin/sh`
|
**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:
|
plus the mounts shown there), then copy every partition to the SD card:
|
||||||
```sh
|
```sh
|
||||||
insmod /usr/modules/mmc_core.ko; insmod /usr/modules/mmc_block.ko; insmod /usr/modules/ak_mci.ko
|
insmod /usr/modules/mmc_core.ko; insmod /usr/modules/mmc_block.ko; insmod /usr/modules/ak_mci.ko
|
||||||
@@ -372,6 +379,9 @@ The first install (§5) must have set the new `bootcmd`.
|
|||||||
- **Serial + SD:** copy your `camera_flash.bin` to the card. At `=>`:
|
- **Serial + SD:** copy your `camera_flash.bin` to 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`.
|
`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.
|
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.bin` from §5a is a complete image. Write
|
||||||
|
it with a programmer, or put it on the card and use the serial command above.
|
||||||
|
|
||||||
## 10. Troubleshooting
|
## 10. Troubleshooting
|
||||||
|
|
||||||
@@ -391,6 +401,123 @@ The first install (§5) must have set the new `bootcmd`.
|
|||||||
| Bad settings, stream won't start | `camcfg reset` (or `camcfg unset KEY`); check `/tmp/rtsp.log` |
|
| 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 |
|
| 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):
|
||||||
|
```sh
|
||||||
|
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 report `Total of 8388608 byte(s) were the same`.
|
||||||
|
- Write down the `crc32` value.
|
||||||
|
- The second `cmp.b` must also be all the same. That one proves the card write.
|
||||||
|
|
||||||
|
On the PC:
|
||||||
|
```sh
|
||||||
|
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:
|
||||||
|
```sh
|
||||||
|
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 `crc32` matches the image's value **before** `sf update`.
|
||||||
|
- `sf update` only 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.bin` to the FAT partition, then
|
||||||
|
`fatload mmc 0:1 0x82000000 camera_flash.bin` replaces the `mmc read` line.
|
||||||
|
|
||||||
|
**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
|
## Credits
|
||||||
|
|
||||||
The Anyka SDK runtime and RTSP sample come from the public `Link-WQS/ANYKA_130L_SDK`. The
|
The Anyka SDK runtime and RTSP sample come from the public `Link-WQS/ANYKA_130L_SDK`. The
|
||||||
|
|||||||
Reference in New Issue
Block a user