summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bootloader/SOURCES1
-rw-r--r--bootloader/x1000.c32
-rw-r--r--bootloader/x1000/boot.c4
-rw-r--r--bootloader/x1000/install.c4
-rw-r--r--bootloader/x1000/utils.c45
-rw-r--r--bootloader/x1000/x1000bootloader.h9
6 files changed, 62 insertions, 33 deletions
diff --git a/bootloader/SOURCES b/bootloader/SOURCES
index 16391f8528..95836eb016 100644
--- a/bootloader/SOURCES
+++ b/bootloader/SOURCES
@@ -93,4 +93,5 @@ x1000/boot.c
93x1000/gui.c 93x1000/gui.c
94x1000/install.c 94x1000/install.c
95x1000/recovery.c 95x1000/recovery.c
96x1000/utils.c
96#endif 97#endif
diff --git a/bootloader/x1000.c b/bootloader/x1000.c
index 8b1dae3050..1c9f3cd2fa 100644
--- a/bootloader/x1000.c
+++ b/bootloader/x1000.c
@@ -56,15 +56,8 @@
56#include <stdio.h> 56#include <stdio.h>
57#include <stdarg.h> 57#include <stdarg.h>
58 58
59void init_lcd(void);
60void init_usb(void);
61int init_disk(void);
62
63void usb_mode(void);
64
65/* Flags to indicate if hardware was already initialized */ 59/* Flags to indicate if hardware was already initialized */
66bool usb_inited = false; 60bool usb_inited = false;
67bool disk_inited = false;
68 61
69/* Set to true if a SYS_USB_CONNECTED event is seen 62/* Set to true if a SYS_USB_CONNECTED event is seen
70 * Set to false if a SYS_USB_DISCONNECTED event is seen */ 63 * Set to false if a SYS_USB_DISCONNECTED event is seen */
@@ -80,26 +73,6 @@ void init_usb(void)
80 usb_inited = true; 73 usb_inited = true;
81} 74}
82 75
83int init_disk(void)
84{
85 if(disk_inited)
86 return 0;
87
88 while(!storage_present(IF_MD(0))) {
89 splash2(0, "Insert SD card", "Press " BL_QUIT_NAME " for recovery");
90 if(get_button(HZ/4) == BL_QUIT)
91 return -1;
92 }
93
94 if(disk_mount_all() <= 0) {
95 splash(5*HZ, "Cannot mount disk");
96 return -1;
97 }
98
99 disk_inited = true;
100 return 0;
101}
102
103void usb_mode(void) 76void usb_mode(void)
104{ 77{
105 init_usb(); 78 init_usb();
@@ -137,6 +110,11 @@ void main(void)
137 110
138 filesystem_init(); 111 filesystem_init();
139 112
113 /* 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
115 * present, blocking with an "insert SD card" prompt if appropriate. */
116 disk_mount_all();
117
140 /* If USB booting, the user probably needs to enter recovery mode; 118 /* If USB booting, the user probably needs to enter recovery mode;
141 * let's not force them to hold down the recovery key. */ 119 * let's not force them to hold down the recovery key. */
142 bool recovery_mode = get_boot_flag(BOOT_FLAG_USB_BOOT); 120 bool recovery_mode = get_boot_flag(BOOT_FLAG_USB_BOOT);
diff --git a/bootloader/x1000/boot.c b/bootloader/x1000/boot.c
index f9e04d1223..bb9528ba3c 100644
--- a/bootloader/x1000/boot.c
+++ b/bootloader/x1000/boot.c
@@ -28,11 +28,9 @@
28#include "power.h" 28#include "power.h"
29#include "boot-x1000.h" 29#include "boot-x1000.h"
30 30
31extern int init_disk(void);
32
33void boot_rockbox(void) 31void boot_rockbox(void)
34{ 32{
35 if(init_disk() != 0) 33 if(check_disk(true) != DISK_PRESENT)
36 return; 34 return;
37 35
38 size_t max_size = 0; 36 size_t max_size = 0;
diff --git a/bootloader/x1000/install.c b/bootloader/x1000/install.c
index aa4fdde3b0..e4af66443b 100644
--- a/bootloader/x1000/install.c
+++ b/bootloader/x1000/install.c
@@ -25,8 +25,6 @@
25#include "installer-x1000.h" 25#include "installer-x1000.h"
26#include <stdio.h> 26#include <stdio.h>
27 27
28extern int init_disk(void);
29
30enum { 28enum {
31 INSTALL, 29 INSTALL,
32 BACKUP, 30 BACKUP,
@@ -35,7 +33,7 @@ enum {
35 33
36static void bootloader_action(int which) 34static void bootloader_action(int which)
37{ 35{
38 if(init_disk() != 0) { 36 if(check_disk(true) != DISK_PRESENT) {
39 splash2(5*HZ, "Install aborted", "Cannot access SD card"); 37 splash2(5*HZ, "Install aborted", "Cannot access SD card");
40 return; 38 return;
41 } 39 }
diff --git a/bootloader/x1000/utils.c b/bootloader/x1000/utils.c
new file mode 100644
index 0000000000..f4dbac4c5e
--- /dev/null
+++ b/bootloader/x1000/utils.c
@@ -0,0 +1,45 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2022 Aidan MacDonald
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 "x1000bootloader.h"
23#include "storage.h"
24#include "button.h"
25#include "kernel.h"
26
27/* this is both incorrect and incredibly racy... */
28int check_disk(bool wait)
29{
30 if(storage_present(IF_MD(0)))
31 return DISK_PRESENT;
32 if(!wait)
33 return DISK_ABSENT;
34
35 while(!storage_present(IF_MD(0))) {
36 splash2(0, "Insert SD card", "Press " BL_QUIT_NAME " to cancel");
37 if(get_button(HZ/4) == BL_QUIT)
38 return DISK_CANCELED;
39 }
40
41 /* a lie intended to give time for mounting the disk in the background */
42 splash(HZ, "Scanning disk");
43
44 return DISK_PRESENT;
45}
diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h
index 05f421fc61..bb35cd3b78 100644
--- a/bootloader/x1000/x1000bootloader.h
+++ b/bootloader/x1000/x1000bootloader.h
@@ -23,6 +23,7 @@
23#define __X1000BOOTLOADER_H__ 23#define __X1000BOOTLOADER_H__
24 24
25#include "config.h" 25#include "config.h"
26#include <stdbool.h>
26 27
27#if defined(FIIO_M3K) 28#if defined(FIIO_M3K)
28# define BL_RECOVERY BUTTON_VOL_UP 29# define BL_RECOVERY BUTTON_VOL_UP
@@ -96,6 +97,14 @@ void reboot(void);
96 * Misc 97 * Misc
97 */ 98 */
98 99
100enum {
101 DISK_PRESENT = 0,
102 DISK_ABSENT = -1,
103 DISK_CANCELED = -2,
104};
105
106int check_disk(bool wait);
107
99void recovery_menu(void) __attribute__((noreturn)); 108void recovery_menu(void) __attribute__((noreturn));
100 109
101#endif /* __X1000BOOTLOADER_H__ */ 110#endif /* __X1000BOOTLOADER_H__ */