int nsh_main(int argc, char *argv[]) { int exitval = 0; int ret; /* Call all C++ static constructors */ #if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) up_cxxinitialize(); #endif /* Make sure that we are using our symbol take */ #if defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_EXECFUNCS_SYMTAB) exec_setsymtab(CONFIG_EXECFUNCS_SYMTAB, 0); #endif /* Register the BINFS file system */ #if defined(CONFIG_FS_BINFS) && (CONFIG_BUILTIN) ret = builtin_initialize(); if (ret < 0) { fprintf(stderr, "ERROR: builtin_initialize failed: %d\n", ret); exitval = 1; } #endif /* Initialize the NSH library */ nsh_initialize(); /* If the Telnet console is selected as a front-end, then start the * Telnet daemon. */ #ifdef CONFIG_NSH_TELNET ret = nsh_telnetstart(); if (ret < 0) { /* The daemon is NOT running. Report the the error then fail... * either with the serial console up or just exiting. */ fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", ret); exitval = 1; } #endif /* If the serial console front end is selected, then run it on this thread */ #ifdef CONFIG_NSH_CONSOLE ret = nsh_consolemain(0, NULL); /* nsh_consolemain() should not return. So if we get here, something * is wrong. */ fprintf(stderr, "ERROR: nsh_consolemain() returned: %d\n", ret); exitval = 1; #endif return exitval; }
int spawn_main(int argc, char *argv[]) { posix_spawn_file_actions_t file_actions; posix_spawnattr_t attr; FAR const char *filepath; pid_t pid; int ret; /* Initialize the memory monitor */ mm_initmonitor(); /* Initialize the ELF binary loader */ message("Initializing the ELF binary loader\n"); ret = elf_initialize(); if (ret < 0) { err("ERROR: Initialization of the ELF loader failed: %d\n", ret); exit(1); } mm_update(&g_mmstep, "after elf_initialize"); /* Create a ROM disk for the ROMFS filesystem */ message("Registering romdisk at /dev/ram%d\n", CONFIG_EXAMPLES_ELF_DEVMINOR); ret = romdisk_register(CONFIG_EXAMPLES_ELF_DEVMINOR, (FAR uint8_t *)romfs_img, NSECTORS(romfs_img_len), SECTORSIZE); if (ret < 0) { err("ERROR: romdisk_register failed: %d\n", ret); elf_uninitialize(); exit(1); } mm_update(&g_mmstep, "after romdisk_register"); /* Mount the file system */ message("Mounting ROMFS filesystem at target=%s with source=%s\n", MOUNTPT, CONFIG_EXAMPLES_ELF_DEVPATH); ret = mount(CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, "romfs", MS_RDONLY, NULL); if (ret < 0) { err("ERROR: mount(%s,%s,romfs) failed: %s\n", CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, errno); elf_uninitialize(); } mm_update(&g_mmstep, "after mount"); /* Does the system support the PATH variable? Has the PATH variable * already been set? If YES and NO, then set the PATH variable to * the ROMFS mountpoint. */ #if defined(CONFIG_BINFMT_EXEPATH) && !defined(CONFIG_PATH_INITIAL) (void)setenv("PATH", MOUNTPT, 1); #endif /* Make sure that we are using our symbol take */ exec_setsymtab(exports, nexports); /************************************************************************* * Case 1: Simple program with arguments *************************************************************************/ /* Output a seperated so that we can clearly discriminate the output of * this program from the others. */ testheader(g_hello); /* Initialize the attributes file actions structure */ ret = posix_spawn_file_actions_init(&file_actions); if (ret != 0) { err("ERROR: posix_spawn_file_actions_init failed: %d\n", ret); } posix_spawn_file_actions_dump(&file_actions); ret = posix_spawnattr_init(&attr); if (ret != 0) { err("ERROR: posix_spawnattr_init failed: %d\n", ret); } posix_spawnattr_dump(&attr); mm_update(&g_mmstep, "after file_action/attr init"); /* If the binary loader does not support the PATH variable, then * create the full path to the executable program. Otherwise, * use the relative path so that the binary loader will have to * search the PATH variable to find the executable. */ #ifdef CONFIG_BINFMT_EXEPATH filepath = g_hello; #else snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_hello); filepath = fullpath; #endif /* Execute the program */ mm_update(&g_mmstep, "before posix_spawn"); ret = posix_spawn(&pid, filepath, &file_actions, &attr, NULL, (FAR char * const*)&g_argv); if (ret != 0) { err("ERROR: posix_spawn failed: %d\n", ret); } sleep(4); mm_update(&g_mmstep, "after posix_spawn"); /* Free attibutes and file actions */ ret = posix_spawn_file_actions_destroy(&file_actions); if (ret != 0) { err("ERROR: posix_spawn_file_actions_destroy failed: %d\n", ret); } posix_spawn_file_actions_dump(&file_actions); ret = posix_spawnattr_destroy(&attr); if (ret != 0) { err("ERROR: posix_spawnattr_destroy failed: %d\n", ret); } posix_spawnattr_dump(&attr); mm_update(&g_mmstep, "after file_action/attr destruction"); /************************************************************************* * Case 2: Simple program with redirection of stdin to a file input *************************************************************************/ /* Output a seperated so that we can clearly discriminate the output of * this program from the others. */ testheader(g_redirect); /* Initialize the attributes file actions structure */ ret = posix_spawn_file_actions_init(&file_actions); if (ret != 0) { err("ERROR: posix_spawn_file_actions_init failed: %d\n", ret); } posix_spawn_file_actions_dump(&file_actions); ret = posix_spawnattr_init(&attr); if (ret != 0) { err("ERROR: posix_spawnattr_init failed: %d\n", ret); } posix_spawnattr_dump(&attr); mm_update(&g_mmstep, "after file_action/attr init"); /* Set up to close stdin (0) and open testdata.txt as the program input */ ret = posix_spawn_file_actions_addclose(&file_actions, 0); if (ret != 0) { err("ERROR: posix_spawn_file_actions_addclose failed: %d\n", ret); } posix_spawn_file_actions_dump(&file_actions); snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_data); ret = posix_spawn_file_actions_addopen(&file_actions, 0, fullpath, O_RDONLY, 0644); if (ret != 0) { err("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret); } posix_spawn_file_actions_dump(&file_actions); mm_update(&g_mmstep, "after adding file_actions"); /* If the binary loader does not support the PATH variable, then * create the full path to the executable program. Otherwise, * use the relative path so that the binary loader will have to * search the PATH variable to find the executable. */ #ifdef CONFIG_BINFMT_EXEPATH filepath = g_redirect; #else snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_redirect); filepath = fullpath; #endif /* Execute the program */ mm_update(&g_mmstep, "before posix_spawn"); ret = posix_spawn(&pid, filepath, &file_actions, &attr, NULL, NULL); if (ret != 0) { err("ERROR: posix_spawn failed: %d\n", ret); } sleep(2); mm_update(&g_mmstep, "after posix_spawn"); /* Free attibutes and file actions */ ret = posix_spawn_file_actions_destroy(&file_actions); if (ret != 0) { err("ERROR: posix_spawn_file_actions_destroy failed: %d\n", ret); } posix_spawn_file_actions_dump(&file_actions); ret = posix_spawnattr_destroy(&attr); if (ret != 0) { err("ERROR: posix_spawnattr_destroy failed: %d\n", ret); } posix_spawnattr_dump(&attr); mm_update(&g_mmstep, "after file_action/attr destruction"); /* Clean-up */ elf_uninitialize(); mm_update(&g_mmstep, "End-of-Test"); return 0; }
int boardctl(unsigned int cmd, uintptr_t arg) { int ret; switch (cmd) { /* CMD: BOARDIOC_INIT * DESCRIPTION: Perform one-time application initialization. * ARG: None * CONFIGURATION: CONFIG_LIB_BOARDCTL * DEPENDENCIES: Board logic must provide board_app_initialization */ case BOARDIOC_INIT: { ret = board_app_initialize(); } break; #ifdef CONFIG_BOARDCTL_POWEROFF /* CMD: BOARDIOC_POWEROFF * DESCRIPTION: Power off the board * ARG: Integer value providing power off status information * CONFIGURATION: CONFIG_BOARDCTL_POWEROFF * DEPENDENCIES: Board logic must provide board_power_off */ case BOARDIOC_POWEROFF: { ret = board_power_off((int)arg); } break; #endif #ifdef CONFIG_BOARDCTL_RESET /* CMD: BOARDIOC_RESET * DESCRIPTION: Reset the board * ARG: Integer value providing power off status information * CONFIGURATION: CONFIG_BOARDCTL_RESET * DEPENDENCIES: Board logic must provide board_reset */ case BOARDIOC_RESET: { ret = board_reset((int)arg); } break; #endif #ifdef CONFIG_BOARDCTL_SYMTAB /* CMD: BOARDIOC_SYMTAB * DESCRIPTION: Select a symbol table * ARG: A pointer to an instance of struct boardioc_symtab_s * CONFIGURATION: CONFIG_BOARDCTL_SYMTAB * DEPENDENCIES: None */ case BOARDIOC_SYMTAB: { FAR const struct boardioc_symtab_s *symdesc = (FAR const struct boardioc_symtab_s *)arg; DEBUGASSERT(symdesc != NULL); exec_setsymtab(symdesc->symtab, symdesc->nsymbols); ret = OK; } break; #endif #ifdef CONFIG_BOARDCTL_TSCTEST /* CMD: BOARDIOC_TSCTEST_SETUP * DESCRIPTION: Touchscreen controller test configuration * ARG: Touch controller device minor number * CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_TSCTEST * DEPENDENCIES: Board logic must provide board_tsc_setup() */ case BOARDIOC_TSCTEST_SETUP: { ret = board_tsc_setup((int)arg); } break; /* CMD: BOARDIOC_TSCTEST_TEARDOWN * DESCRIPTION: Touchscreen controller test configuration * ARG: None * CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_TSCTEST * DEPENDENCIES: Board logic must provide board_tsc_teardown() */ case BOARDIOC_TSCTEST_TEARDOWN: { board_tsc_teardown(); ret = OK; } break; #endif #ifdef CONFIG_BOARDCTL_ADCTEST /* CMD: BOARDIOC_ADCTEST_SETUP * DESCRIPTION: ADC controller test configuration * ARG: None * CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_ADCTEST * DEPENDENCIES: Board logic must provide board_adc_setup() */ case BOARDIOC_ADCTEST_SETUP: { ret = board_adc_setup(); } break; #endif #ifdef CONFIG_BOARDCTL_PWMTEST /* CMD: BOARDIOC_PWMTEST_SETUP * DESCRIPTION: PWM controller test configuration * ARG: None * CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_PWMTEST * DEPENDENCIES: Board logic must provide board_pwm_setup() */ case BOARDIOC_PWMTEST_SETUP: { ret = board_pwm_setup(); } break; #endif #ifdef CONFIG_BOARDCTL_CANINIT /* CMD: BOARDIOC_CAN_INITIALIZE * DESCRIPTION: CAN device initialization * ARG: None * CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_CANINIT * DEPENDENCIES: Board logic must provide board_can_initialize() */ case BOARDIOC_CAN_INITIALIZE: { ret = board_can_initialize(); } break; #endif #ifdef CONFIG_BOARDCTL_GRAPHICS /* CMD: BOARDIOC_GRAPHICS_SETUP * DESCRIPTION: Configure graphics that require special initialization * procedures * ARG: A pointer to an instance of struct boardioc_graphics_s * CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_GRAPHICS * DEPENDENCIES: Board logic must provide board_adc_setup() */ case BOARDIOC_GRAPHICS_SETUP: { FAR struct boardioc_graphics_s *setup = ( FAR struct boardioc_graphics_s *)arg; setup->dev = board_graphics_setup(setup->devno); ret = setup->dev ? OK : -ENODEV; } break; #endif default: { #ifdef CONFIG_BOARDCTL_IOCTL /* Boards may also select CONFIG_BOARDCTL_IOCTL=y to enable board- * specific commands. In this case, all commands not recognized * by boardctl() will be forwarded to the board-provided board_ioctl() * function. */ ret = board_ioctl(cmd, arg); #else ret = -ENOTTY; #endif } break; } /* Set the errno value on any errors */ if (ret < 0) { set_errno(-ret); return ERROR; } return OK; }