📄 mvflash.c
字号:
/******************************************************************************** Copyright 2002, GALILEO TECHNOLOGY, LTD. ** THIS CODE CONTAINS CONFIDENTIAL INFORMATION OF MARVELL. ** NO RIGHTS ARE GRANTED HEREIN UNDER ANY PATENT, MASK WORK RIGHT OR COPYRIGHT ** OF MARVELL OR ANY THIRD PARTY. MARVELL RESERVES THE RIGHT AT ITS SOLE ** DISCRETION TO REQUEST THAT THIS CODE BE IMMEDIATELY RETURNED TO MARVELL. ** THIS CODE IS PROVIDED "AS IS". MARVELL MAKES NO WARRANTIES, EXPRESSED, ** IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, COMPLETENESS OR PERFORMANCE. ** ** MARVELL COMPRISES MARVELL TECHNOLOGY GROUP LTD. (MTGL) AND ITS SUBSIDIARIES, ** MARVELL INTERNATIONAL LTD. (MIL), MARVELL TECHNOLOGY, INC. (MTI), MARVELL ** SEMICONDUCTOR, INC. (MSI), MARVELL ASIA PTE LTD. (MAPL), MARVELL JAPAN K.K. ** (MJKK), GALILEO TECHNOLOGY LTD. (GTL) AND GALILEO TECHNOLOGY, INC. (GTI). ********************************************************************************** mvFlash.c - FLASH memory functions and definitions for SV use** DESCRIPTION: * This mvFlash driver gives the user a convenient interface to the FLASH * memory located on the user`s board, it supports various layout* configurations such as:* 1. One pure 8 bit device (Such as AMD`s AM29LV040B).* 2. 1,2,4 or 8 devices 16 bit wide configured to operate in 8 bit mode.* 3. 1,2 or 4 devices each 16 bit wide.* Before using the driver you must call the initialization function at* least once or when ever you are changing the FLASH base address.* The list bellow contains the supported FLASH memory devices, new* devices can be added easily in the future.** DEPENDENCIES:* None.********************************************************************************//*includes*/#include "armboot.h"#include "mvFlash.h"/* locals *//******************************************************************************* mvFlashParametrs[] , mvFlashTypes[] ** Those two tables contain the supported mvFlash devices information* needed by the driver: * The first table "mvFlashParametrs" starts with 10 shared fields * (currently 6 are reserved):* index 0 => Pointer to an entry in the second table list* index 1 => baseAddress - Flash memory device base address.* index 2 => width - 1, 2, 4 or 8 Bytes. * index 3 => mode - PURE8, X8 or X16 mvFlash configuration* (for X16 devices only)* The second table (mvFlashTypes) contains: * Entry`s structure:* Manufacture ID,Device ID,number of sectors,list of sector`s sizes* (in Kbytes starting with sector number 0).* The end of the list is pointed with a zero.******************************************************************************/static unsigned int mvFlashParametrs[10]; /* 0 Entry pointer */ /* 1 Base address */ /* 2 Width */ /* 3 Mode */ /* 4,5,6,7,8,9, spare entries. */static unsigned int mvFlashTypes[] = { /* 0 */ AMD_FLASH,AM29F400BB,11,16,8,8,32,64,64,64,64,64,64,64, /* 1 */ AMD_FLASH,AM29F400BT,11,64,64,64,64,64,64,64,32,8,8,16, /* 2 */ ST_FLASH,M29W040 ,8,64,64,64,64,64,64,64,64, /* 3 */ AMD_FLASH,AM29LV040B,8,64,64,64,64,64,64,64,64, /* 4 */ AMD_FLASH,AM29LV800BT,19,64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,32,8,8,16, /* 5 */ INTEL_FLASH,I28F320J3A,32,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128, /* 6 */ INTEL_FLASH,I28F640J3A,64,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128, /* 7 */ INTEL_FLASH,I28F128J3A,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128, /* 8 */ AMD_FLASH,AM29LV400BB,11,16,8,8,32,64,64,64,64,64,64,64, /* 9 */ AMD_FLASH,AM29LV400BT,11,64,64,64,64,64,64,64,32,8,8,16, /* 10 */ INTEL_FLASH,I28F320B3_T,71,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,8,8,8,8,8,8,8,8, /* 11 */ INTEL_FLASH,I28F320B3_B,71,8,8,8,8,8,8,8,8,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, /* 12 */ INTEL_FLASH,I28F160B3_B,39,8,8,8,8,8,8,8,8,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64, /* 13 */ INTEL_FLASH,I28F160B3_T,39,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64, 64,64,8,8,8,8,8,8,8,8, /* 14 */ AMD_FLASH,AM29LV160DT,35,64,64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,32,8,8,16, /* 15 */ AMD_FLASH,AM29LV160DB,35,16,8,8,32,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64,64,64, /* 16 */ MXIC_FLASH,MX29LV160BT,35,64,64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,32,8,8,16, /* 17 */ MXIC_FLASH,MX29LV160AB,35,16,8,8,32,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,64,64,64,64,64,64,64, /* 18 */ SST_FLASH,SST39VF800A,19,64,64,64,64,64,64,64,64,64,64, 64,64,64,64,64,32,8,8,16, 0 /* End of list indicator */ };/* Local functions */static unsigned int mvFlashGetSize(void);static unsigned int mvFlashGetSectorSize(unsigned int);/******************************************************************************** mvFlashInit - Initializes the FLASH memory driver`s parameters.** DESCRIPTION:* This function auto detects flash memory which may be present in* the system according to the flashTypes table defined in * gtFlash.c and initializes the global internal data structures * with the flash's base address, width, pointer to flash in the* flashTypes table and flash mode (PURE8 , X8 , X16) .If the flash* device was not found in the flashTypes table by this function , * the return value will be 0, otherwise the return value will be * the flash's size that was found. this function must be called * at least once before using the flash memory. If the flash's base * address was changed, this function must be called again.** INPUTS: * flashBaseAddress - The physical base address for the flash * memory device. For example, if the Flash * Memory is connected to chip select 0 on the * device interface of the MV device the value* for the base address will be 0x1C00:0000.* flashWidth - The physical width of the flash memory* as connected to the MV's device interface * (1,2,4 or 8 bytes).* flashMode - Two forms of flash memory are supported by this * driver. Pure 8 bit devices (PURE8), such as boot * devices, and 16 bit devices which can be configured * to operate either as 8 bit devices (X8) or as 16 bit* devices (X16). ** OUTPUT:* None.** RETURN:* The flash's total size of a successful detection , 0 otherwise .********************************************************************************/unsigned int mvFlashInit(unsigned int flashBaseAddress, unsigned int flashWidth, FLASH_DEV_MODE flashMode){ unsigned short mfrId=0; unsigned short devId = 0xffff; unsigned int FirstAddr, SecondAddr, ThirdAddr; unsigned int pArray=0; unsigned int counter; unsigned int flashSize=0; /* update the list with relevant parametrs */ mvFlashParametrs[0] = 0; /* Default initialization */ mvFlashParametrs[1] = flashBaseAddress; mvFlashParametrs[2] = flashWidth; mvFlashParametrs[3] = flashMode; /* Get the FLASH`s ID */ switch(FLASH_WIDTH) { case 1: /* AMD or ST or MXIC ?? **/ if( flashMode == PURE8 ) /* Boot Flash*/ { FirstAddr = 0x5555; SecondAddr= 0x2aaa; ThirdAddr = 0x5555; } else /* X16 device configured to 8bit Mode */ { FirstAddr = 0xaaaa; SecondAddr= 0x5555; ThirdAddr = 0xaaaa; } mvFlashReset(); MV_WRITE_CHAR(FLASH_BASE_ADDR + FirstAddr,0xAA); MV_WRITE_CHAR(FLASH_BASE_ADDR + SecondAddr,0x55); MV_WRITE_CHAR(FLASH_BASE_ADDR + ThirdAddr,0x90); MV_READ_CHAR(FLASH_BASE_ADDR + 0x0,&mfrId); if (mfrId == AMD_FLASH || mfrId == ST_FLASH || mfrId == MXIC_FLASH) { mvFlashReset(); MV_WRITE_CHAR(FLASH_BASE_ADDR + FirstAddr,0xAA); MV_WRITE_CHAR(FLASH_BASE_ADDR + SecondAddr,0x55); MV_WRITE_CHAR(FLASH_BASE_ADDR + ThirdAddr,0x90); MV_READ_CHAR(FLASH_BASE_ADDR + 0x1,&devId); break; } /* Micron or Intel ?? **/ MV_WRITE_CHAR(FLASH_BASE_ADDR,0xff); /* Read Array */ /* Flash reset for Intel/Micron */ MV_WRITE_CHAR(FLASH_BASE_ADDR,0x90); /* IDENTIFY Device */ MV_READ_CHAR(FLASH_BASE_ADDR + 0x0,&mfrId); /*Address for ManufactureID*/ if(mfrId == INTEL_FLASH || mfrId == MICRON_FLASH) { MV_WRITE_CHAR(FLASH_BASE_ADDR,0xff); /* Read Array */ /*Flash reset for Intel/Micron*/ MV_WRITE_CHAR(FLASH_BASE_ADDR,0x90); /* IDENTIFY Device */ MV_READ_CHAR(FLASH_BASE_ADDR + 0x2,&devId); /*Address for DeviceID*/ } break; case 2: case 4: case 8: /* AMD or ST or MXIC ??? */ mvFlashReset(); MV_WRITE_SHORT(FLASH_BASE_ADDR + 0x5555 * FLASH_WIDTH,0xaa); MV_WRITE_SHORT(FLASH_BASE_ADDR + 0x2aaa * FLASH_WIDTH,0x55); MV_WRITE_SHORT(FLASH_BASE_ADDR + 0x5555 * FLASH_WIDTH,0x90); MV_READ_SHORT(FLASH_BASE_ADDR,&mfrId); mvFlashReset(); /* Read the device ID */ if (mfrId == AMD_FLASH || mfrId == SST_FLASH || mfrId == ST_FLASH || mfrId == MXIC_FLASH) { MV_WRITE_SHORT(FLASH_BASE_ADDR + 0x5555 * FLASH_WIDTH,0xaa); MV_WRITE_SHORT(FLASH_BASE_ADDR + 0x2aaa * FLASH_WIDTH,0x55); MV_WRITE_SHORT(FLASH_BASE_ADDR + 0x5555 * FLASH_WIDTH,0x90); MV_READ_SHORT(FLASH_BASE_ADDR + 0x1 * FLASH_WIDTH,&devId); break; } /* Micron or Intel ?? **/ mvFlashReset(); MV_WRITE_WORD(FLASH_BASE_ADDR,0x00ff00ff); MV_WRITE_WORD(FLASH_BASE_ADDR,0x00900090); if( (FLASH_WIDTH == 4) || (FLASH_WIDTH == 8) ) /* 32 or 64 bit */ { MV_READ_SHORT(FLASH_BASE_ADDR,&mfrId); } else /* FLASH_WIDTH = 2 */ { MV_READ_SHORT(FLASH_BASE_ADDR,&mfrId); } if( (mfrId == INTEL_FLASH) || (mfrId == MICRON_FLASH) ) { /* Flash reset for Intel/Micron */ mvFlashReset(); MV_WRITE_WORD(FLASH_BASE_ADDR,0x00ff00ff); MV_WRITE_WORD(FLASH_BASE_ADDR,0x00900090); if( (FLASH_WIDTH == 2) ||(FLASH_WIDTH == 4) ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -