mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-22 00:46:54 +00:00
54 lines
1.7 KiB
C
54 lines
1.7 KiB
C
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
#include "esp_secure_boot.h"
|
|
#include "esp_log.h"
|
|
#include "esp32s2/rom/secure_boot.h"
|
|
|
|
static const char *TAG = "secure_boot";
|
|
|
|
esp_err_t esp_secure_boot_permanently_enable(void)
|
|
{
|
|
uint8_t hash[32];
|
|
|
|
if (esp_rom_efuse_is_secure_boot_enabled())
|
|
{
|
|
ESP_LOGI(TAG, "secure boot is already enabled, continuing..");
|
|
return ESP_OK;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Verifying bootloader signature...\n");
|
|
int r = ets_secure_boot_verify_bootloader(hash, false);
|
|
if (r != ESP_OK) {
|
|
ESP_LOGE(TAG, "Failed to verify bootloader signature");
|
|
return r;
|
|
}
|
|
|
|
esp_efuse_batch_write_begin(); /* Batch all efuse writes at the end of this function */
|
|
|
|
esp_efuse_write_field_bit(ESP_EFUSE_SECURE_BOOT_EN);
|
|
esp_efuse_write_field_bit(ESP_EFUSE_DIS_BOOT_REMAP);
|
|
esp_efuse_write_field_bit(ESP_EFUSE_DIS_LEGACY_SPI_BOOT);
|
|
|
|
// TODO: also disable JTAG here, etc
|
|
|
|
esp_err_t err = esp_efuse_batch_write_commit();
|
|
|
|
if (err == ESP_OK) {
|
|
assert(esp_rom_efuse_is_secure_boot_enabled());
|
|
ESP_LOGI(TAG, "Secure boot permanently enabled");
|
|
}
|
|
|
|
return ESP_OK;
|
|
}
|