diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2005-05-20 18:16:45 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2005-05-20 18:16:45 +0000 |
commit | 8e958b540b36eea59fdf48258009de572d7e5ec9 (patch) | |
tree | ca868ae9e128c126e764d0e171dfb5cc7f9c378a | |
parent | 3beafe4c44987d339a34be3dd1d19fefdb62df88 (diff) | |
download | rockbox-8e958b540b36eea59fdf48258009de572d7e5ec9.tar.gz rockbox-8e958b540b36eea59fdf48258009de572d7e5ec9.zip |
Boot loader: correct handling of CPU frequency setting, better button handling, USB mode handling
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6492 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | bootloader/main.c | 83 |
1 files changed, 75 insertions, 8 deletions
diff --git a/bootloader/main.c b/bootloader/main.c index dbc8bf480f..5a1e79735b 100644 --- a/bootloader/main.c +++ b/bootloader/main.c | |||
@@ -42,6 +42,32 @@ int usb_screen(void) | |||
42 | return 0; | 42 | return 0; |
43 | } | 43 | } |
44 | 44 | ||
45 | static void usb_enable(bool on) | ||
46 | { | ||
47 | GPIO_OUT &= ~0x01000000; /* GPIO24 is the Cypress chip power */ | ||
48 | GPIO_ENABLE |= 0x01000000; | ||
49 | GPIO_FUNCTION |= 0x01000000; | ||
50 | |||
51 | GPIO1_FUNCTION |= 0x00000080; /* GPIO39 is the USB detect input */ | ||
52 | |||
53 | if(on) | ||
54 | { | ||
55 | /* Power on the Cypress chip */ | ||
56 | GPIO_OUT |= 0x01000000; | ||
57 | sleep(2); | ||
58 | } | ||
59 | else | ||
60 | { | ||
61 | /* Power off the Cypress chip */ | ||
62 | GPIO_OUT &= ~0x01000000; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | bool usb_detect(void) | ||
67 | { | ||
68 | return (GPIO1_READ & 0x80)?true:false; | ||
69 | } | ||
70 | |||
45 | void start_iriver_fw(void) | 71 | void start_iriver_fw(void) |
46 | { | 72 | { |
47 | asm(" move.w #0x2700,%sr"); | 73 | asm(" move.w #0x2700,%sr"); |
@@ -127,10 +153,32 @@ void main(void) | |||
127 | int i; | 153 | int i; |
128 | int rc; | 154 | int rc; |
129 | char buf[256]; | 155 | char buf[256]; |
156 | bool rc_on_button = false; | ||
157 | bool on_button = false; | ||
158 | int data; | ||
159 | |||
160 | /* Read the buttons early */ | ||
161 | |||
162 | /* Set GPIO33, GPIO37, GPIO38 and GPIO52 as general purpose inputs */ | ||
163 | GPIO1_FUNCTION |= 0x00100062; | ||
164 | GPIO1_ENABLE &= ~0x00100062; | ||
165 | |||
166 | data = GPIO1_READ; | ||
167 | if ((data & 0x20) == 0) | ||
168 | on_button = true; | ||
169 | |||
170 | if ((data & 0x40) == 0) | ||
171 | rc_on_button = true; | ||
130 | 172 | ||
131 | power_init(); | 173 | power_init(); |
132 | system_init(); | 174 | system_init(); |
133 | kernel_init(); | 175 | kernel_init(); |
176 | |||
177 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
178 | /* Set up waitstates for the peripherals */ | ||
179 | set_cpu_frequency(0); /* PLL off */ | ||
180 | #endif | ||
181 | |||
134 | backlight_init(); | 182 | backlight_init(); |
135 | set_irq_level(0); | 183 | set_irq_level(0); |
136 | lcd_init(); | 184 | lcd_init(); |
@@ -140,19 +188,21 @@ void main(void) | |||
140 | 188 | ||
141 | lcd_setfont(FONT_SYSFIXED); | 189 | lcd_setfont(FONT_SYSFIXED); |
142 | 190 | ||
191 | snprintf(buf, 256, "Rockboot version 1"); | ||
192 | lcd_puts(0, line++, buf); | ||
193 | |||
143 | sleep(HZ/50); /* Allow the button driver to check the buttons */ | 194 | sleep(HZ/50); /* Allow the button driver to check the buttons */ |
144 | 195 | ||
145 | if(button_status() & BUTTON_REC || | 196 | if(button_status() & BUTTON_REC || rc_on_button) { |
146 | (button_status() & BUTTON_RC_ON) == BUTTON_RC_ON) { | ||
147 | lcd_puts(0, 8, "Starting original firmware..."); | 197 | lcd_puts(0, 8, "Starting original firmware..."); |
148 | lcd_update(); | 198 | lcd_update(); |
149 | start_iriver_fw(); | 199 | start_iriver_fw(); |
150 | } | 200 | } |
151 | 201 | ||
152 | if((button_status() & BUTTON_ON) & button_hold()) { | 202 | if(on_button & button_hold()) { |
153 | lcd_puts(0, 8, "HOLD switch on, power off..."); | 203 | lcd_puts(0, 8, "HOLD switch on, power off..."); |
154 | lcd_update(); | 204 | lcd_update(); |
155 | sleep(HZ/2); | 205 | sleep(HZ*2); |
156 | /* Reset the cookie for the crt0 crash check */ | 206 | /* Reset the cookie for the crt0 crash check */ |
157 | asm(" move.l #0,%d0"); | 207 | asm(" move.l #0,%d0"); |
158 | asm(" move.l %d0,0x10017ffc"); | 208 | asm(" move.l %d0,0x10017ffc"); |
@@ -166,7 +216,7 @@ void main(void) | |||
166 | power_off(); | 216 | power_off(); |
167 | } | 217 | } |
168 | #endif | 218 | #endif |
169 | 219 | ||
170 | rc = ata_init(); | 220 | rc = ata_init(); |
171 | if(rc) | 221 | if(rc) |
172 | { | 222 | { |
@@ -175,21 +225,38 @@ void main(void) | |||
175 | lcd_clear_display(); | 225 | lcd_clear_display(); |
176 | snprintf(str, 31, "ATA error: %d", rc); | 226 | snprintf(str, 31, "ATA error: %d", rc); |
177 | lcd_puts(0, 1, str); | 227 | lcd_puts(0, 1, str); |
178 | lcd_puts(0, 3, "Press ON to debug"); | ||
179 | lcd_update(); | 228 | lcd_update(); |
180 | while(!(button_get(true) & BUTTON_REL)); | 229 | while(!(button_get(true) & BUTTON_REL)); |
181 | #endif | 230 | #endif |
182 | panicf("ata: %d", rc); | 231 | panicf("ata: %d", rc); |
183 | } | 232 | } |
184 | 233 | ||
234 | /* A hack to enter USB mode without using the USB thread */ | ||
235 | if(usb_detect()) | ||
236 | { | ||
237 | lcd_clear_display(); | ||
238 | lcd_puts(0, 7, " Bootloader USB mode"); | ||
239 | lcd_update(); | ||
240 | |||
241 | ata_spin(); | ||
242 | ata_enable(false); | ||
243 | usb_enable(true); | ||
244 | while(usb_detect()) | ||
245 | { | ||
246 | ata_spin(); /* Prevent the drive from spinning down */ | ||
247 | sleep(HZ); | ||
248 | } | ||
249 | |||
250 | system_reboot(); | ||
251 | } | ||
252 | |||
185 | disk_init(); | 253 | disk_init(); |
186 | 254 | ||
187 | rc = disk_mount_all(); | 255 | rc = disk_mount_all(); |
188 | if (rc<=0) | 256 | if (rc<=0) |
189 | { | 257 | { |
190 | lcd_clear_display(); | 258 | lcd_clear_display(); |
191 | lcd_puts(0, 0, "No partition"); | 259 | lcd_puts(0, 0, "No partition found"); |
192 | lcd_puts(0, 1, "found."); | ||
193 | while(button_get(true) != SYS_USB_CONNECTED) {}; | 260 | while(button_get(true) != SYS_USB_CONNECTED) {}; |
194 | } | 261 | } |
195 | 262 | ||