一直找不到n14u的init.rc文件,心里还在纳闷,无意中进到router/rc目录,才发现了一些端倪!
原来,华硕用的是*硬编码*的方式来实现init.rc的,rc目录就相当于init.rc!
而里面的各种文件,分别担当了不同的角色,比如lan.c,wan.c之类的,看名字就能明白是干什么的了。
下面的代码是init.c中的片段:
case MODEL_RTN14U:
nvram_set("boardflags", "0x100"); // although it is not used in ralink driver, set for vlan
nvram_set("vlan1hwname", "et0"); // vlan. used to get "%smacaddr" for compare and find parent interface.
nvram_set("vlan2hwname", "et0"); // vlan. used to get "%smacaddr" for compare and find parent interface.
nvram_set("lan_ifname", "br0");
if(nvram_get_int("sw_mode")==SW_MODE_AP) {
nvram_set("lan_ifnames", "vlan1 vlan2 ra0");
nvram_set("wan_ifnames", "");
}
else { // router/default
nvram_set("lan_ifnames", "vlan1 ra0");
nvram_set("wan_ifnames", "vlan2");
}
nvram_set("wl_ifnames","ra0");
// it is virtual id only for ui control
nvram_set("wl0_vifnames", "wl0.1 wl0.2 wl0.3");
nvram_set("wl1_vifnames", "");
nvram_set_int("btn_rst_gpio", 1|GPIO_ACTIVE_LOW);
nvram_set_int("btn_wps_gpio", 2|GPIO_ACTIVE_LOW);
nvram_set_int("led_usb_gpio", 42|GPIO_ACTIVE_LOW);
nvram_set_int("led_lan_gpio", 41|GPIO_ACTIVE_LOW);
nvram_set_int("led_wan_gpio", 40|GPIO_ACTIVE_LOW);
nvram_set_int("led_pwr_gpio", 43|GPIO_ACTIVE_LOW);
nvram_set_int("led_wps_gpio", 43|GPIO_ACTIVE_LOW);
nvram_set_int("led_2g_gpio", 72|GPIO_ACTIVE_LOW);
eval("rtkswitch", "11");
nvram_set("ehci_ports", "1-1");
nvram_set("ohci_ports", "2-1");
// if(!nvram_get("ct_max"))
nvram_set("ct_max", "300000"); // force
if (nvram_match("wl_mssid", "1"))
add_rc_support("mssid");
add_rc_support("2.4G update usbX1");
add_rc_support("rawifi");
add_rc_support("switchctrl"); //for hwnat only
add_rc_support("manual_stb");
// the following values is model dep. so move it from default.c to here
nvram_set("wl0_HT_TxStream", "2");
nvram_set("wl0_HT_RxStream", "2");
break;
仔细研究rc里面的代码,发现代码里面有大量的_dprintf用于调试内容的输出,这对于我们分析系统是非常有利的,该函数在shared.h(share目录)中定义如下:
#ifdef DEBUG_NOISY
#define _dprintf cprintf
#define csprintf cprintf
#else
#define _dprintf(args...) do { } while(0)
#define csprintf(args...) do { } while(0)
#endif
只需要把开关DEBUG_NOISY打开就行了。