int main(int argc, char *argv[]) { init_cmd(); add_cmd("times", do_times, "Multiply"); add_cmd("plus", do_plus, "Add"); add_param("value", &value, "Value", NULL); add_quit_helper(app_quit); run_console(NULL); finish_cmd(); return 0; }
virtual int console_main(int argc, char_t** argv, char_t** env) { int err = 0, err2 = 0; if (!(err = before_get_cgi_form(argc, argv, env))) { if (!(err = get_cgi_form(argc, argv, env))) { if (!(err = before_run_console(argc, argv, env))) { if (!(err = run_console(argc, argv, env))) { } if ((err2 = after_run_console(argc, argv, env)) && (!err)) { err = err2; } } } if ((err2 = after_get_cgi_form(argc, argv, env)) && (!err)) { err = err2; } } return err; }
void app_main() { init_peripherals(); motor_a = new Motor(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM0A, MCPWM0B, GPIO_PWM0A_OUT, GPIO_PWM0B_OUT); motor_b = new Motor(MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM1A, MCPWM1B, GPIO_PWM1A_OUT, GPIO_PWM1B_OUT); printf("Press a key to enter console\n"); bool debug = false; for (int i = 0; i < 20; ++i) { if (getchar() != EOF) { debug = true; break; } vTaskDelay(100/portTICK_PERIOD_MS); } if (debug) run_console(); // never returns printf("\nStarting application\n"); xTaskCreate(&main_loop, "Main loop", 10240, NULL, 1, &xMainTask); }
/*f main */ extern int main( int argc, char **argv ) { int i, okay, gdb_enabled; int cycles; int r; unsigned int regs[16]; char *symbol_map; char *eth_device; unsigned int memory_regions[8][3]; unsigned int execution_regions[8][3]; file_desc files_to_load [8]; int nfiles_to_load = 0; int must_launch_minicom = 0; int use_single_pipeline = 0; memset (files_to_load, 0, sizeof(files_to_load)); /*b Set default values */ for (i=0; i<8; i++) { memory_regions[i][0] = 0; memory_regions[i][1] = 0; memory_regions[i][2] = 100; execution_regions[i][0] = 0; execution_regions[i][1] = 0; execution_regions[i][2] = 0; } // f=stdin; cycles=1000; gdb_enabled = 0; symbol_map = "../../os/linux/System.map"; eth_device = "eth3"; for (i=0; i<16; i++) { regs[i] = 0xdeadcafe; } // tty_fd = run_console (); // ether_init(eth_device); /*b Parse arguments */ for (i=1; i<argc; i++) { /*b '--' */ if (!strcmp( argv[i], "--" )) { files_to_load[nfiles_to_load++].fp = stdin; continue; } /*b '-a' */ if (!strcmp( argv[i], "-a" )) { i++; if (i<argc) { int base; if (sscanf( argv[i], "%x", &base)!=1) { fprintf( stderr, "Failed to parse '%s' for base address of load\n", argv[i] ); } files_to_load[nfiles_to_load].addr = base; } continue; } /*b '-b' */ if (!strcmp( argv[i], "-b" )) { files_to_load[nfiles_to_load].binary=1; continue; } /*b '-d' */ if (!strcmp( argv[i], "-d" )) { i++; if (i<argc) { if (sscanf( argv[i], "%d", &debug_level)!=1) { fprintf( stderr, "Failed to parse '%s' for debug mask\n", argv[i] ); } } continue; } /*b '-e' */ if (!strcmp( argv[i], "-e" )) { i++; if (i<argc) { eth_device = argv[i]; } continue; } /*b '-f' */ if (!strcmp( argv[i], "-f" )) { i++; if (i<argc) { FILE * fp = fopen(argv[i],"r"); if (!fp) { fprintf( stderr, "Failed to open file '%s'\n", argv[i] ); } files_to_load[nfiles_to_load].name = argv[i]; files_to_load[nfiles_to_load++].fp = fp; } continue; } /*b '-g' */ if (!strncmp (argv[i], "-g", 2)) { gdb_enabled = 1; continue; } /*b '-h' */ if (!strncmp (argv[i], "-h", 2)) { usage(); exit(0); } /*b '-r' */ if (!strncmp( argv[i], "-r", 2 )) { i++; if (i<argc) { if (sscanf( argv[i-1], "-r%d", &r)!=1) { fprintf( stderr, "Failed to parse '%s' for register initialization\n", argv[i] ); } regs[r&0xf] = strtoul(argv[i], NULL, 0); } continue; } /*b '-s' */ if (!strncmp( argv[i], "-s", 2 )) { i++; if (i<argc) { symbol_map = argv[i]; } continue; } /*b '-t' */ if (!strcmp( argv[i], "-t" )) { i++; if (i<argc) { if (sscanf( argv[i], "%d", &cycles)!=1) { fprintf( stderr, "Failed to parse '%s' for length of run\n", argv[i] ); } } continue; } /*b '-S' */ if (!strcmp( argv[i], "-S" )) { use_single_pipeline=1; continue; } /*b '-M' */ if (!strcmp( argv[i], "-M" )) { i+=3; if (i<argc) { int j; for (j=0; j<8; j++) { if (memory_regions[j][2]>4) { break; } } if (j<8) { if ( (sscanf( argv[i-2], "%08x", &memory_regions[j][0])!=1) || (sscanf( argv[i-1], "%08x", &memory_regions[j][1])!=1) || (sscanf( argv[i], "%d", &memory_regions[j][2])!=1) ) { fprintf( stderr, "Failed to parse arguments (hex start, hex end, int level) for memory tracing\n" ); } } } continue; } /*b '-T' */ if (!strcmp( argv[i], "-T" )) { i+=3; if (i<argc) { int j; if ((sscanf( argv[i-2], "%d", &j )==1) && (j>=0) && (j<8)) { if ( (sscanf( argv[i-1], "%08x", &execution_regions[j][0])!=1) || (sscanf( argv[i], "%08x", &execution_regions[j][1])!=1) ) { fprintf( stderr, "Failed to parse arguments (region, hex start, hex end) for exec tracing\n" ); } else { execution_regions[j][2] = 1; } } } continue; } /*b '-m' */ if (!strcmp (argv[i], "-m")) { must_launch_minicom = 1; } /*b All done */ } /*b Connect to system components (console, ethernet) */ tty_fd = run_console(); if (must_launch_minicom) launch_minicom(); ether_init(eth_device); /*b Build system */ ram = new c_ram_model( 1<<24 ); // Create RAM of size 1<<24 = 16MB memory = new c_memory_model(); if (0 && use_single_pipeline) { // c_gip_pipeline_single *gip_single; // gip_single = new c_gip_pipeline_single( memory ); // gip = (c_execution_model_class *)gip_single; } else { c_gip_full *gip_full; gip_full = new c_gip_full( memory ); gip = (c_execution_model_class *)gip_full; } zero_page_ram = new c_ram_model( 1<<24 ); // Create zero-pagee RAM of size 1<<24 = 16MB mmio = new c_mmio_model( gip ); // Create our standard MMIO model zero_page_ram->register_with_memory_map( memory, 0x00000000, 0x10000000 ); // Register zero-page RAM at 0x00000000 to 0xd0000000 ram->register_with_memory_map( memory, 0xc0000000, 0x10000000 ); // Register RAM at 0xc0000000 to 0xd0000000 mmio->register_with_memory_map( memory, 0xff000000, 0x00ffffff ); // Register MMIO at 0xff000000 to 0xfffffff memory->register_debug_handler( NULL, memory_model_debug ); // microkernel * ukernel = new microkernel(gip); // gip->register_microkernel (ukernel); /*b Load code and symbols */ for (i = 0; i < nfiles_to_load; i++) { file_desc * fdp = files_to_load + i; if (fdp->binary) { printf ("Loading binary file '%s' at %08x\n", fdp->name, fdp->addr); gip->load_code_binary( fdp->fp, fdp->addr ); } else { printf ("Loading text file '%s' at %08x\n", fdp->name, fdp->addr); gip->load_code( fdp->fp, fdp->addr ); } } for (i=0; i<16; i++) { gip->set_register( i, regs[i] ); } symbol_initialize( symbol_map ); /*b Set a signal handler */ signal (SIGUSR1, handle_user1); signal (SIGUSR2, handle_user2); /*b Enable memory logging and tracing of GIP */ // memory->set_log_file( "memory_model.log" ); for (i=0; i<8; i++) { if (memory_regions[i][2]<4) { memory->set_log_level( memory_regions[i][0], memory_regions[i][1]-memory_regions[i][0], memory_regions[i][2] ); } } gip->trace_set_file( "gip_exec_trace.log" ); for (i=0; i<8; i++) { if (execution_regions[i][2]) { gip->trace_region( i, execution_regions[i][0], execution_regions[i][1] ); // Trace execution in main ram } } /*b Initialize GDB server if required */ if (gdb_enabled) { printf ("Starting GDB interface...\n"); gdb_stub_init( gip, memory, mmio ); } else { gdb_stub_disable(); } /*b Run until completion, or forever if under gdb */ // time_to_next_irq = 100000; if (gdb_enabled) { int next_timer = get_ticks() + 1; int instruction_count; while (1) { if (sigusr1) { sigusr1 = 0; gdb_trap (5); } instruction_count = gdb_poll( okay ); if (instruction_count<=0) { instruction_count = 100000; } if (instruction_count > 50) instruction_count = 50; // if (instruction_count > time_to_next_irq) // instruction_count = time_to_next_irq; int actual_count = gip->step( &okay, instruction_count ); // time_to_next_irq -= actual_count; // if (ether_poll()) // ukernel->handle_interrupt (2); // if (keyboard_poll ()) // ukernel->handle_interrupt (1); if (get_ticks() > next_timer) { next_timer++; // ukernel->handle_interrupt (0); } } } else { int next_timer = get_ticks() + 1; // struct timeval tv; int instruction_count; int actual_count; int total_instructions = 0; int start_time = get_ticks(); okay = 0; while ((cycles>0) && (!okay)) { if (sigusr1) { sigusr1 = 0; } instruction_count = cycles; // if (instruction_count > time_to_next_irq) // instruction_count = time_to_next_irq; // if (instruction_count > 500) instruction_count = 500; if (instruction_count > 50) instruction_count = 50; actual_count = gip->step( &okay, instruction_count ); cycles -= actual_count; total_instructions += actual_count; // if (ether_poll()) // ukernel->handle_interrupt (2); // if (keyboard_poll ()) // ukernel->handle_interrupt (1); if (get_ticks() > next_timer) { next_timer++; // ukernel->handle_interrupt (0); } } } /*b Done */ }
static void prompt_and_wait() { char* menu_files[MAX_MENU_LEVEL] = { NULL }; char* menu_scripts[MAX_MENU_LEVEL] = { NULL }; int menu_sel[MAX_MENU_LEVEL] = { 0 }; unsigned int menu_level = 0; int menu_result; //always ensure if mountings are good ensure_common_roots_mounted(); //initialize the recovery -> either call the script for initalization, or switch to full version #if !OPEN_RCVR_VERSION_LITE run_shell_script("/bin/init_recovery.sh "OPEN_RECOVERY_PHONE_SWITCH, 1, NULL); #endif menu_files[0] = malloc(strlen(MAIN_MENU_FILE)+1); strcpy(menu_files[0], MAIN_MENU_FILE); ui_led_blink(1); create_menu(menu_files[0], menu_scripts[0]); ui_led_toggle(0); int title_length; char** headers; headers = prepend_title(MENU_HEADERS, &title_length); int override_initial_selection = -1; int call_finish_in_loop = 1; for (;;) { if (call_finish_in_loop) { finish_recovery(NULL); call_finish_in_loop = 0; } int menu_item; if (override_initial_selection != -1) { menu_item = get_menu_selection(headers, MENU_ITEMS, MENU_ITEMS_SELECTABLE, title_length, override_initial_selection, 0); override_initial_selection = -1; } else menu_item = get_menu_selection(headers, MENU_ITEMS, MENU_ITEMS_SELECTABLE, title_length, 0, 0); // Parse open recovery commands int chosen_item = select_action(menu_item); chosen_item = device_perform_action(chosen_item); //if tag, menu, or scripted menu -> don't hide menu //do it here explicitly, it would be a mess in the switch if (chosen_item != ITEM_TAG && chosen_item != ITEM_NEW_MENU && chosen_item != ITEM_NEW_MENU_SCRIPTED) hide_menu_selection(); fprintf(stderr, "Menu: %d, %d, %s\n", menu_item, chosen_item, MENU_ITEMS_TARGET[menu_item]); switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; ui_set_background(BACKGROUND_ICON_ERROR); break; case ITEM_WIPE_CACHE: ui_print("\n-- Wiping cache...\n"); ui_led_blink(1); erase_root("CACHE:"); ensure_common_roots_mounted(); ui_led_toggle(0); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; ui_set_background(BACKGROUND_ICON_ERROR); break; case ITEM_APPLY_SDCARD: //HACK for "error: a label can only be part of a statement and a declaration is not a statement" //the rule is retarted, the follwing "dummy" statement is cut in optimization override_initial_selection=override_initial_selection; //confirm it char* confirm_headers[] = { "Confirm installing update package?", MENU_ITEMS[menu_item], "", NULL }; char* confirm_items[] = { "Yes", "No", NULL }; int confirm_item = show_interactive_menu(confirm_headers, confirm_items); if (confirm_item == 1) //YES! { ui_print("\n-- Install from sdcard...\n"); ui_led_blink(1); ensure_common_roots_unmounted(); ensure_root_path_mounted("SDCARD:"); set_sdcard_update_bootloader_message(); call_finish_in_loop = 1; int status = install_package(MENU_ITEMS_TARGET[menu_item]); ensure_common_roots_mounted(); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } else if (!ui_text_visible()) return; // reboot if logs aren't visible else { if (firmware_update_pending()) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("\nReboot via menu to complete\n" "installation.\n"); } else { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("\nInstall from sdcard complete.\n"); } } create_menu(menu_files[menu_level], menu_scripts[menu_level]); free(headers); headers = prepend_title(MENU_HEADERS, &title_length); ui_led_toggle(0); } override_initial_selection = menu_item; break; case ITEM_SHELL_SCRIPT: ui_print("\n-- Shell script...\n"); ui_print("%s\n", MENU_ITEMS_TARGET[menu_item]); ui_led_blink(1); ensure_common_roots_mounted(); run_shell_script(MENU_ITEMS_TARGET[menu_item], 1, NULL); create_menu(menu_files[menu_level], menu_scripts[menu_level]); free(headers); headers = prepend_title(MENU_HEADERS, &title_length); ui_led_toggle(0); ui_print("Done.\n"); override_initial_selection = menu_item; break; case ITEM_TAG: if (MENU_ITEMS_TAG[menu_item] == 0x00) { int tag_fd = creat(MENU_ITEMS_TARGET[menu_item], 0644); if (tag_fd < 0) LOGE("Failed to set the tag.\n"); else { MENU_ITEMS_TAG[menu_item] = 0x01; MENU_ITEMS[menu_item][1] = 'X'; close(tag_fd); } } else if (MENU_ITEMS_TAG[menu_item] == 0x01) //just a little check if 0xFF aint there if bug is present { remove(MENU_ITEMS_TARGET[menu_item]); MENU_ITEMS_TAG[menu_item] = 0x00; MENU_ITEMS[menu_item][1] = ' '; } override_initial_selection = menu_item; break; case ITEM_NEW_MENU: if (menu_level + 1 >= MAX_MENU_LEVEL) { //too much menus, ignore break; } ui_led_blink(1); if (!strcmp(MENU_ITEMS_TARGET[menu_item], "..")) { if (menu_level) { free(menu_files[menu_level]); menu_files[menu_level] = NULL; if (menu_scripts[menu_level]) { free(menu_scripts[menu_level]); menu_scripts[menu_level] = NULL; } menu_sel[menu_level] = 0; menu_level--; override_initial_selection = menu_sel[menu_level]; } } else { menu_sel[menu_level] = menu_item; menu_level++; menu_files[menu_level] = malloc(strlen(MENU_ITEMS_TARGET[menu_item]) + 1); strcpy(menu_files[menu_level], MENU_ITEMS_TARGET[menu_item]); } ensure_common_roots_mounted(); menu_result = create_menu(menu_files[menu_level], menu_scripts[menu_level]); //if fail, remove the new menu if (menu_result && menu_level) { free(menu_files[menu_level]); menu_files[menu_level] = NULL; if (menu_scripts[menu_level]) { free(menu_scripts[menu_level]); menu_scripts[menu_level] = NULL; } menu_level--; } free(headers); headers = prepend_title(MENU_HEADERS, &title_length); ui_led_toggle(0); break; case ITEM_NEW_MENU_SCRIPTED: if (menu_level + 1 >= MAX_MENU_LEVEL) { //too much menus, ignore break; } ui_led_blink(1); char cmdBuff[MAX_LINE_LENGTH]; strcpy(cmdBuff, MENU_ITEMS_TARGET[menu_item]); char* ptr; //menufile:script ptr = strtok(cmdBuff, ":"); if (ptr != NULL) { menu_sel[menu_level] = menu_item; menu_level++; menu_files[menu_level] = malloc(strlen(ptr) + 1); strcpy(menu_files[menu_level], ptr); ptr = strtok(NULL, ""); if (ptr != NULL) { if (ptr[0] == '/' || (ptr[0] == '\"' && ptr[1] == '/')) { menu_scripts[menu_level] = malloc(strlen(ptr) + 1); strcpy(menu_scripts[menu_level], ptr); } else { menu_scripts[menu_level] = malloc(strlen(CUSTOM_SHELL_SCRIPT_PATH) + strlen(ptr) + 2); if (ptr[0] == '\"') sprintf(menu_scripts[menu_level], "\"%s/%s", CUSTOM_SHELL_SCRIPT_PATH, ptr+1); else sprintf(menu_scripts[menu_level], "%s/%s", CUSTOM_SHELL_SCRIPT_PATH, ptr); } } ensure_common_roots_mounted(); menu_result = create_menu(menu_files[menu_level], menu_scripts[menu_level]); //if fail, remove the new menu if (menu_result && menu_level) { free(menu_files[menu_level]); menu_files[menu_level] = NULL; if (menu_scripts[menu_level]) { free(menu_scripts[menu_level]); menu_scripts[menu_level] = NULL; } menu_level--; } free(headers); headers = prepend_title(MENU_HEADERS, &title_length); } ui_led_toggle(0); break; case ITEM_CONSOLE: #if OPEN_RECOVERY_HAVE_CONSOLE ensure_common_roots_mounted(); ui_print("Opening console...\n"); int console_error = run_console(NULL); if (console_error) if (console_error == CONSOLE_FORCE_QUIT) ui_print("Console was forcibly closed.\n"); else if (console_error == CONSOLE_FAILED_START) ui_print("Console failed to start.\n"); else { ui_print("Closing console...\n"); //don't bother printing error to UI fprintf(stderr, "Console closed with error %d.\n", console_error); } else ui_print("Closing console...\n"); create_menu(menu_files[menu_level], menu_scripts[menu_level]); free(headers); headers = prepend_title(MENU_HEADERS, &title_length); #else LOGE("This phone doesn't support console.\n"); #endif override_initial_selection = menu_item; break; case ITEM_ERROR: LOGE("Unknown command: %s.\n", MENU_ITEMS_ACTION[menu_item]); break; } } }