Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
304 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
304 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
304 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,
304 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/>.
304 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
961 theseven 25
#include "bootflash.h"
304 theseven 26
#include "clickwheel.h"
961 theseven 27
#include "clockgates.h"
28
#include "s5l8702.h"
304 theseven 29
 
30
 
961 theseven 31
#define sysi ((uint8_t*)0x2203fdf8)
32
#define sysiword ((uint32_t*)0x2203fdf8)
33
 
34
 
304 theseven 35
void targetinit_late()
36
{
961 theseven 37
    int i;
38
 
304 theseven 39
    clickwheel_init();
961 theseven 40
 
41
    uint8_t* nor = (uint8_t*)memalign(0x10, 0x1000);
42
    uint32_t* norword = (uint32_t*)nor;
43
    if (!nor) return;
44
    bootflash_readraw(nor, 0, 0x1000);
45
    uint32_t scfg_size = norword[1];
46
    uint32_t scfg_entrycount = norword[5];
47
    if (norword[0] == 0x53436667 && scfg_size <= 0x1000
48
     && scfg_entrycount * 0x14 + 0x18 == scfg_size)
49
    {
50
        memset(sysi, 0, 0x128);
51
        sysiword[0] = 0x53797349;
52
        sysiword[1] = 4;
53
        sysiword[0x22] = 0x414e;
54
        sysiword[0x38] = 0x4000000;
55
        sysiword[0x39] = 0x8000000;
56
        sysiword[0x3a] = 0x40000;
57
        sysiword[0x3b] = 0x22000000;
58
        sysiword[0x3c] = 0x100000;
59
        sysiword[0x3d] = 0x24000000;
60
        sysiword[0x46] = 0x7672736e;
61
        sysiword[0x47] = 0x1308004;
62
        sysiword[0x48] = 0x53797349;
63
        sysiword[0x49] = 0x2203fdf8;
64
        for (i = 0; i < scfg_entrycount; i++)
65
            switch (norword[6 + i * 5])
66
            {
67
                case 0x53724e6d: // SrNm
68
                    memcpy(&sysi[0x18], &norword[6 + i * 5 + 1], 16);
69
                    break;
70
                case 0x46774964: // FwId
71
                    memcpy(&sysi[0x38], &norword[6 + i * 5 + 2], 8);
72
                    break;
73
                case 0x48775672: // HwVr
74
                    sysiword[0x21] = norword[6 + i * 5 + 2];
75
                    break;
76
                case 0x5265676e: // Regn
77
                    if (nor[24 + i * 0x14 + 4] == 1 && nor[24 + i * 0x14 + 5] == 0)
78
                        memcpy(&sysi[0x92], &norword[6 + i * 5 + 2], 4);
79
                    break;
80
                case 0x4d6f6423: // Mod#
81
                    memcpy(&sysi[0x98], &norword[6 + i * 5 + 1], 16);
82
                    break;
83
                case 0x436f6463: // Codc
84
                    sysiword[0x45] = norword[6 + i * 5 + 1];
85
                    break;
86
                case 0x53775672: // SwVr
87
                    memcpy(&sysi[0x108], &norword[6 + i * 5 + 1], 16);
88
                    break;
89
            }
90
		switch (sysiword[0x21])
91
		{
92
			case 0x130100:
93
				sysiword[0x47] = 0x1308004;
94
				break;
95
			case 0x130200:
96
				sysiword[0x47] = 0x1708004;
97
				break;
98
		}
99
    }
100
    free(nor);
304 theseven 101
}
961 theseven 102
 
103
void targetinit_execfirmware() ICODE_ATTR;
104
void targetinit_execfirmware()
105
{
106
    clockgate_enable(CLOCKGATE_I2C_0, true);
107
    while (IIC10(0));
108
    IICCON(0) = 0x184;
109
}
110