3 Copyright 2005, Broadcom Corporation
6 THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
7 KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
8 SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
9 FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
17 #include <sys/ioctl.h>
18 #include <sys/mount.h>
23 #include <sys/reboot.h>
26 #include <sys/types.h>
28 #include <sys/sysinfo.h>
33 #define SHELL "/bin/sh"
35 static int fatalsigs
[] = {
46 static int initsigs
[] = {
56 static char *defenv
[] = {
59 "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
65 /* Set terminal settings to reasonable defaults */
66 static void set_term(int fd
)
72 /* set control chars */
73 tty
.c_cc
[VINTR
] = 3; /* C-c */
74 tty
.c_cc
[VQUIT
] = 28; /* C-\ */
75 tty
.c_cc
[VERASE
] = 127; /* C-? */
76 tty
.c_cc
[VKILL
] = 21; /* C-u */
77 tty
.c_cc
[VEOF
] = 4; /* C-d */
78 tty
.c_cc
[VSTART
] = 17; /* C-q */
79 tty
.c_cc
[VSTOP
] = 19; /* C-s */
80 tty
.c_cc
[VSUSP
] = 26; /* C-z */
82 /* use line dicipline 0 */
86 tty
.c_cflag
&= CBAUD
|CBAUDEX
|CSIZE
|CSTOPB
|PARENB
|PARODD
;
87 tty
.c_cflag
|= CREAD
|HUPCL
|CLOCAL
;
91 tty
.c_iflag
= ICRNL
| IXON
| IXOFF
;
94 tty
.c_oflag
= OPOST
| ONLCR
;
98 ISIG
| ICANON
| ECHO
| ECHOE
| ECHOK
| ECHOCTL
| ECHOKE
| IEXTEN
;
100 tcsetattr(fd
, TCSANOW
, &tty
);
103 static int console_init(void)
108 ioctl(0, TIOCNOTTY
, 0);
115 if ((fd
= open(_PATH_CONSOLE
, O_RDWR
)) < 0) {
116 /* Avoid debug messages is redirected to socket packet if no exist a UART chip, added by honor, 2003-12-04 */
117 open("/dev/null", O_RDONLY
);
118 open("/dev/null", O_WRONLY
);
119 open("/dev/null", O_WRONLY
);
120 perror(_PATH_CONSOLE
);
127 ioctl(0, TIOCSCTTY
, 1);
128 tcsetpgrp(0, getpgrp());
135 * Waits for a file descriptor to change status or unblocked signal
136 * @param fd file descriptor
137 * @param timeout seconds to wait before timing out or 0 for no timeout
138 * @return 1 if descriptor changed status or 0 if timed out or -1 on error
140 static int waitfor(int fd
, int timeout
)
143 struct timeval tv
= { timeout
, 0 };
147 return select(fd
+ 1, &rfds
, NULL
, NULL
, (timeout
> 0) ? &tv
: NULL
);
150 static pid_t
run_shell(int timeout
, int nowait
)
155 /* Wait for user input */
156 if (waitfor(STDIN_FILENO
, timeout
) <= 0) return 0;
158 switch (pid
= fork()) {
163 /* Reset signal handlers set for parent process */
164 for (sig
= 0; sig
< (_NSIG
-1); sig
++)
165 signal(sig
, SIG_DFL
);
169 printf("\n\nTomato %s\n\n", tomato_version
);
171 /* Now run it. The new program will take over this PID,
172 * so nothing further in init.c should be run. */
173 execve(SHELL
, (char *[]) { SHELL
, NULL
}, defenv
);
175 /* We're still here? Some error happened. */
183 waitpid(pid
, NULL
, 0);
189 int console_main(int argc
, char *argv
[])
191 for (;;) run_shell(0, 0);
196 static void shutdn(int rb
)
202 _dprintf("shutdn rb=%d\n", rb
);
205 for (i
= 0; i
< sizeof(fatalsigs
) / sizeof(fatalsigs
[0]); i
++)
206 sigaddset(&ss
, fatalsigs
[i
]);
207 for (i
= 0; i
< sizeof(initsigs
) / sizeof(initsigs
[0]); i
++)
208 sigaddset(&ss
, initsigs
[i
]);
209 sigprocmask(SIG_BLOCK
, &ss
, NULL
);
211 for (i
= 30; i
> 0; --i
) {
212 if (((act
= check_action()) == ACT_IDLE
) || (act
== ACT_REBOOT
)) break;
213 _dprintf("Busy with %d. Waiting before shutdown... %d\n", act
, i
);
216 set_action(ACT_REBOOT
);
218 // Disconnect pppd - need this for PPTP/L2TP to finish gracefully
232 umount("/jffs"); // may hang if not
238 for (i
= 4; i
> 0; --i
) {
249 reboot(rb
? RB_AUTOBOOT
: RB_HALT_SYSTEM
);
256 static void handle_fatalsigs(int sig
)
258 _dprintf("fatal sig=%d\n", sig
);
262 /* Fixed the race condition & incorrect code by using sigwait()
263 * instead of pause(). But SIGCHLD is a problem, since other
264 * code: 1) messes with it and 2) depends on CHLD being caught so
265 * that the pid gets immediately reaped instead of left a zombie.
266 * Pidof still shows the pid, even though it's in zombie state.
267 * So this SIGCHLD handler reaps and then signals the mainline by
270 static void handle_reap(int sig
)
276 static int check_nv(const char *name
, const char *value
)
279 if (!nvram_match("manual_boot_nv", "1")) {
280 if (((p
= nvram_get(name
)) == NULL
) || (strcmp(p
, value
) != 0)) {
281 _dprintf("Error: Critical variable %s is invalid. Resetting.\n", name
);
282 nvram_set(name
, value
);
289 static inline int invalid_mac(const char *mac
)
291 return (!mac
|| !(*mac
) || strncasecmp(mac
, "00:90:4c", 8) == 0);
294 static int find_sercom_mac_addr(void)
297 unsigned char m
[6], s
[18];
299 sprintf(s
, MTD_DEV(%dro
), 0);
300 if ((fp
= fopen(s
, "rb"))) {
301 fseek(fp
, 0x1ffa0, SEEK_SET
);
302 fread(m
, sizeof(m
), 1, fp
);
304 sprintf(s
, "%02X:%02X:%02X:%02X:%02X:%02X",
305 m
[0], m
[1], m
[2], m
[3], m
[4], m
[5]);
306 nvram_set("et0macaddr", s
);
307 return !invalid_mac(s
);
312 static int find_dir320_mac_addr(void)
316 int i
, part
, size
, found
= 0;
318 if (!mtd_getinfo("board_data", &part
, &size
))
320 sprintf(s
, MTD_DEV(%dro
), part
);
322 if ((fp
= fopen(s
, "rb"))) {
323 buffer
= malloc(size
);
324 memset(buffer
, 0, size
);
325 fread(buffer
, size
, 1, fp
);
326 if (!memcmp(buffer
, "RGCFG1", 6)) {
327 for (i
= 6; i
< size
- 24; i
++) {
328 if (!memcmp(buffer
+ i
, "lanmac=", 7)) {
329 memcpy(s
, buffer
+ i
+ 7, 17);
331 nvram_set("et0macaddr", s
);
334 else if (!memcmp(buffer
+ i
, "wanmac=", 7)) {
335 memcpy(s
, buffer
+ i
+ 7, 17);
337 nvram_set("il0macaddr", s
);
340 nvram_set("et0macaddr", s
);
351 strcpy(s
, nvram_safe_get("wl0_hwaddr"));
353 nvram_set("et0macaddr", s
);
358 static int init_vlan_ports(void)
361 int model
= get_model();
365 switch (check_hw_type()) {
366 case HW_BCM5352E
: // G v4, GS v3, v4
367 dirty
|= check_nv("vlan0ports", "3 2 1 0 5*");
372 dirty
|= check_nv("vlan0ports", "0 5*");
373 dirty
|= check_nv("vlan1ports", "1 5");
374 dirty
|= check_nv("vlan_enable", "1");
378 case MODEL_WL500GPv2
:
381 if (nvram_match("vlan1ports", "0 5u")) // 520GU or 330GE or WL500GE?
382 dirty
|= check_nv("vlan1ports", "0 5");
383 else if (nvram_match("vlan1ports", "4 5u"))
384 dirty
|= check_nv("vlan1ports", "4 5");
387 dirty
|= check_nv("vlan0ports", "1 2 3 4 5*");
388 dirty
|= check_nv("vlan1ports", "0 5");
392 dirty
|= (nvram_get("vlan2ports") != NULL
);
393 nvram_unset("vlan2ports");
394 dirty
|= check_nv("vlan1ports", "0 5");
396 case MODEL_WRT310Nv1
:
397 dirty
|= check_nv("vlan1ports", "1 2 3 4 8*");
398 dirty
|= check_nv("vlan2ports", "0 8");
401 dirty
|= check_nv("vlan0ports", "0 1 2 3 5*");
402 dirty
|= check_nv("vlan1ports", "4 5");
407 case MODEL_WNR3500LV2
:
410 dirty
|= check_nv("vlan1ports", "4 3 2 1 8*");
411 dirty
|= check_nv("vlan2ports", "0 8");
414 dirty
|= check_nv("vlan2ports", "0 1 2 3 5*");
415 dirty
|= check_nv("vlan1ports", "4 5");
417 case MODEL_WNR2000v2
:
418 dirty
|= check_nv("vlan1ports", "4 3 2 1 5*");
419 dirty
|= check_nv("vlan2ports", "0 5");
422 dirty
|= check_nv("vlan1ports", "4 5");
425 dirty
|= check_nv("vlan1ports", "1 2 3 4 5*");
426 dirty
|= check_nv("vlan2ports", "0 5");
429 dirty
|= check_nv("vlan0ports", "1 2 3 4 5*");
430 dirty
|= check_nv("vlan1ports", "0 5");
434 dirty
|= check_nv("vlan0ports", "3 2 1 0 5*");
435 dirty
|= check_nv("vlan1ports", "4 5");
437 case MODEL_WRT610Nv2
:
438 case MODEL_F5D8235v3
:
439 dirty
|= check_nv("vlan1ports", "1 2 3 4 8*");
440 dirty
|= check_nv("vlan2ports", "0 8");
444 dirty
|= check_nv("vlan1ports", "3 2 1 0 8*");
445 dirty
|= check_nv("vlan2ports", "4 8");
453 dirty
|= check_nv("vlan1ports", "0 1 2 3 5*");
454 dirty
|= check_nv("vlan2ports", "4 5");
459 dirty
|= check_nv("vlan1ports", "0 1 2 3 8*");
460 dirty
|= check_nv("vlan2ports", "4 8");
462 case MODEL_WRT160Nv3
:
463 if (nvram_match("vlan1ports", "1 2 3 4 5*")) {
464 // fix lan port numbering on CSE41, CSE51
465 dirty
|= check_nv("vlan1ports", "4 3 2 1 5*");
467 else if (nvram_match("vlan1ports", "1 2 3 4 8*")) {
469 dirty
|= check_nv("vlan1ports", "4 3 2 1 8*");
478 static void check_bootnv(void)
486 dirty
= check_nv("wl0_leddc", "0x640000") | check_nv("wl1_leddc", "0x640000");
490 dirty
|= check_nv("vlan0hwname", "et0");
491 dirty
|= check_nv("vlan1hwname", "et0");
494 dirty
|= check_nv("wl0gpio0", "130");
497 dirty
|= check_nv("wl0gpio1", "0x02");
501 // need to cleanup some variables...
502 if ((nvram_get("t_model") == NULL
) && (nvram_get("MyFirmwareVersion") != NULL
)) {
503 nvram_unset("MyFirmwareVersion");
504 nvram_set("restore_defaults", "1");
508 /* fix WL500W mac adresses for WAN port */
509 if (invalid_mac(nvram_get("et1macaddr"))) {
510 strcpy(mac
, nvram_safe_get("et0macaddr"));
512 dirty
|= check_nv("et1macaddr", mac
);
514 dirty
|= check_nv("wl0gpio0", "0x88");
517 dirty
|= check_nv("sdram_init", "0x0009"); // 32MB; defaults: 0x000b, 0x0009
518 dirty
|= check_nv("wl0gpio0", "136");
520 case MODEL_WL500GPv2
:
522 dirty
|= check_nv("wl0gpio1", "136");
525 dirty
|= check_nv("vlan0hwname", "et0");
526 dirty
|= check_nv("vlan1hwname", "et0");
527 dirty
|= check_nv("boardflags", "0x00000100"); // set BFL_ENETVLAN
528 nvram_unset("wl0gpio0");
531 if (strlen(nvram_safe_get("et0macaddr")) == 12 ||
532 strlen(nvram_safe_get("il0macaddr")) == 12) {
533 dirty
|= find_dir320_mac_addr();
535 if (nvram_get("vlan2hwname") != NULL
) {
536 nvram_unset("vlan2hwname");
539 dirty
|= check_nv("wandevs", "vlan1");
540 dirty
|= check_nv("vlan1hwname", "et0");
541 dirty
|= check_nv("wl0gpio0", "8");
542 dirty
|= check_nv("wl0gpio1", "0");
543 dirty
|= check_nv("wl0gpio2", "0");
544 dirty
|= check_nv("wl0gpio3", "0");
546 if (invalid_mac(nvram_get("et0macaddr"))) {
547 dirty
|= find_sercom_mac_addr();
550 case MODEL_WRT160Nv1
:
551 case MODEL_WRT310Nv1
:
553 dirty
|= check_nv("wl0gpio0", "8");
557 dirty
|= check_nv("boardflags", "0x00000710"); // needed to enable USB
558 dirty
|= check_nv("vlan2hwname", "et0");
559 dirty
|= check_nv("ledbh0", "7");
561 case MODEL_WNR3500LV2
:
562 dirty
|= check_nv("vlan2hwname", "et0");
564 case MODEL_WNR2000v2
:
565 dirty
|= check_nv("ledbh5", "8");
568 dirty
|= check_nv("reset_gpio", "5");
569 dirty
|= check_nv("ledbh0", "136");
570 dirty
|= check_nv("ledbh1", "11");
571 /* fall through, same as RT-N16 */
573 dirty
|= check_nv("vlan2hwname", "et0");
575 case MODEL_WRT610Nv2
:
576 dirty
|= check_nv("vlan2hwname", "et0");
577 dirty
|= check_nv("pci/1/1/ledbh2", "8");
578 dirty
|= check_nv("sb/1/ledbh1", "8");
579 if (invalid_mac(nvram_get("pci/1/1/macaddr"))) {
580 strcpy(mac
, nvram_safe_get("et0macaddr"));
582 dirty
|= check_nv("pci/1/1/macaddr", mac
);
589 case MODEL_F5D8235v3
:
590 if (nvram_match("sb/1/macaddr", nvram_safe_get("et0macaddr"))) {
591 strcpy(mac
, nvram_safe_get("et0macaddr"));
593 dirty
|= check_nv("sb/1/macaddr", mac
);
595 dirty
|= check_nv("pci/1/1/macaddr", mac
);
598 dirty
|= check_nv("vlan2hwname", "et0");
599 if (strncasecmp(nvram_safe_get("pci/1/1/macaddr"), "00:90:4c", 8) == 0 ||
600 strncasecmp(nvram_safe_get("sb/1/macaddr"), "00:90:4c", 8) == 0) {
601 strcpy(mac
, nvram_safe_get("et0macaddr"));
603 dirty
|= check_nv("sb/1/macaddr", mac
);
605 dirty
|= check_nv("pci/1/1/macaddr", mac
);
614 case MODEL_WRT160Nv3
:
615 dirty
|= check_nv("vlan2hwname", "et0");
620 if (strncmp(nvram_safe_get("pmon_ver"), "CFE", 3) != 0) return;
622 hardware
= check_hw_type();
623 if (!nvram_get("boardtype") ||
624 !nvram_get("boardnum") ||
625 !nvram_get("boardflags") ||
626 !nvram_get("clkfreq") ||
627 !nvram_get("os_flash_addr") ||
628 !nvram_get("dl_ram_addr") ||
629 !nvram_get("os_ram_addr") ||
630 !nvram_get("scratch") ||
631 !nvram_get("et0macaddr") ||
632 ((hardware
!= HW_BCM4704_BCM5325F
) && (!nvram_get("vlan0ports") || !nvram_get("vlan0hwname")))) {
633 _dprintf("Unable to find critical settings, erasing NVRAM\n");
638 dirty
|= check_nv("aa0", "3");
639 dirty
|= check_nv("wl0gpio0", "136");
640 dirty
|= check_nv("wl0gpio2", "0");
641 dirty
|= check_nv("wl0gpio3", "0");
642 dirty
|= check_nv("cctl", "0");
643 dirty
|= check_nv("ccode", "0");
647 /* Lower the DDR ram drive strength , the value will be stable for all boards
648 Latency 3 is more stable for all ddr 20050420 by honor */
649 dirty
|= check_nv("sdram_init", "0x010b");
650 dirty
|= check_nv("sdram_config", "0x0062");
651 if (!nvram_match("debug_clkfix", "0")) {
652 dirty
|= check_nv("clkfreq", "216");
655 nvram_set("sdram_ncdl", "0x0");
657 dirty
|= check_nv("pa0itssit", "62");
658 dirty
|= check_nv("pa0b0", "0x15eb");
659 dirty
|= check_nv("pa0b1", "0xfa82");
660 dirty
|= check_nv("pa0b2", "0xfe66");
661 //dirty |= check_nv("pa0maxpwr", "0x4e");
663 case HW_BCM5352E
: // G v4, GS v3, v4
664 dirty
|= check_nv("sdram_init", "0x010b");
665 dirty
|= check_nv("sdram_config", "0x0062");
667 nvram_set("sdram_ncdl", "0x0");
669 dirty
|= check_nv("pa0itssit", "62");
670 dirty
|= check_nv("pa0b0", "0x168b");
671 dirty
|= check_nv("pa0b1", "0xfabf");
672 dirty
|= check_nv("pa0b2", "0xfeaf");
673 //dirty |= check_nv("pa0maxpwr", "0x4e");
676 dirty
|= check_nv("pa0itssit", "62");
677 dirty
|= check_nv("pa0b0", "0x1326");
678 dirty
|= check_nv("pa0b1", "0xFB51");
679 dirty
|= check_nv("pa0b2", "0xFE87");
680 //dirty |= check_nv("pa0maxpwr", "0x4e");
682 case HW_BCM4704_BCM5325F
:
686 dirty
|= check_nv("pa0itssit", "62");
687 dirty
|= check_nv("pa0b0", "0x170c");
688 dirty
|= check_nv("pa0b1", "0xfa24");
689 dirty
|= check_nv("pa0b2", "0xfe70");
690 //dirty |= check_nv("pa0maxpwr", "0x48");
697 dirty
|= init_vlan_ports();
701 REBOOT
: // do a simple reboot
708 static int init_nvram(void)
710 unsigned long features
;
720 sprintf(s
, "%d", model
);
721 nvram_set("t_model", s
);
730 name
= "WRT54G/GS/GL";
731 switch (check_hw_type()) {
733 nvram_set("gpio2", "adm_eecs");
734 nvram_set("gpio3", "adm_eesk");
735 nvram_unset("gpio4");
736 nvram_set("gpio5", "adm_eedi");
737 nvram_set("gpio6", "adm_rc");
740 nvram_unset("gpio2");
741 nvram_unset("gpio3");
742 nvram_unset("gpio4");
743 nvram_unset("gpio5");
744 nvram_unset("gpio6");
747 nvram_set("opo", "0x0008");
748 nvram_set("ag0", "0x02");
751 nvram_set("gpio2", "ses_led");
752 nvram_set("gpio3", "ses_led2");
753 nvram_set("gpio4", "ses_button");
754 features
= SUP_SES
| SUP_WHAM_LED
;
761 if (!nvram_match("t_fix1", (char *)name
)) {
762 nvram_set("lan_ifnames", "vlan0 eth1");
763 nvram_set("gpio2", "ses_button");
764 nvram_set("reset_gpio", "7");
766 nvram_set("pa0itssit", "62");
767 nvram_set("pa0b0", "0x1542");
768 nvram_set("pa0b1", "0xfacb");
769 nvram_set("pa0b2", "0xfec7");
770 //nvram_set("pa0maxpwr", "0x4c");
773 case MODEL_WRTSL54GS
:
776 features
= SUP_SES
| SUP_WHAM_LED
;
781 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
784 case MODEL_WZRRSG54HP
:
787 features
= SUP_SES
| SUP_AOSS_LED
| SUP_HPAMP
;
789 case MODEL_WZRRSG54HP
:
790 name
= "WZR-RS-G54HP";
797 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
| SUP_HPAMP
;
801 bf
= strtoul(nvram_safe_get("boardflags"), NULL
, 0);
807 if (nvram_match("wlx_hpamp", "")) {
808 if (nvram_get_int("wl_txpwr") > 10) nvram_set("wl_txpwr", "10");
809 nvram_set("wlx_hpamp", "1");
810 nvram_set("wlx_hperx", "0");
814 if (nvram_match("wlx_hpamp", "0")) {
820 if (nvram_match("wlx_hperx", "0")) {
827 sprintf(s
, "0x%lX", n
);
828 nvram_set("boardflags", s
);
832 syslog(LOG_WARNING
, "Unexpected: boardflag=%lX", bf
);
843 features
= SUP_SES
| SUP_AOSS_LED
;
845 case MODEL_WHR2A54G54
:
847 name
= "WHR2-A54G54";
848 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
853 features
= SUP_SES
| SUP_AOSS_LED
;
858 features
= SUP_SES
| SUP_AOSS_LED
;
863 features
= SUP_SES
| SUP_AOSS_LED
;
873 features
= SUP_SES
| SUP_AOSS_LED
;
882 features
= SUP_NONVE
;
886 name
= "WR850G v2/v3";
887 features
= SUP_NONVE
;
894 nvram_set("usb_ohci", "-1");
896 if (!nvram_match("t_fix1", (char *)name
)) {
897 nvram_set("lan_ifnames", "vlan0 eth1 eth2 eth3"); // set to "vlan0 eth2" by DD-WRT; default: vlan0 eth1
903 features
= SUP_SES
| SUP_80211N
;
905 nvram_set("usb_ohci", "-1");
913 nvram_set("usb_uhci", "-1");
932 if (!nvram_match("t_fix1", (char *)name
)) {
933 nvram_set("lan_ifnames", "vlan0 eth1 eth2");
934 nvram_set("wl_ifname", "eth1");
935 nvram_set("wan_ifname", "none");
940 name
= "TrueMobile 2300";
949 #ifndef WL_BSS_INFO_VERSION
950 #error WL_BSS_INFO_VERSION
952 #if WL_BSS_INFO_VERSION >= 108
958 nvram_set("opo", "12");
964 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
966 nvram_set("opo", "0x0008");
967 nvram_set("ag0", "0x0C");
973 features
= SUP_SES
| SUP_80211N
;
974 if (!nvram_match("t_fix1", (char *)name
)) {
975 nvram_set("lan_ifnames", "vlan0 eth1");
976 nvram_set("wan_ifnameX", "vlan1");
977 nvram_set("wl_ifname", "eth1");
983 features
= SUP_SES
| SUP_80211N
;
985 nvram_set("usb_uhci", "-1");
987 if (!nvram_match("t_fix1", (char *)name
)) {
988 nvram_set("lan_ifnames", "vlan0 eth1");
989 nvram_set("wan_ifnameX", "vlan1");
990 nvram_set("wl_ifname", "eth1");
996 features
= SUP_SES
| SUP_BRAU
| SUP_80211N
;
997 if (!nvram_match("t_fix1", (char *)name
)) {
998 nvram_set("lan_ifnames", "vlan0 eth1");
999 nvram_set("wan_ifnameX", "vlan1");
1000 nvram_set("wl_ifname", "eth1");
1006 features
= SUP_80211N
;
1007 if (!nvram_match("t_fix1", (char *)name
)) {
1008 nvram_set("lan_ifnames", "vlan0 eth1");
1009 nvram_set("wan_ifnameX", "vlan1");
1010 nvram_set("wl_ifname", "eth1");
1016 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1018 nvram_set("usb_uhci", "-1");
1020 if (!nvram_match("t_fix1", (char *)name
)) {
1021 nvram_set("lan_ifnames", "vlan1 eth1");
1022 nvram_set("wan_iface", "vlan2");
1023 nvram_set("wan_ifname", "vlan2");
1024 nvram_set("wan_ifnameX", "vlan2");
1025 nvram_set("wan_ifnames", "vlan2");
1026 nvram_set("wl_ifname", "eth1");
1032 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1034 nvram_set("usb_uhci", "-1");
1036 if (!nvram_match("t_fix1", (char *)name
)) {
1037 nvram_set("lan_ifnames", "vlan1 eth1");
1038 nvram_set("wan_ifnameX", "vlan2");
1039 nvram_set("wl_ifname", "eth1");
1040 nvram_set("vlan_enable", "1");
1046 features
= SUP_SES
| SUP_80211N
;
1047 if (!nvram_match("t_fix1", (char *)name
)) {
1048 nvram_set("lan_ifnames", "vlan2 eth1");
1049 nvram_set("wan_ifnameX", "vlan1");
1050 nvram_set("landevs", "vlan2 wl0");
1051 nvram_set("wandevs", "vlan1");
1052 nvram_unset("vlan0ports");
1058 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1060 nvram_set("usb_uhci", "-1");
1061 #if defined(LINUX26) && defined(TCONFIG_USB_EXTRAS)
1062 if (nvram_get_int("usb_mmc") == -1) nvram_set("usb_mmc", "0");
1065 if (!nvram_match("t_fix1", (char *)name
)) {
1066 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1067 nvram_set("wan_ifnameX", "vlan2");
1068 nvram_set("wl_ifnames", "eth1 eth2");
1069 nvram_set("landevs", "vlan1 wl0 wl1");
1070 nvram_set("wandevs", "vlan2");
1071 #if defined(LINUX26) && defined(TCONFIG_USB)
1072 nvram_set("usb_noled", "1-1.4"); /* SD/MMC Card */
1076 case MODEL_WNR3500L
:
1078 name
= "WNR3500L/U/v2";
1079 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
| SUP_1000ET
;
1080 if (!nvram_match("t_fix1", (char *)name
)) {
1081 nvram_set("sromrev", "3");
1082 nvram_set("lan_ifnames", "vlan1 eth1");
1083 nvram_set("wan_ifnameX", "vlan2");
1084 nvram_set("wl_ifname", "eth1");
1087 case MODEL_WNR3500LV2
:
1089 name
= "WNR3500L v2";
1090 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
| SUP_1000ET
;
1091 if (!nvram_match("t_fix1", (char *)name
)) {
1092 nvram_set("lan_ifnames", "vlan1 eth1");
1093 nvram_set("wan_ifnameX", "vlan2");
1094 nvram_set("wl_ifname", "eth1");
1097 case MODEL_WNR2000v2
:
1099 name
= "WNR2000 v2";
1100 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
;
1101 if (!nvram_match("t_fix1", (char *)name
)) {
1102 nvram_set("lan_ifnames", "vlan0 eth1");
1103 nvram_set("wan_ifnameX", "vlan1");
1104 nvram_set("wl_ifname", "eth1");
1111 case MODEL_F5D8235v3
:
1113 features
= SUP_SES
| SUP_80211N
;
1116 name
= "Share Max N300 (F7D3301/F7D7301) v1";
1119 name
= "Share N300 (F7D3302/F7D7302) v1";
1122 name
= "Play Max / N600 HD (F7D4301/F7D8301) v1";
1125 name
= "Play N600 (F7D4302/F7D8302) v1";
1127 case MODEL_F5D8235v3
:
1128 name
= "N F5D8235-4 v3";
1132 nvram_set("usb_uhci", "-1");
1134 if (!nvram_match("t_fix1", (char *)name
)) {
1135 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1136 nvram_set("wan_ifnameX", "vlan2");
1137 nvram_set("landevs", "vlan1 wl0 wl1");
1138 nvram_set("wandevs", "vlan2");
1144 name
= nvram_safe_get("boot_hw_model");
1145 ver
= nvram_safe_get("boot_hw_ver");
1146 features
= SUP_SES
| SUP_80211N
;
1147 if (!nvram_match("t_fix1", (char *)name
)) {
1148 nvram_set("lan_ifnames", "vlan1 eth1");
1149 nvram_set("wan_ifnameX", "vlan2");
1150 nvram_set("wl_ifname", "eth1");
1155 name
= nvram_safe_get("boot_hw_model");
1156 ver
= nvram_safe_get("boot_hw_ver");
1157 features
= SUP_SES
| SUP_80211N
;
1159 nvram_set("usb_uhci", "-1");
1161 if (!nvram_match("t_fix1", (char *)name
)) {
1162 nvram_set("lan_ifnames", "vlan1 eth1");
1163 nvram_set("wan_ifnameX", "vlan2");
1164 nvram_set("wl_ifname", "eth1");
1169 name
= nvram_safe_get("boot_hw_model");
1170 ver
= nvram_safe_get("boot_hw_ver");
1171 features
= SUP_SES
| SUP_80211N
;
1172 if (!nvram_match("t_fix1", (char *)name
)) {
1173 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1174 nvram_set("wan_ifnameX", "vlan2");
1175 nvram_set("wl_ifname", "eth1");
1180 name
= nvram_safe_get("boot_hw_model");
1181 ver
= nvram_safe_get("boot_hw_ver");
1182 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1184 nvram_set("usb_uhci", "-1");
1186 if (!nvram_match("t_fix1", (char *)name
)) {
1187 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1188 nvram_set("wan_ifnameX", "vlan2");
1189 nvram_set("wl_ifname", "eth1");
1193 case MODEL_WRT160Nv3
:
1194 // same as M10, M20, WRT310Nv2, E1000v1
1196 name
= nvram_safe_get("boot_hw_model");
1197 ver
= nvram_safe_get("boot_hw_ver");
1198 if (nvram_match("boot_hw_model", "E100")){
1201 if (nvram_match("boot_hw_model", "M10") || nvram_match("boot_hw_model", "M20")){
1204 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
;
1205 if (!nvram_match("t_fix1", (char *)name
)) {
1206 nvram_set("lan_ifnames", "vlan1 eth1");
1207 nvram_set("wan_ifnameX", "vlan2");
1208 nvram_set("wl_ifname", "eth1");
1213 name
= nvram_match("boardrev", "0x1307") ? "E2000" : "WRT320N";
1214 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1215 if (!nvram_match("t_fix1", (char *)name
)) {
1216 nvram_set("lan_ifnames", "vlan1 eth1");
1217 nvram_set("wan_ifnameX", "vlan2");
1218 nvram_set("wl_ifname", "eth1");
1221 case MODEL_WRT610Nv2
:
1223 name
= nvram_match("boot_hw_model", "E300") ? "E3000" : "WRT610N v2";
1224 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1226 nvram_set("usb_uhci", "-1");
1228 if (!nvram_match("t_fix1", (char *)name
)) {
1229 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1230 nvram_set("wan_ifnameX", "vlan2");
1231 nvram_set("wl_ifname", "eth1");
1237 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1239 nvram_set("usb_uhci", "-1");
1241 if (!nvram_match("t_fix1", (char *)name
)) {
1242 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1243 nvram_set("wan_ifnameX", "vlan2");
1244 nvram_set("wl_ifname", "eth1");
1247 #endif // CONFIG_BCMWL5
1251 // The 330gE has only one wired port which can act either as WAN or LAN.
1252 // Failsafe mode is to have it start as a LAN port so you can get an IP
1253 // address via DHCP and access the router config page.
1254 if (!nvram_match("t_fix1", (char *)name
)) {
1255 nvram_set("wl_ifname", "eth1");
1256 nvram_set("lan_ifnames", "eth1");
1257 nvram_set("wan_ifnameX", "eth0");
1258 nvram_set("wan_islan", "1");
1259 nvram_set("wan_proto", "disabled");
1262 case MODEL_WL500GPv2
:
1264 name
= "WL-500gP v2";
1267 nvram_set("usb_uhci", "-1");
1275 nvram_set("usb_uhci", "-1");
1280 name
= "WL-500g Deluxe";
1281 // features = SUP_SES;
1283 nvram_set("usb_ohci", "-1");
1285 if (!nvram_match("t_fix1", (char *)name
)) {
1286 nvram_set("wl_ifname", "eth1");
1287 nvram_set("lan_ifnames", "vlan0 eth1");
1288 nvram_set("wan_ifnameX", "vlan1");
1289 nvram_unset("wl0gpio0");
1296 if (!nvram_match("t_fix1", (char *)name
)) {
1297 nvram_set("wan_ifnameX", "vlan1");
1298 nvram_set("wl_ifname", "eth1");
1303 name
= "ZXV10 H618B";
1304 features
= SUP_SES
| SUP_AOSS_LED
;
1306 case MODEL_WL1600GL
:
1311 #endif // WL_BSS_INFO_VERSION >= 108
1312 case MODEL_WZRG300N
:
1315 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
| SUP_80211N
;
1317 case MODEL_WRT160Nv1
:
1320 name
= (model
== MODEL_WRT300N
) ? "WRT300N v1" : "WRT160N v1";
1321 features
= SUP_SES
| SUP_80211N
;
1322 if (!nvram_match("t_fix1", (char *)name
)) {
1323 nvram_set("wan_ifnameX", "eth1");
1324 nvram_set("lan_ifnames", "eth0 eth2");
1327 case MODEL_WRT310Nv1
:
1329 name
= "WRT310N v1";
1330 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1331 if (!nvram_match("t_fix1", (char *)name
)) {
1332 nvram_set("lan_ifnames", "vlan1 eth1");
1333 nvram_set("wan_ifnameX", "vlan2");
1334 nvram_set("wl_ifname", "eth1");
1340 nvram_set("t_fix1", name
);
1341 /* Don't show the version information if it's empty (null or empty string) */
1342 if (ver
== NULL
|| strcmp(ver
, "") == 0) {
1343 sprintf(s
, "%s %s", mfr
, name
);
1345 sprintf(s
, "%s %s v%s", mfr
, name
, ver
);
1349 snprintf(s
, sizeof(s
), "%s %d/%s/%s/%s/%s", mfr
, check_hw_type(),
1350 nvram_safe_get("boardtype"), nvram_safe_get("boardnum"), nvram_safe_get("boardrev"), nvram_safe_get("boardflags"));
1354 nvram_set("t_model_name", s
);
1356 nvram_set("pa0maxpwr", "400"); // allow Tx power up tp 400 mW, needed for ND only
1358 sprintf(s
, "0x%lX", features
);
1359 nvram_set("t_features", s
);
1362 note: set wan_ifnameX if wan_ifname needs to be overriden
1365 if (nvram_is_empty("wan_ifnameX")) {
1367 nvram_set("wan_ifnameX", ((strtoul(nvram_safe_get("boardflags"), NULL
, 0) & BFL_ENETVLAN
) ||
1368 (check_hw_type() == HW_BCM4712
)) ? "vlan1" : "eth1");
1370 p
= nvram_safe_get("wan_ifname");
1371 if ((*p
== 0) || (nvram_match("wl_ifname", p
))) {
1372 p
= ((strtoul(nvram_safe_get("boardflags"), NULL
, 0) & BFL_ENETVLAN
) ||
1373 (check_hw_type() == HW_BCM4712
)) ? "vlan1" : "eth1";
1375 nvram_set("wan_ifnameX", p
);
1379 //!!TB - do not force country code here to allow nvram override
1380 //nvram_set("wl_country", "JP");
1381 //nvram_set("wl_country_code", "JP");
1382 nvram_set("wan_get_dns", "");
1383 nvram_set("wan_get_domain", "");
1384 nvram_set("ppp_get_ip", "");
1385 nvram_set("action_service", "");
1386 nvram_set("jffs2_format", "0");
1387 nvram_set("rrules_radio", "-1");
1388 nvram_unset("https_crt_gen");
1389 nvram_unset("log_wmclear");
1391 nvram_set("ipv6_get_dns", "");
1393 #ifdef TCONFIG_MEDIA_SERVER
1394 nvram_unset("ms_rescan");
1396 if (nvram_get_int("http_id_gen") == 1) nvram_unset("http_id");
1398 nvram_unset("sch_rboot_last");
1399 nvram_unset("sch_rcon_last");
1400 nvram_unset("sch_c1_last");
1401 nvram_unset("sch_c2_last");
1402 nvram_unset("sch_c3_last");
1404 nvram_set("brau_state", "");
1405 if ((features
& SUP_BRAU
) == 0) nvram_set("script_brau", "");
1406 if ((features
& SUP_SES
) == 0) nvram_set("sesx_script", "");
1408 if ((features
& SUP_1000ET
) == 0) nvram_set("jumbo_frame_enable", "0");
1410 // compatibility with old versions
1411 if (nvram_match("wl_net_mode", "disabled")) {
1412 nvram_set("wl_radio", "0");
1413 nvram_set("wl_net_mode", "mixed");
1419 /* Get the special files from nvram and copy them to disc.
1420 * These were files saved with "nvram setfile2nvram <filename>".
1421 * Better hope that they were saved with full pathname.
1423 static void load_files_from_nvram(void)
1427 char buf
[NVRAM_SPACE
];
1429 if (nvram_getall(buf
, sizeof(buf
)) != 0)
1432 for (name
= buf
; *name
; name
+= strlen(name
) + 1) {
1433 if (strncmp(name
, "FILE:", 5) == 0) { /* This special name marks a file to get. */
1434 if ((cp
= strchr(name
, '=')) == NULL
)
1437 syslog(LOG_INFO
, "Loading file '%s' from nvram", name
+ 5);
1438 nvram_nvram2file(name
, name
+ 5);
1439 if (memcmp(".autorun", cp
- 8, 9) == 0)
1443 /* Start any autorun files that may have been loaded into one of the standard places. */
1445 run_nvscript(".autorun", NULL
, 3);
1448 #if defined(LINUX26) && defined(TCONFIG_USB)
1449 static inline void tune_min_free_kbytes(void)
1451 struct sysinfo info
;
1453 memset(&info
, 0, sizeof(struct sysinfo
));
1455 if (info
.totalram
>= 55 * 1024 * 1024) {
1456 // If we have 64MB+ RAM, tune min_free_kbytes
1457 // to reduce page allocation failure errors.
1458 f_write_string("/proc/sys/vm/min_free_kbytes", "8192", 0, 0);
1463 static void sysinit(void)
1465 static int noconsole
= 0;
1466 static const time_t tm
= 0;
1475 mount("proc", "/proc", "proc", 0, NULL
);
1476 mount("tmpfs", "/tmp", "tmpfs", 0, NULL
);
1479 mount("devfs", "/dev", "tmpfs", MS_MGC_VAL
| MS_NOATIME
, NULL
);
1480 mknod("/dev/null", S_IFCHR
| 0666, makedev(1, 3));
1481 mknod("/dev/console", S_IFCHR
| 0600, makedev(5, 1));
1482 mount("sysfs", "/sys", "sysfs", MS_MGC_VAL
, NULL
);
1483 mkdir("/dev/shm", 0777);
1484 mkdir("/dev/pts", 0777);
1485 mknod("/dev/pts/ptmx", S_IRWXU
|S_IFCHR
, makedev(5, 2));
1486 mknod("/dev/pts/0", S_IRWXU
|S_IFCHR
, makedev(136, 0));
1487 mknod("/dev/pts/1", S_IRWXU
|S_IFCHR
, makedev(136, 1));
1488 mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL
, NULL
);
1491 if (console_init()) noconsole
= 1;
1495 static const char *mkd
[] = {
1496 "/tmp/etc", "/tmp/var", "/tmp/home", "/tmp/mnt",
1497 "/tmp/splashd", //!!Victek
1498 "/tmp/share", "/var/webmon", // !!TB
1499 "/var/log", "/var/run", "/var/tmp", "/var/lib", "/var/lib/misc",
1500 "/var/spool", "/var/spool/cron", "/var/spool/cron/crontabs",
1501 "/tmp/var/wwwext", "/tmp/var/wwwext/cgi-bin", // !!TB - CGI support
1505 for (i
= 0; mkd
[i
]; ++i
) {
1506 mkdir(mkd
[i
], 0755);
1508 mkdir("/var/lock", 0777);
1509 mkdir("/var/tmp/dhcp", 0777);
1510 mkdir("/home/root", 0700);
1511 chmod("/tmp", 0777);
1512 f_write("/etc/hosts", NULL
, 0, 0, 0644); // blank
1513 f_write("/etc/fstab", NULL
, 0, 0, 0644); // !!TB - blank
1514 simple_unlock("cron");
1515 simple_unlock("firewall");
1516 simple_unlock("restrictions");
1519 if ((d
= opendir("/rom/etc")) != NULL
) {
1520 while ((de
= readdir(d
)) != NULL
) {
1521 if (de
->d_name
[0] == '.') continue;
1522 snprintf(s
, sizeof(s
), "%s/%s", "/rom/etc", de
->d_name
);
1523 snprintf(t
, sizeof(t
), "%s/%s", "/etc", de
->d_name
);
1528 symlink("/proc/mounts", "/etc/mtab");
1530 #ifdef TCONFIG_SAMBASRV
1531 if ((d
= opendir("/usr/codepages")) != NULL
) {
1532 while ((de
= readdir(d
)) != NULL
) {
1533 if (de
->d_name
[0] == '.') continue;
1534 snprintf(s
, sizeof(s
), "/usr/codepages/%s", de
->d_name
);
1535 snprintf(t
, sizeof(t
), "/usr/share/%s", de
->d_name
);
1543 eval("hotplug2", "--coldplug");
1546 static const char *dn
[] = {
1547 "null", "zero", "random", "urandom", "full", "ptmx", "nvram",
1550 for (i
= 0; dn
[i
]; ++i
) {
1551 snprintf(s
, sizeof(s
), "/dev/%s", dn
[i
]);
1554 chmod("/dev/gpio", 0660);
1557 set_action(ACT_IDLE
);
1559 for (i
= 0; defenv
[i
]; ++i
) {
1564 printf("\n\nHit ENTER for console...\n\n");
1571 // disable IPv6 by default on all interfaces
1572 f_write_string("/proc/sys/net/ipv6/conf/default/disable_ipv6", "1", 0, 0);
1575 for (i
= 0; i
< sizeof(fatalsigs
) / sizeof(fatalsigs
[0]); i
++) {
1576 signal(fatalsigs
[i
], handle_fatalsigs
);
1578 signal(SIGCHLD
, handle_reap
);
1580 switch (model
= get_model()) {
1581 case MODEL_WR850GV1
:
1582 case MODEL_WR850GV2
:
1583 // need to cleanup some variables...
1584 if ((nvram_get("t_model") == NULL
) && (nvram_get("MyFirmwareVersion") != NULL
)) {
1585 nvram_unset("MyFirmwareVersion");
1586 nvram_set("restore_defaults", "1");
1591 #ifdef CONFIG_BCMWL5
1592 // ctf must be loaded prior to any other modules
1593 if (nvram_invmatch("ctf_disable", "1"))
1602 switch (hardware
= check_hw_type()) {
1604 modprobe("bcm57xx");
1615 eval("nvram", "defaults", "--initcheck");
1618 // set the packet size
1619 if (nvram_get_int("jumbo_frame_enable")) {
1620 // only set the size here - 'enable' flag is set by the driver
1621 // eval("et", "robowr", "0x40", "0x01", "0x1F"); // (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)
1622 eval("et", "robowr", "0x40", "0x05", nvram_safe_get("jumbo_frame_size"));
1625 klogctl(8, NULL
, nvram_get_int("console_loglevel"));
1627 #if defined(LINUX26) && defined(TCONFIG_USB)
1628 tune_min_free_kbytes();
1631 set_host_domain_name();
1637 if (!noconsole
) xstart("console");
1639 i
= nvram_get_int("sesx_led");
1640 led(LED_AMBER
, (i
& 1) != 0);
1641 led(LED_WHITE
, (i
& 2) != 0);
1642 led(LED_AOSS
, (i
& 4) != 0);
1643 led(LED_BRIDGE
, (i
& 8) != 0);
1647 int init_main(int argc
, char *argv
[])
1653 nvram_unset("debug_rc_svc");
1657 sigemptyset(&sigset
);
1658 for (i
= 0; i
< sizeof(initsigs
) / sizeof(initsigs
[0]); i
++) {
1659 sigaddset(&sigset
, initsigs
[i
]);
1661 sigprocmask(SIG_BLOCK
, &sigset
, NULL
);
1663 #if defined(DEBUG_NOISY)
1664 nvram_set("debug_logeval", "1");
1665 nvram_set("debug_cprintf", "1");
1666 nvram_set("debug_cprintf_file", "1");
1667 nvram_set("debug_ddns", "1");
1672 state
= SIGUSR2
; /* START */
1675 TRACE_PT("main loop signal/state=%d\n", state
);
1678 case SIGUSR1
: /* USER1: service handler */
1682 case SIGHUP
: /* RESTART */
1683 case SIGINT
: /* STOP */
1684 case SIGQUIT
: /* HALT */
1685 case SIGTERM
: /* REBOOT */
1687 unlink("/var/notice/sysup");
1689 run_nvscript("script_shut", NULL
, 10);
1697 if ((state
== SIGTERM
/* REBOOT */) ||
1698 (state
== SIGQUIT
/* HALT */)) {
1699 remove_storage_main(1);
1702 shutdn(state
== SIGTERM
/* REBOOT */);
1705 if (state
== SIGINT
/* STOP */) {
1709 // SIGHUP (RESTART) falls through
1711 case SIGUSR2
: /* START */
1712 SET_LED(RELEASE_WAN_CONTROL
);
1715 load_files_from_nvram();
1718 fd
= file_lock("usb"); // hold off automount processing
1721 run_nvscript("script_init", NULL
, 2);
1723 file_unlock(fd
); // allow to process usb hotplug events
1726 * On RESTART some partitions can stay mounted if they are busy at the moment.
1727 * In that case USB drivers won't unload, and hotplug won't kick off again to
1728 * remount those drives that actually got unmounted. Make sure to remount ALL
1729 * partitions here by simulating hotplug event.
1731 if (state
== SIGHUP
/* RESTART */)
1732 add_remove_usbhost("-1", 1);
1743 #ifdef CONFIG_BCMWL5
1745 /* Restart NAS one more time - for some reason without
1746 * this the new driver doesn't always bring WDS up.
1753 syslog(LOG_INFO
, "%s: Tomato %s", nvram_safe_get("t_model_name"), tomato_version
);
1756 notice_set("sysup", "");
1760 chld_reap(0); /* Periodically reap zombies. */
1762 sigwait(&sigset
, &state
);
1768 int reboothalt_main(int argc
, char *argv
[])
1770 int reboot
= (strstr(argv
[0], "reboot") != NULL
);
1771 puts(reboot
? "Rebooting..." : "Shutting down...");
1774 kill(1, reboot
? SIGTERM
: SIGQUIT
);
1776 /* In the case we're hung, we'll get stuck and never actually reboot.
1777 * The only way out is to pull power.
1778 * So after 'reset_wait' seconds (default: 20), forcibly crash & restart.
1781 int wait
= nvram_get_int("reset_wait") ? : 20;
1782 if ((wait
< 10) || (wait
> 120)) wait
= 10;
1784 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
1786 puts("Still running... Doing machine reset.");
1788 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
1790 f_write("/proc/sysrq-trigger", "b", 1, 0 , 0); /* machine reset */