📄 test.c
字号:
ok && (arg < argc) && (token = argv[arg]) && shell_decode_token( token, &type, &decode ); arg++ ) { switch( type ) { case SHELL_TOKEN_OPTION : /* Find match */ for(i=0; (i<OPTION_COUNT) && (strcmp(decode.option, options[i].option) != 0); i++) ; switch(i) { case OPTION_HELP : *help = TRUE; break; case OPTION_LOOP : *until_break = TRUE; break; default : error = SHELL_ERROR_OPTION; shell_error_data = token; ok = FALSE; break; } break; case SHELL_TOKEN_NUMBER : if( count == 0 ) *parg1 = decode.number; else if( count == 1 ) *parg2 = decode.number; else if( count == 2 ) *parg3 = decode.number; else ok = FALSE; count++; break; case SHELL_TOKEN_STRING : /* Use raw token to find match with module name */ if( modix != MODULE_ALL ) ok = FALSE; else { for(modix=0; (modix < MODULE_ALL) && (strcmp(token, modules[modix].t_module_name) != 0); (modix)++) ; if( modix == MODULE_ALL ) ok = FALSE; } break; } } if( !ok ) { return error; } *pmodule = &modules[modix]; if( *help ) { return ( *until_break || (count != 0) ) ? SHELL_ERROR_SYNTAX : OK; } if( *until_break ) { return ( *help || (count != 0) || (modix != MODULE_ALL) ) ? SHELL_ERROR_SYNTAX : OK; } /* --- argument special considerations --- */#define pstart parg1#define psize parg2#define ploops parg3 if( modix == MODULE_ALL ) get_default_ram(pstart, psize, ploops); if( modix == MODULE_RAM ) { if( count == 0 ) { get_default_ram(pstart, psize, ploops); count = 3; } if( count == 3 ) { /* Check validity of addresses, and adjust if possible */ rc = ram_range_valid(pstart, psize); if( rc != OK ) return rc; } }#undef pstart#undef psize#undef ploops /* --- special considerations end --- */ return ( count != modules[modix].t_arg_count ) ? SHELL_ERROR_SYNTAX : OK;}/************************************************************************ * test_all ************************************************************************/static booltest_all( void ){ UINT32 rambase, srambase, size, loops; srambase = 0; get_default_ram( &rambase, &size, &loops ); SYSCON_read( SYSCON_BOARD_SRAM_BASE_ID, &srambase, sizeof(srambase) ); if( !do_test(&modules[ MODULE_RAM ], TRUE, rambase, size, loops) ) return FALSE; if( SHELL_PUTC( '\n' ) ) return FALSE; if (srambase) { SYSCON_read( SYSCON_BOARD_SRAM_SIZE_ID, &size, sizeof(size) ); if ( !do_test(&modules[ MODULE_RAM ], TRUE, KSEG1(srambase), size, loops) ) return FALSE; if ( SHELL_PUTC( '\n' ) ) return FALSE; } if (!do_test( &modules[ MODULE_FLASH ], TRUE, 0, 0, 0 )) return FALSE; return TRUE;}/************************************************************************ * test_ram ************************************************************************/static booltest_ram( UINT32 start, UINT32 size, UINT32 loops ){#define TEST_BLOCK 0x80000 UINT32 cnt; UINT32 dummy; UINT32 newstart, newend; UINT32 seed; UINT32 *erroradr; char *wheel = "|/-\\"; printf("Memory test from 0x%08X to 0x%08X, ", start, start + size - 4 ); if( !loops ) printf("loop indefinitely.\n" ); else printf("%d loop%s\n", loops, loops == 1 ? "." : "s."); if (loops != 1 || (size > TEST_BLOCK)) printf( "%s\n", shell_msg_ctrl_c); erroradr = 0; for (cnt=0; ((loops == 0) || (cnt<loops)) && erroradr==0 && !ctrl_c; cnt++) { printf("\rNow running loop %d %c", cnt+1, wheel[wix = ((wix+1) & 0x3)]); seed = cnt; for ( newstart=start; (newstart<start+size) && erroradr==0 && !ctrl_c; newstart += TEST_BLOCK) { newend = newstart + TEST_BLOCK; if (newend > start+size) newend = start+size; dummy = newstart; mem_pattern_write(newstart, (UINT32)&dummy, newend, seed); seed = dummy; printf("\b%c", wheel[wix = ((wix+1) & 0x3)]); if ( GETCHAR_CTRLC(DEFAULT_PORT) ) ctrl_c = TRUE; } seed = cnt; for ( newstart=start; (newstart<start+size) && erroradr==0 && !ctrl_c; newstart += TEST_BLOCK) { newend = newstart + TEST_BLOCK; if (newend > start+size) newend = start+size; dummy = newstart; if ((erroradr = mem_pattern_verify(newstart, (UINT32)&dummy, newend, seed))) { printf("\nFailed at address: 0x%08X\n", (UINT32)erroradr); printf("Written Read Difference Re-Read\n"); for (cnt=0; cnt<8; cnt++) printf("0x%08X 0x%08X 0x%08X 0x%08X\n", errordump[cnt*2], errordump[cnt*2+1], errordump[cnt*2] ^ errordump[cnt*2+1], erroradr[cnt]); } seed = dummy; if (erroradr == 0) { printf("\b%c", wheel[wix = ((wix+1) & 0x3)]); if ( GETCHAR_CTRLC(DEFAULT_PORT) ) ctrl_c = TRUE; } } } if (!ctrl_c) printf("\n"); return erroradr == 0;}/************************************************************************ * test_flash ************************************************************************/static booltest_flash( void ){ UINT32 rc ; t_FLASH_ctrl_descriptor flash_ctrl; flash_ctrl.command = FLASH_CTRL_TEST_SYSTEMFLASH; rc = IO_ctrl( SYS_MAJOR_FLASH_STRATA, 0, (UINT8 *)(&flash_ctrl)) ; if (rc) { err = rc; return FALSE ; } return TRUE;} /************************************************************************ * ram_range_valid ************************************************************************/static UINT32ram_range_valid( UINT32 *pstart, UINT32 *psize ){ UINT32 adj_start; UINT32 adj_size; if( *pstart + *psize < MAX( *pstart, *psize ) ) { /* Overflow */ return SHELL_ERROR_RAM_RANGE; } /* Adjust start and size to be 0x100 aligned */ adj_start = (*pstart + 0xff) & ~0xff; adj_size = *psize & ~0xff; while ( (adj_size != 0) && (adj_start + adj_size) > (*pstart + *psize) ) { adj_size -= 0x100; } if( adj_size == 0 ) return SHELL_ERROR_RAM_RANGE; *pstart = adj_start; *psize = adj_size; return sys_validate_range( adj_start, adj_size, 1, TRUE );}/* Command definition for help */static t_cmd cmd_def ={ "test", test, "test [-l] | [-m] [ <module> [ <module arguments> ] ]", "The test command can perform a number of self-tests on different\n" "modules. If no module is supplied, all available modules are tested\n" "and a final pass/fail status is indicated. If a module is specified,\n" "only this module is tested.\n" "\n" "If the option '-m' is applied and no module is specified, a list\n" "of the available modules is displayed.\n" "\n" "If the option '-m' is applied and a module is specified, additional\n" "information about the module test and the optional arguments is\n" "displayed.\n" "\n" "If the option '-l' is applied, all available modules are tested\n" "repetitively, until Ctrl-C is pressed or a test fails. The '-l'\n" "option cannot be specified together with other options or arguments.", options, OPTION_COUNT, FALSE};/* Command definitions for SDB 't' command (secret command) */static t_cmd cmd_def_sdb_lower ={ "t", test_sdb, "t (Microsoft SDB command)", "Performs self-test as required by Microsoft SDB requirements.\n" "Detects and tests RAM and flash memories. A final pass/fail status\n" "is indicated.\n" "\n" "In order to run this test, a minimum of 64 MByte SDRAM and 32 MByte\n" "flash must be available. If these requirements are not met, the test\n" "will not start at all.", NULL, 0, TRUE};/************************************************************************ * Implementation : Public functions ************************************************************************//************************************************************************ * * shell_test_init * Description : * ------------- * * Initialise command * * Return values : * --------------- * * void * ************************************************************************/t_cmd *shell_test_init( void ){ return &cmd_def;}/************************************************************************ * * shell_test_sdb_init * Description : * ------------- * * Initialise command * * Return values : * --------------- * * void * ************************************************************************/t_cmd *shell_test_sdb_init( void ){ return &cmd_def_sdb_lower;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -