Subversion Repositories freemyipod

Rev

Rev 385 | Rev 546 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 385 Rev 530
Line 1... Line 1...
1
//
1
//
2
//
2
//
3
//    Copyright 2010 TheSeven
3
//    Copyright 2010 TheSeven
4
//
4
//
5
//
5
//
6
//    This file is part of emBIOS.
6
//    This file is part of emCORE.
7
//
7
//
8
//    emBIOS is free software: you can redistribute it and/or
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
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
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
11
//    License, or (at your option) any later version.
12
//
12
//
13
//    emBIOS is distributed in the hope that it will be useful,
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
16
//    See the GNU General Public License for more details.
17
//
17
//
18
//    You should have received a copy of the GNU General Public License along
18
//    You should have received a copy of the GNU General Public License along
19
//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>.
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
20
//
21
//
21
//
22
 
22
 
23
 
23
 
24
#include "embiosapp.h"
24
#include "emcoreapp.h"
-
 
25
#include "libpng.h"
-
 
26
#include "libui.h"
25
 
27
 
26
 
28
 
27
void main();
29
void main();
28
EMBIOS_APP_HEADER("Installer thread", 0x10000, main, 127)
30
EMCORE_APP_HEADER("emCORE installer", main, 127)
29
 
31
 
30
 
32
 
-
 
33
extern char background_png[];
-
 
34
extern uint32_t background_png_size;
31
uint16_t lcdbuffer[320 * 240];
35
extern char darkener_png[];
-
 
36
extern uint32_t darkener_png_size;
-
 
37
extern char disclaimer_png[];
-
 
38
extern uint32_t disclaimer_png_size;
32
#define BMPIDX_SIDEPANE 0
39
extern char actions_png[];
33
#define BMPIDX_WARNING 1
40
extern uint32_t actions_png_size;
-
 
41
extern char f_png_emcorelib[];
34
#define BMPIDX_INSTALLING 2
42
extern char f_ui_emcorelib[];
35
#define BMPIDX_FORMATTING 3
43
extern uint32_t flashscript[];
36
#define BMPIDX_COPYING 4
44
extern uint32_t firstinstcost;
-
 
45
extern uint32_t firstinstscript[];
37
#define BMPIDX_FLASHING 5
46
extern uint32_t commoncost;
-
 
47
extern uint32_t commonscript[];
-
 
48
 
38
 
49
 
39
struct wakeup eventwakeup;
50
struct wakeup eventwakeup;
40
volatile int button;
51
volatile int button;
41
 
-
 
42
char mallocbuf[0xea0000] __attribute__((aligned(16)));
-
 
43
tlsf_pool mallocpool;
-
 
44
 
-
 
45
extern uint32_t _scriptstart;
52
volatile int scrollpos;
46
 
53
 
47
 
54
 
48
#define SHA1CONFIG    (*((volatile uint32_t*)(0x38000000)))
55
#define SHA1CONFIG    (*((volatile uint32_t*)(0x38000000)))
49
#define SHA1RESET     (*((volatile uint32_t*)(0x38000004)))
56
#define SHA1RESET     (*((volatile uint32_t*)(0x38000004)))
50
#define SHA1RESULT      ((volatile uint32_t*)(0x38000020))
57
#define SHA1RESULT      ((volatile uint32_t*)(0x38000020))
Line 94... Line 101...
94
    for (i = 0; i < 5; i++) hashbuf[i] = SHA1RESULT[i];
101
    for (i = 0; i < 5; i++) hashbuf[i] = SHA1RESULT[i];
95
    clockgate_enable(0, false);
102
    clockgate_enable(0, false);
96
}
103
}
97
 
104
 
98
 
105
 
99
void handler(enum button_event eventtype, int which, int value)
106
void handler(void* user, enum button_event eventtype, int which, int value)
100
{
107
{
101
    if (eventtype == BUTTON_PRESS) button |= 1 << which;
108
    if (eventtype == BUTTON_PRESS) button |= 1 << which;
-
 
109
    if (eventtype == WHEEL_MOVED_ACCEL)
-
 
110
        scrollpos = MAX(0, MIN(295, scrollpos + value / 8));
102
    wakeup_signal(&eventwakeup);
111
    wakeup_signal(&eventwakeup);
103
}
112
}
104
 
113
 
105
void* malloc(size_t size)
-
 
