mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-19 09:25:54 +08:00
添加智能灯固件代码
This commit is contained in:
89
firmware/esp-idf/wumei-smart-firmware/main/flash_encrypt.c
Normal file
89
firmware/esp-idf/wumei-smart-firmware/main/flash_encrypt.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
#include "flash_encrypt.h"
|
||||
|
||||
static void print_chip_info(void);
|
||||
static void print_flash_encryption_status(void);
|
||||
static void read_write_flash(void);
|
||||
static const char* TAG = "flash-encrypt";
|
||||
|
||||
void flash_encrypy_start(void)
|
||||
{
|
||||
printf("\ncheck Flash Encryption status\n");
|
||||
|
||||
print_chip_info();
|
||||
print_flash_encryption_status();
|
||||
read_write_flash();
|
||||
}
|
||||
|
||||
|
||||
static void print_chip_info(void)
|
||||
{
|
||||
/* 打印芯片信息 */
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
printf("This is ESP32 chip with %d CPU cores, WiFi%s%s, ",
|
||||
chip_info.cores,
|
||||
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
|
||||
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
|
||||
|
||||
printf("silicon revision %d, ", chip_info.revision);
|
||||
|
||||
printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
|
||||
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
|
||||
}
|
||||
|
||||
|
||||
static void print_flash_encryption_status(void)
|
||||
{
|
||||
uint32_t flash_crypt_cnt = 0;
|
||||
esp_efuse_read_field_blob(TARGET_CRYPT_CNT_EFUSE, &flash_crypt_cnt, TARGET_CRYPT_CNT_WIDTH);
|
||||
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 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));
|
||||
|
||||
/*生成将要写入的数据 */
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user