Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Flash encryption not working

Mehul_dudeMehul_dude India
edited July 3 in Mongoose OS

#mos flash esp32
This command is flashing the demo.js in the esp32.

#mos flash-read --arch esp32 0x190000 2000 - //command changed
#mos flash-read --platform esp32 0x190000 2000 -

This command is reading 2000 bytes of demo.js which is the CA certificate.

C:\Users\Mansaa.mos\apps-2.3\wifi_bulb>mos flash-read --platform esp32 0x190000 2000 -
Using port COM9
Opening COM9 @ 115200...
Connecting to ESP32 ROM, attempt 1 of 10...
Connected, chip: ESP32D0WDQ6 R1
Running flasher @ 0...
Flasher is running
Reading 2000 @ 0x190000...
Read 2000 bytes in 0.20 seconds (76.97 KBit/sec)
��� � � � � � � � � � � � � � ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������)� �� �� �I �ca.pem ���������� � � � �
� � � � � � � � � � � � � � � � � ! " # $ % & ' ( ) * + , - . / 1 2 3 4 5 6 7 8 9 : ; < = > ? A B C D E F G H I J K L M N O Q R ����������������������������������� �Subject: O=Digital Signature Trust Co., CN=DST Root CA X3
Not Before: Sep 30 21:12:19 2000 GMT
Not After : Sep 30 14:01:15 2021 GMT
-----BEGIN CERTIFICATE-----
---CA Certificate--
-----END CERTIFICATE-----
Subject: C=IE, O=Baltimore, OU=CyberTrust, CN=Baltimore CyberTrust Root
Not Before: May 12 18:46:00 2000 GMT
Not After : May

#mos -X esp32-gen-key flash_encryption_key fe.key \ --esp32-enable-flash-encryption --dry-run=false

This command is generating the fe.key and enabling flash encryption.

C:\Users\Mansaa.mos\apps-2.3\wifi_bulb>mos -X esp32-gen-key flash_encryption_key fe.key 
Using port COM9
Opening COM9 @ 115200...
Connecting to ESP32 ROM, attempt 1 of 10...
Connecting to ESP32 ROM, attempt 2 of 10...
Connecting to ESP32 ROM, attempt 3 of 10...
Connecting to ESP32 ROM, attempt 4 of 10...
Connecting to ESP32 ROM, attempt 5 of 10...
Connected, chip: ESP32D0WDQ6 R1
Device MAC address: b4:e6:2d:93:a6:25
Error: flash_encryption_key is already set

#mos flash esp32 --esp32-encryption-key-file fe.key

This command is flashing the demo.js but with encryption key

C:\Users\Mansaa.mos\apps-2.3\wifi_bulb>mos flash esp32 --esp32-encryption-key-file fe.key
Fetching https://github.com/mongoose-os-apps/demo-js/releases/download/2.3/demo-js-esp32.zip...
Loaded demo-js/esp32 version 1.0 (20180615-171315/???)
Using port COM9
Opening COM9 @ 115200...
Connecting to ESP32 ROM, attempt 1 of 10...
Connected, chip: ESP32D0WDQ6 R1
Running flasher @ 0...
Flasher is running
Flash size: 4194304, params: 0x0220 (dio,32m,40m)
Deduping...
16384 @ 0x9000 -> 8192
262144 @ 0x190000 -> 0
Writing...
20480 @ 0x1000
4096 @ 0x8000
8192 @ 0x9000
8192 @ 0xd000
1540096 @ 0x10000
Wrote 1573952 bytes in 137.11 seconds (89.68 KBit/sec)
Verifying...
18368 @ 0x1000
3072 @ 0x8000
16384 @ 0x9000
8192 @ 0xd000
1536128 @ 0x10000
262144 @ 0x190000
Booting firmware...
All done!

But now when again I am performing

#mos flash-read --arch esp32 0x190000 2000 -

It is showing

C:\Users\Mansaa.mos\apps-2.3\wifi_bulb>mos flash-read --platform esp32 0x190000 2000 -
Using port COM9
Opening COM9 @ 115200...
Connecting to ESP32 ROM, attempt 1 of 10...
Connected, chip: ESP32D0WDQ6 R1
Running flasher @ 0...
Flasher is running
Reading 2000 @ 0x190000...
Read 2000 bytes in 0.20 seconds (76.97 KBit/sec)
��� � � � � � � � � � � � � � ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������)� �� �� �I �ca.pem ���������� � � � �
� � � � � � � � � � � � � � � � � ! " # $ % & ' ( ) * + , - . / 1 2 3 4 5 6 7 8 9 : ; < = > ? A B C D E F G H I J K L M N O Q R ����������������������������������� �Subject: O=Digital Signature Trust Co., CN=DST Root CA X3
Not Before: Sep 30 21:12:19 2000 GMT
Not After : Sep 30 14:01:15 2021 GMT
-----BEGIN CERTIFICATE-----
---Ca certificate--
-----END CERTIFICATE-----
Subject: C=IE, O=Baltimore, OU=CyberTrust, CN=Baltimore CyberTrust Root
Not Before: May 12 18:46:00 2000 GMT
Not After : May

and in mos tool I am getting error

[Jul 3 17:46:15.821] ets_main.c 371
[Jul 3 17:46:16.156] ets Jun 8 2016 00:22:57
[Jul 3 17:46:16.158]
[Jul 3 17:46:16.158] rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[Jul 3 17:46:16.163] flash read err, 1000
[Jul 3 17:46:16.165] ets_main.c 371
[Jul 3 17:46:16.500] ets Jun 8 2016 00:22:57
[Jul 3 17:46:16.503]
[Jul 3 17:46:16.503] rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[Jul 3 17:46:16.508] flash read err, 1000
[Jul 3 17:46:16.510] ets_main.c 371
[Jul 3 17:46:16.845] ets Jun 8 2016 00:22:57
[Jul 3 17:46:16.847]
[Jul 3 17:46:16.848] rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[Jul 3 17:46:16.853] flash read err, 1000
[Jul 3 17:46:16.855] ets_main.c 371
[Jul 3 17:46:17.190] ets Jun 8 2016 00:22:57
[Jul 3 17:46:17.192]
[Jul 3 17:46:17.192] rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[Jul 3 17:46:17.197] flash read err, 1000

Please provide the solution regarding how to do the flash encryption and if there is an error in the commands.

Comments

  • nliviunliviu Romania

    It looks like the encryption for the device is already set:

    Error: flash_encryption_key is already set
    

    When you run the first time mos -X esp32-gen-key flash_encryption_key fe.key --esp32-enable-flash-encryption --dry-run=false, you should see something like this:

    Using port /dev/ttyUSB0
    Opening /dev/ttyUSB0 @ 115200...
    Connecting to ESP32 ROM, attempt 1 of 10...
      Connected, chip: ESP32D0WDQ6 R1
    Device MAC address: aa:bb:cc:dd:ee:ff
    
    flash_encryption_key : ****************************************
    efuse_rd_disable     : 0x0 -> 0x1
    efuse_wr_disable     : 0x0000 -> 0x0080
    flash_crypt_cnt      : 0x00 -> 0x01
    JTAG_disable         : 0x0 -> 0x1
    download_dis_encrypt : 0x0 -> 0x1
    download_dis_decrypt : 0x0 -> 0x1
    download_dis_cache   : 0x0 -> 0x1
    flash_crypt_config   : 0x0 -> 0xf
    
    Wrote key to fe.key
    
    Programming eFuses...
    Success
    
  • I have done this but after that I execute #mos flash esp32 --esp32-encryption-key-file fe.key command the flashing of the esp32 is done.
    And if I again try to read the flash it is reading.

    And also the firmware is not booting from the flash. It is showing the flash read error like this...

    [Jul 3 17:46:15.821] ets_main.c 371
    [Jul 3 17:46:16.156] ets Jun 8 2016 00:22:57
    [Jul 3 17:46:16.158]
    [Jul 3 17:46:16.158] rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    [Jul 3 17:46:16.163] flash read err, 1000
    [Jul 3 17:46:16.165] ets_main.c 371
    [Jul 3 17:46:16.500] ets Jun 8 2016 00:22:57

    I am not able to achieve the successful flash encryption.
    Could you please help me with correct commands that I have to use and that are working for the flash encryption?

Sign In or Register to comment.