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

📄 erase.c

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

/************************************************************************
 *
 *  erase.c
 *
 *  Shell erase command
 *
 *  erase [-s|-e|<address> <size>]
 *
 *  We differentiate between "monitor flash", "environment flash"  and 
 *  "system flash".
 *
 *  Monitor flash is the flash memory used for holding YAMON.
 *  Environment flash is the flash memory used for environment variables.
 *  System flash is the flash available for the user.
 *
 *  -s ( "Erase system flash" ) option is only available on boards 
 *  having system flash.
 *
 *
 * ######################################################################
 *
 * 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 <flash_api.h>
#include <sysdev.h>
#include <io_api.h>
#include <ctype.h>
#include <stdio.h>
#include <sysenv_api.h>
#include <sys_api.h>
#include <env_api.h>
#include <string.h>
#include "shell.h"

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

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

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

/* OPTIONS */
static t_cmd_option options[] =
{ 
#define OPTION_ENV	0
  { "e",  "Erase and reinitialise entire environment area." },
#define OPTION_SYSTEM	1
  { "s",  "Erase entire system flash (default option)." }
};
#define OPTION_COUNT	(sizeof(options)/sizeof(t_cmd_option))

static char erase_msg[]         = "Erasing...";
static char *syntax_sysflash    = "erase [-s|-e|<address> <size>]";
static char *syntax_no_sysflash = "erase -e | <address> <size>";

static UINT32 default_start;
static UINT32 default_size;
static UINT32 option_count;
static bool   sysflash_avail;

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

static UINT32 
get_options(
    UINT32 argc,
    char   **argv,
    bool   *system,
    bool   *env,
    UINT32 *start,
    UINT32 *size );

static bool
get_default_range(
    UINT32 *start,
    UINT32 *size );

static UINT32
do_erase(
    bool   system,
    bool   env,
    UINT32 start,
    UINT32 size );

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

/************************************************************************
 *                          erase
 ************************************************************************/
static MON_FUNC(erase)
{
    UINT32 start;
    UINT32 size;
    bool   system, env;
    UINT32 rc;
    
    rc = get_options( argc, argv, &system, &env, &start, &size );

    if( rc == OK )
        rc = do_erase( system, env, start, size );

    return rc;
}


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

    return do_erase( FALSE, FALSE, default_start, default_size );
}
   

/************************************************************************
 *                          get_default_range
 ************************************************************************/
static bool
get_default_range(
    UINT32 *start,
    UINT32 *size )
{
    if( 
        (SYSCON_read( SYSCON_BOARD_SYSTEMFLASH_BASE_ID,
		     (void *)start,
		     sizeof(UINT32) ) == OK) &&

        (SYSCON_read( SYSCON_BOARD_SYSTEMFLASH_SIZE_ID,
		     (void *)size,
		     sizeof(UINT32) ) == OK) )
    {
        /* System flash available */
	return TRUE;
    }
    else
    {	
        /* System flash not available */
        return FALSE;
    }
}


/************************************************************************
 *                          do_erase
 ************************************************************************/
static UINT32
do_erase(
    bool   system,
    bool   env,
    UINT32 start,
    UINT32 size )
{
    UINT32 rc = OK;
    t_FLASH_ctrl_descriptor   flash_ctrl;
    char		      msg[120];
    char		      ch;
    bool		      cancelled = FALSE;

    if( system || env )
    {
	if(SHELL_PUTS( erase_msg )) return OK;

        if( system )
        {

	printf("system...\n");

            /* Erase entire system flash */

            flash_ctrl.command = FLASH_CTRL_ERASE_SYSTEMFLASH;
            rc = IO_ctrl( SYS_MAJOR_FLASH_STRATA, 0, (UINT8 *)(&flash_ctrl) );
            if(rc != OK )
	    {
	        SHELL_PUTC( '\n' );
                return rc;
	    }
        }

        if( env )
        {
	printf("env...\n");

            /* Erase entire file flash */

            flash_ctrl.command = FLASH_CTRL_ERASE_FILEFLASH;
            rc = IO_ctrl( SYS_MAJOR_FLASH_STRATA, 0, (UINT8 *)(&flash_ctrl) );
            if(rc != OK)
	    {
	        SHELL_PUTC( '\n' );
                return rc;
	    }

	    /* Reinit sysenv (handling of environment records in flash) */
	    SYSENV_init();
        }
    }
    else
    {
        /* Inquire what will actually be erased */

        flash_ctrl.command      = FLASH_CTRL_INQUIRE_FLASH_AREA;
        flash_ctrl.user_physadr = PHYS(start);
        flash_ctrl.user_length  = size;
        rc = IO_ctrl( SYS_MAJOR_FLASH_STRATA, 0, (UINT8 *)(&flash_ctrl) );
        if(rc != OK)
	{
		printf(" inquire = %d\n",rc);
            return rc;
	}

        flash_ctrl.user_physadr = flash_ctrl.driver_physadr;
        flash_ctrl.user_length  = flash_ctrl.driver_length;

        sprintf( msg,
	    "The following area will be erased:\n"
	    "Start address = 0x%08x\n"
	    "Size          = 0x%08x\n"
	    "Confirm ? (y/n) ",
            flash_ctrl.user_physadr, flash_ctrl.user_length);

        if(SHELL_PUTS( msg )) 
	{

⌨️ 快捷键说明

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