1 /* 2 * (C) Copyright 2017 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <command.h> 9 #include "test-rockchip.h" 10 11 typedef struct board_module { 12 char *name; 13 int (*test)(int argc, char * const argv[]); 14 } board_module_t; 15 16 static board_module_t g_board_modules[] = { 17 #if defined(CONFIG_IRQ) 18 { .name = "timer", .test = board_timer_test }, 19 #endif 20 { .name = "brom", .test = board_brom_dnl_test }, 21 22 #if defined(CONFIG_DM_KEY) 23 { .name = "key", .test = board_key_test }, 24 #endif 25 #if defined(CONFIG_MMC) 26 { .name = "emmc", .test = board_emmc_test }, 27 #endif 28 #if defined(CONFIG_DM_REGULATOR) 29 { .name = "regulator", .test = board_regulator_test }, 30 #endif 31 #if defined(CONFIG_RKNAND) 32 { .name = "rknand", .test = board_rknand_test }, 33 #endif 34 #if defined(CONFIG_GMAC_ROCKCHIP) 35 { .name = "eth", .test = board_eth_test }, 36 #endif 37 #if defined(CONFIG_RK_IR) 38 { .name = "ir", .test = board_ir_test }, 39 #endif 40 #if defined(CONFIG_ROCKCHIP_VENDOR_PARTITION) 41 { .name = "vendor", .test = board_vendor_storage_test }, 42 #endif 43 }; 44 45 static void help(void) 46 { 47 printf("Command: rktest [module] [args...]\n\n" 48 " - module: timer|key|emmc|rknand|regulator|eth|ir|brom|vendor\n" 49 " - args: depends on module\n"); 50 } 51 52 static int do_rockchip_test(cmd_tbl_t *cmdtp, int flag, 53 int argc, char * const argv[]) 54 { 55 ulong ms_start = 0, ms = 0, sec = 0; 56 board_module_t *module = NULL; 57 char *module_name = NULL; 58 int index = 0, err = 0; 59 bool found = false; 60 61 if (argc >= 2) { 62 module_name = argv[1]; 63 } else { 64 help(); 65 return 0; 66 } 67 68 if (!module_name) 69 return 0; 70 71 72 for (index = 0; index < ARRAY_SIZE(g_board_modules); index++) { 73 module = &g_board_modules[index]; 74 if (module && !strcmp(module->name, module_name)) { 75 found = true; 76 77 printf("***********************************************************\n"); 78 printf("Rockchip Board Module [%s] Test start.\n", module_name); 79 printf("***********************************************************\n"); 80 81 ms_start = get_timer(0); 82 83 err = module->test(argc, argv); 84 85 ms = get_timer(ms_start); 86 if (ms >= 1000) { 87 sec = ms / 1000; 88 ms = ms % 1000; 89 } 90 91 printf("-----------------------------------------------------------\n"); 92 printf("Rockchip Board Module [%s] Test end <%s>.. Total: %lu.%lus\n", 93 module->name, err ? "FAILED" : "PASS", sec, ms); 94 printf("-----------------------------------------------------------\n\n\n"); 95 } 96 } 97 98 if (!found) 99 printf("Rockchip Board Module [%s] is not support !\n", 100 module_name); 101 102 return 0; 103 } 104 105 U_BOOT_CMD( 106 rktest, 10, 0, do_rockchip_test, 107 "Rockchip Board Module Test", 108 "" 109 ); 110