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

📄 strata32.c

📁 2440通过简易JTAG烧写LOADER的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************************
 NAME: strata32.c
 DESC: Strata Flash Programming code through 2410 JTAG 
 HISTORY:
 JUN.14.2002:LSJ     : ported for 2410
 Aug.19.2002:purnnamu: ported for 2410 JTAG version.
 Nov.15.2002:purnnamu: - Fast programming by removing _RESET() in programming loop 
                         and omitting nGCS1 deassertion
                       - E28F128 ClearLockBit function is added at sector erase step.
 *************************************************************************************/

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

#include "pin2440.h"
#include "Jtag.h"
//#include "K9S1208.h"
#include "sjf2440.h"

#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_ADDR_28F128      0x08000000  // nGCS1, 128MB area
#define TARGET_ADDR_28F128      0x0  // nGCS0, 128MB  yczhao HHTECH

static U32 srcAddr;

static U32 targetOffset; 
static U32 targetAddress; 
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 realAddr,U32 data);
static void Strata_EraseSector(int targetAddr);
static int  Strata_CheckID(int targetAddr);
static int  Strata_CheckDevice(int targetAddr);
static int  Strata_CheckBlockLock(int targetAddr);
static int Strata_ClearBlockLock(int targetAddr); 
static int  Strata_BlankCheck(int targetAddr,int targetSize);
static int  _WAIT(void);

/*yczhao HHTECH*/
#define _WR(addr,data)  MRW_Wr16Q(addr,data,0,0xf)
#define _RD(addr)       MRW_Rd16Q(addr,0,0xf)      
#define _RESET()	MRW_Wr16Q(targetAddress,0x00ff00ff,0,0xf)

void Program28F128J3A(void)
{
    int 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 0x0(Bank0) for programming.\n");
    printf("2. After programming, 28F128J3A may be located at 0x0(Bank0) for booting.\n");
         
    targetAddress=TARGET_ADDR_28F128;
    targetSize=imageSize;

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

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

    if ( (Strata_CheckID(targetAddress) & 0xffff) != 0x0089 )       // ID number = 0x0089
    {
		printf("id = %x\n",(Strata_CheckID(targetAddress) & 0xffff));
        printf("Identification check error !!\n");
        return ;
    }
    if ( (Strata_CheckDevice(targetAddress) & 0xffff) != 0x0018 )   // Device number=0x0018
    {
		printf("device = %x\n",(Strata_CheckDevice(targetAddress) & 0xffff));
        printf("Device check error !!\n");
        return ;
    }

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

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

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

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

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

	/*yczhao HHTECH*/
 //   for (i=0; i<targetSize; i+=4) 
	for (i=0; i<targetSize; i+=2) 
    {
        Strata_ProgFlash(i+targetAddress+targetOffset, *((U32 *)(srcAddr+i)));
        if((i%0x100)==0xfc)
            printf("[%x]",i+4);
    }
    printf("\nEnd of the data writing \n");

    _RESET();

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

}


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

//==========================================================================================
int Strata_CheckDevice(int targetAddr) 
{
    //_RESET();
//	_WR(targetAddr, 0x00900090);
	_WR(targetAddr, 0x00000090); //yczhao HHTECH
//    return _RD(targetAddr+0x4); // Read Device Code, including lower, higher 16-bit, 8MB, Intel Strate Flash ROM
                                // targetAddress must be the beginning location of a Block Address
/*yczhao HhTECH*/
	return _RD(targetAddr+0x2); // Read Device Code, including lower, higher 16-bit, 8MB, Intel Strate Flash ROM
                                // targetAddress must be the beginning location of a Block Address
}

//==========================================================================================
int Strata_CheckBlockLock(int targetAddr) 
{
    //_RESET();
 //   _WR(targetAddr, 0x00900090);
    _WR(targetAddr, 0x00000090); //yczhao HHTECH
 //   return _RD(targetAddr+0x8); 

	//yczhao HHTech
    return _RD(targetAddr+0x4);
    // Read Block Lock configuration, 
    // targetAddress must be the beginning location of a Block Address
}


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

    _RESET();  
}

/*
//==========================================================================================
void Strata_EraseSector(int targetAddress) 
{
    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(targetAddress, 0x00200020);
	//  _WR(targetAddress, 0x00d000d0);

⌨️ 快捷键说明

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