From c6abf3382a67aa5dcb3b85abe01ad4cfbdcd717d Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Tue, 8 Sep 2026 11:22:42 +0100 Subject: [PATCH] firmware: move iriver flash helper functions into target tree Move the iriver-specific functions for detecting flashed Rockbox/OF images into system-iriver.c and remove the HAVE_FLASHED_ROCKBOX define which is now redundant (all targets using system-iriver.c enable it). Copyright attribution on the new system-iriver.h header is a best guess from Git history. Change-Id: If1933f881a63fd517162ab9ca8f4a3007b997739 --- apps/plugin.c | 4 ++ apps/plugins/iriver_flash.c | 1 + bootloader/iriver_h300.c | 1 + firmware/eeprom_settings.c | 1 + firmware/export/config/iriverh100.h | 4 -- firmware/export/config/iriverh120.h | 3 -- firmware/export/config/iriverh300.h | 3 -- firmware/export/config/sim.h | 2 - firmware/export/system.h | 10 ----- firmware/system.c | 40 ------------------- .../target/coldfire/iriver/system-iriver.c | 30 ++++++++++++++ .../target/coldfire/iriver/system-iriver.h | 37 +++++++++++++++++ 12 files changed, 74 insertions(+), 62 deletions(-) create mode 100644 firmware/target/coldfire/iriver/system-iriver.h diff --git a/apps/plugin.c b/apps/plugin.c index b62f6f3107..bdcdffbdcc 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -67,6 +67,10 @@ #include "usbstack/usb_audio.h" #endif +#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) +#include "system-iriver.h" +#endif + #define WRAPPER(_x_) _x_ ## _wrapper #if (CONFIG_PLATFORM & PLATFORM_HOSTED) diff --git a/apps/plugins/iriver_flash.c b/apps/plugins/iriver_flash.c index 1ad222bf40..2b6f70adf9 100644 --- a/apps/plugins/iriver_flash.c +++ b/apps/plugins/iriver_flash.c @@ -23,6 +23,7 @@ #include "plugin.h" #include "lib/helper.h" #include "checksum.h" +#include "system-iriver.h" /* * Flash commands may rely on null pointer dereferences to work correctly. diff --git a/bootloader/iriver_h300.c b/bootloader/iriver_h300.c index 98f72e14ca..8fb273edb2 100644 --- a/bootloader/iriver_h300.c +++ b/bootloader/iriver_h300.c @@ -25,6 +25,7 @@ #include "string.h" #include "cpu.h" #include "system.h" +#include "system-iriver.h" #include "lcd.h" #include "lcd-remote.h" #include "scroll_engine.h" diff --git a/firmware/eeprom_settings.c b/firmware/eeprom_settings.c index b2e75ebf54..abd719b89a 100644 --- a/firmware/eeprom_settings.c +++ b/firmware/eeprom_settings.c @@ -23,6 +23,7 @@ #include "crc32.h" #include "system.h" +#include "system-iriver.h" #include "string.h" #include "logf.h" diff --git a/firmware/export/config/iriverh100.h b/firmware/export/config/iriverh100.h index e8add732de..5d9b46fec9 100644 --- a/firmware/export/config/iriverh100.h +++ b/firmware/export/config/iriverh100.h @@ -141,10 +141,6 @@ /* Define this if you want to use coldfire's i2c interface */ #define CONFIG_I2C I2C_COLDFIRE -/* Define this if you can run rockbox from flash memory */ -/* In theory we can, but somebody needs to verify there are no issues. */ -#define HAVE_FLASHED_ROCKBOX - /* define this if the hardware can be powered off while charging */ #define HAVE_POWEROFF_WHILE_CHARGING diff --git a/firmware/export/config/iriverh120.h b/firmware/export/config/iriverh120.h index b591b10e83..00fba08361 100644 --- a/firmware/export/config/iriverh120.h +++ b/firmware/export/config/iriverh120.h @@ -148,9 +148,6 @@ /* Define this if you want to use coldfire's i2c interface */ #define CONFIG_I2C I2C_COLDFIRE -/* Define this if you can run rockbox from flash memory */ -#define HAVE_FLASHED_ROCKBOX - /* define this if the hardware can be powered off while charging */ #define HAVE_POWEROFF_WHILE_CHARGING diff --git a/firmware/export/config/iriverh300.h b/firmware/export/config/iriverh300.h index 4b93c62cec..572210e8f7 100644 --- a/firmware/export/config/iriverh300.h +++ b/firmware/export/config/iriverh300.h @@ -157,9 +157,6 @@ /* Define this if you want to use coldfire's i2c interface */ #define CONFIG_I2C I2C_COLDFIRE -/* Define this if you can run rockbox from flash memory */ -#define HAVE_FLASHED_ROCKBOX - /* The size of the flash ROM */ #define FLASH_SIZE 0x400000 diff --git a/firmware/export/config/sim.h b/firmware/export/config/sim.h index b4ba80a87a..fe9194da35 100644 --- a/firmware/export/config/sim.h +++ b/firmware/export/config/sim.h @@ -77,8 +77,6 @@ #undef INCLUDE_TIMEOUT_API -#undef HAVE_FLASHED_ROCKBOX - #undef IPOD_ACCESSORY_PROTOCOL #undef HAVE_WHEEL_POSITION diff --git a/firmware/export/system.h b/firmware/export/system.h index 498c0b048d..cdfa948836 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h @@ -40,16 +40,6 @@ extern void system_init(void); extern long cpu_frequency; -struct flash_header { - uint32_t magic; - uint32_t length; - char version[32]; -}; - -bool detect_flashed_romimage(void); -bool detect_flashed_ramimage(void); -bool detect_original_firmware(void); - #if defined(HAVE_ADJUSTABLE_CPU_FREQ) \ && defined(ROCKBOX_HAS_LOGF) && (NUM_CORES == 1) #define CPU_BOOST_LOGGING diff --git a/firmware/system.c b/firmware/system.c index 20c927efeb..d709bb1a02 100644 --- a/firmware/system.c +++ b/firmware/system.c @@ -161,43 +161,3 @@ void cpu_idle_mode(bool on_off) cpu_boost_unlock(); } #endif /* HAVE_ADJUSTABLE_CPU_FREQ */ - - -#ifdef HAVE_FLASHED_ROCKBOX -static bool detect_flash_header(uint8_t *addr) -{ -#ifndef BOOTLOADER - int oldmode = system_memory_guard(MEMGUARD_NONE); -#endif - struct flash_header hdr; - memcpy(&hdr, addr, sizeof(struct flash_header)); -#ifndef BOOTLOADER - system_memory_guard(oldmode); -#endif - return hdr.magic == FLASH_MAGIC; -} -#endif - -bool detect_flashed_romimage(void) -{ -#ifdef HAVE_FLASHED_ROCKBOX - return detect_flash_header((uint8_t *)FLASH_ROMIMAGE_ENTRY); -#else - return false; -#endif /* HAVE_FLASHED_ROCKBOX */ -} - -bool detect_flashed_ramimage(void) -{ -#ifdef HAVE_FLASHED_ROCKBOX - return detect_flash_header((uint8_t *)FLASH_RAMIMAGE_ENTRY); -#else - return false; -#endif /* HAVE_FLASHED_ROCKBOX */ -} - -bool detect_original_firmware(void) -{ - return !(detect_flashed_ramimage() || detect_flashed_romimage()); -} - diff --git a/firmware/target/coldfire/iriver/system-iriver.c b/firmware/target/coldfire/iriver/system-iriver.c index d16931ac1f..da709e5c38 100644 --- a/firmware/target/coldfire/iriver/system-iriver.c +++ b/firmware/target/coldfire/iriver/system-iriver.c @@ -21,9 +21,11 @@ #include "cpu.h" #include "kernel.h" #include "system.h" +#include "system-iriver.h" #include "power.h" #include "timer.h" #include "pcf50606.h" +#include /* Settings for all possible clock frequencies (with properly working timers) * NOTE: Some 5249 chips don't like having PLLDIV set to 0. We must avoid that! @@ -161,3 +163,31 @@ void cf_set_cpu_frequency(long frequency) break; } } + +static bool detect_flash_header(uint8_t *addr) +{ +#ifndef BOOTLOADER + int oldmode = system_memory_guard(MEMGUARD_NONE); +#endif + struct flash_header hdr; + memcpy(&hdr, addr, sizeof(struct flash_header)); +#ifndef BOOTLOADER + system_memory_guard(oldmode); +#endif + return hdr.magic == FLASH_MAGIC; +} + +bool detect_flashed_romimage(void) +{ + return detect_flash_header((uint8_t *)FLASH_ROMIMAGE_ENTRY); +} + +bool detect_flashed_ramimage(void) +{ + return detect_flash_header((uint8_t *)FLASH_RAMIMAGE_ENTRY); +} + +bool detect_original_firmware(void) +{ + return !(detect_flashed_ramimage() || detect_flashed_romimage()); +} diff --git a/firmware/target/coldfire/iriver/system-iriver.h b/firmware/target/coldfire/iriver/system-iriver.h new file mode 100644 index 0000000000..e87a108c35 --- /dev/null +++ b/firmware/target/coldfire/iriver/system-iriver.h @@ -0,0 +1,37 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 Miika Pekkarinen + * + * 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. + * + ****************************************************************************/ +#ifndef __SYSTEM_IRIVER_H__ +#define __SYSTEM_IRIVER_H__ + +#include +#include + +struct flash_header +{ + uint32_t magic; + uint32_t length; + char version[32]; +}; + +bool detect_flashed_romimage(void); +bool detect_flashed_ramimage(void); +bool detect_original_firmware(void); + +#endif /* __SYSTEM_IRIVER_H__ */