summaryrefslogtreecommitdiff
path: root/bootloader/x1000/utils.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-03-05 09:41:46 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-03-12 18:25:10 +0000
commitb87f2ed851ef191f1bfff245b77add2ab8b65091 (patch)
treeaf0abb1b0150ba6bd6c835da8d518b2492dbed68 /bootloader/x1000/utils.c
parented897d1359bcf09692746d2b8b31fcbd2da95b58 (diff)
downloadrockbox-b87f2ed851ef191f1bfff245b77add2ab8b65091.tar.gz
rockbox-b87f2ed851ef191f1bfff245b77add2ab8b65091.zip
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
Diffstat (limited to 'bootloader/x1000/utils.c')
-rw-r--r--bootloader/x1000/utils.c28
1 files changed, 28 insertions, 0 deletions
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 @@
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#include "x1000bootloader.h" 22#include "x1000bootloader.h"
23#include "core_alloc.h"
23#include "storage.h" 24#include "storage.h"
24#include "button.h" 25#include "button.h"
25#include "kernel.h" 26#include "kernel.h"
26#include "usb.h" 27#include "usb.h"
28#include "rb-loader.h"
29#include "loader_strerror.h"
27 30
28/* Set to true if a SYS_USB_CONNECTED event is seen 31/* Set to true if a SYS_USB_CONNECTED event is seen
29 * Set to false if a SYS_USB_DISCONNECTED event is seen 32 * Set to false if a SYS_USB_DISCONNECTED event is seen
@@ -68,3 +71,28 @@ void usb_mode(void)
68 71
69 splash(3*HZ, "USB disconnected"); 72 splash(3*HZ, "USB disconnected");
70} 73}
74
75int load_rockbox(const char* filename, size_t* sizep)
76{
77 if(check_disk(true) != DISK_PRESENT)
78 return -1;
79
80 int handle = core_alloc_maximum("rockbox", sizep, &buflib_ops_locked);
81 if(handle < 0) {
82 splash(5*HZ, "Out of memory");
83 return -2;
84 }
85
86 unsigned char* loadbuffer = core_get_data(handle);
87 int rc = load_firmware(loadbuffer, filename, *sizep);
88 if(rc <= 0) {
89 core_free(handle);
90 splash2(5*HZ, "Error loading Rockbox", loader_strerror(rc));
91 return -3;
92 }
93
94 core_shrink(handle, loadbuffer, rc);
95 *sizep = rc;
96
97 return handle;
98}