int thttp_main(int argc, char *argv[]) #endif { struct in_addr addr; #ifdef CONFIG_EXAMPLES_THTTPD_NOMAC uint8_t mac[IFHWADDRLEN]; #endif char *thttpd_argv = "thttpd"; int ret; /* Configure SLIP */ #ifdef CONFIG_NET_SLIP ret = slip_initialize(SLIP_DEVNO, CONFIG_NET_SLIPTTY); if (ret < 0) { printf("ERROR: SLIP initialization failed: %d\n", ret); exit(1); } #endif /* Many embedded network interfaces must have a software assigned MAC */ #ifdef CONFIG_EXAMPLES_THTTPD_NOMAC printf("Assigning MAC\n"); mac[0] = 0x00; mac[1] = 0xe0; mac[2] = 0xde; mac[3] = 0xad; mac[4] = 0xbe; mac[5] = 0xef; netlib_setmacaddr(NET_DEVNAME, mac); #endif /* Set up our host address */ printf("Setup network addresses\n"); addr.s_addr = HTONL(CONFIG_THTTPD_IPADDR); netlib_sethostaddr(NET_DEVNAME, &addr); /* Set up the default router address */ addr.s_addr = HTONL(CONFIG_EXAMPLES_THTTPD_DRIPADDR); netlib_setdraddr(NET_DEVNAME, &addr); /* Setup the subnet mask */ addr.s_addr = HTONL(CONFIG_EXAMPLES_THTTPD_NETMASK); netlib_setnetmask(NET_DEVNAME, &addr); /* Initialize the NXFLAT binary loader */ printf("Initializing the NXFLAT binary loader\n"); ret = nxflat_initialize(); if (ret < 0) { printf("ERROR: Initialization of the NXFLAT loader failed: %d\n", ret); exit(2); } /* Create a ROM disk for the ROMFS filesystem */ printf("Registering romdisk\n"); ret = romdisk_register(0, (uint8_t*)romfs_img, NSECTORS(romfs_img_len), SECTORSIZE); if (ret < 0) { printf("ERROR: romdisk_register failed: %d\n", ret); nxflat_uninitialize(); exit(1); } /* Mount the file system */ printf("Mounting ROMFS filesystem at target=%s with source=%s\n", MOUNTPT, ROMFSDEV); ret = mount(ROMFSDEV, MOUNTPT, "romfs", MS_RDONLY, NULL); if (ret < 0) { printf("ERROR: mount(%s,%s,romfs) failed: %s\n", ROMFSDEV, MOUNTPT, errno); nxflat_uninitialize(); } /* Start THTTPD. At present, symbol table info is passed via global variables */ g_thttpdsymtab = exports; g_thttpdnsymbols = NEXPORTS; printf("Starting THTTPD\n"); fflush(stdout); thttpd_main(1, &thttpd_argv); printf("THTTPD terminated\n"); fflush(stdout); return 0; }
int nxflat_main(int argc, char *argv[]) { struct binary_s bin; int ret; int i; /* Initialize the NXFLAT binary loader */ message("Initializing the NXFLAT binary loader\n"); ret = nxflat_initialize(); if (ret < 0) { err("ERROR: Initialization of the NXFLAT loader failed: %d\n", ret); exit(1); } /* Create a ROM disk for the ROMFS filesystem */ message("Registering romdisk\n"); ret = romdisk_register(0, romfs_img, NSECTORS(romfs_img_len), SECTORSIZE); if (ret < 0) { err("ERROR: romdisk_register failed: %d\n", ret); nxflat_uninitialize(); exit(1); } /* Mount the file system */ message("Mounting ROMFS filesystem at target=%s with source=%s\n", MOUNTPT, ROMFSDEV); ret = mount(ROMFSDEV, MOUNTPT, "romfs", MS_RDONLY, NULL); if (ret < 0) { err("ERROR: mount(%s,%s,romfs) failed: %s\n", ROMFSDEV, MOUNTPT, errno); nxflat_uninitialize(); } /* Now excercise every progrm in the ROMFS file system */ for (i = 0; dirlist[i]; i++) { testheader(dirlist[i]); memset(&bin, 0, sizeof(struct binary_s)); snprintf(path, 128, "%s/%s", MOUNTPT, dirlist[i]); bin.filename = path; bin.exports = exports; bin.nexports = NEXPORTS; ret = load_module(&bin); if (ret < 0) { err("ERROR: Failed to load program '%s'\n", dirlist[i]); exit(1); } ret = exec_module(&bin, 50); if (ret < 0) { err("ERROR: Failed to execute program '%s'\n", dirlist[i]); unload_module(&bin); } message("Wait a bit for test completion\n"); sleep(4); } message("End-of-Test.. Exit-ing\n"); return 0; }