Archos recorders: The Rockboy overlay loader now uses the same header as the plugin loader.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8354 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2006-01-16 18:51:12 +00:00
parent b1a17a6246
commit ffb0cdc426
3 changed files with 44 additions and 47 deletions

View file

@ -34,47 +34,62 @@ int audiobuf_size;
/* this is the plugin entry point */ /* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter) enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{ {
int fh, readsize; int fd, readsize;
struct { struct plugin_header header;
unsigned long magic;
unsigned char *start_addr;
unsigned char *end_addr;
enum plugin_status(*entry_point)(struct plugin_api*, void*);
} header;
rb = api; rb = api;
fh = rb->open(OVL_NAME, O_RDONLY); fd = rb->open(OVL_NAME, O_RDONLY);
if (fh < 0) if (fd < 0)
{ {
rb->splash(2*HZ, true, "Couldn't open " OVL_DISPLAYNAME " overlay."); rb->splash(2*HZ, true, "Can't open " OVL_NAME);
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
readsize = rb->read(fh, &header, sizeof(header)); readsize = rb->read(fd, &header, sizeof(header));
if (readsize != sizeof(header) || header.magic != 0x524f564c) rb->close(fd);
/* Close for now. Less code than doing it in all error checks.
* Would need to seek back anyway. */
if (readsize != sizeof(header))
{ {
rb->close(fh); rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
rb->splash(2*HZ, true, OVL_NAME " is not a valid Rockbox overlay.");
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID)
{
rb->splash(2*HZ, true, OVL_DISPLAYNAME
" overlay: Incompatible model.");
return PLUGIN_ERROR;
}
if (header.api_version != PLUGIN_API_VERSION)
{
rb->splash(2*HZ, true, OVL_DISPLAYNAME
" overlay: Incompatible version.");
return PLUGIN_ERROR;
}
audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size); audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size);
if (header.start_addr < audiobuf || if (header.load_addr < audiobuf ||
header.end_addr > audiobuf + audiobuf_size) header.end_addr > audiobuf + audiobuf_size)
{ {
rb->close(fh);
rb->splash(2*HZ, true, OVL_DISPLAYNAME rb->splash(2*HZ, true, OVL_DISPLAYNAME
" overlay doesn't fit into memory."); " overlay doesn't fit into memory.");
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
rb->memset(header.start_addr, 0, header.end_addr - header.start_addr); rb->memset(header.load_addr, 0, header.end_addr - header.load_addr);
rb->lseek(fh, 0, SEEK_SET); fd = rb->open(OVL_NAME, O_RDONLY);
readsize = rb->read(fh, header.start_addr, header.end_addr - header.start_addr); if (fd < 0)
rb->close(fh);
if (readsize <= (int)sizeof(header))
{ {
rb->splash(2*HZ, true, "Error loading " OVL_DISPLAYNAME " overlay."); rb->splash(2*HZ, true, "Can't open " OVL_NAME);
return PLUGIN_ERROR;
}
readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr);
rb->close(fd);
if (readsize < 0)
{
rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
return header.entry_point(api, parameter); return header.entry_point(api, parameter);

View file

@ -19,7 +19,7 @@ MEMORY
SECTIONS SECTIONS
{ {
.header : { .header : {
_ovl_start_addr = .; _plugin_start_addr = .;
*(.header) *(.header)
} > OVERLAY_RAM } > OVERLAY_RAM
@ -42,6 +42,6 @@ SECTIONS
*(.bss) *(.bss)
*(COMMON) *(COMMON)
. = ALIGN(0x4); . = ALIGN(0x4);
_ovl_end_addr = .; _plugin_end_addr = .;
} > OVERLAY_RAM } > OVERLAY_RAM
} }

View file

@ -20,25 +20,7 @@
#include "loader.h" #include "loader.h"
#include "rockmacros.h" #include "rockmacros.h"
#if MEM <= 8 && !defined(SIMULATOR)
/* On archos this is loaded as an overlay */
/* These are defined in the linker script */
extern unsigned char ovl_start_addr[];
extern unsigned char ovl_end_addr[];
const struct {
unsigned long magic;
unsigned char *start_addr;
unsigned char *end_addr;
enum plugin_status (*entry_point)(struct plugin_api*, void*);
} header __attribute__ ((section (".header"))) = {
0x524f564c, /* ROVL */
ovl_start_addr, ovl_end_addr, plugin_start
};
#else
PLUGIN_HEADER PLUGIN_HEADER
#endif
#ifdef USE_IRAM #ifdef USE_IRAM
extern char iramcopy[]; extern char iramcopy[];
@ -109,10 +91,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
audio_bufferbase = audio_bufferpointer audio_bufferbase = audio_bufferpointer
= rb->plugin_get_audio_buffer((int *)&audio_buffer_free); = rb->plugin_get_audio_buffer((int *)&audio_buffer_free);
#if MEM <= 8 && !defined(SIMULATOR) #if MEM <= 8 && !defined(SIMULATOR)
/* loaded as an overlay, protect from overwriting ourselves */ /* loaded as an overlay plugin, protect from overwriting ourselves */
if ((unsigned)(ovl_start_addr - (unsigned char *)audio_bufferbase) if ((unsigned)(plugin_start_addr - (unsigned char *)audio_bufferbase)
< audio_buffer_free) < audio_buffer_free)
audio_buffer_free = ovl_start_addr - (unsigned char *)audio_bufferbase; audio_buffer_free = plugin_start_addr - (unsigned char *)audio_bufferbase;
#endif #endif
#ifdef USE_IRAM #ifdef USE_IRAM