?? erase.c
字號:
/************************************************************************ * * 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. * * ###################################################################### * * mips_start_of_legal_notice * * Copyright (c) 2004 MIPS Technologies, Inc. All rights reserved. * * * Unpublished rights (if any) reserved under the copyright laws of the * United States of America and other countries. * * This code is proprietary to MIPS Technologies, Inc. ("MIPS * Technologies"). Any copying, reproducing, modifying or use of this code * (in whole or in part) that is not expressly permitted in writing by MIPS * Technologies or an authorized third party is strictly prohibited. At a * minimum, this code is protected under unfair competition and copyright * laws. Violations thereof may result in criminal penalties and fines. * * MIPS Technologies reserves the right to change this code to improve * function, design or otherwise. MIPS Technologies does not assume any * liability arising out of the application or use of this code, or of any * error or omission in such code. Any warranties, whether express, * statutory, implied or otherwise, including but not limited to the implied * warranties of merchantability or fitness for a particular purpose, are * excluded. Except as expressly provided in any written license agreement * from MIPS Technologies or an authorized third party, the furnishing of * this code does not give recipient any license to any intellectual * property rights, including any patent rights, that cover this code. * * This code shall not be exported, reexported, transferred, or released, * directly or indirectly, in violation of the law of any country or * international law, regulation, treaty, Executive Order, statute, * amendments or supplements thereto. Should a conflict arise regarding the * export, reexport, transfer, or release of this code, the laws of the * United States of America shall be the governing law. * * This code constitutes one or more of the following: commercial computer * software, commercial computer software documentation or other commercial * items. If the user of this code, 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 code, 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 code 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 code from MIPS Technologies or an authorized * third party. * * * * * mips_end_of_legal_notice * * ************************************************************************//************************************************************************ * 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 <string.h>#include <sysenv_api.h>#include <sys_api.h>#include <env_api.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 boolget_default_range( UINT32 *start, UINT32 *size );static UINT32do_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 boolget_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 UINT32do_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 ) { /* 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 ) { /* 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); rc = IO_ctrl( SYS_MAJOR_FLASH_STRATA, 0, (UINT8 *)(&flash_ctrl) ); if(rc != OK) { 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"
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -