| 160 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2010 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
| 551 |
theseven |
6 |
// This file is part of emCORE.
|
| 160 |
theseven |
7 |
//
|
| 551 |
theseven |
8 |
// emCORE is free software: you can redistribute it and/or
|
| 160 |
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 |
//
|
| 551 |
theseven |
13 |
// emCORE is distributed in the hope that it will be useful,
|
| 160 |
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
|
| 551 |
theseven |
19 |
// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
| 160 |
theseven |
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
| 551 |
theseven |
24 |
#include "emcoreapp.h"
|
|
|
25 |
#include "libpng.h"
|
|
|
26 |
#include "libui.h"
|
| 160 |
theseven |
27 |
|
|
|
28 |
|
| 551 |
theseven |
29 |
#define STRINGIFY(x) #x
|
| 672 |
theseven |
30 |
#define STR(x) STRINGIFY(x)
|
|
|
31 |
#define BOOTNOTE_FILENAME "/Notes/" STR(BASENAME) ".bootnote"
|
| 551 |
theseven |
32 |
|
|
|
33 |
|
| 835 |
theseven |
34 |
void main(int argc, const char** argv);
|
| 551 |
theseven |
35 |
EMCORE_APP_HEADER("emCORE installer", main, 127)
|
| 160 |
theseven |
36 |
|
|
|
37 |
|
| 551 |
theseven |
38 |
extern char background_png[];
|
|
|
39 |
extern uint32_t background_png_size;
|
|
|
40 |
extern char darkener_png[];
|
|
|
41 |
extern uint32_t darkener_png_size;
|
|
|
42 |
extern char disclaimer_png[];
|
|
|
43 |
extern uint32_t disclaimer_png_size;
|
|
|
44 |
extern char actions_png[];
|
|
|
45 |
extern uint32_t actions_png_size;
|
|
|
46 |
extern char f_png_emcorelib[];
|
|
|
47 |
extern char f_ui_emcorelib[];
|
|
|
48 |
extern uint32_t flashscript[];
|
|
|
49 |
extern uint32_t firstinstcost;
|
|
|
50 |
extern uint32_t firstinstscript[];
|
|
|
51 |
extern uint32_t commoncost;
|
|
|
52 |
extern uint32_t commonscript[];
|
| 160 |
theseven |
53 |
|
|
|
54 |
|
|
|
55 |
uint32_t fat32_ok;
|
|
|
56 |
uint32_t fat32_startsector;
|
|
|
57 |
uint32_t fat32_secperclus;
|
|
|
58 |
uint32_t fat32_database;
|
|
|
59 |
uint32_t fat32_fatbase;
|
|
|
60 |
uint32_t fat32_fatsize;
|
|
|
61 |
uint32_t fat32_fatcount;
|
|
|
62 |
uint32_t fat32_sectorcount;
|
|
|
63 |
uint32_t fat32_clustercount;
|
|
|
64 |
uint32_t fat32_rootdirclus;
|
|
|
65 |
|
| 551 |
theseven |
66 |
struct wakeup eventwakeup;
|
|
|
67 |
volatile int button;
|
|
|
68 |
volatile int scrollpos;
|
|
|
69 |
|
|
|
70 |
|
| 160 |
theseven |
71 |
#define nor ((uint8_t*)0x24000000)
|
|
|
72 |
#define norword ((uint32_t*)0x24000000)
|
|
|
73 |
|
|
|
74 |
|
| 551 |
theseven |
75 |
void handler(void* user, enum button_event eventtype, int which, int value)
|
| 160 |
theseven |
76 |
{
|
|
|
77 |
if (eventtype == BUTTON_PRESS) button |= 1 << which;
|
| 630 |
theseven |
78 |
if (eventtype == BUTTON_RELEASE) button &= ~(1 << which);
|
| 551 |
theseven |
79 |
if (eventtype == WHEEL_MOVED_ACCEL)
|
|
|
80 |
scrollpos = MAX(0, MIN(309, scrollpos + value / 8));
|
| 160 |
theseven |
81 |
wakeup_signal(&eventwakeup);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
uint32_t freeret(uint32_t rc, void* ptr)
|
|
|
85 |
{
|
| 551 |
theseven |
86 |
free(ptr);
|
| 160 |
theseven |
87 |
return rc;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
int decryptfw(void* image, uint32_t offset)
|
|
|
91 |
{
|
|
|
92 |
uint32_t size = ((uint32_t*)image)[5];
|
|
|
93 |
if (size > 0x800000) return 0;
|
|
|
94 |
hwkeyaes(HWKEYAES_DECRYPT, ((uint32_t*)image)[2], &((uint8_t*)image)[offset], size);
|
|
|
95 |
memcpy(image, &((uint8_t*)image)[offset], size);
|
| 551 |
theseven |
96 |
cputc(3, '.');
|
| 160 |
theseven |
97 |
return size;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
uint32_t getfw(const char* filename, uint32_t* sector, int* size)
|
|
|
101 |
{
|
|
|
102 |
uint32_t i;
|
| 551 |
theseven |
103 |
uint32_t* buffer = memalign(0x10, 0x800);
|
| 160 |
theseven |
104 |
if (storage_read_sectors_md(0, 0, 1, buffer) != 0) return freeret(1, buffer);
|
|
|
105 |
if (*((uint16_t*)((uint32_t)buffer + 0x1FE)) != 0xAA55) return freeret(1, buffer);
|
|
|
106 |
uint32_t startsector = 0;
|
|
|
107 |
for (i = 0x1C2; i < 0x200; i += 0x10)
|
|
|
108 |
if (((uint8_t*)buffer)[i] == 0)
|
|
|
109 |
{
|
|
|
110 |
startsector = *((uint16_t*)((uint32_t)buffer + i + 4))
|
|
|
111 |
| (*((uint16_t*)((uint32_t)buffer + i + 6)) << 16);
|
|
|
112 |
break;
|
|
|
113 |
}
|
| 551 |
theseven |
114 |
cputc(3, '.');
|
| 160 |
theseven |
115 |
if (startsector == 0) return freeret(1, buffer);
|
|
|
116 |
if (storage_read_sectors_md(0, startsector, 1, buffer) != 0) return freeret(1, buffer);
|
| 551 |
theseven |
117 |
cputc(3, '.');
|
| 160 |
theseven |
118 |
if (buffer[0x40] != 0x5B68695D) return freeret(1, buffer);
|
|
|
119 |
if (storage_read_sectors_md(0, startsector + 1 + (buffer[0x41] >> 11), 1, buffer) != 0)
|
|
|
120 |
return freeret(1, buffer);
|
| 551 |
theseven |
121 |
cputc(3, '.');
|
| 160 |
theseven |
122 |
for (i = 0; i < 0x1FE; i += 10)
|
|
|
123 |
if (memcmp(&buffer[i], filename, 8) == 0)
|
|
|
124 |
{
|
|
|
125 |
*sector = startsector + (buffer[i + 3] >> 11);
|
|
|
126 |
*size = buffer[i + 4] + 0x800;
|
| 551 |
theseven |
127 |
free(buffer);
|
|
|
128 |
cputc(3, '.');
|
| 160 |
theseven |
129 |
return 0;
|
|
|
130 |
}
|
|
|
131 |
return freeret(2, buffer);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
uint32_t readfw(const char* filename, void** address, int* size)
|
|
|
135 |
{
|
|
|
136 |
uint32_t sector;
|
|
|
137 |
uint32_t rc = getfw(filename, §or, size);
|
|
|
138 |
if (rc) return rc;
|
| 551 |
theseven |
139 |
*address = memalign(0x10, *size);
|
| 160 |
theseven |
140 |
if (storage_read_sectors_md(0, sector, ((*size + 0x7FF) >> 11), *address) != 0)
|
|
|
141 |
return freeret(1, *address);
|
| 551 |
theseven |
142 |
cputc(3, '.');
|
| 160 |
theseven |
143 |
*size = decryptfw(*address, 0x800);
|
| 551 |
theseven |
144 |
realloc(*address, *size);
|
| 160 |
theseven |
145 |
return 0;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
uint32_t getapplenor(const char* filename, void** address, int* size)
|
|
|
149 |
{
|
|
|
150 |
uint32_t i;
|
|
|
151 |
for (i = 0xffe00; i < 0x100000; i += 0x28)
|
|
|
152 |
if (memcmp(&nor[i], filename, 8) == 0)
|
|
|
153 |
{
|
|
|
154 |
*size = norword[(i + 0x10) >> 2] + 0x200;
|
|
|
155 |
*address = &nor[norword[(i + 0xc) >> 2]];
|
|
|
156 |
return 0;
|
|
|
157 |
}
|
|
|
158 |
return 1;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
uint32_t readapplenor(const char* filename, void** address, int* size)
|
|
|
162 |
{
|
|
|
163 |
void* noraddr;
|
|
|
164 |
uint32_t rc = getapplenor(filename, &noraddr, size);
|
|
|
165 |
if (rc) return rc;
|
|
|
166 |
*address = malloc(*size);
|
|
|
167 |
memcpy(*address, noraddr, *size);
|
| 551 |
theseven |
168 |
cputc(3, '.');
|
| 160 |
theseven |
169 |
*size = decryptfw(*address, 0x200);
|
|
|
170 |
realloc(*address, *size);
|
|
|
171 |
return 0;
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
uint32_t fat32_resize_patchdirs(uint32_t clusterchain, uint32_t clustoffset,
|
|
|
175 |
struct progressbar_state* progressbar, int min, int len)
|
|
|
176 |
{
|
|
|
177 |
uint32_t i, j, rc;
|
|
|
178 |
uint32_t* buffer = (uint32_t*)memalign(0x10, 0x800);
|
|
|
179 |
int pos = min, newlen = len / 15;
|
|
|
180 |
while (clusterchain < 0x0ffffff0)
|
|
|
181 |
{
|
|
|
182 |
uint32_t sectorbase = (clusterchain - 2) * fat32_secperclus + fat32_database;
|
|
|
183 |
for (i = 0; i < fat32_secperclus; i++)
|
|
|
184 |
{
|
|
|
185 |
if (storage_read_sectors_md(0, sectorbase + i, 1, buffer))
|
|
|
186 |
{
|
|
|
187 |
free(buffer);
|
|
|
188 |
return 2;
|
|
|
189 |
}
|
|
|
190 |
for (j = 0; j < 64; j++)
|
|
|
191 |
if (!((uint8_t*)buffer)[i << 2])
|
|
|
192 |
{
|
|
|
193 |
free(buffer);
|
|
|
194 |
return 0;
|
|
|
195 |
}
|
|
|
196 |
else if (((uint8_t*)buffer)[j << 5] == 0xe5) continue;
|
|
|
197 |
else if (((uint8_t*)buffer)[(j << 5) + 11] & 8) continue;
|
|
|
198 |
else
|
|
|
199 |
{
|
|
|
200 |
uint32_t clust = (((uint16_t*)buffer)[(j << 4) + 0xa] << 16)
|
|
|
201 |
| ((uint16_t*)buffer)[(j << 4) + 0xd];
|
|
|
202 |
if (clust > 1 && clust < 0xffffff0)
|
|
|
203 |
{
|
|
|
204 |
clust += clustoffset;
|
|
|
205 |
((uint16_t*)buffer)[(j << 4) + 0xa] = clust >> 16;
|
|
|
206 |
((uint16_t*)buffer)[(j << 4) + 0xd] = clust & 0xffff;
|
|
|
207 |
if ((((uint8_t*)buffer)[(j << 5) + 0xb] & 0x10)
|
|
|
208 |
&& memcmp(&((uint8_t*)buffer)[j << 5], ". ", 11)
|
|
|
209 |
&& memcmp(&((uint8_t*)buffer)[j << 5], ".. ", 11))
|
|
|
210 |
if ((rc = fat32_resize_patchdirs(clust, clustoffset,
|
|
|
211 |
progressbar, pos, newlen)))
|
|
|
212 |
{
|
|
|
213 |
free(buffer);
|
|
|
214 |
return rc;
|
|
|
215 |
}
|
|
|
216 |
pos += newlen;
|
|
|
217 |
newlen = 15 * newlen / 16;
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
if (storage_write_sectors_md(0, sectorbase + i, 1, buffer))
|
|
|
221 |
{
|
|
|
222 |
free(buffer);
|
|
|
223 |
return 2;
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
uint32_t fatsector = fat32_fatbase + (clusterchain >> 9);
|
|
|
227 |
if (storage_read_sectors_md(0, fatsector, 1, buffer))
|
|
|
228 |
{
|
|
|
229 |
free(buffer);
|
|
|
230 |
return 2;
|
|
|
231 |
}
|
|
|
232 |
clusterchain = buffer[(i << 9) + (clusterchain & 0x1FF)];
|
|
|
233 |
}
|
|
|
234 |
free(buffer);
|
|
|
235 |
if (len) progressbar_setpos(progressbar, min + len, false);
|
|
|
236 |
return 0;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
uint32_t fat32_resize_fulldisk(struct progressbar_state* progressbar)
|
|
|
240 |
{
|
|
|
241 |
uint32_t i, j, rc;
|
|
|
242 |
uint32_t fatsectors = 1;
|
|
|
243 |
uint32_t oldfatsectors = 0;
|
|
|
244 |
uint32_t clustercount;
|
|
|
245 |
uint32_t reserved;
|
|
|
246 |
struct storage_info storageinfo;
|
|
|
247 |
storage_get_info(0, &storageinfo);
|
|
|
248 |
uint32_t totalsectors = storageinfo.num_sectors;
|
|
|
249 |
uint32_t* buf1 = (uint32_t*)memalign(0x10, 0x800);
|
|
|
250 |
uint32_t* buf2 = (uint32_t*)memalign(0x10, 0x800);
|
|
|
251 |
if (!fat32_ok)
|
|
|
252 |
{
|
|
|
253 |
fat32_secperclus = 4;
|
|
|
254 |
fat32_rootdirclus = 2;
|
|
|
255 |
}
|
|
|
256 |
while (fatsectors != oldfatsectors)
|
|
|
257 |
{
|
|
|
258 |
oldfatsectors = fatsectors;
|
|
|
259 |
if (!fat32_ok) reserved = 2;
|
|
|
260 |
else reserved = (fat32_database - fatsectors - 2) % fat32_secperclus + 2;
|
|
|
261 |
clustercount = (totalsectors - fatsectors - reserved) / fat32_secperclus;
|
|
|
262 |
fatsectors = (clustercount + 513) >> 9;
|
|
|
263 |
}
|
|
|
264 |
uint32_t database = fatsectors + reserved;
|
|
|
265 |
uint32_t clusoffset;
|
|
|
266 |
if (!fat32_ok) clusoffset = 0;
|
|
|
267 |
else clusoffset = (fat32_database - database) / fat32_secperclus;
|
|
|
268 |
memset(buf1, 0, 0x800);
|
|
|
269 |
if (fat32_ok)
|
|
|
270 |
if (storage_read_sectors_md(0, fat32_startsector, 1, buf2))
|
|
|
271 |
{
|
|
|
272 |
fat32_ok = 0;
|
|
|
273 |
free(buf1);
|
|
|
274 |
free(buf2);
|
|
|
275 |
return 2;
|
|
|
276 |
}
|
|
|
277 |
memcpy(buf1, "\xeb\x58\x00MSWIN5.0\0\x08", 0xd);
|
|
|
278 |
((uint8_t*)buf1)[0xd] = fat32_secperclus;
|
|
|
279 |
((uint16_t*)buf1)[7] = reserved;
|
|
|
280 |
memcpy(&((uint8_t*)buf1)[0x10], "\x01\0\0\0\0\xf8\0\0\x3f\0\xff", 0xb);
|
|
|
281 |
buf1[8] = totalsectors;
|
|
|
282 |
buf1[9] = fatsectors;
|
|
|
283 |
buf1[0xb] = fat32_rootdirclus + clusoffset;
|
|
|
284 |
((uint16_t*)buf1)[0x18] = 1;
|
|
|
285 |
((uint8_t*)buf1)[0x40] = 0x80;
|
|
|
286 |
((uint8_t*)buf1)[0x42] = 0x29;
|
| 672 |
theseven |
287 |
if (!fat32_ok) memcpy(&((uint8_t*)buf1)[0x43], "\0\0\0\0iPod Nano2G", 0xf);
|
| 160 |
theseven |
288 |
else memcpy(&((uint8_t*)buf1)[0x43], &((uint8_t*)buf2)[0x43], 0xf);
|
|
|
289 |
memcpy(&((uint8_t*)buf1)[0x52], "FAT32 ", 8);
|
|
|
290 |
((uint16_t*)buf1)[0xff] = 0xaa55;
|
|
|
291 |
if (storage_write_sectors_md(0, 0, 1, buf1))
|
|
|
292 |
{
|
|
|
293 |
fat32_ok = 0;
|
|
|
294 |
free(buf1);
|
|
|
295 |
free(buf2);
|
|
|
296 |
return 2;
|
|
|
297 |
}
|
|
|
298 |
if (fat32_ok)
|
|
|
299 |
{
|
|
|
300 |
if (storage_read_sectors_md(0, fat32_startsector + ((uint16_t*)buf2)[0x18], 1, buf1))
|
|
|
301 |
{
|
|
|
302 |
fat32_ok = 0;
|
|
|
303 |
free(buf1);
|
|
|
304 |
free(buf2);
|
|
|
305 |
return 2;
|
|
|
306 |
}
|
|
|
307 |
buf1[0x7a] += clustercount - fat32_clustercount;
|
|
|
308 |
}
|
|
|
309 |
else
|
|
|
310 |
{
|
|
|
311 |
memset(buf1, 0, 0x800);
|
|
|
312 |
buf1[0] = 0x41615252;
|
|
|
313 |
buf1[0x79] = 0x61417272;
|
|
|
314 |
buf1[0x7a] = clustercount - 1;
|
|
|
315 |
buf1[0x7b] = 2;
|
|
|
316 |
buf1[0x7f] = 0xaa550000;
|
|
|
317 |
}
|
|
|
318 |
if (storage_write_sectors_md(0, 1, 1, buf1))
|
|
|
319 |
{
|
|
|
320 |
fat32_ok = 0;
|
|
|
321 |
free(buf1);
|
|
|
322 |
free(buf2);
|
|
|
323 |
return 2;
|
|
|
324 |
}
|
|
|
325 |
progressbar_setpos(progressbar, 5, false);
|
|
|
326 |
uint32_t cursect = 0;
|
|
|
327 |
if (!fat32_ok)
|
|
|
328 |
{
|
|
|
329 |
for (i = 0; i < fatsectors; i++)
|
|
|
330 |
{
|
|
|
331 |
memset(buf1, 0, 0x800);
|
|
|
332 |
if (!i) memcpy(buf1, "\xf8\xff\xff\x0f\xff\xff\xff\xff\xff\xff\xff\x0f", 12);
|
|
|
333 |
if (storage_write_sectors_md(0, reserved + i, 1, buf1))
|
|
|
334 |
{
|
|
|
335 |
free(buf1);
|
|
|
336 |
free(buf2);
|
|
|
337 |
return 2;
|
|
|
338 |
}
|
|
|
339 |
progressbar_setpos(progressbar, 5 + i * 90 / fatsectors, false);
|
|
|
340 |
}
|
|
|
341 |
}
|
|
|
342 |
else
|
|
|
343 |
{
|
|
|
344 |
for (i = 0; i < fatsectors; i++)
|
|
|
345 |
{
|
|
|
346 |
memset(buf1, 0, 0x800);
|
|
|
347 |
for (j = 0; j < 512; j++)
|
|
|
348 |
{
|
|
|
349 |
if (!i && !j) buf1[j] = 0x0fffffff;
|
|
|
350 |
else if (!i && j == 1) buf1[j] = 0xffffffff;
|
|
|
351 |
else if (((i << 9) | j) < clusoffset + 2);
|
|
|
352 |
else if (((i << 9) | j) >= clusoffset + fat32_clustercount + 2);
|
|
|
353 |
else
|
|
|
354 |
{
|
|
|
355 |
uint32_t oldclust = (((i << 9) | j) - clusoffset);
|
|
|
356 |
if (((oldclust >> 9) + fat32_fatbase) != cursect)
|
|
|
357 |
{
|
|
|
358 |
cursect = (oldclust >> 9) + fat32_fatbase;
|
|
|
359 |
if (storage_read_sectors_md(0, cursect, 1, buf2))
|
|
|
360 |
{
|
|
|
361 |
fat32_ok = 0;
|
|
|
362 |
free(buf1);
|
|
|
363 |
free(buf2);
|
|
|
364 |
return 2;
|
|
|
365 |
}
|
|
|
366 |
}
|
|
|
367 |
buf1[j] = buf2[oldclust & 0x1ff];
|
|
|
368 |
if (buf1[j] > 1 && buf1[j] < 0xffffff0)
|
|
|
369 |
buf1[j] += clusoffset;
|
|
|
370 |
}
|
|
|
371 |
}
|
|
|
372 |
if (storage_write_sectors_md(0, reserved + i, 1, buf1))
|
|
|
373 |
{
|
|
|
374 |
fat32_ok = 0;
|
|
|
375 |
free(buf1);
|
|
|
376 |
free(buf2);
|
|
|
377 |
return 2;
|
|
|
378 |
}
|
|
|
379 |
progressbar_setpos(progressbar, 5 + i * 20 / fatsectors, false);
|
|
|
380 |
}
|
|
|
381 |
}
|
|
|
382 |
fat32_startsector = 0;
|
|
|
383 |
fat32_database = database;
|
|
|
384 |
fat32_fatbase = reserved;
|
|
|
385 |
fat32_fatsize = fatsectors;
|
|
|
386 |
fat32_fatcount = 1;
|
|
|
387 |
fat32_sectorcount = totalsectors;
|
|
|
388 |
fat32_clustercount = clustercount;
|
|
|
389 |
fat32_rootdirclus = fat32_rootdirclus + clusoffset;
|
|
|
390 |
if (!fat32_ok)
|
|
|
391 |
{
|
|
|
392 |
for (i = 0; i < fat32_secperclus; i++)
|
|
|
393 |
{
|
|
|
394 |
memset(buf1, 0, 0x800);
|
| 672 |
theseven |
395 |
if (!i) memcpy(buf1, "iPod Nano2G\x08", 12);
|
| 160 |
theseven |
396 |
if (storage_write_sectors_md(0, database + i, 1, buf1))
|
|
|
397 |
{
|
|
|
398 |
free(buf1);
|
|
|
399 |
free(buf2);
|
|
|
400 |
return 2;
|
|
|
401 |
}
|
|
|
402 |
}
|
|
|
403 |
free(buf1);
|
|
|
404 |
free(buf2);
|
|
|
405 |
}
|
|
|
406 |
else
|
|
|
407 |
{
|
|
|
408 |
free(buf1);
|
|
|
409 |
free(buf2);
|
|
|
410 |
if ((rc = fat32_resize_patchdirs(fat32_rootdirclus, clusoffset, progressbar, 25, 75)))
|
|
|
411 |
{
|
|
|
412 |
fat32_ok = 0;
|
|
|
413 |
return rc;
|
|
|
414 |
}
|
|
|
415 |
}
|
|
|
416 |
progressbar_setpos(progressbar, 100, false);
|
|
|
417 |
fat32_ok = 1;
|
|
|
418 |
return 0;
|
|
|
419 |
}
|
|
|
420 |
|
|
|
421 |
uint32_t fat32_init()
|
|
|
422 |
{
|
|
|
423 |
uint32_t i;
|
|
|
424 |
fat32_ok = 0;
|
|
|
425 |
fat32_startsector = 0xFFFFFFFF;
|
|
|
426 |
uint32_t* buf = (uint32_t*)memalign(0x10, 0x800);
|
|
|
427 |
|
|
|
428 |
if (storage_read_sectors_md(0, 0, 1, buf)) return freeret(2, buf);
|
|
|
429 |
|
|
|
430 |
if (*((uint16_t*)((uint32_t)buf + 0x1FE)) != 0xAA55) return 1;
|
|
|
431 |
|
|
|
432 |
for (i = 0x1C2; i < 0x200; i += 0x10)
|
|
|
433 |
if (((uint8_t*)buf)[i] == 0xB)
|
|
|
434 |
{
|
|
|
435 |
fat32_startsector = *((uint16_t*)((uint32_t)buf + i + 4))
|
|
|
436 |
| (*((uint16_t*)((uint32_t)buf + i + 6)) << 16);
|
|
|
437 |
break;
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
if (fat32_startsector == 0xFFFFFFFF
|
|
|
441 |
&& *((uint16_t*)((uint32_t)buf + 0x52)) == 0x4146
|
|
|
442 |
&& *((uint8_t*)((uint32_t)buf + 0x54)) == 0x54)
|
|
|
443 |
fat32_startsector = 0;
|
|
|
444 |
|
|
|
445 |
if (fat32_startsector == 0xFFFFFFFF) return freeret(1, buf);
|
|
|
446 |
|
|
|
447 |
if (storage_read_sectors_md(0, fat32_startsector, 1, buf)) return freeret(2, buf);
|
|
|
448 |
|
|
|
449 |
if (*((uint16_t*)((uint32_t)buf + 0x1FE)) != 0xAA55) return freeret(1, buf);
|
|
|
450 |
|
|
|
451 |
if (((uint8_t*)buf)[0xB] != 0 || ((uint8_t*)buf)[0xC] != 8) return freeret(1, buf);
|
|
|
452 |
|
|
|
453 |
fat32_secperclus = ((uint8_t*)buf)[0xD];
|
|
|
454 |
uint32_t reserved = ((uint16_t*)buf)[0x7];
|
|
|
455 |
fat32_fatcount = ((uint8_t*)buf)[0x10];
|
|
|
456 |
|
|
|
457 |
if (((uint8_t*)buf)[0x11] != 0) return freeret(1, buf);
|
|
|
458 |
|
|
|
459 |
fat32_sectorcount = buf[8];
|
|
|
460 |
fat32_fatsize = buf[9];
|
|
|
461 |
|
|
|
462 |
if (((uint16_t*)buf)[0x15] != 0) return freeret(1, buf);
|
|
|
463 |
|
|
|
464 |
fat32_rootdirclus = buf[0xB];
|
|
|
465 |
free(buf);
|
|
|
466 |
|
|
|
467 |
fat32_clustercount = (fat32_sectorcount - reserved
|
|
|
468 |
- fat32_fatcount * fat32_fatsize) / fat32_secperclus;
|
|
|
469 |
|
|
|
470 |
fat32_fatbase = fat32_startsector + reserved;
|
|
|
471 |
fat32_database = fat32_fatbase + fat32_fatcount * fat32_fatsize;
|
|
|
472 |
|
|
|
473 |
fat32_ok = 1;
|
|
|
474 |
return 0;
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
void main(void)
|
|
|
478 |
{
|
|
|
479 |
uint32_t i, j, k, rc;
|
|
|
480 |
uint32_t dummy;
|
| 256 |
theseven |
481 |
int deleterc = 1;
|
| 160 |
theseven |
482 |
struct progressbar_state progressbar;
|
|
|
483 |
bool repartition = false;
|
|
|
484 |
bool appleflash;
|
|
|
485 |
void* syscfgptr;
|
|
|
486 |
int osossize = 0;
|
|
|
487 |
void* ososptr;
|
|
|
488 |
int diaguclsize = 0;
|
|
|
489 |
void* diaguclptr;
|
|
|
490 |
int diskuclsize = 0;
|
|
|
491 |
void* diskuclptr;
|
|
|
492 |
uint8_t* norbuf;
|
|
|
493 |
#define norbufword ((uint32_t*)norbuf)
|
|
|
494 |
|
| 551 |
theseven |
495 |
cputc(3, '.');
|
| 651 |
theseven |
496 |
struct emcorelib_header* libpng = get_library(LIBPNG_IDENTIFIER, LIBPNG_API_VERSION, LIBSOURCE_RAM_NEEDCOPY, f_png_emcorelib);
|
| 551 |
theseven |
497 |
if (!libpng) panicf(PANIC_KILLTHREAD, "Could not load PNG decoder library!");
|
|
|
498 |
struct libpng_api* png = (struct libpng_api*)libpng->api;
|
|
|
499 |
cputc(3, '.');
|
| 651 |
theseven |
500 |
struct emcorelib_header* libui = get_library(LIBUI_IDENTIFIER, LIBUI_API_VERSION, LIBSOURCE_RAM_NEEDCOPY, f_ui_emcorelib);
|
| 551 |
theseven |
501 |
if (!libui) panicf(PANIC_KILLTHREAD, "Could not load user interface library!");
|
|
|
502 |
struct libui_api* ui = (struct libui_api*)libui->api;
|
|
|
503 |
cputc(3, '.');
|
| 160 |
theseven |
504 |
|
| 551 |
theseven |
505 |
struct png_info* handle = png->png_open(background_png, background_png_size);
|
|
|
506 |
if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse background image!");
|
|
|
507 |
cputc(3, '.');
|
|
|
508 |
struct png_rgb* bg = png->png_decode_rgb(handle);
|
|
|
509 |
if (!bg) panicf(PANIC_KILLTHREAD, "Could not decode background image!");
|
|
|
510 |
png->png_destroy(handle);
|
|
|
511 |
cputc(3, '.');
|
|
|
512 |
void* darkened = malloc(176 * 132 * 3);
|
|
|
513 |
if (!darkened) panicf(PANIC_KILLTHREAD, "Could not allocate darkened image!");
|
|
|
514 |
cputc(3, '.');
|
|
|
515 |
handle = png->png_open(darkener_png, darkener_png_size);
|
|
|
516 |
if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse darkener image!");
|
|
|
517 |
cputc(3, '.');
|
|
|
518 |
struct png_rgba* darkener = png->png_decode_rgba(handle);
|
|
|
519 |
if (!darkener) panicf(PANIC_KILLTHREAD, "Could not decode darkener image!");
|
|
|
520 |
png->png_destroy(handle);
|
|
|
521 |
cputc(3, '.');
|
|
|
522 |
ui->blenda(176, 132, 255, darkened, 0, 0, 176, bg, 0, 0, 176, darkener, 0, 0, 176);
|
|
|
523 |
free(darkener);
|
|
|
524 |
cputc(3, '.');
|
|
|
525 |
handle = png->png_open(disclaimer_png, disclaimer_png_size);
|
|
|
526 |
if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse disclaimer image!");
|
|
|
527 |
cputc(3, '.');
|
|
|
528 |
struct png_rgba* disclaimer = png->png_decode_rgba(handle);
|
|
|
529 |
if (!disclaimer) panicf(PANIC_KILLTHREAD, "Could not decode disclaimer image!");
|
|
|
530 |
png->png_destroy(handle);
|
|
|
531 |
cputc(3, '.');
|
|
|
532 |
handle = png->png_open(actions_png, actions_png_size);
|
|
|
533 |
if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse actions image!");
|
|
|
534 |
cputc(3, '.');
|
|
|
535 |
struct png_rgba* actions = png->png_decode_rgba(handle);
|
|
|
536 |
if (!actions) panicf(PANIC_KILLTHREAD, "Could not decode actions image!");
|
|
|
537 |
png->png_destroy(handle);
|
|
|
538 |
cputc(3, '.');
|
|
|
539 |
void* framebuf = malloc(160 * 91 * 3);
|
|
|
540 |
if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate frame buffer!");
|
|
|
541 |
cputc(3, '.');
|
| 160 |
theseven |
542 |
|
| 551 |
theseven |
543 |
deleterc = remove(BOOTNOTE_FILENAME);
|
|
|
544 |
cputc(3, '.');
|
|
|
545 |
disk_unmount(0);
|
|
|
546 |
rc = fat32_init();
|
|
|
547 |
if (rc == 2) panic(PANIC_KILLTHREAD, "Data flash I/O error!");
|
|
|
548 |
cputc(3, '.');
|
| 253 |
theseven |
549 |
|
| 160 |
theseven |
550 |
if (norword[0x400] == 0x53436667) appleflash = false;
|
|
|
551 |
else if (norword[0x1000] == 0x53436667) appleflash = true;
|
|
|
552 |
else panic(PANIC_KILLTHREAD, "Boot flash contents are damaged! "
|
|
|
553 |
"(No SYSCFG found)\n\nPlease ask for help.\n");
|
|
|
554 |
|
| 551 |
theseven |
555 |
|
| 160 |
theseven |
556 |
if (appleflash)
|
|
|
557 |
{
|
| 551 |
theseven |
558 |
syscfgptr = &nor[0x4000];
|
| 160 |
theseven |
559 |
if (readapplenor("hslfksid", &diskuclptr, &diskuclsize)) diskuclsize = 0;
|
|
|
560 |
else
|
|
|
561 |
{
|
| 551 |
theseven |
562 |
cputc(3, '.');
|
| 160 |
theseven |
563 |
void* newptr = malloc(diskuclsize + (diskuclsize >> 3) + 256);
|
|
|
564 |
if (ucl_nrv2e_99_compress(diskuclptr, diskuclsize, newptr,
|
|
|
565 |
(uint32_t*)&diskuclsize, 0, 10, 0, 0))
|
|
|
566 |
{
|
|
|
567 |
free(newptr);
|
|
|
568 |
diskuclsize = 0;
|
|
|
569 |
}
|
| 551 |
theseven |
570 |
cputc(3, '.');
|
| 160 |
theseven |
571 |
free(diskuclptr);
|
|
|
572 |
realloc(newptr, diskuclsize);
|
|
|
573 |
diskuclptr = newptr;
|
|
|
574 |
}
|
| 551 |
theseven |
575 |
cputc(3, '.');
|
| 160 |
theseven |
576 |
if (readapplenor("hslfgaid", &diaguclptr, &diaguclsize)) diaguclsize = 0;
|
|
|
577 |
else
|
|
|
578 |
{
|
| 551 |
theseven |
579 |
cputc(3, '.');
|
| 160 |
theseven |
580 |
void* newptr = malloc(diaguclsize + (diaguclsize >> 3) + 256);
|
|
|
581 |
if (ucl_nrv2e_99_compress(diaguclptr, diaguclsize, newptr,
|
|
|
582 |
(uint32_t*)&diaguclsize, 0, 10, 0, 0))
|
|
|
583 |
{
|
|
|
584 |
free(newptr);
|
|
|
585 |
diaguclsize = 0;
|
|
|
586 |
}
|
| 551 |
theseven |
587 |
cputc(3, '.');
|
| 160 |
theseven |
588 |
free(diaguclptr);
|
|
|
589 |
realloc(newptr, diaguclsize);
|
|
|
590 |
diaguclptr = newptr;
|
|
|
591 |
}
|
| 551 |
theseven |
592 |
cputc(3, '.');
|
| 256 |
theseven |
593 |
if (readfw(deleterc ? "DNANkbso" : "DNANsoso", &ososptr, &osossize)) osossize = 0;
|
| 160 |
theseven |
594 |
if (osossize)
|
|
|
595 |
{
|
| 551 |
theseven |
596 |
cputc(3, '.');
|
| 160 |
theseven |
597 |
if (((uint8_t*)ososptr)[0x64d48] == 0x2b && ((uint8_t*)ososptr)[0x64d54] == 0x34)
|
|
|
598 |
{
|
|
|
599 |
((uint8_t*)ososptr)[0x64d48] = 0x43;
|
|
|
600 |
((uint8_t*)ososptr)[0x64d54] = 0x52;
|
|
|
601 |
}
|
|
|
602 |
if (((uint8_t*)ososptr)[0x3acd8] == 0x01)
|
|
|
603 |
((uint8_t*)ososptr)[0x3acd8] = 0x00;
|
|
|
604 |
}
|
|
|
605 |
}
|
|
|
606 |
else
|
|
|
607 |
{
|
| 551 |
theseven |
608 |
syscfgptr = &nor[0x1000];
|
| 160 |
theseven |
609 |
diskuclsize = bootflash_filesize("diskmode");
|
|
|
610 |
if (diskuclsize > 0)
|
|
|
611 |
{
|
|
|
612 |
diskuclptr = bootflash_getaddr("diskmode");
|
|
|
613 |
if (!(bootflash_attributes("diskmode") & 0x800))
|
|
|
614 |
{
|
|
|
615 |
void* newptr = malloc(diskuclsize + (diskuclsize >> 3) + 256);
|
|
|
616 |
if (ucl_nrv2e_99_compress(diskuclptr, diskuclsize, newptr,
|
|
|
617 |
(uint32_t*)&diskuclsize, 0, 10, 0, 0))
|
|
|
618 |
{
|
|
|
619 |
free(newptr);
|
|
|
620 |
diskuclsize = 0;
|
|
|
621 |
}
|
| 551 |
theseven |
622 |
cputc(3, '.');
|
| 160 |
theseven |
623 |
realloc(newptr, diskuclsize);
|
|
|
624 |
diskuclptr = newptr;
|
|
|
625 |
}
|
|
|
626 |
}
|
| 551 |
theseven |
627 |
cputc(3, '.');
|
| 160 |
theseven |
628 |
diaguclsize = bootflash_filesize("diagmode");
|
|
|
629 |
if (diaguclsize > 0)
|
|
|
630 |
{
|
|
|
631 |
diaguclptr = bootflash_getaddr("diagmode");
|
|
|
632 |
if (!(bootflash_attributes("diagmode") & 0x800))
|
|
|
633 |
{
|
|
|
634 |
void* newptr = malloc(diaguclsize + (diaguclsize >> 3) + 256);
|
|
|
635 |
if (ucl_nrv2e_99_compress(diaguclptr, diaguclsize, newptr,
|
|
|
636 |
(uint32_t*)&diaguclsize, 0, 10, 0, 0))
|
|
|
637 |
{
|
|
|
638 |
free(newptr);
|
|
|
639 |
diaguclsize = 0;
|
|
|
640 |
}
|
| 551 |
theseven |
641 |
cputc(3, '.');
|
| 160 |
theseven |
642 |
realloc(newptr, diaguclsize);
|
|
|
643 |
diaguclptr = newptr;
|
|
|
644 |
}
|
|
|
645 |
}
|
|
|
646 |
}
|
| 551 |
theseven |
647 |
cputc(3, '.');
|
| 160 |
theseven |
648 |
norbuf = malloc(0x100000);
|
|
|
649 |
memset(norbuf, 0xff, 0x100000);
|
|
|
650 |
memcpy(&norbuf[0x1000], syscfgptr, 0x1000);
|
|
|
651 |
free(syscfgptr);
|
| 551 |
theseven |
652 |
cputc(3, '.');
|
|
|
653 |
|
|
|
654 |
uint32_t* script = flashscript;
|
| 160 |
theseven |
655 |
uint32_t sp = 0;
|
|
|
656 |
uint32_t beginptr = 0x2000;
|
|
|
657 |
uint32_t endptr = 0x100000;
|
|
|
658 |
uint32_t dirptr = 0;
|
|
|
659 |
while (script[sp])
|
|
|
660 |
{
|
|
|
661 |
uint32_t file = script[sp] & 0xff;
|
|
|
662 |
uint32_t flags = (script[sp] >> 8) & 0xff;
|
|
|
663 |
uint32_t align = (script[sp] >> 16) & 0xff;
|
|
|
664 |
void* data;
|
|
|
665 |
uint32_t size;
|
|
|
666 |
sp++;
|
|
|
667 |
switch (file)
|
|
|
668 |
{
|
|
|
669 |
case 1:
|
|
|
670 |
data = diskuclptr;
|
|
|
671 |
size = diskuclsize;
|
|
|
672 |
flags |= 2;
|
|
|
673 |
break;
|
|
|
674 |
case 2:
|
|
|
675 |
data = diaguclptr;
|
|
|
676 |
size = diaguclsize;
|
|
|
677 |
flags |= 2;
|
|
|
678 |
break;
|
|
|
679 |
default:
|
| 551 |
theseven |
680 |
data = (void*)(script[sp++]);
|
| 160 |
theseven |
681 |
size = script[sp++];
|
|
|
682 |
}
|
|
|
683 |
if (size)
|
|
|
684 |
{
|
|
|
685 |
if (align && !(flags & 1))
|
|
|
686 |
{
|
|
|
687 |
if ((align << 12) < beginptr)
|
|
|
688 |
panicf(PANIC_KILLTHREAD, "Error: Align failed! (%02X)", align);
|
|
|
689 |
beginptr = align << 12;
|
|
|
690 |
}
|
|
|
691 |
if (endptr - beginptr < size)
|
|
|
692 |
panicf(PANIC_KILLTHREAD, "Error: Flash is full!");
|
|
|
693 |
uint32_t storesize = size;
|
|
|
694 |
if (flags & 2) storesize |= 0x80000000;
|
|
|
695 |
if (flags & 1)
|
|
|
696 |
{
|
|
|
697 |
endptr -= ((size + 0xfff) & ~0xfff);
|
|
|
698 |
memcpy(&norbuf[endptr], data, size);
|
|
|
699 |
file = endptr;
|
|
|
700 |
}
|
|
|
701 |
else
|
|
|
702 |
{
|
|
|
703 |
memcpy(&norbuf[beginptr], data, size);
|
|
|
704 |
file = beginptr;
|
|
|
705 |
beginptr += ((size + 0xfff) & ~0xfff);
|
|
|
706 |
}
|
|
|
707 |
if (!(flags & 4))
|
|
|
708 |
{
|
|
|
709 |
if (dirptr >= 0x1000)
|
|
|
710 |
panicf(PANIC_KILLTHREAD, "Error: Directory is full!");
|
|
|
711 |
memcpy(&norbuf[dirptr], &script[sp], 8);
|
|
|
712 |
norbufword[(dirptr >> 2) + 2] = file;
|
|
|
713 |
norbufword[(dirptr >> 2) + 3] = storesize;
|
|
|
714 |
dirptr += 0x10;
|
|
|
715 |
sp += 2;
|
|
|
716 |
}
|
|
|
717 |
}
|
|
|
718 |
else if (!(flags & 4)) sp += 2;
|
| 551 |
theseven |
719 |
cputc(3, '.');
|
| 160 |
theseven |
720 |
}
|
|
|
721 |
if (diskuclptr && (uint32_t)diskuclptr < 0x24000000) free(diskuclptr);
|
|
|
722 |
if (diaguclptr && (uint32_t)diaguclptr < 0x24000000) free(diaguclptr);
|
| 551 |
theseven |
723 |
|
|
|
724 |
if (appleflash || rc || fat32_startsector)
|
|
|
725 |
{
|
|
|
726 |
button = 0;
|
|
|
727 |
wakeup_init(&eventwakeup);
|
|
|
728 |
struct button_hook_entry* hook = button_register_handler(handler, NULL);
|
|
|
729 |
if (!hook) panicf(PANIC_KILLTHREAD, "Could not register button hook!");
|
| 160 |
theseven |
730 |
|
| 551 |
theseven |
731 |
displaylcd(0, 0, 176, 132, darkened, 0, 0, 176);
|
|
|
732 |
backlight_set_fade(32);
|
|
|
733 |
backlight_set_brightness(177);
|
|
|
734 |
backlight_on(true);
|
|
|
735 |
scrollpos = 0;
|
|
|
736 |
|
|
|
737 |
while (true)
|
|
|
738 |
{
|
|
|
739 |
ui->blenda(160, 91, 255, framebuf, 0, 0, 160,
|
|
|
740 |
darkened, 8, 27, 176, disclaimer, 0, scrollpos, 160);
|
|
|
741 |
displaylcd(8, 27, 160, 91, framebuf, 0, 0, 160);
|
|
|
742 |
|
|
|
743 |
wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
|
|
|
744 |
if (button == 0x18) break;
|
|
|
745 |
else if (button == 4)
|
|
|
746 |
{
|
|
|
747 |
if (deleterc)
|
|
|
748 |
{
|
|
|
749 |
sleep(500000);
|
|
|
750 |
ui->blenda(160, 60, 255, framebuf, 0, 0, 160,
|
|
|
751 |
darkened, 8, 27, 176, disclaimer, 0, 550, 160);
|
| 672 |
theseven |
752 |
displaylcd(8, 27, 160, 60, framebuf, 0, 0, 160);
|
|
|
753 |
displaylcd(8, 87, 160, 31, darkened, 8, 87, 176);
|
| 551 |
theseven |
754 |
button = 0;
|
|
|
755 |
while (!button) wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
|
|
|
756 |
memcpy((void*)0x2202bf00, "diskmodehotstuff\1\0\0", 20);
|
|
|
757 |
}
|
|
|
758 |
shutdown(false);
|
|
|
759 |
reset();
|
|
|
760 |
}
|
|
|
761 |
}
|
|
|
762 |
|
|
|
763 |
button_unregister_handler(hook);
|
|
|
764 |
}
|
|
|
765 |
|
|
|
766 |
if (rc)
|
|
|
767 |
{
|
|
|
768 |
ui->blenda(160, 80, 255, framebuf, 0, 0, 160,
|
|
|
769 |
darkened, 8, 27, 176, disclaimer, 0, 470, 160);
|
| 672 |
theseven |
770 |
displaylcd(8, 27, 160, 80, framebuf, 0, 0, 160);
|
|
|
771 |
displaylcd(8, 107, 160, 11, darkened, 8, 107, 176);
|
| 551 |
theseven |
772 |
|
|
|
773 |
button = 0;
|
|
|
774 |
struct button_hook_entry* hook = button_register_handler(handler, NULL);
|
|
|
775 |
if (!hook) panicf(PANIC_KILLTHREAD, "Could not register button hook!");
|
|
|
776 |
|
|
|
777 |
while (true)
|
|
|
778 |
{
|
|
|
779 |
wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
|
|
|
780 |
if (button == 2)
|
|
|
781 |
{
|
|
|
782 |
repartition = true;
|
|
|
783 |
break;
|
|
|
784 |
}
|
|
|
785 |
else if (button == 4)
|
|
|
786 |
{
|
|
|
787 |
if (deleterc)
|
|
|
788 |
{
|
|
|
789 |
sleep(500000);
|
|
|
790 |
ui->blenda(160, 60, 255, framebuf, 0, 0, 160,
|
|
|
791 |
darkened, 8, 27, 176, disclaimer, 0, 550, 160);
|
| 672 |
theseven |
792 |
displaylcd(8, 27, 160, 60, framebuf, 0, 0, 160);
|
|
|
793 |
displaylcd(8, 87, 160, 31, darkened, 8, 87, 176);
|
| 551 |
theseven |
794 |
button = 0;
|
|
|
795 |
while (!button) wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
|
|
|
796 |
memcpy((void*)0x2202bf00, "diskmodehotstuff\1\0\0", 20);
|
|
|
797 |
}
|
|
|
798 |
shutdown(false);
|
|
|
799 |
reset();
|
|
|
800 |
}
|
|
|
801 |
}
|
|
|
802 |
|
|
|
803 |
button_unregister_handler(hook);
|
|
|
804 |
}
|
|
|
805 |
else if (fat32_startsector)
|
|
|
806 |
{
|
| 672 |
theseven |
807 |
ui->blenda(130, 70, 255, framebuf, 0, 0, 130,
|
|
|
808 |
darkened, 23, 27, 176, disclaimer, 0, 400, 160);
|
|
|
809 |
displaylcd(8, 27, 160, 91, darkened, 8, 27, 176);
|
|
|
810 |
displaylcd(23, 27, 130, 70, framebuf, 0, 0, 130);
|
| 551 |
theseven |
811 |
|
|
|
812 |
button = 0;
|
|
|
813 |
struct button_hook_entry* hook = button_register_handler(handler, NULL);
|
|
|
814 |
if (!hook) panicf(PANIC_KILLTHREAD, "Could not register button hook!");
|
|
|
815 |
|
|
|
816 |
while (true)
|
|
|
817 |
{
|
|
|
818 |
wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
|
|
|
819 |
if (button == 2)
|
|
|
820 |
{
|
|
|
821 |
repartition = true;
|
|
|
822 |
break;
|
|
|
823 |
}
|
|
|
824 |
else if (button == 4) break;
|
|
|
825 |
}
|
|
|
826 |
|
|
|
827 |
button_unregister_handler(hook);
|
|
|
828 |
}
|
|
|
829 |
|
|
|
830 |
free(darkened);
|
|
|
831 |
free(disclaimer);
|
|
|
832 |
|
| 160 |
theseven |
833 |
if (repartition)
|
|
|
834 |
{
|
| 551 |
theseven |
835 |
ui->blenda(110, 20, 255, framebuf, 0, 0, 110, bg, 33, 55, 176, actions, 0, 0, 110);
|
|
|
836 |
displaylcd(0, 0, 176, 132, bg, 0, 0, 176);
|
|
|
837 |
displaylcd(33, 55, 110, 20, framebuf, 0, 0, 110);
|
|
|
838 |
progressbar_init(&progressbar, 10, 165, 74, 83, 0x77ff, 0xe8, 0x125f, 0, 100);
|
| 160 |
theseven |
839 |
if (fat32_resize_fulldisk(&progressbar))
|
|
|
840 |
panic(PANIC_KILLTHREAD, "Data flash I/O error!");
|
|
|
841 |
}
|
|
|
842 |
|
| 551 |
theseven |
843 |
ui->blenda(110, 20, 255, framebuf, 0, 0, 110, bg, 33, 55, 176, actions, 0, 20, 110);
|
|
|
844 |
displaylcd(0, 0, 176, 132, bg, 0, 0, 176);
|
|
|
845 |
displaylcd(33, 55, 110, 20, framebuf, 0, 0, 110);
|
|
|
846 |
backlight_set_fade(32);
|
|
|
847 |
backlight_set_brightness(177);
|
|
|
848 |
backlight_on(true);
|
|
|
849 |
|
| 160 |
theseven |
850 |
disk_mount(0);
|
| 692 |
theseven |
851 |
remove("/.boot/init.emcoreapp");
|
| 551 |
theseven |
852 |
int updating = !(appleflash || rc);
|
|
|
853 |
int cost;
|
| 160 |
theseven |
854 |
if (updating)
|
|
|
855 |
{
|
| 551 |
theseven |
856 |
cost = commoncost;
|
|
|
857 |
script = commonscript;
|
| 160 |
theseven |
858 |
}
|
|
|
859 |
else
|
|
|
860 |
{
|
| 551 |
theseven |
861 |
cost = firstinstcost + commoncost;
|
|
|
862 |
script = firstinstscript;
|
| 160 |
theseven |
863 |
}
|
| 551 |
theseven |
864 |
progressbar_init(&progressbar, 10, 165, 74, 83, 0x77ff, 0xe8, 0x125f, 0, cost);
|
|
|
865 |
sp = 0;
|
|
|
866 |
cost = 0;
|
| 160 |
theseven |
867 |
while (script[sp])
|
|
|
868 |
{
|
|
|
869 |
int fd;
|
|
|
870 |
void* data;
|
|
|
871 |
switch (script[sp])
|
|
|
872 |
{
|
|
|
873 |
case 1:
|
| 551 |
theseven |
874 |
mkdir((char*)(script[sp + 1]));
|
| 160 |
theseven |
875 |
sp += 2;
|
|
|
876 |
break;
|
|
|
877 |
case 2:
|
|
|
878 |
if (script[sp + 2] == 0xffffffff)
|
|
|
879 |
{
|
|
|
880 |
data = ososptr;
|
|
|
881 |
script[sp + 3] = osossize;
|
|
|
882 |
}
|
| 551 |
theseven |
883 |
else if (script[sp + 2] == 0xfffffffe && appleflash)
|
| 160 |
theseven |
884 |
{
|
|
|
885 |
data = nor;
|
|
|
886 |
script[sp + 3] = 0x100000;
|
|
|
887 |
}
|
| 551 |
theseven |
888 |
else if (script[sp + 2] == 0xfffffffe) script[sp + 3] = 0;
|
| 160 |
theseven |
889 |
if (!script[sp + 3])
|
|
|
890 |
{
|
|
|
891 |
sp += 4;
|
|
|
892 |
break;
|
|
|
893 |
}
|
|
|
894 |
case 3:
|
| 551 |
theseven |
895 |
fd = file_open((char*)(script[sp + 1]), O_RDONLY);
|
| 160 |
theseven |
896 |
if (fd >= 0)
|
|
|
897 |
{
|
|
|
898 |
close(fd);
|
|
|
899 |
sp += 4;
|
|
|
900 |
break;
|
|
|
901 |
}
|
|
|
902 |
case 4:
|
| 551 |
theseven |
903 |
if (script[sp + 2] < 0xfffffffe) data = (void*)(script[sp + 2]);
|
|
|
904 |
fd = file_creat((char*)(script[sp + 1]));
|
| 160 |
theseven |
905 |
if (fd >= 0)
|
|
|
906 |
{
|
|
|
907 |
write(fd, data, script[sp + 3]);
|
|
|
908 |
close(fd);
|
|
|
909 |
}
|
|
|
910 |
sp += 4;
|
|
|
911 |
break;
|
|
|
912 |
default:
|
|
|
913 |
panic(PANIC_KILLTHREAD, "Bad installation script!");
|
|
|
914 |
}
|
| 551 |
theseven |
915 |
cost += script[sp++];
|
|
|
916 |
progressbar_setpos(&progressbar, cost, false);
|
| 160 |
theseven |
917 |
}
|
|
|
918 |
|
| 551 |
theseven |
919 |
ui->blenda(110, 20, 255, framebuf, 0, 0, 110, bg, 33, 55, 176, actions, 0, 40, 110);
|
|
|
920 |
displaylcd(33, 55, 110, 20, framebuf, 0, 0, 110);
|
|
|
921 |
progressbar_init(&progressbar, 10, 165, 74, 83, 0x77ff, 0xe8, 0x125f, 0, 256);
|
| 160 |
theseven |
922 |
for (i = 0; i < 256; i++)
|
|
|
923 |
{
|
|
|
924 |
bootflash_writeraw(&norbuf[i << 12], i << 12, 1 << 12);
|
|
|
925 |
progressbar_setpos(&progressbar, i, false);
|
|
|
926 |
}
|
|
|
927 |
|
| 551 |
theseven |
928 |
free(norbuf);
|
|
|
929 |
free(framebuf);
|
|
|
930 |
free(actions);
|
|
|
931 |
free(bg);
|
|
|
932 |
|
|
|
933 |
release_library(libui);
|
|
|
934 |
release_library(libpng);
|
|
|
935 |
library_unload(libui);
|
|
|
936 |
library_unload(libpng);
|
|
|
937 |
|
| 160 |
theseven |
938 |
shutdown(false);
|
|
|
939 |
reset();
|
|
|
940 |
}
|