示例#1
0
void start_backup(void)
{
	char drive[64];
#ifdef HAVE_OPENRISC
	sprintf(drive, "/dev/sda");
#elif HAVE_RB600
	sprintf(drive, "/dev/sda");
#else
	sprintf(drive, "/dev/%s", getdisc());
#endif
	//backup nvram
	fprintf(stderr, "backup nvram\n");
	FILE *in = fopen("/usr/local/nvram/nvram.bin", "rb");
	if (in) {
		char *mem = malloc(65536);
		fread(mem, 65536, 1, in);
		fclose(in);
		in = fopen(drive, "r+b");
		fseeko(in, 0, SEEK_END);
		off_t mtdlen = ftello(in);
		fseeko(in, mtdlen - (65536 * 2), SEEK_SET);
		fwrite(mem, 65536, 1, in);
		fclose(in);
		eval("sync");
		fprintf(stderr, "reread for sync disc\n");
		in = fopen(drive, "rb");
		fseeko(in, mtdlen - (65536 * 2), SEEK_SET);
		fread(mem, 65536, 1, in);
		fprintf(stderr, "%X%X%X%X\n", mem[0] & 0xff, mem[1] & 0xff, mem[2] & 0xff, mem[3] & 0xff);
		fclose(in);
		free(mem);
	}

}
示例#2
0
void start_recover(void)
{
	FILE *in;
	char dev[64];
	fprintf(stderr, "recover broken nvram\n");
#ifdef HAVE_OPENRISC
	sprintf(dev, "/dev/sda");
#elif HAVE_RB600
	sprintf(dev, "/dev/sda");
#else
	sprintf(dev, "/dev/%s", getdisc());
#endif
	in = fopen(dev, "rb");
	fseeko(in, 0, SEEK_END);
	off_t mtdlen = ftello64(in);
	fseeko(in, mtdlen - (65536 * 2), SEEK_SET);

	unsigned char *mem = malloc(65536);
	fread(mem, 65536, 1, in);
	fclose(in);
	if (mem[0] == 0x46 && mem[1] == 0x4c && mem[2] == 0x53 && mem[3] == 0x48) {
		fprintf(stderr, "found recovery\n");
		in = fopen("/usr/local/nvram/nvram.bin", "wb");
		if (in != NULL) {
			fwrite(mem, 65536, 1, in);
			fclose(in);
		}
	}
	free(mem);

}
示例#3
0
void start_sysinit(void)
{
	time_t tm = 0;

	char dev[64];
	char *disk = getdisc();

	if (disk == NULL) {
		fprintf(stderr, "no valid dd-wrt partition found, calling shell");
		eval("/bin/sh");
		exit(0);
	}

	FILE *in = fopen("/usr/local/nvram/nvram.db", "rb");

	if (in != NULL) {
		fclose(in);
		mkdir("/tmp/nvram", 0700);
		eval("cp", "/etc/nvram/nvram.db", "/tmp/nvram");
		eval("cp", "/etc/nvram/offsets.db", "/tmp/nvram");
		eval("/usr/sbin/convertnvram");
		nvram_commit();
		eval("rm", "-f", "/etc/nvram/nvram.db");
		eval("rm", "-f", "/etc/nvram/offsets.db");
	}
	//recover nvram if available
	in = fopen("/usr/local/nvram/nvram.bin", "rb");
	if (in == NULL) {
		fprintf(stderr, "recover broken nvram\n");
		sprintf(dev, "/dev/%s", disk);
		in = fopen(dev, "rb");
		fseeko(in, 0, SEEK_END);
		off_t mtdlen = ftello(in);
		fseeko(in, mtdlen - (65536 * 2), SEEK_SET);
		unsigned char *mem = malloc(65536);
		fread(mem, 65536, 1, in);
		fclose(in);
		if (mem[0] == 0x46 && mem[1] == 0x4c && mem[2] == 0x53 && mem[3] == 0x48) {
			fprintf(stderr, "found recovery\n");
			in = fopen("/usr/local/nvram/nvram.bin", "wb");
			if (in != NULL) {
				fwrite(mem, 65536, 1, in);
				fclose(in);
				free(mem);
				eval("sync");
				sleep(5);
				eval("event", "5", "1", "15");
			}
		}
		free(mem);
	} else {
		fclose(in);
	}

	if (!nvram_match("disable_watchdog", "1"))
		eval("watchdog");	// system watchdog
#ifdef HAVE_ERC
	if (isregistered_real() && nvram_match("ree_resetme", "1")) {
		fprintf(stderr, "Restoring REE default nvram\n");
		eval("nvram", "restore", "/etc/defaults/x86ree.backup");
		eval("reboot");
		eval("event", "5", "1", "15");
	}
#endif

	cprintf("sysinit() setup console\n");

	/*
	 * Setup console 
	 */

	cprintf("sysinit() klogctl\n");
	klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel")));
	cprintf("sysinit() get router\n");

	/*
	 * eval("insmod","md5"); eval("insmod","aes"); eval("insmod","blowfish");
	 * eval("insmod","deflate"); eval("insmod","des");
	 * eval("insmod","michael_mic"); eval("insmod","cast5");
	 * eval("insmod","crypto_null"); 
	 */

	detect_ethernet_devices();
	eval("ifconfig", "eth0", "0.0.0.0", "up");
	eval("ifconfig", "eth1", "0.0.0.0", "up");
	eval("ifconfig", "eth2", "0.0.0.0", "up");
	eval("ifconfig", "eth3", "0.0.0.0", "up");

	struct ifreq ifr;
	int s;

	if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
		char eabuf[32];

		strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
		ioctl(s, SIOCGIFHWADDR, &ifr);
		nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf));
		nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf));
		close(s);
	}
	detect_wireless_devices();

	mknod("/dev/rtc", S_IFCHR | 0644, makedev(253, 0));
#ifdef HAVE_CPUTEMP
	// insmod("nsc_gpio");
	// insmod("scx200_gpio");
	// insmod("scx200_i2c");
	// insmod("scx200_acb");
	// insmod("lm77");
#endif

	nvram_set("wl0_ifname", "ath0");
	mknod("/dev/crypto", S_IFCHR | 0644, makedev(10, 70));
	/*
	 * Set a sane date 
	 */
	stime(&tm);
	cprintf("done\n");
	return;
}