Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 by Dave Chapman |
| 11 | * |
| 12 | * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing |
| 13 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; either version 2 |
| 17 | * of the License, or (at your option) any later version. |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 18 | * |
| 19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 20 | * KIND, either express or implied. |
| 21 | * |
| 22 | ****************************************************************************/ |
| 23 | #include "config.h" |
| 24 | |
| 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include <string.h> |
| 28 | #include "cpu.h" |
| 29 | #include "system.h" |
| 30 | #include "lcd.h" |
| 31 | #include "kernel.h" |
| 32 | #include "thread.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 33 | #include "storage.h" |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 34 | #include "fat.h" |
| 35 | #include "disk.h" |
| 36 | #include "font.h" |
Dave Chapman | a4d48d0 | 2007-11-01 23:38:57 +0000 | [diff] [blame] | 37 | #include "button.h" |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 38 | #include "adc.h" |
| 39 | #include "adc-target.h" |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 40 | #include "backlight.h" |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 41 | #include "backlight-target.h" |
| 42 | #include "panic.h" |
| 43 | #include "power.h" |
| 44 | #include "file.h" |
| 45 | #include "common.h" |
| 46 | |
Rob Purchase | 9f0fbec | 2008-11-17 21:16:00 +0000 | [diff] [blame] | 47 | /* Show the Rockbox logo - in show_logo.c */ |
| 48 | extern int show_logo(void); |
Dave Chapman | d462a64 | 2008-09-06 17:50:59 +0000 | [diff] [blame] | 49 | |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 50 | /* Address to load main Rockbox image to */ |
| 51 | #define LOAD_ADDRESS 0x20000000 /* DRAM_START */ |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 52 | |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 53 | char version[] = APPSVERSION; |
| 54 | |
| 55 | extern int line; |
| 56 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 57 | #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */ |
| 58 | |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 59 | /* The following function is just test/development code */ |
| 60 | #ifdef CPU_TCC77X |
| 61 | void show_debug_screen(void) |
| 62 | { |
| 63 | int button; |
| 64 | int power_count = 0; |
| 65 | int count = 0; |
| 66 | bool do_power_off = false; |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 67 | |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 68 | lcd_puts_scroll(0,0,"this is a very long line to test scrolling"); |
| 69 | while (!do_power_off) { |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 70 | line = 1; |
| 71 | button = button_get(false); |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 72 | |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 73 | /* Power-off if POWER button has been held for a time |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 74 | This loop is currently running at about 100 iterations/second |
| 75 | */ |
| 76 | if (button & POWEROFF_BUTTON) { |
| 77 | power_count++; |
Marc Guay | f6cde72 | 2008-07-06 21:32:59 +0000 | [diff] [blame] | 78 | if (power_count > 100) |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 79 | do_power_off = true; |
| 80 | } else { |
| 81 | power_count = 0; |
| 82 | } |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 83 | #if 0 |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 84 | if (button & BUTTON_SELECT){ |
Dave Chapman | d462a64 | 2008-09-06 17:50:59 +0000 | [diff] [blame] | 85 | _backlight_off(); |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 86 | } |
| 87 | else{ |
| 88 | _backlight_on(); |
| 89 | } |
Dave Chapman | d462a64 | 2008-09-06 17:50:59 +0000 | [diff] [blame] | 90 | #endif |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 91 | printf("Btn: 0x%08x",button); |
| 92 | #if 0 |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 93 | printf("Tick: %d",current_tick); |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 94 | printf("GPIOA: 0x%08x",GPIOA); |
| 95 | printf("GPIOB: 0x%08x",GPIOB); |
| 96 | printf("GPIOC: 0x%08x",GPIOC); |
| 97 | printf("GPIOD: 0x%08x",GPIOD); |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 98 | printf("GPIOE: 0x%08x",GPIOE); |
| 99 | #endif |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 100 | |
| 101 | #if 0 |
| 102 | int i; |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 103 | for (i = 0; i<4; i++) |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 104 | { |
| 105 | printf("ADC%d: 0x%04x",i,adc_read(i)); |
| 106 | } |
| 107 | #endif |
| 108 | count++; |
| 109 | printf("Count: %d",count); |
| 110 | sleep(HZ/10); |
| 111 | |
| 112 | } |
| 113 | |
| 114 | lcd_clear_display(); |
| 115 | line = 0; |
| 116 | printf("POWER-OFF"); |
| 117 | |
| 118 | /* Power-off */ |
| 119 | power_off(); |
| 120 | |
| 121 | printf("(NOT) POWERED OFF"); |
| 122 | while (true); |
| 123 | } |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 124 | |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 125 | #else /* !CPU_TCC77X */ |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 126 | |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 127 | void show_debug_screen(void) |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 128 | { |
Dave Chapman | a4d48d0 | 2007-11-01 23:38:57 +0000 | [diff] [blame] | 129 | int button; |
| 130 | int power_count = 0; |
| 131 | int count = 0; |
| 132 | bool do_power_off = false; |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 133 | #ifdef HAVE_BUTTON_DATA |
| 134 | unsigned int data; |
| 135 | #endif |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 136 | |
| 137 | while(!do_power_off) { |
| 138 | line = 0; |
| 139 | printf("Hello World!"); |
| 140 | |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 141 | #ifdef HAVE_BUTTON_DATA |
| 142 | button = button_read_device(&data); |
| 143 | #else |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 144 | button = button_read_device(); |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 145 | #endif |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 146 | |
| 147 | /* Power-off if POWER button has been held for a long time |
| 148 | This loop is currently running at about 100 iterations/second |
| 149 | */ |
| 150 | if (button & POWEROFF_BUTTON) { |
| 151 | power_count++; |
| 152 | if (power_count > 200) |
| 153 | do_power_off = true; |
| 154 | } else { |
| 155 | power_count = 0; |
| 156 | } |
| 157 | |
| 158 | printf("Btn: 0x%08x",button); |
| 159 | |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 160 | count++; |
| 161 | printf("Count: %d",count); |
| 162 | } |
| 163 | |
| 164 | lcd_clear_display(); |
| 165 | line = 0; |
| 166 | printf("POWER-OFF"); |
| 167 | |
| 168 | /* Power-off */ |
| 169 | power_off(); |
| 170 | |
| 171 | printf("(NOT) POWERED OFF"); |
| 172 | while (true); |
| 173 | } |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 174 | #endif |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 175 | |
| 176 | void* main(void) |
| 177 | { |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 178 | #ifdef TCCBOOT |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 179 | int rc; |
| 180 | unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS; |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 181 | #endif |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 182 | |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 183 | system_init(); |
Dave Chapman | d462a64 | 2008-09-06 17:50:59 +0000 | [diff] [blame] | 184 | power_init(); |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 185 | #ifndef COWON_D2 |
| 186 | /* The D2 doesn't enable threading or interrupts */ |
| 187 | kernel_init(); |
| 188 | enable_irq(); |
| 189 | #endif |
Rob Purchase | 562b9de | 2008-03-05 00:21:56 +0000 | [diff] [blame] | 190 | lcd_init(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 191 | |
| 192 | adc_init(); |
| 193 | button_init(); |
| 194 | backlight_init(); |
| 195 | |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 196 | font_init(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 197 | lcd_setfont(FONT_SYSFIXED); |
Rob Purchase | 9f0fbec | 2008-11-17 21:16:00 +0000 | [diff] [blame] | 198 | |
| 199 | show_logo(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 200 | |
Jens Arnold | ef12b3b | 2007-11-12 18:49:53 +0000 | [diff] [blame] | 201 | _backlight_on(); |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 202 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 203 | /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is |
| 204 | available for loading the firmware. Otherwise display the debug screen. */ |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 205 | #ifdef TCCBOOT |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 206 | printf("Rockbox boot loader"); |
| 207 | printf("Version %s", version); |
| 208 | |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 209 | printf("ATA"); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 210 | rc = storage_init(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 211 | if(rc) |
| 212 | { |
| 213 | reset_screen(); |
| 214 | error(EATA, rc); |
| 215 | } |
| 216 | |
| 217 | printf("mount"); |
| 218 | rc = disk_mount_all(); |
| 219 | if (rc<=0) |
| 220 | { |
| 221 | error(EDISK,rc); |
| 222 | } |
| 223 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 224 | rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 225 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 226 | if (rc < 0) |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 227 | { |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 228 | error(EBOOTFILE,rc); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 229 | } |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 230 | else if (rc == EOK) |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 231 | { |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 232 | int(*kernel_entry)(void); |
| 233 | |
| 234 | kernel_entry = (void*) loadbuffer; |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 235 | rc = kernel_entry(); |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 236 | } |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 237 | #else |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 238 | show_debug_screen(); |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 239 | #endif |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 240 | |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 241 | return 0; |
| 242 | } |