FatFs does not work on encrypted partition

BennoTr
Posts: 5
Joined: Fri Mar 02, 2018 9:53 am

FatFs does not work on encrypted partition

Postby BennoTr » Fri Mar 02, 2018 10:08 am

Hi all.

I took the wear_levelling example and set the encrypted flag on the storage partition:

Code: Select all

# Name,   Type, SubType, Offset,  Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1M,
storage,  data, fat,     ,        1M, encrypted
Now the FW displays the following errors during mounting of the filesystem:

Code: Select all

I (108) example: Mounting FAT filesystem
E (203) wl_flash: initSections(269): result = 0x00000104
E (203) wl_flash: init(161): result = 0x00000104
E (203) wl_ext_safe: init(73): result = 0x00000104
E (208) wear_levelling: wl_mount: init instance=0x00000000, result=0x104
E (213) vfs_fat_spiflash: failed to mount wear levelling layer. result = 260
E (223) example: Failed to mount FATFS (0x104)

According to this forum thread viewtopic.php?t=3305 it shold be possible to use FatFs with wear leveling on an encrypted partition.

So what goes wrong?


Regards,
Benno

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: FatFs does not work on encrypted partition

Postby ESP_igrr » Sun Mar 04, 2018 3:55 pm

Do you have flash encryption enabled in bootloader settings, or have you only changed the flag in the partition table? (Don't enable flash encryption yet if you have not done it, just a question...)

BennoTr
Posts: 5
Joined: Fri Mar 02, 2018 9:53 am

Re: FatFs does not work on encrypted partition

Postby BennoTr » Mon Mar 05, 2018 8:21 am

@ESP_igrr

I only set the encryped flag in the partition table. But I do not think that enabling encryption via the bootloader would make it work, because the error

Code: Select all

E (203) wl_flash: initSections(269): result = 0x00000104
points to the code at WL_Flash.cpp line 298/269

Code: Select all

    result = this->flash_drv->write(this->addr_cfg, &this->cfg, sizeof(wl_config_t));
    WL_RESULT_CHECK(result);
and here it tries to write the configuration with size sizeof(wl_config_t). This wl_config_t has a size of 9*4=36 bytes. But spi_flash_write_encrypted does reject every write with a size not a muptile of 16 with ESP_ERR_INVALID_SIZE.

Regards,
Benno

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: FatFs does not work on encrypted partition

Postby ESP_igrr » Mon Mar 05, 2018 2:15 pm

You're right, it looks like wl_config_t has grown by 4 bytes somewhere... We will check this.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: FatFs does not work on encrypted partition

Postby ESP_Angus » Wed May 16, 2018 2:31 pm

Hi Benno,

Sorry for the slow reply. This bug has been fixed in the IDF master branch, and will be in the V3.1 release:
https://github.com/espressif/esp-idf/co ... 75d67d9ece


Angus

BennoTr
Posts: 5
Joined: Fri Mar 02, 2018 9:53 am

Re: FatFs does not work on encrypted partition

Postby BennoTr » Fri May 18, 2018 11:48 am

Hi Angus.

I tried your patch with the wear_levelling example and the encrypted flag set on the storage partition. Now the low level errors have disapeared, but now I get the high level error when opening a file for writing:

Code: Select all

I (244) example: Mounting FAT filesystem
W (404) vfs_fat_spiflash: f_mount failed (13)
I (404) vfs_fat_spiflash: Formatting FATFS partition
I (814) vfs_fat_spiflash: Mounting again
I (814) example: Opening file
E (824) example: Failed to open file for writing
According to the log messages formating the partition has worked. But when I restart the exact same log messages apear. So on re-start the device detected the partition as not formated.

Please test the wear_levelling example with encrypted flag set for yourself.

Regards,
Benno

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: FatFs does not work on encrypted partition

Postby ESP_Angus » Tue Jun 05, 2018 1:11 am

Hi Benno,

Thanks for your patience while we looked into this. We've identified the bug running wear levelling on encrypted partitions and a fix is being developed.

Angus

mitipi
Posts: 3
Joined: Mon Jul 17, 2017 9:43 am

Re: FatFs does not work on encrypted partition

Postby mitipi » Tue Jul 03, 2018 8:45 am

Hi @ESP_Angus,

Is the fix now deployed, I saw a read-only fatfs encryption commit without using wear-leveling recently. Can you provide some details?

Best regards,
Mitipi

Mikhail Khalizev
Posts: 5
Joined: Mon Oct 21, 2019 12:45 am

Re: FatFs does not work on encrypted partition

Postby Mikhail Khalizev » Mon Oct 21, 2019 12:47 am

Hi.

Any news about it?
How I see, fat still is not working on encrypted partition.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: FatFs does not work on encrypted partition

Postby ESP_Angus » Mon Oct 21, 2019 4:45 am

Hi Mikhail,
Mikhail Khalizev wrote:
Mon Oct 21, 2019 12:47 am
How I see, fat still is not working on encrypted partition.
This should work now. If it's not working, can you please give some more details (ESP-IDF version, exact configuration & setup, behaviour you're seeing when trying to use the FAT partition.)

Who is online

Users browsing this forum: Google [Bot] and 97 guests