106
{
-
 
107
    void* result = tlsf_malloc(mallocpool, size);
-
 
108
    if (!result && size) panic(PANIC_KILLTHREAD, "Out of memory!");
-
 
109
    return result;
-
 
110
}
-
 
111
 
-
 
112
void* memalign(size_t align, size_t size)
-
 
113
{
-
 
114
    void* result = tlsf_memalign(mallocpool, align, size);
-
 
115
    if (!result && size) panic(PANIC_KILLTHREAD, "Out of memory!");
-
 
116
    return result;
-
 
117
}
-
 
118
 
-
 
119
void* realloc(void* ptr, size_t size)
-
 
120
{
-
 
121
    void* result = tlsf_realloc(mallocpool, ptr, size);
-
 
122
    if (!result && size) panic(PANIC_KILLTHREAD, "Out of memory!");
-
 
123
    return result;
-
 
124
}
-
 
125
 
-
 
126
void free(void* ptr)
-
 
127
{
-
 
128
    tlsf_free(mallocpool, ptr);
-
 
129
}
-
 
130
 
-
 
131
uint32_t freeret(uint32_t rc, void* ptr)
-
 
132
{
-
 
133
    tlsf_free(mallocpool, ptr);
-
 
134
    return rc;
-
 
135
}
-
 
136
 
-
 
137
void mkfat32(struct progressbar_state* progressbar)
114
void mkfat32(struct progressbar_state* progressbar)
138
{
115
{
139
    uint32_t i, j, rc;
116
    uint32_t i, j, rc;
140
    uint32_t rootdirclus = 2;
117
    uint32_t rootdirclus = 2;
141
    uint32_t secperclus = 1;
118
    uint32_t secperclus = 1;
Line 169... Line 146...
169
    ((uint8_t*)buf)[0x42] = 0x29;
146
    ((uint8_t*)buf)[0x42] = 0x29;
170
    memcpy(&((uint8_t*)buf)[0x43], "\0\0\0\0iPodClassic", 0xf);
147
    memcpy(&((uint8_t*)buf)[0x43], "\0\0\0\0iPodClassic", 0xf);
171
    memcpy(&((uint8_t*)buf)[0x52], "FAT32   ", 8);
148
    memcpy(&((uint8_t*)buf)[0x52], "FAT32   ", 8);
172
    ((uint16_t*)buf)[0xff] = 0xaa55;
149
    ((uint16_t*)buf)[0xff] = 0xaa55;
173
    if (rc = storage_write_sectors_md(0, 0, 1, buf))
150
    if (rc = storage_write_sectors_md(0, 0, 1, buf))
174
        panicf(PANIC_KILLTHREAD, "Error writing MBR: %08X", rc);
151
        panicf(PANIC_KILLTHREAD, "\nError writing MBR: %08X", rc);
175
    memset(buf, 0, 0x800);
152
    memset(buf, 0, 0x800);
176
    buf[0] = 0x41615252;
153
    buf[0] = 0x41615252;
177
    buf[0x79] = 0x61417272;
154
    buf[0x79] = 0x61417272;
178
    buf[0x7a] = clustercount - 1;
155
    buf[0x7a] = clustercount - 1;
179
    buf[0x7b] = 2;
156
    buf[0x7b] = 2;
180
    buf[0x7f] = 0xaa550000;
157
    buf[0x7f] = 0xaa550000;
181
    if (rc = storage_write_sectors_md(0, 1, 1, buf))
158
    if (rc = storage_write_sectors_md(0, 1, 1, buf))
182
        panicf(PANIC_KILLTHREAD, "Error writing FSINFO: %08X", rc);
159
        panicf(PANIC_KILLTHREAD, "\nError writing FSINFO: %08X", rc);
183
    progressbar_init(progressbar, 5, 189, 65, 80, 0, 0xdefb, 0x1d, 0, fatsectors);
160
    progressbar_init(progressbar, 15, 304, 135, 159, 0x77ff, 0xe8, 0x125f, 0, fatsectors);
184
    uint32_t cursect = 0;
161
    uint32_t cursect = 0;
185
    for (i = 0; i < fatsectors; i += 32)
162
    for (i = 0; i < fatsectors; i += 32)
186
    {
163
    {
187
        memset(buf, 0, 0x20000);
164
        memset(buf, 0, 0x20000);
188
        if (!i) memcpy(buf, "\xf8\xff\xff\x0f\xff\xff\xff\xff\xff\xff\xff\x0f", 12);
165
        if (!i) memcpy(buf, "\xf8\xff\xff\x0f\xff\xff\xff\xff\xff\xff\xff\x0f", 12);
189
        if (rc = storage_write_sectors_md(0, reserved + i, MIN(fatsectors - i, 32), buf))
166
        if (rc = storage_write_sectors_md(0, reserved + i, MIN(fatsectors - i, 32), buf))
190
            panicf(PANIC_KILLTHREAD, "Error writing FAT sectors %d-%d: %08X", i, MIN(fatsectors - 1, i + 31), rc);
167
            panicf(PANIC_KILLTHREAD, "\nError writing FAT sectors %d-%d: %08X",
-
 
168
                   i, MIN(fatsectors - 1, i + 31), rc);
191
        progressbar_setpos(progressbar, i, false);
169
        progressbar_setpos(progressbar, i, false);
192
    }
170
    }
193
    memset(buf, 0, secperclus * 0x1000);
171
    memset(buf, 0, secperclus * 0x1000);
194
    memcpy(buf, "iPodClassic\x08", 12);
172
    memcpy(buf, "iPodClassic\x08", 12);
195
    if (rc = storage_write_sectors_md(0, database, secperclus, buf))
173
    if (rc = storage_write_sectors_md(0, database, secperclus, buf))
196
        panicf(PANIC_KILLTHREAD, "Error writing root directory sectors: %08X", i, rc);
174
        panicf(PANIC_KILLTHREAD, "\nError writing root directory sectors: %08X", i, rc);
197
    free(buf);
175
    free(buf);
198
    disk_mount(0);
176
    disk_mount(0);
199
}
177
}
200
 
