File tree Expand file tree Collapse file tree 6 files changed +69
-4
lines changed Expand file tree Collapse file tree 6 files changed +69
-4
lines changed Original file line number Diff line number Diff line change @@ -132,3 +132,6 @@ jobs:
132
132
133
133
- name : write-bin test
134
134
run : timeout 20 bash espflash/tests/scripts/write-bin.sh
135
+
136
+ - name : read-flash test
137
+ run : timeout 20 bash espflash/tests/scripts/read-flash.sh
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
34
34
- Fix ` -s ` argument collision (#731 )
35
35
- ` address ` and ` size ` in ` erase-region ` have to be multiples of 4096 (#771 )
36
36
- Fixed typos in error variant names (#782 )
37
+ - Fix ` read-flash ` which didn't work with some lengths (#804 )
37
38
38
39
### Removed
39
40
Original file line number Diff line number Diff line change @@ -347,12 +347,35 @@ impl Connection {
347
347
result
348
348
}
349
349
350
+ /// Read the response from a serial port
351
+ pub fn read_flash_response ( & mut self ) -> Result < Option < CommandResponse > , Error > {
352
+ let mut response = Vec :: new ( ) ;
353
+
354
+ self . decoder . decode ( & mut self . serial , & mut response) ?;
355
+
356
+ if response. is_empty ( ) {
357
+ return Ok ( None ) ;
358
+ }
359
+ let value = CommandResponseValue :: Vector ( response. clone ( ) ) ;
360
+
361
+ let header = CommandResponse {
362
+ resp : 1_u8 ,
363
+ return_op : CommandType :: ReadFlash as u8 ,
364
+ return_length : response. len ( ) as u16 ,
365
+ value,
366
+ error : 0_u8 ,
367
+ status : 0_u8 ,
368
+ } ;
369
+
370
+ Ok ( Some ( header) )
371
+ }
372
+
350
373
/// Read the response from a serial port
351
374
pub fn read_response ( & mut self ) -> Result < Option < CommandResponse > , Error > {
352
375
match self . read ( 10 ) ? {
353
376
None => Ok ( None ) ,
354
377
Some ( response) => {
355
- // Here is what esptool does: https://github.com/espressif/esptool/blob/master /esptool/loader.py#L458
378
+ // Here is what esptool does: https://github.com/espressif/esptool/blob/81b2eaee261aed0d3d754e32c57959d6b235bfed /esptool/loader.py#L518
356
379
// from esptool: things are a bit weird here, bear with us
357
380
358
381
// We rely on the known and expected response sizes which should be fine for now
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ pub enum Error {
87
87
#[ diagnostic( code( espflash:: read_flash:: incorrect_digest_length) ) ]
88
88
IncorrectDigestLength ( usize ) ,
89
89
90
- #[ error( "Incorrect response from the sutb /ROM loader" ) ]
90
+ #[ error( "Incorrect response from the stub /ROM loader" ) ]
91
91
#[ diagnostic( code( espflash:: read_flash:: incorrect_response) ) ]
92
92
IncorrectResponse ,
93
93
Original file line number Diff line number Diff line change @@ -1242,7 +1242,7 @@ impl Flasher {
1242
1242
} ) ?;
1243
1243
1244
1244
while data. len ( ) < size as usize {
1245
- let response = self . connection . read_response ( ) ?;
1245
+ let response = self . connection . read_flash_response ( ) ?;
1246
1246
let chunk: Vec < u8 > = if let Some ( response) = response {
1247
1247
response. value . try_into ( ) ?
1248
1248
} else {
@@ -1262,7 +1262,7 @@ impl Flasher {
1262
1262
return Err ( Error :: ReadMoreThanExpected ) ;
1263
1263
}
1264
1264
1265
- let response = self . connection . read_response ( ) ?;
1265
+ let response = self . connection . read_flash_response ( ) ?;
1266
1266
let digest: Vec < u8 > = if let Some ( response) = response {
1267
1267
response. value . try_into ( ) ?
1268
1268
} else {
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ KNOWN_PATTERN=$' \x01\xa0\x02\xB3\x04\xC4\x08\xD5\x10\xE6\x20\xF7\x40\x88\x50\x99 '
4
+ KNOWN_PATTERN+=$' \x60\xAA\x70\xBB\x80\xCC\x90\xDD\xA0\xEE\xB0\xFF\xC0\x11\xD0\x22 '
5
+ KNOWN_PATTERN+=$' \xE0\x33\xF0\x44\x05\x55\x15\x66\x25\x77\x35\x88\x45\x99\x55\xAA '
6
+ KNOWN_PATTERN+=$' \x65\xBB\x75\xCC\x85\xDD\x95\xEE\xA5\xFF\xB5\x00\xC5\x11\xD5\x22 '
7
+ KNOWN_PATTERN+=$' \xE5\x33\xF5\x44\x06\x55\x16\x66\x26\x77\x36\x88\x46\x99\x56\xAA '
8
+ KNOWN_PATTERN+=$' \x66\xBB\x76\xCC\x86\xDD\x96\xEE\xA6\xFF\xB6\x00\xC6\x11\xD6\x22 '
9
+
10
+ echo -ne " $KNOWN_PATTERN " > pattern.bin
11
+ result=$( espflash write-bin 0x0 pattern.bin 2>&1 )
12
+ echo " $result "
13
+ if [[ ! $result =~ " Binary successfully written to flash!" ]]; then
14
+ echo " Failed to write binary to flash"
15
+ exit 1
16
+ fi
17
+
18
+ lengths=(2 5 10 26 44 86)
19
+
20
+ for len in " ${lengths[@]} " ; do
21
+ echo " Testing read-flash with length: $len "
22
+
23
+ result=$( espflash read-flash 0 " $len " flash_content.bin 2>&1 )
24
+ echo " $result "
25
+ if [[ ! $result =~ " Flash content successfully read and written to" ]]; then
26
+ echo " Failed to read $len bytes from flash"
27
+ exit 1
28
+ fi
29
+
30
+ EXPECTED=$( echo -ne " $KNOWN_PATTERN " | head -c " $len " )
31
+
32
+ if ! cmp -s <( echo -ne " $EXPECTED " ) flash_content.bin; then
33
+ echo " Verification failed: content does not match expected for length"
34
+ exit 1
35
+ fi
36
+ done
37
+
38
+ echo " All read-flash tests passed!"
You can’t perform that action at this time.
0 commit comments