blob: c69a6da42c3e24b83d07a2ef26f46a6ce8610aa5 [file] [log] [blame]
Dave Chapman28f6ae42007-10-28 11:08:10 +00001/***************************************************************************
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 Stenberg2acc0ac2008-06-28 18:10:04 +000014 * 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 Chapman28f6ae42007-10-28 11:08:10 +000018 *
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 Sevakis4ea4cdf2014-08-08 02:28:11 -040031#include "../kernel-internal.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000032#include "storage.h"
Michael Sevakis7d1a47c2013-08-05 22:02:45 -040033#include "file_internal.h"
Dave Chapman28f6ae42007-10-28 11:08:10 +000034#include "disk.h"
35#include "font.h"
Dave Chapmana4d48d02007-11-01 23:38:57 +000036#include "button.h"
Dave Chapman28f6ae42007-10-28 11:08:10 +000037#include "adc.h"
38#include "adc-target.h"
Rob Purchase3b466712008-03-29 17:26:16 +000039#include "backlight.h"
Dave Chapman28f6ae42007-10-28 11:08:10 +000040#include "backlight-target.h"
41#include "panic.h"
42#include "power.h"
43#include "file.h"
44#include "common.h"
Marcin Bukat0b296912012-03-04 15:34:29 +010045#include "rb-loader.h"
46#include "loader_strerror.h"
Rafaël Carré5d236b22010-05-27 09:41:46 +000047#include "version.h"
Dave Chapman28f6ae42007-10-28 11:08:10 +000048
Rob Purchase9f0fbec2008-11-17 21:16:00 +000049/* Show the Rockbox logo - in show_logo.c */
Bertrik Sikken7e3a3f42011-09-08 18:31:15 +000050extern void show_logo(void);
Dave Chapmand462a642008-09-06 17:50:59 +000051
Dave Chapman85807cd2008-09-22 19:15:18 +000052/* Address to load main Rockbox image to */
53#define LOAD_ADDRESS 0x20000000 /* DRAM_START */
Rob Purchase47ea0302008-01-14 22:04:48 +000054
Dave Chapman28f6ae42007-10-28 11:08:10 +000055extern int line;
56
Rob Purchasec8836112008-03-12 20:57:19 +000057#define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */
58
Dave Chapmanf2042982008-05-02 19:12:09 +000059/* The following function is just test/development code */
Dave Chapmanf2042982008-05-02 19:12:09 +000060void show_debug_screen(void)
61{
62 int button;
63 int power_count = 0;
64 int count = 0;
65 bool do_power_off = false;
Rob Purchasef62388f2009-06-24 07:37:11 +000066
67 lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---");
Dave Chapman85807cd2008-09-22 19:15:18 +000068 while (!do_power_off) {
Dave Chapmanf2042982008-05-02 19:12:09 +000069 line = 1;
70 button = button_get(false);
Rob Purchasef62388f2009-06-24 07:37:11 +000071
Dave Chapman85807cd2008-09-22 19:15:18 +000072 /* Power-off if POWER button has been held for a time
Dave Chapmanf2042982008-05-02 19:12:09 +000073 This loop is currently running at about 100 iterations/second
74 */
75 if (button & POWEROFF_BUTTON) {
76 power_count++;
Marc Guayf6cde722008-07-06 21:32:59 +000077 if (power_count > 100)
Dave Chapmanf2042982008-05-02 19:12:09 +000078 do_power_off = true;
79 } else {
80 power_count = 0;
81 }
Dave Chapman85807cd2008-09-22 19:15:18 +000082#if 0
Marc Guayb93667b2008-06-21 15:18:36 +000083 if (button & BUTTON_SELECT){
Marcin Bukat89ba7e82015-01-09 00:22:40 +010084 backlight_hw_off();
Marc Guayb93667b2008-06-21 15:18:36 +000085 }
86 else{
Marcin Bukat89ba7e82015-01-09 00:22:40 +010087 backlight_hw_on();
Marc Guayb93667b2008-06-21 15:18:36 +000088 }
Dave Chapmand462a642008-09-06 17:50:59 +000089#endif
Dave Chapman85807cd2008-09-22 19:15:18 +000090 printf("Btn: 0x%08x",button);
91#if 0
Dave Chapmanf2042982008-05-02 19:12:09 +000092 printf("Tick: %d",current_tick);
Dave Chapmanf2042982008-05-02 19:12:09 +000093 printf("GPIOA: 0x%08x",GPIOA);
94 printf("GPIOB: 0x%08x",GPIOB);
95 printf("GPIOC: 0x%08x",GPIOC);
96 printf("GPIOD: 0x%08x",GPIOD);
Dave Chapman85807cd2008-09-22 19:15:18 +000097 printf("GPIOE: 0x%08x",GPIOE);
98#endif
Dave Chapmanf2042982008-05-02 19:12:09 +000099
100#if 0
101 int i;
Dave Chapman85807cd2008-09-22 19:15:18 +0000102 for (i = 0; i<4; i++)
Dave Chapmanf2042982008-05-02 19:12:09 +0000103 {
104 printf("ADC%d: 0x%04x",i,adc_read(i));
105 }
106#endif
107 count++;
108 printf("Count: %d",count);
Rob Purchasef62388f2009-06-24 07:37:11 +0000109 lcd_update();
Dave Chapmanf2042982008-05-02 19:12:09 +0000110 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 Chapman85807cd2008-09-22 19:15:18 +0000124
Rob Purchase3b466712008-03-29 17:26:16 +0000125void* main(void)
126{
Dave Chapman85807cd2008-09-22 19:15:18 +0000127#ifdef TCCBOOT
Rob Purchasec8836112008-03-12 20:57:19 +0000128 int rc;
129 unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS;
Rob Purchaseaddb5222008-02-13 23:50:44 +0000130#endif
Dave Chapman28f6ae42007-10-28 11:08:10 +0000131
Rob Purchaseaddb5222008-02-13 23:50:44 +0000132 system_init();
Dave Chapmand462a642008-09-06 17:50:59 +0000133 power_init();
Rob Purchasef62388f2009-06-24 07:37:11 +0000134
Dave Chapmanf2042982008-05-02 19:12:09 +0000135 kernel_init();
136 enable_irq();
Rob Purchasef62388f2009-06-24 07:37:11 +0000137
Rob Purchase562b9de2008-03-05 00:21:56 +0000138 lcd_init();
Rob Purchaseaddb5222008-02-13 23:50:44 +0000139
140 adc_init();
141 button_init();
142 backlight_init();
143
Dave Chapman28f6ae42007-10-28 11:08:10 +0000144 font_init();
Rob Purchaseaddb5222008-02-13 23:50:44 +0000145 lcd_setfont(FONT_SYSFIXED);
Rob Purchase9f0fbec2008-11-17 21:16:00 +0000146
147 show_logo();
Rob Purchaseaddb5222008-02-13 23:50:44 +0000148
Marcin Bukat89ba7e82015-01-09 00:22:40 +0100149 backlight_hw_on();
Dave Chapman28f6ae42007-10-28 11:08:10 +0000150
Rob Purchasec8836112008-03-12 20:57:19 +0000151/* 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 Chapman85807cd2008-09-22 19:15:18 +0000153#ifdef TCCBOOT
Rob Purchasec8836112008-03-12 20:57:19 +0000154 printf("Rockbox boot loader");
Michael Sevakis95a4c3a2014-08-28 10:26:45 -0400155 printf("Version %s", rbversion);
Rob Purchasec8836112008-03-12 20:57:19 +0000156
Rob Purchaseaddb5222008-02-13 23:50:44 +0000157 printf("ATA");
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000158 rc = storage_init();
Rob Purchaseaddb5222008-02-13 23:50:44 +0000159 if(rc)
160 {
161 reset_screen();
Rafaël Carré1ec82122010-06-23 05:08:36 +0000162 error(EATA, rc, true);
Rob Purchaseaddb5222008-02-13 23:50:44 +0000163 }
164
Michael Sevakis7d1a47c2013-08-05 22:02:45 -0400165 filesystem_init();
166
Rob Purchaseaddb5222008-02-13 23:50:44 +0000167 printf("mount");
168 rc = disk_mount_all();
169 if (rc<=0)
170 {
Rafaël Carré1ec82122010-06-23 05:08:36 +0000171 error(EDISK,rc, true);
Rob Purchaseaddb5222008-02-13 23:50:44 +0000172 }
173
Rob Purchasec8836112008-03-12 20:57:19 +0000174 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
Rob Purchaseaddb5222008-02-13 23:50:44 +0000175
Marcin Bukat0b296912012-03-04 15:34:29 +0100176 if (rc <= EFILE_EMPTY)
Rob Purchaseaddb5222008-02-13 23:50:44 +0000177 {
Rafaël Carré1ec82122010-06-23 05:08:36 +0000178 error(EBOOTFILE,rc, true);
Rob Purchaseaddb5222008-02-13 23:50:44 +0000179 }
Marcin Bukat0b296912012-03-04 15:34:29 +0100180 else
Rob Purchaseaddb5222008-02-13 23:50:44 +0000181 {
Vitja Makarov0152fe62009-09-21 08:38:52 +0000182 int(*kernel_entry)(void) = (void *) loadbuffer;
Rob Purchasec8836112008-03-12 20:57:19 +0000183
Vitja Makarov0152fe62009-09-21 08:38:52 +0000184 disable_irq();
Rob Purchase18b004b2008-04-27 13:30:11 +0000185 rc = kernel_entry();
Dave Chapman28f6ae42007-10-28 11:08:10 +0000186 }
Vitja Makarov0152fe62009-09-21 08:38:52 +0000187
188 panicf("Boot failed!");
Rob Purchase18b004b2008-04-27 13:30:11 +0000189#else
Rob Purchase3b466712008-03-29 17:26:16 +0000190 show_debug_screen();
Rob Purchase18b004b2008-04-27 13:30:11 +0000191#endif
Rob Purchasec8836112008-03-12 20:57:19 +0000192
Dave Chapman28f6ae42007-10-28 11:08:10 +0000193 return 0;
194}