source: src/router/services/tools/overclock_routerstation.c @ 11706

Last change on this file since 11706 was 11706, checked in by BrainSlayer, 4 years ago

overclocking capability for routerstation

File size: 2.8 KB
Line 
1/*
2 * overclock_routerstation.c
3 *
4 * Copyright (C) 2008 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 * usage:
21 * nvram set cpuclk=800
22 * startservice overclock
23 *
24 * valid cpuclk values are 680, 720, 800
25 */
26#include <unistd.h>
27#include <sys/types.h>
28#include <stdio.h>
29#include <string.h>
30#include <stdlib.h>
31#include <fcntl.h>
32#include <shutils.h>
33#include <bcmnvram.h>
34
35
36int overclock(FILE *out,char *freq,int value)
37{
38fseek(out,0xd3,SEEK_SET);
39int val = getc(out);
40if (val==value)
41        {
42        fprintf(stderr,"board already clocked to %sMhz\n",freq);
43        return -1;
44        }
45fseek(out,0xd3,SEEK_SET);
46putc(value,out);
47return 0;
48}
49
50void start_overclock( void )    // hidden feature. must be called with
51                                // "startservice overlock". then reboot the
52                                // unit
53{
54    long len;
55    long i;
56
57    FILE *in = fopen( "/dev/mtdblock/0", "rb" );
58    fseek(in,0,SEEK_END);
59    len = ftell(in);
60    rewind(in);
61    fseek(in,0xc0,SEEK_SET);
62    char check[8];
63    char values[8]={0x24,0x08,0x00,0xaa,0x15,0x09,0x00,0x04};
64    fread(check,1,8,in);
65    if (memcmp(check,values,8))
66        {
67        fprintf(stderr,"no compatible routerstation bootloader found\n");
68        fclose(in);
69        return;
70        }
71    FILE *out = fopen( "/tmp/boot", "w+b" );
72    rewind(in);
73    for (i=0;i<len;i++)
74        putc(getc(in),out);
75    fclose(in);
76    int ret=1;
77    if (nvram_match("cpuclk","200"))
78        ret=overclock(out,"200",0x1);
79    if (nvram_match("cpuclk","300"))
80        ret=overclock(out,"300",0x2);
81    if (nvram_match("cpuclk","333"))
82        ret=overclock(out,"333",0x3);
83    if (nvram_match("cpuclk","400"))
84        ret=overclock(out,"400",0x6);
85    if (nvram_match("cpuclk","600"))
86        ret=overclock(out,"600",0x7);
87    if (nvram_match("cpuclk","680"))  //special ubiquiti setting with different ddram clock settings
88        ret=overclock(out,"680",0xa);
89    if (nvram_match("cpuclk","720"))
90        ret=overclock(out,"720",0x1e);
91    if (nvram_match("cpuclk","800"))
92        ret=overclock(out,"800",0x1f);
93fclose(out);
94if (!ret)
95    {
96    fprintf(stderr,"write new bootloader\n");
97//    eval( "mtd", "-f", "write", "/tmp/boot", "RedBoot" );
98    fprintf(stderr,"board now clocked to %sMhz\n",nvram_safe_get("cpuclk"));
99    }
100}
101
102
103// int main (int argc, char *argv[]) { start_overclock (); }
104
Note: See TracBrowser for help on using the repository browser.