From 7554a49309fe31e69747c64caa28b4303270481b Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 5 Mar 2022 09:38:13 +0000 Subject: x1000: bootloader: refactor init_disk Add check_disk() to query the disk insertion status and prompt the user if necessary. Use this in place of init_disk(). Perform an unconditional disk_mount_all() from the main function. Change-Id: I9a8cc42266edf99cd15ece3aee8fa25835df04ae --- bootloader/x1000/boot.c | 4 +--- bootloader/x1000/install.c | 4 +--- bootloader/x1000/utils.c | 45 ++++++++++++++++++++++++++++++++++++++ bootloader/x1000/x1000bootloader.h | 9 ++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 bootloader/x1000/utils.c (limited to 'bootloader/x1000') 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 @@ #include "power.h" #include "boot-x1000.h" -extern int init_disk(void); - void boot_rockbox(void) { - if(init_disk() != 0) + if(check_disk(true) != DISK_PRESENT) return; 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 @@ #include "installer-x1000.h" #include -extern int init_disk(void); - enum { INSTALL, BACKUP, @@ -35,7 +33,7 @@ enum { static void bootloader_action(int which) { - if(init_disk() != 0) { + if(check_disk(true) != DISK_PRESENT) { splash2(5*HZ, "Install aborted", "Cannot access SD card"); return; } 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2022 Aidan MacDonald + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "x1000bootloader.h" +#include "storage.h" +#include "button.h" +#include "kernel.h" + +/* this is both incorrect and incredibly racy... */ +int check_disk(bool wait) +{ + if(storage_present(IF_MD(0))) + return DISK_PRESENT; + if(!wait) + return DISK_ABSENT; + + while(!storage_present(IF_MD(0))) { + splash2(0, "Insert SD card", "Press " BL_QUIT_NAME " to cancel"); + if(get_button(HZ/4) == BL_QUIT) + return DISK_CANCELED; + } + + /* a lie intended to give time for mounting the disk in the background */ + splash(HZ, "Scanning disk"); + + return DISK_PRESENT; +} 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 @@ #define __X1000BOOTLOADER_H__ #include "config.h" +#include #if defined(FIIO_M3K) # define BL_RECOVERY BUTTON_VOL_UP @@ -96,6 +97,14 @@ void reboot(void); * Misc */ +enum { + DISK_PRESENT = 0, + DISK_ABSENT = -1, + DISK_CANCELED = -2, +}; + +int check_disk(bool wait); + void recovery_menu(void) __attribute__((noreturn)); #endif /* __X1000BOOTLOADER_H__ */ -- cgit v1.2.3