wt_flash.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:90k
- /****************************************************************************
- File Name : tt_flash.c
- Description : Testtool FLASH Commands
- Copyright (C) 2004, ST Microelectronics
-
- ****************************************************************************/
- /* Includes --------------------------------------------------------------- */
- /* Standard Includes */
- #include <stdio.h>
- #include <stddef.h>
- #include <stdlib.h>
- #include <string.h>
- #include <debug.h>
- #include "stack.h"
- #include "stlite.h"
- #include "stddefs.h"
- #include "stdevice.h"
- /* STAPI Includes */
- #include "stflash.h"
- #include "sttbx.h"
- #include "testtool.h"
- /* Local Includes */
- #include "wts_app_data.h"
- #include "wts_flash.h"
- /* Private Types ------------------------------------------------------ */
- /* Private Constants -------------------------------------------------- */
- #define FREMONT
- /* Definitions for Flash */
- #if 0
- #define FLASH_BANK_0_BASE_ADDRESS_LOCAL 0x40000000 /* check this as it should be 7f80000 */
- #define WTFLASH_BANK_0_BASE FLASH_BANK_0_BASE_ADDRESS_LOCAL /*FLASH_BANK_0_BASE_ADDRESS*/
- #endif
- #ifdef ST_5105
- #define STFLASH_VPP_0_ENABLE 0x45200000
- #elif defined(ST_5100)
- #define STFLASH_VPP_0_ENABLE 0x41400000
- #endif
- #define WTFLASH_MAIN_SIZE 0x00010000 /*0x10000 = 64Kbytes *//*0x00020000*/
- #define WTFLASH_MAIN01_SIZE 0x00008000 /* 32Kb */
- #define WTFLASH_PARA_0_SIZE 0x00002000 /* 8Kb */
- #define WTFLASH_BOOT_0_SIZE 0x00004000 /* 16Kb */
- /* if BANK_1 defined it is available */
- #if defined(FLASH_BANK_1_BASE_ADDRESS)
- #define STFLASH_BANK_1_BASE FLASH_BANK_1_BASE_ADDRESS
- #define NUM_BANKS 2
- #else
- #define NUM_BANKS 1
- #endif
- /* if VPP not defined it is not needed */
- #if !defined(STFLASH_VPP_0_ENABLE)
- #define STFLASH_VPP_0_ENABLE (U32)NULL
- #endif
- #if !defined(STFLASH_VPP_1_ENABLE)
- #define STFLASH_VPP_1_ENABLE (U32)NULL
- #endif
- /*#define DEVICE_TYPE STFLASH_M29W160BT*/
- #define DEVICE_TYPE STFLASH_M29W320DT
- #define MIN_ACCESS_WIDTH STFLASH_ACCESS_16_BITS
- #define MAX_ACCESS_WIDTH STFLASH_ACCESS_16_BITS
- #define wtNUM_BLOCKS 135//35
- #define wtNUM_SECTIONS wtNUM_BLOCKS /*24*/
- #define wtTOTAL_BLOCKS ( wtNUM_BLOCKS)
- #define CR 13
- #define LF 10
- #define wtCODE_BLOCKS 16
- #define wtFIRST_CODE_BLOCK 0
- #define wtLANG_BLOCKS 8
- #define wtFIRST_LANG_BLOCK 16
- #define wtLNB_BLOCKS 2
- #define wtFIRST_LNB_BLOCK 24
- #define wtLOGO_BLOCKS 1
- #define wtFIRST_LOGO_BLOCK 31
- /* Private Variables -------------------------------------------------- */
- #if 1
- /* ------------------------STFLASH_M29W640DT-------------------------- */
- STFLASH_Block_t BlockData_s[wtNUM_BLOCKS] =
- {
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 8 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 9 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 10 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 11 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 12 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 13 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 14 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 15 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 16 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 17 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 18 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 19 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 20 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 21 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 22 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 23 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 24 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 25 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 26 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 27 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 28 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 29 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 30 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 8 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 9 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 10 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 11 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 12 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 13 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 14 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 15 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 16 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 17 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 18 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 19 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 20 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 21 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 22 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 23 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 24 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 25 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 26 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 27 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 28 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 29 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 60 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 8 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 9 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 10 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 11 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 12 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 13 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 14 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 15 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 16 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 17 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 18 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 19 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 20 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 21 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 22 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 23 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 24 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 25 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 26 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 27 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 28 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 29 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 90 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 8 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 9 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 10 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 11 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 12 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 13 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 14 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 15 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 16 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 17 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 18 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 19 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 20 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 21 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 22 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 23 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 24 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 25 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 26 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 27 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 28 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 29 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 120 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {WTFLASH_MAIN_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 8 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 9 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 10 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 11 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 12 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 13 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 14 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }}; /* 135 */
- /* ------------------------STFLASH_M29W160BT-------------------------- */
- #else
- STFLASH_Block_t BlockData_s[wtNUM_BLOCKS] =
- {
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*0*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*8*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*9*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
-
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*16*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*19*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*1.5M*/
-
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*24*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*25*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*26*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*27*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*28*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*29*/
- { WTFLASH_MAIN_SIZE, STFLASH_MAIN_BLOCK },/*30*/
-
- {WTFLASH_MAIN01_SIZE , STFLASH_PARAMETER_BLOCK }, /* 31 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 32 */
- {WTFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 33 */
- {WTFLASH_BOOT_0_SIZE , STFLASH_BOOT_BLOCK }}; /* 34 */
- #endif
- static U32 FlashSize = 0; /* Non-zero = file converted */
- static char *FlashData_p = NULL;
- /*static SectionInfo_t SectionInfo[wtNUM_SECTIONS]; gleam*/
- static SectionInfo_t SectionInfo[wtNUM_BLOCKS];
- static BlockInfo_t BlockInfo[wtTOTAL_BLOCKS + 1];
- static U32 BaseAddress[NUM_BANKS];
- static STFLASH_Block_t GetBlkDat_s[wtNUM_BLOCKS];
- BOOL binFile ;
- /* Private Macros ----------------------------------------------------- */
- extern U32 wtFlashBankBaseAddr;
- #define WTFLASH_BASE_ADDR1 wtFlashBankBaseAddr
- /* Global Variables ------------------------------------------------------- */
- STFLASH_Handle_t FLASHHndl[2];
- ST_DeviceName_t FLASHDeviceName[2] = {"Bank0", "Bank1"};
- /* Private Function prototypes ---------------------------------------- */
- /* Functions ---------------------------------------------------------- */
- /*-------------------------------------------------------------------------
- * Function : FLASH_Close
- * close FLASH
- * Input : None
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t FLASH_Close( U8 BankNum )
- {
- ST_ErrorCode_t ErrCode;
- ErrCode = STFLASH_Close(FLASHHndl[BankNum]);
- STTBX_Print(("STFLASH_Close()=%sn", wts_GetErrorText(ErrCode) ));
- return ( ErrCode );
- } /* end FLASH_Close */
- /*-------------------------------------------------------------------------
- * Function : FLASH_GetParams
- * Get Flash Parameters
- * Input : None
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t FLASH_GetParams( U8 BankNum, STFLASH_Params_t *FLASHParams_p )
- {
- ST_ErrorCode_t ErrCode;
-
- /* assign structure for returning data */
- FLASHParams_p->InitParams.Blocks = GetBlkDat_s;
- ErrCode = STFLASH_GetParams(FLASHHndl[BankNum], FLASHParams_p );
- #if 1
- STTBX_Print(("| ManufactCode =0x%04x | DeviceCode =0x%04x |n",FLASHParams_p->ManufactCode,FLASHParams_p->DeviceCode));
- #endif
- STTBX_Print(("STFLASH_GetParams(%d)=%sn", BankNum, wts_GetErrorText(ErrCode)));
- return ( ErrCode );
- } /* end FLASH_Close */
- /*-------------------------------------------------------------------------
- * Function : FLASH_Init
- * Initialise FLASH
- * Input : None
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t FLASH_Init( U8 BankNum )
- {
- ST_ErrorCode_t ErrCode;
- STFLASH_InitParams_t InitParams;
- InitParams.DeviceType = DEVICE_TYPE;
- #if 0
- STTBX_Print(("InitParams.DeviceType= %dn", DEVICE_TYPE));
- #endif
- if ( BankNum == BANK0 )
- {
- #if 0
- InitParams.BaseAddress = (U32*)WTFLASH_BANK_0_BASE;
- #else
- InitParams.BaseAddress = (U32*)WTFLASH_BASE_ADDR1; /*&wtFlashBankBaseAddr;*/
- STTBX_Print(("nBaseAddress=[0x%x]n",InitParams.BaseAddress));
- #endif
- InitParams.VppAddress = (U32*)STFLASH_VPP_0_ENABLE;
- }
- else
- {
- #if defined(STFLASH_BANK_1_BASE)
- InitParams.BaseAddress = (U32*)STFLASH_BANK_1_BASE;
- InitParams.VppAddress = (U32*)STFLASH_VPP_1_ENABLE;
- #else
- return ST_ERROR_FEATURE_NOT_SUPPORTED;
- #endif
- }
- InitParams.MinAccessWidth = MIN_ACCESS_WIDTH;
- InitParams.MaxAccessWidth = MAX_ACCESS_WIDTH;
- InitParams.NumberOfBlocks = wtNUM_BLOCKS;
- InitParams.Blocks = BlockData_s;
- InitParams.DriverPartition = SystemPartition;
- ErrCode = STFLASH_Init(FLASHDeviceName[BankNum], &InitParams );
- STTBX_Print(("STFLASH_Init(%s)=%sn", FLASHDeviceName[BankNum], wts_GetErrorText(ErrCode) ));
- return ( ErrCode );
- } /* end FLASH_Init */
- /*-------------------------------------------------------------------------
- * Function : FLASH_Open
- * Open FLASH
- * Input : None
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t FLASH_Open( U8 BankNum )
- {
- ST_ErrorCode_t ErrCode;
- STFLASH_OpenParams_t OpenParams;
-
- memset((char*)&OpenParams,0,sizeof(STFLASH_OpenParams_t));
-
- ErrCode = STFLASH_Open(FLASHDeviceName[BankNum], &OpenParams, &FLASHHndl[BankNum]);
- STTBX_Print(("STFLASH_Open(%s)=%sn", FLASHDeviceName[BankNum], wts_GetErrorText(ErrCode) ));
- return ( ErrCode );
- } /* end FLASH_Open */
- /*-------------------------------------------------------------------------
- * Function : FLASH_Term
- * Terminate FLASH
- * Input : ForceTerminate
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t FLASH_Term( BOOL ForceTerminate, U8 BankNum )
- {
- ST_ErrorCode_t ErrCode;
- STFLASH_TermParams_t TermParams;
- TermParams.ForceTerminate = ForceTerminate;
- ErrCode = STFLASH_Term(FLASHDeviceName[BankNum], &TermParams);
- STTBX_Print(("STFLASH_Term(%s)=%sn", FLASHDeviceName[BankNum], wts_GetErrorText(ErrCode) ));
- return ( ErrCode );
- } /* end FLASH_Term */
- /*-------------------------------------------------------------------------
- * Function : FLASH_SetupBlockInfo
- * Setup Block Info structure
- * Input :
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t FLASH_SetupBlockInfo( void )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- STFLASH_Params_t FLASHParams;
- U8 Bank=0, Block=0;
- U32 BlockStart = 0;
- static U8 Section = 0;
-
- memset((char*)&FLASHParams,0,sizeof(STFLASH_Params_t));
- if ( Section == 0 )
- {
- /*
- ** Set the address for each section
- */
- for ( Bank = 0; ( Bank < NUM_BANKS ) && ( ErrCode == ST_NO_ERROR ); Bank ++ )
- {
- ErrCode = FLASH_Init( Bank ); /* Init Bank */
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = FLASH_Open( Bank );
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = FLASH_GetParams( Bank, &FLASHParams );
- if ( ErrCode == ST_NO_ERROR )
- {
- BlockStart = BaseAddress[Bank] = (U32) FLASHParams.InitParams.BaseAddress;
- for ( Block = 0; Block < FLASHParams.InitParams.NumberOfBlocks; Block ++)
- {
- BlockInfo[Section].Bank = Bank;
- BlockInfo[Section].Address = BlockStart;
- BlockInfo[Section].Length = FLASHParams.InitParams.Blocks[Block].Length;
- #ifdef DEBUG_OUTPUT
- STTBX_Print(("Block %2d (%d) 0x%08x 0x%08x (%6d) bytesn",
- Block, Section,
- BlockInfo[Section].Address,
- BlockInfo[Section].Length,
- BlockInfo[Section].Length ));
- #endif
- Section ++;
- BlockStart += FLASHParams.InitParams.Blocks[Block].Length;
- }
- }
- ErrCode = FLASH_Term( TRUE, Bank );
- }
- }
- BlockInfo[Section].Address = BlockStart;
- }
- if ( ErrCode == ST_NO_ERROR )
- STTBX_Print(("Flash setup Ok (%d blocks)n", Section ));
- return( ErrCode );
- } /* end of FLASH_SetupBlockInfo */
- /*-------------------------------------------------------------------------
- * Function : FLASH_Setup
- * Setup Block Info structure
- * Input :
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t FLASH_Setup( void )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Bank;
-
- /* ** Set the address for each section*/
-
- for ( Bank = 0; ( Bank < NUM_BANKS ) && ( ErrCode == ST_NO_ERROR ); Bank ++ )
- {
- ErrCode = FLASH_Init( Bank ); /* Init Bank */
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = FLASH_Open( Bank );
- }
- if ( ErrCode == ST_NO_ERROR )
- STTBX_Print(("Flash setup Ok.....n" ));
- }
- return( ErrCode );
- } /* end of Flash_Setup */
- /*-------------------------------------------------------------------------
- * Function : FreeFileDataBuffer
- * as is
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void FreeFileDataBuffer(void)
- {
- /* deallocate File data buffer */
- if ( FlashData_p != NULL )
- memory_deallocate( SystemPartition, FlashData_p );
- } /* end of FreeFileDataBuffer() */
- /*-------------------------------------------------------------------------
- * Function : GetBlockNumber
- * Get block number from address
- * Input :
- * Output :
- * Return : Block number of address
- * ----------------------------------------------------------------------*/
- static U8 GetBlockNumber( U32 Address )
- {
- U8 Block;
- /* find the block this address is in */
- for ( Block = 0; Block < wtTOTAL_BLOCKS; Block++ )
- {
- if (( Address >= BlockInfo[Block].Address ) &&
- ( Address < (BlockInfo[Block].Address+BlockInfo[Block].Length)))
- {
- break;
- }
- }
- return Block;
- } /* end GetBlockNumber */
- /*-------------------------------------------------------------------------
- * Function : ConvertTotalMemory
- * Convert Raw Hex file into memory buffer suitable to write to
- * flash copying created data over data read from filem, the
- * created data will be smaller as each byte takes three bytes
- * in the Hex file.
- * Input :
- * Output :
- * Return : size of data in buffer
- * ----------------------------------------------------------------------*/
- static U32 ConvertTotalMemory( long unsigned int MemSize )
- {
- char *OldPtr, *NewPtr;
- int Section;
- U32 InOffset;
- U32 OutOffset;
- U32 BlockOffset;
- U32 Value=0;
- U8 Count=0 , Block=0;
-
- for ( Section = 0; Section < wtNUM_BLOCKS; Section ++ )
- {
- SectionInfo[Section].Block = 0xff;
- SectionInfo[Section].Address = 0;
- SectionInfo[Section].Offset = 0;
- SectionInfo[Section].Size = 0;
- }
- /* Convert File */
- Section = 0;
- OldPtr = FlashData_p;
- NewPtr = (char*) NULL;
-
- for ( InOffset = 0, OutOffset = 0; InOffset < MemSize; )
- {
- /* Line format =
- ** Address Data (both in hex)
- ** 12345678 11 22 33 44 55 etc. CR/LF
- */
- Value = (U32) strtol( OldPtr, &NewPtr, 16 );
- if ( NewPtr != OldPtr ) /* if conversion possible */
- {
- if ( Value > 255 ) /* which means it is an address */
- {
- if (( Block = GetBlockNumber( Value )) == wtTOTAL_BLOCKS )/*changed temp*/
- {
- STTBX_Print(("Invalid address 0x%xn", Value ));
- break;
- }
- else
- {
- /*
- ** check if the address is non-contiguous
- ** or if it is a new block
- */
- if ((( SectionInfo[Section].Address + SectionInfo[Section].Size ) != Value ) ||
- ( SectionInfo[Section].Block != Block ))
- {
- Section ++;
- }
- /* Start New Block */
- if ( SectionInfo[Section].Block == 0xff )
- {
- SectionInfo[Section].Address = Value;
- SectionInfo[Section].Block = Block;
- SectionInfo[Section].Offset = OutOffset;
- SectionInfo[Section].Size = 0;
- }
- }
- }
- else
- {
- BlockOffset = OutOffset;
- for ( Count = 0; Count < Section; Count++ )
- BlockOffset -= SectionInfo[Count].Size;
- if (( BlockOffset+1 ) > BlockInfo[SectionInfo[Section].Block].Length )
- {
- Section++;
- }
- /* Start New Block */
- if ( SectionInfo[Section].Block == 0xff )
- {
- SectionInfo[Section].Address = BlockInfo[Block].Address + BlockOffset;
- SectionInfo[Section].Block = GetBlockNumber(SectionInfo[Section].Address);
- SectionInfo[Section].Offset = OutOffset;
- SectionInfo[Section].Size = 0;
- }
- SectionInfo[Section].Size ++;
- FlashData_p[OutOffset++] = (char) Value;
- }
- InOffset += (U32)( NewPtr - OldPtr );
- OldPtr = NewPtr;
- if ( Section > wtNUM_BLOCKS )
- {
- STTBX_Print(("Program Limitationn"));
- exit(0);
- }
- }
- else
- break;
- } /* end of for loop */
- STTBX_Print(("n"));
- /* display the first few bytes of each section */
- for ( Section = 0; Section < wtNUM_BLOCKS; Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- STTBX_Print(("Section %2d, Block %3d, Addr 0x%08x, Offset 0x%08x, Size %6dn",
- Section,
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Offset,
- SectionInfo[Section].Size ));
- #ifdef DEBUG_INFO
- for ( InOffset = 0;
- ( InOffset < 32 ) && ( InOffset < SectionInfo[Section].Size );
- InOffset ++ )
- {
- STTBX_Print((" %02x", FlashData_p[ SectionInfo[Section].Offset + InOffset ] ));
- }
- STTBX_Print(("n"));
- #endif
- }
- }
- return ( OutOffset );
- } /* end ConvertTotalMemory */
- /*-------------------------------------------------------------------------
- * Function : ConvertMemory
- * Convert Raw Hex file into memory buffer suitable to write to
- * flash copying created data over data read from filem, the
- * created data will be smaller as each byte takes three bytes
- * in the Hex file.
- * Input :
- * Output :
- * Return : size of data in buffer
- * ----------------------------------------------------------------------*/
- static U32 ConvertMemory( long unsigned int MemSize )
- {
- char *OldPtr, *NewPtr;
- int Section;
- U32 InOffset;
- U32 OutOffset;
- U32 BlockOffset;
- U32 Value=0;
- U8 Count=0 , Block=0;
-
- for ( Section = 0; Section < wtNUM_SECTIONS; Section ++ )
- {
- SectionInfo[Section].Block = 0xff;
- SectionInfo[Section].Address = 0;
- SectionInfo[Section].Offset = 0;
- SectionInfo[Section].Size = 0;
- }
- /* Convert File */
- Section = 0;
- OldPtr = FlashData_p;
- NewPtr = (char*) NULL;
-
- for ( InOffset = 0, OutOffset = 0; InOffset < MemSize; )
- {
- /* Line format =
- ** Address Data (both in hex)
- ** 12345678 11 22 33 44 55 etc. CR/LF
- */
- Value = (U32) strtol( OldPtr, &NewPtr, 16 );
- if ( NewPtr != OldPtr ) /* if conversion possible */
- {
- if ( Value > 255 ) /* which means it is an address */
- {
- if (( Block = GetBlockNumber( Value )) == wtTOTAL_BLOCKS )/*changed temp*/
- {
- STTBX_Print(("Invalid address 0x%xn", Value ));
- break;
- }
- else
- {
- /*
- ** check if the address is non-contiguous
- ** or if it is a new block
- */
- if ((( SectionInfo[Section].Address + SectionInfo[Section].Size ) != Value ) ||
- ( SectionInfo[Section].Block != Block ))
- {
- Section ++;
- }
- /* Start New Block */
- if ( SectionInfo[Section].Block == 0xff )
- {
- SectionInfo[Section].Address = Value;
- SectionInfo[Section].Block = Block;
- SectionInfo[Section].Offset = OutOffset;
- SectionInfo[Section].Size = 0;
- }
- }
- }
- else
- {
- BlockOffset = OutOffset;
- for ( Count = 0; Count < Section; Count++ )
- BlockOffset -= SectionInfo[Count].Size;
- if (( BlockOffset+1 ) > BlockInfo[SectionInfo[Section].Block].Length )
- {
- Section++;
- }
- /* Start New Block */
- if ( SectionInfo[Section].Block == 0xff )
- {
- SectionInfo[Section].Address = BlockInfo[Block].Address + BlockOffset;
- SectionInfo[Section].Block = GetBlockNumber(SectionInfo[Section].Address);
- SectionInfo[Section].Offset = OutOffset;
- SectionInfo[Section].Size = 0;
- }
- SectionInfo[Section].Size ++;
- FlashData_p[OutOffset++] = (char) Value;
- }
- InOffset += (U32)( NewPtr - OldPtr );
- OldPtr = NewPtr;
- if ( Section > wtNUM_SECTIONS )
- {
- STTBX_Print(("Program Limitationn"));
- exit(0);
- }
- }
- else
- break;
- } /* end of for loop */
- STTBX_Print(("n"));
- /* display the first few bytes of each section */
- for ( Section = 0; Section < wtNUM_SECTIONS; Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- STTBX_Print(("Section %2d, Block %3d, Addr 0x%08x, Offset 0x%08x, Size %6dn",
- Section,
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Offset,
- SectionInfo[Section].Size ));
- #ifdef DEBUG_INFO
- for ( InOffset = 0;
- ( InOffset < 32 ) && ( InOffset < SectionInfo[Section].Size );
- InOffset ++ )
- {
- STTBX_Print((" %02x", FlashData_p[ SectionInfo[Section].Offset + InOffset ] ));
- }
- STTBX_Print(("n"));
- #endif
- }
- }
- return ( OutOffset );
- } /* end ConvertMemory */
- /*-------------------------------------------------------------------------
- * Function : ReadFile
- * Read HEX file into memory
- * Input :
- * Output :
- * Return : File size
- * ----------------------------------------------------------------------*/
- U32 FLASH_ReadFile( char *Filename )
- {
- long int ReadFile_p=0; /* datafile descriptor */
- long int FileSize=0; /* size in bytes of the file */
- int nameLength ;
- int Section;
- nameLength = strlen( Filename ) ;
- if ((Filename[nameLength-1]=='n' ||Filename[nameLength-1]=='N') &&
- (Filename[nameLength-2]=='i' ||Filename[nameLength-2]=='I') &&
- (Filename[nameLength-3]=='b' ||Filename[nameLength-3]=='B') &&
- Filename[nameLength-4]=='.' ) {
- binFile = TRUE ;
- ReadFile_p = debugopen(Filename, "rb");
- } else {
- binFile = FALSE ;
- ReadFile_p = debugopen(Filename, "rb");
- }
- STTBX_Print(("opening file = '%s'n", Filename ));
- /* Open and Read file into memory
- ReadFile_p = debugopen(Filename, "rb");*/
- STTBX_Print(("ReadFile_p = 0x%8xn",ReadFile_p));
-
- if(ReadFile_p < 0)
- {
- STTBX_Print(("Error opening file '%s'n", Filename ));
- return (0);
- }
- else
- {
- FileSize = debugfilesize(ReadFile_p);
- STTBX_Print(("FileSize = 0x%8xn",FileSize));
- /* allocate File data buffer */
- FreeFileDataBuffer();
- FlashData_p = (char*) memory_allocate( SystemPartition, (U32) FileSize );
- if ( FlashData_p != NULL )
- {
- STTBX_Print(("Loading '%s' into memory, wait .. ", Filename ));
- debugread(ReadFile_p, FlashData_p, (size_t) FileSize);
- STTBX_Print(("%d bytesn", FileSize ));
- }
- else
- {
- STTBX_Print(("Not enough memory for file (%d bytes)n", FileSize));
- FileSize = 0;
- }
- debugclose(ReadFile_p);
- }
- if (binFile)
- {
- for ( Section = 0; Section < wtNUM_BLOCKS; Section ++ )
- {
- SectionInfo[Section].Address = BlockInfo[Section].Address;
- SectionInfo[Section].Block = Section;
- SectionInfo[Section].Offset = BlockInfo[Section].Address-wtFlashBankBaseAddr;/*WTFLASH_BANK_0_BASE;*/
- SectionInfo[Section].Size = BlockInfo[Section].Length;
- }
- STTBX_Print(("n"));
- #if 1
- /* display the first few bytes of each section */
- for ( Section = 0; Section < wtNUM_BLOCKS; Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- STTBX_Print(("Section %2d, Block %3d, Addr 0x%08x, Offset 0x%08x, Size 0x%08xn",
- Section,
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Offset,
- SectionInfo[Section].Size ));
- }
- }
- #endif
- FlashSize = (U32)FileSize;
- return( FlashSize );
- }
- else
- {
- if ( FileSize > 0 )
- {
- /* convert buffer to binary and resize memory */
- STTBX_Print(("Converting file in memory, wait .. "));
- /* FlashSize = ConvertMemory( FileSize ); gleam*/
- FlashSize = ConvertTotalMemory( FileSize );
- if ( FlashSize > 0 )
- {
- STTBX_Print(("%d bytesn", FlashSize ));
- FlashData_p = (char*) memory_reallocate( SystemPartition, FlashData_p, FlashSize );
- }
- else
- STTBX_Print(("Invalid filen"));
- }
- return( FlashSize );
- }
- } /* end of FLASH_ReadFile */
- BOOL ReadProgram(char *Filename ,U32 StartAddress ,U32 Length )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- int Section, Bank;
- U32 ReadOffset;
- U32 NumberOfBytes;
- U8 *Buffer_p;
- int nameLength,numBytes ;
- long int ReadFile_p=0; /* datafile descriptor */
- volatile char *ptr_to_m;
- nameLength = strlen( Filename ) ;
- if (Filename[nameLength-1]=='n' &&
- Filename[nameLength-2]=='i' &&
- Filename[nameLength-3]=='b' &&
- Filename[nameLength-4]=='.' ) {
- binFile = TRUE ;
- ReadFile_p = debugopen(Filename, "wb");
- } else {
- Filename[nameLength ]= '.' ;
- Filename[nameLength+1]= 'b' ;
- Filename[nameLength+2]= 'i' ;
- Filename[nameLength+3]= 'n' ;
- binFile = FALSE ;
- ReadFile_p = debugopen(Filename, "wb");
- }
- if (ReadFile_p<=0) {
- STTBX_Print(("nCannot Create data file '%s'n", Filename ));
- return FALSE;
- }
-
- /* Read the data and compare */
- Bank = BlockInfo[ SectionInfo[0].Block ].Bank;
- ReadOffset = StartAddress - BaseAddress[Bank];
- /* allocate temp buffer to put flash data in */
- Buffer_p = memory_allocate( SystemPartition, Length );
- if ( Buffer_p != NULL )
- {
- STTBX_Print(("Address t| 0x%08x | 0x%08x |ReadOffset = 0x%08x |n ",
- StartAddress,
- StartAddress + Length-1,
- ReadOffset));
- ErrCode = STFLASH_Read( FLASHHndl[Bank],
- ReadOffset,
- Buffer_p,
- Length,
- &NumberOfBytes );
- if(ErrCode != ST_NO_ERROR)
- {
- STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
- return FALSE;
- }
- numBytes = (int) debugwrite( (long int)ReadFile_p, (void*)Buffer_p, Length);
- STTBX_Print(("write file size = %d bytesn", numBytes ));
- #if 0
- /* ===================== check whether array is erased================== */
- ptr_to_m = (char *)0x40000000; /* point to lowest _add in FlashROM */
- *ptr_to_m = (char) 0xf0f0; /* read_array command */
- for(ptr_to_m = (char *)0x40000000; /* point to flash_start and change type */
- ptr_to_m < (char *)0x40200000; /* point to flash_end and change type */
- ptr_to_m++,Buffer_p++) { /* inc pointer */
- *Buffer_p = *ptr_to_m;
- if (*ptr_to_m != *Buffer_p){ /* check all bits are set to 1 */
- debugmessage("ROMTOOL> ERROR!!! EPROM not erased properlyn");
- return 0;
- }
- }
-
- /* ===================== check whether array is erased================== */
- numBytes = (int) debugwrite( (long int)ReadFile_p, (U8 *)Buffer_p, Length);
- STTBX_Print(("write file size = %d bytesn", numBytes ));
- #endif
- /* deallocate temp buffer */
- memory_deallocate( SystemPartition, Buffer_p );
- }
- STTBX_Print(("!!!! Read file successfully!!!!n"));
- return TRUE;
- }
- /*-------------------------------------------------------------------------
- * Function : EraseLNBFlash
- * Function to Read Hex file and erase areas required
- * Input : EraselLNB
- * Output :
- * Return : EraseFailed = TRUE else FALSE
- * ----------------------------------------------------------------------*/
- BOOL EraseLNBFlash( BOOL Erasel)
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = TRUE;
- /* check data size */
- if ( Erasel )
- {
- EraseFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- if ( Erasel )
- {
- for ( Section = wtFIRST_LNB_BLOCK;( Section < wtFIRST_LNB_BLOCK+wtLNB_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
- {
- Bank = BlockInfo[Section].Bank;
- #ifdef DEBUG
- STTBX_Print(("tBaseAddress[Bank]=0x%08x n",BaseAddress[Bank]));
- STTBX_Print(("tBlockInfo[Section].Address=0x%08x n",BlockInfo[Section].Address));
- #endif
- EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
- STTBX_Print(("bank %d block %2dt| 0x%08x | 0x%08x | ",
- Bank, Section,
- BlockInfo[Section].Address,
- BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
- ErrCode = STFLASH_Erase( FLASHHndl[Bank],
- EraseOffset,
- BlockInfo[Section].Length );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Erase FAILEDn"));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- }
-
- STTBX_Print(("tt+------------+------------+n"));
- }
- if ( EraseFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- } /* end ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : EraseLNBFlash
- * Function to Read Hex file and erase areas required
- * Input : Erasel
- * Output :
- * Return : EraseFailed = TRUE else FALSE
- * ----------------------------------------------------------------------*/
- BOOL EraseLogoFlash( BOOL Erasel )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = TRUE;
- /* check data size */
- if ( Erasel )
- {
- EraseFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- if ( Erasel )
- {
- for ( Section = wtFIRST_LOGO_BLOCK;( Section < wtFIRST_LOGO_BLOCK+wtLOGO_BLOCKS) && ( ErrCode == ST_NO_ERROR ); Section ++)
- {
- Bank = BlockInfo[Section].Bank;
- #ifdef DEBUG
- STTBX_Print(("tBaseAddress[Bank]=0x%08x n",BaseAddress[Bank]));
- STTBX_Print(("tBlockInfo[Section].Address=0x%08x n",BlockInfo[Section].Address));
- #endif
- EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
- STTBX_Print(("bank %d block %2dt| 0x%08x | 0x%08x | ",
- Bank, Section,
- BlockInfo[Section].Address,
- BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
- ErrCode = STFLASH_Erase( FLASHHndl[Bank],
- EraseOffset,
- BlockInfo[Section].Length );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Erase FAILEDn"));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- }
-
- STTBX_Print(("tt+------------+------------+n"));
- }
- if ( EraseFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- } /* end ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : EraseLNBFlash
- * Function to Read Hex file and erase areas required
- * Input : Erasel
- * Output :
- * Return : EraseFailed = TRUE else FALSE
- * ----------------------------------------------------------------------*/
- BOOL EraseLanguageFlash( BOOL Erasel )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = TRUE;
- /* check data size */
- if ( Erasel )
- {
- EraseFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- if ( Erasel )
- {
- for ( Section = wtFIRST_LANG_BLOCK;( Section < wtFIRST_LANG_BLOCK+wtLANG_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
- {
- Bank = BlockInfo[Section].Bank;
- #ifdef DEBUG
- STTBX_Print(("tBaseAddress[Bank]=0x%08x n",BaseAddress[Bank]));
- STTBX_Print(("tBlockInfo[Section].Address=0x%08x n",BlockInfo[Section].Address));
- #endif
- EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
- STTBX_Print(("bank %d block %2dt| 0x%08x | 0x%08x | ",
- Bank, Section,
- BlockInfo[Section].Address,
- BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
- ErrCode = STFLASH_Erase( FLASHHndl[Bank],
- EraseOffset,
- BlockInfo[Section].Length );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Erase FAILEDn"));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- }
-
- STTBX_Print(("tt+------------+------------+n"));
- }
- if ( EraseFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- } /* end ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : EraseCodeFlash
- * Function to Read Hex file and erase areas required
- * Input : EraseCode
- * Output :
- * Return : EraseFailed = TRUE else FALSE
- * ----------------------------------------------------------------------*/
- BOOL EraseCodeFlash( BOOL EraseCode )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = TRUE;
- /* check data size */
- if ( EraseCode )
- {
- EraseFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- if ( EraseCode )
- {
- for ( Section = 0;( Section < wtCODE_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
- {
- Bank = BlockInfo[Section].Bank;
- #ifdef DEBUG
- STTBX_Print(("tBaseAddress[Bank]=0x%08x n",BaseAddress[Bank]));
- STTBX_Print(("tBlockInfo[Section].Address=0x%08x n",BlockInfo[Section].Address));
- #endif
- EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
- STTBX_Print(("bank %d block %2dt| 0x%08x | 0x%08x | ",
- Bank, Section,
- BlockInfo[Section].Address,
- BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
- ErrCode = STFLASH_Erase( FLASHHndl[Bank],
- EraseOffset,
- BlockInfo[Section].Length );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Erase FAILEDn"));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- }
-
- STTBX_Print(("tt+------------+------------+n"));
- }
- if ( EraseFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- } /* end ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : EraseFlash
- * Function to Read Hex file and erase areas required
- * Input : EraseAll
- * Output :
- * Return : EraseFailed = TRUE else FALSE
- * ----------------------------------------------------------------------*/
- BOOL EraseFlash( BOOL EraseAll )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = TRUE;
- volatile char *ptr_to_m;
- /* check data size */
- if (( FlashSize != 0 ) || EraseAll )
- {
- EraseFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- if ( EraseAll )
- {
- for ( Section = 0;( Section < wtTOTAL_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
- {
- Bank = BlockInfo[Section].Bank;
- #ifdef DEBUG
- STTBX_Print(("tBaseAddress[Bank]=0x%08x n",BaseAddress[Bank]));
- STTBX_Print(("tBlockInfo[Section].Address=0x%08x n",BlockInfo[Section].Address));
- #endif
- EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
- STTBX_Print(("bank %d block %2dt| 0x%08x | 0x%08x | ",
- Bank, Section,
- BlockInfo[Section].Address,
- BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
- ErrCode = STFLASH_Erase( FLASHHndl[Bank],
- EraseOffset,
- BlockInfo[Section].Length );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Erase FAILEDn"));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- /* ===================== check whether array is erased================== */
- ptr_to_m = (char *)wtFlashBankBaseAddr; /* point to lowest _add in FlashROM */
- *ptr_to_m = (char) 0xf0f0; /* read_array command */
- debugmessage("ROMTOOL> Checking whether the array has been fully erased....n");
- for(ptr_to_m = (char*)wtFlashBankBaseAddr; /* point to flash_start and change type */
- ptr_to_m < (char *)(wtFlashBankBaseAddr+0x00200000); /* point to flash_end and change type */
- ptr_to_m++) { /* inc pointer */
- if (*ptr_to_m != 0xff){ /* check all bits are set to 1 */
- debugmessage("ROMTOOL> ERROR!!! EPROM not erased properlyn");
- return 0;
- }
- }
- if( 1 )
- debugmessage( "ROMTOOL> Array has been erased successfully!an") ;
-
- /* ===================== check whether array is erased================== */
- }
- else
- {
- /* Find out which blocks are to be Erased */
- for ( Section = 0; ( Section < wtNUM_SECTIONS ) && ( EraseFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- /*
- ** Erase = erase whole block, valid parameters are block base address & block size
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- EraseOffset = BlockInfo[ SectionInfo[Section].Block ].Address - BaseAddress[Bank];
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- BlockInfo[ SectionInfo[Section].Block ].Address,
- BlockInfo[ SectionInfo[Section].Block ].Address +
- BlockInfo[ SectionInfo[Section].Block ].Length - 1 ));
-
- ErrCode = STFLASH_Erase( FLASHHndl[Bank],
- EraseOffset,
- BlockInfo[ SectionInfo[Section].Block ].Length );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("ErrCode = 0x%8xn",ErrCode));
- STTBX_Print(("Erase FAILEDn"));
- STTBX_Print(("FLASHHndl[Bank] = 0x%8Xn",FLASHHndl[Bank]));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- }
- }
- STTBX_Print(("tt+------------+------------+n"));
- }
- if ( EraseFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- } /* end ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : ProgramAllFlash
- * Function to Read Hex file and program flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL ProgramAllFlash( void )
- {
- ST_ErrorCode_t ErrCode;
- int Section, Bank;
- U32 NumberOfBytes;
- BOOL ProgramFailed;
- /* check data size */
- if ( FlashSize == 0 )
- ProgramFailed = TRUE;
- else
- {
- ProgramFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be written to */
- /* Write the data to the Flash */
- /*STTBX_Print(("Printing the contents of BlockInfo n"));
- for ( Section = 0; ( Section < wtNUM_SECTIONS ) ; Section ++ )
- {
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- }*/
- for ( Section = 0; ( Section < wtTOTAL_BLOCKS ) && ( ProgramFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- U32 WriteOffset;
- /*
- ** Write = write bytes from Offset
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- #ifdef DEBUG
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- #endif
- WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /*SectionInfo[Section].Address += 0x4; Tara*/
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Write( FLASHHndl[Bank],
- WriteOffset,
- (U8*)&FlashData_p[SectionInfo[Section].Offset],
- SectionInfo[Section].Size,
- &NumberOfBytes );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Program FAILEDn"));
- ProgramFailed = TRUE;
- }
- else
- STTBX_Print(("PROGRAMMEDn"));
- }
- }
- if ( ProgramFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end ProgramAllFlash */
- /*-------------------------------------------------------------------------
- * Function : ProgramLNBFlash
- * Function to Read Hex file and program flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL ProgramLNBFlash( void )
- {
- ST_ErrorCode_t ErrCode;
- int Section, Bank;
- U32 NumberOfBytes;
- BOOL ProgramFailed;
- /* check data size */
- if ( FlashSize == 0 )
- ProgramFailed = TRUE;
- else
- {
- ProgramFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be written to */
- /* Write the data to the Flash */
- /*STTBX_Print(("Printing the contents of BlockInfo n"));
- for ( Section = 0; ( Section < wtNUM_SECTIONS ) ; Section ++ )
- {
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- }*/
- for ( Section = wtFIRST_LNB_BLOCK; ( Section < wtFIRST_LNB_BLOCK+wtLNB_BLOCKS ) && ( ProgramFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- U32 WriteOffset;
- /*
- ** Write = write bytes from Offset
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- #ifdef DEBUG
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- #endif
- WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /*SectionInfo[Section].Address += 0x4; Tara*/
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Write( FLASHHndl[Bank],
- WriteOffset,
- (U8*)&FlashData_p[SectionInfo[Section-wtFIRST_LNB_BLOCK].Offset],
- SectionInfo[Section-wtFIRST_LNB_BLOCK].Size,
- &NumberOfBytes );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Program FAILEDn"));
- ProgramFailed = TRUE;
- }
- else
- STTBX_Print(("PROGRAMMEDn"));
- }
- }
- if ( ProgramFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end ProgramLNBFlash */
- /*-------------------------------------------------------------------------
- * Function : ProgramLNBFlash
- * Function to Read Hex file and program flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL ProgramLogoFlash( void )
- {
- ST_ErrorCode_t ErrCode;
- int Section, Bank;
- U32 NumberOfBytes;
- BOOL ProgramFailed;
- /* check data size */
- if ( FlashSize == 0 )
- ProgramFailed = TRUE;
- else
- {
- ProgramFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be written to */
- /* Write the data to the Flash */
- /*STTBX_Print(("Printing the contents of BlockInfo n"));
- for ( Section = 0; ( Section < wtNUM_SECTIONS ) ; Section ++ )
- {
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- }*/
- for ( Section = wtFIRST_LOGO_BLOCK; ( Section < wtFIRST_LOGO_BLOCK+wtLOGO_BLOCKS ) && ( ProgramFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- U32 WriteOffset;
- /*
- ** Write = write bytes from Offset
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- #ifdef DEBUG
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- #endif
- WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /*SectionInfo[Section].Address += 0x4; Tara*/
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Write( FLASHHndl[Bank],
- WriteOffset,
- (U8*)&FlashData_p[SectionInfo[Section-wtFIRST_LOGO_BLOCK].Offset],
- SectionInfo[Section-wtFIRST_LOGO_BLOCK].Size,
- &NumberOfBytes );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Program FAILEDn"));
- ProgramFailed = TRUE;
- }
- else
- STTBX_Print(("PROGRAMMEDn"));
- }
- }
- if ( ProgramFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end ProgramLNBFlash */
- /*-------------------------------------------------------------------------
- * Function : ProgramLNBFlash
- * Function to Read Hex file and program flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL ProgramLanguageFlash( void )
- {
- ST_ErrorCode_t ErrCode;
- int Section, Bank;
- U32 NumberOfBytes;
- BOOL ProgramFailed;
- /* check data size */
- if ( FlashSize == 0 )
- ProgramFailed = TRUE;
- else
- {
- ProgramFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be written to */
- /* Write the data to the Flash */
- /*STTBX_Print(("Printing the contents of BlockInfo n"));
- for ( Section = 0; ( Section < wtNUM_SECTIONS ) ; Section ++ )
- {
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- }*/
- for ( Section = wtFIRST_LANG_BLOCK; ( Section < wtFIRST_LANG_BLOCK+wtLANG_BLOCKS ) && ( ProgramFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- U32 WriteOffset;
- /*
- ** Write = write bytes from Offset
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- #ifdef DEBUG
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- #endif
- WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /*SectionInfo[Section].Address += 0x4; Tara*/
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Write( FLASHHndl[Bank],
- WriteOffset,
- (U8*)&FlashData_p[SectionInfo[Section-wtFIRST_LANG_BLOCK].Offset],
- SectionInfo[Section-wtFIRST_LANG_BLOCK].Size,
- &NumberOfBytes );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Program FAILEDn"));
- ProgramFailed = TRUE;
- }
- else
- STTBX_Print(("PROGRAMMEDn"));
- }
- }
- if ( ProgramFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end ProgramLNBFlash */
- /*-------------------------------------------------------------------------
- * Function : ProgramFlash
- * Function to Read Hex file and program flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL ProgramFlash( void )
- {
- ST_ErrorCode_t ErrCode;
- int Section, Bank;
- U32 NumberOfBytes;
- BOOL ProgramFailed;
- /* check data size */
- if ( FlashSize == 0 )
- ProgramFailed = TRUE;
- else
- {
- ProgramFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be written to */
- /* Write the data to the Flash */
- /*STTBX_Print(("Printing the contents of BlockInfo n"));
- for ( Section = 0; ( Section < wtNUM_SECTIONS ) ; Section ++ )
- {
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- }*/
- for ( Section = 0; ( Section < wtNUM_SECTIONS ) && ( ProgramFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- U32 WriteOffset;
- /*
- ** Write = write bytes from Offset
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- #ifdef DEBUG
- STTBX_Print(("Section=%dt", Section ));
- STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
- STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
- STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
- #endif
- WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /*SectionInfo[Section].Address += 0x4; Tara*/
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Write( FLASHHndl[Bank],
- WriteOffset,
- (U8*)&FlashData_p[SectionInfo[Section].Offset],
- SectionInfo[Section].Size,
- &NumberOfBytes );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Program FAILEDn"));
- ProgramFailed = TRUE;
- }
- else
- STTBX_Print(("PROGRAMMEDn"));
- }
- }
- if ( ProgramFailed == TRUE )
- {
- FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : VerifyAllFlash
- * Function to Read Hex file and verify flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL VerifyAllFlash( void )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- int Section, Bank;
- U32 Length;
- U32 ReadOffset;
- U32 NumberOfBytes;
- U8 *Buffer_p;
- BOOL VerifyFailed;
- /* check data size */
- if ( FlashSize == 0 )
- VerifyFailed = TRUE;
- else
- {
- VerifyFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be verified */
- /* Read the data and compare */
- for ( Section = 0; ( Section < wtTOTAL_BLOCKS ) && ( VerifyFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- Length = BlockInfo[ SectionInfo[Section].Block ].Length;
- ReadOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /* allocate temp buffer to put flash data in */
- Buffer_p = memory_allocate( SystemPartition, Length );
- if ( Buffer_p != NULL )
- {
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Read( FLASHHndl[Bank],
- ReadOffset,
- Buffer_p,
- SectionInfo[Section].Size,
- &NumberOfBytes );
- if(ErrCode != ST_NO_ERROR)
- {
- STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
- }
- if ( memcmp( Buffer_p,(U8*)&FlashData_p[SectionInfo[Section].Offset],
- SectionInfo[Section].Size ) != 0 )
- {
- STTBX_Print(("Verify FAILEDn"));
- VerifyFailed = TRUE;
- }
- else
- STTBX_Print(("VERIFIEDn"));
- /* deallocate temp buffer */
- memory_deallocate( SystemPartition, Buffer_p );
- }
- }
- }
- FreeFileDataBuffer();
-
- if ( VerifyFailed == TRUE )
- {
- STTBX_Print(("!!!! VERIFY Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end VerifyAllFlash */
- /*-------------------------------------------------------------------------
- * Function : VerifyLNBFlash
- * Function to Read Hex file and verify flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL VerifyLNBFlash( void )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- int Section, Bank;
- U32 Length;
- U32 ReadOffset;
- U32 NumberOfBytes;
- U8 *Buffer_p;
- BOOL VerifyFailed;
-
- /* check data size */
- if ( FlashSize == 0 )
- VerifyFailed = TRUE;
- else
- {
- VerifyFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be verified */
- /* Read the data and compare */
- for ( Section = wtFIRST_LNB_BLOCK; ( Section < wtFIRST_LNB_BLOCK+wtLNB_BLOCKS ) && ( VerifyFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- Length = BlockInfo[ SectionInfo[Section].Block ].Length;
- ReadOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /* allocate temp buffer to put flash data in */
- Buffer_p = memory_allocate( SystemPartition, Length );
- if ( Buffer_p != NULL )
- {
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Read( FLASHHndl[Bank],
- ReadOffset,
- Buffer_p,
- SectionInfo[Section].Size,
- &NumberOfBytes );
- if(ErrCode != ST_NO_ERROR)
- {
- STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
- }
- if ( memcmp( Buffer_p,(U8*)&FlashData_p[SectionInfo[Section-wtFIRST_LNB_BLOCK].Offset],
- SectionInfo[Section-wtFIRST_LNB_BLOCK].Size ) != 0 )
- {
- STTBX_Print(("Verify FAILEDn"));
- VerifyFailed = TRUE;
- }
- else
- STTBX_Print(("VERIFIEDn"));
- /* deallocate temp buffer */
- memory_deallocate( SystemPartition, Buffer_p );
- }
- }
- }
- FreeFileDataBuffer();
-
- if ( VerifyFailed == TRUE )
- {
- STTBX_Print(("!!!! VERIFY Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end VerifyLNBFlash */
- /*-------------------------------------------------------------------------
- * Function : VerifyLNBFlash
- * Function to Read Hex file and verify flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL VerifyLogoFlash( void )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- int Section, Bank;
- U32 Length;
- U32 ReadOffset;
- U32 NumberOfBytes;
- U8 *Buffer_p;
- BOOL VerifyFailed;
-
- /* check data size */
- if ( FlashSize == 0 )
- VerifyFailed = TRUE;
- else
- {
- VerifyFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be verified */
- /* Read the data and compare */
- for ( Section = wtFIRST_LOGO_BLOCK; ( Section < wtFIRST_LOGO_BLOCK+wtLOGO_BLOCKS ) && ( VerifyFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- Length = BlockInfo[ SectionInfo[Section].Block ].Length;
- ReadOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /* allocate temp buffer to put flash data in */
- Buffer_p = memory_allocate( SystemPartition, Length );
- if ( Buffer_p != NULL )
- {
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Read( FLASHHndl[Bank],
- ReadOffset,
- Buffer_p,
- SectionInfo[Section].Size,
- &NumberOfBytes );
- if(ErrCode != ST_NO_ERROR)
- {
- STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
- }
- if ( memcmp( Buffer_p,(U8*)&FlashData_p[SectionInfo[Section-wtFIRST_LOGO_BLOCK].Offset],
- SectionInfo[Section-wtFIRST_LOGO_BLOCK].Size ) != 0 )
- {
- STTBX_Print(("Verify FAILEDn"));
- VerifyFailed = TRUE;
- }
- else
- STTBX_Print(("VERIFIEDn"));
- /* deallocate temp buffer */
- memory_deallocate( SystemPartition, Buffer_p );
- }
- }
- }
- FreeFileDataBuffer();
-
- if ( VerifyFailed == TRUE )
- {
- STTBX_Print(("!!!! VERIFY Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end VerifyLNBFlash */
- /*-------------------------------------------------------------------------
- * Function : VerifyLNBFlash
- * Function to Read Hex file and verify flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL VerifyLanguageFlash( void )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- int Section, Bank;
- U32 Length;
- U32 ReadOffset;
- U32 NumberOfBytes;
- U8 *Buffer_p;
- BOOL VerifyFailed;
-
- /* check data size */
- if ( FlashSize == 0 )
- VerifyFailed = TRUE;
- else
- {
- VerifyFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be verified */
- /* Read the data and compare */
- for ( Section = wtFIRST_LANG_BLOCK; ( Section < wtFIRST_LANG_BLOCK+wtLANG_BLOCKS ) && ( VerifyFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- Length = BlockInfo[ SectionInfo[Section].Block ].Length;
- ReadOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /* allocate temp buffer to put flash data in */
- Buffer_p = memory_allocate( SystemPartition, Length );
- if ( Buffer_p != NULL )
- {
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Read( FLASHHndl[Bank],
- ReadOffset,
- Buffer_p,
- SectionInfo[Section].Size,
- &NumberOfBytes );
- if(ErrCode != ST_NO_ERROR)
- {
- STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
- }
- if ( memcmp( Buffer_p,(U8*)&FlashData_p[SectionInfo[Section-wtFIRST_LANG_BLOCK].Offset],
- SectionInfo[Section-wtFIRST_LANG_BLOCK].Size ) != 0 )
- {
- STTBX_Print(("Verify FAILEDn"));
- VerifyFailed = TRUE;
- }
- else
- STTBX_Print(("VERIFIEDn"));
- /* deallocate temp buffer */
- memory_deallocate( SystemPartition, Buffer_p );
- }
- }
- }
- FreeFileDataBuffer();
-
- if ( VerifyFailed == TRUE )
- {
- STTBX_Print(("!!!! VERIFY Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end VerifyLNBFlash */
- /*-------------------------------------------------------------------------
- * Function : VerifyFlash
- * Function to Read Hex file and verify flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL VerifyFlash( void )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- int Section, Bank;
- U32 Length;
- U32 ReadOffset;
- U32 NumberOfBytes;
- U8 *Buffer_p;
- BOOL VerifyFailed;
- /* check data size */
- if ( FlashSize == 0 )
- VerifyFailed = TRUE;
- else
- {
- VerifyFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- /* Find out which blocks are to be verified */
- /* Read the data and compare */
- for ( Section = 0; ( Section < wtNUM_SECTIONS ) && ( VerifyFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- Length = BlockInfo[ SectionInfo[Section].Block ].Length;
- ReadOffset = SectionInfo[Section].Address - BaseAddress[Bank];
- /* allocate temp buffer to put flash data in */
- Buffer_p = memory_allocate( SystemPartition, Length );
- if ( Buffer_p != NULL )
- {
- STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
- SectionInfo[Section].Block,
- SectionInfo[Section].Address,
- SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
- ErrCode = STFLASH_Read( FLASHHndl[Bank],
- ReadOffset,
- Buffer_p,
- SectionInfo[Section].Size,
- &NumberOfBytes );
- if(ErrCode != ST_NO_ERROR)
- {
- STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
- }
- if ( memcmp( Buffer_p,(U8*)&FlashData_p[SectionInfo[Section].Offset],
- SectionInfo[Section].Size ) != 0 )
- {
- STTBX_Print(("Verify FAILEDn"));
- VerifyFailed = TRUE;
- }
- else
- STTBX_Print(("VERIFIEDn"));
- /* deallocate temp buffer */
- memory_deallocate( SystemPartition, Buffer_p );
- }
- }
- }
- FreeFileDataBuffer();
-
- if ( VerifyFailed == TRUE )
- {
- STTBX_Print(("!!!! VERIFY Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end VerifyFlash */
- /* Testtool Functions --------------------------------------------------- */
- #ifdef TESTTOOL
- /*-------------------------------------------------------------------------
- * Function : TTFLASH_GetParams
- *
- * Input : *pars_p, *result_sym_p
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- static BOOL TTFLASH_GetParams( STTST_Parse_t *pars_p, char *Result )
- {
- ST_ErrorCode_t ErrCode;
- STFLASH_Params_t FLASHParams;
- STFLASH_Params_t *FLASHParams_p;
- U8 BankNum;
- U8 Block;
- U32 BlockStart;
- /* Get Flash bank parameter from command line */
- STTST_GetInteger( pars_p, BANK0, (S32 *)&BankNum );
- ErrCode = FLASH_GetParams(BankNum, &FLASHParams);
- FLASHParams_p = &FLASHParams;
- BlockStart = (U32) FLASHParams_p->InitParams.BaseAddress;
- STTBX_Print(("Bank %d, Blocks %dn", BankNum,
- FLASHParams_p->InitParams.NumberOfBlocks ));
- STTBX_Print(("Base Address 0x%08xn", FLASHParams_p->InitParams.BaseAddress ));
- STTBX_Print(("VppAddress 0x%08xn",FLASHParams_p->InitParams.VppAddress ));
- STTBX_Print(("Manufacturer Code 0x%08Xn", FLASHParams_p->ManufactCode ));
- STTBX_Print(("Device Code 0x%08Xn", FLASHParams_p->DeviceCode ));
- STTBX_Print(("AccessWidths Min %d, Max %dn",
- FLASHParams_p->InitParams.MinAccessWidth,
- FLASHParams_p->InitParams.MaxAccessWidth ));
- STTBX_Print(("Block Start Size Typen"));
- for ( Block = 0; Block < FLASHParams_p->InitParams.NumberOfBlocks; Block ++)
- {
- STTBX_Print(("%5d 0x%08x %8d ",
- Block,
- BlockStart,
- FLASHParams_p->InitParams.Blocks[Block].Length ));
- switch( FLASHParams_p->InitParams.Blocks[Block].Type )
- {
- case STFLASH_EMPTY_BLOCK:
- STTBX_Print(("Emptyn"));
- break;
- case STFLASH_BOOT_BLOCK:
- STTBX_Print(("Bootn"));
- break;
- case STFLASH_PARAMETER_BLOCK:
- STTBX_Print(("Parametern"));
- break;
- case STFLASH_MAIN_BLOCK:
- STTBX_Print(("Mainn"));
- break;
- default:
- STTBX_Print(("Unknownn"));
- break;
-
- }
- BlockStart += FLASHParams_p->InitParams.Blocks[Block].Length;
- }
- return ( ErrCode == ST_NO_ERROR ? FALSE : TRUE);
- } /* end TTFLASH_GetParams */
- /*-------------------------------------------------------------------------
- * Function : TT_SetupBlockInfo
- * Setup FLASH Block Info
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL TT_SetupBlockInfo( STTST_Parse_t *pars_p, char *Result )
- {
- ST_ErrorCode_t ErrCode;
-
- ErrCode = FLASH_SetupBlockInfo();
-
- return ( ErrCode != ST_NO_ERROR ? TRUE : FALSE );
- }
- /*-------------------------------------------------------------------------
- * Function : TT_FlashSetup
- * Setup FLASH Block Info
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL TT_FlashSetup( STTST_Parse_t *pars_p, char *Result )
- {
- ST_ErrorCode_t ErrCode;
-
- ErrCode = FLASH_Setup();
-
- return ( ErrCode != ST_NO_ERROR ? TRUE : FALSE );
- }
- /*-------------------------------------------------------------------------
- * Function : TT_ReadFile
- * Function to Read Hex file
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL TT_ReadFile( STTST_Parse_t *pars_p, char *Result )
- {
- char Filename[81];
- STTST_GetString( pars_p, "flash.hex", Filename, 80 );
- /* Read File */
- /* Convert from file format to memory format */
-
- STTBX_Print(("filename = %sn",Filename));
- if ( FlashSize == 0 )
- FlashSize = FLASH_ReadFile( Filename );
-
- return ( FlashSize == 0 ? TRUE : FALSE );
- }
- /*-------------------------------------------------------------------------
- * Function : TT_EraseFlash
- * Function to erase flash for loaded data
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL TT_EraseFlash( STTST_Parse_t *pars_p, char *Result )
- {
- char Text[11];
- BOOL EraseAll;
- STTST_GetString( pars_p, "", Text, 10 );
- if ( strcmp( Text, "ALL" ) == 0 )
- {
- EraseAll = TRUE;
- STTBX_Print(("EraseAll = TRUEn"));
- }
- else
- {
- EraseAll = FALSE;
- STTBX_Print(("EraseAll = FALSEn"));
- }
- return EraseFlash( EraseAll );
- }
- /*-------------------------------------------------------------------------
- * Function : TT_ProgramFlash
- * Function to program flash with loaded data
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL TT_ProgramFlash( STTST_Parse_t *pars_p, char *Result )
- {
- return ProgramFlash();
- }
- /*-------------------------------------------------------------------------
- * Function : TT_VerifyFlash
- * Function to verify flash with loaded data
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL TT_VerifyFlash( STTST_Parse_t *pars_p, char *Result )
- {
- return VerifyFlash();
- }
- #endif /* TESTTOOL */
- /*-------------------------------------------------------------------------
- * Function : FLASH_InitCommands
- * Definition of the macros
- * (commands and constants to be used with Testtool)
- * Input :
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- BOOL FLASH_InitCommand( void )
- {
- BOOL RetErr;
- RetErr = FALSE;
-
- #ifdef TESTTOOL
- RetErr |= STTST_RegisterCommand("FLASH_GETPARMS", TTFLASH_GetParams, "Get FLASH Parameters");
- RetErr |= STTST_RegisterCommand("FLASH_BLOCKINFO", TT_SetupBlockInfo, "Get Flash Block Data");
- RetErr |= STTST_RegisterCommand("FLASH_SETUP", TT_FlashSetup, "Setup Flash Bank(Init&Open) Data");
- RetErr |= STTST_RegisterCommand("FLASH_ERASE", TT_EraseFlash, "<ALL> Erase Flash");
- RetErr |= STTST_RegisterCommand("FLASH_PROGRAM", TT_ProgramFlash, "Program Flash");
- RetErr |= STTST_RegisterCommand("FLASH_READ", TT_ReadFile, "<Filename> Read Flash Data");
- RetErr |= STTST_RegisterCommand("FLASH_VERIFY", TT_VerifyFlash, "Verify Flash");
- #endif
-
- return( RetErr );
- } /* end FLASH_InitCommand */
- /* EOF --------------------------------------------------------------------- */