| 253 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2009 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of the Linux4Nano toolkit.
|
|
|
7 |
//
|
|
|
8 |
// TheSeven's iBugger is free software: you can redistribute it and/or
|
|
|
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 |
//
|
|
|
13 |
// TheSeven's iBugger is distributed in the hope that it will be useful,
|
|
|
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
|
|
|
19 |
// with the Linux4Nano toolkit. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
#include <toolkit.h>
|
|
|
25 |
#include <ftl.h>
|
|
|
26 |
#include "timer.h"
|
|
|
27 |
|
|
|
28 |
extern void _loaddest() __attribute__((noreturn));
|
|
|
29 |
extern char _filename;
|
|
|
30 |
|
|
|
31 |
uint32_t fatsect[0x2000] __attribute__((aligned(16)));
|
|
|
32 |
|
|
|
33 |
void main()
|
|
|
34 |
{
|
|
|
35 |
int i;
|
|
|
36 |
singlebeep(50, 100000);
|
|
|
37 |
sleep(50000);
|
|
|
38 |
singlebeep(40, 100000);
|
|
|
39 |
if (ftl_init()) beep(2);
|
|
|
40 |
ftl_read(0, 1, fatsect);
|
|
|
41 |
if (((uint16_t*)fatsect)[0xff] != 0xaa55) beep(5);
|
|
|
42 |
uint32_t partstart = 0;
|
|
|
43 |
for (i = 0x1c2; i < 0x200; i += 0x10)
|
|
|
44 |
if (((uint8_t*)fatsect)[i] == 0xb)
|
|
|
45 |
{
|
|
|
46 |
partstart = *((uint16_t*)((uint32_t)fatsect + i + 4))
|
|
|
47 |
| (*((uint16_t*)((uint32_t)fatsect + i + 6)) << 16);
|
|
|
48 |
break;
|
|
|
49 |
}
|
|
|
50 |
if (*((uint16_t*)((uint32_t)fatsect + 0x52)) != 0x4146
|
|
|
51 |
|| *((uint8_t*)((uint32_t)fatsect + 0x54)) != 0x54)
|
|
|
52 |
beep(9);
|
|
|
53 |
ftl_read(partstart, 1, fatsect);
|
|
|
54 |
if (((uint16_t*)fatsect)[0xff] != 0xaa55) beep(4);
|
|
|
55 |
uint32_t secperclus = ((uint8_t*)fatsect)[0xd];
|
|
|
56 |
uint32_t reserved = ((uint16_t*)fatsect)[7];
|
|
|
57 |
uint32_t fatcount = ((uint8_t*)fatsect)[0x10];
|
|
|
58 |
uint32_t fatsize = fatsect[9];
|
|
|
59 |
uint32_t rootdirclus = fatsect[0xb];
|
|
|
60 |
uint32_t startsect = partstart + reserved + fatcount * fatsize - 2 * secperclus;
|
|
|
61 |
while (rootdirclus < 0xfffffff)
|
|
|
62 |
{
|
|
|
63 |
ftl_read(startsect + rootdirclus * secperclus, secperclus, fatsect);
|
|
|
64 |
for (i = 0; i < secperclus * 64; i++)
|
|
|
65 |
if (!memcmp(&fatsect[i * 8], "NOTES ", 11))
|
|
|
66 |
{
|
|
|
67 |
rootdirclus = (((uint16_t*)fatsect)[i * 16 + 0xa] << 16)
|
|
|
68 |
| ((uint16_t*)fatsect)[i * 16 + 0xd];
|
|
|
69 |
while (rootdirclus < 0xfffffff)
|
|
|
70 |
{
|
|
|
71 |
ftl_read(startsect + rootdirclus * secperclus, secperclus, fatsect);
|
|
|
72 |
for (i = 0; i < secperclus * 64; i++)
|
|
|
73 |
if (!memcmp(&fatsect[i * 8], &_filename, 11))
|
|
|
74 |
{
|
|
|
75 |
rootdirclus = (((uint16_t*)fatsect)[i * 16 + 0xa] << 16)
|
|
|
76 |
| ((uint16_t*)fatsect)[i * 16 + 0xd];
|
|
|
77 |
uint32_t dest = (uint32_t)_loaddest;
|
|
|
78 |
int fatsectnum = -1;
|
|
|
79 |
while (rootdirclus < 0xfffffff)
|
|
|
80 |
{
|
|
|
81 |
ftl_read(startsect + rootdirclus * secperclus, secperclus, (void*)dest);
|
|
|
82 |
dest += secperclus * 2048;
|
|
|
83 |
if ((rootdirclus >> 9) != fatsectnum)
|
|
|
84 |
{
|
|
|
85 |
ftl_read(partstart + reserved + (rootdirclus >> 9), 1, fatsect);
|
|
|
86 |
fatsectnum = rootdirclus >> 9;
|
|
|
87 |
}
|
|
|
88 |
rootdirclus = fatsect[rootdirclus & 0x1ff];
|
|
|
89 |
}
|
|
|
90 |
memcpy(_loaddest, (void*)(((uint32_t)_loaddest) + 0x1000), dest - ((uint32_t)_loaddest));
|
|
|
91 |
singlebeep(40, 100000);
|
|
|
92 |
sleep(50000);
|
|
|
93 |
singlebeep(30, 100000);
|
|
|
94 |
DMACON0 = 0;
|
|
|
95 |
DMACON1 = 0;
|
|
|
96 |
DMACON2 = 0;
|
|
|
97 |
DMACON3 = 0;
|
|
|
98 |
DMACON4 = 0;
|
|
|
99 |
DMACON5 = 0;
|
|
|
100 |
DMACON6 = 0;
|
|
|
101 |
DMACON7 = 0;
|
|
|
102 |
DMACON8 = 0;
|
|
|
103 |
TACMD = 2;
|
|
|
104 |
TBCMD = 2;
|
|
|
105 |
TCCMD = 2;
|
|
|
106 |
TDCMD = 2;
|
|
|
107 |
TACON = TACON;
|
|
|
108 |
TBCON = TBCON;
|
|
|
109 |
TCCON = TCCON;
|
|
|
110 |
TDCON = TDCON;
|
|
|
111 |
SRCPND = SRCPND;
|
|
|
112 |
_loaddest();
|
|
|
113 |
return;
|
|
|
114 |
}
|
|
|
115 |
ftl_read(partstart + reserved + (rootdirclus >> 9), 1, fatsect);
|
|
|
116 |
rootdirclus = fatsect[rootdirclus & 0x1ff];
|
|
|
117 |
}
|
|
|
118 |
beep(7);
|
|
|
119 |
}
|
|
|
120 |
ftl_read(partstart + reserved + (rootdirclus >> 9), 1, fatsect);
|
|
|
121 |
rootdirclus = fatsect[rootdirclus & 0x1ff];
|
|
|
122 |
}
|
|
|
123 |
beep(6);
|
|
|
124 |
}
|