Skip to content

Commit 119cef5

Browse files
committed
contrib/espressif: add using the error codes
1 parent 606ca34 commit 119cef5

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

contrib/loaders/flash/espressif/include/esp_stub.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ enum esp_stub_cmd {
5252

5353
// TODO: remove or move upper when they are completely ready to replace the old ones
5454
/****************************************************************************************/
55-
#define ESP_STUB_ERR_OK 0
56-
#define ESP_STUB_ERR_FAIL (-1)
55+
#define ESP_STUB_OK 0
56+
#define ESP_STUB_FAIL (-1)
5757
#define ESP_STUB_ERR_NOT_SUPPORTED (-2)
5858
#define ESP_STUB_ERR_INFLATE (-3)
5959
#define ESP_STUB_ERR_NOT_ENOUGH_DATA (-4)

contrib/loaders/flash/espressif/src/stub_main.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <esp-stub-lib/flash.h>
99
#include <esp-stub-lib/log.h>
1010
#include <esp-stub-lib/bit_utils.h>
11+
#include <esp-stub-lib/err.h>
1112

1213
#include "esp_stub.h"
1314
#include "stub_apptrace.h"
@@ -49,7 +50,7 @@ static __maybe_unused int handle_test1(va_list ap)
4950
STUB_LOG_TRACE();
5051
STUB_LOG_TRACEF("foo:%u\n", 0x2A);
5152

52-
return ESP_STUB_ERR_OK;
53+
return ESP_STUB_OK;
5354
}
5455

5556
static int stub_apptrace_process_recvd_data(const uint8_t *buf, uint32_t size)
@@ -64,7 +65,7 @@ static int stub_apptrace_process_recvd_data(const uint8_t *buf, uint32_t size)
6465

6566
STUB_LOG("\n");
6667

67-
return ESP_STUB_ERR_OK;
68+
return ESP_STUB_OK;
6869
}
6970

7071
static __maybe_unused int handle_apptrace_read_from_host(va_list ap)
@@ -90,7 +91,7 @@ static __maybe_unused int stub_apptrace_process_write_data(uint32_t addr, uint8
9091
for (uint32_t i = 0; i < size; i++)
9192
buf[i] = data++;
9293

93-
return ESP_STUB_ERR_OK;
94+
return ESP_STUB_OK;
9495
}
9596

9697
static __maybe_unused int handle_apptrace_write_to_host(va_list ap)
@@ -122,6 +123,7 @@ int stub_main(int cmd, ...)
122123
va_list ap;
123124
void *flash_state = NULL;
124125
int ret = ESP_STUB_ERR_NOT_SUPPORTED;
126+
stub_lib_err_t rc = STUB_LIB_FAIL;
125127

126128
/* zero bss */
127129
for (uint32_t *p = &_bss_start; p < &_bss_end; p++)
@@ -131,23 +133,32 @@ int stub_main(int cmd, ...)
131133

132134
STUB_LOG_INIT();
133135

134-
stub_lib_flash_init(&flash_state);
136+
rc = stub_lib_flash_init(&flash_state);
137+
if (rc != STUB_LIB_OK) {
138+
STUB_LOGE("Flash initialization failed\n");
139+
return ESP_STUB_FAIL;
140+
}
135141

136-
STUB_LOGD("Command: %x\n", cmd);
142+
STUB_LOGD("Command: 0x%x\n", cmd);
137143

138144
const struct stub_cmd_handler *handler = cmd_handlers;
139145
while (handler->handler) {
140146
if (handler->cmd == cmd) {
141-
STUB_LOGI("Executing command: %s\n", handler->name);
147+
STUB_LOGI("Executing command: %s (0x%x)\n", handler->name, handler->cmd);
142148
ret = handler->handler(ap);
149+
if (ret != ESP_STUB_OK) {
150+
STUB_LOGE("Command %s (0x%x) failed\n", handler->name, handler->cmd);
151+
goto flash_va_end;
152+
}
143153
break;
144154
}
145155
handler++;
146156
}
147157

148158
if (!handler->handler)
149-
STUB_LOG("Unknown command!\n");
159+
STUB_LOGE("Unknown command: 0x%x\n", cmd);
150160

