How to Add a New Flash Driver to the Download Tool

The abstract of the document

The goal of this document is to guide the reader on how to modify the source code and rebuild the download tool to support a new flash type on an EP93xx board.

The principle of the download program

The strategy of the flash project is based on the internal serial booting mode of an EP93xx chip. It also takes into account of the different memory layouts of the EDB93xx boards.

First, the first-stage boot code running in the internal Ethernet buffer (0x80014000-0x80014800) detects the SDRAM automatically, initializes the serial, gets the second-stage code from the host PC, copies the second-stage code to SDRAM, and then switches to SDRAM to execute the second-stage code.

Second, the second-stage code has a standard architecture including the UART and flash drivers. This code has a flexible architecture and can be easily written by the C programming language. The C code can be easily changed to support a new flash type.

The architecture of the flash driver

The data structures of the flash driver

The erase sector information structure:



typedef struct EraseBlockInfo {

	unsigned long               blocks;

	unsigned long               block_size;

	} EraseBlockInfo_t;

	

The common flash interface information structure:



typedef struct CFIQuery {

	unsigned long               DeviceSize;

	unsigned long               NumEraseBlocks;

	struct EraseBlockInfo       sBlockInfo[4];

	} CFIQuery_t;

	

The flash information structure:



typedef struct FlashInfo {

	unsigned short              ManufactureId;

	unsigned short              DeviceId[4];

	unsigned short              ByteWidth;

	unsigned long               FlashBase;

	unsigned long               SysConBase;

	struct CFIQuery             *pQuery;

	} FlashInfo_t;

	

The function of the flash driver

The flash operation function pointer:



typedef struct FlashOps {

	int (*FlashQuery)(struct FlashInfo *pInfo);

	int (*FlashErase)(struct FlashInfo *pInfo, int iOffset, int len);

	int (*FlashProgram)(struct FlashInfo *pInfo, int iOffset, void *data, int len);

	} FlashOps_t;

	

The instance of Intel flash driver

Add the intel.c and intel.h

intel.h defines the Intel flash operation MACros and functions. Refer to download/src/src/intel.h. intel.c declares the Intel operation functions. Refer to download/src/src/intel.c. Three functions must be implemented so these functions can be called from main.c



Function: int IntelFlashQuery(struct FlashInfo *pInfo);

Description: This routine reads the flash manufacture ID and device ID.

Return: 0 - success, 1 - failure.



Function: int IntelFlashErase(struct FlashInfo *pInfo, int iOffset, int len);

Description: This routine programs the Intel flash.

Arguments: iOffset - the offset address.

	data - the data pointer.

	len  - the length.

Return: 0 - success, 1 - failure.



Function: int IntelFlashProgram(struct FlashInfo *pInfo, int iOffset, void *data, int len);

Description: This routine erases the sectors of Intel flash.

Arguments: iOffset - the offset address.

	len  - the length.

Return: 0 - success, 1 - failure.

	

Add the Intel operation function

Add the following function pointer to download/src/src/main.c



struct FlashOps sFlashOps[]={

    // AMD operation function pointer

    {

        AmdFlashQuery,

        AmdFlashErase,

        AmdFlashProgram

    },



+    // INTEL operation function pointer

+    {

+        IntelFlashQuery,

+        IntelFlashErase,

+        IntelFlashProgram

+    },

    

    // Add your operation function pointer





    // The last one indicates the termination

    {

        0,

        0,

        0

    }

};

	

Add the following code to download/src/src/main.c



else if(!sFlashOps[1].FlashQuery())

    {

        // The flash is intel compatible serial.

        spFlashOps = [1];

        

#ifdef _DBG 

        iOffSet = 0x00;     

        iFileSize = 0x20000;

        for(index=0; index<1024; index++)

        {

            data[index] = 0xaa;

        }

        spFlashOps->FlashErase(, iOffSet, iFileSize);

        spFlashOps->FlashProgram(, iOffSet, (void *)data, 1024);

#endif



        Serial_SendChar('I');

    }

	

Change the Makefile

Change download/src/src/Makefile to build the source code.



#

# The set of object files that comprise the download utility.

#

OBJS = init.o serial.o timer.o amd.o intel.o at25f1024.o sst25vf020.o main.o 

	

Build the download tool

Build the download tools on Linux platform

Make sure the 3.2.1-elf tools are in the search path.



#export PATH=/usr/local/arm/3.2.1-elf/bin:$PATH

#cd download/src

#make

	

Build the download tool on Windows platform

Build the download tool from the Windows command line



Microsoft Visual Studio - The Microsoft VC tools are required to build the code.

The tools should be under "C:\Program Files\Microsoft Visual Studio\VC98"

The ARM ADS tools - The ARM ADS tools are required to build the code.

The tools should be under "C:\Program Files\ARM\ADSv1_2\Bin"

>cd download\src

>set path=%CD%\download\src\bin;%path%;

>make