From e2fcbd04ea8a9334b6c961a2f19933d8b9d675d4 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 5 Mar 2022 09:23:54 +0000 Subject: x1000: bootloader: split off rockbox boot code Change-Id: Ie3a097b24ee96551f6c3d08938dcb83f59ba1073 --- bootloader/SOURCES | 1 + bootloader/x1000.c | 42 ----------------------- bootloader/x1000/boot.c | 70 ++++++++++++++++++++++++++++++++++++++ bootloader/x1000/x1000bootloader.h | 8 +++++ 4 files changed, 79 insertions(+), 42 deletions(-) create mode 100644 bootloader/x1000/boot.c (limited to 'bootloader') diff --git a/bootloader/SOURCES b/bootloader/SOURCES index 0aa5985ef5..e818fab916 100644 --- a/bootloader/SOURCES +++ b/bootloader/SOURCES @@ -89,6 +89,7 @@ sansaconnect.c show_logo.c #elif defined(FIIO_M3K) || defined(SHANLING_Q1) || defined(EROS_QN) x1000.c +x1000/boot.c x1000/gui.c x1000/install.c #endif diff --git a/bootloader/x1000.c b/bootloader/x1000.c index 72a02188c3..c57ddfff4e 100644 --- a/bootloader/x1000.c +++ b/bootloader/x1000.c @@ -73,10 +73,7 @@ int init_disk(void); void recovery_menu(void) __attribute__((noreturn)); -void boot_rockbox(void); void usb_mode(void); -void shutdown(void); -void reboot(void); /* Defines the recovery menu contents */ const struct menuitem recovery_items[] = { @@ -212,31 +209,6 @@ void recovery_menu(void) } } -void boot_rockbox(void) -{ - if(init_disk() != 0) - return; - - size_t max_size = 0; - int handle = core_alloc_maximum("rockbox", &max_size, &buflib_ops_locked); - if(handle < 0) { - splash(5*HZ, "Out of memory"); - return; - } - - unsigned char* loadbuffer = core_get_data(handle); - int rc = load_firmware(loadbuffer, BOOTFILE, max_size); - if(rc <= 0) { - core_free(handle); - splash2(5*HZ, "Error loading Rockbox", loader_strerror(rc)); - return; - } - - gui_shutdown(); - - x1000_boot_rockbox(loadbuffer, rc); -} - void usb_mode(void) { init_usb(); @@ -257,20 +229,6 @@ void usb_mode(void) splash(3*HZ, "USB disconnected"); } -void shutdown(void) -{ - splash(HZ, "Shutting down"); - power_off(); - while(1); -} - -void reboot(void) -{ - splash(HZ, "Rebooting"); - system_reboot(); - while(1); -} - void main(void) { system_init(); diff --git a/bootloader/x1000/boot.c b/bootloader/x1000/boot.c new file mode 100644 index 0000000000..f9e04d1223 --- /dev/null +++ b/bootloader/x1000/boot.c @@ -0,0 +1,70 @@ +/*************************************************************************** + * __________ __ ___. + * 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 "core_alloc.h" +#include "rb-loader.h" +#include "loader_strerror.h" +#include "system.h" +#include "kernel.h" +#include "power.h" +#include "boot-x1000.h" + +extern int init_disk(void); + +void boot_rockbox(void) +{ + if(init_disk() != 0) + return; + + size_t max_size = 0; + int handle = core_alloc_maximum("rockbox", &max_size, &buflib_ops_locked); + if(handle < 0) { + splash(5*HZ, "Out of memory"); + return; + } + + unsigned char* loadbuffer = core_get_data(handle); + int rc = load_firmware(loadbuffer, BOOTFILE, max_size); + if(rc <= 0) { + core_free(handle); + splash2(5*HZ, "Error loading Rockbox", loader_strerror(rc)); + return; + } + + gui_shutdown(); + + x1000_boot_rockbox(loadbuffer, rc); +} + +void shutdown(void) +{ + splash(HZ, "Shutting down"); + power_off(); + while(1); +} + +void reboot(void) +{ + splash(HZ, "Rebooting"); + system_reboot(); + while(1); +} diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h index fb7aa80e7f..47f340532d 100644 --- a/bootloader/x1000/x1000bootloader.h +++ b/bootloader/x1000/x1000bootloader.h @@ -84,4 +84,12 @@ void bootloader_install(void); void bootloader_backup(void); void bootloader_restore(void); +/* + * Boot code + */ + +void boot_rockbox(void); +void shutdown(void); +void reboot(void); + #endif /* __X1000BOOTLOADER_H__ */ -- cgit v1.2.3