kopia lustrzana https://github.com/espressif/esp-idf
Init phy data to default if invalid in flash partition to avoid bootloops
Signed-off-by: ronghulin <ronghulin@espressif.com> Merges https://github.com/espressif/esp-idf/pull/6610pull/6828/head
rodzic
3373eff989
commit
63a7a8489b
|
@ -430,6 +430,16 @@ menu "PHY"
|
||||||
|
|
||||||
If unsure, choose 'n'.
|
If unsure, choose 'n'.
|
||||||
|
|
||||||
|
config ESP32_PHY_DEFAULT_INIT_IF_INVALID
|
||||||
|
bool "Reset default PHY init data if invalid"
|
||||||
|
default n
|
||||||
|
depends on ESP32_PHY_INIT_DATA_IN_PARTITION
|
||||||
|
help
|
||||||
|
If enabled, PHY init data will be restored to default if
|
||||||
|
it cannot be verified successfully to avoid endless bootloops.
|
||||||
|
|
||||||
|
If unsure, choose 'n'.
|
||||||
|
|
||||||
if ESP32_PHY_INIT_DATA_IN_PARTITION
|
if ESP32_PHY_INIT_DATA_IN_PARTITION
|
||||||
config ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN
|
config ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN
|
||||||
bool "Support multiple PHY init data bin"
|
bool "Support multiple PHY init data bin"
|
||||||
|
|
|
@ -339,16 +339,42 @@ const esp_phy_init_data_t* esp_phy_get_init_data(void)
|
||||||
ESP_LOGE(TAG, "failed to allocate memory for PHY init data");
|
ESP_LOGE(TAG, "failed to allocate memory for PHY init data");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
// read phy data from flash
|
||||||
esp_err_t err = esp_partition_read(partition, 0, init_data_store, init_data_store_length);
|
esp_err_t err = esp_partition_read(partition, 0, init_data_store, init_data_store_length);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "failed to read PHY data partition (0x%x)", err);
|
ESP_LOGE(TAG, "failed to read PHY data partition (0x%x)", err);
|
||||||
|
free(init_data_store);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
// verify data
|
||||||
if (memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) != 0 ||
|
if (memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) != 0 ||
|
||||||
memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post),
|
memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post),
|
||||||
PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) != 0) {
|
PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) != 0) {
|
||||||
|
#ifndef CONFIG_ESP32_PHY_DEFAULT_INIT_IF_INVALID
|
||||||
ESP_LOGE(TAG, "failed to validate PHY data partition");
|
ESP_LOGE(TAG, "failed to validate PHY data partition");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#else
|
||||||
|
ESP_LOGE(TAG, "failed to validate PHY data partition, restoring default data into flash...");
|
||||||
|
|
||||||
|
memcpy(init_data_store,
|
||||||
|
PHY_INIT_MAGIC, sizeof(phy_init_magic_pre));
|
||||||
|
memcpy(init_data_store + sizeof(phy_init_magic_pre),
|
||||||
|
&phy_init_data, sizeof(phy_init_data));
|
||||||
|
memcpy(init_data_store + sizeof(phy_init_magic_pre) + sizeof(phy_init_data),
|
||||||
|
PHY_INIT_MAGIC, sizeof(phy_init_magic_post));
|
||||||
|
|
||||||
|
assert(memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) == 0);
|
||||||
|
assert(memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post),
|
||||||
|
PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) == 0);
|
||||||
|
|
||||||
|
// write default data
|
||||||
|
err = esp_partition_write(partition, 0, init_data_store, init_data_store_length);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "failed to write default PHY data partition (0x%x)", err);
|
||||||
|
free(init_data_store);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif // CONFIG_ESP32_PHY_DEFAULT_INIT_IF_INVALID
|
||||||
}
|
}
|
||||||
#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN
|
#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN
|
||||||
if ((*(init_data_store + (sizeof(phy_init_magic_pre) + PHY_SUPPORT_MULTIPLE_BIN_OFFSET)))) {
|
if ((*(init_data_store + (sizeof(phy_init_magic_pre) + PHY_SUPPORT_MULTIPLE_BIN_OFFSET)))) {
|
||||||
|
|
Ładowanie…
Reference in New Issue