| 1 | /* |
|---|
| 2 | * sysinit-wrt300nv2.c |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2006 Sebastian Gottschall <gottschall@dd-wrt.com> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or |
|---|
| 7 | * modify it under the terms of the GNU General Public License |
|---|
| 8 | * as published by the Free Software Foundation; either version 2 |
|---|
| 9 | * of the License, or (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | * |
|---|
| 20 | * $Id: |
|---|
| 21 | * |
|---|
| 22 | * System Initialisation for Avila Gateworks and compatible Routers |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | #include <stdio.h> |
|---|
| 26 | #include <stdlib.h> |
|---|
| 27 | #include <limits.h> |
|---|
| 28 | #include <time.h> |
|---|
| 29 | #include <unistd.h> |
|---|
| 30 | #include <errno.h> |
|---|
| 31 | #include <syslog.h> |
|---|
| 32 | #include <signal.h> |
|---|
| 33 | #include <string.h> |
|---|
| 34 | #include <termios.h> |
|---|
| 35 | #include <sys/klog.h> |
|---|
| 36 | #include <sys/types.h> |
|---|
| 37 | #include <sys/mount.h> |
|---|
| 38 | #include <sys/reboot.h> |
|---|
| 39 | #include <sys/stat.h> |
|---|
| 40 | #include <sys/sysmacros.h> |
|---|
| 41 | #include <sys/time.h> |
|---|
| 42 | #include <sys/utsname.h> |
|---|
| 43 | #include <sys/wait.h> |
|---|
| 44 | |
|---|
| 45 | #include <bcmnvram.h> |
|---|
| 46 | #include <shutils.h> |
|---|
| 47 | #include <utils.h> |
|---|
| 48 | #include <cymac.h> |
|---|
| 49 | |
|---|
| 50 | void start_sysinit( void ) |
|---|
| 51 | { |
|---|
| 52 | struct utsname name; |
|---|
| 53 | struct stat tmp_stat; |
|---|
| 54 | time_t tm = 0; |
|---|
| 55 | |
|---|
| 56 | unlink( "/etc/nvram/.lock" ); |
|---|
| 57 | cprintf( "sysinit() proc\n" ); |
|---|
| 58 | /* |
|---|
| 59 | * /proc |
|---|
| 60 | */ |
|---|
| 61 | mount( "proc", "/proc", "proc", MS_MGC_VAL, NULL ); |
|---|
| 62 | // system2 ("/etc/convert"); |
|---|
| 63 | mount( "sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL ); |
|---|
| 64 | cprintf( "sysinit() tmp\n" ); |
|---|
| 65 | |
|---|
| 66 | /* |
|---|
| 67 | * /tmp |
|---|
| 68 | */ |
|---|
| 69 | mount( "ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL ); |
|---|
| 70 | mount( "devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL ); |
|---|
| 71 | /* |
|---|
| 72 | * eval("mount","/etc/www.fs","/www","-t","squashfs","-o","loop"); |
|---|
| 73 | * eval("mount","/etc/modules.fs","/lib/modules","-t","squashfs","-o","loop"); |
|---|
| 74 | * eval("mount","/etc/usr.fs","/usr","-t","squashfs","-o","loop"); |
|---|
| 75 | */ |
|---|
| 76 | eval( "mkdir", "/tmp/www" ); |
|---|
| 77 | eval( "mknod", "/dev/gpio", "c", "127", "0" ); |
|---|
| 78 | eval( "mknod", "/dev/nvram", "c", "229", "0" ); |
|---|
| 79 | eval( "mknod", "/dev/ppp", "c", "108", "0" ); |
|---|
| 80 | eval( "mknod", "/dev/rtc", "c", "254", "0" ); |
|---|
| 81 | eval( "mknod", "/dev/crypto", "c", "10", "70" ); |
|---|
| 82 | eval( "mount", "-o", "remount,rw", "/" ); |
|---|
| 83 | |
|---|
| 84 | unlink( "/tmp/nvram/.lock" ); |
|---|
| 85 | eval( "mkdir", "/tmp/nvram" ); |
|---|
| 86 | // #ifdef HAVE_REGISTER |
|---|
| 87 | // #else |
|---|
| 88 | // eval ("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); |
|---|
| 89 | // #endif |
|---|
| 90 | // mkdir ("/usr/local/nvram", 0777); |
|---|
| 91 | // unlink ("/tmp/nvram/.lock"); |
|---|
| 92 | // eval ("mkdir", "/tmp/nvram"); |
|---|
| 93 | // eval ("cp", "/etc/nvram/nvram.db", "/tmp/nvram"); |
|---|
| 94 | // eval ("cp", "/etc/nvram/offsets.db", "/tmp/nvram"); |
|---|
| 95 | cprintf( "sysinit() var\n" ); |
|---|
| 96 | |
|---|
| 97 | /* |
|---|
| 98 | * /var |
|---|
| 99 | */ |
|---|
| 100 | mkdir( "/tmp/var", 0777 ); |
|---|
| 101 | mkdir( "/var/lock", 0777 ); |
|---|
| 102 | mkdir( "/var/log", 0777 ); |
|---|
| 103 | mkdir( "/var/run", 0777 ); |
|---|
| 104 | mkdir( "/var/tmp", 0777 ); |
|---|
| 105 | |
|---|
| 106 | eval( "watchdog" ); // system watchdog |
|---|
| 107 | |
|---|
| 108 | cprintf( "sysinit() setup console\n" ); |
|---|
| 109 | |
|---|
| 110 | /* |
|---|
| 111 | * Setup console |
|---|
| 112 | */ |
|---|
| 113 | |
|---|
| 114 | cprintf( "sysinit() klogctl\n" ); |
|---|
| 115 | klogctl( 8, NULL, atoi( nvram_safe_get( "console_loglevel" ) ) ); |
|---|
| 116 | cprintf( "sysinit() get router\n" ); |
|---|
| 117 | |
|---|
| 118 | /* |
|---|
| 119 | * Modules |
|---|
| 120 | */ |
|---|
| 121 | uname( &name ); |
|---|
| 122 | nvram_set( "intel_eth", "0" ); |
|---|
| 123 | |
|---|
| 124 | #if 1 |
|---|
| 125 | insmod( "ixp400th" ); |
|---|
| 126 | insmod( "ixp400" ); |
|---|
| 127 | system2( "cat /usr/lib/firmware/IxNpeMicrocode.dat > /dev/IxNpe" ); |
|---|
| 128 | insmod( "ixp400_eth" ); |
|---|
| 129 | eval( "ifconfig", "ixp0", "0.0.0.0", "up" ); |
|---|
| 130 | eval( "ifconfig", "ixp1", "0.0.0.0", "up" ); |
|---|
| 131 | insmod( "ocf" ); |
|---|
| 132 | insmod( "cryptodev" ); |
|---|
| 133 | // insmod("ixp4xx", "init_crypto=0"); |
|---|
| 134 | #else |
|---|
| 135 | // eval ("mknod", "/dev/IxNpe","c","10","184"); |
|---|
| 136 | system2( "cat /usr/lib/firmware/NPE-B > /dev/misc/ixp4xx_ucode" ); |
|---|
| 137 | system2( "cat /usr/lib/firmware/NPE-C > /dev/misc/ixp4xx_ucode" ); |
|---|
| 138 | #endif |
|---|
| 139 | |
|---|
| 140 | insmod( "ath_hal" ); |
|---|
| 141 | insmod( "ath_pci" ); |
|---|
| 142 | |
|---|
| 143 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 144 | insmod( "ath_mimo_pci" ); |
|---|
| 145 | #endif |
|---|
| 146 | // insmod("ath_pci", "rfkill=0", "autocreate=none"); |
|---|
| 147 | |
|---|
| 148 | /* |
|---|
| 149 | * if (ifexists ("wifi0")) eval ("ifconfig", "wifi0", "up"); if (ifexists |
|---|
| 150 | * ("wifi1")) eval ("ifconfig", "wifi1", "up"); if (ifexists ("wifi2")) |
|---|
| 151 | * eval ("ifconfig", "wifi2", "up"); if (ifexists ("wifi3")) eval |
|---|
| 152 | * ("ifconfig", "wifi3", "up"); if (ifexists ("wifi4")) eval ("ifconfig", |
|---|
| 153 | * "wifi4", "up"); if (ifexists ("wifi5")) eval ("ifconfig", "wifi5", |
|---|
| 154 | * "up"); |
|---|
| 155 | */ |
|---|
| 156 | |
|---|
| 157 | /* |
|---|
| 158 | * Configure mac addresses by reading data from eeprom |
|---|
| 159 | */ |
|---|
| 160 | // char *filename = |
|---|
| 161 | // "/sys/devices/platform/IXP4XX-I2C.0/i2c-0/0-0051/eeprom"; /* |
|---|
| 162 | // bank2=0x100 */ |
|---|
| 163 | char *filename = "/dev/mtdblock/0"; /* bank2=0x100 */ |
|---|
| 164 | FILE *file = fopen( filename, "r" ); |
|---|
| 165 | |
|---|
| 166 | if( file ) |
|---|
| 167 | { |
|---|
| 168 | unsigned char buf[16]; |
|---|
| 169 | |
|---|
| 170 | fseek( file, 0x5ffa0, SEEK_SET ); // point of mac address |
|---|
| 171 | fread( &buf[0], 6, 1, file ); |
|---|
| 172 | char mac[16]; |
|---|
| 173 | |
|---|
| 174 | sprintf( mac, "%02x:%02x:%02x:%02x:%02x:%02x", buf[0], buf[1], buf[2], |
|---|
| 175 | buf[3], buf[4], buf[5] ); |
|---|
| 176 | fprintf( stderr, "configure primary mac %s\n", mac ); |
|---|
| 177 | eval( "ifconfig", "ixp0", "hw", "ether", mac ); |
|---|
| 178 | eval( "ifconfig", "wifi0", "hw", "ether", mac ); |
|---|
| 179 | nvram_set( "et0macaddr", mac ); |
|---|
| 180 | MAC_ADD( mac ); |
|---|
| 181 | fprintf( stderr, "configure secondary mac %s\n", mac ); |
|---|
| 182 | eval( "ifconfig", "ixp1", "hw", "ether", mac ); |
|---|
| 183 | |
|---|
| 184 | fclose( file ); |
|---|
| 185 | } |
|---|
| 186 | eval( "ifconfig", "ixp0", "0.0.0.0", "up" ); |
|---|
| 187 | eval( "ifconfig", "ixp1", "0.0.0.0", "up" ); |
|---|
| 188 | |
|---|
| 189 | /* |
|---|
| 190 | * Set a sane date |
|---|
| 191 | */ |
|---|
| 192 | stime( &tm ); |
|---|
| 193 | nvram_set( "wl0_ifname", "ath0" ); |
|---|
| 194 | |
|---|
| 195 | nvram_set( "use_crypto", "0" ); |
|---|
| 196 | cprintf( "done\n" ); |
|---|
| 197 | return 0; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | int check_cfe_nv( void ) |
|---|
| 201 | { |
|---|
| 202 | nvram_set( "portprio_support", "0" ); |
|---|
| 203 | return 0; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | int check_pmon_nv( void ) |
|---|
| 207 | { |
|---|
| 208 | return 0; |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | void start_overclocking( void ) |
|---|
| 212 | { |
|---|
| 213 | } |
|---|
| 214 | void enable_dtag_vlan( int enable ) |
|---|
| 215 | { |
|---|
| 216 | |
|---|
| 217 | } |
|---|