Subversion Repositories freemyipod

Rev

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

Rev 547 Rev 551
Line 146... Line 146...
146
    ((uint8_t*)buf)[0x42] = 0x29;
146
    ((uint8_t*)buf)[0x42] = 0x29;
147
    memcpy(&((uint8_t*)buf)[0x43], "\0\0\0\0iPodClassic", 0xf);
147
    memcpy(&((uint8_t*)buf)[0x43], "\0\0\0\0iPodClassic", 0xf);
148
    memcpy(&((uint8_t*)buf)[0x52], "FAT32   ", 8);
148
    memcpy(&((uint8_t*)buf)[0x52], "FAT32   ", 8);
149
    ((uint16_t*)buf)[0xff] = 0xaa55;
149
    ((uint16_t*)buf)[0xff] = 0xaa55;
150
    if (rc = storage_write_sectors_md(0, 0, 1, buf))
150
    if (rc = storage_write_sectors_md(0, 0, 1, buf))
151
        panicf(PANIC_KILLTHREAD, "\nError writing MBR: %08X", rc);
151
        panicf(PANIC_KILLTHREAD, "Error writing MBR: %08X", rc);
152
    memset(buf, 0, 0x800);
152
    memset(buf, 0, 0x800);
153
    buf[0] = 0x41615252;
153
    buf[0] = 0x41615252;
154
    buf[0x79] = 0x61417272;
154
    buf[0x79] = 0x61417272;
155
    buf[0x7a] = clustercount - 1;
155
    buf[0x7a] = clustercount - 1;
156
    buf[0x7b] = 2;
156
    buf[0x7b] = 2;
157
    buf[0x7f] = 0xaa550000;
157
    buf[0x7f] = 0xaa550000;
158
    if (rc = storage_write_sectors_md(0, 1, 1, buf))
158
    if (rc = storage_write_sectors_md(0, 1, 1, buf))
159
        panicf(PANIC_KILLTHREAD, "\nError writing FSINFO: %08X", rc);
159
        panicf(PANIC_KILLTHREAD, "Error writing FSINFO: %08X", rc);
160
    progressbar_init(progressbar, 15, 304, 135, 159, 0x77ff, 0xe8, 0x125f, 0, fatsectors);
160
    progressbar_init(progressbar, 15, 304, 135, 159, 0x77ff, 0xe8, 0x125f, 0, fatsectors);
161
    uint32_t cursect = 0;
161
    uint32_t cursect = 0;
162
    for (i = 0; i < fatsectors; i += 32)
162
    for (i = 0; i < fatsectors; i += 32)
163
    {
163
    {
164
        memset(buf, 0, 0x20000);
164
        memset(buf, 0, 0x20000);
165
        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);
166
        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))
167
            panicf(PANIC_KILLTHREAD, "\nError writing FAT sectors %d-%d: %08X",
167
            panicf(PANIC_KILLTHREAD, "Error writing FAT sectors %d-%d: %08X",
168
                   i, MIN(fatsectors - 1, i + 31), rc);
168
                   i, MIN(fatsectors - 1, i + 31), rc);
169
        progressbar_setpos(progressbar, i, false);
169
        progressbar_setpos(progressbar, i, false);
170
    }
170
    }
171
    memset(buf, 0, secperclus * 0x1000);
171
    memset(buf, 0, secperclus * 0x1000);
172
    memcpy(buf, "iPodClassic\x08", 12);
172
    memcpy(buf, "iPodClassic\x08", 12);
173
    if (rc = storage_write_sectors_md(0, database, secperclus, buf))
173
    if (rc = storage_write_sectors_md(0, database, secperclus, buf))
174
        panicf(PANIC_KILLTHREAD, "\nError writing root directory sectors: %08X", i, rc);
174
        panicf(PANIC_KILLTHREAD, "Error writing root directory sectors: %08X", i, rc);
175
    free(buf);
175
    free(buf);
176
    disk_mount(0);
176
    disk_mount(0);
177
}
177
}
178
 
178
 
179
void main(void)
179
void main(void)
Line 188... Line 188...
188
    uint8_t* oldnor;
188
    uint8_t* oldnor;
