x1000: bootloader: split off rockbox boot code

Change-Id: Ie3a097b24ee96551f6c3d08938dcb83f59ba1073
This commit is contained in:
Aidan MacDonald 2022-03-05 09:23:54 +00:00
parent 22cf852db1
commit e2fcbd04ea
4 changed files with 79 additions and 42 deletions

View file

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

View file

@ -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();

70
bootloader/x1000/boot.c Normal file
View file

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

View file

@ -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__ */