Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
126 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
126 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
126 theseven 9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
126 theseven 14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
126 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
132 theseven 25
#include "clickwheel.h"
563 theseven 26
#include "s5l8701.h"
126 theseven 27
 
28
 
29
#define nor ((uint8_t*)0x24000000)
30
#define norword ((uint32_t*)0x24000000)
31
#define sysi ((uint8_t*)0x2202bdf0)
32
#define sysiword ((uint32_t*)0x2202bdf0)
33
 
34
 
35
void targetinit_late()
36
{
37
    int i;
38
 
132 theseven 39
    clickwheel_init();
40
 
126 theseven 41
    uint32_t scfg_size = norword[0x401];
42
    uint32_t scfg_entrycount = norword[0x405];
43
    if (norword[0x400] == 0x53436667 && scfg_size <= 0x1000
44
     && scfg_entrycount * 0x14 + 0x18 == scfg_size)
45
    {
46
        memset(sysi, 0, 0x104);
47
        sysiword[0] = 0x53797349;
48
        sysiword[1] = 0x104;
49
        sysiword[0x21] = 0x100000;
50
        for (i = 0; i < scfg_entrycount; i++)
51
            switch (norword[0x406 + i * 5])
52
            {
53
                case 0x48774e6d: // HwNm
54
                    memcpy(&sysi[0x08], &norword[0x406 + i * 5 + 1], 16);
55
                    break;
56
                case 0x48775672: // HwVr
57
                    if (norword[0x406 + i * 5 + 1] == 0)
58
                        sysiword[0x21] = norword[0x406 + i * 5 + 2];
59
                    break;
60
                case 0x53724e6d: // SrNm
61
                    memcpy(&sysi[0x18], &norword[0x406 + i * 5 + 1], 16);
62
                    break;
63
                case 0x46774964: // FwId
64
                    if (nor[0x1018 + i * 0x14 + 7] == 0)
65
                    {
66
                        memcpy(&sysi[0x38], &norword[0x406 + i * 5 + 2], 3);
67
                        sysi[0x3b] = 2;
68
                        sysiword[0xf] = 0xa2700;
69
                    }
70
                    else memcpy(&sysi[0x38], &norword[0x406 + i * 5 + 2], 8);
71
                    memset(&sysi[0x40], 10, 0);
72
                    break;
73
                case 0x556e7443: // UntC
74
                    memcpy(&sysi[0xbc], &norword[0x406 + i * 5 + 1], 16);
75
                    break;
76
                case 0x52746341: // RtcA
77
                    if (norword[0x406 + i * 5 + 1] == 1)
78
                        sysiword[0x80] = norword[0x406 + i * 5 + 2];
79
                    break;
80
                case 0x42747279: // Btry
81
                    if (norword[0x406 + i * 5 + 1] == 1)
82
                        memcpy(&sysi[0x5c], &norword[0x406 + i * 5 + 2], 12);
83
                    break;
84
                case 0x5265676e: // Regn
85
                    if (nor[0x1018 + i * 0x14 + 4] == 1 && nor[0x1018 + i * 0x14 + 5] == 0)
86
                        memcpy(&sysi[0x92], &norword[0x406 + i * 5 + 2], 4);
87
                    break;
88
                case 0x4d6f6423: // Mod#
89
                    memcpy(&sysi[0x98], &norword[0x406 + i * 5 + 1], 16);
90
                    break;
91
                case 0x48774f31: // Hw01
92
                    memcpy(&sysi[0xa8], &norword[0x406 + i * 5 + 1], 16);
93
                    break;
94
                case 0x436f6e74: // Cont
95
                    if (nor[0x1018 + i * 0x14 + 4] == 0 && nor[0x1018 + i * 0x14 + 5] == 0)
96
                    {
97
                        sysi[0xb8] = nor[0x1018 + i * 0x14 + 6];
98
                        sysi[0xb9] = nor[0x1018 + i * 0x14 + 8];
99
                    }
100
                    break;
101
                case 0x426b4c74: // BkLt
102
                    if (nor[0x1018 + i * 0x14 + 4] == 0xaa && nor[0x1018 + i * 0x14 + 5] == 0x55)
103
                    {
104
                        sysi[0xba] = nor[0x1018 + i * 0x14 + 6];
105
                        sysi[0xbb] = nor[0x1018 + i * 0x14 + 8];
106
                    }
107
                    break;
108
                case 0x44726d56: // DrmV
109
                    memcpy(&sysi[0xce], &norword[0x406 + i * 5 + 1], 16);
110
                    break;
111
            }
112
        sysiword[2] = 0x646f5069;
113
        sysiword[3] = 0x36334e20;
114
        sysi[0x88] = 0x4e;
115
        sysi[0x89] = 0x41;
116
        sysiword[0x38] = 0x2000000;
117
        sysiword[0x39] = 0x8000000;
118
        sysiword[0x3a] = 0x2c000;
119
        sysiword[0x3b] = 0x22000000;
120
        sysiword[0x3c] = 0x100000;
121
        sysiword[0x3d] = 0x24000000;
122
        sysiword[0x4a] = 0x53797349;
123
        sysiword[0x4b] = 0x2202bdf0;
124
    }
125
}
563 theseven 126
 
127
void targetinit_execfirmware()
128
{
129
    PWRCON(0) &= ~(1 << 5);
130
    IICSTAT = (1 << 4);
131
}