| 1 | /* |
|---|
| 2 | * sysinit-gateworx.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 <arpa/inet.h> |
|---|
| 49 | #include <sys/socket.h> |
|---|
| 50 | #include <linux/if.h> |
|---|
| 51 | #include <linux/sockios.h> |
|---|
| 52 | #include <linux/mii.h> |
|---|
| 53 | |
|---|
| 54 | static int detect( char *devicename ) |
|---|
| 55 | { |
|---|
| 56 | char devcall[128]; |
|---|
| 57 | int res; |
|---|
| 58 | |
|---|
| 59 | sprintf( devcall, "/sbin/lspci|/bin/grep \"%s\"|/bin/wc -l", devicename ); |
|---|
| 60 | FILE *in = popen( devcall, "rb" ); |
|---|
| 61 | |
|---|
| 62 | fscanf( in, "%d", &res ); |
|---|
| 63 | pclose( in ); |
|---|
| 64 | return res > 0 ? 1 : 0; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | #ifndef HAVE_TONZE |
|---|
| 68 | #ifndef HAVE_NOP8670 |
|---|
| 69 | |
|---|
| 70 | /*void checkupdate( void ) |
|---|
| 71 | { |
|---|
| 72 | int res, res2 = 0; |
|---|
| 73 | FILE *in = |
|---|
| 74 | popen( "/bin/cat /dev/mtdblock/0|/bin/grep NewMedia|wc -l", "rb" ); |
|---|
| 75 | fscanf( in, "%d", &res ); |
|---|
| 76 | pclose( in ); |
|---|
| 77 | if( res == 0 ) |
|---|
| 78 | { |
|---|
| 79 | in = popen( "/bin/cat /dev/mtdblock/0|/bin/grep \"2\\.02\"|wc -l", |
|---|
| 80 | "rb" ); |
|---|
| 81 | fscanf( in, "%d", &res2 ); |
|---|
| 82 | pclose( in ); |
|---|
| 83 | if( res2 == 0 ) |
|---|
| 84 | { |
|---|
| 85 | in = popen( "/bin/cat /dev/mtdblock/0|/bin/grep \"2\\.04\"|wc -l", |
|---|
| 86 | "rb" ); |
|---|
| 87 | fscanf( in, "%d", &res2 ); |
|---|
| 88 | pclose( in ); |
|---|
| 89 | if( res2 == 1 || res2 == 7 ) // 7 is the result for debug |
|---|
| 90 | // info enabled reboot builds |
|---|
| 91 | { |
|---|
| 92 | fprintf( stderr, "updating avila type 2 redboot\n" ); |
|---|
| 93 | eval( "tar", "-xaf", "/usr/lib/firmware/redboot.tg7", "-C", |
|---|
| 94 | "/tmp" ); |
|---|
| 95 | eval( "mtd", "-r", "-f", "write", "/tmp/avila-rb.bin", |
|---|
| 96 | "RedBoot" ); |
|---|
| 97 | return; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | if( res == 1 ) |
|---|
| 102 | { |
|---|
| 103 | in = popen( "/bin/cat /dev/mtdblock/0|/bin/grep \"2\\.03\"|wc -l", |
|---|
| 104 | "rb" ); |
|---|
| 105 | fscanf( in, "%d", &res2 ); |
|---|
| 106 | pclose( in ); |
|---|
| 107 | } |
|---|
| 108 | if( res2 == 1 ) // redboot update is needed |
|---|
| 109 | { |
|---|
| 110 | in = popen( "/bin/dmesg|/bin/grep \"Memory: 64MB\"|wc -l", "rb" ); |
|---|
| 111 | fscanf( in, "%d", &res ); |
|---|
| 112 | pclose( in ); |
|---|
| 113 | if( res == 1 ) |
|---|
| 114 | res2 = 64; |
|---|
| 115 | in = popen( "/bin/dmesg|/bin/grep \"Memory: 32MB\"|wc -l", "rb" ); |
|---|
| 116 | fscanf( in, "%d", &res ); |
|---|
| 117 | pclose( in ); |
|---|
| 118 | if( res == 1 ) |
|---|
| 119 | res2 = 32; |
|---|
| 120 | in = popen( "/bin/dmesg|/bin/grep \"Memory: 128MB\"|wc -l", "rb" ); |
|---|
| 121 | fscanf( in, "%d", &res ); |
|---|
| 122 | pclose( in ); |
|---|
| 123 | if( res == 1 ) |
|---|
| 124 | res2 = 128; |
|---|
| 125 | in = popen( "/bin/dmesg|/bin/grep \"Memory: 256MB\"|wc -l", "rb" ); |
|---|
| 126 | fscanf( in, "%d", &res ); |
|---|
| 127 | pclose( in ); |
|---|
| 128 | if( res == 1 ) |
|---|
| 129 | res2 = 256; |
|---|
| 130 | fprintf( stderr, "updating redboot %d MB\n", res2 ); |
|---|
| 131 | char fname[64]; |
|---|
| 132 | |
|---|
| 133 | sprintf( fname, "/tmp/rb-%d.bin", res2 ); |
|---|
| 134 | eval( "tar", "-xaf", "/usr/lib/firmware/redboot.tg7", "-C", "/tmp" ); |
|---|
| 135 | eval( "mtd", "-r", "-f", "write", fname, "RedBoot" ); |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | */ |
|---|
| 139 | #endif |
|---|
| 140 | #endif |
|---|
| 141 | void start_sysinit( void ) |
|---|
| 142 | { |
|---|
| 143 | struct utsname name; |
|---|
| 144 | struct stat tmp_stat; |
|---|
| 145 | time_t tm = 0; |
|---|
| 146 | |
|---|
| 147 | unlink( "/etc/nvram/.lock" ); |
|---|
| 148 | cprintf( "sysinit() proc\n" ); |
|---|
| 149 | /* |
|---|
| 150 | * /proc |
|---|
| 151 | */ |
|---|
| 152 | mount( "proc", "/proc", "proc", MS_MGC_VAL, NULL ); |
|---|
| 153 | // system2 ("/etc/convert"); |
|---|
| 154 | mount( "sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL ); |
|---|
| 155 | cprintf( "sysinit() tmp\n" ); |
|---|
| 156 | |
|---|
| 157 | /* |
|---|
| 158 | * /tmp |
|---|
| 159 | */ |
|---|
| 160 | mount( "ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL ); |
|---|
| 161 | mount( "devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL ); |
|---|
| 162 | mount( "devpts", "/proc/bus/usb", "usbfs", MS_MGC_VAL, NULL ); |
|---|
| 163 | /* |
|---|
| 164 | * eval("mount","/etc/www.fs","/www","-t","squashfs","-o","loop"); |
|---|
| 165 | * eval("mount","/etc/modules.fs","/lib/modules","-t","squashfs","-o","loop"); |
|---|
| 166 | * eval("mount","/etc/usr.fs","/usr","-t","squashfs","-o","loop"); |
|---|
| 167 | */ |
|---|
| 168 | eval( "mkdir", "/tmp/www" ); |
|---|
| 169 | eval( "mknod", "/dev/gpio", "c", "127", "0" ); |
|---|
| 170 | eval( "ledtool", "1", "1" ); // blink the led 4 times |
|---|
| 171 | eval( "mknod", "/dev/nvram", "c", "229", "0" ); |
|---|
| 172 | eval( "mknod", "/dev/ppp", "c", "108", "0" ); |
|---|
| 173 | eval( "mknod", "/dev/rtc", "c", "254", "0" ); |
|---|
| 174 | eval( "mknod", "/dev/crypto", "c", "10", "70" ); |
|---|
| 175 | eval( "mount", "-o", "remount,rw", "/" ); |
|---|
| 176 | |
|---|
| 177 | unlink( "/tmp/nvram/.lock" ); |
|---|
| 178 | eval( "mkdir", "/tmp/nvram" ); |
|---|
| 179 | // #ifdef HAVE_REGISTER |
|---|
| 180 | // #else |
|---|
| 181 | // eval ("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); |
|---|
| 182 | // #endif |
|---|
| 183 | // mkdir ("/usr/local/nvram", 0777); |
|---|
| 184 | // unlink ("/tmp/nvram/.lock"); |
|---|
| 185 | // eval ("mkdir", "/tmp/nvram"); |
|---|
| 186 | // eval ("cp", "/etc/nvram/nvram.db", "/tmp/nvram"); |
|---|
| 187 | // eval ("cp", "/etc/nvram/offsets.db", "/tmp/nvram"); |
|---|
| 188 | cprintf( "sysinit() var\n" ); |
|---|
| 189 | |
|---|
| 190 | /* |
|---|
| 191 | * /var |
|---|
| 192 | */ |
|---|
| 193 | mkdir( "/tmp/var", 0777 ); |
|---|
| 194 | mkdir( "/var/lock", 0777 ); |
|---|
| 195 | mkdir( "/var/log", 0777 ); |
|---|
| 196 | mkdir( "/var/run", 0777 ); |
|---|
| 197 | mkdir( "/var/tmp", 0777 ); |
|---|
| 198 | |
|---|
| 199 | if (!nvram_match("disable_watchdog","1")) |
|---|
| 200 | eval( "watchdog" ); // system watchdog |
|---|
| 201 | |
|---|
| 202 | cprintf( "sysinit() setup console\n" ); |
|---|
| 203 | |
|---|
| 204 | /* |
|---|
| 205 | * Setup console |
|---|
| 206 | */ |
|---|
| 207 | |
|---|
| 208 | cprintf( "sysinit() klogctl\n" ); |
|---|
| 209 | klogctl( 8, NULL, atoi( nvram_safe_get( "console_loglevel" ) ) ); |
|---|
| 210 | cprintf( "sysinit() get router\n" ); |
|---|
| 211 | |
|---|
| 212 | /* |
|---|
| 213 | * Modules |
|---|
| 214 | */ |
|---|
| 215 | uname( &name ); |
|---|
| 216 | #ifndef HAVE_TONZE |
|---|
| 217 | #ifndef HAVE_NOP8670 |
|---|
| 218 | // checkupdate( ); |
|---|
| 219 | #endif |
|---|
| 220 | #endif |
|---|
| 221 | nvram_set( "intel_eth", "0" ); |
|---|
| 222 | if( detect( "82541" ) ) // Intel Gigabit |
|---|
| 223 | { |
|---|
| 224 | nvram_set( "intel_eth", "1" ); |
|---|
| 225 | insmod( "e1000" ); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | #ifndef HAVE_NOWIFI |
|---|
| 229 | insmod( "ath_hal" ); |
|---|
| 230 | if( nvram_get( "rate_control" ) != NULL ) |
|---|
| 231 | { |
|---|
| 232 | char rate[64]; |
|---|
| 233 | |
|---|
| 234 | sprintf( rate, "ratectl=%s", nvram_safe_get( "rate_control" ) ); |
|---|
| 235 | eval( "insmod", "ath_pci", rate ); |
|---|
| 236 | } |
|---|
| 237 | else |
|---|
| 238 | { |
|---|
| 239 | insmod( "ath_pci" ); |
|---|
| 240 | } |
|---|
| 241 | #endif |
|---|
| 242 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 243 | insmod( "ath_mimo_pci" ); |
|---|
| 244 | #endif |
|---|
| 245 | |
|---|
| 246 | #if 1 |
|---|
| 247 | insmod( "ixp400th" ); |
|---|
| 248 | insmod( "ixp400" ); |
|---|
| 249 | system2( "cat /usr/lib/firmware/IxNpeMicrocode.dat > /dev/IxNpe" ); |
|---|
| 250 | insmod( "ixp400_eth" ); |
|---|
| 251 | eval( "ifconfig", "ixp0", "0.0.0.0", "up" ); |
|---|
| 252 | eval( "ifconfig", "ixp1", "0.0.0.0", "up" ); |
|---|
| 253 | insmod( "ocf" ); |
|---|
| 254 | insmod( "cryptodev" ); |
|---|
| 255 | // insmod("ixp4xx", "init_crypto=0"); |
|---|
| 256 | #else |
|---|
| 257 | // eval ("mknod", "/dev/IxNpe","c","10","184"); |
|---|
| 258 | system2( "cat /usr/lib/firmware/NPE-B > /dev/misc/ixp4xx_ucode" ); |
|---|
| 259 | system2( "cat /usr/lib/firmware/NPE-C > /dev/misc/ixp4xx_ucode" ); |
|---|
| 260 | #endif |
|---|
| 261 | |
|---|
| 262 | // insmod("ath_pci", "rfkill=0", "autocreate=none"); |
|---|
| 263 | |
|---|
| 264 | /* |
|---|
| 265 | * if (ifexists ("wifi0")) eval ("ifconfig", "wifi0", "up"); if (ifexists |
|---|
| 266 | * ("wifi1")) eval ("ifconfig", "wifi1", "up"); if (ifexists ("wifi2")) |
|---|
| 267 | * eval ("ifconfig", "wifi2", "up"); if (ifexists ("wifi3")) eval |
|---|
| 268 | * ("ifconfig", "wifi3", "up"); if (ifexists ("wifi4")) eval ("ifconfig", |
|---|
| 269 | * "wifi4", "up"); if (ifexists ("wifi5")) eval ("ifconfig", "wifi5", |
|---|
| 270 | * "up"); |
|---|
| 271 | */ |
|---|
| 272 | |
|---|
| 273 | // insmod("ipv6"); |
|---|
| 274 | |
|---|
| 275 | insmod( "ad7418" ); // temp / voltage sensor |
|---|
| 276 | /* |
|---|
| 277 | * Configure mac addresses by reading data from eeprom |
|---|
| 278 | */ |
|---|
| 279 | // char *filename = |
|---|
| 280 | // "/sys/devices/platform/IXP4XX-I2C.0/i2c-0/0-0051/eeprom"; /* |
|---|
| 281 | // bank2=0x100 */ |
|---|
| 282 | #ifdef HAVE_NOP8670 |
|---|
| 283 | |
|---|
| 284 | char filename[64]; |
|---|
| 285 | |
|---|
| 286 | sprintf( filename, "/dev/mtdblock/%d", getMTD( "RedBoot config" ) ); |
|---|
| 287 | FILE *file = fopen( filename, "r" ); |
|---|
| 288 | |
|---|
| 289 | if( file ) |
|---|
| 290 | { |
|---|
| 291 | eval( "ifconfig", "ixp0", "0.0.0.0", "down" ); |
|---|
| 292 | eval( "ifconfig", "ixp1", "0.0.0.0", "down" ); |
|---|
| 293 | unsigned char buf[16]; |
|---|
| 294 | int i; |
|---|
| 295 | |
|---|
| 296 | fseek( file, 0x422, SEEK_SET ); |
|---|
| 297 | fread( &buf[0], 6, 1, file ); |
|---|
| 298 | char mac[16]; |
|---|
| 299 | unsigned int copy[16]; |
|---|
| 300 | |
|---|
| 301 | for( i = 0; i < 6; i++ ) |
|---|
| 302 | copy[i] = buf[i] & 0xff; |
|---|
| 303 | sprintf( mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], |
|---|
| 304 | copy[2], copy[3], copy[4], copy[5] ); |
|---|
| 305 | fprintf( stderr, "configure IXP0 to %s\n", mac ); |
|---|
| 306 | eval( "ifconfig", "ixp0", "hw", "ether", mac ); |
|---|
| 307 | fseek( file, 0x43b, SEEK_SET ); |
|---|
| 308 | fread( &buf[6], 6, 1, file ); |
|---|
| 309 | for( i = 0; i < 12; i++ ) |
|---|
| 310 | copy[i] = buf[i] & 0xff; |
|---|
| 311 | sprintf( mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[6], copy[7], |
|---|
| 312 | copy[8], copy[9], copy[10], copy[11] ); |
|---|
| 313 | fprintf( stderr, "configure IXP1 to %s\n", mac ); |
|---|
| 314 | eval( "ifconfig", "ixp1", "hw", "ether", mac ); |
|---|
| 315 | fclose( file ); |
|---|
| 316 | eval( "ifconfig", "ixp0", "0.0.0.0", "up" ); |
|---|
| 317 | eval( "ifconfig", "ixp1", "0.0.0.0", "up" ); |
|---|
| 318 | } |
|---|
| 319 | #else |
|---|
| 320 | char *filename = "/sys/devices/platform/IXP4XX-I2C.0/i2c-adapter:i2c-0/0-0051/eeprom"; /* bank2=0x100 |
|---|
| 321 | */ |
|---|
| 322 | FILE *file = fopen( filename, "r" ); |
|---|
| 323 | |
|---|
| 324 | if( file ) |
|---|
| 325 | { |
|---|
| 326 | unsigned char buf[16]; |
|---|
| 327 | |
|---|
| 328 | fread( &buf[0], 16, 1, file ); |
|---|
| 329 | char mac[16]; |
|---|
| 330 | |
|---|
| 331 | unsigned int copy[16]; |
|---|
| 332 | int i; |
|---|
| 333 | |
|---|
| 334 | for( i = 0; i < 12; i++ ) |
|---|
| 335 | copy[i] = buf[i] & 0xff; |
|---|
| 336 | sprintf( mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], |
|---|
| 337 | copy[2], copy[3], copy[4], copy[5] ); |
|---|
| 338 | eval( "ifconfig", "ixp0", "hw", "ether", mac ); |
|---|
| 339 | sprintf( mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[6], copy[7], |
|---|
| 340 | copy[8], copy[9], copy[10], copy[11] ); |
|---|
| 341 | eval( "ifconfig", "ixp1", "hw", "ether", mac ); |
|---|
| 342 | |
|---|
| 343 | fclose( file ); |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | #endif |
|---|
| 347 | eval( "ifconfig", "ixp0", "0.0.0.0", "up" ); |
|---|
| 348 | eval( "ifconfig", "ixp1", "0.0.0.0", "up" ); |
|---|
| 349 | if( getRouterBrand( ) == ROUTER_BOARD_GATEWORX_GW2345 ) // lets load |
|---|
| 350 | // the spi |
|---|
| 351 | // drivers |
|---|
| 352 | // for this |
|---|
| 353 | // switch |
|---|
| 354 | { |
|---|
| 355 | insmod( "spi-algo-bit" ); |
|---|
| 356 | if( nvram_match( "DD_BOARD", "Avila GW2355" ) ) |
|---|
| 357 | insmod( "spi-ixp4xx-gw2355" ); |
|---|
| 358 | else |
|---|
| 359 | insmod( "spi-ixp4xx" ); |
|---|
| 360 | insmod( "ks8995m" ); |
|---|
| 361 | sleep( 1 ); |
|---|
| 362 | system2( "echo R01=01 > /proc/driver/KS8995M" ); // enable switch |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | char filename2[64]; |
|---|
| 366 | |
|---|
| 367 | sprintf( filename2, "/dev/mtdblock/%d", getMTD( "RedBoot" ) ); |
|---|
| 368 | file = fopen( filename2, "r" ); |
|---|
| 369 | if( file ) |
|---|
| 370 | { |
|---|
| 371 | fseek( file, 0x1f800, SEEK_SET ); |
|---|
| 372 | unsigned int signature; |
|---|
| 373 | |
|---|
| 374 | fread( &signature, 4, 1, file ); |
|---|
| 375 | if( signature == 0x20021103 ) |
|---|
| 376 | { |
|---|
| 377 | fprintf( stderr, "Compex WP188 detected\n" ); |
|---|
| 378 | eval( "ifconfig", "ixp0", "0.0.0.0", "down" ); |
|---|
| 379 | eval( "ifconfig", "ixp1", "0.0.0.0", "down" ); |
|---|
| 380 | unsigned char buf[16]; |
|---|
| 381 | |
|---|
| 382 | fseek( file, 0x1f810, SEEK_SET ); |
|---|
| 383 | fread( &buf[0], 6, 1, file ); |
|---|
| 384 | char mac[16]; |
|---|
| 385 | int i; |
|---|
| 386 | |
|---|
| 387 | unsigned int copy[16]; |
|---|
| 388 | |
|---|
| 389 | for( i = 0; i < 12; i++ ) |
|---|
| 390 | copy[i] = buf[i] & 0xff; |
|---|
| 391 | |
|---|
| 392 | sprintf( mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], |
|---|
| 393 | copy[2], copy[3], copy[4], copy[5] ); |
|---|
| 394 | fprintf( stderr, "configure IXP0 to %s\n", mac ); |
|---|
| 395 | eval( "ifconfig", "ixp0", "hw", "ether", mac ); |
|---|
| 396 | fseek( file, 0x1f818, SEEK_SET ); |
|---|
| 397 | fread( &buf[6], 6, 1, file ); |
|---|
| 398 | for( i = 0; i < 12; i++ ) |
|---|
| 399 | copy[i] = buf[i] & 0xff; |
|---|
| 400 | sprintf( mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[6], copy[7], |
|---|
| 401 | copy[8], copy[9], copy[10], copy[11] ); |
|---|
| 402 | fprintf( stderr, "configure IXP1 to %s\n", mac ); |
|---|
| 403 | eval( "ifconfig", "ixp1", "hw", "ether", mac ); |
|---|
| 404 | eval( "ifconfig", "ixp0", "0.0.0.0", "up" ); |
|---|
| 405 | eval( "ifconfig", "ixp1", "0.0.0.0", "up" ); |
|---|
| 406 | } |
|---|
| 407 | else |
|---|
| 408 | { |
|---|
| 409 | eval( "insmod", "avila-ide" ); |
|---|
| 410 | } |
|---|
| 411 | fclose( file ); |
|---|
| 412 | } |
|---|
| 413 | #ifdef HAVE_MAKSAT |
|---|
| 414 | if( nvram_match( "DD_BOARD2", "ADI Engineering Pronghorn Metro" ) ) |
|---|
| 415 | #else |
|---|
| 416 | if( nvram_match( "DD_BOARD", "ADI Engineering Pronghorn Metro" ) ) |
|---|
| 417 | #endif |
|---|
| 418 | { |
|---|
| 419 | fprintf( stderr, "Pronghorn Metro detected\n" ); |
|---|
| 420 | eval( "setmac", "-f", "/dev/mtdblock/7", "-n", "1", "-i", "0", "-r", |
|---|
| 421 | "npe_eth0_esa" ); |
|---|
| 422 | eval( "setmac", "-f", "/dev/mtdblock/7", "-n", "1", "-i", "1", "-r", |
|---|
| 423 | "npe_eth1_esa" ); |
|---|
| 424 | struct ifreq ifr; |
|---|
| 425 | int s; |
|---|
| 426 | |
|---|
| 427 | if( ( s = socket( AF_INET, SOCK_RAW, IPPROTO_RAW ) ) ) |
|---|
| 428 | { |
|---|
| 429 | char eabuf[32]; |
|---|
| 430 | |
|---|
| 431 | strncpy( ifr.ifr_name, "ixp0", IFNAMSIZ ); |
|---|
| 432 | ioctl( s, SIOCGIFHWADDR, &ifr ); |
|---|
| 433 | nvram_set( "et0macaddr_safe", |
|---|
| 434 | ether_etoa( ( unsigned char * )ifr.ifr_hwaddr.sa_data, |
|---|
| 435 | eabuf ) ); |
|---|
| 436 | close( s ); |
|---|
| 437 | } |
|---|
| 438 | } |
|---|
| 439 | #ifdef HAVE_WG302V1 |
|---|
| 440 | eval( "setmac", "-f", "/dev/mtdblock/7", "-n", "1", "-i", "0", "-r", |
|---|
| 441 | "zcom_npe_esa" ); |
|---|
| 442 | struct ifreq ifr; |
|---|
| 443 | int s; |
|---|
| 444 | |
|---|
| 445 | if( ( s = socket( AF_INET, SOCK_RAW, IPPROTO_RAW ) ) ) |
|---|
| 446 | { |
|---|
| 447 | char eabuf[32]; |
|---|
| 448 | |
|---|
| 449 | strncpy( ifr.ifr_name, "ixp0", IFNAMSIZ ); |
|---|
| 450 | ioctl( s, SIOCGIFHWADDR, &ifr ); |
|---|
| 451 | nvram_set( "et0macaddr_safe", |
|---|
| 452 | ether_etoa( ( unsigned char * )ifr.ifr_hwaddr.sa_data, |
|---|
| 453 | eabuf ) ); |
|---|
| 454 | close( s ); |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | #else |
|---|
| 458 | #ifdef HAVE_WG302 |
|---|
| 459 | eval( "setmac", "-f", "/dev/mtdblock/7", "-n", "1", "-i", "0", "-r", |
|---|
| 460 | "npe_eth0_esa" ); |
|---|
| 461 | struct ifreq ifr; |
|---|
| 462 | int s; |
|---|
| 463 | |
|---|
| 464 | if( ( s = socket( AF_INET, SOCK_RAW, IPPROTO_RAW ) ) ) |
|---|
| 465 | { |
|---|
| 466 | char eabuf[32]; |
|---|
| 467 | |
|---|
| 468 | strncpy( ifr.ifr_name, "ixp0", IFNAMSIZ ); |
|---|
| 469 | ioctl( s, SIOCGIFHWADDR, &ifr ); |
|---|
| 470 | nvram_set( "et0macaddr_safe", |
|---|
| 471 | ether_etoa( ( unsigned char * )ifr.ifr_hwaddr.sa_data, |
|---|
| 472 | eabuf ) ); |
|---|
| 473 | close( s ); |
|---|
| 474 | } |
|---|
| 475 | #endif |
|---|
| 476 | #endif |
|---|
| 477 | #ifdef HAVE_TONZE |
|---|
| 478 | { |
|---|
| 479 | struct ifreq ifr; |
|---|
| 480 | int s; |
|---|
| 481 | |
|---|
| 482 | if( ( s = socket( AF_INET, SOCK_RAW, IPPROTO_RAW ) ) ) |
|---|
| 483 | { |
|---|
| 484 | char eabuf[32]; |
|---|
| 485 | |
|---|
| 486 | strncpy( ifr.ifr_name, "ixp0", IFNAMSIZ ); |
|---|
| 487 | ioctl( s, SIOCGIFHWADDR, &ifr ); |
|---|
| 488 | nvram_set( "et0macaddr_safe", |
|---|
| 489 | ether_etoa( ( unsigned char * )ifr.ifr_hwaddr.sa_data, |
|---|
| 490 | eabuf ) ); |
|---|
| 491 | close( s ); |
|---|
| 492 | } |
|---|
| 493 | } |
|---|
| 494 | #endif |
|---|
| 495 | |
|---|
| 496 | #ifdef HAVE_CAMBRIA |
|---|
| 497 | if (nvram_match("DD_BOARD","Cambria GW2358-4") || nvram_match("DD_BOARD2","Cambria GW2358-4")) |
|---|
| 498 | { |
|---|
| 499 | insmod("8250_gw2358"); |
|---|
| 500 | system2( "echo 0 >/proc/sys/dev/wifi0/ledpin" ); |
|---|
| 501 | system2( "echo 1 >/proc/sys/dev/wifi0/softled" ); |
|---|
| 502 | system2( "echo 1 >/proc/sys/dev/wifi1/ledpin" ); |
|---|
| 503 | system2( "echo 1 >/proc/sys/dev/wifi1/softled" ); |
|---|
| 504 | system2( "echo 2 >/proc/sys/dev/wifi2/ledpin" ); |
|---|
| 505 | system2( "echo 1 >/proc/sys/dev/wifi2/softled" ); |
|---|
| 506 | system2( "echo 3 >/proc/sys/dev/wifi3/ledpin" ); |
|---|
| 507 | system2( "echo 1 >/proc/sys/dev/wifi3/softled" ); |
|---|
| 508 | } |
|---|
| 509 | if (nvram_match("DD_BOARD","Cambria GW2350") || nvram_match("DD_BOARD2","Cambria GW2350")) |
|---|
| 510 | { |
|---|
| 511 | insmod("8250_gw2350"); |
|---|
| 512 | } |
|---|
| 513 | #endif |
|---|
| 514 | |
|---|
| 515 | /* |
|---|
| 516 | * Set a sane date |
|---|
| 517 | */ |
|---|
| 518 | stime( &tm ); |
|---|
| 519 | nvram_set( "wl0_ifname", "ath0" ); |
|---|
| 520 | #ifndef HAVE_NOP8670 |
|---|
| 521 | eval( "hwclock", "-s" ); |
|---|
| 522 | #endif |
|---|
| 523 | nvram_set( "use_crypto", "0" ); |
|---|
| 524 | cprintf( "done\n" ); |
|---|
| 525 | eval( "/bin/tar", "-xzf", "/dev/mtdblock/4", "-C", "/" ); |
|---|
| 526 | FILE *in = fopen( "/tmp/nvram/nvram.db", "rb" ); |
|---|
| 527 | |
|---|
| 528 | if( in != NULL ) |
|---|
| 529 | { |
|---|
| 530 | fclose( in ); |
|---|
| 531 | eval( "/usr/sbin/convertnvram" ); |
|---|
| 532 | eval( "/sbin/mtd", "erase", "nvram" ); |
|---|
| 533 | nvram_commit( ); |
|---|
| 534 | } |
|---|
| 535 | return; |
|---|
| 536 | } |
|---|
| 537 | |
|---|
| 538 | int check_cfe_nv( void ) |
|---|
| 539 | { |
|---|
| 540 | nvram_set( "portprio_support", "0" ); |
|---|
| 541 | return 0; |
|---|
| 542 | } |
|---|
| 543 | |
|---|
| 544 | int check_pmon_nv( void ) |
|---|
| 545 | { |
|---|
| 546 | return 0; |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | void start_overclocking( void ) |
|---|
| 550 | { |
|---|
| 551 | } |
|---|
| 552 | void enable_dtag_vlan( int enable ) |
|---|
| 553 | { |
|---|
| 554 | |
|---|
| 555 | } |
|---|