-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Virtual Efuses do Not Work When Flash Encryption Previously Enabled (IDFGH-9580) #10929
Comments
yes this is a common issue. you need to erase the flash sometime before enabling virtual fuses. I personally think esp-idf should put a magic value in the virtual fuses partition, and assume all zeros or something sane if the magic value is not there. |
@chipweinberger Are you suggesting that if, in between my steps 3 and 4, I do a full flash erase that virtual fuses will work properly (when enabled in step 4) with flash encryption enabled? I want to clarify because you only get so many enable/disable cycles with flash encryption. |
you just need to make sure the virtual fuses partition is zero'd before you boot. You can do it at any step before boot. Note: if you reflash a different partition table youll need to erase the virtual fuses partition again. |
@chipweinberger this did not work for me. I verified the partition was fully erased, still experience this same issue with garbage efuse values. |
Hi @sidwarkd!
Your chip is really encrypted at the (2) point. Why do you need to enable virt efuses?
You misunderstood it, it means that the bootloader during the first boot will take a look at FLASH_CRYPT_CNT and encrypt the images that require encryption if it is 0, 2, 4, 6, after encryption is done burn the next bit. So Flash encryption is on when it is 1 or 3 or 5 or 7. Looks like efuse_em was encrypted too, but shouldn't be encrypted. |
@KonstantinKondrashov Thank you for the clarification on the number of bits set in FLASH_CRYPT_CNT. That makes sense. I went back to my example and ran As for efuses after encryption, there are lots of other things to test (Secure Boot) that you may want to not permanently burn efuses for. When you say "When virt efuse mode is on then no real flash encryption happens" what do you mean? From the Virtual Efuses section it states:
If you can't test flash encryption with virtual efuses then the documentation should be updated to clarify. Thanks again for your help and the clarification. |
@sidwarkd When
Actually, we use this for testing here https://github.com/espressif/esp-idf/blob/master/examples/system/efuse/sdkconfig.ci.virt_sb_v2_and_fe.esp32. But not in that way as you. I tried the way you suggested and it really shows garbage data. It is wired because the efuse_em partition should not be encrypted. I found a bug, https://github.com/espressif/esp-idf/blob/master/components/efuse/src/esp_efuse_utility.c#L470. The last arg must be false, not true. I will fix it on the mater and backport to 4.4 as well.
Sorry for the delay. |
Nice debugging Konstantin! |
@KonstantinKondrashov Thanks for digging in on this and finding the issue and fixing it. Great work! I am still a little bit confused on the documentation side. If Thanks again for your help. |
Flash encryption is a hardware feature, so it requires that eFuses (key and FLASH_CRYPT_CNT) should be burned fiscally otherwise FE does not work. In case when the VIRTUAL efuse mode is on then real eFuses (in regs) are not fiscally burned. Given that if real FE is not on then we should prevent the encryption in bootloader_flash_write(). Such tests we do on our CI. There are other tests that require that FE is already enabled for those tests we do not use the efuse virtual mode. Probably it makes sense to extend that condition to check whether the FE is really enabled and do encryption then. That will fit your needs. |
@KonstantinKondrashov Sorry for the confusion. All of my needs are met with the fix you have provided. I was merely pointing out the documentation shouldn't suggest you can test flash encryption with virtual efuses when you cannot. |
I agree with @sidwarkd that this should be written in the docs because it is really confusing that there is no real flash encryption applied. |
esp_efuse_utility_load_efuses_from_flash() read emul_efuse as an encrypted partition, but that is not correct, this partition was never encrypted. Need to read it as not encrypted partition. Fxed the case: If FE is already on then EFUSE VIRT mode can work with it. Closes espressif/esp-idf#10929
esp_efuse_utility_load_efuses_from_flash() read emul_efuse as an encrypted partition, but that is not correct, this partition was never encrypted. Need to read it as not encrypted partition. Fxed the case: If FE is already on then EFUSE VIRT mode can work with it. Closes espressif/esp-idf#10929
esp_efuse_utility_load_efuses_from_flash() read emul_efuse as an encrypted partition, but that is not correct, this partition was never encrypted. Need to read it as not encrypted partition. Fxed the case: If FE is already on then EFUSE VIRT mode can work with it. Closes #10929
esp_efuse_utility_load_efuses_from_flash() read emul_efuse as an encrypted partition, but that is not correct, this partition was never encrypted. Need to read it as not encrypted partition. Fxed the case: If FE is already on then EFUSE VIRT mode can work with it. Closes #10929
Answers checklist.
IDF version.
v4.4.4
Operating System used.
Linux
How did you build your project?
Command line with idf.py
If you are using Windows, please specify command line type.
None
Development Kit.
ESP32 Pico DevKitM-2 v1.0
Power Supply used.
USB
What is the expected behavior?
If flash encryption was enabled prior to enabling virtual efuses I expect the application to run normally after enabling virtual efuses.
What is the actual behavior?
If flash encryption was enabled prior to enabling virtual efuses the bootloader appears to read complete garbage from the efuses and the device fails to boot. The documentation suggests that all flash reads are "transparently decrypted" when encryption is enabled but this does not appear to be happening.
Steps to reproduce.
idf.py encrypted-flash monitor
. Device will boot and run normallyDebug Logs.
More Information.
As an additional comment it appears the documentation is wrong about flash encryption and the FLASH_CRYPT_CNT efuse. The documentation states "If even number of bits set (0, 2, 4, 6) - encrypt flash at boot time. If odd number of bits set (1, 3, 5, 7) - do not encrypt flash at boot time." However, when I have flash encryption disabled (confirmed with boot log) and I do an
espefuse.py summary
I get the following.There are an even number of bits set (two) and flash encryption is disabled. Which would also be true of the device from the factory with zero bits set. So it seems in reality it's the exact opposite of what the docs state. Can you confirm this?
The text was updated successfully, but these errors were encountered: