JianyuWang0623 opened a new pull request, #3946:
URL: https://github.com/apache/nuttx-apps/pull/3946
## Summary
1. Zero the fastboot context at initialization, so an `upload` issued
without a prior staging command can't invoke a garbage leftover function
pointer with a garbage leftover size.
2. Export `fastboot_handler()` (already present in this tree) via a new
`include/system/fastboot.h`, since it had no public prototype.
3. Track the sparse output offset per `download`+`flash` round-trip instead
of carrying it across calls. Each chunk already locates itself via its own
leading `DONT_CARE`:
- Aligned image, trailing gap present: `seg1 = [RAW 0..9][DONT_CARE
9..N]` ends at offset `N`, which happened to reset the old carried state; `seg2
= [DONT_CARE 0..9][RAW 9..18]` then lands correctly at offset 9.
- Unaligned image, host drops the trailing gap: `seg1 = [RAW 0..9]` ends
at offset `9 < N`, so the old code *kept* that offset; `seg2`'s own `DONT_CARE`
then added on top of it, landing RAW at offset 18 instead of 9 — silent
corruption.
This also drops keeping the flash fd open across segments; the target is
now opened/closed per `flash`, with no measurable cost (X = this patch, Y = fd
kept across segments):
| Storage | Image | X: open/close per flash | Y: fd kept across segs | X
- Y |
| --- | --- | --- | --- | --- |
| eMMC | unaligned 16M | 2.330 s | 2.659 s | -0.33 s |
| eMMC | aligned 16M | 2.430 s | 2.481 s | -0.05 s |
| NOR flash | unaligned 7.2M | 195.26 s | 195.35 s | -0.09 s |
4. Open the flash target with `O_DIRECT`, intended to bypass caching on
drivers that honor this flag.
## Impact
- (1) and (3) are bug fixes, no API change; (3) fixes silent data corruption
when flashing a multi-chunk sparse image.
- (2) only adds a header, no behavior change.
- (4) is a no-op on the BCH/MTD path tested here; it only matters on drivers
that honor `O_DIRECT` (SPIFFS, 9P, FTL), which were not tested.
## Testing
`tools/checkpatch.sh -c -u -m -g origin/master..HEAD` on all 4 commits: all
checks pass.
**`sim:nsh`**, apps `9c67ba071` against `apache/nuttx` master `3122150b`.
Host: native x86_64 Linux (compiler version not captured in this pass).
- Serial, TCP: build and daemon start up cleanly.
- `filedump`/`upload` (offset+size, negative offset, malformed args):
byte-exact.
- Sparse offset bug: reproduced before this patch (RAW chunk landed at block
18 instead of 9) and confirmed fixed after (lands at block 9), using the
"unaligned, host drops the trailing gap" scenario above on a `mkrd` ramdisk
target.
- USB: not exercised, sim has no USB device controller.
**`lckfb-szpi-esp32s3:fastboot`** (ESP32-S3 real board), apps `9c67ba071`
against `apache/nuttx` master `7505b874722`. Host: Ubuntu 22.04.5 LTS x86_64,
`xtensa-esp32s3-elf-gcc` 12.2.0. Flash target is a real SPI NOR partition
exposed as a raw MTD block device (not a ramdisk).
- USB: `getvar`/`flash` (sparse and non-sparse) byte-exact on read-back.
- TCP (WiFi): three `getvar` commands back-to-back on the same connection,
all `OKAY`.
- Serial (UART0): `getvar` and short `filedump` round-trips passed; larger
multi-KB `download`/`flash`/`upload` transfers over this transport were not
exercised in this pass.
- `O_DIRECT`: aligned and non-aligned-size writes to the real partition,
with and without the flag — no `EINVAL`, no corruption, no observable
difference either way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]