Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup
0007  *
0008  * @brief This source file contains the kernel command.
0009  */
0010 
0011 /*
0012  * Copyright (c) 2022 Chris Johns.  All rights reserved.
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <string.h>
0039 #include <errno.h>
0040 
0041 #include <rtems.h>
0042 #include <rtems/shell.h>
0043 #include <rtems/version.h>
0044 
0045 static void kernel_summary(void) {
0046   printf(
0047     "RTEMS: %d.%d.%d",
0048     rtems_version_major(), rtems_version_minor(), rtems_version_revision());
0049   if (rtems_version_release_label_is_valid()) {
0050     printf(" (%s)", rtems_version_release_label());
0051   }
0052 #if RTEMS_SMP
0053     printf(" SMP:%d cores", rtems_scheduler_get_processor_maximum());
0054 #endif
0055     printf("\n");
0056 }
0057 
0058 static void cpu_summary(void) {
0059   printf("CPU: " CPU_NAME " (" CPU_MODEL_NAME ")\n");
0060 }
0061 
0062 static void bsp_summary(void) {
0063   printf("BSP: %s\n", rtems_board_support_package());
0064 }
0065 
0066 static void tools_summary(void) {
0067   printf( "Tools: " __VERSION__ "\n");
0068 }
0069 
0070 static void opts_summary(void) {
0071   printf("Options:"
0072 #if RTEMS_DEBUG
0073          " DEBUG"
0074 #endif
0075 #if RTEMS_MULTIPROCESSING
0076          " MULTIPROCESSING"
0077 #endif
0078 #if RTEMS_NETWORKING
0079          " NETWORKING"
0080 #endif
0081 #if RTEMS_PARAVIRT
0082          " PARAVIRT"
0083 #endif
0084 #if RTEMS_POSIX_API
0085          " POSIX"
0086 #endif
0087 #if RTEMS_PROFILING
0088          " PROFILING"
0089 #endif
0090 #if RTEMS_SMP
0091          " SMP"
0092 #endif
0093          "\n");
0094 }
0095 
0096 static void help(void) {
0097   printf( "Usage:: rtems <command>\n");
0098   printf( " where <command> is:\n");
0099   printf( "  help   : this help\n");
0100   printf( "  ver    : kernel version\n");
0101   printf( "  cpu    : kernel version\n");
0102   printf( "  bsp    : BSP name\n");
0103   printf( "  tools  : tools version\n");
0104   printf( "  opts   : options\n");
0105   printf( "  all    : all commands\n");
0106 }
0107 
0108 static int rtems_shell_main_rtems(
0109   int argc, char *argv[]) {
0110 
0111   if (argc == 1) {
0112     kernel_summary();
0113   } else if (argc == 2) {
0114     if (strcmp(argv[1], "help") == 0) {
0115       help();
0116     } else if (strcmp(argv[1], "ver") == 0) {
0117       kernel_summary();
0118     } else if (strcmp(argv[1], "cpu") == 0) {
0119       cpu_summary();
0120     } else if (strcmp(argv[1], "bsp") == 0) {
0121       bsp_summary();
0122     } else if (strcmp(argv[1], "tools") == 0) {
0123       tools_summary();
0124     } else if (strcmp(argv[1], "opts") == 0) {
0125       opts_summary();
0126     } else if (strcmp(argv[1], "all") == 0) {
0127       kernel_summary();
0128       cpu_summary();
0129       bsp_summary();
0130       tools_summary();
0131       opts_summary();
0132     } else {
0133       printf("error: invalid command; try `help`\n");
0134       return 1;
0135     }
0136   } else {
0137     printf("error: invalid command; try `help`\n");
0138     return 1;
0139   }
0140   return 0;
0141 }
0142 
0143 #define HELP_LINE \
0144   "rtems <command> (eg. help)"
0145 
0146 rtems_shell_cmd_t rtems_shell_RTEMS_Command = {
0147   "rtems",                             /* name */
0148   HELP_LINE,                           /* usage */
0149   "rtems",                             /* topic */
0150   rtems_shell_main_rtems,              /* command */
0151   NULL,                                /* alias */
0152   NULL,                                /* next */
0153   0500,                                /* mode */
0154   0,                                   /* uid */
0155   0                                    /* gid */
0156 };