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" |
Michael Sevakis | 4ea4cdf | 2014-08-08 02:28:11 -0400 | [diff] [blame] | 31 | #include "../kernel-internal.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 32 | #include "storage.h" |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 33 | #include "file_internal.h" |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 34 | #include "disk.h" |
| 35 | #include "font.h" |
Dave Chapman | a4d48d0 | 2007-11-01 23:38:57 +0000 | [diff] [blame] | 36 | #include "button.h" |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 37 | #include "adc.h" |
| 38 | #include "adc-target.h" |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 39 | #include "backlight.h" |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 40 | #include "backlight-target.h" |
| 41 | #include "panic.h" |
| 42 | #include "power.h" |
| 43 | #include "file.h" |
| 44 | #include "common.h" |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 45 | #include "rb-loader.h" |
| 46 | #include "loader_strerror.h" |
Rafaël Carré | 5d236b2 | 2010-05-27 09:41:46 +0000 | [diff] [blame] | 47 | #include "version.h" |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 48 | |
Rob Purchase | 9f0fbec | 2008-11-17 21:16:00 +0000 | [diff] [blame] | 49 | /* Show the Rockbox logo - in show_logo.c */ |
Bertrik Sikken | 7e3a3f4 | 2011-09-08 18:31:15 +0000 | [diff] [blame] | 50 | extern void show_logo(void); |
Dave Chapman | d462a64 | 2008-09-06 17:50:59 +0000 | [diff] [blame] | 51 | |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 52 | /* Address to load main Rockbox image to */ |
| 53 | #define LOAD_ADDRESS 0x20000000 /* DRAM_START */ |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 54 | |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 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 */ |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 60 | void show_debug_screen(void) |
| 61 | { |
| 62 | int button; |
| 63 | int power_count = 0; |
| 64 | int count = 0; |
| 65 | bool do_power_off = false; |
Rob Purchase | f62388f | 2009-06-24 07:37:11 +0000 | [diff] [blame] | 66 | |
| 67 | lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---"); |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 68 | while (!do_power_off) { |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 69 | line = 1; |
| 70 | button = button_get(false); |
Rob Purchase | f62388f | 2009-06-24 07:37:11 +0000 | [diff] [blame] | 71 | |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 72 | /* Power-off if POWER button has been held for a time |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 73 | This loop is currently running at about 100 iterations/second |
| 74 | */ |
| 75 | if (button & POWEROFF_BUTTON) { |
| 76 | power_count++; |
Marc Guay | f6cde72 | 2008-07-06 21:32:59 +0000 | [diff] [blame] | 77 | if (power_count > 100) |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 78 | do_power_off = true; |
| 79 | } else { |
| 80 | power_count = 0; |
| 81 | } |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 82 | #if 0 |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 83 | if (button & BUTTON_SELECT){ |
Marcin Bukat | 89ba7e8 | 2015-01-09 00:22:40 +0100 | [diff] [blame] | 84 | backlight_hw_off(); |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 85 | } |
| 86 | else{ |
Marcin Bukat | 89ba7e8 | 2015-01-09 00:22:40 +0100 | [diff] [blame] | 87 | backlight_hw_on(); |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 88 | } |
Dave Chapman | d462a64 | 2008-09-06 17:50:59 +0000 | [diff] [blame] | 89 | #endif |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 90 | printf("Btn: 0x%08x",button); |
| 91 | #if 0 |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 92 | printf("Tick: %d",current_tick); |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 93 | printf("GPIOA: 0x%08x",GPIOA); |
| 94 | printf("GPIOB: 0x%08x",GPIOB); |
| 95 | printf("GPIOC: 0x%08x",GPIOC); |
| 96 | printf("GPIOD: 0x%08x",GPIOD); |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 97 | printf("GPIOE: 0x%08x",GPIOE); |
| 98 | #endif |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 99 | |
| 100 | #if 0 |
| 101 | int i; |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 102 | for (i = 0; i<4; i++) |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 103 | { |
| 104 | printf("ADC%d: 0x%04x",i,adc_read(i)); |
| 105 | } |
| 106 | #endif |
| 107 | count++; |
| 108 | printf("Count: %d",count); |
Rob Purchase | f62388f | 2009-06-24 07:37:11 +0000 | [diff] [blame] | 109 | lcd_update(); |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 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 | |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 125 | void* main(void) |
| 126 | { |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 127 | #ifdef TCCBOOT |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 128 | int rc; |
| 129 | unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS; |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 130 | #endif |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 131 | |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 132 | system_init(); |
Dave Chapman | d462a64 | 2008-09-06 17:50:59 +0000 | [diff] [blame] | 133 | power_init(); |
Rob Purchase | f62388f | 2009-06-24 07:37:11 +0000 | [diff] [blame] | 134 | |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 135 | kernel_init(); |
| 136 | enable_irq(); |
Rob Purchase | f62388f | 2009-06-24 07:37:11 +0000 | [diff] [blame] | 137 | |
Rob Purchase | 562b9de | 2008-03-05 00:21:56 +0000 | [diff] [blame] | 138 | lcd_init(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 139 | |
| 140 | adc_init(); |
| 141 | button_init(); |
| 142 | backlight_init(); |
| 143 | |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 144 | font_init(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 145 | lcd_setfont(FONT_SYSFIXED); |
Rob Purchase | 9f0fbec | 2008-11-17 21:16:00 +0000 | [diff] [blame] | 146 | |
| 147 | show_logo(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 148 | |
Marcin Bukat | 89ba7e8 | 2015-01-09 00:22:40 +0100 | [diff] [blame] | 149 | backlight_hw_on(); |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 150 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 151 | /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is |
| 152 | available for loading the firmware. Otherwise display the debug screen. */ |
Dave Chapman | 85807cd | 2008-09-22 19:15:18 +0000 | [diff] [blame] | 153 | #ifdef TCCBOOT |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 154 | printf("Rockbox boot loader"); |
Michael Sevakis | 95a4c3a | 2014-08-28 10:26:45 -0400 | [diff] [blame] | 155 | printf("Version %s", rbversion); |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 156 | |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 157 | printf("ATA"); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 158 | rc = storage_init(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 159 | if(rc) |
| 160 | { |
| 161 | reset_screen(); |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 162 | error(EATA, rc, true); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 165 | filesystem_init(); |
| 166 | |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 167 | printf("mount"); |
| 168 | rc = disk_mount_all(); |
| 169 | if (rc<=0) |
| 170 | { |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 171 | error(EDISK,rc, true); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 174 | rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 175 | |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 176 | if (rc <= EFILE_EMPTY) |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 177 | { |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 178 | error(EBOOTFILE,rc, true); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 179 | } |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 180 | else |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 181 | { |
Vitja Makarov | 0152fe6 | 2009-09-21 08:38:52 +0000 | [diff] [blame] | 182 | int(*kernel_entry)(void) = (void *) loadbuffer; |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 183 | |
Vitja Makarov | 0152fe6 | 2009-09-21 08:38:52 +0000 | [diff] [blame] | 184 | disable_irq(); |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 185 | rc = kernel_entry(); |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 186 | } |
Vitja Makarov | 0152fe6 | 2009-09-21 08:38:52 +0000 | [diff] [blame] | 187 | |
| 188 | panicf("Boot failed!"); |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 189 | #else |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 190 | show_debug_screen(); |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 191 | #endif |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 192 | |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 193 | return 0; |
| 194 | } |