178
 
201
void main(void)
179
void main(void)
202
{
180
{
203
    uint32_t i, j, k, rc;
181
    uint32_t i, j, k, rc;
204
    void* bitmapdata[6];
-
 
205
    uint32_t bitmapsize[6];
-
 
206
    uint32_t* script;
-
 
207
#define scriptb ((uint8_t*)script)
-
 
208
    uint32_t dummy;
182
    uint32_t dummy;
209
    struct progressbar_state progressbar;
183
    struct progressbar_state progressbar;
210
    bool appleflash;
184
    bool appleflash;
211
    void* syscfgptr;
185
    void* syscfgptr;
212
    uint8_t* norbuf;
186
    uint8_t* norbuf;
213
#define norbufword ((uint32_t*)norbuf)
187
#define norbufword ((uint32_t*)norbuf)
214
    uint8_t* oldnor;
188
    uint8_t* oldnor;
215
#define oldnorword ((uint32_t*)oldnor)
189
#define oldnorword ((uint32_t*)oldnor)
216
 
190
 
217
    button = 0;
191
    cputc(3, '.');
218
    wakeup_init(&eventwakeup);
-
 
219
    button_register_handler(handler);
192
    struct emcorelib_header* libpng = get_library(0x64474e50, LIBPNG_API_VERSION, LIBSOURCE_RAM_NEEDCOPY, f_png_emcorelib);
220
    mallocpool = tlsf_create(mallocbuf, sizeof(mallocbuf));
193
    if (!libpng) panicf(PANIC_KILLTHREAD, "\nCould not load PNG decoder library!");
221
 
-
 
222
    script = &_scriptstart;
194
    struct libpng_api* png = (struct libpng_api*)libpng->api;
223
    for (i = 0; i < 6; i++)
195
    cputc(3, '.');
224
    {
-
 
225
        bitmapsize[i] = *script;
196
    struct emcorelib_header* libui = get_library(0x49554365, LIBUI_API_VERSION, LIBSOURCE_RAM_NEEDCOPY, f_ui_emcorelib);
226
        bitmapdata[i] = &script[1];
197
    if (!libui) panicf(PANIC_KILLTHREAD, "\nCould not load user interface library!");
227
        script = &script[1 + (bitmapsize[i] >> 2)];
198
    struct libui_api* ui = (struct libui_api*)libui->api;
228
    }
199
    cputc(3, '.');
229
 
200
 
230
    void* bmpbuffer = malloc(0x25900);
201
    struct png_info* handle = png->png_open(background_png, background_png_size);
-
 
202
    if (!handle) panicf(PANIC_KILLTHREAD, "\nCould not parse background image!");
231
    memset(lcdbuffer, 0xff, 0x25800);
203
    cputc(3, '.');
232
    ucl_decompress(bitmapdata[BMPIDX_SIDEPANE], bitmapsize[BMPIDX_SIDEPANE], bmpbuffer, &dummy);
204
    struct png_rgb* bg = png->png_decode_rgb(handle);
233
    renderbmp(&lcdbuffer[195], bmpbuffer, 320);
205
    if (!bg) panicf(PANIC_KILLTHREAD, "\nCould not decode background image!");
234
    bool updating = mkdir("/iLoader") == -4;
206
    png->png_destroy(handle);
235
    if (!updating)
207
    cputc(3, '.');
236
    {
-
 
237
        ucl_decompress(bitmapdata[BMPIDX_WARNING], bitmapsize[BMPIDX_WARNING], bmpbuffer, &dummy);
-
 
238
        renderbmp(lcdbuffer, bmpbuffer, 320);
208
    handle = png->png_open(actions_png, actions_png_size);
239
        displaylcd(0, 319, 0, 239, lcdbuffer, 0);
209
    if (!handle) panicf(PANIC_KILLTHREAD, "\nCould not parse actions image!");
240
    }
-
 
241
    else
210
    cputc(3, '.');
242
    {
-
 
243
        ucl_decompress(bitmapdata[BMPIDX_INSTALLING], bitmapsize[BMPIDX_INSTALLING],
211
    struct png_rgba* actions = png->png_decode_rgba(handle);
244
                       bmpbuffer, &dummy);
212
    if (!actions) panicf(PANIC_KILLTHREAD, "\nCould not decode actions image!");
245
        renderbmp(lcdbuffer, bmpbuffer, 320);
213
    png->png_destroy(handle);
246
    }
214
    cputc(3, '.');
247
    backlight_set_fade(32);
215
    void* framebuf = malloc(290 * 165 * 3);
248
    backlight_set_brightness(177);
216
    if (!framebuf) panicf(PANIC_KILLTHREAD, "\nCould not allocate frame buffer!");
249
    backlight_on(true);
217
    cputc(3, '.');
250
 
218
 
-
 
219
    disk_unmount(0);
-
 
220
    bool updating = disk_mount(0);
-
 
221
    cputc(3, '.');
251
 
222
 
252
    norbuf = memalign(0x100000, 0x10);
223
    norbuf = memalign(0x100000, 0x10);
253
    oldnor = memalign(0x100000, 0x10);
224
    oldnor = memalign(0x100000, 0x10);
254
    memset(norbuf, 0xff, 0x100000);
225
    memset(norbuf, 0xff, 0x100000);
-
 
226
    cputc(3, '.');
255
    bootflash_readraw(oldnor, 0, 0x100000);
227
    bootflash_readraw(oldnor, 0, 0x100000);
-
 
228
    cputc(3, '.');
256
    if (oldnorword[0x400] == 0x53436667) appleflash = false;
229
    if (oldnorword[0x400] == 0x53436667) appleflash = false;
257
    else
230
    else
258
    {
231
    {
-
 
232
        updating = false;
259
        if (oldnorword[0] == 0x53436667) appleflash = true;
233
        if (oldnorword[0] == 0x53436667) appleflash = true;
260
        else panic(PANIC_KILLTHREAD, "Boot flash contents are damaged! "
234
        else panic(PANIC_KILLTHREAD, "\nBoot flash contents are damaged! "
261
                                     "(No SYSCFG found)\n\nPlease ask for help.\n");
235
                                     "(No SYSCFG found)\n\nPlease ask for help.\n");
262
    }
236
    }
263
    memcpy(&norbuf[0x1000], &oldnor[appleflash ? 0 : 0x1000], 0x1000);
237
    memcpy(&norbuf[0x1000], &oldnor[appleflash ? 0 : 0x1000], 0x1000);
-
 
238
    cputc(3, '.');
-
 
239
 
-
 
240
    uint32_t* script = flashscript;
264
    uint32_t sp = 0;
241
    uint32_t sp = 0;
265
    uint32_t beginptr = 0x2000;
242
    uint32_t beginptr = 0x2000;
266
    uint32_t endptr = 0x100000;
243
    uint32_t endptr = 0x100000;
267
    uint32_t dirptr = 0;
244
    uint32_t dirptr = 0;
268
    while (script[sp])
245
    while (script[sp])
Line 274... Line 251...
274
        uint32_t size;
251
        uint32_t size;
275
        sp++;
252
        sp++;
276
        switch (file)
253
        switch (file)
277
        {
254
        {
278
            default:
255
            default:
279
                data = &scriptb[script[sp++]];
256
                data = (void*)(script[sp++]);
280
                size = script[sp++];
257
                size = script[sp++];
281
        }
258
        }
282
        if (size)
259
        if (size)
283
        {
260
        {
284
            if (align && !(flags & 1))
261
            if (align && !(flags & 1))
285
            {
262
            {
286
                if ((align << 12) < beginptr)
263
                if ((align << 12) < beginptr)
287
                    panicf(PANIC_KILLTHREAD, "Error: Align failed! (%02X)", align);
264
                    panicf(PANIC_KILLTHREAD, "\nError: Align failed! (%02X)", align);
288
                beginptr = align << 12;
265
                beginptr = align << 12;
289
            }
266
            }
290
            if (endptr - beginptr < size)
267
            if (endptr - beginptr < size)
291
                panicf(PANIC_KILLTHREAD, "Error: Flash is full!");
268
                panicf(PANIC_KILLTHREAD, "\nError: Flash is full!");
292
            uint32_t storesize = size;
269
            uint32_t storesize = size;
293
            if (flags & 2) storesize |= 0x80000000;
270
            if (flags & 2) storesize |= 0x80000000;
294
            int offs = 0;
271
            int offs = 0;
295
            if (flags & 8)
272
            if (flags & 8)
296
            {
273
            {
Line 310... Line 287...
310
                beginptr += ((size + 0xfff) & ~0xfff);
287
                beginptr += ((size + 0xfff) & ~0xfff);
311
            }
288
            }
312
            if (!(flags & 4))
289
            if (!(flags & 4))
313
            {
290
            {
314
                if (dirptr >= 0x1000)
291
                if (dirptr >= 0x1000)
315
                    panicf(PANIC_KILLTHREAD, "Error: Directory is full!");
292
                    panicf(PANIC_KILLTHREAD, "\nError: Directory is full!");
316
                memcpy(&norbuf[dirptr], &script[sp], 8);
293
                memcpy(&norbuf[dirptr], &script[sp], 8);
317
                norbufword[(dirptr >> 2) + 2] = file;
294
                norbufword[(dirptr >> 2) + 2] = file;
318
                norbufword[(dirptr >> 2) + 3] = storesize;
295
                norbufword[(dirptr >> 2) + 3] = storesize;
319
                dirptr += 0x10;
296
                dirptr += 0x10;
320
                sp += 2;
297
                sp += 2;
Line 333... Line 310...
333
                hwkeyaes(HWKEYAES_ENCRYPT, 2, &norbuf[file + 0x40], 0x10);
310
                hwkeyaes(HWKEYAES_ENCRYPT, 2, &norbuf[file + 0x40], 0x10);
334
                hwkeyaes(HWKEYAES_ENCRYPT, 2, &norbuf[file + 0x800], size);
311
                hwkeyaes(HWKEYAES_ENCRYPT, 2, &norbuf[file + 0x800], size);
335
            }
312
            }
336
        }
313
        }
337
        else if (!(flags & 4)) sp += 2;
314
        else if (!(flags & 4)) sp += 2;
-
 
315
        cputc(3, '.');
338
    }
316
    }
