spi_flash: remove duplicate definition of spi_flash_unlock

The other (static) definition is in flash_ops.c, all references are
also in flash_ops.c.
This commit is contained in:
Ivan Grokhotkov
2019-08-23 12:37:55 +08:00
committed by Angus Gratton
parent 2f557d1a59
commit 12c9d9a564
18 changed files with 274 additions and 140 deletions

View File

@@ -13,16 +13,29 @@
#include "esp_efuse.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_partition.h"
#include "esp_flash_encrypt.h"
#include "esp_efuse_table.h"
static void example_print_chip_info(void);
static void example_print_flash_encryption_status(void);
static void example_read_write_flash(void);
static const char* TAG = "example";
void app_main(void)
{
uint32_t flash_crypt_cnt = 0;
esp_flash_enc_mode_t mode;
printf("\nExample to check Flash Encryption status\n");
printf("\nSample program to check Flash Encryption\n");
example_print_chip_info();
example_print_flash_encryption_status();
example_read_write_flash();
}
static void example_print_chip_info(void)
{
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
@@ -35,33 +48,52 @@ void app_main(void)
printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
esp_efuse_read_field_blob(ESP_EFUSE_FLASH_CRYPT_CNT, &flash_crypt_cnt, 7);
if (esp_flash_encryption_enabled()) {
printf("Flash encryption feature is enabled\n");
mode = esp_get_flash_encryption_mode();
if (mode == ESP_FLASH_ENC_MODE_DEVELOPMENT) {
printf("Flash encryption mode is DEVELOPMENT\n");
/* If odd bits set flash encryption is enabled else disabled */
if (__builtin_parity(flash_crypt_cnt) == 1) {
printf("Flash in encrypted mode with flash_crypt_cnt = %d\n", flash_crypt_cnt);
}
else {
printf("Flash in plaintext mode with flash_crypt_cnt = %d\n", flash_crypt_cnt);
}
} else {
printf("Flash encryption mode is RELEASE\n");
}
}
else {
printf("FLASH_CRYPT_CNT eFuse value is %d\n", flash_crypt_cnt);
printf("Flash encryption feature is disabled\n\n");
}
printf("Halting...\n");
while(1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
static void example_print_flash_encryption_status(void)
{
uint32_t flash_crypt_cnt = 0;
esp_efuse_read_field_blob(ESP_EFUSE_FLASH_CRYPT_CNT, &flash_crypt_cnt, 7);
printf("FLASH_CRYPT_CNT eFuse value is %d\n", flash_crypt_cnt);
esp_flash_enc_mode_t mode = esp_get_flash_encryption_mode();
if (mode == ESP_FLASH_ENC_MODE_DISABLED) {
printf("Flash encryption feature is disabled\n");
} else {
printf("Flash encryption feature is enabled in %s mode\n",
mode == ESP_FLASH_ENC_MODE_DEVELOPMENT ? "DEVELOPMENT" : "RELEASE");
}
}
static void example_read_write_flash(void)
{
const esp_partition_t* partition = esp_partition_find_first(
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage");
assert(partition);
printf("Erasing partition \"%s\" (0x%x bytes)\n", partition->label, partition->size);
ESP_ERROR_CHECK(esp_partition_erase_range(partition, 0, partition->size));
/* Generate the data which will be written */
const size_t data_size = 32;
uint8_t plaintext_data[data_size];
for (uint8_t i = 0; i < data_size; ++i) {
plaintext_data[i] = i;
}
printf("Writing data with esp_partition_write:\n");
ESP_LOG_BUFFER_HEXDUMP(TAG, plaintext_data, data_size, ESP_LOG_INFO);
ESP_ERROR_CHECK(esp_partition_write(partition, 0, plaintext_data, data_size));
uint8_t read_data[data_size];
printf("Reading with esp_partition_read:\n");
ESP_ERROR_CHECK(esp_partition_read(partition, 0, read_data, data_size));
ESP_LOG_BUFFER_HEXDUMP(TAG, read_data, data_size, ESP_LOG_INFO);
printf("Reading with spi_flash_read:\n");
ESP_ERROR_CHECK(spi_flash_read(partition->address, read_data, data_size));
ESP_LOG_BUFFER_HEXDUMP(TAG, read_data, data_size, ESP_LOG_INFO);
}