Move error message generation out of irivertools.cpp to make it independent from...
[Rockbox.git] / bootloader / telechips.c
blob7563a186326526945b49baa29993273fe7ea16da
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Dave Chapman
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include "cpu.h"
27 #include "system.h"
28 #include "lcd.h"
29 #include "kernel.h"
30 #include "thread.h"
31 #include "ata.h"
32 #include "fat.h"
33 #include "disk.h"
34 #include "font.h"
35 #include "button.h"
36 #include "adc.h"
37 #include "adc-target.h"
38 #include "backlight.h"
39 #include "backlight-target.h"
40 #include "panic.h"
41 #include "power.h"
42 #include "file.h"
43 #include "common.h"
45 #if defined(COWON_D2)
46 #include "pcf50606.h"
47 #define LOAD_ADDRESS 0x20000000 /* DRAM_START */
48 #endif
50 char version[] = APPSVERSION;
52 extern int line;
54 #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */
56 /* The following function is just test/development code */
57 #ifdef CPU_TCC77X
58 void show_debug_screen(void)
60 int button;
61 int power_count = 0;
62 int count = 0;
63 bool do_power_off = false;
65 lcd_puts_scroll(0,0,"this is a very long line to test scrolling");
66 while(!do_power_off) {
67 line = 1;
68 button = button_get(false);
70 /* Power-off if POWER button has been held for a long time
71 This loop is currently running at about 100 iterations/second
73 if (button & POWEROFF_BUTTON) {
74 power_count++;
75 if (power_count > 200)
76 do_power_off = true;
77 } else {
78 power_count = 0;
81 printf("Btn: 0x%08x",button);
82 printf("Tick: %d",current_tick);
84 printf("GPIOA: 0x%08x",GPIOA);
85 printf("GPIOB: 0x%08x",GPIOB);
86 printf("GPIOC: 0x%08x",GPIOC);
87 printf("GPIOD: 0x%08x",GPIOD);
88 // printf("GPIOE: 0x%08x",GPIOE);
90 #if 0
91 int i;
92 for (i = 0; i<4; i++)
94 printf("ADC%d: 0x%04x",i,adc_read(i));
96 #endif
97 count++;
98 printf("Count: %d",count);
99 sleep(HZ/10);
103 lcd_clear_display();
104 line = 0;
105 printf("POWER-OFF");
107 /* Power-off */
108 power_off();
110 printf("(NOT) POWERED OFF");
111 while (true);
113 #else /* !CPU_TCC77X */
114 void show_debug_screen(void)
116 int button;
117 int power_count = 0;
118 int count = 0;
119 bool do_power_off = false;
120 #ifdef HAVE_BUTTON_DATA
121 unsigned int data;
122 #endif
124 while(!do_power_off) {
125 line = 0;
126 printf("Hello World!");
128 #ifdef HAVE_BUTTON_DATA
129 button = button_read_device(&data);
130 #else
131 button = button_read_device();
132 #endif
134 /* Power-off if POWER button has been held for a long time
135 This loop is currently running at about 100 iterations/second
137 if (button & POWEROFF_BUTTON) {
138 power_count++;
139 if (power_count > 200)
140 do_power_off = true;
141 } else {
142 power_count = 0;
145 printf("Btn: 0x%08x",button);
147 count++;
148 printf("Count: %d",count);
151 lcd_clear_display();
152 line = 0;
153 printf("POWER-OFF");
155 /* Power-off */
156 power_off();
158 printf("(NOT) POWERED OFF");
159 while (true);
161 #endif
163 void* main(void)
165 #if defined(COWON_D2) && defined(TCCBOOT)
166 int rc;
167 unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS;
168 #endif
170 power_init();
171 system_init();
172 #ifndef COWON_D2
173 /* The D2 doesn't enable threading or interrupts */
174 kernel_init();
175 enable_irq();
176 #endif
177 lcd_init();
179 adc_init();
180 button_init();
181 backlight_init();
183 font_init();
184 lcd_setfont(FONT_SYSFIXED);
186 _backlight_on();
188 /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is
189 available for loading the firmware. Otherwise display the debug screen. */
190 #if defined(COWON_D2) && defined(TCCBOOT)
191 printf("Rockbox boot loader");
192 printf("Version %s", version);
194 printf("ATA");
195 rc = ata_init();
196 if(rc)
198 reset_screen();
199 error(EATA, rc);
202 printf("mount");
203 rc = disk_mount_all();
204 if (rc<=0)
206 error(EDISK,rc);
209 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
211 if (rc < 0)
213 error(EBOOTFILE,rc);
215 else if (rc == EOK)
217 int(*kernel_entry)(void);
219 kernel_entry = (void*) loadbuffer;
220 rc = kernel_entry();
222 #else
223 show_debug_screen();
224 #endif
226 return 0;
229 /* These functions are present in the firmware library, but we reimplement
230 them here because the originals do a lot more than we want */
231 void usb_acknowledge(void)
235 void usb_wait_for_disconnect(void)