From 6533d983ca48b48563cd6177c2a9d4ad1a84b749 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sun, 11 Oct 2020 09:30:41 -0400 Subject: [PATCH] hosted: Add ROLO support for hosted targets Change-Id: I2d46a63ee8225a9d9d77dd80a06c418af78c260c --- apps/filetree.c | 2 +- firmware/SOURCES | 4 + firmware/export/config/agptekrocker.h | 5 ++ firmware/export/config/xduoox20.h | 6 ++ firmware/export/config/xduoox3ii.h | 7 ++ firmware/export/rolo.h | 4 + firmware/rolo.c | 6 +- firmware/target/hosted/rolo.c | 102 ++++++++++++++++++++++++++ 8 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 firmware/target/hosted/rolo.c diff --git a/apps/filetree.c b/apps/filetree.c index 9279f84c17..f8a1263e7f 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -616,7 +616,7 @@ int ft_enter(struct tree_context* c) set_file(buf, (char *)global_settings.kbd_file, MAX_FILENAME); break; -#if (CONFIG_PLATFORM & PLATFORM_NATIVE) +#if defined(HAVE_ROLO) /* firmware file */ case FILE_ATTR_MOD: splash(0, ID2P(LANG_WAIT)); diff --git a/firmware/SOURCES b/firmware/SOURCES index 42677725fc..cbbebbc66f 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -47,6 +47,10 @@ debug.c #endif /* PLATFORM_NATIVE */ panic.c +#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(BOOTFILE) +target/hosted/rolo.c +#endif + #ifdef HAVE_SDL target/hosted/sdl/button-sdl.c target/hosted/sdl/kernel-sdl.c diff --git a/firmware/export/config/agptekrocker.h b/firmware/export/config/agptekrocker.h index 749786dff1..a97522d976 100644 --- a/firmware/export/config/agptekrocker.h +++ b/firmware/export/config/agptekrocker.h @@ -124,3 +124,8 @@ #define BATTERY_CAPACITY_MIN 600 /* min. capacity selectable */ #define BATTERY_CAPACITY_MAX 600 /* max. capacity selectable */ #define BATTERY_CAPACITY_INC 0 /* capacity increment */ + +/* ROLO */ +#define BOOTFILE_EXT "rocker" +#define BOOTFILE "rockbox." BOOTFILE_EXT +#define BOOTDIR "/.rockbox" diff --git a/firmware/export/config/xduoox20.h b/firmware/export/config/xduoox20.h index 1852027cf0..a8d2175719 100644 --- a/firmware/export/config/xduoox20.h +++ b/firmware/export/config/xduoox20.h @@ -122,3 +122,9 @@ #define BATTERY_CAPACITY_MIN 2400 /* min. capacity selectable */ #define BATTERY_CAPACITY_MAX 2400 /* max. capacity selectable */ #define BATTERY_CAPACITY_INC 0 /* capacity increment */ + +/* ROLO */ +#define BOOTFILE_EXT "x20" +#define BOOTFILE "rockbox." BOOTFILE_EXT +#define BOOTDIR "/.rockbox" + diff --git a/firmware/export/config/xduoox3ii.h b/firmware/export/config/xduoox3ii.h index dab7c0f257..143d4442fd 100644 --- a/firmware/export/config/xduoox3ii.h +++ b/firmware/export/config/xduoox3ii.h @@ -122,3 +122,10 @@ #define BATTERY_CAPACITY_MIN 2000 /* min. capacity selectable */ #define BATTERY_CAPACITY_MAX 2000 /* max. capacity selectable */ #define BATTERY_CAPACITY_INC 0 /* capacity increment */ + +/* ROLO */ +#define BOOTFILE_EXT "x3ii" +#define BOOTFILE "rockbox." BOOTFILE_EXT +#define BOOTDIR "/.rockbox" + + diff --git a/firmware/export/rolo.h b/firmware/export/rolo.h index 1a06d61892..4b6c8abf64 100644 --- a/firmware/export/rolo.h +++ b/firmware/export/rolo.h @@ -21,6 +21,10 @@ #ifndef __ROLO_H__ #define __ROLO_H__ +#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(BOOTFILE) +#define HAVE_ROLO +#endif + int rolo_load(const char* file); #ifdef CPU_PP diff --git a/firmware/rolo.c b/firmware/rolo.c index 7cded0906f..50f3d68183 100644 --- a/firmware/rolo.c +++ b/firmware/rolo.c @@ -45,7 +45,7 @@ #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) #include "bootdata.h" #include "crc32.h" -extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume); /*mi4-loader.c*/ +extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume); /*mi4-loader.c*/ #endif #define LOAD_FIRMWARE(a,b,c) load_mi4(a,b,c) #elif defined(RKW_FORMAT) @@ -56,7 +56,7 @@ extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) #include "bootdata.h" #include "crc32.h" -extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume); /*rb-loader.c*/ +extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume); /*rb-loader.c*/ #endif #define LOAD_FIRMWARE(a,b,c) load_firmware(a,b,c) #endif @@ -98,7 +98,7 @@ void rolo_restart_cop(void) /* Invalidate cache */ commit_discard_idcache(); - + /* Disable cache */ CACHE_CTL = CACHE_CTL_DISABLE; diff --git a/firmware/target/hosted/rolo.c b/firmware/target/hosted/rolo.c new file mode 100644 index 0000000000..432d69c86e --- /dev/null +++ b/firmware/target/hosted/rolo.c @@ -0,0 +1,102 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2020 Solomon Peachy + * + * 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 "config.h" +#include "lcd.h" +#ifdef HAVE_REMOTE_LCD +#include "lcd-remote.h" +#endif +#include "audio.h" +#include "button.h" +#include "scroll_engine.h" +#include "storage.h" +#include "rolo.h" +#include "rbpaths.h" + +#include +#include + +#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) +#include "bootdata.h" +#include "crc32.h" +extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume); /*rb-loader.c*/ +#endif + +static void rolo_error(const char *text, const char *text2) +{ + lcd_clear_display(); + lcd_puts(0, 0, "ROLO error:"); + lcd_puts_scroll(0, 1, text); + if (text2) + lcd_puts_scroll(0, 2, text2); + lcd_update(); + button_get(true); + button_get(true); + button_get(true); + lcd_scroll_stop(); +} + +int rolo_load(const char* filename) +{ + lcd_clear_display(); + lcd_puts(0, 0, "ROLO..."); + lcd_puts(0, 1, "Loading"); + lcd_update(); +#ifdef HAVE_REMOTE_LCD + lcd_remote_clear_display(); + lcd_remote_puts(0, 0, "ROLO..."); + lcd_remote_puts(0, 1, "Loading"); + lcd_remote_update(); +#endif + + audio_stop(); + +#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) + /* write the bootdata as if rolo were the bootloader */ + unsigned int crc = 0; + if (strcmp(filename, BOOTDIR "/" BOOTFILE) == 0) + crc = crc_32(boot_data.payload, boot_data.length, 0xffffffff); + + if(crc > 0 && crc == boot_data.crc) + write_bootdata(filebuf, filebuf_size, boot_data.boot_volume); /* rb-loader.c */ +#endif + +#ifdef HAVE_STORAGE_FLUSH + lcd_puts(0, 1, "Flushing storage buffers"); + lcd_update(); + storage_flush(); +#endif + + lcd_puts(0, 1, "Executing"); + lcd_update(); +#ifdef HAVE_REMOTE_LCD + lcd_remote_puts(0, 1, "Executing"); + lcd_remote_update(); +#endif + + char buf[256]; + snprintf(buf, sizeof(buf), "%s/%s", HOME_DIR, filename); + execl(buf, BOOTFILE, NULL); + + rolo_error("Failed to launch!", strerror(errno)); + + /* never reached */ + return 0; +}