Page 1 of 2

FatFs does not work on encrypted partition

Posted: Fri Mar 02, 2018 10:08 am
by BennoTr
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

Re: FatFs does not work on encrypted partition

Posted: Sun Mar 04, 2018 3:55 pm
by ESP_igrr
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...)

Re: FatFs does not work on encrypted partition

Posted: Mon Mar 05, 2018 8:21 am
by BennoTr
@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

Re: FatFs does not work on encrypted partition

Posted: Mon Mar 05, 2018 2:15 pm
by ESP_igrr
You're right, it looks like wl_config_t has grown by 4 bytes somewhere... We will check this.

Re: FatFs does not work on encrypted partition

Posted: Wed May 16, 2018 2:31 pm
by ESP_Angus
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

Re: FatFs does not work on encrypted partition

Posted: Fri May 18, 2018 11:48 am
by BennoTr
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

Re: FatFs does not work on encrypted partition

Posted: Tue Jun 05, 2018 1:11 am
by ESP_Angus
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

Re: FatFs does not work on encrypted partition

Posted: Tue Jul 03, 2018 8:45 am
by mitipi
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

Re: FatFs does not work on encrypted partition

Posted: Mon Oct 21, 2019 12:47 am
by Mikhail Khalizev
Hi.

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

Re: FatFs does not work on encrypted partition

Posted: Mon Oct 21, 2019 4:45 am
by ESP_Angus
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.)