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