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

📄 flash_strata.c

📁 MIPS YAMON, a famous monitor inc. source, make file and PDF manuals.
💻 C
📖 第 1 页 / 共 5 页
字号:
/************************************************************************ * *      FLASH_STRATA.C * *      The 'FLASH_STRATA' module implements the FLASH device driver *      interface to be used via 'IO' device driver services: * *        1) init  device:  configure and initialize FLASH driver *        2) open  device:  not used *        3) close device:  not used *        4) read  device:  not used *        5) write device:  write FLASH device *        6) ctrl  device:  a) ERASE_SYSTEMFLASH *                          b) ERASE_FILEFLASH * * * ###################################################################### * * 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 <syserror.h>#include <sysdev.h>#include <mips.h>#include <io_api.h>#include <syscon_api.h>#include <flash_api.h>#include <flash_strata_api.h>#include <sys_api.h>#include <stdio.h>#include <string.h>/************************************************************************ *      Definitions ************************************************************************//* FLASH-device, relative register address inside a block */#define FLASH_BLOCKSTATUS_OFS                   0x0008/* field: LOCK */#define FLASH_BLOCKSTATUS_LOCK_MSK          0x00010001/* flash memory ID's */#define INTEL_MNFCR_CODE			0x0089#define STRATA_DEV1_CODE			0x0014#define STRATA_DEV2_CODE			0x0015#define FLASH_QUERYQCHAR_OFS                    0x0040#define FLASH_QUERYRCHAR_OFS                    0x0044#define FLASH_QUERYYCHAR_OFS                    0x0048#define FLASH_QUERYQCHAR                    0x00510051#define FLASH_QUERYRCHAR                    0x00520052#define FLASH_QUERYYCHAR                    0x00590059/* status */#define FLASH_READY				0x0000#define FLASH_NOT_DETECTED			0x0001#define FLASH_BUSY				0x0002#define FLASH_ERROR				0x0003#define FLASH_TIMEOUT                           0x0004#define FLASH_INVALID_SECTOR                    0x0005#define FLASH_SECTOR_LOCKED                     0x0006/* Commands and masks, etc... */#define FLASH_STATUS_READY			0x00800080#define FLASH_STATUS_MASK                       0x00FF00FF#define FLASH_STATUS_OK                         0x00800080#define FLASH_STATUS_ERASE                      0x00600060#define FLASH_STATUS_LOCK                       0x00020002#define FLASH_STATUS_LOW_VOLTAGE                0x00080008#define FLASH_READ_COMMAND			0x00FF00FF#define FLASH_ERASE_COMMAND			0x00200020#define FLASH_CONFIRM_COMMAND		        0x00D000D0#define FLASH_CLEAR_STATUS_COMMAND	        0x00500050#define FLASH_WRITE_WORD_COMMAND	        0x00100010#define FLASH_WRITE_BUFFER_COMMAND	        0x00E800E8#define FLASH_STATUS_COMMAND		        0x00700070#define FLASH_QUERY_COMMAND			0x00980098#define FLASH_READ_ID_CODES_COMMAND		0x00900090#define FLASH_CLEAR_LOCK_COMMAND                0x00600060#define FLASH_LOCK_SECTOR                       0x00010001/* Timeout values */#define FLASH_TMOUT_100MS                       100#define FLASH_TMOUT_250MS                       250#define FLASH_TMOUT_500MS                       500#define FLASH_TMOUT_1SEC                        1000#define FLASH_TMOUT_2SEC                        2000#define FLASH_TMOUT_2_5SEC                      2500/* Retry counts */#define FLASH_MAX_LOOPS				0xFFFFFFFF#define FLASH_RETRY_5                           5#define FLASH_RETRY_10                          10#define FLASH_RETRY_20                          20#define FLASH_RETRY_50                          50/* Identification tags for memory devices */typedef enum flash_device_id{	FLASH_SYSTEMFLASH_DEVICE = 0,	FLASH_MONITORFLASH_DEVICE,	FLASH_FILEFLASH_DEVICE,	FLASH_BOOT_DEVICE,	FLASH_UNKNOWN_DEVICE} t_flash_device_id ;/* union, to access bytes inside a word, independant of endianness */typedef union flash_access{	volatile UINT32 d32 ;	volatile UINT8  d8[4] ;} t_flash_access ;/************************************************************************ *  Macro Definitions*************************************************************************/#define WRITE_ENABLE   SYSCON_write( SYSCON_BOARD_SYSTEMFLASH_WRITE_ENABLE_ID, \                                    NULL, sizeof( UINT32 ) );#define WRITE_DISABLE  SYSCON_write( SYSCON_BOARD_SYSTEMFLASH_WRITE_DISABLE_ID, \                                    NULL, sizeof( UINT32 ) );/************************************************************************ *      Public variables ************************************************************************//************************************************************************ *      Static variables ************************************************************************/static char* flash_error_string[] = {    /* ERROR_FLASH_PROGRAM_ERROR      */ "Flash device failure",    /* ERROR_FLASH_INVALID_ADDRESS    */ "Invalid address",    /* ERROR_FLASH_INVALID_COMMAND    */ "Internal ERROR: Invalid control command",    /* ERROR_FLASH_TIME_OUT           */ "Internal ERROR: Flash device timed out during operation",    /* ERROR_FLASH_VERIFY_ERROR       */ "Data verify error",    /* ERROR_FLASH_LOCKED             */ "Some sectors are locked",    /* ERROR_FLASH_ERASE_ERROR        */ "Sector has erase error",    /* ERROR_FLASH_LOW_VOLTAGE        */ "Low programming voltage detected",    /* ERROR_FLASH_WRITE_PROTECTED    */ "Flash is write protected",    /* ERROR_FLASH_FILE_FLASH_PROT    */ "Environment FLASH is write protected",    /* ERROR_FLASH_FILE_FLASH_LOCK    */ "Environment FLASH is lock-bit protected",    /* ERROR_FLASH_MONITOR_FLASH_LOCK */ "Some MONITOR FLASH sector(s) locked",    /* ERROR_FLASH_QRY_NOT_FOUND      */ "CFI Query-ID string of FLASH not found",    /* ERROR_FLASH_BOOT_WRITE_PROTECTED */ "Write access to this area not allowed"} ;static char* flash_error_hint_string[] = {    /* ERROR_FLASH_PROGRAM_ERROR      */ NULL,    /* ERROR_FLASH_INVALID_ADDRESS    */ NULL,    /* ERROR_FLASH_INVALID_COMMAND    */ NULL,    /* ERROR_FLASH_TIME_OUT           */ NULL,    /* ERROR_FLASH_VERIFY_ERROR       */ "Check flash has been erased before programming",    /* ERROR_FLASH_LOCKED             */ "Unlock sector(s) before programming",    /* ERROR_FLASH_ERASE_ERROR        */ NULL,    /* ERROR_FLASH_LOW_VOLTAGE        */ NULL,    /* ERROR_FLASH_WRITE_PROTECTED    */ "Disable write protection: Switch S1-3",    /* ERROR_FLASH_FILE_FLASH_PROT    */ "Check programming addresses",    /* ERROR_FLASH_FILE_FLASH_LOCK    */ "Disable 'clear lock-bit' protection: (MFWR-jumper) must be fitted",    /* ERROR_FLASH_MONITOR_FLASH_LOCK */ NULL,    /* ERROR_FLASH_QRY_NOT_FOUND      */ NULL,    /* ERROR_FLASH_BOOT_WRITE_PROTECTED */ NULL} ;static UINT32 flash_last_error ;static char   flash_diag_msg[160] ;/* these variables are initialized at 'init' with the physical   address boundaries of:     a) system FLASH     b) monitor FLASH     c) file FLASH.   Following rule is to apply:     'start' <= physical-device-address-space < 'end'*/static UINT32  systemflash_phys_start ;static UINT32  systemflash_phys_end ;static UINT32  systemflash_block_size ;static UINT32  systemflash_bank_count ;static UINT32  systemflash_block_count ;static UINT32  monitorflash_phys_start ;static UINT32  monitorflash_phys_end ;static UINT32  monitorflash_block_size ;static UINT32  fileflash_phys_start ;static UINT32  fileflash_phys_end ;static UINT32  fileflash_block_size ;static UINT32  boot_phys_start ;static UINT32  boot_phys_end ;/************************************************************************ *      Static function prototypes ************************************************************************//************************************************************************ * *                          FLASH_STRATA_init *  Description : *  ------------- * This service initializes the FLASH driver to handle all * FLASH devices on this board environment. *   * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    not used *  'p_param',   INOUT, not used * * *  Return values : *  --------------- * *  'OK'(=0) * * * ************************************************************************/staticINT32 FLASH_STRATA_init(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          void   *p_param ) ;    /* INOUT: device parameter block       *//************************************************************************ * *                          FLASH_STRATA_write *  Description : *  ------------- *  This service writes data into a specified address location, which *  can be in either SYSTEM-FLASH or FILE-FLASH space. Default is RAM. *   * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    minor device number for multi device drivers *  'p_param',   IN,    variable of type, t_FLASH_write_descriptor. * * *  Return values : *  --------------- * * 'OK' = 0x00:                         data has been stored *  ERROR_FLASH_PROGRAM_ERROR           Flash device failure *  ERROR_FLASH_INVALID_ADDRESS,        Physical address not impl.     * * ************************************************************************/staticINT32 FLASH_STRATA_write(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          t_FLASH_write_descriptor *p_param ) ; /* IN: write data       *//************************************************************************ * *                          FLASH_STRATA_ctrl *  Description : *  ------------- *  This service comprise following specific FLASH services: *    1) 'ERASE_SYSTEMFLASH' *    2) 'ERASE_FILEFLASH' *    3) 'FLASH_CTRL_ERASE_FLASH_AREA' *    4) 'FLASH_CTRL_INQUIRE_FLASH_AREA' *    5) 'FLASH_CTRL_TEST_SYSTEMFLASH' *   * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    minor device number for multi device drivers *  'p_param',   IN,    variable of type, t_FLASH_ctrl_descriptor. * * *  Return values : *  --------------- * * 'OK' = 0x00:                         FLASH service completed successfully *  ERROR_FLASH_PROGRAM_ERROR           Flash device failure * * ************************************************************************/staticINT32 FLASH_STRATA_ctrl(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          t_FLASH_ctrl_descriptor *p_param ) ;  /* IN: write data       *//************************************************************************ * *                          FLASH_STRATA_is_system_flash_write_protected *  Description : *  ------------- *  Check if system flash id write protected *   * *  Parameters : *  ------------ * * * *  Return values : *  --------------- * *  FALSE: not write protected *  TRUE:  write protected * * ************************************************************************/staticbool FLASH_STRATA_is_system_flash_write_protected( void ) ;/************************************************************************ * *                          FLASH_STRATA_is_file_flash_write_protected *  Description : *  ------------- *  Check if file flash id write protected *   * *  Parameters : *  ------------ * * * *  Return values : *  --------------- * *  FALSE: not write protected *  TRUE:  write protected * * ************************************************************************/staticbool FLASH_STRATA_is_file_flash_write_protected( void ) ;/************************************************************************ * *                          FLASH_STRATA_is_monitor_flash_write_protected *  Description : *  ------------- *  Check if file flash id write protected * * *  Parameters : *  ------------ * * *

⌨️ 快捷键说明

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