- /****************************************************************************
- 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 -------------------------------------------------- */
- /* Definitions for Flash */
- #if 0
- #define FLASH_BANK_0_BASE_ADDRESS_LOCAL 0x40000000 /* check this as it should be 7f80000 */
- #define STFLASH_BANK_0_BASE FLASH_BANK_0_BASE_ADDRESS_LOCAL /*FLASH_BANK_0_BASE_ADDRESS*/
- #endif
- #define STFLASH_MAIN_0_SIZE STFLASH_MAIN_SIZE
- #define STFLASH_MAIN_1_SIZE STFLASH_MAIN_SIZE
- #ifdef ST_5105
- #define STFLASH_VPP_0_ENABLE 0x45200000
- #elif defined(ST_5100)
- #define STFLASH_VPP_0_ENABLE 0x41400000
- #endif
- /* 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
- /***********leslie***********/
- /*M29W160DT*/
- #define DEVICE_TYPE STFLASH_M29W320DT /*STFLASH_M29W800T*/
- #define MIN_ACCESS_WIDTH STFLASH_ACCESS_16_BITS
- #define MAX_ACCESS_WIDTH STFLASH_ACCESS_16_BITS
- #define NUM_BLOCKS 135
- /**********************/
- #define STFLASH_MAIN00_SIZE 0x00010000 /* 64Kb */
- #define STFLASH_MAIN01_SIZE 0x00008000 /* 32Kb */
- #define STFLASH_PARA_0_SIZE 0x00002000 /* 8Kb */
- #define STFLASH_BOOT_0_SIZE 0x00004000 /* 16Kb */
- #define NUM_SECTIONS NUM_BLOCKS
- #define TOTAL_BLOCKS (NUM_BANKS * NUM_BLOCKS)
- #ifdef rayf
- #define CODE_SECTIONS 0
- #define LANG_SECTIONS 16
- #define LNB_SECTIONS 24
- #define LOGO_SECTIONS 31
- #define CODE_BLOCKS 16
- #define FIRST_CODE_BLOCK 0
- #define LANG_BLOCKS 8
- #define FIRST_LANG_BLOCK 16
- #define LNB_BLOCKS 2
- #define FIRST_LNB_BLOCK 24
- #define LOGO_BLOCKS 1
- #define FIRST_LOGO_BLOCK 31
- #endif
- #define CR 13
- #define LF 10
- /* Private Variables -------------------------------------------------- */
- /* Bank sizes (bytes) */
- /* Each device is configured as 512kb x 16 bits */ STFLASH_Block_t wts_BlockData_s[NUM_BLOCKS] =
- {
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 8 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 9 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 10 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 11 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 12 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 13 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 14 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 15 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 16 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 17 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 18 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 19 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 20 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 21 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 22 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 23 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 24 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 25 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 26 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 27 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 28 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 29 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 30 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 8 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 9 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 10 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 11 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 12 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 13 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 14 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 15 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 16 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 17 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 18 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 19 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 20 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 21 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 22 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 23 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 24 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 25 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 26 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 27 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 28 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 29 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 60 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 8 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 9 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 10 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 11 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 12 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 13 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 14 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 15 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 16 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 17 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 18 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 19 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 20 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 21 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 22 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 23 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 24 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 25 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 26 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 27 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 28 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 29 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 90 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 8 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 9 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 10 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 11 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 12 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 13 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 14 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 15 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 16 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 17 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 18 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 19 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 20 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 21 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 22 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 23 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 24 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 25 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 26 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 27 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 28 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 29 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 120 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 1 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 2 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 3 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 4 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 5 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 6 */
- {STFLASH_MAIN00_SIZE , STFLASH_MAIN_BLOCK }, /* 7 */
- {STFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 8 */
- {STFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 9 */
- {STFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 10 */
- {STFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 11 */
- {STFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 12 */
- {STFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 13 */
- {STFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK }, /* 14 */
- {STFLASH_PARA_0_SIZE , STFLASH_PARAMETER_BLOCK } /* 135 */
- }; /* 34 */
- /****************************/
- static U32 FlashSize = 0; /* Non-zero = file converted */
- static char *FlashData_p = NULL;
- static SectionInfo_t SectionInfo[NUM_SECTIONS];
- static BlockInfo_t BlockInfo[TOTAL_BLOCKS + 1];
- static U32 BaseAddress[NUM_BANKS];
- static STFLASH_Block_t GetBlkDat_s[NUM_BLOCKS];
- /* Private Macros ----------------------------------------------------- */
- extern U32 wtFlashBankBaseAddr;
- #define WTFLASH_BASE_ADDR2 wtFlashBankBaseAddr
- /* Global Variables ------------------------------------------------------- */
- STFLASH_Handle_t wts_FLASHHndl[2];
- ST_DeviceName_t wts_FLASHDeviceName[2] = {"Bank0", "Bank1"};
- /* Private Function prototypes ---------------------------------------- */
- /* Functions ---------------------------------------------------------- */
- /*-------------------------------------------------------------------------
- * Function : wts_FLASH_Close
- * close FLASH
- * Input : None
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t wts_FLASH_Close( U8 BankNum )
- {
- ST_ErrorCode_t ErrCode;
- ErrCode = STFLASH_Close(wts_FLASHHndl[BankNum]);
- STTBX_Print(("STFLASH_Close()=%sn", wts_GetErrorText(ErrCode) ));
- return ( ErrCode );
- } /* end wts_FLASH_Close */
- /*-------------------------------------------------------------------------
- * Function : wts_FLASH_GetParams
- * Get Flash Parameters
- * Input : None
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t wts_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(wts_FLASHHndl[BankNum], FLASHParams_p );
- STTBX_Print(("STFLASH_GetParams(%d)=%sn", BankNum, wts_GetErrorText(ErrCode)));
- return ( ErrCode );
- } /* end wts_FLASH_Close */
- /*-------------------------------------------------------------------------
- * Function : wts_FLASH_Init
- * Initialise FLASH
- * Input : None
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t wts_FLASH_Init( U8 BankNum )
- {
- ST_ErrorCode_t ErrCode;
- STFLASH_InitParams_t InitParams;
- InitParams.DeviceType = DEVICE_TYPE;
- if ( BankNum == BANK0 )
- {
- #if 0
- InitParams.BaseAddress = (U32*)STFLASH_BANK_0_BASE;
- #else
- InitParams.BaseAddress = (U32*)WTFLASH_BASE_ADDR2;
- 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 = NUM_BLOCKS;
- InitParams.Blocks = wts_BlockData_s;
- InitParams.DriverPartition = SystemPartition;
- ErrCode = STFLASH_Init(wts_FLASHDeviceName[BankNum], &InitParams );
- STTBX_Print(("STFLASH_Init(%s)=%sn", wts_FLASHDeviceName[BankNum], wts_GetErrorText(ErrCode) ));
- return ( ErrCode );
- } /* end wts_FLASH_Init */
- /*-------------------------------------------------------------------------
- * Function : wts_FLASH_Open
- * Open FLASH
- * Input : None
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t wts_FLASH_Open( U8 BankNum )
- {
- ST_ErrorCode_t ErrCode;
- STFLASH_OpenParams_t OpenParams;
- memset((char*)&OpenParams,0,sizeof(STFLASH_OpenParams_t));
- ErrCode = STFLASH_Open(wts_FLASHDeviceName[BankNum], &OpenParams, &wts_FLASHHndl[BankNum]);
- STTBX_Print(("STFLASH_Open(%s)=%sn", wts_FLASHDeviceName[BankNum], wts_GetErrorText(ErrCode) ));
- return ( ErrCode );
- } /* end wts_FLASH_Open */
- /*-------------------------------------------------------------------------
- * Function : wts_FLASH_Term
- * Terminate FLASH
- * Input : ForceTerminate
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t wts_FLASH_Term( BOOL ForceTerminate, U8 BankNum )
- {
- ST_ErrorCode_t ErrCode;
- STFLASH_TermParams_t TermParams;
- TermParams.ForceTerminate = ForceTerminate;
- ErrCode = STFLASH_Term(wts_FLASHDeviceName[BankNum], &TermParams);
- STTBX_Print(("STFLASH_Term(%s)=%sn", wts_FLASHDeviceName[BankNum], wts_GetErrorText(ErrCode) ));
- return ( ErrCode );
- } /* end wts_FLASH_Term */
- /*-------------------------------------------------------------------------
- * Function : wts_FLASH_SetupBlockInfo
- * Setup Block Info structure
- * Input :
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t wts_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 = wts_FLASH_Init( Bank ); /* Init Bank */
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = wts_FLASH_Open( Bank );
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_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 = wts_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 wts_FLASH_SetupBlockInfo */
- /*-------------------------------------------------------------------------
- * Function : wts_FLASH_Setup
- * Setup Block Info structure
- * Input :
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t wts_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 = wts_FLASH_Init( Bank ); /* Init Bank */
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = wts_FLASH_Open( Bank );
- }
- if ( ErrCode == ST_NO_ERROR )
- STTBX_Print(("Flash setup Ok.....n" ));
- }
- return( ErrCode );
- } /* end of Flash_Setup */
- /*-------------------------------------------------------------------------
- * Function : wts_FreeFileDataBuffer
- * as is
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void wts_FreeFileDataBuffer(void)
- {
- /* deallocate File data buffer */
- if ( FlashData_p != NULL )
- memory_deallocate( SystemPartition, FlashData_p );
- } /* end of wts_FreeFileDataBuffer() */
- /*-------------------------------------------------------------------------
- * Function : wts_GetBlockNumber
- * Get block number from address
- * Input :
- * Output :
- * Return : Block number of address
- * ----------------------------------------------------------------------*/
- static U8 wts_GetBlockNumber( U32 Address )
- {
- U8 Block;
- /* find the block this address is in */
- for ( Block = 0; Block < TOTAL_BLOCKS; Block++ )
- {
- if (( Address >= BlockInfo[Block].Address ) &&
- ( Address < (BlockInfo[Block].Address+BlockInfo[Block].Length)))
- {
- break;
- }
- }
- return Block;
- } /* end wts_GetBlockNumber */
- /*-------------------------------------------------------------------------
- * Function : wts_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 wts_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 < NUM_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 */
- {
- 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 = wts_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 > NUM_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 < NUM_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 wts_ConvertTotalMemory */
- /*-------------------------------------------------------------------------
- * Function : wts_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 wts_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 < NUM_SECTIONS; Section ++ )
- {
- SectionInfo[Section].Block = 0xff;
- SectionInfo[Section].Address = 0;
- SectionInfo[Section].Offset = 0;
- SectionInfo[Section].Size = 0;
- }
- /* Convert File */
- /*ray Section = 0;*/
- 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 = wts_GetBlockNumber( Value )) == TOTAL_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 = wts_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 > NUM_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 < NUM_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 wts_ConvertMemory */
- /*-------------------------------------------------------------------------
- * Function : wts_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 wts_BinConvertMemory( 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 < NUM_SECTIONS; Section ++ )
- {
- SectionInfo[Section].Block = 0xff;
- SectionInfo[Section].Address = 0;
- SectionInfo[Section].Offset = 0;
- SectionInfo[Section].Size = 0;
- }
- /* Convert File */
- /*ray Section = 0;*/
- Section = 0;
- OldPtr = FlashData_p;
- NewPtr = (char*) NULL;
- for ( InOffset = 0, OutOffset = 0; InOffset < MemSize; )
- {
- 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 = wts_GetBlockNumber(SectionInfo[Section].Address);
- SectionInfo[Section].Offset = OutOffset;
- SectionInfo[Section].Size = 0;
- }
- SectionInfo[Section].Size ++;
- FlashData_p[OutOffset++] = (char) Value;
- InOffset += (U32)STFLASH_MAIN00_SIZE; /*( NewPtr - OldPtr );*/
- OldPtr = NewPtr;
- if ( Section > NUM_SECTIONS )
- {
- STTBX_Print(("Program Limitationn"));
- exit(0);
- }
- } /* end of for loop */
- STTBX_Print(("n"));
- /* display the first few bytes of each section */
- for ( Section = 0; Section < NUM_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 wts_ConvertMemory */
- #if 0 /*def rayf*/
- /*-------------------------------------------------------------------------
- * Function : ReadFile
- * Read HEX file into memory
- * Input :
- * Output :
- * Return : File size
- * ----------------------------------------------------------------------*/
- U32 wts_FLASH_ReadFile( char *Filename )
- {
- long int ReadFile_p=0; /* datafile descriptor */
- long int FileSize=0; /* size in bytes of the file */
- int nameLength ;
- nameLength = strlen( Filename ) ;
- if (Filename[nameLength-1]=='n' &&
- Filename[nameLength-2]=='i' &&
- Filename[nameLength-3]=='b' &&
- Filename[nameLength-4]=='.' ) {
- binFile = TRUE ;
- } else {
- binFile = FALSE ;
- }
- /* 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 */
- wts_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 HEX file (%d bytes)n", FileSize));
- FileSize = 0;
- }
- debugclose(ReadFile_p);
- }
- if ( FileSize > 0 )
- {
- /* convert buffer to binary and resize memory */
- STTBX_Print(("Converting file in memory, wait .. "));
- if(binFile)
- FlashSize = (U32)FileSize;
- else
- FlashSize = wts_ConvertMemory( 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 wts_FLASH_ReadFile */
- #else
- /*-------------------------------------------------------------------------
- * Function : ReadFile
- * Read HEX file into memory
- * Input :
- * Output :
- * Return : File size
- * ----------------------------------------------------------------------*/
- U32 wts_FLASH_ReadFile( char *Filename )
- {
- long int HexFile_p=0; /* datafile descriptor */
- long int HexFileSize=0; /* size in bytes of the file */
- /* Open and Read file into memory */
- HexFile_p = debugopen(Filename, "rb");
- STTBX_Print(("HexFile_p = 0x%8xn",HexFile_p));
- if(HexFile_p < 0)
- {
- STTBX_Print(("Error opening file '%s'n", Filename ));
- return (0);
- }
- else
- {
- HexFileSize = debugfilesize(HexFile_p);
- STTBX_Print(("HexFileSize = 0x%8xn",HexFileSize));
- /* allocate File data buffer */
- wts_FreeFileDataBuffer();
- FlashData_p = (char*) memory_allocate( SystemPartition, (U32) HexFileSize );
- if ( FlashData_p != NULL )
- {
- STTBX_Print(("Loading '%s' into memory, wait .. ", Filename ));
- debugread(HexFile_p, FlashData_p, (size_t) HexFileSize);
- STTBX_Print(("%d bytesn", HexFileSize ));
- }
- else
- {
- STTBX_Print(("Not enough memory for HEX file (%d bytes)n", HexFileSize));
- HexFileSize = 0;
- }
- debugclose(HexFile_p);
- }
- if ( HexFileSize > 0 )
- {
- /* convert buffer to binary and resize memory */
- STTBX_Print(("Converting file in memory, wait .. "));
- FlashSize = wts_ConvertMemory( HexFileSize );
- 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 wts_FLASH_ReadFile */
- #endif
- /*-------------------------------------------------------------------------
- * Function : wts_EraseFlash
- * Function to Read Hex file and erase areas required
- * Input : EraseAll
- * Output :
- * Return : EraseFailed = TRUE else FALSE
- * ----------------------------------------------------------------------*/
- BOOL wts_EraseFlash( BOOL EraseAll )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = TRUE;
- /* check data size */
- if (( FlashSize != 0 ) || EraseAll )
- {
- EraseFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- if ( EraseAll )
- {
- for ( /*Section = 0*/Section = 0;( Section < TOTAL_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
- {
- Bank = BlockInfo[Section].Bank;
- EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
- STTBX_Print(("%d block %2dt| 0x%08x | 0x%08x | ",
- Bank, Section,
- BlockInfo[Section].Address,
- BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
- ErrCode = STFLASH_Erase( wts_FLASHHndl[Bank],
- EraseOffset,
- BlockInfo[Section].Length );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Erase FAILEDn"));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- }
- else
- {
- /* Find out which blocks are to be Erased */
- for ( /*Section = 0*/Section = 0; ( Section < NUM_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( wts_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(("wts_FLASHHndl[Bank] = 0x%8Xn",wts_FLASHHndl[Bank]));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- }
- }
- STTBX_Print(("tt+------------+------------+n"));
- }
- if ( EraseFailed == TRUE )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- } /* end wts_ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : wts_ProgramFlash
- * Function to Read Hex file and program flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL wts_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 < NUM_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 < NUM_SECTIONS ) && ( ProgramFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- U32 WriteOffset;
- /*
- ** Write = write bytes from Offset
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- 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));
- 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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end wts_ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : wts_ProgramFlash
- * Function to Read Hex file and program flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL wts_BinProgramFlash( void )
- {
- ST_ErrorCode_t ErrCode;
- int Section, Bank=0;
- U32 NumberOfBytes;
- BOOL ProgramFailed;
- U32 FlashOffset=0;
- /* check data size */
- if ( FlashSize == 0 )
- ProgramFailed = TRUE;
- else
- {
- ProgramFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- if(binFile){
- ErrCode = STFLASH_Write( wts_FLASHHndl[Bank],
- FlashOffset,
- (U8*)&FlashData_p,
- FlashSize,
- &NumberOfBytes );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Program FAILEDn"));
- ProgramFailed = TRUE;
- }
- else
- STTBX_Print(("PROGRAMMEDn"));
- }
- else{
- for ( Section = 0; ( Section < NUM_SECTIONS ) && ( ProgramFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- U32 WriteOffset;
- /*
- ** Write = write bytes from Offset
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- 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));
- 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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end wts_ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : wts_VerifyFlash
- * Function to Read Hex file and verify flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL wts_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 = 0; ( Section < NUM_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( wts_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 );
- }
- }
- }
- wts_FreeFileDataBuffer();
- if ( VerifyFailed == TRUE )
- {
- STTBX_Print(("!!!! VERIFY Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end wts_VerifyFlash */
- #ifdef rayf
- BOOL wts_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( wts_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;
- }
- BOOL wts_EraseLogoFlash( BOOL Erase )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = TRUE;
- /* check data size */
- if ( Erase )
- {
- EraseFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- if ( Erase )
- {
- for ( Section = FIRST_LOGO_BLOCK;( Section < FIRST_LOGO_BLOCK+LOGO_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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- }
- BOOL wts_EraseLanguageFlash( BOOL Erase )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = TRUE;
- /* check data size */
- if ( Erase )
- {
- EraseFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- if ( Erase )
- {
- for ( Section = FIRST_LANG_BLOCK;( Section < FIRST_LANG_BLOCK+LANG_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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- }
- /*-------------------------------------------------------------------------
- * Function : wts_EraseLNBFlash
- * Function to Read Hex file and erase areas required
- * Input : EraselLNB
- * Output :
- * Return : EraseFailed = TRUE else FALSE
- * ----------------------------------------------------------------------*/
- BOOL wts_EraseLNBFlash( BOOL Erase )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- U8 Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = TRUE;
- /* check data size */
- if ( Erase )
- {
- EraseFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- if ( Erase )
- {
- for ( Section = FIRST_LNB_BLOCK;( Section < FIRST_LNB_BLOCK+LNB_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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- } /* end wts_ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : wts_EraseCodeFlash
- * Function to Read Hex file and erase areas required
- * Input : EraseCode
- * Output :
- * Return : EraseFailed = TRUE else FALSE
- * ----------------------------------------------------------------------*/
- BOOL wts_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 = FIRST_CODE_BLOCK;( Section < FIRST_CODE_BLOCK+CODE_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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! ERASE Failed !!!!n"));
- return TRUE;
- }
- return EraseFailed;
- } /* end wts_ProgramFlash */
- /*-------------------------------------------------------------------------
- * Function : wts_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 wts_LogoConvertMemory( long unsigned int MemSize )
- {
- int Section;
- U32 InOffset;
- for ( Section = 31; Section < NUM_SECTIONS; Section ++ )
- {
- SectionInfo[Section].Block = 0xff;
- SectionInfo[Section].Address = 0;
- SectionInfo[Section].Offset = 0;
- SectionInfo[Section].Size = 0;
- }
- /* Convert File */
- Section = 31;
- for ( InOffset = 0;InOffset < MemSize; )
- {
- InOffset += 0x8000;
- if(InOffset < MemSize){
- SectionInfo[Section].Address = wtFlashBankBaseAddr + 0x10000*Section;
- SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
- SectionInfo[Section].Offset = InOffset - 0x8000; /*0x10000*Section;*/
- SectionInfo[Section].Size = 0x8000;
- }
- else{
- SectionInfo[Section].Address = wtFlashBankBaseAddr + 0x10000*Section;
- SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
- SectionInfo[Section].Offset = InOffset - 0x8000; /*0x10000*Section;*/
- SectionInfo[Section].Size = MemSize - (InOffset - 0x8000);
- }
- 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 ));
- Section++;
- }
- return MemSize;
- } /* end wts_ConvertMemory */
- BOOL wts_ProgramLogoFlash( void)
- {
- ST_ErrorCode_t ErrCode;
- long int File_p=0; /* datafile descriptor */
- long int FileSize=0; /* size in bytes of the file */
- BOOL ProgramFailed;
- U32 NumberOfBytes;
- int Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = FALSE;
- char Filename[] = "logo.bin";
- U32 EarLength = 0x5000;
- U32 WriteOffset = 0x401F0000;
- /* Open and Read file into memory */
- File_p = debugopen(Filename, "rb");
- STTBX_Print(("File_p = 0x%8xn",File_p));
- if(File_p < 0)
- {
- STTBX_Print(("Error opening file '%s'n", Filename ));
- return (0);
- }
- else
- {
- FileSize = debugfilesize(File_p);
- STTBX_Print(("FileSize = 0x%8xn",FileSize));
- /* allocate File data buffer */
- STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
- wts_FreeFileDataBuffer();
- STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
- FlashData_p = (char*) memory_allocate( SystemPartition, (U32) FileSize );
- STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
- if ( FlashData_p != NULL )
- {
- STTBX_Print(("Loading '%s' into memory, wait .. ", Filename ));
- debugread(File_p, FlashData_p, (size_t) FileSize);
- STTBX_Print(("%d bytesn", FileSize ));
- STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
- }
- else
- {
- STTBX_Print(("Not enough memory for bin file (%d bytes)n", FileSize));
- FileSize = 0;
- }
- debugclose(File_p);
- }
- if ( FileSize > 0 )
- {
- /* convert buffer to binary and resize memory */
- STTBX_Print(("Converting file in memory, wait .. nn"));
- FlashSize = wts_LogoConvertMemory( FileSize );
- if ( FlashSize > 0 )
- {
- STTBX_Print(("%d bytesn", FlashSize ));
- FlashData_p = (char*) memory_reallocate( SystemPartition, FlashData_p, FlashSize );
- }
- else
- STTBX_Print(("Invalid filen"));
- }
- for ( Section = 31; ( Section < NUM_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( wts_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(("wts_FLASHHndl[Bank] = 0x%8Xn",wts_FLASHHndl[Bank]));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- }
- /* 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 < NUM_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 = 31; ( Section < NUM_SECTIONS ) && ( ProgramFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- /*
- ** Write = write bytes from Offset
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- 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));
- 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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- }
- #if 1
- /*-------------------------------------------------------------------------
- * Function : wts_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 wts_LangConvertMemory( long unsigned int MemSize )
- {
- int Section;
- U32 InOffset;
- for ( Section = 16; Section < NUM_SECTIONS; Section ++ )
- {
- SectionInfo[Section].Block = 0xff;
- SectionInfo[Section].Address = 0;
- SectionInfo[Section].Offset = 0;
- SectionInfo[Section].Size = 0;
- }
- /* Convert File */
- Section = 16;
- for ( InOffset = 0;InOffset < MemSize; )
- {
- InOffset += 0x10000;
- if(InOffset < MemSize){
- SectionInfo[Section].Address = wtFlashBankBaseAddr + 0x10000*Section;
- SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
- SectionInfo[Section].Offset = InOffset - 0x10000; /*0x10000*Section;*/
- SectionInfo[Section].Size = 0x10000;
- }
- else{
- SectionInfo[Section].Address = wtFlashBankBaseAddr + 0x10000*Section;
- SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
- SectionInfo[Section].Offset = InOffset - 0x10000; /*0x10000*Section;*/
- SectionInfo[Section].Size = MemSize - (InOffset - 0x10000);
- }
- 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 ));
- Section++;
- }
- return MemSize;
- } /* end wts_ConvertMemory */
- BOOL wts_ProgramLanguageFlash( char *Filename )
- {
- ST_ErrorCode_t ErrCode;
- long int File_p=0; /* datafile descriptor */
- long int FileSize=0; /* size in bytes of the file */
- BOOL ProgramFailed;
- U32 NumberOfBytes;
- int Section, Bank;
- U32 EraseOffset;
- BOOL EraseFailed = FALSE;
- U32 EarLength = 0x80000;
- U32 WriteOffset = 0x40100000;
- /* Open and Read file into memory */
- File_p = debugopen(Filename, "rb");
- STTBX_Print(("File_p = 0x%8xn",File_p));
- if(File_p < 0)
- {
- STTBX_Print(("Error opening file '%s'n", Filename ));
- return (0);
- }
- else
- {
- FileSize = debugfilesize(File_p);
- STTBX_Print(("FileSize = 0x%8xn",FileSize));
- /* allocate File data buffer */
- STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
- wts_FreeFileDataBuffer();
- STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
- FlashData_p = (char*) memory_allocate( SystemPartition, (U32) FileSize );
- STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
- if ( FlashData_p != NULL )
- {
- STTBX_Print(("Loading '%s' into memory, wait .. ", Filename ));
- debugread(File_p, FlashData_p, (size_t) FileSize);
- STTBX_Print(("%d bytesn", FileSize ));
- STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
- }
- else
- {
- STTBX_Print(("Not enough memory for bin file (%d bytes)n", FileSize));
- FileSize = 0;
- }
- debugclose(File_p);
- }
- if ( FileSize > 0 )
- {
- /* convert buffer to binary and resize memory */
- STTBX_Print(("Converting file in memory, wait .. nn"));
- FlashSize = wts_LangConvertMemory( FileSize );
- if ( FlashSize > 0 )
- {
- STTBX_Print(("%d bytesn", FlashSize ));
- FlashData_p = (char*) memory_reallocate( SystemPartition, FlashData_p, FlashSize );
- }
- else
- STTBX_Print(("Invalid filen"));
- }
- for ( Section = 16; ( Section < NUM_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( wts_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(("wts_FLASHHndl[Bank] = 0x%8Xn",wts_FLASHHndl[Bank]));
- EraseFailed = TRUE;
- }
- else
- STTBX_Print(("ERASEDn"));
- }
- }
- /* 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 < NUM_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 = 16; ( Section < NUM_SECTIONS ) && ( ProgramFailed == FALSE ); Section ++ )
- {
- if ( SectionInfo[Section].Block != 0xFF )
- {
- /*
- ** Write = write bytes from Offset
- */
- Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
- 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));
- 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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- }
- #else
- BOOL wts_ProgramLanguageFlash( char *Filename )
- {
- int nameLength ;
- BOOL binFile,ProgramFailed ;
- ST_ErrorCode_t ErrCode;
- long int ReadFile_p=0; /* datafile descriptor */
- U32 FileSize=0; /* size in bytes of the file */
- U32 WriteOffset = 0x40100000;
- U32 NumberOfBytes;
- nameLength = strlen( Filename ) ;
- if (Filename[nameLength-1]=='n' && Filename[nameLength-2]=='i' &&
- Filename[nameLength-3]=='b' && Filename[nameLength-4]=='.' )
- {
- binFile = TRUE ;
- }
- /* 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 */
- wts_FreeFileDataBuffer();
- FlashData_p = (char*) memory_allocate( SystemPartition, 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 HEX file (%d bytes)n", FileSize));
- FileSize = 0;
- }
- FlashData_p = (char*) memory_reallocate( SystemPartition, FlashData_p, FileSize );
- STTBX_Print(("FlashData_p memory_reallocaten"));
- debugclose(ReadFile_p);
- }
- if(FileSize > 0){
- ErrCode = STFLASH_Write( wts_FLASHHndl[BANK0],
- WriteOffset,
- (U8*)FlashData_p,
- FileSize,
- &NumberOfBytes );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Program FAILEDn"));
- ProgramFailed = TRUE;
- }
- else
- STTBX_Print(("PROGRAMMEDn"));
- }
- else
- return 0;
- if ( ProgramFailed == TRUE )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- /* loop thru the data file */
- return 1;
- }
- #endif
- #if 0
- BOOL wts_ProgramLanguageFlash( void )
- {
- ST_ErrorCode_t ErrCode;
- int Section, Bank=0;
- U32 NumberOfBytes;
- BOOL ProgramFailed;
- U32 FlashOffset=0;
- /* check data size */
- if ( FlashSize == 0 )
- ProgramFailed = TRUE;
- else
- {
- ProgramFailed = FALSE;
- STTBX_Print(("tt+------------+------------+n"));
- }
- FlashOffset = (U32)0x40100000;
- ErrCode = STFLASH_Write( wts_FLASHHndl[1],
- FlashOffset,
- (U8 *)FlashData_p,
- FlashSize,
- &NumberOfBytes );
- if ( ErrCode != ST_NO_ERROR )
- {
- STTBX_Print(("Program FAILEDn"));
- ProgramFailed = TRUE;
- }
- else
- STTBX_Print(("PROGRAMMEDn"));
- if ( ProgramFailed == TRUE )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end wts_ProgramFlash */
- #endif
- /*-------------------------------------------------------------------------
- * Function : wts_ProgramAllFlash
- * Function to Read Hex file and program flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL wts_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 < NUM_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 < TOTAL_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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end wts_ProgramAllFlash */
- /*-------------------------------------------------------------------------
- * Function : wts_ProgramLNBFlash
- * Function to Read Hex file and program flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL wts_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 < NUM_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 = CODE_BLOCKS; ( Section < TOTAL_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( wts_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 )
- {
- wts_FreeFileDataBuffer();
- STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end wts_ProgramLNBFlash */
- BOOL wts_VerifyLogoFlash( void )
- {}
- BOOL wts_VerifyLanguageFlash( void )
- {}
- /*-------------------------------------------------------------------------
- * Function : wts_VerifyAllFlash
- * Function to Read Hex file and verify flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL wts_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 < TOTAL_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( wts_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 );
- }
- }
- }
- wts_FreeFileDataBuffer();
- if ( VerifyFailed == TRUE )
- {
- STTBX_Print(("!!!! VERIFY Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end wts_VerifyAllFlash */
- /*-------------------------------------------------------------------------
- * Function : wts_VerifyLNBFlash
- * Function to Read Hex file and verify flash with contents
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- BOOL wts_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 = CODE_BLOCKS; ( Section < TOTAL_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( wts_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 );
- }
- }
- }
- wts_FreeFileDataBuffer();
- if ( VerifyFailed == TRUE )
- {
- STTBX_Print(("!!!! VERIFY Failed !!!!n"));
- return TRUE;
- }
- else
- {
- STTBX_Print(("tt+------------+------------+n"));
- return FALSE;
- }
- } /* end wts_VerifyLNBFlash */
- #endif
- /* Testtool Functions --------------------------------------------------- */
- #ifdef TESTTOOL
- /*-------------------------------------------------------------------------
- * Function : wts_TTFLASH_GetParams
- *
- * Input : *pars_p, *result_sym_p
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- static BOOL wts_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 = wts_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 wts_TTFLASH_GetParams */
- /*-------------------------------------------------------------------------
- * Function : wts_TT_SetupBlockInfo
- * Setup FLASH Block Info
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL wts_TT_SetupBlockInfo( STTST_Parse_t *pars_p, char *Result )
- {
- ST_ErrorCode_t ErrCode;
- ErrCode = wts_FLASH_SetupBlockInfo();
- return ( ErrCode != ST_NO_ERROR ? TRUE : FALSE );
- }
- /*-------------------------------------------------------------------------
- * Function : wts_TT_FlashSetup
- * Setup FLASH Block Info
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL wts_TT_FlashSetup( STTST_Parse_t *pars_p, char *Result )
- {
- ST_ErrorCode_t ErrCode;
- ErrCode = wts_FLASH_Setup();
- return ( ErrCode != ST_NO_ERROR ? TRUE : FALSE );
- }
- /*-------------------------------------------------------------------------
- * Function : wts_TT_ReadFile
- * Function to Read Hex file
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL wts_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 = wts_FLASH_ReadFile( Filename );
- return ( FlashSize == 0 ? TRUE : FALSE );
- }
- /*-------------------------------------------------------------------------
- * Function : wts_TT_EraseFlash
- * Function to erase flash for loaded data
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL wts_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 wts_EraseFlash( EraseAll );
- }
- /*-------------------------------------------------------------------------
- * Function : wts_TT_ProgramFlash
- * Function to program flash with loaded data
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL wts_TT_ProgramFlash( STTST_Parse_t *pars_p, char *Result )
- {
- return wts_ProgramFlash();
- }
- /*-------------------------------------------------------------------------
- * Function : wts_TT_VerifyFlash
- * Function to verify flash with loaded data
- * Input :
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static BOOL wts_TT_VerifyFlash( STTST_Parse_t *pars_p, char *Result )
- {
- return wts_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 wts_FLASH_InitCommand( void )
- {
- BOOL RetErr;
- RetErr = FALSE;
- #ifdef TESTTOOL
- RetErr |= STTST_RegisterCommand("FLASH_GETPARMS", wts_TTFLASH_GetParams, "Get FLASH Parameters");
- RetErr |= STTST_RegisterCommand("FLASH_BLOCKINFO", wts_TT_SetupBlockInfo, "Get Flash Block Data");
- RetErr |= STTST_RegisterCommand("FLASH_SETUP", wts_TT_FlashSetup, "Setup Flash Bank(Init&Open) Data");
- RetErr |= STTST_RegisterCommand("FLASH_ERASE", wts_TT_EraseFlash, "<ALL> Erase Flash");
- RetErr |= STTST_RegisterCommand("FLASH_PROGRAM", wts_TT_ProgramFlash, "Program Flash");
- RetErr |= STTST_RegisterCommand("FLASH_READ", wts_TT_ReadFile, "<Filename> Read Flash Data");
- RetErr |= STTST_RegisterCommand("FLASH_VERIFY", wts_TT_VerifyFlash, "Verify Flash");
- #endif
- return( RetErr );
- } /* end wts_FLASH_InitCommand */
- /* EOF --------------------------------------------------------------------- */