Skip to content
themactepPublic

About

Linux CLI app for CH341A and EZP flash chip programmers. A part of Thingino family.

Resources

Stars

16 stars

Watchers

1 watching

Forks

Repository files navigation

Scriba

A command-line flash programming tool for IP camera chips. Scriba reads, writes, erases, and verifies SPI NOR, SPI NAND, and EEPROM memory using inexpensive USB programmers. Built for the Thingino firmware project.

Current version: 1.1.0 — see CHANGELOG.md.

Quick Start

# Build
git clone https://github.com/themactep/scriba.git && cd scriba
make && sudo make install

# Identify the flash chip
scriba -i

# Show the version
scriba -V

# Save a backup
scriba -R backup.bin

# Write new firmware
scriba -W firmware.bin

Supported Programmers

Scriba auto-detects the connected programmer — no configuration needed.

Programmer VID:PID
CH341A (black PCB) 1a86:5512 Must be modified for 3.3 V; see CH341A guide
EZP2019 / EZP2019+ 1fc8:310b / 310c Works out of the box
EZP2023 1fc8:310d
CH347T / CH347F 1a86:55db / 55de Put a CH347T board in mode 1 (UART + SPI + I2C). SPI flash and SPI EEPROM only, no I2C or Microwire EEPROM yet. Hardware SPI clock, 15 MHz by default
serprog over TCP network A thingino backpack, or any serprog programmer reachable over TCP: --host. SPI NOR flash and SPI EEPROM

Force a specific programmer with -P:

scriba -P ch341a -i
scriba -P ch347 -i
scriba -P ezp2019 -i
scriba -P serprog --host 192.0.2.10 -i

With more than one supported programmer connected, auto-detect lists them and asks which one to use; -P skips the question. Only the programmer wired to the chip can detect it.

Check the flash supply voltage. Winbond ...FW and ...JW parts are 1.8 V and need level shifting on a 3.3 V CH341A. A marginal clip or a voltage mismatch shows up as sporadic bit flips in repeated reads; use -R (or Read twice in the web version) to catch it before trusting a dump.

Set the CH347 SPI clock with --spi-speed <kHz>. It picks the fastest of 60, 30, 15, 7.5, 3.75, 1.875, 0.9375 or 0.46875 MHz that does not exceed the request; use a lower clock for long clip leads or in-circuit reads:

scriba -P ch347 --spi-speed 30000 -R backup.bin

On CH347T firmware 0341 or newer (and any CH347F), scriba carries chip-select inside the SPI data frames, as WCH's own Linux driver does, which saves USB round trips on every flash command. --no-cs-flags uses separate chip-select commands instead. In the web version, the clock selector and Fast CS appear once a CH347 is connected.

Over the network: serprog

--host reaches a programmer that speaks flashrom's serprog protocol over TCP, such as a thingino backpack with a clip on the camera's flash. The port defaults to 8888; host names, .local names and IPv6 addresses work:

scriba --host thingino-backpack-xxxx.local -i
scriba --host 192.0.2.10:8888 -R backup.bin
scriba --host '[2001:db8::10]' --spi-speed 8000 -W firmware.bin

The programmer takes the chip when scriba connects and lets go of it when scriba exits: a backpack powers the chip, or parks the camera in its bootrom, as its status page is set. If it cannot, scriba says so and stops.

Every SPI transaction is a network round trip. A thingino backpack programs runs of pages itself, with its own command for it, so a whole 16 MB chip erases, writes and verifies in under three minutes over Wi-Fi. Other serprog programmers get the plain path, about 7 KB/s over Wi-Fi; blank pages are skipped either way. SPI NAND is not supported over serprog yet; use --nor or a USB programmer. The Windows build is USB-only; serprog needs POSIX sockets.

Build & Install

Prerequisites: GCC, libusb-1.0 development files, make

make              # dynamic linking (needs libusb-1.0 installed)
make STATIC_LIBUSB=yes  # link the bundled libusb, no system libusb needed
make static       # fully static executable (Linux/MinGW)
sudo make install # installs binary + udev rules, reloads udev

make install copies the udev rules for every supported programmer and reloads them. If your programmer was already plugged in, unplug and replug it after installation.

Web Version (WebUSB / WASM)

Scriba also runs in the browser via WebAssembly and WebUSB — no driver installation needed. Requires a Chromium-based browser (Chrome, Edge, Opera).

Read twice reads the chip a second time and saves the dump only if both reads match, as -R does on the command line. Trim 0xFF tail saves a read only up to its last data byte, as flash_dump_trimmed.bin; writing that back loses nothing, because Write erases the whole chip first. Every saved read ends with its SHA-256 in the log. The Partitions card shows the layout of a read or a loaded image, with where the data ends; blank partitions are dimmed. The CH347 clock selector and Fast CS appear once a CH347 is connected.

