⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:

/************************************************************************
 *
 *  test.c
 *
 *  Shell test command
 *
 *  test [-l] | [-m] [ <module> [ <module parameters> ] ]
 *
 *
 * ######################################################################
 *
 * Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved. 
 * 
 * Unpublished rights reserved under the Copyright Laws of the United States of 
 * America. 
 * 
 * This document contains information that is proprietary to MIPS Technologies, 
 * Inc. ("MIPS Technologies"). Any copying, modifying or use of this information 
 * (in whole or in part) which is not expressly permitted in writing by MIPS 
 * Technologies or a contractually-authorized third party is strictly 
 * prohibited. At a minimum, this information is protected under unfair 
 * competition laws and the expression of the information contained herein is 
 * protected under federal copyright laws. Violations thereof may result in 
 * criminal penalties and fines. 
 * MIPS Technologies or any contractually-authorized third party reserves the 
 * right to change the information contained in this document to improve 
 * function, design or otherwise. MIPS Technologies does not assume any 
 * liability arising out of the application or use of this information. Any 
 * license under patent rights or any other intellectual property rights owned 
 * by MIPS Technologies or third parties shall be conveyed by MIPS Technologies 
 * or any contractually-authorized third party in a separate license agreement 
 * between the parties. 
 * The information contained in this document constitutes one or more of the 
 * following: commercial computer software, commercial computer software 
 * documentation or other commercial items. If the user of this information, or 
 * any related documentation of any kind, including related technical data or 
 * manuals, is an agency, department, or other entity of the United States 
 * government ("Government"), the use, duplication, reproduction, release, 
 * modification, disclosure, or transfer of this information, or any related 
 * documentation of any kind, is restricted in accordance with Federal 
 * Acquisition Regulation 12.212 for civilian agencies and Defense Federal 
 * Acquisition Regulation Supplement 227.7202 for military agencies. The use of 
 * this information by the Government is further restricted in accordance with 
 * the terms of the license agreement(s) and/or applicable contract terms and 
 * conditions covering this information from MIPS Technologies or any 
 * contractually-authorized third party. 
 *
 ************************************************************************/


/************************************************************************
 *  Include files
 ************************************************************************/

#include <sysdefs.h>
#include <shell_api.h>
#include <syscon_api.h>
#include "shell.h"
#include <sysdev.h>
#include <io_api.h>
#include <flash_api.h>
#include <sys_api.h>
#include <stdio.h>
#include <string.h>

/************************************************************************
 *  "Private" externals
 ************************************************************************/

/* From memtest.S */

extern UINT32 errordump[];
extern UINT32 memtest(UINT32, UINT32, UINT32, UINT32);

/************************************************************************
 *  Definitions
 ************************************************************************/

/* Requirements for SDB (Atlas) set by Microsoft */
#define SDB_REQUIREMENT_RAMSIZE	(64 * 1024 * 1024)

typedef struct test_mod {
    char    *t_module_name;
    UINT32   t_module_index;
    char    *t_start_text;
    char    *t_help_text;
    UINT32   t_arg_count;
    bool   (*t_func)();
} t_test_mod;

/************************************************************************
 *  Public variables
 ************************************************************************/

/************************************************************************
 *  Static function prototypes
 ************************************************************************/

static UINT32 
get_options(
    UINT32 argc,
    char   **argv,
    bool   *help,
    bool   *until_break,
    t_test_mod **pmodule,
    UINT32 *parg1,
    UINT32 *parg2,
    UINT32 *parg3 );

static bool
do_test(
    t_test_mod *pmodule,
    bool       write_msg,
    UINT32     tstarg1,
    UINT32     tstarg2,
    UINT32     tstarg3 );

static void
get_default_ram(
    UINT32 *pstart,
    UINT32 *psize,
    UINT32 *ploops );

static bool
test_ram( 
    UINT32 start, 
    UINT32 size,
    UINT32 loops );

static bool
test_flash( void ); 

static bool
test_all( void );

static UINT32
ram_range_valid(
    UINT32 *pstart,
    UINT32 *psize );

/************************************************************************
 *  Static variables
 ************************************************************************/

/* OPTIONS */
static t_cmd_option options[] =
{
#define OPTION_HELP	0
  { "m", "List available test modules" },
#define OPTION_LOOP	1
  { "l", "Loop default tests until Ctrl-C is pressed" }
};
#define OPTION_COUNT	(sizeof(options)/sizeof(t_cmd_option))

static t_test_mod modules[] =
{
#define MODULE_RAM   0
    { "ram", MODULE_RAM, "Testing RAM\n",

	"\nUsage: test ram [<address> <size> <loops>]\n"
	"Default start address is the first RAM address not used by YAMON.\n"
	"Default size is all RAM not used by YAMON.\n"
        "Default loop count is 10.\n"
	"Loop count of 0 will cause the test to loop indefinitely.\n"
	"Start address is 256 byte aligned (by adding between 0 and 255).\n"
	"Size is 256 byte aligned (by subtracting between 0 and 255 ).\n"
        "In case this causes the end address to increase, size is\n"
        "reduced by 256.\n"
        "Range is not restricted to RAM.\n\n",

	3, &test_ram },

#define MODULE_FLASH 1
    { "flash", MODULE_FLASH, "Testing Flash\n",

	"\nUsage: test flash\n"
	"Performs a non-destructive test of the system and environment flash memory\n"
	"areas (if present). The test communicates with the state-machine in the\n"
	"flash chips for every sector in the areas tested.\n\n",
	0, &test_flash },

#define MODULE_ALL   2
    { "all", MODULE_ALL, "Testing ALL\n",
	"\nUsage : test [-m] [ <module> ]\n\nAvailable modules :\n",
	0, &test_all },
};

