1 | /* |
---|
2 | * COPYRIGHT (c) 2013 Chris Johns <chrisj@rtems.org> |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.com/license/LICENSE. |
---|
7 | */ |
---|
8 | /** |
---|
9 | * @file |
---|
10 | * |
---|
11 | * @ingroup rtems_rtld |
---|
12 | * |
---|
13 | * @brief RTEMS Application Loader. |
---|
14 | * |
---|
15 | * Shell command wrappers for the RTEMS Application loader. |
---|
16 | */ |
---|
17 | |
---|
18 | #if HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <stdbool.h> |
---|
23 | #include <stdio.h> |
---|
24 | #include <stdlib.h> |
---|
25 | #include <string.h> |
---|
26 | |
---|
27 | #include <rtems/rtl/rap.h> |
---|
28 | #include <rtems/rtl/rap-shell.h> |
---|
29 | |
---|
30 | static void |
---|
31 | shell_rap_command_help (void) |
---|
32 | { |
---|
33 | printf ("usage: rap [cmd] [arg]\n" \ |
---|
34 | "Commands and options:\n" \ |
---|
35 | "ls: List the loaded applications (also list)\n" \ |
---|
36 | "ld: Load an application (also load)\n" \ |
---|
37 | "un: Unload an application (also unload)\n"); |
---|
38 | } |
---|
39 | |
---|
40 | static void |
---|
41 | shell_rap_get_error (const char* what) |
---|
42 | { |
---|
43 | char message[64]; |
---|
44 | int error; |
---|
45 | error = rtems_rap_get_error (message, sizeof (message)); |
---|
46 | printf ("error: %s: (%d) %s\n", what, error, message); |
---|
47 | } |
---|
48 | |
---|
49 | static bool |
---|
50 | shell_rap_list_handler (void* handle) |
---|
51 | { |
---|
52 | printf (" %-10p %-10p %-s\n", |
---|
53 | handle, rtems_rap_dl_handle (handle), rtems_rap_name (handle)); |
---|
54 | return true; |
---|
55 | } |
---|
56 | |
---|
57 | static int |
---|
58 | shell_rap_list (int argc, char* argv[]) |
---|
59 | { |
---|
60 | printf (" App DL Handle Name\n"); |
---|
61 | return rtems_rap_iterate (shell_rap_list_handler) ? 0 : 1; |
---|
62 | } |
---|
63 | |
---|
64 | static int |
---|
65 | shell_rap_load (int argc, char* argv[]) |
---|
66 | { |
---|
67 | int r = 0; |
---|
68 | if (argc == 0) |
---|
69 | { |
---|
70 | printf ("error: no application name\n"); |
---|
71 | return 0; |
---|
72 | } |
---|
73 | if (rtems_rap_load (argv[0], 0, argc - 1, (const char**) (argv + 1))) |
---|
74 | printf ("%s loaded\n", argv[0]); |
---|
75 | else |
---|
76 | { |
---|
77 | r = 1; |
---|
78 | shell_rap_get_error ("loading"); |
---|
79 | } |
---|
80 | return r; |
---|
81 | } |
---|
82 | |
---|
83 | int |
---|
84 | shell_rap (int argc, char* argv[]) |
---|
85 | { |
---|
86 | if (argc == 1) |
---|
87 | { |
---|
88 | shell_rap_command_help (); |
---|
89 | return 0; |
---|
90 | } |
---|
91 | |
---|
92 | if ((strcmp (argv[1], "ls") == 0) || |
---|
93 | (strcmp (argv[1], "list") == 0)) |
---|
94 | { |
---|
95 | return shell_rap_list (argc - 2, argv + 2); |
---|
96 | } |
---|
97 | else if ((strcmp (argv[1], "ld") == 0) || |
---|
98 | (strcmp (argv[1], "load") == 0)) |
---|
99 | { |
---|
100 | return shell_rap_load (argc - 2, argv + 2); |
---|
101 | } |
---|
102 | |
---|
103 | printf ("error: invalid command: %s\n", argv[1]); |
---|
104 | return 0; |
---|
105 | } |
---|
106 | |
---|