summaryrefslogtreecommitdiff
path: root/bootloader/xduoox3.c
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader/xduoox3.c')
-rw-r--r--bootloader/xduoox3.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/bootloader/xduoox3.c b/bootloader/xduoox3.c
new file mode 100644
index 0000000000..3db87a866d
--- /dev/null
+++ b/bootloader/xduoox3.c
@@ -0,0 +1,184 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 by Roman Stolyarov
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "jz4760b.h"
24#include "../kernel-internal.h"
25#include "backlight.h"
26#include "font.h"
27#include "lcd.h"
28#include "file.h"
29#include "usb.h"
30#include "system.h"
31#include "button.h"
32#include "common.h"
33#include "rb-loader.h"
34#include "loader_strerror.h"
35#include "storage.h"
36#include "file_internal.h"
37#include "disk.h"
38#include "string.h"
39#include "adc.h"
40#include "version.h"
41
42#include "xdebug.h"
43
44extern void show_logo(void);
45extern void power_off(void);
46
47static void show_splash(int timeout, const char *msg)
48{
49 reset_screen();
50 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
51 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
52 lcd_update();
53
54 sleep(timeout);
55}
56
57static void usb_mode(void)
58{
59 int button;
60
61 /* Init USB */
62 usb_init();
63 usb_start_monitoring();
64
65 /* Wait for threads to connect */
66 show_splash(HZ/2, "Waiting for USB");
67
68 while (1)
69 {
70 button = button_get_w_tmo(HZ/2);
71
72 if (button == SYS_USB_CONNECTED)
73 break; /* Hit */
74 }
75
76 if (button == SYS_USB_CONNECTED)
77 {
78 /* Got the message - wait for disconnect */
79 show_splash(0, "Bootloader USB mode");
80
81 usb_acknowledge(SYS_USB_CONNECTED_ACK);
82
83 while (1)
84 {
85 button = button_get(true);
86 if (button == SYS_USB_DISCONNECTED)
87 break;
88 }
89 }
90}
91
92static int boot_rockbox(void)
93{
94 int rc;
95 void (*kernel_entry)(void);
96
97 printf("Mounting disk...\n");
98 rc = disk_mount_all();
99 if (rc <= 0)
100 {
101 verbose = true;
102 error(EDISK,rc, true);
103 }
104
105 printf("Loading firmware...\n");
106 rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000);
107 if(rc <= EFILE_EMPTY)
108 return rc;
109 else
110 {
111 printf("Starting Rockbox...\n");
112 adc_close(); /* Disable SADC, seems to fix the re-init Rockbox does */
113
114 disable_interrupt();
115 kernel_entry = (void*) CONFIG_SDRAM_START;
116 kernel_entry();
117
118 return 0; /* Shouldn't happen */
119 }
120}
121
122static void reset_configuration(void)
123{
124 int rc;
125
126 rc = disk_mount_all();
127 if (rc <= 0)
128 {
129 verbose = true;
130 error(EDISK,rc, true);
131 }
132
133 if(rename(ROCKBOX_DIR "/config.cfg", ROCKBOX_DIR "/config.old") == 0)
134 show_splash(HZ/2, "Configuration reset successfully!");
135 else
136 show_splash(HZ/2, "Couldn't reset configuration!");
137}
138
139int main(void)
140{
141 int rc;
142
143 serial_puts("\n\nSPL Stage 2\n\n");
144
145 kernel_init();
146 lcd_init();
147 font_init();
148 lcd_setfont(FONT_SYSFIXED);
149 button_init();
150 backlight_init();
151
152 show_logo();
153
154 filesystem_init();
155
156 rc = storage_init();
157 if(rc)
158 {
159 verbose = true;
160 error(EATA, rc, true);
161 }
162
163 /* Don't mount the disks yet, there could be file system/partition errors
164 which are fixable in USB mode */
165
166 reset_screen();
167
168 printf(MODEL_NAME" Rockbox Bootloader\n");
169 printf("Version %s\n", rbversion);
170
171 rc = boot_rockbox();
172
173 if(rc <= EFILE_EMPTY)
174 {
175 verbose = true;
176 printf("Error: %s", loader_strerror(rc));
177 }
178
179 /* Halt */
180 while (1)
181 core_idle();
182
183 return 0;
184}