Split clone main and ethereum main, add comments and remove unnecessary lines
This commit is contained in:
81
src/main.c
81
src/main.c
@@ -762,69 +762,77 @@ void library_main(libargs_t *args) {
|
||||
os_lib_end();
|
||||
}
|
||||
|
||||
__attribute__((section(".boot"))) int main(int arg0) {
|
||||
#ifdef USE_LIB_ETHEREUM
|
||||
/* Eth clones do not actually contain any logic, they delegate everything to the ETH application.
|
||||
* Start Eth in lib mode with the correct chain config
|
||||
*/
|
||||
__attribute__((noreturn)) void clone_main(libargs_t *args) {
|
||||
PRINTF("Starting in clone_main\n");
|
||||
BEGIN_TRY {
|
||||
TRY {
|
||||
unsigned int libcall_params[5];
|
||||
chain_config_t local_chainConfig;
|
||||
init_coin_config(&local_chainConfig);
|
||||
|
||||
PRINTF("Hello from Eth-clone\n");
|
||||
check_api_level(CX_COMPAT_APILEVEL);
|
||||
// delegate to Ethereum app/lib
|
||||
libcall_params[0] = (unsigned int) "Ethereum";
|
||||
libcall_params[1] = 0x100;
|
||||
libcall_params[2] = RUN_APPLICATION;
|
||||
libcall_params[3] = (unsigned int) &local_chainConfig;
|
||||
#ifdef HAVE_NBGL
|
||||
const char app_name[] = APPNAME;
|
||||
caller_app_t capp;
|
||||
nbgl_icon_details_t icon_details;
|
||||
uint8_t bitmap[sizeof(ICONBITMAP)];
|
||||
|
||||
memcpy(&icon_details, &ICONGLYPH, sizeof(ICONGLYPH));
|
||||
memcpy(&bitmap, &ICONBITMAP, sizeof(bitmap));
|
||||
icon_details.bitmap = (const uint8_t *) bitmap;
|
||||
capp.name = app_name;
|
||||
capp.icon = &icon_details;
|
||||
libcall_params[4] = (unsigned int) &capp;
|
||||
#else
|
||||
libcall_params[4] = NULL;
|
||||
#endif // HAVE_NBGL
|
||||
|
||||
if (arg0) {
|
||||
// call as a library
|
||||
libcall_params[2] = ((unsigned int *) arg0)[1];
|
||||
libcall_params[4] = ((unsigned int *) arg0)[3]; // library arguments
|
||||
// Clone called by Exchange, forward the request to Ethereum
|
||||
if (args != NULL) {
|
||||
if (args->id != 0x100) {
|
||||
os_sched_exit(0);
|
||||
}
|
||||
libcall_params[2] = args->command;
|
||||
libcall_params[4] = (unsigned int) args->get_printable_amount;
|
||||
os_lib_call((unsigned int *) &libcall_params);
|
||||
((unsigned int *) arg0)[0] = libcall_params[1];
|
||||
// Ethereum fulfilled the request and returned to us. We return to Exchange.
|
||||
os_lib_end();
|
||||
} else {
|
||||
// launch coin application
|
||||
libcall_params[1] = 0x100; // use the Init call, as we won't exit
|
||||
// Clone called from Dashboard, start Ethereum
|
||||
libcall_params[2] = RUN_APPLICATION;
|
||||
// On Stax, forward our icon to Ethereum
|
||||
#ifdef HAVE_NBGL
|
||||
const char app_name[] = APPNAME;
|
||||
caller_app_t capp;
|
||||
nbgl_icon_details_t icon_details;
|
||||
uint8_t bitmap[sizeof(ICONBITMAP)];
|
||||
|
||||
memcpy(&icon_details, &ICONGLYPH, sizeof(ICONGLYPH));
|
||||
memcpy(&bitmap, &ICONBITMAP, sizeof(bitmap));
|
||||
icon_details.bitmap = (const uint8_t *) bitmap;
|
||||
capp.name = app_name;
|
||||
capp.icon = &icon_details;
|
||||
libcall_params[4] = (unsigned int) &capp;
|
||||
#else
|
||||
libcall_params[4] = 0;
|
||||
#endif // HAVE_NBGL
|
||||
os_lib_call((unsigned int *) &libcall_params);
|
||||
// Ethereum should not return to us
|
||||
os_sched_exit(-1);
|
||||
}
|
||||
}
|
||||
FINALLY {
|
||||
}
|
||||
}
|
||||
END_TRY;
|
||||
// no return
|
||||
#else
|
||||
|
||||
// os_lib_call will raise if Ethereum application is not installed. Do not try to recover.
|
||||
os_sched_exit(-1);
|
||||
}
|
||||
|
||||
int ethereum_main(libargs_t *args) {
|
||||
// exit critical section
|
||||
__asm volatile("cpsie i");
|
||||
|
||||
// ensure exception will work as planned
|
||||
os_boot();
|
||||
|
||||
if (!arg0) {
|
||||
if (args == NULL) {
|
||||
// called from dashboard as standalone eth app
|
||||
coin_main(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
libargs_t *args = (libargs_t *) arg0;
|
||||
if (args->id != 0x100) {
|
||||
app_exit();
|
||||
return 0;
|
||||
@@ -838,6 +846,13 @@ __attribute__((section(".boot"))) int main(int arg0) {
|
||||
// called as ethereum or altcoin library
|
||||
library_main(args);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((section(".boot"))) int main(int arg0) {
|
||||
#ifdef USE_LIB_ETHEREUM
|
||||
clone_main((libargs_t *) arg0);
|
||||
#else
|
||||
return ethereum_main((libargs_t *) arg0);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user