/* * Copyright 2010 Stefan Lankes, Chair for Operating Systems, * RWTH Aachen University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This file is part of MetalSVM. */ #include #include #include #include #include #include #include #include #include #ifdef CONFIG_LWIP #include #include #include #include #include #include #include #include #include #include #endif #include #include #include #ifdef CONFIG_ROCKCREEK #include #include #endif void echo_init(void); void ping_init(void); void netio_init(void); int test_init(void); /* * Note that linker symbols are not variables, they have no memory allocated for * maintaining a value, rather their address is their value. */ extern const void bss_start; extern const void bss_end; int lowlevel_init(void) { // initialize .bss section memset((void*)&bss_start, 0x00, ((size_t) &bss_end - (size_t) &bss_start)); koutput_init(); //kprintf("Now, the BSS section (0x%x - 0x%x) is initialized.\n", (size_t) &bss_start, (size_t) &bss_end); return 0; } #if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK)) static struct netif* default_netif = NULL; static int init_netifs(void) { struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; kputs("Initialize NICs...\n"); // Set up the lwIP network interface // Allocate and configure netif default_netif = (struct netif *) mem_malloc(sizeof(struct netif)); if(default_netif == NULL) { kprintf("ERROR: Out of memory for default netif\n"); return -ENOMEM; } memset(default_netif, 0x00, sizeof(struct netif)); #ifdef CONFIG_ROCKCREEK /* Set network address variables */ IP4_ADDR(&gw, 192,168,28,254); IP4_ADDR(&ipaddr, 192,168,28,RCCE_ue()+1); IP4_ADDR(&netmask, 255,255,255,0); /* Bring up the network interface */ if (!netif_add(default_netif, &ipaddr, &netmask, &gw, NULL, rckemacif_init, tcpip_input)) { kputs("Unable to add network interface\n"); return -ENODEV; } netif_set_default(default_netif); netif_set_up(default_netif); //mmnif_open(); #else /* Clear network address because we use DHCP to get an ip address */ IP4_ADDR(&gw, 0,0,0,0); IP4_ADDR(&ipaddr, 0,0,0,0); IP4_ADDR(&netmask, 0,0,0,0); /* Bring up the network interface */ if (!netif_add(default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, tcpip_input)) { kputs("Unable to add network interface\n"); return -ENODEV; } netif_set_default(default_netif); kprintf("Starting DHCPCD...\n"); dhcp_start(default_netif); #endif return 0; } #endif #ifdef CONFIG_LWIP static void tcpip_init_done(void* arg) { sys_sem_t* sem = (sys_sem_t*)arg; #if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK)) init_netifs(); #endif sys_sem_signal(sem); } #endif #ifdef CONFIG_LWIP static int network_shutdown(void) { #ifdef CONFIG_ROCKCREEK if (default_netif) { netif_set_link_down(default_netif); mem_free(default_netif); default_netif = NULL; } //mmnif_close(); #elif defined(CONFIG_PCI) if (default_netif) { dhcp_release(default_netif); dhcp_stop(default_netif); mem_free(default_netif); default_netif = NULL; } #endif return 0; } #endif int shutdown(void) { #ifdef CONFIG_LWIP return network_shutdown(); #else return 0; #endif } static void list_fs(vfs_node_t* node, uint32_t depth) { int j, i = 0; dirent_t* dirent = NULL; fildes_t* file = kmalloc(sizeof(fildes_t)); file->offset = 0; file->flags = 0; while ((dirent = readdir_fs(node, i)) != 0) { for(j=0; jname); if (strcmp(dirent->name, ".") && strcmp(dirent->name, "..")) { vfs_node_t *new_node = finddir_fs(node, dirent->name); if (new_node) { if (new_node->type == FS_FILE) { char buff[16] = {[0 ... 15] = 0x00}; file->node = new_node; file->offset = 0; file->flags = 0; read_fs(file, (uint8_t*)buff, 8); for(j=0; jip_addr.addr) { sys_msleep(DHCP_FINE_TIMER_MSECS); dhcp_fine_tmr(); mscnt += DHCP_FINE_TIMER_MSECS; if (mscnt >= DHCP_COARSE_TIMER_SECS*1000) { dhcp_coarse_tmr(); mscnt = 0; } } #endif // start echo, ping and/or netio server //echo_init(); //ping_init(); //netio_init(); #endif //list_root(); test_init(); return 0; }