Subversion Repositories freemyipod

Rev

Rev 373 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 373 Rev 421
Line 129... Line 129...
129
    while (!vbus_state());
129
    while (!vbus_state());
130
    udelay(1000000);
130
    udelay(1000000);
131
    while (vbus_state() && !usb_ejected);
131
    while (vbus_state() && !usb_ejected);
132
    udelay(200000);
132
    udelay(200000);
133
    usb_exit();
133
    usb_exit();
134
    lcdconsole_puts("\nLoading UBI file...\n", 0, 0xffff);
134
    lcdconsole_puts("\nLoading UBI file...\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
135
    int found = 0;
135
    int found = 0;
136
    uint16_t cluster;
136
    uint16_t cluster;
137
    uint32_t size;
137
    uint32_t size;
138
    uint16_t totalclusters = 0;
138
    uint16_t totalclusters = 0;
139
    for (i = 0; i < RAMDISK_SECTORSIZE; i += 32)
139
    for (i = 0; i < RAMDISK_SECTORSIZE; i += 32)
Line 149... Line 149...
149
        else if (*((uint16_t*)&ramdisk[1 + fatsectors][i + 26]))
149
        else if (*((uint16_t*)&ramdisk[1 + fatsectors][i + 26]))
150
            totalclusters += (*((uint32_t*)&ramdisk[1 + fatsectors][i + 28])
150
            totalclusters += (*((uint32_t*)&ramdisk[1 + fatsectors][i + 28])
151
                            + RAMDISK_SECTORSIZE - 1) / RAMDISK_SECTORSIZE;
151
                            + RAMDISK_SECTORSIZE - 1) / RAMDISK_SECTORSIZE;
152
    if (!found)
152
    if (!found)
153
    {
153
    {
154
        lcdconsole_puts("No UBI file found!", 0, 0xffff);
154
        lcdconsole_puts("No UBI file found!", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
155
        return;
155
        return;
156
    }
156
    }
157
    if (found != 1)
157
    if (found != 1)
158
    {
158
    {
159
        lcdconsole_puts("Multiple UBI files found!\nPlease copy exactly one.", 0, 0xffff);
159
        lcdconsole_puts("Multiple UBI files found!\nPlease copy exactly one.", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
160
        return;
160
        return;
161
    }
161
    }
162
    if (!size || !cluster)
162
    if (!size || !cluster)
163
    {
163
    {
164
        lcdconsole_puts("UBI file is empty!", 0, 0xffff);
164
        lcdconsole_puts("UBI file is empty!", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
165
        return;
165
        return;
166
    }
166
    }
167
    uint16_t dest = 0;
167
    uint16_t dest = 0;
168
    while (cluster != 0xffff)
168
    while (cluster != 0xffff)
169
    {
169
    {
170
        swap(fatsectors + cluster, dest++);
170
        swap(fatsectors + cluster, dest++);
171
        cluster = *((uint16_t*)&ramdisk[swapmap[1 + (cluster / (RAMDISK_SECTORSIZE / 2))]]
171
        cluster = *((uint16_t*)&ramdisk[swapmap[1 + (cluster / (RAMDISK_SECTORSIZE / 2))]]
172
                                       [(cluster % (RAMDISK_SECTORSIZE / 2)) * 2]); 
172
                                       [(cluster % (RAMDISK_SECTORSIZE / 2)) * 2]); 
173
    }
173
    }
174
    lcdconsole_puts("Rearranging files...\n", 0, 0xffff);
174
    lcdconsole_puts("Rearranging files...\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
175
    uint16_t offset = RAMDISK_SECTORS - totalclusters - 2;
175
    uint16_t offset = RAMDISK_SECTORS - totalclusters - 2;
176
    memset(newfat, 0, sizeof(newfat));
176
    memset(newfat, 0, sizeof(newfat));
177
    memset(newdir, 0, sizeof(newdir));
177
    memset(newdir, 0, sizeof(newdir));
178
    *((uint32_t*)newfat) = *((uint32_t*)ramdisk[swapmap[1]]);
178
    *((uint32_t*)newfat) = *((uint32_t*)ramdisk[swapmap[1]]);
179
    dest = 2;
179
    dest = 2;
Line 203... Line 203...
203
    fatsectors = (2 * (totalclusters + 2) + RAMDISK_SECTORSIZE - 1) / RAMDISK_SECTORSIZE;
203
    fatsectors = (2 * (totalclusters + 2) + RAMDISK_SECTORSIZE - 1) / RAMDISK_SECTORSIZE;
204
    _ramdiskptr = ramdisk[offset - fatsectors];
204
    _ramdiskptr = ramdisk[offset - fatsectors];
205
    memcpy(ramdisk[offset + 1], newdir, RAMDISK_SECTORSIZE);
205
    memcpy(ramdisk[offset + 1], newdir, RAMDISK_SECTORSIZE);
206
    memcpy(ramdisk[offset - fatsectors + 1], newfat, fatsectors * RAMDISK_SECTORSIZE);
206
    memcpy(ramdisk[offset - fatsectors + 1], newfat, fatsectors * RAMDISK_SECTORSIZE);
207
    fat16_write_mbr(_ramdiskptr, totalclusters + fatsectors + 2);
207
    fat16_write_mbr(_ramdiskptr, totalclusters + fatsectors + 2);
208
    lcdconsole_puts("Booting...", 0, 0xffff);
208
    lcdconsole_puts("Booting...", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
209
    displaylcd_sync();
209
    displaylcd_sync();
210
    udelay(10000);
210
    udelay(10000);
211
    execfirmware(ramdisk[0]);
211
    execfirmware(ramdisk[0]);
212
}
212
}
213
 
213
 
Line 227... Line 227...
227
    interrupt_init();
227
    interrupt_init();
228
#ifdef HAVE_I2C
228
#ifdef HAVE_I2C
229
    i2c_init();
229
    i2c_init();
230
#endif
230
#endif
231
    power_init();
231
    power_init();
232
    lcdconsole_puts(welcomestring, 0, 0xffff);
232
    lcdconsole_puts(welcomestring, LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
233
#ifdef HAVE_BACKLIGHT
233
#ifdef HAVE_BACKLIGHT
234
    backlight_init();
234
    backlight_init();
235
#endif
235
#endif
236
#ifdef HAVE_TARGETINIT_LATE
236
#ifdef HAVE_TARGETINIT_LATE
237
    targetinit_late();
237
    targetinit_late();