339
 
317
 
340
    if (!updating)
318
    if (!updating)
341
    {
319
    {
-
 
320
        void* darkened = malloc(320 * 240 * 3);
-
 
321
        if (!darkened) panicf(PANIC_KILLTHREAD, "\nCould not allocate darkened image!");
-
 
322
        cputc(3, '.');
-
 
323
        handle = png->png_open(darkener_png, darkener_png_size);
-
 
324
        if (!handle) panicf(PANIC_KILLTHREAD, "\nCould not parse darkener image!");
-
 
325
        cputc(3, '.');
-
 
326
        struct png_rgba* darkener = png->png_decode_rgba(handle);
-
 
327
        if (!darkener) panicf(PANIC_KILLTHREAD, "\nCould not decode darkener image!");
-
 
328
        png->png_destroy(handle);
-
 
329
        cputc(3, '.');
-
 
330
        ui->blenda(320, 240, 255, darkened, 0, 0, 320, bg, 0, 0, 320, darkener, 0, 0, 320);
-
 
331
        free(darkener);
-
 
332
        cputc(3, '.');
-
 
333
        handle = png->png_open(disclaimer_png, disclaimer_png_size);
-
 
334
        if (!handle) panicf(PANIC_KILLTHREAD, "\nCould not parse disclaimer image!");
-
 
335
        cputc(3, '.');
-
 
336
        struct png_rgba* disclaimer = png->png_decode_rgba(handle);
-
 
337
        if (!disclaimer) panicf(PANIC_KILLTHREAD, "\nCould not decode disclaimer image!");
-
 
338
        png->png_destroy(handle);
-
 
339
        cputc(3, '.');
-
 
340
 
-
 
341
        button = 0;
-
 
342
        wakeup_init(&eventwakeup);
-
 
343
        struct button_hook_entry* hook = button_register_handler(handler, NULL);
-
 
344
        if (!hook) panicf(PANIC_KILLTHREAD, "\nCould not register button hook!");
-
 
345
 
-
 
346
        displaylcd(0, 0, 320, 240, darkened, 0, 0, 320);
-
 
347
        backlight_set_fade(32);
-
 
348
        backlight_set_brightness(177);
-
 
349
        backlight_on(true);
-
 
350
        scrollpos = 0;
-
 
351
 
342
        while (true)
352
        while (true)
343
        {
353
        {
-
 
354
            ui->blenda(290, 165, 255, framebuf, 0, 0, 290,
-
 
355
                       darkened, 15, 50, 320, disclaimer, 0, scrollpos, 290);
-
 
356
            displaylcd(15, 50, 290, 165, framebuf, 0, 0, 290);
-
 
357
 
344
            wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
358
            wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
345
            if (button == 2) break;
359
            if (button == 0x18) break;
346
            else if (button == 4)
360
            else if (button == 4)
347
            {
361
            {
348
                shutdown(false);
362
                shutdown(false);
349
                reset();
363
                reset();
350
            }
364
            }
351
            button = 0;
365
            button = 0;
352
        }
366
        }
-
 
367
 
353
        memset(lcdbuffer, 0xff, 0x25800);
368
        button_unregister_handler(hook);
354
        ucl_decompress(bitmapdata[BMPIDX_SIDEPANE], bitmapsize[BMPIDX_SIDEPANE], bmpbuffer, &dummy);
-
 
355
        renderbmp(&lcdbuffer[195], bmpbuffer, 320);
369
        free(darkened);
356
        ucl_decompress(bitmapdata[BMPIDX_INSTALLING], bitmapsize[BMPIDX_INSTALLING],
-
 
357
                       bmpbuffer, &dummy);
370
        free(disclaimer);
358
        renderbmp(lcdbuffer, bmpbuffer, 320);
371
                
359
        ucl_decompress(bitmapdata[BMPIDX_FORMATTING], bitmapsize[BMPIDX_FORMATTING],
372
        ui->blenda(165, 36, 255, framebuf, 0, 0, 165, bg, 77, 100, 320, actions, 0, 0, 165);
360
                        bmpbuffer, &dummy);
-
 
361
        renderbmp(&lcdbuffer[320 * 36], bmpbuffer, 320);
373
        displaylcd(0, 0, 320, 240, bg, 0, 0, 320);
362
        displaylcd(0, 319, 0, 239, lcdbuffer, 0);
374
        displaylcd(77, 100, 165, 36, framebuf, 0, 0, 165);
-
 
375
 
363
        mkfat32(&progressbar);
376
        mkfat32(&progressbar);
364
    }
377
    }
