Subversion Repositories freemyipod

Rev

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

Rev 838 Rev 875
Line 29... Line 29...
29
#define STRINGIFY(x) #x
29
#define STRINGIFY(x) #x
30
#define STR(x) STRINGIFY(x)
30
#define STR(x) STRINGIFY(x)
31
#define BOOTNOTE_FILENAME "/Notes/" STR(BASENAME) ".bootnote"
31
#define BOOTNOTE_FILENAME "/Notes/" STR(BASENAME) ".bootnote"
32
 
32
 
33
 
33
 
34
void main(int argc, const char** argv);
34
static void main(int argc, const char** argv);
35
EMCORE_APP_HEADER("emCORE installer", main, 127)
35
EMCORE_APP_HEADER("emCORE installer", main, 127)
36
 
36
 
37
 
37
 
38
extern char background_png[];
38
extern char background_png[];
39
extern uint32_t background_png_size;
39
extern uint32_t background_png_size;
Line 50... Line 50...
50
extern uint32_t firstinstscript[];
50
extern uint32_t firstinstscript[];
51
extern uint32_t commoncost;
51
extern uint32_t commoncost;
52
extern uint32_t commonscript[];
52
extern uint32_t commonscript[];
53
 
53
 
54
 
54
 
55
uint32_t fat32_ok;
55
static uint32_t fat32_ok;
56
uint32_t fat32_startsector;
56
static uint32_t fat32_startsector;
57
uint32_t fat32_secperclus;
57
static uint32_t fat32_secperclus;
58
uint32_t fat32_database;
58
static uint32_t fat32_database;
59
uint32_t fat32_fatbase;
59
static uint32_t fat32_fatbase;
60
uint32_t fat32_fatsize;
60
static uint32_t fat32_fatsize;
61
uint32_t fat32_fatcount;
61
static uint32_t fat32_fatcount;
62
uint32_t fat32_sectorcount;
62
static uint32_t fat32_sectorcount;
63
uint32_t fat32_clustercount;
63
static uint32_t fat32_clustercount;
64
uint32_t fat32_rootdirclus;
64
static uint32_t fat32_rootdirclus;
65
 
65
 
66
struct wakeup eventwakeup;
66
static struct wakeup eventwakeup;
67
volatile int button;
67
static volatile int button;
68
volatile int scrollpos;
68
static volatile int scrollpos;
69
 
69
 
70
 
70
 
71
#define nor ((uint8_t*)0x24000000)
71
#define nor ((uint8_t*)0x24000000)
72
#define norword ((uint32_t*)0x24000000)
72
#define norword ((uint32_t*)0x24000000)
73
 
73
 
74
 
74
 
75
void handler(void* user, enum button_event eventtype, int which, int value)
75
static void handler(void* user, enum button_event eventtype, int which, int value)
76
{
76
{
77
    if (eventtype == BUTTON_PRESS) button |= 1 << which;
77
    if (eventtype == BUTTON_PRESS) button |= 1 << which;
78
    if (eventtype == BUTTON_RELEASE) button &= ~(1 << which);
78
    if (eventtype == BUTTON_RELEASE) button &= ~(1 << which);
79
    if (eventtype == WHEEL_MOVED_ACCEL)
79
    if (eventtype == WHEEL_MOVED_ACCEL)
80
        scrollpos = MAX(0, MIN(309, scrollpos + value / 8));
80
        scrollpos = MAX(0, MIN(309, scrollpos + value / 8));
81
    wakeup_signal(&eventwakeup);
81
    wakeup_signal(&eventwakeup);
82
}
82
}
83
 
83
 
84
uint32_t freeret(uint32_t rc, void* ptr)
84
static uint32_t freeret(uint32_t rc, void* ptr)
85
{
85
{
86
    free(ptr);
86
    free(ptr);
87
    return rc;
87
    return rc;
88
}
88
}
89
 
89
 
90
int decryptfw(void* image, uint32_t offset)
90
static int decryptfw(void* image, uint32_t offset)
91
{
91
{
92
    uint32_t size = ((uint32_t*)image)[5];
92
    uint32_t size = ((uint32_t*)image)[5];
93
    if (size > 0x800000) return 0;
93
    if (size > 0x800000) return 0;
94
    hwkeyaes(HWKEYAES_DECRYPT, ((uint32_t*)image)[2], &((uint8_t*)image)[offset], size);
94
    hwkeyaes(HWKEYAES_DECRYPT, ((uint32_t*)image)[2], &((uint8_t*)image)[offset], size);
95
    memcpy(image, &((uint8_t*)image)[offset], size);
95
    memcpy(image, &((uint8_t*)image)[offset], size);
96
    cputc(3, '.');
96
    cputc(3, '.');
97
    return size;
97
    return size;
98
}
98
}
99
 
99
 
100
uint32_t getfw(const char* filename, uint32_t* sector, int* size)
100
static uint32_t getfw(const char* filename, uint32_t* sector, int* size)
101
{
101
{
102
    uint32_t i;
102
    uint32_t i;
103
    uint32_t* buffer = memalign(0x10, 0x800);
103
    uint32_t* buffer = memalign(0x10, 0x800);
104
    if (storage_read_sectors_md(0, 0, 1, buffer) != 0) return freeret(1, buffer);
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);
105
    if (*((uint16_t*)((uint32_t)buffer + 0x1FE)) != 0xAA55) return freeret(1, buffer);
Line 129... Line 129...
129
            return 0;
129
            return 0;
130
        }
