/* Initialise the resolver. Open a socket and bind it to the address of the server. return -1 if something goes wrong, otherwise 0. If we are being called a second time we have to be careful to allow any ongoing lookups to finish before we close the socket and connect to a different DNS server. The danger here is that we may have to wait for upto 32 seconds if the DNS server is down. */ int cyg_dns_res_init(struct in_addr *dns_server) { struct sockaddr_in server; struct servent *sent; static int init =0; CYG_REPORT_FUNCNAMETYPE( "cyg_dns_res_init", "returning %d" ); CYG_REPORT_FUNCARG1( "dns_server=%08x", dns_server ); CYG_CHECK_DATA_PTR( dns_server, "dns_server is not a valid pointer!" ); if (init) { cyg_drv_mutex_lock(&dns_mutex); cyg_thread_free_data_index(ptdindex); if (s >= 0) { close(s); } } else { init = 1; cyg_drv_mutex_init(&dns_mutex); cyg_drv_mutex_lock(&dns_mutex); } s = socket(PF_INET, SOCK_DGRAM, 0); if (s < 0) { cyg_drv_mutex_unlock(&dns_mutex); CYG_REPORT_RETVAL( -1 ); return -1; } sent = getservbyname("domain", "udp"); if (sent == (struct servent *)0) { s = -1; cyg_drv_mutex_unlock(&dns_mutex); CYG_REPORT_RETVAL( -1 ); return -1; } memcpy((char *)&server.sin_addr, (const void *)dns_server, sizeof(server.sin_addr)); server.sin_port = sent->s_port; server.sin_family = AF_INET; server.sin_len = sizeof(server); if (connect(s, (struct sockaddr *)&server, sizeof(server)) < 0) { s = -1; cyg_drv_mutex_unlock(&dns_mutex); CYG_REPORT_RETVAL( -1 ); return -1; } ptdindex = cyg_thread_new_data_index(); cyg_drv_mutex_unlock(&dns_mutex); CYG_REPORT_RETVAL( 0 ); return 0; }
static void startup(CYG_ADDRESS data) { cyg_ucount32 pdc_data_index; struct _pdc_app_entry *pdc; printf("SYSTEM INITIALIZATION in progress\n"); #ifdef USE_JFFS2 { int res; printf("... Mounting JFFS2 on \"/\"\n"); res = mount(CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2"); if (res < 0) { printf("Mount \"/\" failed - res: %d\n", res); } chdir("/"); } #endif pdc_data_index = cyg_thread_new_data_index(); printf("data index = %d\n", pdc_data_index); printf("Creating system threads\n"); for (pdc = __PDC_APP_TAB__; pdc != &__PDC_APP_TAB_END__; pdc++) { printf("Creating %s thread\n", pdc->name); cyg_thread_create(pdc->prio, pdc->entry, (cyg_addrword_t) pdc_data_index, pdc->name, (void *) pdc->stack, STACKSIZE, &pdc->t, &pdc->t_obj); } printf("Starting threads\n"); for (pdc = __PDC_APP_TAB__; pdc != &__PDC_APP_TAB_END__; pdc++) { printf("Starting %s\n", pdc->name); cyg_thread_resume(pdc->t); if (pdc->init) { (pdc->init) (pdc_data_index); } } printf("SYSTEM THREADS STARTED!\n"); }
static void startup_thread(CYG_ADDRESS data) { cyg_ucount32 nanox_data_index; int i; struct nx_thread *nx; printf("SYSTEM INITIALIZATION in progress\n"); printf("NETWORK:\n"); init_all_network_interfaces(); #ifdef USE_ROMDISK { char ROM_fs[32]; int res; printf("Mount ROM file system\n"); #ifdef CYGPKG_HAL_ARM_SA11X0_IPAQ // Work around hardware anomaly which causes major screen flicker { char *hold_rom_fs; if ((hold_rom_fs = malloc(0x80080)) != 0) { // Note: ROM fs requires 32 byte alignment hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31); memcpy(hold_rom_fs, 0x50F00000, 0x80000); sprintf(ROM_fs, "0x%08x", hold_rom_fs); } else { printf("Can't allocate memory to hold ROM fs!\n"); } } #else sprintf(ROM_fs, "0x%08x", 0x50F00000); sprintf(ROM_fs, "0x%08x", 0x61F00000); #endif printf("ROM fs at %s\n", ROM_fs); if ((res = mount(ROM_fs, "/", "romfs")) < 0) { printf("... failed\n"); } chdir("/"); } #endif #ifdef USE_JFFS2 { int res; printf("... Mounting JFFS2 on \"/\"\n"); res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" ); if (res < 0) { printf("Mount \"/\" failed - res: %d\n", res); } chdir("/"); } #endif // Allocate a free thread data slot // Note: all MicroWindows/NanoX threads use this slot for NanoX-private // data. That's why there is only one call here. nanox_data_index = cyg_thread_new_data_index(); printf("data index = %d\n", nanox_data_index); printf("Creating system threads\n"); nx = &_threads[1]; for (i = 1; i < NUM(_threads); i++, nx++) { cyg_thread_create(nx->prio, nx->entry, (cyg_addrword_t) nanox_data_index, nx->name, (void *)nx->stack, STACKSIZE, &nx->t, &nx->t_obj); } printf("Starting threads\n"); nx = &_threads[1]; for (i = 1; i < NUM(_threads); i++, nx++) { printf("Starting %s\n", nx->name); cyg_thread_resume(nx->t); // Special case - run additional code, specific to this environment // only after the server has had a chance to startup if (i == 2) { ecos_nx_init(nanox_data_index); } } printf("SYSTEM THREADS STARTED!\n"); }
static void startup(CYG_ADDRESS data) { cyg_ucount32 nanox_data_index; struct _mw_app_entry *nx; printf("SYSTEM INITIALIZATION in progress\n"); printf("NETWORK:\n"); init_all_network_interfaces(); #ifdef USE_ROMDISK { char ROM_fs[32]; int res; printf("Mount ROM file system\n"); #if (defined CYGPKG_HAL_ARM_SA11X0_IPAQ) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS) // Work around hardware anomaly which causes major screen flicker { char *hold_rom_fs; if ((hold_rom_fs = malloc(0x80080)) != 0) { // Note: ROM fs requires 32 byte alignment hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31); memcpy(hold_rom_fs, 0x50F00000, 0x80000); sprintf(ROM_fs, "0x%08x", hold_rom_fs); } else { printf("Can't allocate memory to hold ROM fs!\n"); } } #else sprintf(ROM_fs, "0x%08x", 0x50F00000); sprintf(ROM_fs, "0x%08x", 0x61F00000); #endif printf("ROM fs at %s\n", ROM_fs); if ((res = mount(ROM_fs, "/", "romfs")) < 0) { printf("... failed\n"); } chdir("/"); } #endif #ifdef USE_JFFS2 { int res; printf("... Mounting JFFS2 on \"/\"\n"); res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" ); if (res < 0) { printf("Mount \"/\" failed - res: %d\n", res); } chdir("/"); } #endif // Allocate a free thread data slot // Note: all MicroWindows/NanoX threads use this slot for NanoX-private // data. That's why there is only one call here. nanox_data_index = cyg_thread_new_data_index(); printf("data index = %d\n", nanox_data_index); printf("Creating system threads\n"); for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__; nx++) { printf("Creating %s thread\n", nx->name); cyg_thread_create(nx->prio, nx->entry, (cyg_addrword_t) nanox_data_index, nx->name, (void *)nx->stack, STACKSIZE, &nx->t, &nx->t_obj); } printf("Starting threads\n"); for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__; nx++) { printf("Starting %s\n", nx->name); cyg_thread_resume(nx->t); if (nx->init) { (nx->init)(nanox_data_index); } } printf("SYSTEM THREADS STARTED!\n"); }