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/x1000/boot.c | 70 ++++++++++++++++++++++++++++++++++++++ bootloader/x1000/x1000bootloader.h | 8 +++++ 2 files changed, 78 insertions(+) create mode 100644 bootloader/x1000/boot.c (limited to 'bootloader/x1000') 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