static bool   ctrl_c;
static int    wix;
static UINT32 err;


/************************************************************************
 *  Implementation : Static functions
 ************************************************************************/

/************************************************************************
 *                          test
 ************************************************************************/
static MON_FUNC(test)
{
    /* Options */
    bool        help;
    bool        until_break;
    t_test_mod *pmodule;
    UINT32     i;
    UINT32     tstarg1, tstarg2, tstarg3;
    UINT32     rc;

    rc = get_options( argc, argv, &help, &until_break, &pmodule, 
		      &tstarg1, &tstarg2, &tstarg3 );

    if( rc != OK )
        return rc;
    else
    {
	err = OK;
    
	if( help )
	{
	    if (SHELL_PUTS( pmodule->t_help_text )) 
	    {
	        return OK;
	    }

            if( pmodule->t_module_index == MODULE_ALL) {
	        for( i = 0; i < MODULE_ALL; i++ )
	        {
                    if( SHELL_PUTS( modules[i].t_module_name ) ||
		        SHELL_PUTC( '\n' ) )
                    {
                        break;
                    }
	        }
	            
		SHELL_PUTC( '\n' );
		return OK;
            }
	}
	else
	{
	    if (until_break)
	    {
		SHELL_DISABLE_MORE;
	    }

	    while (TRUE)
	    {
	        i = do_test( pmodule,	
		     (pmodule->t_module_index == MODULE_ALL) ? FALSE : TRUE,
		     tstarg1, tstarg2, tstarg3 );
		printf("\n");
		if (!i || !until_break)
		    break;
	    }
        }

	return err;
    }
}


/************************************************************************
 *                          test_sdb
 ************************************************************************/
static MON_FUNC(test_sdb)
{
    bool rc;
    UINT32 start, size, dummy;

    if( argc != 1 )
    {
        if( *(argv[1]) == '-' )
	{
	    shell_error_data = argv[1];
	    return SHELL_ERROR_OPTION;
	}
	else
	    return SHELL_ERROR_SYNTAX;
    }

    err = OK;

    if( sys_ramsize < SDB_REQUIREMENT_RAMSIZE )
    {	
        SHELL_PUTS( "Not enough RAM\n" );
    }
    else
    {
        get_default_ram( &start, &size, &dummy );

    	rc = do_test( &modules[ MODULE_RAM ], TRUE, start, size, 1 );

        SHELL_PUTC( '\n' );

	if( !rc )
            return err;

    	rc = do_test( &modules[ MODULE_FLASH ], TRUE, 0, 0, 0 );

        SHELL_PUTC( '\n' );

	if( !rc )
            return err;
    }

    return err;
}


/************************************************************************
 *                          do_test
 ************************************************************************/
static bool
do_test(
    t_test_mod *pmodule,
    bool       write_msg,
    UINT32     tstarg1,
    UINT32     tstarg2,
    UINT32     tstarg3 )
{
    bool pass;

    ctrl_c = FALSE;
    if( SHELL_PUTS( pmodule->t_start_text )) return FALSE;

    pass = pmodule->t_func( tstarg1, tstarg2, tstarg3 );

    if( write_msg )
    {
        if( ctrl_c )
	{
	    err = SHELL_ERROR_CONTROL_C_DETECTED;
	}
	else
	{
            SHELL_PUTS( 
	        pass ? 
	            "Test passed" : 
		    "Test failed" );
        }
    }

    return (pass && !ctrl_c) ? TRUE : FALSE;
}


/************************************************************************
 *                          get_default_ram
 ************************************************************************/
static void
get_default_ram(
    UINT32 *pstart,
    UINT32 *psize,
    UINT32 *ploops )
{
    /* Setup default RAM parameters */
    *pstart = (KSEG1(sys_freemem) + 0xff) & ~0xff;  
    *psize  = KSEG1(sys_ramsize) - *pstart;
    *ploops = 10;
}


/************************************************************************
 *                          get_options
 ************************************************************************/
static UINT32
get_options(
    UINT32 argc,
    char   **argv,
    bool   *help,
    bool   *until_break,
    t_test_mod **pmodule,
    UINT32 *parg1,
    UINT32 *parg2,
    UINT32 *parg3 )
{
    t_shell_option decode;
    UINT32	   type;
    char	   *token;
    UINT32	   i;
    UINT32	   modix;
    bool	   ok    = TRUE;
    UINT32	   count = 0;
    UINT32	   arg;
    UINT32	   error = SHELL_ERROR_SYNTAX;
    UINT32	   rc;

    /* Defaults */
    *help        = FALSE;
    *until_break = FALSE;
    modix        = MODULE_ALL;
 
    for( arg = 1; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -