1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Aidan MacDonald 2022-03-05 09:41:46 +00:00
parent ed897d1359
commit b87f2ed851
3 changed files with 35 additions and 20 deletions

View file

@ -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;
}