From 22cf852db1a37349061a665ea5b7a45bb1b2c2a7 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 5 Mar 2022 09:21:58 +0000 Subject: [PATCH] x1000: bootloader: split off installer code Change-Id: I75918301214cd415392f8c95e8a07205cfa21659 --- bootloader/SOURCES | 1 + bootloader/x1000.c | 58 --------------------- bootloader/x1000/install.c | 83 ++++++++++++++++++++++++++++++ bootloader/x1000/x1000bootloader.h | 8 +++ 4 files changed, 92 insertions(+), 58 deletions(-) create mode 100644 bootloader/x1000/install.c diff --git a/bootloader/SOURCES b/bootloader/SOURCES index 39b46b0b8d..0aa5985ef5 100644 --- a/bootloader/SOURCES +++ b/bootloader/SOURCES @@ -90,4 +90,5 @@ show_logo.c #elif defined(FIIO_M3K) || defined(SHANLING_Q1) || defined(EROS_QN) x1000.c x1000/gui.c +x1000/install.c #endif diff --git a/bootloader/x1000.c b/bootloader/x1000.c index a079c478d5..72a02188c3 100644 --- a/bootloader/x1000.c +++ b/bootloader/x1000.c @@ -77,9 +77,6 @@ void boot_rockbox(void); void usb_mode(void); void shutdown(void); void reboot(void); -void bootloader_install(void); -void bootloader_backup(void); -void bootloader_restore(void); /* Defines the recovery menu contents */ const struct menuitem recovery_items[] = { @@ -274,61 +271,6 @@ void reboot(void) while(1); } -enum { - INSTALL, - BACKUP, - RESTORE, -}; - -void bootloader_action(int which) -{ - if(init_disk() != 0) { - splash2(5*HZ, "Install aborted", "Cannot access SD card"); - return; - } - - const char* msg; - switch(which) { - case INSTALL: msg = "Installing"; break; - case BACKUP: msg = "Backing up"; break; - case RESTORE: msg = "Restoring"; break; - default: return; /* can't happen */ - } - - splash(0, msg); - - int rc; - switch(which) { - case INSTALL: rc = install_bootloader("/bootloader." BOOTFILE_EXT); break; - case BACKUP: rc = backup_bootloader(BOOTBACKUP_FILE); break; - case RESTORE: rc = restore_bootloader(BOOTBACKUP_FILE); break; - default: return; - } - - static char buf[64]; - snprintf(buf, sizeof(buf), "%s (%d)", installer_strerror(rc), rc); - const char* msg1 = rc == 0 ? "Success" : buf; - const char* msg2 = "Press " BL_QUIT_NAME " to continue"; - splash2(0, msg1, msg2); - - while(get_button(TIMEOUT_BLOCK) != BL_QUIT); -} - -void bootloader_install(void) -{ - bootloader_action(INSTALL); -} - -void bootloader_backup(void) -{ - bootloader_action(BACKUP); -} - -void bootloader_restore(void) -{ - bootloader_action(RESTORE); -} - void main(void) { system_init(); diff --git a/bootloader/x1000/install.c b/bootloader/x1000/install.c new file mode 100644 index 0000000000..aa4fdde3b0 --- /dev/null +++ b/bootloader/x1000/install.c @@ -0,0 +1,83 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2021-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 "kernel.h" +#include "button.h" +#include "installer-x1000.h" +#include + +extern int init_disk(void); + +enum { + INSTALL, + BACKUP, + RESTORE, +}; + +static void bootloader_action(int which) +{ + if(init_disk() != 0) { + splash2(5*HZ, "Install aborted", "Cannot access SD card"); + return; + } + + const char* msg; + switch(which) { + case INSTALL: msg = "Installing"; break; + case BACKUP: msg = "Backing up"; break; + case RESTORE: msg = "Restoring"; break; + default: return; /* can't happen */ + } + + splash(0, msg); + + int rc; + switch(which) { + case INSTALL: rc = install_bootloader("/bootloader." BOOTFILE_EXT); break; + case BACKUP: rc = backup_bootloader(BOOTBACKUP_FILE); break; + case RESTORE: rc = restore_bootloader(BOOTBACKUP_FILE); break; + default: return; + } + + static char buf[64]; + snprintf(buf, sizeof(buf), "%s (%d)", installer_strerror(rc), rc); + const char* msg1 = rc == 0 ? "Success" : buf; + const char* msg2 = "Press " BL_QUIT_NAME " to continue"; + splash2(0, msg1, msg2); + + while(get_button(TIMEOUT_BLOCK) != BL_QUIT); +} + +void bootloader_install(void) +{ + bootloader_action(INSTALL); +} + +void bootloader_backup(void) +{ + bootloader_action(BACKUP); +} + +void bootloader_restore(void) +{ + bootloader_action(RESTORE); +} diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h index df891e54bb..fb7aa80e7f 100644 --- a/bootloader/x1000/x1000bootloader.h +++ b/bootloader/x1000/x1000bootloader.h @@ -76,4 +76,12 @@ void init_lcd(void); void gui_shutdown(void); +/* + * Installer + */ + +void bootloader_install(void); +void bootloader_backup(void); +void bootloader_restore(void); + #endif /* __X1000BOOTLOADER_H__ */