diff --git a/firmware/SOURCES b/firmware/SOURCES index 6c238fb1ca..5a540ba7ea 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -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 diff --git a/firmware/export/config.h b/firmware/export/config.h index 89b698bdfe..fd5527932a 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -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" diff --git a/firmware/export/lc-dlopen.h b/firmware/export/lc-dlopen.h new file mode 100644 index 0000000000..c92ffce4ce --- /dev/null +++ b/firmware/export/lc-dlopen.h @@ -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__ */ diff --git a/firmware/export/lc-rock.h b/firmware/export/lc-rock.h new file mode 100644 index 0000000000..bd4101cb03 --- /dev/null +++ b/firmware/export/lc-rock.h @@ -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__ */ diff --git a/firmware/export/load_code.h b/firmware/export/load_code.h index df85a81f82..c2595f7b04 100644 --- a/firmware/export/load_code.h +++ b/firmware/export/load_code.h @@ -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__ */ diff --git a/firmware/load_code.c b/firmware/lc-rock.c similarity index 100% rename from firmware/load_code.c rename to firmware/lc-rock.c