x1000: bootloader: refactor usb handling
Drop init_usb(), instead initialize USB early in the main function so the hardware is placed into a known good state after a USB boot. The impact on boot time should be minimal. Change-Id: I9774ddfc2c27811363bdb0c54cb0e57b5ca59d73
This commit is contained in:
parent
7554a49309
commit
5bdb2fccdb
4 changed files with 29 additions and 39 deletions
|
@ -56,43 +56,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Flags to indicate if hardware was already initialized */
|
||||
bool usb_inited = false;
|
||||
|
||||
/* Set to true if a SYS_USB_CONNECTED event is seen
|
||||
* Set to false if a SYS_USB_DISCONNECTED event is seen */
|
||||
bool is_usb_connected = false;
|
||||
|
||||
void init_usb(void)
|
||||
{
|
||||
if(usb_inited)
|
||||
return;
|
||||
|
||||
usb_init();
|
||||
usb_start_monitoring();
|
||||
usb_inited = true;
|
||||
}
|
||||
|
||||
void usb_mode(void)
|
||||
{
|
||||
init_usb();
|
||||
|
||||
if(!is_usb_connected)
|
||||
splash2(0, "Waiting for USB", "Press " BL_QUIT_NAME " to go back");
|
||||
|
||||
while(!is_usb_connected)
|
||||
if(get_button(TIMEOUT_BLOCK) == BL_QUIT)
|
||||
return;
|
||||
|
||||
splash(0, "USB mode");
|
||||
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
||||
|
||||
while(is_usb_connected)
|
||||
get_button(TIMEOUT_BLOCK);
|
||||
|
||||
splash(3*HZ, "USB disconnected");
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
system_init();
|
||||
|
@ -110,6 +73,9 @@ void main(void)
|
|||
|
||||
filesystem_init();
|
||||
|
||||
usb_init();
|
||||
usb_start_monitoring();
|
||||
|
||||
/* It's OK if this doesn't mount anything. Any disk access should
|
||||
* be guarded by a call to check_disk() to see if the disk is really
|
||||
* present, blocking with an "insert SD card" prompt if appropriate. */
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
#include "kernel.h"
|
||||
#include <string.h>
|
||||
|
||||
extern void usb_mode(void);
|
||||
|
||||
enum {
|
||||
MENUITEM_HEADING,
|
||||
MENUITEM_ACTION,
|
||||
|
|
|
@ -23,6 +23,13 @@
|
|||
#include "storage.h"
|
||||
#include "button.h"
|
||||
#include "kernel.h"
|
||||
#include "usb.h"
|
||||
|
||||
/* Set to true if a SYS_USB_CONNECTED event is seen
|
||||
* Set to false if a SYS_USB_DISCONNECTED event is seen
|
||||
* Handled by the gui code since that's how events are delivered
|
||||
* TODO: this is an ugly kludge */
|
||||
bool is_usb_connected = false;
|
||||
|
||||
/* this is both incorrect and incredibly racy... */
|
||||
int check_disk(bool wait)
|
||||
|
@ -43,3 +50,21 @@ int check_disk(bool wait)
|
|||
|
||||
return DISK_PRESENT;
|
||||
}
|
||||
|
||||
void usb_mode(void)
|
||||
{
|
||||
if(!is_usb_connected)
|
||||
splash2(0, "Waiting for USB", "Press " BL_QUIT_NAME " to cancel");
|
||||
|
||||
while(!is_usb_connected)
|
||||
if(get_button(TIMEOUT_BLOCK) == BL_QUIT)
|
||||
return;
|
||||
|
||||
splash(0, "USB mode");
|
||||
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
||||
|
||||
while(is_usb_connected)
|
||||
get_button(TIMEOUT_BLOCK);
|
||||
|
||||
splash(3*HZ, "USB disconnected");
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ enum {
|
|||
};
|
||||
|
||||
int check_disk(bool wait);
|
||||
void usb_mode(void);
|
||||
|
||||
void recovery_menu(void) __attribute__((noreturn));
|
||||
|
||||
|
|
Loading…
Reference in a new issue