socdiag.c (2454B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * socdiag: low-level diagnostics shell for Orion (SOC) driver. 8 */ 9 10 #include <shared/bsl.h> 11 12 #include <appl/diag/system.h> 13 #include <unistd.h> 14 15 #include <sal/core/boot.h> 16 #include <sal/appl/sal.h> 17 #include <sal/appl/config.h> 18 #include <soc/debug.h> 19 20 #include <bde/pli/plibde.h> 21 22 ibde_t *bde; 23 24 int 25 bde_create(void) 26 { 27 return plibde_create(&bde); 28 } 29 30 int devlist(const char* arg); 31 32 /* 33 * Main loop. 34 */ 35 int main(int argc, char *argv[]) 36 { 37 char *socrc = SOC_INIT_RC; 38 char *config_file = NULL, *config_temp = NULL; 39 int len = 0; 40 41 if ((config_file = getenv("BCM_CONFIG_FILE")) != NULL) { 42 len = sal_strlen(config_file); 43 if ((config_temp = sal_alloc(len+5, NULL)) != NULL) { 44 sal_strncpy(config_temp, config_file, len); 45 sal_strncpy(&config_temp[len], ".tmp", 5); 46 sal_config_file_set(config_file, config_temp); 47 /* coverity[tainted_data] */ 48 sal_free(config_temp); 49 } else { 50 LOG_CLI((BSL_META("sal_alloc failed. \n"))); 51 exit(1); 52 } 53 } 54 55 if (sal_core_init() < 0 || sal_appl_init() < 0) { 56 LOG_CLI((BSL_META("SAL Initialization failed\n"))); 57 exit(1); 58 } 59 60 #ifdef DEBUG_STARTUP 61 debugk_select(DEBUG_STARTUP); 62 #endif 63 64 LOG_CLI((BSL_META("Broadcom Command Monitor: " 65 "Copyright (c) 1998-2010 Broadcom Corp.\n"))); 66 LOG_CLI((BSL_META("Version %s built %s\n"), _build_release, _build_date)); 67 68 switch (argc) { 69 case 3: 70 socrc = argv[2]; 71 case 2: 72 if (!strcmp(argv[1], "-testbios") || !strcmp(argv[1], "-tb")) { 73 diag_init(); 74 if (socrc) { 75 sh_rcload_file(0, NULL, socrc, 0); 76 } 77 } else if (!strcmp(argv[1], "-reload") || !strcmp(argv[1], "-r")) { 78 sal_boot_flags_set(sal_boot_flags_get() | BOOT_F_RELOAD); 79 diag_shell(); 80 } else if (!strcmp(argv[1], "-devlist")) { 81 devlist(argv[2]); 82 return 0; 83 } else { 84 LOG_CLI((BSL_META("Unknown option: %s\n"), argv[1])); 85 exit(1); 86 } 87 break; 88 89 default: 90 diag_shell(); 91 break; 92 } 93 94 return 0; 95 } 96 97 #include <soc/cm.h> 98 #include <appl/diag/sysconf.h> 99 100 int 101 devlist(const char* arg) 102 { 103 sysconf_init(); 104 soc_cm_display_known_devices(); 105 return 0; 106 } 107