365
 
378
 
366
    ucl_decompress(bitmapdata[BMPIDX_COPYING], bitmapsize[BMPIDX_COPYING],
379
    ui->blenda(165, 36, 255, framebuf, 0, 0, 165, bg, 77, 100, 320, actions, 0, 36, 165);
367
                   bmpbuffer, &dummy);
380
    displaylcd(0, 0, 320, 240, bg, 0, 0, 320);
368
    renderbmp(&lcdbuffer[320 * 72], bmpbuffer, 320);
381
    displaylcd(77, 100, 165, 36, framebuf, 0, 0, 165);
-
 
382
    backlight_set_fade(32);
369
    displaylcd(0, 319, 0, 239, lcdbuffer, 0);
383
    backlight_set_brightness(177);
-
 
384
    backlight_on(true);
370
    int status;
385
    int cost;
371
    if (updating)
386
    if (updating)
372
    {
387
    {
373
        status = script[sp + 3];
388
        cost = commoncost;
374
        sp = script[sp + 1] >> 2;
389
        script = commonscript;
375
    }
390
    }
376
    else
391
    else
377
    {
392
    {
378
        status = script[sp + 2] + script[sp + 3];
393
        cost = firstinstcost + commoncost;
379
        sp += 4;
394
        script = firstinstscript;
380
    }
395
    }
381
    progressbar_init(&progressbar, 5, 189, 101, 116, 0, 0xdefb, 0x1d, 0, status);
396
    sp = 0;
382
    status = 0;
397
    cost = 0;
-
 
398
    progressbar_init(&progressbar, 15, 304, 135, 159, 0x77ff, 0xe8, 0x125f, 0, cost);
383
    while (script[sp])
399
    while (script[sp])
384
    {
400
    {
385
        int fd;
401
        int fd;
386
        void* data;
402
        void* data;
387
        switch (script[sp])
403
        switch (script[sp])
388
        {
404
        {
389
            case 1:
405
            case 1:
390
                mkdir(&scriptb[script[sp + 1]]);
406
                mkdir((char*)(script[sp + 1]));
391
                sp += 2;
407
                sp += 2;
392
                break;
408
                break;
393
            case 2:
409
            case 2:
394
                if (script[sp + 2] == 0xfffffffe && appleflash)
410
                if (script[sp + 2] == 0xfffffffe && appleflash)
395
                {
411
                {
Line 401... Line 417...
401
                {
417
                {
402
                    sp += 4;
418
                    sp += 4;
403
                    break;
419
                    break;
404
                }
420
                }
405
            case 3:
421
            case 3:
406
                fd = file_open(&scriptb[script[sp + 1]], O_RDONLY);
422
                fd = file_open((char*)(script[sp + 1]), O_RDONLY);
407
                if (fd >= 0)
423
                if (fd >= 0)
408
                {
424
                {
409
                    close(fd);
425
                    close(fd);
410
                    sp += 4;
426
                    sp += 4;
411
                    break;
427
                    break;
412
                }
428
                }
413
            case 4:
429
            case 4:
414
                if (script[sp + 2] < 0xfffffffe) data = &scriptb[script[sp + 2]];
430
                if (script[sp + 2] < 0xfffffffe) data = (void*)(script[sp + 2]);
415
                fd = file_creat(&scriptb[script[sp + 1]]);
431
                fd = file_creat((char*)(script[sp + 1]));
416
                if (fd >= 0)
432
                if (fd >= 0)
417
                {
433
                {
418
                    write(fd, data, script[sp + 3]);
434
                    write(fd, data, script[sp + 3]);
419
                    close(fd);
435
                    close(fd);
420
                }
436
                }
421
                sp += 4;
437
                sp += 4;
422
                break;
438
                break;
423
            default:
439
            default:
424
                panic(PANIC_KILLTHREAD, "Bad installation script!");
440
                panic(PANIC_KILLTHREAD, "\nBad installation script!");
425
        }
441
        }
426
        status += script[sp++];
442
        cost += script[sp++];
427
        progressbar_setpos(&progressbar, status, false);
443
        progressbar_setpos(&progressbar, cost, false);
428
    }
444
    }
429
    ucl_decompress(bitmapdata[BMPIDX_FLASHING], bitmapsize[BMPIDX_FLASHING], bmpbuffer, &dummy);
445
    ui->blenda(165, 36, 255, framebuf, 0, 0, 165, bg, 77, 100, 320, actions, 0, 72, 165);
430
    renderbmp(&lcdbuffer[320 * 108], bmpbuffer, 320);
-
 
431
    displaylcd(0, 319, 0, 239, lcdbuffer, 0);
446
    displaylcd(77, 100, 165, 36, framebuf, 0, 0, 165);
432
    progressbar_init(&progressbar, 5, 189, 162, 178, 0, 0xdefb, 0x1d, 0, 256);
447
    progressbar_init(&progressbar, 15, 304, 135, 159, 0x77ff, 0xe8, 0x125f, 0, 256);
433
    for (i = 0; i < 256; i++)
448
    for (i = 0; i < 256; i++)
434
    {
449
    {
435
        bootflash_writeraw(&norbuf[i << 12], i << 12, 1 << 12);
450
        bootflash_writeraw(&norbuf[i << 12], i << 12, 1 << 12);
436
        progressbar_setpos(&progressbar, i, false);
451
        progressbar_setpos(&progressbar, i, false);
437
    }
452
    }