use the correct image -- how could I mix up those?
[Rockbox.git] / bootloader / main-e200r-installer.c
blob9b977ca538b4dcf242ac0fd8fb8faa7a24f37ad6
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Barry Wardell
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
15 * All files in this archive are subject to the GNU General Public License.
16 * See the file COPYING in the source tree root for full license agreement.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include "common.h"
25 #include "cpu.h"
26 #include "file.h"
27 #include "system.h"
28 #include "kernel.h"
29 #include "lcd.h"
30 #include "font.h"
31 #include "ata.h"
32 #include "button.h"
33 #include "disk.h"
34 #include "crc32-mi4.h"
35 #include <string.h>
36 #include "i2c.h"
37 #include "backlight-target.h"
39 /* Bootloader version */
40 char version[] = APPSVERSION;
42 #define START_SECTOR_OF_ROM 1
43 #define ROMSECTOR_TO_HACK 63
44 #define HACK_OFFSET 498
45 #define KNOWN_CRC32 0x5a09c266
46 char knownBytes[] = {0x00, 0x24, 0x07, 0xe1};
47 char changedBytes[] = {0xc0, 0x46, 0xc0, 0x46 };
48 void* main(void)
50 int i;
51 int btn;
52 int num_partitions;
53 int crc32;
54 char sector[512];
55 struct partinfo* pinfo;
56 chksum_crc32gentab ();
58 system_init();
59 kernel_init();
60 lcd_init();
61 font_init();
62 button_init();
63 i2c_init();
64 __backlight_on();
66 lcd_set_foreground(LCD_WHITE);
67 lcd_set_background(LCD_BLACK);
68 lcd_clear_display();
70 btn = button_read_device();
71 verbose = true;
73 lcd_setfont(FONT_SYSFIXED);
75 printf("Rockbox e200R installer");
76 printf("Version: %s", version);
77 printf(MODEL_NAME);
79 i=ata_init();
80 disk_init(IF_MV(0));
81 num_partitions = disk_mount_all();
82 if (num_partitions<=0)
84 error(EDISK,num_partitions);
86 pinfo = disk_partinfo(1);
87 printf("--- Partition info ---");
88 printf("start: %x", pinfo->start);
89 printf("size: %x", pinfo->size);
90 printf("type: %x", pinfo->type);
91 printf("reading: %x", (START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK)*512);
92 ata_read_sectors(IF_MV2(0,)
93 pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
94 1 , sector);
95 crc32 = chksum_crc32 (sector, 512);
96 printf("--- Hack Status ---");
97 printf("Sector checksum: %x", crc32);
99 if ((crc32 == KNOWN_CRC32) &&
100 !memcmp(&sector[HACK_OFFSET], knownBytes,
101 sizeof(knownBytes)/sizeof(*knownBytes)))
104 memcpy(&sector[HACK_OFFSET], changedBytes,
105 sizeof(changedBytes)/sizeof(*changedBytes));
106 ata_write_sectors(IF_MV2(0,)
107 pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
108 1 , sector);
109 printf("Firmware Hacked");
110 printf("Proceed to Step 2");
112 else
113 printf("Unknown bootloader... aborted");
114 GPIOG_OUTPUT_VAL &=~0x80;
116 while(1);
117 return NULL;