mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
333553caf2
fix(hal/include): fix header violations in hal component fix(hal/include): Move type definitions from `xx_hal.h` to `xx_types.h` fix(hal/include): Move type definitions from `xx_hal.h` to `xx_types.h` fix(hal/include): Add comment for a far away `#endif` fix(hal/include): change scope for cpp guard ci: Remove components/hal/ comment from public headers check exceptions Add missing include macro sdkconfig.h for header files Add missing include macro stdbool.h for header files Add missing include macro stdint.h for header files Add missing capability guard macro for header files Add missing cpp guard macro for header files Remove some useless include macros Add some missing `inline` attribute for functions defined in header files Remove components/hal/ from public headers check exceptions fix(hal/include): fix invalid licenses fix(hal/include): fix invalid licenses fix(hal/include): add missing soc_caps.h fix(hal): include soc_caps.h before cap macro is used fix(hal): Remove unnecessary target check fix(hal): fix header and macro problems Add missing include macro Remove loop dependency in hal Add comment for far-away endif fix(hal): Add missing soc_caps.h ci: update check_copyright_ignore.txt Change the sequence of `#include` macro, cpp guard macro Change the wrap scope of capacity macro fix(hal): Change position of C++ guard to pass test
112 lines
2.6 KiB
C
112 lines
2.6 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/*******************************************************************************
|
|
* NOTICE
|
|
* The ll is not public api, don't use in application code.
|
|
* See readme.md in hal/include/hal/readme.md
|
|
******************************************************************************/
|
|
|
|
// The Lowlevel layer for SPI Flash Encryption.
|
|
|
|
#include "soc/dport_reg.h"
|
|
#include "soc/flash_encryption_reg.h"
|
|
#include <stdbool.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* Enable encryption in flash
|
|
*/
|
|
static inline void spi_flash_encrypt_ll_enable(void)
|
|
{
|
|
DPORT_REG_SET_BIT(DPORT_SLAVE_SPI_CONFIG_REG, DPORT_SLAVE_SPI_MASK_PRO | DPORT_SPI_ENCRYPT_ENABLE);
|
|
}
|
|
|
|
/**
|
|
* Disable encryption in flash
|
|
*/
|
|
static inline void spi_flash_encrypt_ll_disable(void)
|
|
{
|
|
DPORT_REG_CLR_BIT(DPORT_SLAVE_SPI_CONFIG_REG, DPORT_SLAVE_SPI_MASK_PRO | DPORT_SPI_ENCRYPT_ENABLE);
|
|
}
|
|
|
|
/**
|
|
* Copy the flash address to physical address
|
|
*
|
|
* @param flash_addr The flash address.
|
|
*
|
|
* @note the address must be 8-byte aligned
|
|
*/
|
|
static inline void spi_flash_encrypt_ll_address_save(uint32_t flash_addr)
|
|
{
|
|
REG_WRITE(FLASH_ENCRYPTION_ADDRESS_REG, flash_addr);
|
|
}
|
|
|
|
/**
|
|
* Wait for flash encryption operation completeness.
|
|
*/
|
|
static inline void spi_flash_encrypt_ll_calculate_wait_idle(void)
|
|
{
|
|
while(!(REG_READ(FLASH_ENCRYPTION_DONE_REG) & BIT(0))) {
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Start encryption on data buffer.
|
|
*/
|
|
static inline void spi_flash_encrypt_ll_calculate_start(void)
|
|
{
|
|
REG_WRITE(FLASH_ENCRYPTION_START_REG, BIT(0));
|
|
}
|
|
|
|
/**
|
|
* Save the plaintext for encryption
|
|
*
|
|
* @param address address of the partition to be written.
|
|
* @param buffer Buffer to store the input data.
|
|
* @param size Buffer size.
|
|
*/
|
|
static inline void spi_flash_encrypt_ll_plaintext_save(uint32_t address, const uint32_t* buffer, uint32_t size)
|
|
{
|
|
for (int i = 0; i < 8; i++) {
|
|
REG_WRITE(FLASH_ENCRYPTION_BUFFER_REG + (i << 2), buffer[i]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Finish the flash encryption and make encrypted result accessible to SPI.
|
|
*/
|
|
static inline void spi_flash_encrypt_ll_done(void)
|
|
{
|
|
// Do nothing on ESP32
|
|
}
|
|
|
|
/**
|
|
* Set to destroy encrypted result
|
|
*/
|
|
static inline void spi_flash_encrypt_ll_destroy(void)
|
|
{
|
|
// Do nothing on ESP32
|
|
}
|
|
|
|
/**
|
|
* Check if is qualified to encrypt the buffer
|
|
*
|
|
* @param address the address of written flash partition.
|
|
* @param length Buffer size.
|
|
*/
|
|
static inline bool spi_flash_encrypt_ll_check(uint32_t address, uint32_t length)
|
|
{
|
|
return ((address % 16) == 0) ? true : false;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|