mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 08:04:33 +02:00
Merge branch 'feature/esptool_reset_options' into 'master'
esptool: Add new options to reset before/after, detect flash size Also fixes bugs with reading MAC, chip id. See merge request !331
This commit is contained in:
@@ -50,11 +50,14 @@ else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
|
|||||||
|
|
||||||
# One time flashing requires user to run esptool.py command themselves,
|
# One time flashing requires user to run esptool.py command themselves,
|
||||||
# and warning is printed about inability to reflash.
|
# and warning is printed about inability to reflash.
|
||||||
|
#
|
||||||
|
# The flashing command is deliberately printed without an auto-reset
|
||||||
|
# step, so the device doesn't immediately reset to flash itself.
|
||||||
|
|
||||||
bootloader: $(BOOTLOADER_BIN)
|
bootloader: $(BOOTLOADER_BIN)
|
||||||
@echo $(SEPARATOR)
|
@echo $(SEPARATOR)
|
||||||
@echo "Bootloader built. One-time flash command is:"
|
@echo "Bootloader built. One-time flash command is:"
|
||||||
@echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
|
@echo "$(subst hard_reset,no_reset,$(ESPTOOLPY_WRITE_FLASH)) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
|
||||||
@echo $(SEPARATOR)
|
@echo $(SEPARATOR)
|
||||||
@echo "* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
|
@echo "* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
|
||||||
|
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
#include "esp_image_format.h"
|
#include "esp_image_format.h"
|
||||||
#include "esp_secure_boot.h"
|
#include "esp_secure_boot.h"
|
||||||
#include "esp_flash_encrypt.h"
|
#include "esp_flash_encrypt.h"
|
||||||
|
#include "esp_flash_partitions.h"
|
||||||
#include "bootloader_flash.h"
|
#include "bootloader_flash.h"
|
||||||
|
|
||||||
#include "bootloader_config.h"
|
#include "bootloader_config.h"
|
||||||
@@ -116,16 +117,14 @@ bool load_partition_table(bootloader_state_t* bs)
|
|||||||
{
|
{
|
||||||
const esp_partition_info_t *partitions;
|
const esp_partition_info_t *partitions;
|
||||||
const int ESP_PARTITION_TABLE_DATA_LEN = 0xC00; /* length of actual data (signature is appended to this) */
|
const int ESP_PARTITION_TABLE_DATA_LEN = 0xC00; /* length of actual data (signature is appended to this) */
|
||||||
const int MAX_PARTITIONS = ESP_PARTITION_TABLE_DATA_LEN / sizeof(esp_partition_info_t);
|
|
||||||
char *partition_usage;
|
char *partition_usage;
|
||||||
|
esp_err_t err;
|
||||||
ESP_LOGI(TAG, "Partition Table:");
|
int num_partitions;
|
||||||
ESP_LOGI(TAG, "## Label Usage Type ST Offset Length");
|
|
||||||
|
|
||||||
#ifdef CONFIG_SECURE_BOOT_ENABLED
|
#ifdef CONFIG_SECURE_BOOT_ENABLED
|
||||||
if(esp_secure_boot_enabled()) {
|
if(esp_secure_boot_enabled()) {
|
||||||
ESP_LOGI(TAG, "Verifying partition table signature...");
|
ESP_LOGI(TAG, "Verifying partition table signature...");
|
||||||
esp_err_t err = esp_secure_boot_verify_signature(ESP_PARTITION_TABLE_ADDR, ESP_PARTITION_TABLE_DATA_LEN);
|
err = esp_secure_boot_verify_signature(ESP_PARTITION_TABLE_ADDR, ESP_PARTITION_TABLE_DATA_LEN);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to verify partition table signature.");
|
ESP_LOGE(TAG, "Failed to verify partition table signature.");
|
||||||
return false;
|
return false;
|
||||||
@@ -141,17 +140,21 @@ bool load_partition_table(bootloader_state_t* bs)
|
|||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "mapped partition table 0x%x at 0x%x", ESP_PARTITION_TABLE_ADDR, (intptr_t)partitions);
|
ESP_LOGD(TAG, "mapped partition table 0x%x at 0x%x", ESP_PARTITION_TABLE_ADDR, (intptr_t)partitions);
|
||||||
|
|
||||||
for(int i = 0; i < MAX_PARTITIONS; i++) {
|
err = esp_partition_table_basic_verify(partitions, true, &num_partitions);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to verify partition table");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Partition Table:");
|
||||||
|
ESP_LOGI(TAG, "## Label Usage Type ST Offset Length");
|
||||||
|
|
||||||
|
for(int i = 0; i < num_partitions; i++) {
|
||||||
const esp_partition_info_t *partition = &partitions[i];
|
const esp_partition_info_t *partition = &partitions[i];
|
||||||
ESP_LOGD(TAG, "load partition table entry 0x%x", (intptr_t)partition);
|
ESP_LOGD(TAG, "load partition table entry 0x%x", (intptr_t)partition);
|
||||||
ESP_LOGD(TAG, "type=%x subtype=%x", partition->type, partition->subtype);
|
ESP_LOGD(TAG, "type=%x subtype=%x", partition->type, partition->subtype);
|
||||||
partition_usage = "unknown";
|
partition_usage = "unknown";
|
||||||
|
|
||||||
if (partition->magic != ESP_PARTITION_MAGIC) {
|
|
||||||
/* invalid partition definition indicates end-of-table */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* valid partition table */
|
/* valid partition table */
|
||||||
switch(partition->type) {
|
switch(partition->type) {
|
||||||
case PART_TYPE_APP: /* app partition */
|
case PART_TYPE_APP: /* app partition */
|
||||||
|
@@ -13,32 +13,43 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
#include "esp_flash_partitions.h"
|
#include "esp_flash_partitions.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
#include "rom/spi_flash.h"
|
||||||
|
|
||||||
static const char *TAG = "flash_parts";
|
static const char *TAG = "flash_parts";
|
||||||
|
|
||||||
esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions)
|
esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions)
|
||||||
{
|
{
|
||||||
int num_parts;
|
int num_parts;
|
||||||
|
uint32_t chip_size = g_rom_flashchip.chip_size;
|
||||||
*num_partitions = 0;
|
*num_partitions = 0;
|
||||||
|
|
||||||
for(num_parts = 0; num_parts < ESP_PARTITION_TABLE_MAX_ENTRIES; num_parts++) {
|
for(num_parts = 0; num_parts < ESP_PARTITION_TABLE_MAX_ENTRIES; num_parts++) {
|
||||||
const esp_partition_info_t *part = &partition_table[num_parts];
|
const esp_partition_info_t *part = &partition_table[num_parts];
|
||||||
|
|
||||||
if(part->magic == 0xFFFF
|
if (part->magic == 0xFFFF
|
||||||
&& part->type == PART_TYPE_END
|
&& part->type == PART_TYPE_END
|
||||||
&& part->subtype == PART_SUBTYPE_END) {
|
&& part->subtype == PART_SUBTYPE_END) {
|
||||||
/* TODO: check md5 */
|
/* TODO: check md5 */
|
||||||
ESP_LOGD(TAG, "partition table verified, %d entries", num_parts);
|
ESP_LOGD(TAG, "partition table verified, %d entries", num_parts);
|
||||||
*num_partitions = num_parts;
|
*num_partitions = num_parts;
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(part->magic != ESP_PARTITION_MAGIC) {
|
if (part->magic != ESP_PARTITION_MAGIC) {
|
||||||
if (log_errors) {
|
if (log_errors) {
|
||||||
ESP_LOGE(TAG, "partition %d invalid magic number 0x%x", num_parts, part->magic);
|
ESP_LOGE(TAG, "partition %d invalid magic number 0x%x", num_parts, part->magic);
|
||||||
}
|
}
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const esp_partition_pos_t *pos = &part->pos;
|
||||||
|
if (pos->offset > chip_size || pos->offset + pos->size > chip_size) {
|
||||||
|
if (log_errors) {
|
||||||
|
ESP_LOGE(TAG, "partition %d invalid - offset 0x%x size 0x%x exceeds flash chip size 0x%x",
|
||||||
|
num_parts, pos->offset, pos->size, chip_size);
|
||||||
|
}
|
||||||
|
return ESP_ERR_INVALID_SIZE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (log_errors) {
|
if (log_errors) {
|
||||||
|
@@ -121,4 +121,61 @@ config ESPTOOLPY_FLASHSIZE
|
|||||||
default "8MB" if ESPTOOLPY_FLASHSIZE_8MB
|
default "8MB" if ESPTOOLPY_FLASHSIZE_8MB
|
||||||
default "16MB" if ESPTOOLPY_FLASHSIZE_16MB
|
default "16MB" if ESPTOOLPY_FLASHSIZE_16MB
|
||||||
|
|
||||||
|
config ESPTOOLPY_FLASHSIZE_DETECT
|
||||||
|
bool "Detect flash size when flashing bootloader"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
If this option is set, 'make flash' targets will automatically detect
|
||||||
|
the flash size and update the bootloader image when flashing.
|
||||||
|
|
||||||
|
choice ESPTOOLPY_BEFORE
|
||||||
|
prompt "Before flashing"
|
||||||
|
default ESPTOOLPY_BEFORE_RESET
|
||||||
|
help
|
||||||
|
Configure whether esptool.py should reset the ESP32 before flashing.
|
||||||
|
|
||||||
|
Automatic resetting depends on the RTS & DTR signals being
|
||||||
|
wired from the serial port to the ESP32. Most USB development
|
||||||
|
boards do this internally.
|
||||||
|
|
||||||
|
The "Reset with ESP32R0 Windows workaround" option works
|
||||||
|
around an automatic reset bug in hardware, when using Windows
|
||||||
|
with some development boards. This fix only works if you're
|
||||||
|
using a silicon revision 0 ESP32.
|
||||||
|
|
||||||
|
config ESPTOOLPY_BEFORE_RESET
|
||||||
|
bool "Reset to bootloader"
|
||||||
|
config ESPTOOLPY_BEFORE_NORESET
|
||||||
|
bool "No reset"
|
||||||
|
config ESPTOOLPY_BEFORE_ESP32R0
|
||||||
|
bool "Reset with ESP32R0 Windows workaround"
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
config ESPTOOLPY_BEFORE
|
||||||
|
string
|
||||||
|
default "default_reset" if ESPTOOLPY_BEFORE_RESET
|
||||||
|
default "no_reset" if ESPTOOLPY_BEFORE_NORESET
|
||||||
|
default "esp32r0" if ESPTOOLPY_BEFORE_ESP32R0
|
||||||
|
|
||||||
|
choice ESPTOOLPY_AFTER
|
||||||
|
prompt "After flashing"
|
||||||
|
default ESPTOOLPY_AFTER_RESET
|
||||||
|
help
|
||||||
|
Configure whether esptool.py should reset the ESP32 after flashing.
|
||||||
|
|
||||||
|
Automatic resetting depends on the RTS & DTR signals being
|
||||||
|
wired from the serial port to the ESP32. Most USB development
|
||||||
|
boards do this internally.
|
||||||
|
|
||||||
|
config ESPTOOLPY_AFTER_RESET
|
||||||
|
bool "Reset after flashing"
|
||||||
|
config ESPTOOLPY_AFTER_NORESET
|
||||||
|
bool "Stay in bootloader"
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
config ESPTOOLPY_AFTER
|
||||||
|
string
|
||||||
|
default "hard_reset" if ESPTOOLPY_AFTER_RESET
|
||||||
|
default "no_reset" if ESPTOOLPY_AFTER_NORESET
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
@@ -13,7 +13,7 @@ PYTHON ?= $(call dequote,$(CONFIG_PYTHON))
|
|||||||
#
|
#
|
||||||
ESPTOOLPY_SRC := $(COMPONENT_PATH)/esptool/esptool.py
|
ESPTOOLPY_SRC := $(COMPONENT_PATH)/esptool/esptool.py
|
||||||
ESPTOOLPY := $(PYTHON) $(ESPTOOLPY_SRC) --chip esp32
|
ESPTOOLPY := $(PYTHON) $(ESPTOOLPY_SRC) --chip esp32
|
||||||
ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD)
|
ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD) --before $(CONFIG_ESPTOOLPY_BEFORE) --after $(CONFIG_ESPTOOLPY_AFTER)
|
||||||
|
|
||||||
# Supporting esptool command line tools
|
# Supporting esptool command line tools
|
||||||
ESPEFUSEPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espefuse.py
|
ESPEFUSEPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espefuse.py
|
||||||
@@ -21,10 +21,15 @@ ESPSECUREPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espsecure.py
|
|||||||
export ESPSECUREPY # is used in bootloader_support component
|
export ESPSECUREPY # is used in bootloader_support component
|
||||||
|
|
||||||
ESPTOOL_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size $(ESPFLASHSIZE)
|
ESPTOOL_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size $(ESPFLASHSIZE)
|
||||||
|
ifdef CONFIG_ESPTOOLPY_FLASHSIZE_DETECT
|
||||||
|
ESPTOOL_WRITE_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size detect
|
||||||
|
else
|
||||||
|
ESPTOOL_WRITE_FLASH_OPTIONS := $(ESPTOOL_FLASH_OPTIONS)
|
||||||
|
endif
|
||||||
|
|
||||||
ESPTOOL_ELF2IMAGE_OPTIONS :=
|
ESPTOOL_ELF2IMAGE_OPTIONS :=
|
||||||
|
|
||||||
ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z) $(ESPTOOL_FLASH_OPTIONS)
|
ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z) $(ESPTOOL_WRITE_FLASH_OPTIONS)
|
||||||
|
|
||||||
ESPTOOL_ALL_FLASH_ARGS += $(CONFIG_APP_OFFSET) $(APP_BIN)
|
ESPTOOL_ALL_FLASH_ARGS += $(CONFIG_APP_OFFSET) $(APP_BIN)
|
||||||
|
|
||||||
|
Submodule components/esptool_py/esptool updated: adc914b91a...fe69994270
Reference in New Issue
Block a user