r31444 missed a file. make fuzeplus sim build again
[maemo-rb.git] / bootloader / imx233.c
blobd808fc8aa95af7e66466e0eb79cd55b0b38e7a23
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2011 by amaury Pouly
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
25 #include <stdio.h>
26 #include <system.h>
27 #include <inttypes.h>
28 #include "config.h"
29 #include "gcc_extensions.h"
30 #include "lcd.h"
31 #include "backlight.h"
32 #include "button-target.h"
33 #include "common.h"
34 #include "storage.h"
35 #include "disk.h"
36 #include "panic.h"
37 #include "power.h"
38 #include "system-target.h"
39 #include "fmradio_i2c.h"
40 #include "version.h"
42 #include "usb.h"
44 extern char loadaddress[];
45 extern char loadaddressend[];
47 #ifdef HAVE_BOOTLOADER_USB_MODE
48 static void usb_mode(int connect_timeout)
50 int button;
52 usb_init();
53 usb_start_monitoring();
55 /* Wait for threads to connect or cable is pulled */
56 printf("USB: Connecting");
58 long end_tick = current_tick + connect_timeout;
60 while(1)
62 button = button_get_w_tmo(HZ/10);
64 if(button == SYS_USB_CONNECTED)
65 break; /* Hit */
67 if(TIME_AFTER(current_tick, end_tick))
69 /* Timed out waiting for the connect - will happen when connected
70 * to a charger through the USB port */
71 printf("USB: Timed out");
72 break;
75 if(usb_detect() == USB_EXTRACTED)
76 break; /* Cable pulled */
79 if(button == SYS_USB_CONNECTED)
81 /* Got the message - wait for disconnect */
82 printf("Bootloader USB mode");
84 usb_acknowledge(SYS_USB_CONNECTED_ACK);
86 while(1)
88 button = button_get_w_tmo(HZ/2);
89 if(button == SYS_USB_DISCONNECTED)
90 break;
94 /* Put drivers initialized for USB connection into a known state */
95 usb_close();
97 #else /* !HAVE_BOOTLOADER_USB_MODE */
98 static void usb_mode(int connect_timeout)
100 (void) connect_timeout;
102 #endif /* HAVE_BOOTLOADER_USB_MODE */
104 void main(uint32_t arg, uint32_t addr) NORETURN_ATTR;
105 void main(uint32_t arg, uint32_t addr)
107 unsigned char* loadbuffer;
108 int buffer_size;
109 void(*kernel_entry)(void);
110 int ret;
112 system_init();
113 kernel_init();
115 power_init();
116 enable_irq();
118 lcd_init();
119 lcd_clear_display();
120 lcd_update();
122 backlight_init();
124 button_init();
126 //button_debug_screen();
127 printf("Boot version: %s", RBVERSION);
128 printf("arg=%x addr=%x", arg, addr);
130 #ifdef SANSA_FUZEPLUS
131 extern void imx233_mmc_disable_window(void);
132 if(arg == 0xfee1dead)
134 printf("Disable MMC window.");
135 imx233_mmc_disable_window();
137 #endif
139 ret = storage_init();
140 if(ret < 0)
141 error(EATA, ret, true);
143 /* NOTE: allow disk_init and disk_mount_all to fail since we can do USB after.
144 * We need this order to determine the correct logical sector size */
145 while(!disk_init(IF_MV(0)))
146 printf("disk_init failed!");
148 if((ret = disk_mount_all()) <= 0)
149 error(EDISK, ret, false);
151 if(usb_detect() == USB_INSERTED)
152 usb_mode(HZ);
154 printf("Loading firmware");
156 loadbuffer = (unsigned char*)loadaddress;
157 buffer_size = (int)(loadaddressend - loadaddress);
159 while((ret = load_firmware(loadbuffer, BOOTFILE, buffer_size)) < 0)
161 error(EBOOTFILE, ret, true);
164 kernel_entry = (void*) loadbuffer;
165 printf("Executing");
166 disable_interrupt(IRQ_FIQ_STATUS);
167 commit_discard_idcache();
168 kernel_entry();
169 printf("ERR: Failed to boot");
171 /* never returns */
172 while(1) ;