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

📄 strata32.c

📁 三星6410的烧写工具源码
💻 C
字号:
/*************************************************************************************
 NAME: strata32.c
 DESC: Strata Flash Programming code through 6410 JTAG 
 HISTORY:
 JUN.14.2002:LSJ     : ported for 6410
 Aug.19.2002:purnnamu: ported for 6410 JTAG version.
 Nov.15.2002:purnnamu: - Fast programming by removing _RESET() in programming loop 
                         and omitting nRCS1 deassertion
                       - E28F128 ClearLockBit function is added at sector erase step.
 *************************************************************************************/

#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
#include "..\include\def.h"

#include "..\include\pin6410.h"
#include "..\include\Jtag.h"
//#include "K9S1208.h"
#include "..\include\sjf6410.h"

#include "..\include\mem_rdwr.h"

//I have not tested yet about fast programming. But, it will reduce the programming time.
//IF the problem is occurred, let FAST_ROM_PROGRAM  0.
#define	FAST_ROM_PROGRAM	1

#define TARGET_RADDR_28F128      0x08000000  // nRCS1, 128MB area

static U32 srcRAddr;

static U32 targetOffset; 
static U32 targetRAddress; 
static U32 targetSize; 

static int error_erase=0;       // Read Status Register, SR.5
static int error_program=0;     // Read Status Register, SR.4


static int  Strata_ProgFlash(U32 realRAddr,U32 rdata);
static void Strata_EraseSector(int targetRAddr);
static int  Strata_CheckID(int targetRAddr);
static int  Strata_CheckDevice(int targetRAddr);
static int  Strata_CheckBlockLock(int targetRAddr);
static int Strata_ClearBlockLock(int targetRAddr); 
static int  Strata_BlankCheck(int targetRAddr,int targetSize);
static int  _WAIT(void);

#if FAST_ROM_PROGRAM	
    #define _WR(raddr,rdata)  MRW_Wr32QQ(raddr,rdata,0,0xf) 
#else
    #define _WR(raddr,rdata)  MRW_Wr32Q(raddr,rdata,0,0xf) 
#endif
#define _RD(raddr)       MRW_Rd32Q(raddr,0,0xf)      
#define _RESET()	MRW_Wr32Q(targetRAddress,0x00ff00ff,0,0xf)


void Program28F128J3A(void)
{
    U32 i;
    U32 temp;

    MRW_JtagInit();

    printf("\n[28F128J3A Flash JTAG Programmer]\n");
    printf("\n*** Very Important Notes ***\n");
    printf("1. 28F128J3A must be located at 0x08000000(Bank1) for programming.\n");
    printf("2. After programming, 28F128J3A may be located at 0x0(Bank0) for booting.\n");
         
    targetRAddress=TARGET_RADDR_28F128;
    targetSize=imageSize;

    printf("\nSource size = %xh\n",targetSize);
    printf("\nAvailable Target Offset RAddress: \n"); 
    printf("0x0,0x20000,0x40000, ..., 0x1ce0000\n");
    printf("Input target raddress offset [0x?] : ");
    scanf("%x",&targetOffset);

    printf("Target base raddress(0x08000000) = 0x%x\n",targetRAddress);
    printf("Target offset      (0x0)        = 0x%x\n",targetOffset);
    printf("Target size        (0x20000*n)  = 0x%x\n",targetSize);

    if ( (Strata_CheckID(targetRAddress) & 0xffff) != 0x0089 )       // ID number = 0x0089
    {
        printf("Identification check error !!\n");
        return ;
    }

    if ( (Strata_CheckDevice(targetRAddress) & 0xffff) != 0x0018 )   // Device number=0x0018
    {
        printf("Device check error !!\n");
        return ;
    }

    printf("\nErase the sector from 0x%x.\n", targetRAddress+targetOffset);

    for(i=0;i<targetSize;i+=0x20000)
    {
		//Strata_ClearBlockLock(targetRAddress+targetOffset+i); 
        Strata_EraseSector(targetRAddress+targetOffset+i);
    }

#if 0    
    if(!Strata_BlankCheck(targetRAddress+targetOffset,targetSize))
    {
        printf("Blank Check Error!!!\n");
        return;
    }
#else
    printf("\nBlank check is skipped.\n");
#endif

    printf("\nStart of the rdata writing...\n");

    srcRAddr=(U32)malloc(targetSize+4);
    if(srcRAddr==0)return;
    
    LoadImageFile((U8 *)srcRAddr,targetSize);

    for (i=0; i<targetSize; i+=4) 
    {
        Strata_ProgFlash(i+targetRAddress+targetOffset, *((U32 *)(srcRAddr+i)));
        if((i%0x100)==0xfc)
            printf("[%x]",i+4);
    }
    printf("\nEnd of the rdata writing \n");

    _RESET();

#if 1
    printf("Verifying Start...\n");
    for (i=0; i<targetSize; i+=4) 
    {
	temp=_RD(i+targetRAddress+targetOffset);
        if (temp != *((U32 *)(srcRAddr+i))) 
        {
            printf("Verify error: src %08x: %08x\n", srcRAddr+i, *((U32 *)(srcRAddr+i)));
            printf("              dst %08x: %08x\n", i+targetRAddress+targetOffset, temp);
            return;
        }
    }
    printf("Verifying End!!!");
#else
    printf("\nverifying is skipped.\n");
#endif

}


