Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:16

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup rtems_rtld
0007  *
0008  * @brief RTEMS Application Loader.
0009  *
0010  * Shell command wrappers for the RTEMS Application loader.
0011  */
0012 
0013 /*
0014  *  COPYRIGHT (c) 2013 Chris Johns <chrisj@rtems.org>
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #ifdef HAVE_CONFIG_H
0039 #include "config.h"
0040 #endif
0041 
0042 #include <stdbool.h>
0043 #include <stdio.h>
0044 #include <stdlib.h>
0045 #include <string.h>
0046 
0047 #include <rtems/rtl/rap.h>
0048 #include <rtems/rtl/rap-shell.h>
0049 
0050 static void
0051 shell_rap_command_help (void)
0052 {
0053   printf ("usage: rap [cmd] [arg]\n" \
0054           "Commands and options:\n" \
0055           "ls:   List the loaded applications (also list)\n" \
0056           "ld:   Load an application (also load)\n" \
0057           "un:   Unload an application (also unload)\n");
0058 }
0059 
0060 static void
0061 shell_rap_get_error (const char* what)
0062 {
0063   char message[64];
0064   int  error;
0065   error = rtems_rap_get_error (message, sizeof (message));
0066   printf ("error: %s: (%d) %s\n", what, error, message);
0067 }
0068 
0069 static bool
0070 shell_rap_list_handler (void* handle)
0071 {
0072   printf (" %-10p %-10p %-s\n",
0073           handle, rtems_rap_dl_handle (handle), rtems_rap_name (handle));
0074   return true;
0075 }
0076 
0077 static int
0078 shell_rap_list (int argc, char* argv[])
0079 {
0080   printf (" App        DL Handle  Name\n");
0081   return rtems_rap_iterate (shell_rap_list_handler) ? 0 : 1;
0082 }
0083 
0084 static int
0085 shell_rap_load (int argc, char* argv[])
0086 {
0087   int r = 0;
0088   if (argc == 0)
0089   {
0090     printf ("error: no application name\n");
0091     return 0;
0092   }
0093   if (rtems_rap_load (argv[0], 0, argc - 1, (const char**) (argv + 1)))
0094     printf ("%s loaded\n", argv[0]);
0095   else
0096   {
0097     r = 1;
0098     shell_rap_get_error ("loading");
0099   }
0100   return r;
0101 }
0102 
0103 int
0104 shell_rap (int argc, char* argv[])
0105 {
0106   if (argc == 1)
0107   {
0108     shell_rap_command_help ();
0109     return 0;
0110   }
0111 
0112   if ((strcmp (argv[1], "ls") == 0) ||
0113       (strcmp (argv[1], "list") == 0))
0114   {
0115     return shell_rap_list (argc - 2, argv + 2);
0116   }
0117   else if ((strcmp (argv[1], "ld") == 0) ||
0118            (strcmp (argv[1], "load") == 0))
0119   {
0120     return shell_rap_load (argc - 2, argv + 2);
0121   }
0122 
0123   printf ("error: invalid command: %s\n", argv[1]);
0124   return 0;
0125 }
0126