@@ -79,12 +79,29 @@ __asm__(
7979 "j stub_main;" );
8080#endif
8181
82+ const char * stub_err_str (int ret_code )
83+ {
84+ switch (ret_code ) {
85+ case ESP_STUB_FAIL :
86+ return "Generic error" ;
87+ case ESP_STUB_OK :
88+ return "Success" ;
89+
90+ case STUB_LIB_FAIL :
91+ return "Failure in the lib" ;
92+ case STUB_LIB_ERR_UNKNOWN_FLASH_ID :
93+ return "Unknown flash ID" ;
94+
95+ default :
96+ return "Unknown stub error" ;
97+ }
98+ }
99+
82100int stub_main (int cmd , ...)
83101{
84102 va_list ap ;
85103 void * flash_state = NULL ;
86104 int ret = ESP_STUB_FAIL ;
87- stub_lib_err_t rc = STUB_LIB_FAIL ;
88105
89106 /* zero bss */
90107 for (uint32_t * p = & _bss_start ; p < & _bss_end ; p ++ ) {
@@ -95,20 +112,21 @@ int stub_main(int cmd, ...)
95112
96113 STUB_LOG_INIT ();
97114
98- rc = stub_lib_flash_init (& flash_state );
99- if (rc != STUB_LIB_OK ) {
100- return ESP_STUB_FAIL ;
101- }
102-
103115 STUB_LOGI ("Command: 0x%x\n" , cmd );
104116
117+ int lib_ret = stub_lib_flash_init (& flash_state );
118+ if (lib_ret != STUB_LIB_OK ) {
119+ STUB_LOGE ("Flash init failure: (0x%X) %s\n" , lib_ret , stub_err_str (lib_ret ));
120+ return lib_ret ;
121+ }
122+
105123 const struct stub_cmd_handler * handler = cmd_handlers ;
106124 while (handler -> handler ) {
107125 if (handler -> cmd == cmd ) {
108126 STUB_LOGI ("Executing command: %s\n" , handler -> name );
109127 ret = handler -> handler (ap );
110128 if (ret != ESP_STUB_OK ) {
111- STUB_LOGE ("Command %s (0x%x) failed\n" , handler -> name , handler -> cmd );
129+ STUB_LOGE ("Command %s (0x%x) failed: (0x%X) %s \n" , handler -> name , handler -> cmd , ret , stub_err_str ( ret ) );
112130 goto flash_va_end ;
113131 }
114132 break ;
@@ -118,6 +136,7 @@ int stub_main(int cmd, ...)
118136
119137 if (!handler -> handler ) {
120138 STUB_LOGE ("Unknown command (0x%x)!\n" , cmd );
139+ ret = ESP_STUB_ERR_CMD_NOT_SUPPORTED ;
121140 }
122141
123142flash_va_end :
0 commit comments