//==========================================================================================
int Strata_CheckID(int targetRAddr) 
{
    //_RESET();
    _WR(targetRAddr, 0x00900090); 
    return _RD(targetRAddr); // Read Identifier Code, including lower, higher 16-bit, 8MB, Intel Strate Flash ROM
                            // targetRAddress must be the beginning location of a Block RAddress
}

//==========================================================================================
int Strata_CheckDevice(int targetRAddr) 
{
    //_RESET();
    _WR(targetRAddr, 0x00900090);
    return _RD(targetRAddr+0x4); // Read Device Code, including lower, higher 16-bit, 8MB, Intel Strate Flash ROM
                                // targetRAddress must be the beginning location of a Block RAddress
}

//==========================================================================================
int Strata_CheckBlockLock(int targetRAddr) 
{
    //_RESET();
    _WR(targetRAddr, 0x00900090);
    return _RD(targetRAddr+0x8); 
    // Read Block Lock configuration, 
    // targetRAddress must be the beginning location of a Block RAddress
}


//==========================================================================================
int Strata_ClearBlockLock(int targetRAddr) 
{
    U32 status;
    //_RESET();
    _WR(targetRAddr, 0x00600060);
    _WR(targetRAddr, 0x00d000d0);
    
    while(1)
    {
	status=_RD(targetRAddr+0x8); 
	if(status&(1<<7))break;
    }

    _RESET();  
}

//==========================================================================================
void Strata_EraseSector(int targetRAddress) 
{
    unsigned long ReadStatus;
    unsigned long bSR5;     // Erase and Clear Lock-bits Status, lower 16bit, 8MB Intel Strate Flash ROM
    unsigned long bSR5_2;   // Erase and Clear Lock-bits Status, higher 16bit, 8MB Intel Strate Flash ROM
    unsigned long bSR7;     // Write State Machine Status, lower 16bit, 8MB Intel Strate Flash ROM
    unsigned long bSR7_2;   // Write State Machine Status, higher 16bit, 8MB Intel Strate Flash ROM
    
	//_RESET();
	//  _WR(targetRAddress, 0x00200020);
	//  _WR(targetRAddress, 0x00d000d0);
    _WR(targetRAddress, 0x00200020); // Block Erase, First Bus Cycle, targetRAddress is the raddress withint the block
    _WR(targetRAddress, 0x00d000d0); // Block Erase, Second Bus Cycle, targetRAddress is the raddress withint the block
    
    //_RESET();
    _WR(targetRAddress, 0x00700070); // Read Status Register, First Bus Cycle, targetRAddress is any valid raddress within the device
    ReadStatus=_RD(targetRAddress);  // Read Status Register, Second Bus Cycle, targetRAddress is any valid raddress within the device
    bSR7=ReadStatus & (1<<7);       // lower 16-bit 8MB Strata
    bSR7_2=ReadStatus & (1<<(7+16));// higher 16-bit 8MB Strata
    
	while(!bSR7 || !bSR7_2) 
    {
        _WR(targetRAddress, 0x00700070);
        ReadStatus=_RD(targetRAddress);
        bSR7=ReadStatus & (1<<7);
        bSR7_2=ReadStatus & (1<<(7+16));
//      printf("wait !!\n");
    }

    _WR(targetRAddress, 0x00700070); // When the block erase is complete, status register bit SR.5 should be checked. 
                    // If a block erase error is detected, the status register should be cleared before
                    // system software attempts correct actions.
    ReadStatus=_RD(targetRAddress);  
    
	bSR5=ReadStatus & (1<<5);           // lower 16-bit 8MB Strata 
    bSR5_2=ReadStatus & (1<<(5+16));    // higher 16-bit 8MB Strata 
    
	if (bSR5==0 && bSR5_2==0) 
    {
        printf("Block @%xh Erase O.K. \n",targetRAddress);
    } 
    else 
    {
        //printf("Error in Block Erasure!!\n");
        _WR(targetRAddress, 0x00500050); // Clear Status Register
        error_erase=1;                  // But not major, is it casual ?
    }

    _RESET();   // write 0xffh(_RESET()) after the last opoeration to reset the device to read array mode.
}

//==========================================================================================
int Strata_BlankCheck(int targetRAddr,int targetSize) 
{
    int i,j;
    for (i=0; i<targetSize; i+=4) 
    {
        j=_RD(i+targetRAddr);

        if (j!=0xffffffff)      // In erasure it changes all block dta to 0xff
        {
            printf("E : %x = %x\n", (i+targetRAddr), j);
            return 0;
        }
    }
    return 1;
}

//==========================================================================================
int Strata_ProgFlash(U32 realRAddr,U32 rdata) 
{
//    volatile U32 *ptargetRAddr;
    unsigned long ReadStatus;
    unsigned long bSR4;    // Erase and Clear Lock-bits Status, lower 16bit, 8MB Intel Strate Flash ROM
    unsigned long bSR4_2;  // Erase and Clear Lock-bits Status, higher 16bit, 8MB Intel Strate Flash ROM
    unsigned long bSR7;    // Write State Machine Status, lower 16bit, 8MB Intel Strate Flash ROM
    unsigned long bSR7_2;  // Write State Machine Status, higher 16bit, 8MB Intel Strate Flash ROM

    //ptargetRAddr = (volatile U32 *)realRAddr;
    //_RESET();

    _WR(realRAddr, 0x00400040);  // realRAddr is any valid adress within the device
                                // Word/Byte Program(or 0x00100010 can be used)
    //*ptargetRAddr=rdata;          // 32 bit rdata
    _WR(realRAddr, rdata);

#if 1
    //_RESET();
    _WR(realRAddr, 0x00700070);  // Read Status Register
    ReadStatus=_RD(realRAddr);   // realRAddr is any valid raddress within the device
    bSR7=ReadStatus & (1<<7);
    bSR7_2=ReadStatus & (1<<(7+16));
    while(!bSR7 || !bSR7_2) 
    {
        // _RESET();
        _WR(realRAddr, 0x00700070);        // Read Status Register
        ReadStatus=_RD(realRAddr);
        bSR7=ReadStatus & (1<<7);
        bSR7_2=ReadStatus & (1<<(7+16));
    }
    
    _WR(realRAddr, 0x00700070); 
    ReadStatus=_RD(realRAddr);             // Real Status Register
    bSR4=ReadStatus & (1<<4);
    bSR4_2=ReadStatus & (1<<(4+16));
    
    if (bSR4==0 && bSR4_2==0) 
    {
        //printf("Successful Program!!\n");
    } 
    else 
    {
        //printf("Error Program!!\n");
        _WR(realRAddr, 0x00500050);          // Clear Status Register
        error_program=1;                    // But not major, is it casual ?
    }
#endif

#if !FAST_ROM_PROGRAM
    _RESET();
#endif
    return 0;
}

⌨️ 快捷键说明

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