summaryrefslogtreecommitdiff
path: root/bootloader/x1000
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader/x1000')
-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
4 files changed, 56 insertions, 6 deletions
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__ */