firmware: introduce CONFIG_BINFMT

Add CONFIG_BINFMT to select the binary format used for
plugins/codecs and define two options for the existing
implementations (native ".rock" format or dlopen-based).

Split the load_code.h header into two separate headers
to make it look less messy.

Change-Id: Ibd66773160df35a8c6f29a617d12c961bdabf317
This commit is contained in:
Aidan MacDonald 2026-01-04 13:36:21 +00:00 committed by Solomon Peachy
parent 8b6491db57
commit 3d0888875e
6 changed files with 116 additions and 39 deletions

View file

@ -36,7 +36,6 @@ usb.c
logf.c
#endif /* ROCKBOX_HAS_LOGF */
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
load_code.c
linuxboot.c
#ifdef RB_PROFILE
profile.c
@ -55,6 +54,10 @@ panic.c
target/hosted/rolo.c
#endif
#if CONFIG_BINFMT == BINFMT_ROCK
lc-rock.c
#endif
#if defined(HAVE_BOOTDATA) || defined(HAVE_MULTIBOOT)
common/multiboot.c
#ifndef BOOTLOADER

View file

@ -401,6 +401,10 @@ Lyre prototype 1 */
#define BUFLIB_BACKEND_MEMPOOL 0 /* Default memory pool backed buflib */
#define BUFLIB_BACKEND_MALLOC 1 /* malloc() buflib (for debugging) */
/* CONFIG_BINFMT */
#define BINFMT_ROCK 0 /* Rockbox ".rock" format */
#define BINFMT_DLOPEN 1 /* dlopen-based */
/* now go and pick yours */
#if defined(IRIVER_H100)
#include "config/iriverh100.h"
@ -675,6 +679,16 @@ Lyre prototype 1 */
#define CONFIG_PLATFORM PLATFORM_NATIVE
#endif
#ifndef CONFIG_BINFMT
# if (CONFIG_PLATFORM & PLATFORM_NATIVE)
# define CONFIG_BINFMT BINFMT_ROCK
# elif (CONFIG_PLATFORM & PLATFORM_HOSTED)
# define CONFIG_BINFMT BINFMT_DLOPEN
# else
# error "CONFIG_BINFMT not defined!"
# endif
#endif
/* setup basic macros from capability masks */
#include "config_caps.h"

View file

@ -0,0 +1,41 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2010 by Thomas Martitz
*
* 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 __LC_DLOPEN_H__
#define __LC_DLOPEN_H__
#include "system.h"
void *lc_open(const char *filename, unsigned char *buf, size_t buf_size);
void *lc_get_header(void *handle);
void lc_close(void *handle);
#ifdef APPLICATION
/* App doesn't simulate code loading from a buffer */
static inline void * lc_open_from_mem(void *addr, size_t blob_size)
{
return NULL;
(void)addr; (void)blob_size;
}
#else
void *lc_open_from_mem(void* addr, size_t blob_size);
#endif
#endif /* __LC_DLOPEN_H__ */

49
firmware/export/lc-rock.h Normal file
View file

@ -0,0 +1,49 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2010 by Thomas Martitz
*
* 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 __LC_ROCK_H__
#define __LC_ROCK_H__
#include "system.h"
void *lc_open(const char *filename, unsigned char *buf, size_t buf_size);
/* header is always at the beginning of the blob, and handle actually points
* to the start of the blob (the header is there) */
static inline void *lc_open_from_mem(void* addr, size_t blob_size)
{
(void)blob_size;
/* commit dcache and discard icache */
commit_discard_idcache();
return addr;
}
static inline void *lc_get_header(void *handle)
{
return handle;
}
/* no need to do anything */
static inline void lc_close(void *handle)
{
(void)handle;
}
#endif /* __LC_ROCK_H__ */

View file

@ -18,49 +18,11 @@
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __LOAD_CODE_H__
#define __LOAD_CODE_H__
#include "config.h"
extern void *lc_open(const char *filename, unsigned char *buf, size_t buf_size);
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
#include "system.h"
/* header is always at the beginning of the blob, and handle actually points
* to the start of the blob (the header is there) */
static inline void *lc_open_from_mem(void* addr, size_t blob_size)
{
(void)blob_size;
/* commit dcache and discard icache */
commit_discard_idcache();
return addr;
}
static inline void *lc_get_header(void *handle) { return handle; }
/* no need to do anything */
static inline void lc_close(void *handle) { (void)handle; }
#elif (CONFIG_PLATFORM & PLATFORM_HOSTED)
#ifdef APPLICATION
/* App doesn't simulate code loading from a buffer */
static inline void * lc_open_from_mem(void *addr, size_t blob_size)
{
return NULL;
(void)addr; (void)blob_size;
}
#else
extern void *lc_open_from_mem(void* addr, size_t blob_size);
#endif
extern void *lc_get_header(void *handle);
extern void lc_close(void *handle);
#endif
/* this struct needs to be the first part of other headers
* (lc_open() casts the other header to this one to load to the correct
* address)
@ -73,4 +35,12 @@ struct lc_header {
unsigned char *end_addr;
};
#if CONFIG_BINFMT == BINFMT_ROCK
# include "lc-rock.h"
#elif CONFIG_BINFMT == BINFMT_DLOPEN
# include "lc-dlopen.h"
#else
# error "Unsupported CONFIG_BINFMT!"
#endif
#endif /* __LOAD_CODE_H__ */