Change the function name in strnatsort so that the code doesn't contradict itself
[kugel-rb/myfork.git] / bootloader / ondavx747.c
blob0d3e592c6d95f0e6a2b0d3d9589f7ca4f9609ebc
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Maurus Cuelenaere
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include "jz4740.h"
24 #include "backlight.h"
25 #include "font.h"
26 #include "lcd.h"
27 #include "usb.h"
28 #include "system.h"
29 #include "button.h"
30 #include "common.h"
31 #include "storage.h"
32 #include "disk.h"
33 #include "string.h"
34 #include "adc.h"
36 extern int show_logo(void);
38 static void show_splash(int timeout, const char *msg)
40 reset_screen();
41 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
42 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
43 lcd_update();
45 sleep(timeout);
48 static void usb_mode(void)
50 int button;
52 /* Init USB */
53 usb_init();
54 usb_start_monitoring();
56 /* Wait for threads to connect */
57 show_splash(HZ/2, "Waiting for USB");
59 while (1)
61 button = button_get_w_tmo(HZ/2);
63 if (button == SYS_USB_CONNECTED)
64 break; /* Hit */
67 if (button == SYS_USB_CONNECTED)
69 /* Got the message - wait for disconnect */
70 show_splash(0, "Bootloader USB mode");
72 usb_acknowledge(SYS_USB_CONNECTED_ACK);
74 while (1)
76 button = button_get(true);
77 if (button == SYS_USB_DISCONNECTED)
79 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
80 break;
85 reset_screen();
88 static int boot_of(void)
90 int fd, rc, len, i, checksum = 0;
91 void (*kernel_entry)(int, void*, void*);
93 /* TODO: get this from the NAND flash instead of SD */
94 fd = open("/ccpmp.bin", O_RDONLY);
95 if(fd < 0)
96 return EFILE_NOT_FOUND;
98 lseek(fd, 4, SEEK_SET);
99 rc = read(fd, (char*)&len, 4); /* CPU is LE */
100 if(rc < 4)
101 return EREAD_IMAGE_FAILED;
103 len += 8;
104 printf("Reading %d bytes...", len);
106 lseek(fd, 0, SEEK_SET);
107 rc = read(fd, (void*)0x80004000, len);
108 if(rc < len)
109 return EREAD_IMAGE_FAILED;
111 close(fd);
113 for(i=0; i<len; i++)
114 checksum += ((unsigned char*)0x80004000)[i];
116 *((unsigned int*)0x80004000) = checksum;
118 printf("Starting the OF...");
120 /* OF requires all clocks on */
121 __cpm_start_all();
123 disable_interrupt();
124 __dcache_writeback_all();
125 __icache_invalidate_all();
127 for(i=8000; i>0; i--)
128 asm volatile("nop\n");
130 kernel_entry = (void*) 0x80004008;
131 kernel_entry(0, "Jan 10 2008", "15:34:42"); /* Reversed from the SPL */
133 return 0;
136 int main(void)
138 int rc;
139 #ifdef HAVE_TOUCHSCREEN
140 int dummy;
141 #endif
142 void (*kernel_entry)(void);
144 kernel_init();
145 lcd_init();
146 font_init();
147 lcd_setfont(FONT_SYSFIXED);
148 button_init();
149 backlight_init();
151 show_logo();
153 rc = storage_init();
154 if(rc)
155 error(EATA, rc);
157 #ifdef HAVE_TOUCHSCREEN
158 rc = button_read_device(&dummy);
159 #else
160 rc = button_read_device();
161 #endif
163 if(rc)
164 verbose = true;
166 if(rc & BUTTON_VOL_UP)
167 usb_mode();
169 if(verbose)
170 reset_screen();
171 printf(MODEL_NAME" Rockbox Bootloader");
172 printf("Version "APPSVERSION);
174 rc = disk_mount_all();
175 if (rc <= 0)
176 error(EDISK,rc);
178 if(button_hold())
180 rc = boot_of();
181 if(rc < 0)
182 printf("Error: %s", strerror(rc));
185 printf("Loading firmware");
186 rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000);
187 if(rc < 0)
188 printf("Error: %s", strerror(rc));
190 if (rc == EOK)
192 printf("Starting Rockbox...");
193 adc_close(); /* Disable SADC */
195 disable_interrupt();
196 kernel_entry = (void*) CONFIG_SDRAM_START;
197 kernel_entry();
200 /* Halt */
201 while (1)
202 core_idle();
204 return 0;