189
#define oldnorword ((uint32_t*)oldnor)
189
#define oldnorword ((uint32_t*)oldnor)
190
 
190
 
191
    cputc(3, '.');
191
    cputc(3, '.');
192
    struct emcorelib_header* libpng = get_library(0x64474e50, LIBPNG_API_VERSION, LIBSOURCE_RAM_NEEDCOPY, f_png_emcorelib);
192
    struct emcorelib_header* libpng = get_library(0x64474e50, LIBPNG_API_VERSION, LIBSOURCE_RAM_NEEDCOPY, f_png_emcorelib);
193
    if (!libpng) panicf(PANIC_KILLTHREAD, "\nCould not load PNG decoder library!");
193
    if (!libpng) panicf(PANIC_KILLTHREAD, "Could not load PNG decoder library!");
194
    struct libpng_api* png = (struct libpng_api*)libpng->api;
194
    struct libpng_api* png = (struct libpng_api*)libpng->api;
195
    cputc(3, '.');
195
    cputc(3, '.');
196
    struct emcorelib_header* libui = get_library(0x49554365, LIBUI_API_VERSION, LIBSOURCE_RAM_NEEDCOPY, f_ui_emcorelib);
196
    struct emcorelib_header* libui = get_library(0x49554365, LIBUI_API_VERSION, LIBSOURCE_RAM_NEEDCOPY, f_ui_emcorelib);
197
    if (!libui) panicf(PANIC_KILLTHREAD, "\nCould not load user interface library!");
197
    if (!libui) panicf(PANIC_KILLTHREAD, "Could not load user interface library!");
198
    struct libui_api* ui = (struct libui_api*)libui->api;
198
    struct libui_api* ui = (struct libui_api*)libui->api;
199
    cputc(3, '.');
199
    cputc(3, '.');
200
 
200
 
201
    struct png_info* handle = png->png_open(background_png, background_png_size);
201
    struct png_info* handle = png->png_open(background_png, background_png_size);
202
    if (!handle) panicf(PANIC_KILLTHREAD, "\nCould not parse background image!");
202
    if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse background image!");
203
    cputc(3, '.');
203
    cputc(3, '.');
204
    struct png_rgb* bg = png->png_decode_rgb(handle);
204
    struct png_rgb* bg = png->png_decode_rgb(handle);
205
    if (!bg) panicf(PANIC_KILLTHREAD, "\nCould not decode background image!");
205
    if (!bg) panicf(PANIC_KILLTHREAD, "Could not decode background image!");
206
    png->png_destroy(handle);
206
    png->png_destroy(handle);
207
    cputc(3, '.');
207
    cputc(3, '.');
208
    handle = png->png_open(actions_png, actions_png_size);
208
    handle = png->png_open(actions_png, actions_png_size);
209
    if (!handle) panicf(PANIC_KILLTHREAD, "\nCould not parse actions image!");
209
    if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse actions image!");
210
    cputc(3, '.');
210
    cputc(3, '.');
211
    struct png_rgba* actions = png->png_decode_rgba(handle);
211
    struct png_rgba* actions = png->png_decode_rgba(handle);
212
    if (!actions) panicf(PANIC_KILLTHREAD, "\nCould not decode actions image!");
212
    if (!actions) panicf(PANIC_KILLTHREAD, "Could not decode actions image!");
213
    png->png_destroy(handle);
213
    png->png_destroy(handle);
214
    cputc(3, '.');
214
    cputc(3, '.');
215
    void* framebuf = malloc(290 * 165 * 3);
215
    void* framebuf = malloc(290 * 165 * 3);
216
    if (!framebuf) panicf(PANIC_KILLTHREAD, "\nCould not allocate frame buffer!");
216
    if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate frame buffer!");
217
    cputc(3, '.');
217
    cputc(3, '.');
218
 
218
 
219
    disk_unmount(0);
219
    disk_unmount(0);
220
    bool updating = disk_mount(0);
220
    bool updating = disk_mount(0);
221
    cputc(3, '.');
221
    cputc(3, '.');
Line 229... Line 229...
229
    if (oldnorword[0x400] == 0x53436667) appleflash = false;
229
    if (oldnorword[0x400] == 0x53436667) appleflash = false;
