diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-03-05 09:39:46 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-03-12 18:25:10 +0000 |
commit | 5bdb2fccdb9846e75e499593c6183346eca3e660 (patch) | |
tree | 2445901276eb7f1e11748b8c1d1134d29848b2a6 /bootloader | |
parent | 7554a49309fe31e69747c64caa28b4303270481b (diff) | |
download | rockbox-5bdb2fccdb9846e75e499593c6183346eca3e660.tar.gz rockbox-5bdb2fccdb9846e75e499593c6183346eca3e660.zip |
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
Diffstat (limited to 'bootloader')
-rw-r--r-- | bootloader/x1000.c | 40 | ||||
-rw-r--r-- | bootloader/x1000/recovery.c | 2 | ||||
-rw-r--r-- | bootloader/x1000/utils.c | 25 | ||||
-rw-r--r-- | bootloader/x1000/x1000bootloader.h | 1 |
4 files changed, 29 insertions, 39 deletions
diff --git a/bootloader/x1000.c b/bootloader/x1000.c index 1c9f3cd2fa..bc56b8f822 100644 --- a/bootloader/x1000.c +++ b/bootloader/x1000.c | |||
@@ -56,43 +56,6 @@ | |||
56 | #include <stdio.h> | 56 | #include <stdio.h> |
57 | #include <stdarg.h> | 57 | #include <stdarg.h> |
58 | 58 | ||
59 | /* Flags to indicate if hardware was already initialized */ | ||
60 | bool usb_inited = false; | ||
61 | |||
62 | /* Set to true if a SYS_USB_CONNECTED event is seen | ||
63 | * Set to false if a SYS_USB_DISCONNECTED event is seen */ | ||
64 | bool is_usb_connected = false; | ||
65 | |||
66 | void init_usb(void) | ||
67 | { | ||
68 | if(usb_inited) | ||
69 | return; | ||
70 | |||
71 | usb_init(); | ||
72 | usb_start_monitoring(); | ||
73 | usb_inited = true; | ||
74 | } | ||
75 | |||
76 | void usb_mode(void) | ||
77 | { | ||
78 | init_usb(); | ||
79 | |||
80 | if(!is_usb_connected) | ||
81 | splash2(0, "Waiting for USB", "Press " BL_QUIT_NAME " to go back"); | ||
82 | |||
83 | while(!is_usb_connected) | ||
84 | if(get_button(TIMEOUT_BLOCK) == BL_QUIT) | ||
85 | return; | ||
86 | |||
87 | splash(0, "USB mode"); | ||
88 | usb_acknowledge(SYS_USB_CONNECTED_ACK); | ||
89 | |||
90 | while(is_usb_connected) | ||
91 | get_button(TIMEOUT_BLOCK); | ||
92 | |||
93 | splash(3*HZ, "USB disconnected"); | ||
94 | } | ||
95 | |||
96 | void main(void) | 59 | void main(void) |
97 | { | 60 | { |
98 | system_init(); | 61 | system_init(); |
@@ -110,6 +73,9 @@ void main(void) | |||
110 | 73 | ||
111 | filesystem_init(); | 74 | filesystem_init(); |
112 | 75 | ||
76 | usb_init(); | ||
77 | usb_start_monitoring(); | ||
78 | |||
113 | /* It's OK if this doesn't mount anything. Any disk access should | 79 | /* It's OK if this doesn't mount anything. Any disk access should |
114 | * be guarded by a call to check_disk() to see if the disk is really | 80 | * be guarded by a call to check_disk() to see if the disk is really |
115 | * present, blocking with an "insert SD card" prompt if appropriate. */ | 81 | * present, blocking with an "insert SD card" prompt if appropriate. */ |
diff --git a/bootloader/x1000/recovery.c b/bootloader/x1000/recovery.c index 809bd6578a..4d806b26a4 100644 --- a/bootloader/x1000/recovery.c +++ b/bootloader/x1000/recovery.c | |||
@@ -26,8 +26,6 @@ | |||
26 | #include "kernel.h" | 26 | #include "kernel.h" |
27 | #include <string.h> | 27 | #include <string.h> |
28 | 28 | ||
29 | extern void usb_mode(void); | ||
30 | |||
31 | enum { | 29 | enum { |
32 | MENUITEM_HEADING, | 30 | MENUITEM_HEADING, |
33 | MENUITEM_ACTION, | 31 | MENUITEM_ACTION, |
diff --git a/bootloader/x1000/utils.c b/bootloader/x1000/utils.c index f4dbac4c5e..56ac6d1fff 100644 --- a/bootloader/x1000/utils.c +++ b/bootloader/x1000/utils.c | |||
@@ -23,6 +23,13 @@ | |||
23 | #include "storage.h" | 23 | #include "storage.h" |
24 | #include "button.h" | 24 | #include "button.h" |
25 | #include "kernel.h" | 25 | #include "kernel.h" |
26 | #include "usb.h" | ||
27 | |||
28 | /* Set to true if a SYS_USB_CONNECTED event is seen | ||
29 | * Set to false if a SYS_USB_DISCONNECTED event is seen | ||
30 | * Handled by the gui code since that's how events are delivered | ||
31 | * TODO: this is an ugly kludge */ | ||
32 | bool is_usb_connected = false; | ||
26 | 33 | ||
27 | /* this is both incorrect and incredibly racy... */ | 34 | /* this is both incorrect and incredibly racy... */ |
28 | int check_disk(bool wait) | 35 | int check_disk(bool wait) |
@@ -43,3 +50,21 @@ int check_disk(bool wait) | |||
43 | 50 | ||
44 | return DISK_PRESENT; | 51 | return DISK_PRESENT; |
45 | } | 52 | } |
53 | |||
54 | void usb_mode(void) | ||
55 | { | ||
56 | if(!is_usb_connected) | ||
57 | splash2(0, "Waiting for USB", "Press " BL_QUIT_NAME " to cancel"); | ||
58 | |||
59 | while(!is_usb_connected) | ||
60 | if(get_button(TIMEOUT_BLOCK) == BL_QUIT) | ||
61 | return; | ||
62 | |||
63 | splash(0, "USB mode"); | ||
64 | usb_acknowledge(SYS_USB_CONNECTED_ACK); | ||
65 | |||
66 | while(is_usb_connected) | ||
67 | get_button(TIMEOUT_BLOCK); | ||
68 | |||
69 | splash(3*HZ, "USB disconnected"); | ||
70 | } | ||
diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h index bb35cd3b78..60353e59fd 100644 --- a/bootloader/x1000/x1000bootloader.h +++ b/bootloader/x1000/x1000bootloader.h | |||
@@ -104,6 +104,7 @@ enum { | |||
104 | }; | 104 | }; |
105 | 105 | ||
106 | int check_disk(bool wait); | 106 | int check_disk(bool wait); |
107 | void usb_mode(void); | ||
107 | 108 | ||
108 | void recovery_menu(void) __attribute__((noreturn)); | 109 | void recovery_menu(void) __attribute__((noreturn)); |
109 | 110 | ||