spi_flash_encrypt_hal_iram.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2021 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // This part is put in iram.
  15. #include "hal/spi_flash_encrypted_ll.h"
  16. void spi_flash_encryption_hal_enable(void)
  17. {
  18. spi_flash_encrypt_ll_enable();
  19. #if CONFIG_IDF_TARGET_ESP32S2
  20. spi_flash_encrypt_ll_aes_accelerator_enable();
  21. #endif //CONFIG_IDF_TARGET_ESP32S2
  22. #if !CONFIG_IDF_TARGET_ESP32
  23. spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
  24. #endif // !CONFIG_IDF_TARGET_ESP32
  25. }
  26. void spi_flash_encryption_hal_disable(void)
  27. {
  28. spi_flash_encrypt_ll_disable();
  29. }
  30. void spi_flash_encryption_hal_prepare(uint32_t address, const uint32_t* buffer, uint32_t size)
  31. {
  32. #if !CONFIG_IDF_TARGET_ESP32
  33. spi_flash_encrypt_ll_buffer_length(size);
  34. #endif // !CONFIG_IDF_TARGET_ESP32
  35. spi_flash_encrypt_ll_address_save(address);
  36. spi_flash_encrypt_ll_plaintext_save(address, buffer, size);
  37. spi_flash_encrypt_ll_calculate_start();
  38. }
  39. void spi_flash_encryption_hal_done(void)
  40. {
  41. spi_flash_encrypt_ll_calculate_wait_idle();
  42. spi_flash_encrypt_ll_done();
  43. }
  44. void spi_flash_encryption_hal_destroy(void)
  45. {
  46. spi_flash_encrypt_ll_destroy();
  47. }
  48. bool spi_flash_encryption_hal_check(uint32_t address, uint32_t length)
  49. {
  50. return spi_flash_encrypt_ll_check(address, length);
  51. }