230
    else
230
    else
231
    {
231
    {
232
        updating = false;
232
        updating = false;
233
        if (oldnorword[0] == 0x53436667) appleflash = true;
233
        if (oldnorword[0] == 0x53436667) appleflash = true;
234
        else panic(PANIC_KILLTHREAD, "\nBoot flash contents are damaged! "
234
        else panic(PANIC_KILLTHREAD, "Boot flash contents are damaged! "
235
                                     "(No SYSCFG found)\n\nPlease ask for help.\n");
235
                                     "(No SYSCFG found)\n\nPlease ask for help.\n");
236
    }
236
    }
237
    memcpy(&norbuf[0x1000], &oldnor[appleflash ? 0 : 0x1000], 0x1000);
237
    memcpy(&norbuf[0x1000], &oldnor[appleflash ? 0 : 0x1000], 0x1000);
238
    cputc(3, '.');
238
    cputc(3, '.');
239
 
239
 
Line 259... Line 259...
259
        if (size)
259
        if (size)
260
        {
260
        {
261
            if (align && !(flags & 1))
261
            if (align && !(flags & 1))
262
            {
262
            {
263
                if ((align << 12) < beginptr)
263
                if ((align << 12) < beginptr)
264
                    panicf(PANIC_KILLTHREAD, "\nError: Align failed! (%02X)", align);
264
                    panicf(PANIC_KILLTHREAD, "Error: Align failed! (%02X)", align);
265
                beginptr = align << 12;
265
                beginptr = align << 12;
266
            }
266
            }
267
            if (endptr - beginptr < size)
267
            if (endptr - beginptr < size)
268
                panicf(PANIC_KILLTHREAD, "\nError: Flash is full!");
268
                panicf(PANIC_KILLTHREAD, "Error: Flash is full!");
269
            uint32_t storesize = size;
269
            uint32_t storesize = size;
270
            if (flags & 2) storesize |= 0x80000000;
270
            if (flags & 2) storesize |= 0x80000000;
271
            int offs = 0;
271
            int offs = 0;
272
            if (flags & 8)
272
            if (flags & 8)
273
            {
273
            {
Line 287... Line 287...
287
                beginptr += ((size + 0xfff) & ~0xfff);
287
                beginptr += ((size + 0xfff) & ~0xfff);
288
            }
288
            }
289
            if (!(flags & 4))
289
            if (!(flags & 4))
290
            {
290
            {
291
                if (dirptr >= 0x1000)
291
                if (dirptr >= 0x1000)
292
                    panicf(PANIC_KILLTHREAD, "\nError: Directory is full!");
292
                    panicf(PANIC_KILLTHREAD, "Error: Directory is full!");
293
                memcpy(&norbuf[dirptr], &script[sp], 8);
293
                memcpy(&norbuf[dirptr], &script[sp], 8);
294
                norbufword[(dirptr >> 2) + 2] = file;
294
                norbufword[(dirptr >> 2) + 2] = file;
295
                norbufword[(dirptr >> 2) + 3] = storesize;
295
                norbufword[(dirptr >> 2) + 3] = storesize;
296
                dirptr += 0x10;
296
                dirptr += 0x10;
297
                sp += 2;
297
                sp += 2;
Line 316... Line 316...
316
    }
316
    }
317
 
317
 
318
    if (!updating)
318
    if (!updating)
319
    {
319
    {
320
        void* darkened = malloc(320 * 240 * 3);
320
        void* darkened = malloc(320 * 240 * 3);
321
        if (!darkened) panicf(PANIC_KILLTHREAD, "\nCould not allocate darkened image!");
321
        if (!darkened) panicf(PANIC_KILLTHREAD, "Could not allocate darkened image!");
322
        cputc(3, '.');
322
        cputc(3, '.');
323
        handle = png->png_open(darkener_png, darkener_png_size);
323
        handle = png->png_open(darkener_png, darkener_png_size);
324
        if (!handle) panicf(PANIC_KILLTHREAD, "\nCould not parse darkener image!");
324
        if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse darkener image!");
325
        cputc(3, '.');
325
        cputc(3, '.');
326
        struct png_rgba* darkener = png->png_decode_rgba(handle);
326
        struct png_rgba* darkener = png->png_decode_rgba(handle);
327
        if (!darkener) panicf(PANIC_KILLTHREAD, "\nCould not decode darkener image!");
327
        if (!darkener) panicf(PANIC_KILLTHREAD, "Could not decode darkener image!");
328
        png->png_destroy(handle);
328
        png->png_destroy(handle);
329
        cputc(3, '.');
329
        cputc(3, '.');
330
        ui->blenda(320, 240, 255, darkened, 0, 0, 320, bg, 0, 0, 320, darkener, 0, 0, 320);
330
        ui->blenda(320, 240, 255, darkened, 0, 0, 320, bg, 0, 0, 320, darkener, 0, 0, 320);
331
        free(darkener);
331
        free(darkener);
332
        cputc(3, '.');
332
        cputc(3, '.');
333
        handle = png->png_open(disclaimer_png, disclaimer_png_size);
333
        handle = png->png_open(disclaimer_png, disclaimer_png_size);
334
        if (!handle) panicf(PANIC_KILLTHREAD, "\nCould not parse disclaimer image!");
334
        if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse disclaimer image!");
335
        cputc(3, '.');
335
        cputc(3, '.');
336
        struct png_rgba* disclaimer = png->png_decode_rgba(handle);
336
        struct png_rgba* disclaimer = png->png_decode_rgba(handle);
337
        if (!disclaimer) panicf(PANIC_KILLTHREAD, "\nCould not decode disclaimer image!");
337
        if (!disclaimer) panicf(PANIC_KILLTHREAD, "Could not decode disclaimer image!");
338
        png->png_destroy(handle);
338
        png->png_destroy(handle);
339
        cputc(3, '.');
339
        cputc(3, '.');
340
 
340
 
341
        button = 0;
341
        button = 0;
342
        wakeup_init(&eventwakeup);
342
        wakeup_init(&eventwakeup);
343
        struct button_hook_entry* hook = button_register_handler(handler, NULL);
343
        struct button_hook_entry* hook = button_register_handler(handler, NULL);
344
        if (!hook) panicf(PANIC_KILLTHREAD, "\nCould not register button hook!");
344
        if (!hook) panicf(PANIC_KILLTHREAD, "Could not register button hook!");
345
 
345
 
346
        displaylcd(0, 0, 320, 240, darkened, 0, 0, 320);
346
        displaylcd(0, 0, 320, 240, darkened, 0, 0, 320);
347
        backlight_set_fade(32);
347
        backlight_set_fade(32);
348
        backlight_set_brightness(177);
348
        backlight_set_brightness(177);
349
        backlight_on(true);
349
        backlight_on(true);
Line 380... Line 380...
380
    displaylcd(0, 0, 320, 240, bg, 0, 0, 320);
380
    displaylcd(0, 0, 320, 240, bg, 0, 0, 320);
381
    displaylcd(77, 100, 165, 36, framebuf, 0, 0, 165);
381
    displaylcd(77, 100, 165, 36, framebuf, 0, 0, 165);
382
    backlight_set_fade(32);
382
    backlight_set_fade(32);
383
    backlight_set_brightness(177);
383
    backlight_set_brightness(177);
384
    backlight_on(true);
384
    backlight_on(true);
-
 
385
 
385
    int cost;
386
    int cost;
386
    if (updating)
387
    if (updating)
387
    {
388
    {
388
        cost = commoncost;
389
        cost = commoncost;
389
        script = commonscript;
390
        script = commonscript;
Line 435... Line 436...
435
                    close(fd);
436
                    close(fd);
436
                }
437
                }
437
                sp += 4;
438
                sp += 4;
438
                break;
439
                break;
439
            default:
440
            default:
440
                panic(PANIC_KILLTHREAD, "\nBad installation script!");
441
                panic(PANIC_KILLTHREAD, "Bad installation script!");
441
        }
442
        }
442
        cost += script[sp++];
443
        cost += script[sp++];
443
        progressbar_setpos(&progressbar, cost, false);
444
        progressbar_setpos(&progressbar, cost, false);
444
    }
445
    }
445
 
446