diff options
Diffstat (limited to 'apps/plugin.c')
-rw-r--r-- | apps/plugin.c | 135 |
1 files changed, 64 insertions, 71 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index 9a20827e26..0997b0a901 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -78,13 +78,8 @@ static bool plugin_loaded = false; | |||
78 | static int plugin_size = 0; | 78 | static int plugin_size = 0; |
79 | static void (*pfn_tsr_exit)(void) = NULL; /* TSR exit callback */ | 79 | static void (*pfn_tsr_exit)(void) = NULL; /* TSR exit callback */ |
80 | 80 | ||
81 | static int plugin_test(int api_version, int model, int memsize); | ||
82 | |||
83 | static const struct plugin_api rockbox_api = { | 81 | static const struct plugin_api rockbox_api = { |
84 | PLUGIN_API_VERSION, | ||
85 | 82 | ||
86 | plugin_test, | ||
87 | |||
88 | /* lcd */ | 83 | /* lcd */ |
89 | lcd_set_contrast, | 84 | lcd_set_contrast, |
90 | lcd_clear_display, | 85 | lcd_clear_display, |
@@ -135,6 +130,7 @@ static const struct plugin_api rockbox_api = { | |||
135 | checkbox, | 130 | checkbox, |
136 | font_get, | 131 | font_get, |
137 | font_getstringsize, | 132 | font_getstringsize, |
133 | font_get_width, | ||
138 | #endif | 134 | #endif |
139 | backlight_on, | 135 | backlight_on, |
140 | backlight_off, | 136 | backlight_off, |
@@ -243,9 +239,18 @@ static const struct plugin_api rockbox_api = { | |||
243 | strcat, | 239 | strcat, |
244 | memcmp, | 240 | memcmp, |
245 | strcasestr, | 241 | strcasestr, |
242 | /* unicode stuff */ | ||
243 | utf8decode, | ||
244 | iso_decode, | ||
245 | utf16LEdecode, | ||
246 | utf16BEdecode, | ||
247 | utf8encode, | ||
248 | utf8length, | ||
246 | 249 | ||
247 | /* sound */ | 250 | /* sound */ |
248 | sound_set, | 251 | sound_set, |
252 | sound_min, | ||
253 | sound_max, | ||
249 | #ifndef SIMULATOR | 254 | #ifndef SIMULATOR |
250 | mp3_play_data, | 255 | mp3_play_data, |
251 | mp3_play_pause, | 256 | mp3_play_pause, |
@@ -307,6 +312,21 @@ static const struct plugin_api rockbox_api = { | |||
307 | &rundb_fd, | 312 | &rundb_fd, |
308 | &rundb_initialized, | 313 | &rundb_initialized, |
309 | 314 | ||
315 | /* menu */ | ||
316 | menu_init, | ||
317 | menu_exit, | ||
318 | menu_show, | ||
319 | menu_run, | ||
320 | menu_cursor, | ||
321 | menu_description, | ||
322 | menu_delete, | ||
323 | menu_count, | ||
324 | menu_moveup, | ||
325 | menu_movedown, | ||
326 | menu_draw, | ||
327 | menu_insert, | ||
328 | menu_set_cursor, | ||
329 | |||
310 | /* misc */ | 330 | /* misc */ |
311 | srand, | 331 | srand, |
312 | rand, | 332 | rand, |
@@ -337,39 +357,13 @@ static const struct plugin_api rockbox_api = { | |||
337 | #endif | 357 | #endif |
338 | #ifdef HAVE_LCD_BITMAP | 358 | #ifdef HAVE_LCD_BITMAP |
339 | read_bmp_file, | 359 | read_bmp_file, |
360 | screen_dump_set_hook, | ||
340 | #endif | 361 | #endif |
341 | show_logo, | 362 | show_logo, |
342 | 363 | ||
343 | /* new stuff at the end, sort into place next time | 364 | /* new stuff at the end, sort into place next time |
344 | the API gets incompatible */ | 365 | the API gets incompatible */ |
345 | 366 | ||
346 | menu_init, | ||
347 | menu_exit, | ||
348 | menu_show, | ||
349 | menu_run, | ||
350 | menu_cursor, | ||
351 | menu_description, | ||
352 | menu_delete, | ||
353 | menu_count, | ||
354 | menu_moveup, | ||
355 | menu_movedown, | ||
356 | menu_draw, | ||
357 | menu_insert, | ||
358 | menu_set_cursor, | ||
359 | |||
360 | #ifdef HAVE_LCD_BITMAP | ||
361 | screen_dump_set_hook, | ||
362 | font_get_width, | ||
363 | #endif | ||
364 | utf8decode, | ||
365 | iso_decode, | ||
366 | utf16LEdecode, | ||
367 | utf16BEdecode, | ||
368 | utf8encode, | ||
369 | utf8length, | ||
370 | |||
371 | sound_min, | ||
372 | sound_max, | ||
373 | }; | 367 | }; |
374 | 368 | ||
375 | int plugin_load(const char* plugin, void* parameter) | 369 | int plugin_load(const char* plugin, void* parameter) |
@@ -377,7 +371,8 @@ int plugin_load(const char* plugin, void* parameter) | |||
377 | enum plugin_status (*plugin_start)(struct plugin_api* api, void* param); | 371 | enum plugin_status (*plugin_start)(struct plugin_api* api, void* param); |
378 | int rc; | 372 | int rc; |
379 | #ifndef SIMULATOR | 373 | #ifndef SIMULATOR |
380 | char buf[64]; | 374 | struct plugin_header header; |
375 | ssize_t readsize; | ||
381 | #endif | 376 | #endif |
382 | int fd; | 377 | int fd; |
383 | 378 | ||
@@ -408,28 +403,50 @@ int plugin_load(const char* plugin, void* parameter) | |||
408 | #else | 403 | #else |
409 | fd = open(plugin, O_RDONLY); | 404 | fd = open(plugin, O_RDONLY); |
410 | if (fd < 0) { | 405 | if (fd < 0) { |
411 | snprintf(buf, sizeof buf, str(LANG_PLUGIN_CANT_OPEN), plugin); | 406 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin); |
412 | gui_syncsplash(HZ*2, true, buf); | ||
413 | return fd; | 407 | return fd; |
414 | } | 408 | } |
415 | 409 | ||
410 | readsize = read(fd, &header, sizeof(header)); | ||
411 | close(fd); | ||
412 | /* Close for now. Less code than doing it in all error checks. | ||
413 | * Would need to seek back anyway. */ | ||
414 | |||
415 | if (readsize != sizeof(header)) { | ||
416 | gui_syncsplash(HZ*2, true, str(LANG_READ_FAILED), plugin); | ||
417 | return -1; | ||
418 | } | ||
419 | if (header.magic != PLUGIN_MAGIC | ||
420 | || header.target_id != TARGET_ID | ||
421 | || header.load_addr != pluginbuf | ||
422 | || header.end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) { | ||
423 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL)); | ||
424 | return -1; | ||
425 | } | ||
426 | if (header.api_version > PLUGIN_API_VERSION | ||
427 | || header.api_version < PLUGIN_MIN_API_VERSION) { | ||
428 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION)); | ||
429 | return -1; | ||
430 | } | ||
431 | |||
416 | /* zero out plugin buffer to ensure a properly zeroed bss area */ | 432 | /* zero out plugin buffer to ensure a properly zeroed bss area */ |
417 | memset(pluginbuf, 0, PLUGIN_BUFFER_SIZE); | 433 | memset(pluginbuf, 0, header.end_addr - pluginbuf); |
418 | 434 | ||
419 | plugin_start = (void*)&pluginbuf; | 435 | fd = open(plugin, O_RDONLY); |
420 | plugin_size = read(fd, plugin_start, PLUGIN_BUFFER_SIZE); | 436 | if (fd < 0) { |
437 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin); | ||
438 | return fd; | ||
439 | } | ||
440 | readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE); | ||
421 | close(fd); | 441 | close(fd); |
422 | if (plugin_size < 0) { | 442 | |
443 | if (readsize < 0) { | ||
423 | /* read error */ | 444 | /* read error */ |
424 | snprintf(buf, sizeof buf, str(LANG_READ_FAILED), plugin); | 445 | gui_syncsplash(HZ*2, true, str(LANG_READ_FAILED), plugin); |
425 | gui_syncsplash(HZ*2, true, buf); | ||
426 | return -1; | ||
427 | } | ||
428 | if (plugin_size == 0) { | ||
429 | /* loaded a 0-byte plugin, implying it's not for this model */ | ||
430 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL)); | ||
431 | return -1; | 446 | return -1; |
432 | } | 447 | } |
448 | plugin_start = header.entry_point; | ||
449 | plugin_size = header.end_addr - header.load_addr; | ||
433 | #endif | 450 | #endif |
434 | 451 | ||
435 | plugin_loaded = true; | 452 | plugin_loaded = true; |
@@ -458,14 +475,6 @@ int plugin_load(const char* plugin, void* parameter) | |||
458 | case PLUGIN_USB_CONNECTED: | 475 | case PLUGIN_USB_CONNECTED: |
459 | return PLUGIN_USB_CONNECTED; | 476 | return PLUGIN_USB_CONNECTED; |
460 | 477 | ||
461 | case PLUGIN_WRONG_API_VERSION: | ||
462 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION)); | ||
463 | break; | ||
464 | |||
465 | case PLUGIN_WRONG_MODEL: | ||
466 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL)); | ||
467 | break; | ||
468 | |||
469 | default: | 478 | default: |
470 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_ERROR)); | 479 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_ERROR)); |
471 | break; | 480 | break; |
@@ -521,19 +530,3 @@ void plugin_tsr(void (*exit_callback)(void)) | |||
521 | { | 530 | { |
522 | pfn_tsr_exit = exit_callback; /* remember the callback for later */ | 531 | pfn_tsr_exit = exit_callback; /* remember the callback for later */ |
523 | } | 532 | } |
524 | |||
525 | |||
526 | static int plugin_test(int api_version, int model, int memsize) | ||
527 | { | ||
528 | if (api_version < PLUGIN_MIN_API_VERSION || | ||
529 | api_version > PLUGIN_API_VERSION) | ||
530 | return PLUGIN_WRONG_API_VERSION; | ||
531 | |||
532 | if (model != MODEL) | ||
533 | return PLUGIN_WRONG_MODEL; | ||
534 | |||
535 | if (memsize != MEM) | ||
536 | return PLUGIN_WRONG_MODEL; | ||
537 | |||
538 | return PLUGIN_OK; | ||
539 | } | ||