source: rtems/cpukit/libmisc/shell/main_rtems.c @ 071640d

Last change on this file since 071640d was 071640d, checked in by Chris Johns <chrisj@…>, on 08/02/22 at 11:00:09

libmisc/shell: Add an 'rtems' command to report a running build

  • Report version, cpu, bsp, tools and options.
  • Property mode set to 100644
File size: 4.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup
7 *
8 * @brief This source file contains the kernel command.
9 */
10
11/*
12 * Copyright (c) 2022 Chris Johns.  All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <errno.h>
40
41#include <rtems.h>
42#include <rtems/shell.h>
43#include <rtems/version.h>
44
45static void kernel_summary(void) {
46  printf(
47    "RTEMS: %d.%d.%d",
48    rtems_version_major(), rtems_version_minor(), rtems_version_revision());
49  if (rtems_version_control_key_is_valid(rtems_version_control_key())) {
50    printf(" (%s)", rtems_version_control_key());
51  }
52#if RTEMS_SMP
53    printf(" SMP:%d cores", rtems_scheduler_get_processor_maximum());
54#endif
55    printf("\n");
56}
57
58static void cpu_summary(void) {
59  printf("CPU: " CPU_NAME " (" CPU_MODEL_NAME ")\n");
60}
61
62static void bsp_summary(void) {
63  printf("BSP: %s\n", rtems_board_support_package());
64}
65
66static void tools_summary(void) {
67  printf( "Tools: " __VERSION__ "\n");
68}
69
70static void opts_summary(void) {
71  printf("Options:"
72#if RTEMS_DEBUG
73         " DEBUG"
74#endif
75#if RTEMS_MULTIPROCESSING
76         " MULTIPROCESSING"
77#endif
78#if RTEMS_NETWORKING
79         " NETWORKING"
80#endif
81#if RTEMS_PARAVIRT
82         " PARAVIRT"
83#endif
84#if RTEMS_POSIX_API
85         " POSIX"
86#endif
87#if RTEMS_PROFILING
88         " PROFILING"
89#endif
90#if RTEMS_SMP
91         " SMP"
92#endif
93         "\n");
94}
95
96static void help(void) {
97  printf( "Usage:: rtems <command>\n");
98  printf( " where <command> is:\n");
99  printf( "  help   : this help\n");
100  printf( "  ver    : kernel version\n");
101  printf( "  cpu    : kernel version\n");
102  printf( "  bsp    : BSP name\n");
103  printf( "  tools  : tools version\n");
104  printf( "  opts   : options\n");
105  printf( "  all    : all commands\n");
106}
107
108static int rtems_shell_main_rtems(
109  int argc, char *argv[]) {
110
111  if (argc == 1) {
112    kernel_summary();
113  } else if (argc == 2) {
114    if (strcmp(argv[1], "help") == 0) {
115      help();
116    } else if (strcmp(argv[1], "ver") == 0) {
117      kernel_summary();
118    } else if (strcmp(argv[1], "cpu") == 0) {
119      cpu_summary();
120    } else if (strcmp(argv[1], "bsp") == 0) {
121      bsp_summary();
122    } else if (strcmp(argv[1], "tools") == 0) {
123      tools_summary();
124    } else if (strcmp(argv[1], "opts") == 0) {
125      opts_summary();
126    } else if (strcmp(argv[1], "all") == 0) {
127      kernel_summary();
128      cpu_summary();
129      bsp_summary();
130      tools_summary();
131      opts_summary();
132    } else {
133      printf("error: invalid command\n");
134      return 1;
135    }
136  } else {
137    printf("error: invalid command\n");
138    return 1;
139  }
140  return 0;
141}
142
143#define HELP_LINE \
144  "rtems <command> (eg. help)"
145
146rtems_shell_cmd_t rtems_shell_RTEMS_Command = {
147  "rtems",                             /* name */
148  HELP_LINE,                           /* usage */
149  "rtems",                             /* topic */
150  rtems_shell_main_rtems,              /* command */
151  NULL,                                /* alias */
152  NULL,                                /* next */
153  0500,                                /* mode */
154  0,                                   /* uid */
155  0                                    /* gid */
156};
Note: See TracBrowser for help on using the repository browser.