From b87f2ed851ef191f1bfff245b77add2ab8b65091 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 5 Mar 2022 09:41:46 +0000 Subject: x1000: bootloader: refactor rockbox boot Separate loading out into its own routine with a file name parameter in preparation for multiboot support. Change-Id: Ic651e9fa7738ea97789e4a9669834c4e3ef22d66 --- bootloader/x1000/boot.c | 24 ++++-------------------- bootloader/x1000/utils.c | 28 ++++++++++++++++++++++++++++ bootloader/x1000/x1000bootloader.h | 3 +++ 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/bootloader/x1000/boot.c b/bootloader/x1000/boot.c index bb9528ba3c..6719375151 100644 --- a/bootloader/x1000/boot.c +++ b/bootloader/x1000/boot.c @@ -21,8 +21,6 @@ #include "x1000bootloader.h" #include "core_alloc.h" -#include "rb-loader.h" -#include "loader_strerror.h" #include "system.h" #include "kernel.h" #include "power.h" @@ -30,27 +28,13 @@ void boot_rockbox(void) { - if(check_disk(true) != DISK_PRESENT) + size_t length; + int handle = load_rockbox(BOOTFILE, &length); + if(handle < 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); + x1000_boot_rockbox(core_get_data(handle), length); } void shutdown(void) diff --git a/bootloader/x1000/utils.c b/bootloader/x1000/utils.c index 56ac6d1fff..6cb9bb379a 100644 --- a/bootloader/x1000/utils.c +++ b/bootloader/x1000/utils.c @@ -20,10 +20,13 @@ ****************************************************************************/ #include "x1000bootloader.h" +#include "core_alloc.h" #include "storage.h" #include "button.h" #include "kernel.h" #include "usb.h" +#include "rb-loader.h" +#include "loader_strerror.h" /* Set to true if a SYS_USB_CONNECTED event is seen * Set to false if a SYS_USB_DISCONNECTED event is seen @@ -68,3 +71,28 @@ void usb_mode(void) splash(3*HZ, "USB disconnected"); } + +int load_rockbox(const char* filename, size_t* sizep) +{ + if(check_disk(true) != DISK_PRESENT) + return -1; + + int handle = core_alloc_maximum("rockbox", sizep, &buflib_ops_locked); + if(handle < 0) { + splash(5*HZ, "Out of memory"); + return -2; + } + + unsigned char* loadbuffer = core_get_data(handle); + int rc = load_firmware(loadbuffer, filename, *sizep); + if(rc <= 0) { + core_free(handle); + splash2(5*HZ, "Error loading Rockbox", loader_strerror(rc)); + return -3; + } + + core_shrink(handle, loadbuffer, rc); + *sizep = rc; + + return handle; +} diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h index 60353e59fd..84feded9b3 100644 --- a/bootloader/x1000/x1000bootloader.h +++ b/bootloader/x1000/x1000bootloader.h @@ -23,6 +23,7 @@ #define __X1000BOOTLOADER_H__ #include "config.h" +#include #include #if defined(FIIO_M3K) @@ -106,6 +107,8 @@ enum { int check_disk(bool wait); void usb_mode(void); +int load_rockbox(const char* filename, size_t* sizep); + void recovery_menu(void) __attribute__((noreturn)); #endif /* __X1000BOOTLOADER_H__ */ -- cgit v1.2.3