A thingino backpack over the network. In Settings (the gear), choose thingino backpack and enter its address, e.g. thingino-backpack-xxxx.local or its IP; Connect Backpack then works like a USB programmer. A browser cannot open a TCP socket, so the page sends the serprog commands to the backpack's POST /api/spi (thingino-backpack 0.4.0 or later), one request each, and reads the answers from the response. The backpack serves it only to scriba's own page (and pages on the operator's own machine), lends the chip on the first request and gives it back a few seconds after the last. Chrome asks once to allow access to the local network: the page is HTTPS and the backpack plain HTTP on the LAN. As with --host: SPI NOR only, the camera off or parkable, and the backpack's own SPI clock.

Build

make web          # builds web/public/wasm/scriba.js and scriba.wasm

The first build initialises the emsdk submodule and installs Emscripten.

Prerequisites: Node.js 20.19+ for the frontend (nvm use in web/); Emscripten is fetched by the build.

Development

cd web
npm ci
npm run dev      # starts Vite dev server on http://localhost:5173

Vite serves static files from web/ including web/public/wasm/ where the Emscripten build places its output. After make web, just reload the browser.

Production

cd web
npm run build    # outputs to web/dist/

Serve the web/dist/ directory with any static file server.

Usage

scriba [options]

Automation:
  -R <file>    Read chip twice and compare — reliable backup
  -W <file>    Erase + write + verify — safe flash

Operations:
  -i           Read chip ID
  -e           Erase chip
  -r <file>    Read chip to file
  -w <file>    Write file to chip
  -v           Verify after write (use with -w)

Options:
  -a <addr>    Start address (hex or decimal)
  -l <bytes>   Length in bytes
  -L           List all supported chips

SPI NAND:
  -d           Disable on-die ECC
  -o <bytes>   Set OOB size (64–256)
  -I           Ignore ECC errors during read
  -k           Skip bad pages

EEPROM:
  -E <chip>    EEPROM type, e.g. 24c32, 93c46, 25q64
  -8           8-bit organization (Microwire)
  -f <bits>    Address size (Microwire)
  -s <bytes>   Page size (SPI EEPROM)

General:
  -P <prog>    Programmer: ch341a, ch347, ezp2019, serprog, auto (default)
  --host <host[:port]>  serprog over TCP, e.g. a thingino backpack (port 8888)
  --spi-speed <kHz>  SPI clock limit (CH347 and serprog; CH347 default 15000)
  --no-cs-flags      CH347: separate chip-select commands
  --nor        Probe SPI NOR only (default: NOR, then NAND)
  --nand       Probe SPI NAND only
  --layout <file>  Show the partitions of an image file (no programmer)
  --debug      USB debug output
  --trace      Dump all SPI traffic
  -V           Print version
  -h           Help

Detection probes SPI NOR first, then SPI NAND. Pin the protocol with --nor or --nand (one at a time) when a part is reported as the wrong kind, or when you know what is in the socket.

Partition layout

SPI NOR flash in cameras carries no partition table, so scriba works the layout out from the image: names and boundaries from an mtdparts= string (preferring one in a U-Boot environment whose CRC checks out), and each partition's contents from its headers: Ingenic and SigmaStar boot images, U-Boot environment, uImage, FIT/device tree, squashfs, JFFS2, UBI. With no mtdparts= string the headers alone give the boundaries. The CLI prints the layout after a whole-chip read, and for any image file with --layout <file>:

Layout from mtdparts (jz_sfc) in the U-Boot env at 0x050000:
  0x000000-0x04FFFF  320 KB boot   Ingenic boot image (SPL + U-Boot), 186 KB used
  0x050000-0x05FFFF   64 KB env    U-Boot env (32 KB, CRC OK, 26 variables)
  0x060000-0x06FFFF   64 KB backup blank
  0x070000-0x1FFFFF 1600 KB kernel uImage "Linux-3.10.14__isvp_swan_1.0__" (kernel, lzma), 1.37 MB
  0x200000-0x7BFFFF 5888 KB rootfs squashfs 4.0 (xz), 5.72 MB used
  0x7C0000-0xFFFFFF 8448 KB data   JFFS2, 1 of 132 erase blocks in use

It also notes images that are not raw flash images (vendor upgrade packages), layouts larger than the chip, and dumps that end inside the layout.

Examples

# Identify the chip
scriba -i

# Reliable backup — reads twice, compares, saves if identical
scriba -R backup.bin

# Safe flash — erases, writes, then verifies
scriba -W firmware.bin

# Partition layout of a dump or firmware image
scriba --layout dump.bin

# Single operations
scriba -r dump.bin -a 0 -l 0x400000    # read 4 MB from offset 0
scriba -w bootloader.bin -v            # write and verify
scriba -e                              # full chip erase

# Debugging
scriba --debug -i                      # see USB communication
scriba --trace -r dump.bin             # dump every SPI byte

# Pin the flash protocol
scriba --nor -i                        # probe SPI NOR only
scriba --nand -R backup.bin            # probe SPI NAND only

# EEPROM
scriba -E 93c46 -r eeprom.bin
scriba -E 24c32 -w eeprom.bin

Testing

make
./test.sh                                    # CLI tests, no hardware needed
SCRIBA_HW=1 SCRIBA_HW_PROG=ch341a ./test.sh  # + identify and a 4 KB read

The hardware pass is read-only: it identifies the chip and reads the first 4 KB. Use SCRIBA_HW_PROG to pick the programmer when more than one is connected.

Versioning

Scriba uses Semantic Versioning. The canonical version is the top-level VERSION file; make injects it into the CLI and WASM builds as SCRIBA_VERSION.

make version      # print the version
scriba -V         # print the version of a built binary

Release history is in CHANGELOG.md; releases are tagged vX.Y.Z.


Scriba began as a streamlined fork of SNANDer by McMCC, later modified by Droid-MAX, and has since been heavily reworked by Paul Philippov with EZP2019 support, code optimizations, and structural improvements.

About

Linux CLI app for CH341A and EZP flash chip programmers. A part of Thingino family.

Resources

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages