forked from len0rd/rockbox
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
This commit is contained in:
parent
905591215f
commit
7554a49309
6 changed files with 62 additions and 33 deletions
|
|
@ -93,4 +93,5 @@ x1000/boot.c
|
||||||
x1000/gui.c
|
x1000/gui.c
|
||||||
x1000/install.c
|
x1000/install.c
|
||||||
x1000/recovery.c
|
x1000/recovery.c
|
||||||
|
x1000/utils.c
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -56,15 +56,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
void init_lcd(void);
|
|
||||||
void init_usb(void);
|
|
||||||
int init_disk(void);
|
|
||||||
|
|
||||||
void usb_mode(void);
|
|
||||||
|
|
||||||
/* Flags to indicate if hardware was already initialized */
|
/* Flags to indicate if hardware was already initialized */
|
||||||
bool usb_inited = false;
|
bool usb_inited = false;
|
||||||
bool disk_inited = false;
|
|
||||||
|
|
||||||
/* Set to true if a SYS_USB_CONNECTED event is seen
|
/* Set to true if a SYS_USB_CONNECTED event is seen
|
||||||
* Set to false if a SYS_USB_DISCONNECTED event is seen */
|
* Set to false if a SYS_USB_DISCONNECTED event is seen */
|
||||||
|
|
@ -80,26 +73,6 @@ void init_usb(void)
|
||||||
usb_inited = true;
|
usb_inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_disk(void)
|
|
||||||
{
|
|
||||||
if(disk_inited)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
while(!storage_present(IF_MD(0))) {
|
|
||||||
splash2(0, "Insert SD card", "Press " BL_QUIT_NAME " for recovery");
|
|
||||||
if(get_button(HZ/4) == BL_QUIT)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(disk_mount_all() <= 0) {
|
|
||||||
splash(5*HZ, "Cannot mount disk");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
disk_inited = true;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void usb_mode(void)
|
void usb_mode(void)
|
||||||
{
|
{
|
||||||
init_usb();
|
init_usb();
|
||||||
|
|
@ -137,6 +110,11 @@ void main(void)
|
||||||
|
|
||||||
filesystem_init();
|
filesystem_init();
|
||||||
|
|
||||||
|
/* 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. */
|
||||||
|
disk_mount_all();
|
||||||
|
|
||||||
/* If USB booting, the user probably needs to enter recovery mode;
|
/* If USB booting, the user probably needs to enter recovery mode;
|
||||||
* let's not force them to hold down the recovery key. */
|
* let's not force them to hold down the recovery key. */
|
||||||
bool recovery_mode = get_boot_flag(BOOT_FLAG_USB_BOOT);
|
bool recovery_mode = get_boot_flag(BOOT_FLAG_USB_BOOT);
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,9 @@
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
#include "boot-x1000.h"
|
#include "boot-x1000.h"
|
||||||
|
|
||||||
extern int init_disk(void);
|
|
||||||
|
|
||||||
void boot_rockbox(void)
|
void boot_rockbox(void)
|
||||||
{
|
{
|
||||||
if(init_disk() != 0)
|
if(check_disk(true) != DISK_PRESENT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t max_size = 0;
|
size_t max_size = 0;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@
|
||||||
#include "installer-x1000.h"
|
#include "installer-x1000.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
extern int init_disk(void);
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
INSTALL,
|
INSTALL,
|
||||||
BACKUP,
|
BACKUP,
|
||||||
|
|
@ -35,7 +33,7 @@ enum {
|
||||||
|
|
||||||
static void bootloader_action(int which)
|
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");
|
splash2(5*HZ, "Install aborted", "Cannot access SD card");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
45
bootloader/x1000/utils.c
Normal file
45
bootloader/x1000/utils.c
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#define __X1000BOOTLOADER_H__
|
#define __X1000BOOTLOADER_H__
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#if defined(FIIO_M3K)
|
#if defined(FIIO_M3K)
|
||||||
# define BL_RECOVERY BUTTON_VOL_UP
|
# define BL_RECOVERY BUTTON_VOL_UP
|
||||||
|
|
@ -96,6 +97,14 @@ void reboot(void);
|
||||||
* Misc
|
* Misc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
enum {
|
||||||
|
DISK_PRESENT = 0,
|
||||||
|
DISK_ABSENT = -1,
|
||||||
|
DISK_CANCELED = -2,
|
||||||
|
};
|
||||||
|
|
||||||
|
int check_disk(bool wait);
|
||||||
|
|
||||||
void recovery_menu(void) __attribute__((noreturn));
|
void recovery_menu(void) __attribute__((noreturn));
|
||||||
|
|
||||||
#endif /* __X1000BOOTLOADER_H__ */
|
#endif /* __X1000BOOTLOADER_H__ */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue