diff options
Diffstat (limited to 'bootloader/gigabeat.c')
-rw-r--r-- | bootloader/gigabeat.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c new file mode 100644 index 0000000000..dcd013e867 --- /dev/null +++ b/bootloader/gigabeat.c | |||
@@ -0,0 +1,115 @@ | |||
1 | #include "config.h" | ||
2 | |||
3 | #include <stdlib.h> | ||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | #include "cpu.h" | ||
7 | #include "system.h" | ||
8 | #include "lcd.h" | ||
9 | #include "kernel.h" | ||
10 | #include "thread.h" | ||
11 | #include "ata.h" | ||
12 | #include "fat.h" | ||
13 | #include "disk.h" | ||
14 | #include "font.h" | ||
15 | #include "adc.h" | ||
16 | #include "backlight.h" | ||
17 | #include "panic.h" | ||
18 | #include "power.h" | ||
19 | #include "file.h" | ||
20 | |||
21 | char version[] = APPSVERSION; | ||
22 | |||
23 | void go_usb_mode() { | ||
24 | /* Drop into USB mode. This does not check for disconnection. */ | ||
25 | |||
26 | int i; | ||
27 | |||
28 | GPBDAT &= 0x7EF; | ||
29 | GPBCON |= 1<<8; | ||
30 | |||
31 | GPGDAT &= 0xE7FF; | ||
32 | GPGDAT |= 1<<11; | ||
33 | |||
34 | for (i = 0; i < 10000000; i++) {continue;} | ||
35 | |||
36 | GPBCON &= 0x2FFCFF; | ||
37 | GPBDAT |= 1<<5; | ||
38 | GPBDAT |= 1<<6; | ||
39 | } | ||
40 | |||
41 | void * main(void) | ||
42 | { | ||
43 | int line = 0, i; | ||
44 | char buf[256]; | ||
45 | struct partinfo* pinfo; | ||
46 | unsigned short* identify_info; | ||
47 | int testfile; | ||
48 | |||
49 | lcd_init(); | ||
50 | lcd_setfont(FONT_SYSFIXED); | ||
51 | /* | ||
52 | lcd_puts(0, line++, "Rockbox boot loader"); | ||
53 | snprintf(buf, sizeof(buf), "Version: 20%s", version); | ||
54 | lcd_puts(0, line++, buf); | ||
55 | snprintf(buf, sizeof(buf), "Gigabeat version: 0x%08x", 1); | ||
56 | lcd_puts(0, line++, buf); | ||
57 | */ | ||
58 | |||
59 | lcd_puts(0, line++, "Hold MENU when booting for rescue mode."); | ||
60 | lcd_update(); | ||
61 | |||
62 | /* hold MENU to enter rescue mode */ | ||
63 | if (GPGDAT & 2) { | ||
64 | lcd_puts(0, line++, "Entering rescue mode.."); | ||
65 | lcd_update(); | ||
66 | go_usb_mode(); | ||
67 | while(1); | ||
68 | } | ||
69 | |||
70 | i = ata_init(); | ||
71 | i = disk_mount_all(); | ||
72 | |||
73 | snprintf(buf, sizeof(buf), "disk_mount_all: %d", i); | ||
74 | lcd_puts(0, line++, buf); | ||
75 | |||
76 | identify_info = ata_get_identify(); | ||
77 | |||
78 | for (i=0; i < 20; i++) | ||
79 | ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]); | ||
80 | |||
81 | buf[40]=0; | ||
82 | |||
83 | /* kill trailing space */ | ||
84 | for (i=39; i && buf[i]==' '; i--) | ||
85 | buf[i] = 0; | ||
86 | |||
87 | lcd_puts(0, line++, "Model"); | ||
88 | lcd_puts(0, line++, buf); | ||
89 | |||
90 | for (i=0; i < 4; i++) | ||
91 | ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]); | ||
92 | |||
93 | buf[8]=0; | ||
94 | |||
95 | lcd_puts(0, line++, "Firmware"); | ||
96 | lcd_puts(0, line++, buf); | ||
97 | |||
98 | pinfo = disk_partinfo(0); | ||
99 | snprintf(buf, sizeof(buf), "Partition 0: 0x%02x %ld MB", | ||
100 | pinfo->type, pinfo->size / 2048); | ||
101 | lcd_puts(0, line++, buf); | ||
102 | |||
103 | testfile = open("/boottest.txt", O_WRONLY|O_CREAT|O_TRUNC); | ||
104 | write(testfile, "It works!", 9); | ||
105 | close(testfile); | ||
106 | |||
107 | lcd_update(); | ||
108 | |||
109 | /* now wait in USB mode so the bootloader can be updated */ | ||
110 | go_usb_mode(); | ||
111 | while(1); | ||
112 | |||
113 | return((void *)0); | ||
114 | } | ||
115 | |||