161+
flash_va_end:
151162
va_end(ap);
152163

153164
if (flash_state)

src/flash/nor/esp_flash.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ int esp_algo_flash_blank_check(struct flash_bank *bank)
328328
destroy_mem_param(&mp);
329329
return ret;
330330
}
331-
if (run.ret_code != ESP_STUB_ERR_OK) {
331+
if (run.ret_code != ESP_STUB_OK) {
332332
LOG_ERROR("Failed to check erase flash (%" PRId32 ")!", run.ret_code);
333333
ret = ERROR_FAIL;
334334
} else {
@@ -380,7 +380,7 @@ static int esp_algo_flash_get_mappings(struct flash_bank *bank,
380380
flash_map->flash_size = target_buffer_get_u32(bank->target, mp.value + ESP_STUB_FLASHMAP_FLASH_SIZE);
381381
flash_map->retcode = target_buffer_get_u32(bank->target, mp.value + ESP_STUB_FLASHMAP_RETCODE);
382382

383-
if (flash_map->retcode != ESP_STUB_ERR_OK) {
383+
if (flash_map->retcode != ESP_STUB_OK) {
384384
LOG_WARNING("Failed to get flash maps (%" PRId32 ")!", flash_map->retcode);
385385
if (flash_map->retcode == ESP_STUB_ERR_INVALID_IMAGE)
386386
LOG_WARNING(
@@ -463,7 +463,7 @@ int esp_algo_flash_erase(struct flash_bank *bank, unsigned int first, unsigned i
463463
LOG_ERROR("Failed to run flasher stub (%d)!", ret);
464464
return ret;
465465
}
466-
if (run.ret_code != ESP_STUB_ERR_OK) {
466+
if (run.ret_code != ESP_STUB_OK) {
467467
LOG_ERROR("Failed to erase flash (%" PRId32 ")!", run.ret_code);
468468
ret = ERROR_FAIL;
469469
} else {
@@ -781,7 +781,7 @@ int esp_algo_flash_write(struct flash_bank *bank, const uint8_t *buffer,
781781
LOG_ERROR("Failed to run flasher stub (%d)!", ret);
782782
return ret;
783783
}
784-
if (run.ret_code != ESP_STUB_ERR_OK) {
784+
if (run.ret_code != ESP_STUB_OK) {
785785
LOG_ERROR("Failed to write flash (%" PRId32 ")!", run.ret_code);
786786
ret = ERROR_FAIL;
787787
} else {
@@ -933,7 +933,7 @@ int esp_algo_flash_read(struct flash_bank *bank, uint8_t *buffer,
933933
LOG_ERROR("Failed to run flasher stub (%d)!", ret);
934934
return ret;
935935
}
936-
if (run.ret_code != ESP_STUB_ERR_OK) {
936+
if (run.ret_code != ESP_STUB_OK) {
937937
LOG_ERROR("Failed to read flash (%" PRId32 ")!", run.ret_code);
938938
ret = ERROR_FAIL;
939939
}
@@ -1300,7 +1300,7 @@ int esp_algo_flash_breakpoint_remove(struct target *target, struct esp_flash_bre
13001300
LOG_ERROR("Failed to run flasher stub (%d)!", ret);
13011301
return ret;
13021302
}
1303-
if (run.ret_code != ESP_STUB_ERR_OK) {
1303+
if (run.ret_code != ESP_STUB_OK) {
13041304
LOG_ERROR("Failed to clear bp (%" PRId32 ")!", run.ret_code);
13051305
return ERROR_FAIL;
13061306
}
@@ -1367,7 +1367,7 @@ static int esp_algo_flash_calc_hash(struct flash_bank *bank, uint8_t *hash,
13671367
destroy_mem_param(&mp);
13681368
return ret;
13691369
}
1370-
if (run.ret_code != ESP_STUB_ERR_OK) {
1370+
if (run.ret_code != ESP_STUB_OK) {
13711371
LOG_ERROR("Failed to get hash value (%" PRId32 ")!", run.ret_code);
13721372
ret = ERROR_FAIL;
13731373
} else {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy