ble: fixed heap corruption on esp32c6 and esp32h2

This commit is contained in:
zwl 2023-08-11 15:19:22 +08:00
parent 461db723f1
commit fb6f00158e
4 changed files with 22 additions and 9 deletions

View File

@ -260,6 +260,9 @@ static void IRAM_ATTR esp_reset_rpa_moudle(void)
static void IRAM_ATTR osi_assert_wrapper(const uint32_t ln, const char *fn, static void IRAM_ATTR osi_assert_wrapper(const uint32_t ln, const char *fn,
uint32_t param1, uint32_t param2) uint32_t param1, uint32_t param2)
{ {
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
esp_ble_controller_log_dump_all(true);
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
BT_ASSERT_PRINT("BLE assert: line %d in function %s, param: 0x%x, 0x%x", ln, fn, param1, param2); BT_ASSERT_PRINT("BLE assert: line %d in function %s, param: 0x%x, 0x%x", ln, fn, param1, param2);
assert(0); assert(0);
} }
@ -822,7 +825,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
if (ble_osi_coex_funcs_register((struct osi_coex_funcs_t *)&s_osi_coex_funcs_ro) != 0) { if (ble_osi_coex_funcs_register((struct osi_coex_funcs_t *)&s_osi_coex_funcs_ro) != 0) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "osi coex funcs reg failed"); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "osi coex funcs reg failed");
ret = ESP_ERR_INVALID_ARG; ret = ESP_ERR_INVALID_ARG;
goto free_controller; goto modem_deint;
} }
#if CONFIG_SW_COEXIST_ENABLE #if CONFIG_SW_COEXIST_ENABLE
@ -832,7 +835,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
ret = ble_controller_init(cfg); ret = ble_controller_init(cfg);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_init failed %d", ret); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_init failed %d", ret);
goto free_controller; goto modem_deint;
} }
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
@ -845,7 +848,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
#endif // CONFIG_BT_CONTROLLER_LOG_DUMP #endif // CONFIG_BT_CONTROLLER_LOG_DUMP
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_log_init failed %d", ret); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_log_init failed %d", ret);
goto free_controller; goto controller_init_err;
} }
#endif // CONFIG_BT_CONTROLLER_LOG_ENABLED #endif // CONFIG_BT_CONTROLLER_LOG_ENABLED
@ -869,9 +872,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
free_controller: free_controller:
controller_sleep_deinit(); controller_sleep_deinit();
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
controller_init_err:
ble_log_deinit_async(); ble_log_deinit_async();
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
ble_controller_deinit(); ble_controller_deinit();
modem_deint:
esp_btbb_disable(); esp_btbb_disable();
esp_phy_disable(); esp_phy_disable();
esp_phy_modem_deinit(); esp_phy_modem_deinit();
@ -1194,7 +1199,9 @@ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t po
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
void esp_ble_controller_log_dump_all(bool output) void esp_ble_controller_log_dump_all(bool output)
{ {
BT_ASSERT_PRINT("\r\n[DUMP_START:");
ble_log_async_output_dump_all(output); ble_log_async_output_dump_all(output);
BT_ASSERT_PRINT("]\r\n");
} }
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED

View File

@ -252,6 +252,9 @@ static void IRAM_ATTR esp_reset_rpa_moudle(void)
static void IRAM_ATTR osi_assert_wrapper(const uint32_t ln, const char *fn, static void IRAM_ATTR osi_assert_wrapper(const uint32_t ln, const char *fn,
uint32_t param1, uint32_t param2) uint32_t param1, uint32_t param2)
{ {
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
esp_ble_controller_log_dump_all(true);
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
BT_ASSERT_PRINT("BLE assert: line %d in function %s, param: 0x%x, 0x%x", ln, fn, param1, param2); BT_ASSERT_PRINT("BLE assert: line %d in function %s, param: 0x%x, 0x%x", ln, fn, param1, param2);
assert(0); assert(0);
} }
@ -717,7 +720,6 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
ble_npl_count_info_t npl_info; ble_npl_count_info_t npl_info;
memset(&npl_info, 0, sizeof(ble_npl_count_info_t)); memset(&npl_info, 0, sizeof(ble_npl_count_info_t));
if (ble_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) { if (ble_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "invalid controller state"); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "invalid controller state");
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
@ -802,7 +804,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
if (ble_osi_coex_funcs_register((struct osi_coex_funcs_t *)&s_osi_coex_funcs_ro) != 0) { if (ble_osi_coex_funcs_register((struct osi_coex_funcs_t *)&s_osi_coex_funcs_ro) != 0) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "osi coex funcs reg failed"); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "osi coex funcs reg failed");
ret = ESP_ERR_INVALID_ARG; ret = ESP_ERR_INVALID_ARG;
goto free_controller; goto modem_deint;
} }
#if CONFIG_SW_COEXIST_ENABLE #if CONFIG_SW_COEXIST_ENABLE
@ -812,7 +814,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
ret = ble_controller_init(cfg); ret = ble_controller_init(cfg);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_init failed %d", ret); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_init failed %d", ret);
goto free_controller; goto modem_deint;
} }
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
@ -825,7 +827,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
#endif // CONFIG_BT_CONTROLLER_LOG_DUMP #endif // CONFIG_BT_CONTROLLER_LOG_DUMP
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_log_init failed %d", ret); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_log_init failed %d", ret);
goto free_controller; goto controller_init_err;
} }
#endif // CONFIG_BT_CONTROLLER_LOG_ENABLED #endif // CONFIG_BT_CONTROLLER_LOG_ENABLED
@ -850,9 +852,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
free_controller: free_controller:
controller_sleep_deinit(); controller_sleep_deinit();
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
controller_init_err:
ble_log_deinit_async(); ble_log_deinit_async();
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
ble_controller_deinit(); ble_controller_deinit();
modem_deint:
esp_btbb_disable(); esp_btbb_disable();
esp_phy_disable(); esp_phy_disable();
modem_clock_deselect_lp_clock_source(PERIPH_BT_MODULE); modem_clock_deselect_lp_clock_source(PERIPH_BT_MODULE);
@ -1173,7 +1177,9 @@ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t po
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
void esp_ble_controller_log_dump_all(bool output) void esp_ble_controller_log_dump_all(bool output)
{ {
BT_ASSERT_PRINT("\r\n[DUMP_START:");
ble_log_async_output_dump_all(output); ble_log_async_output_dump_all(output);
BT_ASSERT_PRINT("]\r\n");
} }
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED

@ -1 +1 @@
Subproject commit d785de0a7c46d9badcd73bc83c2e5cb78f7054b2 Subproject commit 8a951eb29b388d1d80acef5804f6e12e87d862ff

@ -1 +1 @@
Subproject commit 35bd3cd7352014d303a96c46d8ea8446ea0a9a54 Subproject commit 27f93dc1e673c4f7b7704b65ac68c350615a5289