Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash encryption #145

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Flash encryption #145

wants to merge 4 commits into from

Conversation

brianignacio5
Copy link
Collaborator

@brianignacio5 brianignacio5 commented May 30, 2024

Add option for flash encryption by enabling the file encrypt flag and flash encrypted data command.

Fix #95

Fix #139

PTAL and test on spare device to avoid damage on important devices.

Copy link

github-actions bot commented May 30, 2024

Download the artifacts for this pull request:

@brianignacio5 brianignacio5 force-pushed the feature/encrypted-flash branch from b4d8753 to ced3737 Compare May 31, 2024 11:10
@brianignacio5 brianignacio5 changed the title initial flash encryption implementation Flash encryption Oct 14, 2024
@rotempco
Copy link

rotempco commented Oct 15, 2024

I've just testet it.
Still not working on my ESP32-S3

Simple test in js.

     const loaderOptions= {
         transport,
         baudrate: parseInt(115200),
         terminal: espLoaderTerminal
     };
     esploader = new ESPLoader(loaderOptions);
     chip = await esploader.main();

Error

Read bytes
bundle.js:2 TRACE 326.000 Read 163 bytes: 
    4553502d524f4d3a 657370333273332d | ESP-ROM:esp32s3-
    3230323130333237 0d0a4275696c643a | 20210327..Build:
    4d61722032372032 3032310d0a727374 | Mar 27 2021..rst
    3a30783135202855 53425f554152545f | :0x15 (USB_UART_
    434849505f524553 4554292c626f6f74 | CHIP_RESET),boot
    3a30783233202844 4f574e4c4f414428 | :0x23 (DOWNLOAD(
    5553422f55415254 3029290d0a536176 | USB/UART0))..Sav
    65642050433a3078 3430303439306432 | ed PC:0x400490d2
    0d0a776169742075 61727420646f776e | ..wait uart down
    6c6f616428736563 757265206d6f6465 | load(secure mode
    290d0a                            | )..
bundle.js:2 Slip reader results
bundle.js:2 TRACE 326.000 Read 0 bytes:                 
bundle.js:2 TRACE 1382.000 command op:0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
bundle.js:2 Write bytes
bundle.js:2 TRACE 1383.000 Write 46 bytes: 
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
bundle.js:2 TRACE 1437.000 command op:0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
bundle.js:2 Write bytes
bundle.js:2 TRACE 1437.000 Write 46 bytes: 
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
bundle.js:2 Read bytes
bundle.js:2 TRACE 1438.000 Read 275 bytes: 
    4553502d524f4d3a 657370333273332d | ESP-ROM:esp32s3-
    3230323130333237 0d0a4275696c643a | 20210327..Build:
    4d61722032372032 3032310d0a727374 | Mar 27 2021..rst
    3a30783135202855 53425f554152545f | :0x15 (USB_UART_
    434849505f524553 4554292c626f6f74 | CHIP_RESET),boot
    3a30783233202844 4f574e4c4f414428 | :0x23 (DOWNLOAD(
    5553422f55415254 3029290d0a536176 | USB/UART0))..Sav
    65642050433a3078 3430303439306432 | ed PC:0x400490d2
    0d0a776169742075 61727420646f776e | ..wait uart down
    6c6f616428736563 757265206d6f6465 | load(secure mode
    290d0ac001080400 0707122000000000 | ).......... ....
    c0c0010804000707 122000000000c0c0 | ......... ......
    0108040007071220 00000000c0c00108 | ....... ........
    0400070712200000 0000c0c001080400 | ..... ..........
    0707122000000000 c0c0010804000707 | ... ............
    122000000000c0c0 0108040007071220 | . ............. 
    00000000c0c00108 0400070712200000 | ............. ..
    0000c0                            | ...
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1438.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 TRACE 1438.000 command op:0x0a data len=4 wait_response=1 timeout=3.000 data=00100040        
bundle.js:2 Write bytes
bundle.js:2 TRACE 1438.000 Write 14 bytes: c0000a04000000000000100040c0
bundle.js:2 Read bytes
bundle.js:2 TRACE 1439.000 Read 56 bytes: 
    c001080400070712 2000000000c0c001 | ........ .......
    0804000707122000 000000c0c0010804 | ...... .........
    0007071220000000 00c0c00108040007 | .... ...........
    07122000000000c0                  | .. .....
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1439.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1439.000 Read 15 bytes: c0010804000707122000000000c0c0
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1439.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1439.000 Read 28 bytes: 
    c001080400070712 2000000000c0c001 | ........ .......
    0804000707122000 000000c0         | ...... .....
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1439.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1439.000 Read 28 bytes: 
    c001080400070712 2000000000c0c001 | ........ .......
    0804000707122001 050000c0         | ...... .....
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1439.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Raw Read bytes
bundle.js:2 TRACE 1440.000 Read 14 bytes: c0010804000707122001050000c0
esp-updater.js:135  TypeError: Cannot read properties of undefined (reading 'getChipDescription')
    at fe.main (bundle.js:2:68890)
    at async espUpdaterProgram (esp-updater.js:131:16)
    at async HTMLButtonElement.<anonymous> (<anonymous>:10:17)

