diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/rockboy.c | 63 | ||||
-rwxr-xr-x | apps/plugins/rockboy/archos.lds | 4 | ||||
-rw-r--r-- | apps/plugins/rockboy/rockboy.c | 24 |
3 files changed, 44 insertions, 47 deletions
diff --git a/apps/plugins/rockboy.c b/apps/plugins/rockboy.c index d3504572cf..f571894717 100644 --- a/apps/plugins/rockboy.c +++ b/apps/plugins/rockboy.c | |||
@@ -34,47 +34,62 @@ int audiobuf_size; | |||
34 | /* this is the plugin entry point */ | 34 | /* this is the plugin entry point */ |
35 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 35 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
36 | { | 36 | { |
37 | int fh, readsize; | 37 | int fd, readsize; |
38 | struct { | 38 | struct plugin_header header; |
39 | unsigned long magic; | ||
40 | unsigned char *start_addr; | ||
41 | unsigned char *end_addr; | ||
42 | enum plugin_status(*entry_point)(struct plugin_api*, void*); | ||
43 | } header; | ||
44 | 39 | ||
45 | rb = api; | 40 | rb = api; |
46 | 41 | ||
47 | fh = rb->open(OVL_NAME, O_RDONLY); | 42 | fd = rb->open(OVL_NAME, O_RDONLY); |
48 | if (fh < 0) | 43 | if (fd < 0) |
49 | { | 44 | { |
50 | rb->splash(2*HZ, true, "Couldn't open " OVL_DISPLAYNAME " overlay."); | 45 | rb->splash(2*HZ, true, "Can't open " OVL_NAME); |
51 | return PLUGIN_ERROR; | 46 | return PLUGIN_ERROR; |
52 | } | 47 | } |
53 | readsize = rb->read(fh, &header, sizeof(header)); | 48 | readsize = rb->read(fd, &header, sizeof(header)); |
54 | if (readsize != sizeof(header) || header.magic != 0x524f564c) | 49 | rb->close(fd); |
50 | /* Close for now. Less code than doing it in all error checks. | ||
51 | * Would need to seek back anyway. */ | ||
52 | |||
53 | if (readsize != sizeof(header)) | ||
55 | { | 54 | { |
56 | rb->close(fh); | 55 | rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed."); |
57 | rb->splash(2*HZ, true, OVL_NAME " is not a valid Rockbox overlay."); | ||
58 | return PLUGIN_ERROR; | 56 | return PLUGIN_ERROR; |
59 | } | 57 | } |
60 | 58 | if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID) | |
59 | { | ||
60 | rb->splash(2*HZ, true, OVL_DISPLAYNAME | ||
61 | " overlay: Incompatible model."); | ||
62 | return PLUGIN_ERROR; | ||
63 | } | ||
64 | if (header.api_version != PLUGIN_API_VERSION) | ||
65 | { | ||
66 | rb->splash(2*HZ, true, OVL_DISPLAYNAME | ||
67 | " overlay: Incompatible version."); | ||
68 | return PLUGIN_ERROR; | ||
69 | } | ||
70 | |||
61 | audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size); | 71 | audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size); |
62 | if (header.start_addr < audiobuf || | 72 | if (header.load_addr < audiobuf || |
63 | header.end_addr > audiobuf + audiobuf_size) | 73 | header.end_addr > audiobuf + audiobuf_size) |
64 | { | 74 | { |
65 | rb->close(fh); | ||
66 | rb->splash(2*HZ, true, OVL_DISPLAYNAME | 75 | rb->splash(2*HZ, true, OVL_DISPLAYNAME |
67 | " overlay doesn't fit into memory."); | 76 | " overlay doesn't fit into memory."); |
77 | return PLUGIN_ERROR; | ||
78 | } | ||
79 | rb->memset(header.load_addr, 0, header.end_addr - header.load_addr); | ||
80 | |||
81 | fd = rb->open(OVL_NAME, O_RDONLY); | ||
82 | if (fd < 0) | ||
83 | { | ||
84 | rb->splash(2*HZ, true, "Can't open " OVL_NAME); | ||
68 | return PLUGIN_ERROR; | 85 | return PLUGIN_ERROR; |
69 | } | 86 | } |
70 | rb->memset(header.start_addr, 0, header.end_addr - header.start_addr); | 87 | readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr); |
88 | rb->close(fd); | ||
71 | 89 | ||
72 | rb->lseek(fh, 0, SEEK_SET); | 90 | if (readsize < 0) |
73 | readsize = rb->read(fh, header.start_addr, header.end_addr - header.start_addr); | ||
74 | rb->close(fh); | ||
75 | if (readsize <= (int)sizeof(header)) | ||
76 | { | 91 | { |
77 | rb->splash(2*HZ, true, "Error loading " OVL_DISPLAYNAME " overlay."); | 92 | rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed."); |
78 | return PLUGIN_ERROR; | 93 | return PLUGIN_ERROR; |
79 | } | 94 | } |
80 | return header.entry_point(api, parameter); | 95 | return header.entry_point(api, parameter); |
diff --git a/apps/plugins/rockboy/archos.lds b/apps/plugins/rockboy/archos.lds index 55db1e2e30..24f4f1d4eb 100755 --- a/apps/plugins/rockboy/archos.lds +++ b/apps/plugins/rockboy/archos.lds | |||
@@ -19,7 +19,7 @@ MEMORY | |||
19 | SECTIONS | 19 | SECTIONS |
20 | { | 20 | { |
21 | .header : { | 21 | .header : { |
22 | _ovl_start_addr = .; | 22 | _plugin_start_addr = .; |
23 | *(.header) | 23 | *(.header) |
24 | } > OVERLAY_RAM | 24 | } > OVERLAY_RAM |
25 | 25 | ||
@@ -42,6 +42,6 @@ SECTIONS | |||
42 | *(.bss) | 42 | *(.bss) |
43 | *(COMMON) | 43 | *(COMMON) |
44 | . = ALIGN(0x4); | 44 | . = ALIGN(0x4); |
45 | _ovl_end_addr = .; | 45 | _plugin_end_addr = .; |
46 | } > OVERLAY_RAM | 46 | } > OVERLAY_RAM |
47 | } | 47 | } |
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c index a21e9e4368..a7e9bfb8f1 100644 --- a/apps/plugins/rockboy/rockboy.c +++ b/apps/plugins/rockboy/rockboy.c | |||
@@ -20,25 +20,7 @@ | |||
20 | #include "loader.h" | 20 | #include "loader.h" |
21 | #include "rockmacros.h" | 21 | #include "rockmacros.h" |
22 | 22 | ||
23 | #if MEM <= 8 && !defined(SIMULATOR) | ||
24 | /* On archos this is loaded as an overlay */ | ||
25 | |||
26 | /* These are defined in the linker script */ | ||
27 | extern unsigned char ovl_start_addr[]; | ||
28 | extern unsigned char ovl_end_addr[]; | ||
29 | |||
30 | const struct { | ||
31 | unsigned long magic; | ||
32 | unsigned char *start_addr; | ||
33 | unsigned char *end_addr; | ||
34 | enum plugin_status (*entry_point)(struct plugin_api*, void*); | ||
35 | } header __attribute__ ((section (".header"))) = { | ||
36 | 0x524f564c, /* ROVL */ | ||
37 | ovl_start_addr, ovl_end_addr, plugin_start | ||
38 | }; | ||
39 | #else | ||
40 | PLUGIN_HEADER | 23 | PLUGIN_HEADER |
41 | #endif | ||
42 | 24 | ||
43 | #ifdef USE_IRAM | 25 | #ifdef USE_IRAM |
44 | extern char iramcopy[]; | 26 | extern char iramcopy[]; |
@@ -109,10 +91,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
109 | audio_bufferbase = audio_bufferpointer | 91 | audio_bufferbase = audio_bufferpointer |
110 | = rb->plugin_get_audio_buffer((int *)&audio_buffer_free); | 92 | = rb->plugin_get_audio_buffer((int *)&audio_buffer_free); |
111 | #if MEM <= 8 && !defined(SIMULATOR) | 93 | #if MEM <= 8 && !defined(SIMULATOR) |
112 | /* loaded as an overlay, protect from overwriting ourselves */ | 94 | /* loaded as an overlay plugin, protect from overwriting ourselves */ |
113 | if ((unsigned)(ovl_start_addr - (unsigned char *)audio_bufferbase) | 95 | if ((unsigned)(plugin_start_addr - (unsigned char *)audio_bufferbase) |
114 | < audio_buffer_free) | 96 | < audio_buffer_free) |
115 | audio_buffer_free = ovl_start_addr - (unsigned char *)audio_bufferbase; | 97 | audio_buffer_free = plugin_start_addr - (unsigned char *)audio_bufferbase; |
116 | #endif | 98 | #endif |
117 | 99 | ||
118 | #ifdef USE_IRAM | 100 | #ifdef USE_IRAM |