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
15 // This part is put in iram.
16
17 #include "hal/spi_flash_encrypted_ll.h"
18
spi_flash_encryption_hal_enable(void)19 void spi_flash_encryption_hal_enable(void)
20 {
21 spi_flash_encrypt_ll_enable();
22 #if CONFIG_IDF_TARGET_ESP32S2
23 spi_flash_encrypt_ll_aes_accelerator_enable();
24 #endif //CONFIG_IDF_TARGET_ESP32S2
25 #if !CONFIG_IDF_TARGET_ESP32
26 spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
27 #endif // !CONFIG_IDF_TARGET_ESP32
28 }
29
spi_flash_encryption_hal_disable(void)30 void spi_flash_encryption_hal_disable(void)
31 {
32 spi_flash_encrypt_ll_disable();
33 }
34
spi_flash_encryption_hal_prepare(uint32_t address,const uint32_t * buffer,uint32_t size)35 void spi_flash_encryption_hal_prepare(uint32_t address, const uint32_t* buffer, uint32_t size)
36 {
37 #if !CONFIG_IDF_TARGET_ESP32
38 spi_flash_encrypt_ll_buffer_length(size);
39 #endif // !CONFIG_IDF_TARGET_ESP32
40 spi_flash_encrypt_ll_address_save(address);
41 spi_flash_encrypt_ll_plaintext_save(address, buffer, size);
42 spi_flash_encrypt_ll_calculate_start();
43 }
44
spi_flash_encryption_hal_done(void)45 void spi_flash_encryption_hal_done(void)
46 {
47 spi_flash_encrypt_ll_calculate_wait_idle();
48 spi_flash_encrypt_ll_done();
49 }
50
spi_flash_encryption_hal_destroy(void)51 void spi_flash_encryption_hal_destroy(void)
52 {
53 spi_flash_encrypt_ll_destroy();
54 }
55
spi_flash_encryption_hal_check(uint32_t address,uint32_t length)56 bool spi_flash_encryption_hal_check(uint32_t address, uint32_t length)
57 {
58 return spi_flash_encrypt_ll_check(address, length);
59 }
60