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

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

support overclocking for standard routerstation boards

File size: 3.1 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    char check[8];
62    char check2[8];
63    char values[8]={0x24,0x08,0x00,0xaa,0x15,0x09,0x00,0x04};
64    fseek(in,0xc0,SEEK_SET);
65    fread(check,1,8,in);
66    fseek(in,0xc4,SEEK_SET);
67    fread(check2,1,8,in);
68    int ret1=0xff;
69    int ret2=0xff;
70    if ((ret1=memcmp(check,values,8)) && (ret2=memcmp(check2,values,8)))
71        {
72        fprintf(stderr,"no compatible routerstation bootloader found\n");
73        fclose(in);
74        return;
75        }
76    if (!ret1)
77        fprintf(stderr,"bootloader rev1 found\n");
78    if (!ret2)
79        fprintf(stderr,"bootloader rev2 found\n");
80    FILE *out = fopen( "/tmp/boot", "w+b" );
81    rewind(in);
82    for (i=0;i<len;i++)
83        putc(getc(in),out);
84    fclose(in);
85    int ret=1;
86    if (nvram_match("cpuclk","200"))
87        ret=overclock(out,"200",0x1);
88    if (nvram_match("cpuclk","300"))
89        ret=overclock(out,"300",0x2);
90    if (nvram_match("cpuclk","333"))
91        ret=overclock(out,"333",0x3);
92    if (nvram_match("cpuclk","400"))
93        ret=overclock(out,"400",0x6);
94    if (nvram_match("cpuclk","600"))
95        ret=overclock(out,"600",0x7);
96    if (nvram_match("cpuclk","680"))  //special ubiquiti setting with different ddram clock settings
97        ret=overclock(out,"680",0xa);
98    if (nvram_match("cpuclk","720"))
99        ret=overclock(out,"720",0x1e);
100    if (nvram_match("cpuclk","800"))
101        ret=overclock(out,"800",0x1f);
102fclose(out);
103if (!ret)
104    {
105    fprintf(stderr,"write new bootloader\n");
106//    eval( "mtd", "-f", "write", "/tmp/boot", "RedBoot" );
107    fprintf(stderr,"board now clocked to %sMhz\n",nvram_safe_get("cpuclk"));
108    }
109}
110
111
112int main (int argc, char *argv[]) { start_overclock (); }
113
114
Note: See TracBrowser for help on using the repository browser.