summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/plugin.c46
-rw-r--r--apps/plugin.h12
2 files changed, 36 insertions, 22 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 0997b0a901..a2cb0dedcb 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -369,15 +369,15 @@ static const struct plugin_api rockbox_api = {
369int plugin_load(const char* plugin, void* parameter) 369int plugin_load(const char* plugin, void* parameter)
370{ 370{
371 enum plugin_status (*plugin_start)(struct plugin_api* api, void* param); 371 enum plugin_status (*plugin_start)(struct plugin_api* api, void* param);
372 int rc; 372 int fd, rc;
373#ifndef SIMULATOR 373#ifndef SIMULATOR
374 struct plugin_header header; 374 struct plugin_header header;
375 ssize_t readsize; 375 ssize_t readsize;
376#else
377 struct plugin_header *hdr;
376#endif 378#endif
377 int fd;
378
379#ifdef HAVE_LCD_BITMAP 379#ifdef HAVE_LCD_BITMAP
380 int xm,ym; 380 int xm, ym;
381#endif 381#endif
382 382
383 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */ 383 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
@@ -397,18 +397,34 @@ int plugin_load(const char* plugin, void* parameter)
397 lcd_clear_display(); 397 lcd_clear_display();
398#endif 398#endif
399#ifdef SIMULATOR 399#ifdef SIMULATOR
400 plugin_start = sim_plugin_load((char *)plugin, &fd); 400 hdr = sim_plugin_load((char *)plugin, &fd);
401 if(!plugin_start) 401 if (!fd) {
402 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin);
402 return -1; 403 return -1;
404 }
405 if (hdr == NULL
406 || hdr->magic != PLUGIN_MAGIC
407 || hdr->target_id != TARGET_ID
408 || hdr->entry_point == NULL) {
409 sim_plugin_close(fd);
410 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL));
411 return -1;
412 }
413 if (hdr->api_version > PLUGIN_API_VERSION
414 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
415 sim_plugin_close(fd);
416 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION));
417 return -1;
418 }
419 plugin_start = hdr->entry_point;
403#else 420#else
404 fd = open(plugin, O_RDONLY); 421 fd = open(plugin, O_RDONLY);
405 if (fd < 0) { 422 if (fd < 0) {
406 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin); 423 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin);
407 return fd; 424 return fd;
408 } 425 }
409
410 readsize = read(fd, &header, sizeof(header)); 426 readsize = read(fd, &header, sizeof(header));
411 close(fd); 427 close(fd);
412 /* Close for now. Less code than doing it in all error checks. 428 /* Close for now. Less code than doing it in all error checks.
413 * Would need to seek back anyway. */ 429 * Would need to seek back anyway. */
414 430
@@ -428,7 +444,6 @@ int plugin_load(const char* plugin, void* parameter)
428 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION)); 444 gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION));
429 return -1; 445 return -1;
430 } 446 }
431
432 /* zero out plugin buffer to ensure a properly zeroed bss area */ 447 /* zero out plugin buffer to ensure a properly zeroed bss area */
433 memset(pluginbuf, 0, header.end_addr - pluginbuf); 448 memset(pluginbuf, 0, header.end_addr - pluginbuf);
434 449
@@ -445,8 +460,8 @@ int plugin_load(const char* plugin, void* parameter)
445 gui_syncsplash(HZ*2, true, str(LANG_READ_FAILED), plugin); 460 gui_syncsplash(HZ*2, true, str(LANG_READ_FAILED), plugin);
446 return -1; 461 return -1;
447 } 462 }
448 plugin_start = header.entry_point;
449 plugin_size = header.end_addr - header.load_addr; 463 plugin_size = header.end_addr - header.load_addr;
464 plugin_start = header.entry_point;
450#endif 465#endif
451 466
452 plugin_loaded = true; 467 plugin_loaded = true;
@@ -463,11 +478,15 @@ int plugin_load(const char* plugin, void* parameter)
463#else /* LCD_DEPTH == 1 */ 478#else /* LCD_DEPTH == 1 */
464 lcd_set_drawmode(DRMODE_SOLID); 479 lcd_set_drawmode(DRMODE_SOLID);
465#endif /* LCD_DEPTH */ 480#endif /* LCD_DEPTH */
481 /* restore margins */
482 lcd_setmargins(xm,ym);
466#endif /* HAVE_LCD_BITMAP */ 483#endif /* HAVE_LCD_BITMAP */
467 484
468 if (pfn_tsr_exit == NULL) 485 if (pfn_tsr_exit == NULL)
469 plugin_loaded = false; 486 plugin_loaded = false;
470 487
488 sim_plugin_close(fd);
489
471 switch (rc) { 490 switch (rc) {
472 case PLUGIN_OK: 491 case PLUGIN_OK:
473 break; 492 break;
@@ -480,13 +499,6 @@ int plugin_load(const char* plugin, void* parameter)
480 break; 499 break;
481 } 500 }
482 501
483 sim_plugin_close(fd);
484
485#ifdef HAVE_LCD_BITMAP
486 /* restore margins */
487 lcd_setmargins(xm,ym);
488#endif
489
490 return PLUGIN_OK; 502 return PLUGIN_OK;
491} 503}
492 504
diff --git a/apps/plugin.h b/apps/plugin.h
index bf8f34ab9e..69a2a79ba8 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -427,7 +427,6 @@ struct plugin_api {
427 427
428}; 428};
429 429
430#ifndef SIMULATOR
431/* plugin header */ 430/* plugin header */
432struct plugin_header { 431struct plugin_header {
433 unsigned long magic; 432 unsigned long magic;
@@ -438,6 +437,7 @@ struct plugin_header {
438 enum plugin_status(*entry_point)(struct plugin_api*, void*); 437 enum plugin_status(*entry_point)(struct plugin_api*, void*);
439}; 438};
440#ifdef PLUGIN 439#ifdef PLUGIN
440#ifndef SIMULATOR
441extern unsigned char plugin_start_addr[]; 441extern unsigned char plugin_start_addr[];
442extern unsigned char plugin_end_addr[]; 442extern unsigned char plugin_end_addr[];
443#define PLUGIN_HEADER \ 443#define PLUGIN_HEADER \
@@ -445,9 +445,12 @@ extern unsigned char plugin_end_addr[];
445 __attribute__ ((section (".header")))= { \ 445 __attribute__ ((section (".header")))= { \
446 PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \ 446 PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
447 plugin_start_addr, plugin_end_addr, plugin_start }; 447 plugin_start_addr, plugin_end_addr, plugin_start };
448#endif
449#else /* SIMULATOR */ 448#else /* SIMULATOR */
450#define PLUGIN_HEADER 449#define PLUGIN_HEADER \
450 const struct plugin_header __header = { \
451 PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
452 NULL, NULL, plugin_start };
453#endif
451#endif 454#endif
452 455
453int plugin_load(const char* plugin, void* parameter); 456int plugin_load(const char* plugin, void* parameter);
@@ -456,7 +459,6 @@ void* plugin_get_audio_buffer(int *buffer_size);
456void plugin_tsr(void (*exit_callback)(void)); 459void plugin_tsr(void (*exit_callback)(void));
457 460
458/* defined by the plugin */ 461/* defined by the plugin */
459enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter) 462enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter);
460 __attribute__ ((section (".entry")));
461 463
462#endif 464#endif