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

📄 erase.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	    SHELL_PUTC( '\n' );
	    return OK;
	}

	/* Wait for user to type any key */
	do
	{
            while( !GETCHAR( DEFAULT_PORT, &ch ) );
        }
	while( (tolower(ch) != 'y') &&
	       (tolower(ch) != 'n') &&
	       (ch	    != CTRL_C ) );

	if( ch == CTRL_C )
	    rc = SHELL_ERROR_CONTROL_C_DETECTED;
	else
	{
            if(SHELL_PUTC( ch )) 
	    {
	        SHELL_PUTC( '\n' );
	        return OK;
            }
        }

        if( tolower(ch) == 'y' )
        {
	    SHELL_PUTC( '\n' );
	  
	    if(SHELL_PUTS( erase_msg )) 
	    {
	        SHELL_PUTC( '\n' );
		return OK;
	    }

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

    SHELL_PUTS( cancelled ? "\nCancelled\n" : "Done\n" );

    if( !cancelled )
    {
        /* Reinit environment variables */
	env_init();
	if( env_check() )
	{
	    SHELL_PUTC( '\n' );
	}
    }

    return rc;
}


/************************************************************************
 *                          get_options
 ************************************************************************/
static UINT32 
get_options(
    UINT32 argc,
    char   **argv,
    bool   *system,
    bool   *env,
    UINT32 *start,
    UINT32 *size )
{
    t_shell_option decode;
    UINT32	   type;
    UINT32	   int_count = 0;
    bool	   ok = TRUE;
    UINT32	   i;
    UINT32	   arg;
    UINT32	   error = SHELL_ERROR_SYNTAX;

    /* Setup default */
    *system = FALSE;
    *env    = FALSE;
    *start  = default_start;
    *size   = default_size;

    for( arg = 1; 
	     ok && 
	     (arg < argc) && 
             shell_decode_token( argv[arg], &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++) ;

	    if( i == option_count )
	    {
	        error		 = SHELL_ERROR_OPTION;
		shell_error_data = argv[arg];
	        ok		 = FALSE;
	        break;		      
	    }
	    else
	    {
	        switch(i)
	        {
	          case OPTION_SYSTEM :
	            *system = TRUE;
		    *env    = FALSE;
		    break;
	          case OPTION_ENV :
	            *env    = TRUE;
		    *system = FALSE;
		    break;
	          default : /* Should not happen */
			  ;
		}
	    }

	    break;
	  case SHELL_TOKEN_NUMBER :
	    if( int_count == 0 )
	        *start = decode.number;
	    else if( int_count == 1 )
	        *size  = decode.number;
	    else
	        ok = FALSE;

	    int_count++;
	    break;
	 default :
	    ok = FALSE;
	    break;
       }
    }

    if( *system || *env )
    {
        if( int_count != 0 )
            ok = FALSE;
    }
    else
    {
        /* 0 or 2 numbers is OK unless there is no system flash, in
         * which case 0 numbers is NOT ok (since there is not default
         * range) 
         */

	if( ! ( (int_count == 2) ||
	        ((int_count == 0) && sysflash_avail)
	      ) )
        {
	    ok = FALSE;
        }
    }

    return ok ? OK : error;
}


/* Command definition for help */
static t_cmd cmd_def =
{
    "erase",
     erase,
     NULL,

    "Erase flash memory.\n"
    "\n"
    "An option may be applied specifying which flash region to erase.\n"
    "If no such option is applied, the address range to be erased\n"
    "is specified by the <address> and <size> parameters.\n"
    "If no such range is specified either, the range corresponding to the\n"
    "default option is assumed (if there is a default option, this is\n"
    "platform specific).\n"
    "\n"
    "If (and only if) the -e option (erase environment flash) is\n"
    "applied, the system environment variables are reinitialised to\n"
    "factory default values.\n"
    "\n"
    "If a range is specified, all flash blocks touched by the range\n"
    "are cleared. The block size depends on the flash memory type used by the\n"
    "board. The blocks to be cleared are displayed, and the user is asked\n"
    "for confirmation before the operation is performed.\n"
    "\n"
    "Erasing a large flash area takes time. It can easily take several\n"
    "minutes to erase a 32 MByte area.\n"
    "\n"
    "Any set flash sector lock bits will be cleared before the sector is\n"
    "erased. If they cannot be cleared (e.g. due to hardware protection of the\n"
    "lock bits), the command will fail.",

    options,
    0,
    FALSE
};

/* Command definitions for SDB 'e' command (secret command) */

static t_cmd cmd_def_sdb_lower =
{
    "e",
    erase_sdb,

    "e                        (Microsoft SDB command)",

    "Completely erase system flash. The command is equivalent to 'erase',\n"
    "see 'help erase' for more details.",

    NULL,
    0,
    TRUE
};


/************************************************************************
 *  Implementation : Public functions
 ************************************************************************/

/************************************************************************
 *
 *                          shell_erase_init
 *  Description :
 *  -------------
 *
 *  Initialise command
 *
 *  Return values :
 *  ---------------
 *
 *  void
 *
 ************************************************************************/
t_cmd *
shell_erase_init( void )
{
    /* Determine default range (system flash if available) */
    sysflash_avail = get_default_range( &default_start, &default_size );

    if( sysflash_avail )
    {
        cmd_def.syntax = syntax_sysflash;
	option_count   = OPTION_COUNT;
    }
    else	
    {
        cmd_def.syntax = syntax_no_sysflash;
	option_count   = OPTION_COUNT - 1;
    }

    cmd_def.option_count = option_count;

    return &cmd_def;
}


/************************************************************************
 *
 *                          shell_erase_sdb_init
 *  Description :
 *  -------------
 *
 *  Initialise command
 *
 *  Return values :
 *  ---------------
 *
 *  void
 *
 ************************************************************************/
t_cmd *
shell_erase_sdb_init( void )
{
    sysflash_avail = get_default_range( &default_start, &default_size );

    return &cmd_def_sdb_lower;
}

⌨️ 快捷键说明

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