@brianignacio5
Copy link
Collaborator Author

brianignacio5 commented Oct 15, 2024

The end error lets me to believe that the chip is not detected properly. Could you modify:

const loaderOptions= {
         transport,
         baudrate: parseInt(115200),
         terminal: espLoaderTerminal,
         debugLogging: true,
     };

and please share what is the chip magic number output ?

Which esp32s3 board are you using ?

@rotempco
Copy link

Yeah, it sure does look like that, this is the output with debugLogging

Read bytes
bundle.js:2 TRACE 313.000 Read 163 bytes: 
    4553502d524f4d3a 657370333273332d | ESP-ROM:esp32s3-
    3230323130333237 0d0a4275696c643a | 20210327..Build:
    4d61722032372032 3032310d0a727374 | Mar 27 2021..rst
    3a30783135202855 53425f554152545f | :0x15 (USB_UART_
    434849505f524553 4554292c626f6f74 | CHIP_RESET),boot
    3a30783233202844 4f574e4c4f414428 | :0x23 (DOWNLOAD(
    5553422f55415254 3029290d0a536176 | USB/UART0))..Sav
    65642050433a3078 3430303438643062 | ed PC:0x40048d0b
    0d0a776169742075 61727420646f776e | ..wait uart down
    6c6f616428736563 757265206d6f6465 | load(secure mode
    290d0a                            | )..
bundle.js:2 Slip reader results
bundle.js:2 TRACE 313.000 Read 0 bytes:                 
bundle.js:2 TRACE 1372.000 command op:0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
bundle.js:2 Write bytes
bundle.js:2 TRACE 1372.000 Write 46 bytes: 
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
bundle.js:2 TRACE 1434.000 command op:0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
bundle.js:2 Write bytes
bundle.js:2 TRACE 1434.000 Write 46 bytes: 
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
bundle.js:2 Read bytes
bundle.js:2 TRACE 1437.000 Read 275 bytes: 
    4553502d524f4d3a 657370333273332d | ESP-ROM:esp32s3-
    3230323130333237 0d0a4275696c643a | 20210327..Build:
    4d61722032372032 3032310d0a727374 | Mar 27 2021..rst
    3a30783135202855 53425f554152545f | :0x15 (USB_UART_
    434849505f524553 4554292c626f6f74 | CHIP_RESET),boot
    3a30783233202844 4f574e4c4f414428 | :0x23 (DOWNLOAD(
    5553422f55415254 3029290d0a536176 | USB/UART0))..Sav
    65642050433a3078 3430303438643062 | ed PC:0x40048d0b
    0d0a776169742075 61727420646f776e | ..wait uart down
    6c6f616428736563 757265206d6f6465 | load(secure mode
    290d0ac001080400 0707122000000000 | ).......... ....
    c0c0010804000707 122000000000c0c0 | ......... ......
    0108040007071220 00000000c0c00108 | ....... ........
    0400070712200000 0000c0c001080400 | ..... ..........
    0707122000000000 c0c0010804000707 | ... ............
    122000000000c0c0 0108040007071220 | . ............. 
    00000000c0c00108 0400070712200000 | ............. ..
    0000c0                            | ...
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1437.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 TRACE 1437.000 command op:0x0a data len=4 wait_response=1 timeout=3.000 data=00100040        
bundle.js:2 Write bytes
bundle.js:2 TRACE 1437.000 Write 14 bytes: c0000a04000000000000100040c0
bundle.js:2 Read bytes
bundle.js:2 TRACE 1438.000 Read 42 bytes: 
    c001080400070712 2000000000c0c001 | ........ .......
    0804000707122000 000000c0c0010804 | ...... .........
    0007071220000000 00c0             | .... .....
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1438.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1438.000 Read 14 bytes: c0010804000707122000000000c0
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1438.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1438.000 Read 15 bytes: c0010804000707122000000000c0c0
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1438.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1438.000 Read 28 bytes: 
    c001080400070712 2000000000c0c001 | ........ .......
    0804000707122000 000000c0         | ...... .....
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1438.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1438.000 Read 14 bytes: c0010804000707122000000000c0
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1439.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1439.000 Read 14 bytes: c0010804000707122001050000c0
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1439.000 Read 12 bytes: 010804000707122001050000
bundle.js:2 Raw Read bytes
bundle.js:2 TRACE 1439.000 Read 15 bytes: c0010804000707122001050000c0c0
esp-updater.js:136  TypeError: Cannot read properties of undefined (reading 'getChipDescription')
    at fe.main (bundle.js:2:68890)
    at async espUpdaterProgram (esp-updater.js:132:16)
    at async HTMLButtonElement.<anonymous> (<anonymous>:10:17)

@brianignacio5
Copy link
Collaborator Author

What is the terminal output ? What is printed in espLoaderTerminal ?

@rotempco
Copy link

My bad,

here it is

esptool.js
esp-updater.js:14 Serial port WebSerial VendorID 0x303a ProductID 0x1001
esp-updater.js:19 Connecting...
esp-updater.js:14 Debug: _connect_attempt default_reset false
bundle.js:2 Read bytes
bundle.js:2 TRACE 319.000 Read 163 bytes: 
    4553502d524f4d3a 657370333273332d | ESP-ROM:esp32s3-
    3230323130333237 0d0a4275696c643a | 20210327..Build:
    4d61722032372032 3032310d0a727374 | Mar 27 2021..rst
    3a30783135202855 53425f554152545f | :0x15 (USB_UART_
    434849505f524553 4554292c626f6f74 | CHIP_RESET),boot
    3a30783233202844 4f574e4c4f414428 | :0x23 (DOWNLOAD(
    5553422f55415254 3029290d0a536176 | USB/UART0))..Sav
    65642050433a3078 3430303438646538 | ed PC:0x40048de8
    0d0a776169742075 61727420646f776e | ..wait uart down
    6c6f616428736563 757265206d6f6465 | load(secure mode
    290d0a                            | )..
bundle.js:2 Slip reader results
bundle.js:2 TRACE 319.000 Read 0 bytes:                 
esp-updater.js:14 Debug: Timeout
esp-updater.js:14 Debug: Sync
bundle.js:2 TRACE 1394.000 command op:0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
bundle.js:2 Write bytes
bundle.js:2 TRACE 1394.000 Write 46 bytes: 
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
esp-updater.js:14 Debug: Sync err Error: Timeout
esp-updater.js:19 .
esp-updater.js:14 Debug: Sync
bundle.js:2 TRACE 1457.000 command op:0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
bundle.js:2 Write bytes
bundle.js:2 TRACE 1457.000 Write 46 bytes: 
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
bundle.js:2 Read bytes
bundle.js:2 TRACE 1458.000 Read 275 bytes: 
    4553502d524f4d3a 657370333273332d | ESP-ROM:esp32s3-
    3230323130333237 0d0a4275696c643a | 20210327..Build:
    4d61722032372032 3032310d0a727374 | Mar 27 2021..rst
    3a30783135202855 53425f554152545f | :0x15 (USB_UART_
    434849505f524553 4554292c626f6f74 | CHIP_RESET),boot
    3a30783233202844 4f574e4c4f414428 | :0x23 (DOWNLOAD(
    5553422f55415254 3029290d0a536176 | USB/UART0))..Sav
    65642050433a3078 3430303438646538 | ed PC:0x40048de8
    0d0a776169742075 61727420646f776e | ..wait uart down
    6c6f616428736563 757265206d6f6465 | load(secure mode
    290d0ac001080400 0707122000000000 | ).......... ....
    c0c0010804000707 122000000000c0c0 | ......... ......
    0108040007071220 00000000c0c00108 | ....... ........
    0400070712200000 0000c0c001080400 | ..... ..........
    0707122000000000 c0c0010804000707 | ... ............
    122000000000c0c0 0108040007071220 | . ............. 
    00000000c0c00108 0400070712200000 | ............. ..
    0000c0                            | ...
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1458.000 Read 12 bytes: 010804000707122000000000
esp-updater.js:14 Debug: 538052359
esp-updater.js:19 

bundle.js:2 TRACE 1458.000 command op:0x0a data len=4 wait_response=1 timeout=3.000 data=00100040        
bundle.js:2 Write bytes
bundle.js:2 TRACE 1458.000 Write 14 bytes: c0000a04000000000000100040c0
bundle.js:2 Read bytes
bundle.js:2 TRACE 1458.000 Read 57 bytes: 
    c001080400070712 2000000000c0c001 | ........ .......
    0804000707122000 000000c0c0010804 | ...... .........
    0007071220000000 00c0c00108040007 | .... ...........
    07122000000000c0 c0               | .. ......
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1458.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1459.000 Read 28 bytes: 
    c001080400070712 2000000000c0c001 | ........ .......
    0804000707122000 000000c0         | ...... .....
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1459.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1459.000 Read 14 bytes: c0010804000707122000000000c0
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1459.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1459.000 Read 14 bytes: c0010804000707122000000000c0
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1459.000 Read 12 bytes: 010804000707122000000000
bundle.js:2 Read bytes
bundle.js:2 TRACE 1459.000 Read 28 bytes: 
    c001080400070712 2001050000c0c001 | ........ .......
    0804000707122001 050000c0         | ...... .....
bundle.js:2 Slip reader results
bundle.js:2 TRACE 1459.000 Read 12 bytes: 010804000707122001050000
esp-updater.js:19 Detecting chip type... 
esp-updater.js:14 unknown!
esp-updater.js:139  TypeError: Cannot read properties of undefined (reading 'getChipDescription')
    at fe.main (bundle.js:2:68890)
    at async espUpdaterProgram (esp-updater.js:135:16)
    at async HTMLButtonElement.<anonymous> (<anonymous>:10:17)

@brianignacio5
Copy link
Collaborator Author

I don't see Debug: Chip Magic ### where ## is some number. I don't think your error is related to this PR but to the board you are using itself and the magic number is not 0x9.

esp-updater.js:19 Detecting chip type... 
esp-updater.js:14 unknown!

I have here a ESP32-C3 DevKitC-1 and seems to be working.

@rotempco
Copy link

That's weird. It is however a custom PCB, with a ESP32-S3-WROOM-1 chip.
Screenshot 2024-10-15 090126

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"unsupported command error" Support for Flash encryption and Secure Boot?
2 participants