@@ -70,19 +70,50 @@ papyrix-flasher version
7070
7171The Xteink X4 has 16MB of flash memory, organized as:
7272
73- | Region | Address | Size | Description |
74- | --------| ---------| ------| -------------|
75- | Bootloader | 0x0000 | ~ 12KB | ESP32-C3 second-stage bootloader |
76- | Partitions | 0x8000 | 3KB | Partition table |
77- | App (OTA 0) | 0x10000 | ~ 6.3MB | Main application |
78- | App (OTA 1) | 0x650000 | ~ 6.3MB | OTA update partition |
79- | SPIFFS | 0xC90000 | ~ 3.3MB | File storage |
73+ - ** Bootloader** at ` 0x0000 ` (~ 12KB) - ESP32-C3 second-stage bootloader
74+ - ** Partitions** at ` 0x8000 ` (3KB) - Partition table
75+ - ** App (OTA 0)** at ` 0x10000 ` (~ 6.3MB) - Main application
76+ - ** App (OTA 1)** at ` 0x650000 ` (~ 6.3MB) - OTA update partition
77+ - ** SPIFFS** at ` 0xC90000 ` (~ 3.3MB) - File storage
8078
8179By default, ` papyrix-flasher ` writes to:
8280- Bootloader at 0x0000 (embedded in tool)
8381- Partition table at 0x8000 (embedded in tool)
8482- Firmware at 0x10000 (your file)
8583
84+ ## How It Works
85+
86+ This tool implements the ESP32 ROM bootloader protocol to flash firmware over a USB serial connection.
87+
88+ ### Communication Stack
89+
90+ - ** Serial** : 921600 baud, 8N1, no flow control
91+ - ** Framing** : SLIP (Serial Line Internet Protocol) with ` 0xC0 ` delimiters and escape sequences for special bytes
92+ - ** Protocol** : ESP32 ROM bootloader binary protocol with request/response packets and XOR checksum
93+
94+ ### Bootloader Entry
95+
96+ The ESP32-C3 enters bootloader mode via DTR/RTS signal sequence that controls the EN (reset) and GPIO0 (boot mode) pins through transistor drivers:
97+
98+ 1 . Assert EN low (reset the chip)
99+ 2 . Assert GPIO0 low while releasing EN (boot into download mode)
100+ 3 . Release GPIO0 (chip stays in bootloader)
101+
102+ ### Flash Sequence
103+
104+ 1 . ** Reset to bootloader** - DTR/RTS signal sequence
105+ 2 . ** SYNC** - Establish communication with bootloader (up to 10 retries)
106+ 3 . ** SPI_ATTACH** - Attach the SPI flash chip
107+ 4 . ** SPI_SET_PARAMS** - Configure flash size (16MB)
108+ 5 . ** FLASH_DEFL_BEGIN** - Start compressed flash session, erase sectors
109+ 6 . ** FLASH_DEFL_DATA** - Send zlib-compressed firmware in 1KB blocks (with retry on failure)
110+ 7 . ** FLASH_DEFL_END** - Finalize flash session
111+ 8 . ** Hard reset** - Reboot into the new firmware
112+
113+ ### Compression
114+
115+ Firmware is compressed using zlib (deflate) before transfer. The bootloader decompresses data on-the-fly, reducing transfer time significantly (typically 2-4x compression ratio).
116+
86117## Troubleshooting
87118
88119### Device not detected
@@ -119,7 +150,14 @@ papyrix-flasher/
119150├── cmd/papyrix-flasher/ # CLI entry point
120151├── internal/
121152│ ├── slip/ # SLIP protocol encoding/decoding
153+ │ │ ├── slip.go
154+ │ │ └── slip_test.go
122155│ ├── protocol/ # ESP32 bootloader protocol
156+ │ │ ├── commands.go
157+ │ │ ├── commands_test.go
158+ │ │ ├── packet.go
159+ │ │ ├── packet_test.go
160+ │ │ └── esp32c3.go
123161│ ├── serial/ # Serial port abstraction
124162│ ├── detect/ # Device auto-detection
125163│ └── flasher/ # High-level flash operations
@@ -137,13 +175,27 @@ make build
137175# Build for all platforms
138176make build-all
139177
140- # Run tests
141- make test
142-
143178# Update embedded binaries from papyrix-reader
144179make update-embedded
145180```
146181
182+ ### Testing
183+
184+ ``` bash
185+ # Run all tests
186+ make test
187+
188+ # Run tests with verbose output
189+ go test -v ./...
190+
191+ # Run tests for specific packages
192+ go test -v ./internal/slip ./internal/protocol
193+ ```
194+
195+ Unit tests cover the core protocol packages:
196+ - ** slip** : SLIP framing encode/decode, escape sequences, frame extraction
197+ - ** protocol** : Packet encoding/decoding, checksum calculation, command data generation
198+
147199## References
148200
149201- [ Espressif esptool documentation] ( https://docs.espressif.com/projects/esptool/en/latest/ )
0 commit comments