130
        }
131
    return freeret(2, buffer);
131
    return freeret(2, buffer);
132
}
132
}
133
 
133
 
134
uint32_t readfw(const char* filename, void** address, int* size)
134
static uint32_t readfw(const char* filename, void** address, int* size)
135
{
135
{
136
    uint32_t sector;
136
    uint32_t sector;
137
    uint32_t rc = getfw(filename, &sector, size);
137
    uint32_t rc = getfw(filename, &sector, size);
138
    if (rc) return rc;
138
    if (rc) return rc;
139
    *address = memalign(0x10, *size);
139
    *address = memalign(0x10, *size);
Line 143... Line 143...
143
    *size = decryptfw(*address, 0x800);
143
    *size = decryptfw(*address, 0x800);
144
    realloc(*address, *size);
144
    realloc(*address, *size);
145
    return 0;
145
    return 0;
146
}
146
}
147
 
147
 
148
uint32_t getapplenor(const char* filename, void** address, int* size)
148
static uint32_t getapplenor(const char* filename, void** address, int* size)
149
{
149
{
150
    uint32_t i;
150
    uint32_t i;
151
    for (i = 0xffe00; i < 0x100000; i += 0x28)
151
    for (i = 0xffe00; i < 0x100000; i += 0x28)
152
        if (memcmp(&nor[i], filename, 8) == 0)
152
        if (memcmp(&nor[i], filename, 8) == 0)
153
        {
153
        {
Line 156... Line 156...
156
            return 0;
156
            return 0;
157
        }
157
        }
158
    return 1;
158
    return 1;
159
}
159
}
160
 
160
 
161
uint32_t readapplenor(const char* filename, void** address, int* size)
161
static uint32_t readapplenor(const char* filename, void** address, int* size)
162
{
162
{
163
    void* noraddr;
163
    void* noraddr;
164
    uint32_t rc = getapplenor(filename, &noraddr, size);
164
    uint32_t rc = getapplenor(filename, &noraddr, size);
165
    if (rc) return rc;
165
    if (rc) return rc;
166
    *address = malloc(*size);
166
    *address = malloc(*size);
Line 169... Line 169...
169
    *size = decryptfw(*address, 0x200);
169
    *size = decryptfw(*address, 0x200);
170
    realloc(*address, *size);
170
    realloc(*address, *size);
171
    return 0;
171
    return 0;
172
}
172
}
173
 
173
 
174
uint32_t fat32_resize_patchdirs(uint32_t clusterchain, uint32_t clustoffset,
174
static uint32_t fat32_resize_patchdirs(uint32_t clusterchain, uint32_t clustoffset,
175
                                struct progressbar_state* progressbar, int min, int len)
175
                                       struct progressbar_state* progressbar, int min, int len)
176
{
176
{
177
    uint32_t i, j,  rc;
177
    uint32_t i, j,  rc;
178
    uint32_t* buffer = (uint32_t*)memalign(0x10, 0x800);
178
    uint32_t* buffer = (uint32_t*)memalign(0x10, 0x800);
179
    int pos = min, newlen = len / 15;
179
    int pos = min, newlen = len / 15;
180
    while (clusterchain < 0x0ffffff0)
180
    while (clusterchain < 0x0ffffff0)
Line 234... Line 234...
234
    free(buffer);
234
    free(buffer);
235
    if (len) progressbar_setpos(progressbar, min + len, false);
235
    if (len) progressbar_setpos(progressbar, min + len, false);
236
    return 0;
236
    return 0;
237
}
237
}
238
 
238
 
239
uint32_t fat32_resize_fulldisk(struct progressbar_state* progressbar)
239
static uint32_t fat32_resize_fulldisk(struct progressbar_state* progressbar)
240
{
240
{
241
    uint32_t i, j, rc;
241
    uint32_t i, j, rc;
242
    uint32_t fatsectors = 1;
242
    uint32_t fatsectors = 1;
243
    uint32_t oldfatsectors = 0;
243
    uint32_t oldfatsectors = 0;
244
    uint32_t clustercount;
244
    uint32_t clustercount;
Line 416... Line 416...
416
    progressbar_setpos(progressbar, 100, false);
416
    progressbar_setpos(progressbar, 100, false);
417
    fat32_ok = 1;
417
    fat32_ok = 1;
418
    return 0;
418
    return 0;
419
}
419
}
420
 
420
 
421
uint32_t fat32_init()
421
static uint32_t fat32_init()
422
{
422
{
423
    uint32_t i;
423
    uint32_t i;
424
    fat32_ok = 0;
424
    fat32_ok = 0;
425
    fat32_startsector = 0xFFFFFFFF;
425
    fat32_startsector = 0xFFFFFFFF;
426
    uint32_t* buf = (uint32_t*)memalign(0x10, 0x800);
426
    uint32_t* buf = (uint32_t*)memalign(0x10, 0x800);
Line 472... Line 472...
472
 
472
 
473
    fat32_ok = 1;
473
    fat32_ok = 1;
474
    return 0;
474
    return 0;
475
}
475
}
476
 
476
 
477
void main(int argc, const char** argv)
477
static void main(int argc, const char** argv)
478
{
478
{
479
    uint32_t i, j, k, rc;
479
    uint32_t i, j, k, rc;
480
    uint32_t dummy;
480
    uint32_t dummy;
481
    int deleterc = 1;
481
    int deleterc = 1;
482
    struct progressbar_state progressbar;
482
    struct progressbar_state progressbar;