1
2
3
7
8
9
10
11
12
13
14
15
16
17
26
27
28
29
30
31
32
33
34
35
36
37
41
42
43
44
51
52
53
54
55
56
57
58
59
60
61
62
63
67
68
69
70
71
72
73
74
75
76
83
84
85
86
87
/* ... */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <helper/log.h>
#include <helper/binarybuffer.h>
#include "target/target.h"
#include "esp.h"
int esp_common_init(struct esp_common *esp, const struct esp_algorithm_hw *algo_hw)
{
if (!esp)
return ERROR_FAIL;
esp->algo_hw = algo_hw;
return ERROR_OK;
}{ ... }
int esp_dbgstubs_table_read(struct target *target, struct esp_dbg_stubs *dbg_stubs)
{
uint32_t table_size, table_start_id, desc_entry_id, gcov_entry_id;
uint32_t entries[ESP_DBG_STUB_ENTRY_MAX] = {0};
uint8_t entry_buff[sizeof(entries)] = {0};
LOG_TARGET_DEBUG(target, "Read debug stubs info %" PRIx32 " / %d", dbg_stubs->base, dbg_stubs->entries_count);
int res = target_read_buffer(target, dbg_stubs->base, sizeof(uint32_t) * 2, entry_buff);
if (res != ERROR_OK) {
LOG_ERROR("%s: Failed to read first debug stub entry!", target_name(target));
return res;
}if (res != ERROR_OK) { ... }
entries[0] = target_buffer_get_u32(target, entry_buff);
entries[1] = target_buffer_get_u32(target, entry_buff + sizeof(uint32_t));
if (entries[0] != ESP_DBG_STUB_MAGIC_NUM_VAL) {
table_size = 2;
table_start_id = 0;
desc_entry_id = 0;
gcov_entry_id = 1;
}if (entries[0] != ESP_DBG_STUB_MAGIC_NUM_VAL) { ... } else {
table_size = entries[1];
table_start_id = ESP_DBG_STUB_TABLE_START;
desc_entry_id = ESP_DBG_STUB_TABLE_START;
gcov_entry_id = ESP_DBG_STUB_ENTRY_FIRST;
if (table_size > ESP_DBG_STUB_ENTRY_MAX)
table_size = ESP_DBG_STUB_ENTRY_MAX;
res = target_read_buffer(target, dbg_stubs->base + 2 * sizeof(uint32_t), sizeof(uint32_t) * table_size - 2,
entry_buff + sizeof(uint32_t) * 2);
if (res != ERROR_OK) {
LOG_TARGET_ERROR(target, "Failed to read debug stubs info!");
return res;
}if (res != ERROR_OK) { ... }
for (unsigned int i = 2; i < table_size; ++i)
entries[i] = target_buffer_get_u32(target, entry_buff + sizeof(uint32_t) * i);
dbg_stubs->entries[ESP_DBG_STUB_CAPABILITIES] = entries[ESP_DBG_STUB_CAPABILITIES];
}else { ... }
dbg_stubs->entries[ESP_DBG_STUB_DESC] = entries[desc_entry_id];
dbg_stubs->entries[ESP_DBG_STUB_ENTRY_GCOV] = entries[gcov_entry_id];
for (enum esp_dbg_stub_id i = ESP_DBG_STUB_DESC; i < ESP_DBG_STUB_ENTRY_MAX; i++) {
LOG_DEBUG("Check dbg stub %d - %x", i, dbg_stubs->entries[i]);
if (dbg_stubs->entries[i]) {
LOG_DEBUG("New dbg stub %d at %x", dbg_stubs->entries_count, dbg_stubs->entries[i]);
dbg_stubs->entries_count++;
}if (dbg_stubs->entries[i]) { ... }
}for (enum esp_dbg_stub_id i = ESP_DBG_STUB_DESC; i < ESP_DBG_STUB_ENTRY_MAX; i++) { ... }
if (dbg_stubs->entries_count < table_size - table_start_id)
LOG_WARNING("Not full dbg stub table %d of %d", dbg_stubs->entries_count, table_size - table_start_id);
return ERROR_OK;
}{ ... }