X-Git-Url: http://rtime.felk.cvut.cz/gitweb/rtems-devel.git/blobdiff_plain/0369e379945015135d5efed39375c48c32711c76..refs/heads/master:/rtems-omk-template/appdl/init.c diff --git a/rtems-omk-template/appdl/init.c b/rtems-omk-template/appdl/init.c index 0b798d9..206e06b 100644 --- a/rtems-omk-template/appdl/init.c +++ b/rtems-omk-template/appdl/init.c @@ -6,31 +6,33 @@ * clock is required for the test, it should also be set to a known * value by this function. * - * Input parameters: NONE + * (C) 2015 Pavel Pisa * - * Output parameters: NONE - * - * COPYRIGHT (c) 1989-1999. + * Based on RTEMS example test by * On-Line Applications Research Corporation (OAR). * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.com/license/LICENSE. - * - * $Id: init.c,v 1.12.4.1 2003/09/04 18:46:30 joel Exp $ */ #define CONFIGURE_INIT #include +#include "appl_config.h" #include "system.h" #include "app_def.h" -#include "appl_config.h" #include #include +#include #include #include #include +#include + +#define USE_RTEMS_TARFS_LOAD + +#ifdef USE_RTEMS_TARFS_LOAD +#include +#else /*USE_RTEMS_TARFS_LOAD*/ #include +#endif /*USE_RTEMS_TARFS_LOAD*/ #ifdef CONFIG_OC_APP_APPDL_NET #include @@ -53,7 +55,9 @@ #define CONFIGURE_SHELL_COMMANDS_ALL #define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING #define CONFIGURE_SHELL_MOUNT_MSDOS +#ifdef CONFIG_OC_APP_APPDL_NET #define CONFIGURE_SHELL_MOUNT_NFS +#endif #include @@ -110,16 +114,74 @@ int testcmd_forshell(int argc, char **argv) return 0; } +typedef int (*call_t)(int argc, char* argv[]); + +volatile int continue_execution; + +int dlrun_forshell(int argc, char **argv) +{ + void * handle; + int unresolved; + char * message = "loaded"; + char *call_file_name; + char *call_symbol = NULL; + call_t call; + int call_ret; + + if (argc < 2) { + printf ("file to load not specified\n"); + return 1; + } + call_file_name = argv[1]; + + if (argc >= 3) + call_symbol = argv[2]; + + argc -= 2; + argv += 2; + + handle = dlopen (call_file_name, RTLD_NOW | RTLD_GLOBAL); + if (!handle) + { + printf("dlopen failed: %s\n", dlerror()); + return 1; + } + + if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0) + message = "dlinfo error checking unresolved status"; + else if (unresolved) + message = "has unresolved externals"; + + if (call_symbol == NULL) { + printf ("handle: %p %s\n", handle, message); + return 1; + } + + call = dlsym (handle, call_symbol); + if (call == NULL) + { + printf("dlsym failed: symbol %s not found\n", call_symbol); + return 1; + } + + call_ret = call(argc, argv); + + return call_ret; +} + rtems_task Init( rtems_task_argument ignored ) { rtems_status_code status; + #ifdef USE_RTEMS_TARFS_LOAD + int res; + #endif /*USE_RTEMS_TARFS_LOAD*/ printf( "\n\nRTEMS v " BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__) - "\n"); - + "\n"); + rtems_monitor_init(RTEMS_MONITOR_SUSPEND|RTEMS_MONITOR_GLOBAL); /*rtems_capture_cli_init (0);*/ @@ -131,13 +193,17 @@ rtems_task Init( #endif /*CONFIG_OC_APP_APPDL_NET*/ - printf( "Starting application " SW_VER_ID " v " + printf( "Starting application " APP_VER_ID " v " BUILD_VERSION_STRING(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH) - "\n" ); + "\n" ); + #ifdef USE_RTEMS_TARFS_LOAD + res = rtems_tarfs_load("/", (void*)(&TARFILE_START), (long)&TARFILE_SIZE); + printf("rtems_tarfs_load returned %d\n", res); + #else /*USE_RTEMS_TARFS_LOAD*/ status = Untar_FromMemory((unsigned char *)(&TARFILE_START), (long)&TARFILE_SIZE); - printf("Untar_FromMemory returned %s\n",rtems_status_text(status)); + #endif /*USE_RTEMS_TARFS_LOAD*/ Task_1_name = rtems_build_name( 'T', 'S', 'K', '1' ); @@ -161,6 +227,26 @@ rtems_task Init( "test command for shell", testcmd_forshell); + rtems_shell_add_cmd("dlrun", "rtl", + "runtime load object and run specified function", + dlrun_forshell); + + rtems_shell_add_cmd("dlopen", "rtl", + "runtime load object", + shell_dlopen); + + rtems_shell_add_cmd("dlclose", "rtl", + "close reference to loaded object", + shell_dlclose); + + rtems_shell_add_cmd("dlsym", "rtl", + "obtain reference to symbol in loaded object", + shell_dlsym); + + rtems_shell_add_cmd("dlcall", "rtl", + "call function in loaded object", + shell_dlcall); + //rtems_monitor_wakeup(); #ifdef CONFIG_OC_APP_APPDL_TELNETD @@ -177,6 +263,6 @@ rtems_task Init( status = rtems_task_delete( RTEMS_SELF ); - printf( "*** END OF TEST2 ***\n" ); + printf( "*** END OF APPDL ***\n" ); exit( 0 ); }