wts_main.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:31k
- /*****************************************************************************
- File name : main.c
-
- Description : Main entry point
- COPYRIGHT (C) 2004 STMicroelectronics
- *****************************************************************************/
- /* Includes --------------------------------------------------------------- */
- /* Standard Headers */
- #include <stdio.h>
- #include <string.h>
- #include "stddefs.h"
- #include "stlite.h"
- #include "stdevice.h"
- /* STAPI Headers */
- #include "stpio.h"
- #include "stcommon.h"
- #include "stboot.h"
- #include "stflash.h"
- #include "sttbx.h"
- #include "stuart.h"
- #include "testtool.h"
- /* Local Headers */
- #define GLOBAL_DATA
- #include "wts_app_data.h"
- #include "wts_flash.h"
- /*
- #include "wt_flash.h"
- */
- /* Private Types ------------------------------------------------------ */
- U32 wtFlashBankBaseAddr;
- #ifdef rayf
- #include <debug.h>
- #define BUF_LEN 512
- U32 read_start_address; /********/
- U32 read_size; /********/
- BOOL rom_serial = FALSE; /* ROM serial number update */
- BOOL report_verbose = TRUE; /* reporting level LP's init for debugging */
- FILE_STRING rom_datafile; /* datafile name */
- FILE_STRING rom_serialno; /* Serial number/code */
- ROMTOOL_REPORT rom_report = NULL_REPORT; /* reporting level */
- ROMTOOL_MODE rom_operation = NULL_MODE; /* operational mode */
- ROMTOOL_BOARD rom_board = STB3; /* board */
- ROMTOOL_ERASE erase_type=NULL_ERASE;
- ROMTOOL_IMAGE image_type;
- UBYTE byteBuffer[1*1024*1024 /* 4096 */] ; /* a buffer */
- UBYTE lnbByteBuffer[32*1024];
- char buf1[0xff];
- /* ============================= PRIVATE CONSTANTS ================================ */
- static const char *Version = "ROMTOOL V1.0:n"
- #if __ICC_VERSION_NUMBER__ == 50600
- "tChain : DCU: Osprey1.6.2n"
- #elif __ICC_VERSION_NUMBER__ == 50600
- "tChain : DCU: Osprey1.8n"
- #elif __ICC_VERSION_NUMBER__ == 60100
- "tChain : DCU: Osprey1.8.1n"
- #else
- "tChain : DCU: Osprey2.0.0n"
- #endif
- ;
- /* =============================GLOBAL_VARIABLES=============================== */
- #endif
- /* Private Constants -------------------------------------------------- */
- #if 0
- #define SYSTEM_MEMORY_SIZE 0x00400000 /*0x0800000*/ /* 8Mb */
- #define NCACHE_MEMORY_SIZE 0x00080000 /*0x0080000*/ /* 0.5Mb */
- #else
- #define SYSTEM_MEMORY_SIZE 0x00A00000//0x00200000 /*0x0800000*/ /* 8Mb */
- #define NCACHE_MEMORY_SIZE 0x00080000 /*0x0080000*/ /* 0.5Mb */
- #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
- #endif
- /* Private Variables -------------------------------------------------- */
- /* Allow room for OS20 segments in internal memory */
- static unsigned char InternalMemory[ST20_INTERNAL_MEMORY_SIZE-1200];
- static unsigned char SystemMemory[SYSTEM_MEMORY_SIZE];
- static unsigned char NcacheMemory[NCACHE_MEMORY_SIZE];
- static ST_Partition_t TheInternalPartition;
- static ST_Partition_t TheSystemPartition;
- static ST_Partition_t TheNcachePartition;
- #pragma ST_section (InternalMemory, "internal_section")
- #pragma ST_section (SystemMemory, "system_section")
- #pragma ST_section (NcacheMemory, "ncache_section")
- STBOOT_DCache_Area_t DCacheMap[] = { {NULL, NULL} }; /* Dcache must be disabled for flash program*/
- /* Private Macros ----------------------------------------------------- */
- /* Global ----------------------------------------------------------------- */
- ST_Partition_t *InternalPartition = &TheInternalPartition;
- ST_Partition_t *SystemPartition = &TheSystemPartition;
- ST_Partition_t *NcachePartition = &TheNcachePartition;
- /* PTI/OS20 */
- ST_Partition_t *internal_partition = &TheInternalPartition;
- ST_Partition_t *system_partition = &TheSystemPartition;
- ST_Partition_t *ncache_partition = &TheNcachePartition;
- /* Private Function prototypes ---------------------------------------- */
- #if 1
- extern int atoi();
- extern int exit();
- #endif
- /* Functions -------------------------------------------------------------- */
- /*-------------------------------------------------------------------------
- * Function : wts_BOOT_Init
- * Initialise boot process
- * Input : None
- * Output :Initialize the st20 kur
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- static ST_ErrorCode_t wts_BOOT_Init( void )
- {
- ST_ErrorCode_t ErrCode;
- STBOOT_InitParams_t BootParams;
- BootParams.SDRAMFrequency = SDRAM_FREQUENCY;
- BootParams.CacheBaseAddress = (U32*) CACHE_BASE_ADDRESS;
- BootParams.DCacheMap = DCacheMap;
- BootParams.ICacheEnabled = TRUE;
- BootParams.BackendType.DeviceType = STBOOT_DEVICE_UNKNOWN;
- BootParams.BackendType.MajorRevision = STBOOT_REVISION_UNKNOWN;
- BootParams.BackendType.MinorRevision = STBOOT_REVISION_UNKNOWN;
- BootParams.MemorySize = STBOOT_DRAM_MEMORY_SIZE_0;/*Originally SDRAM_SIZE*/
- ErrCode = STBOOT_Init(BOOTDeviceName, &BootParams);
- #ifdef STTBX_PRINT
- printf("STBOOT_Init()=%sn", wts_GetErrorText(ErrCode));
- #endif
- return ( ErrCode );
- } /* end wts_BOOT_Init */
- /*-------------------------------------------------------------------------
- * Function : wts_PIO_Init
- * PIO Init function
- * Input : None
- * Output :Initialise the required PIO Port
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- static ST_ErrorCode_t wts_PIO_Init( void )
- {
- ST_ErrorCode_t ErrCode;
- int Count;
- STPIO_InitParams_t PIOInitParams[NUM_PIO_PORTS];
- /* --- initialise multi-purpose PIO port inputs and outputs --- */
- PIOInitParams[0].BaseAddress = (U32 *)PIO_0_BASE_ADDRESS;
- PIOInitParams[0].InterruptNumber = PIO_0_INTERRUPT;
- PIOInitParams[0].InterruptLevel = PIO_0_INTERRUPT_LEVEL;
- PIOInitParams[1].BaseAddress = (U32 *)PIO_1_BASE_ADDRESS;
- PIOInitParams[1].InterruptNumber = PIO_1_INTERRUPT;
- PIOInitParams[1].InterruptLevel = PIO_1_INTERRUPT_LEVEL;
- PIOInitParams[2].BaseAddress = (U32 *)PIO_2_BASE_ADDRESS;
- PIOInitParams[2].InterruptNumber = PIO_2_INTERRUPT;
- PIOInitParams[2].InterruptLevel = PIO_2_INTERRUPT_LEVEL;
- PIOInitParams[3].BaseAddress = (U32 *)PIO_3_BASE_ADDRESS;
- PIOInitParams[3].InterruptNumber = PIO_3_INTERRUPT;
- PIOInitParams[3].InterruptLevel = PIO_3_INTERRUPT_LEVEL;
- #ifndef ST_5105
- PIOInitParams[4].BaseAddress = (U32 *)PIO_4_BASE_ADDRESS;
- PIOInitParams[4].InterruptNumber = PIO_4_INTERRUPT;
- PIOInitParams[4].InterruptLevel = PIO_4_INTERRUPT_LEVEL;
- PIOInitParams[5].BaseAddress = (U32 *)PIO_5_BASE_ADDRESS;
- PIOInitParams[5].InterruptNumber = PIO_5_INTERRUPT;
- PIOInitParams[5].InterruptLevel = PIO_5_INTERRUPT_LEVEL;
- #endif
- for ( Count = 0; Count < NUM_PIO_PORTS; Count++)
- {
- PIOInitParams[Count].DriverPartition = SystemPartition;
- ErrCode = STPIO_Init (PIODeviceName[Count], &(PIOInitParams[Count]));
- if ( ErrCode != ST_NO_ERROR )
- break;
- }
- #ifdef STTBX_PRINT
- printf("STPIO_Init(0-4)=%sn", wts_GetErrorText(ErrCode));
- #endif
- return ( ErrCode );
- } /* end wts_PIO_Init */
- /*-------------------------------------------------------------------------
- * Function : wts_TBX_Init
- * Toolbox Init
- * Input : None
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- static ST_ErrorCode_t wts_TBX_Init( void )
- {
- ST_ErrorCode_t ErrCode;
- STTBX_InitParams_t InitParams;
- InitParams.SupportedDevices = STTBX_DEVICE_DCU;
- InitParams.DefaultOutputDevice = STTBX_DEVICE_DCU;
- InitParams.DefaultInputDevice = STTBX_DEVICE_DCU;
- /* for STTBX 2.0.0 and later */
- InitParams.CPUPartition_p = SystemPartition;
- strcpy(InitParams.UartDeviceName, UARTDeviceName);
- ErrCode = STTBX_Init(TBXDeviceName, &InitParams );
- #ifdef STTBX_PRINT
- printf("STTBX_Init()=%sn", wts_GetErrorText(ErrCode));
- #endif
- return ( ErrCode );
- } /* end wts_TBX_Init */
- #if defined(TESTTOOL)
- /*-------------------------------------------------------------------------
- * Function : wts_TST_Init
- * : Initialise the TESTOOL driver
- * Input : None
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- static ST_ErrorCode_t wts_TST_Init()
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- STTST_InitParams_t STTST_InitParams;
- memset (STTST_InitParams.InputFileName, 0, sizeof(STTST_InitParams.InputFileName));
- STTST_InitParams.CPUPartition_p = SystemPartition;
- STTST_InitParams.NbMaxOfSymbols = 1000;
- if ( STTST_InitParams.CPUPartition_p == NULL )
- {
- STTBX_Print(("Memory partition undefined, STTST cannot be started !!n"));
- return -1;
- }
- else
- {
- ErrCode = STTST_Init(&STTST_InitParams);
- }
- return ( ErrCode );
- } /* end wts_TST_Init */
- #endif
- /*-------------------------------------------------------------------------
- * Function : wts_UART_Init
- * : Initialise the UART driver
- * Input : None
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- static ST_ErrorCode_t wts_UART_Init( void )
- {
- ST_ErrorCode_t ErrCode;
- STUART_InitParams_t UartInitParams;
- STUART_Params_t UartDefaultParams;
-
- UartDefaultParams.RxMode.DataBits = STUART_8BITS_NO_PARITY;
- UartDefaultParams.RxMode.StopBits = STUART_STOP_1_0;
- UartDefaultParams.RxMode.FlowControl = STUART_NO_FLOW_CONTROL;
- UartDefaultParams.RxMode.BaudRate = 115200;
- UartDefaultParams.RxMode.TermString = NULL;
- UartDefaultParams.RxMode.TimeOut = 1;
- UartDefaultParams.RxMode.NotifyFunction = NULL;
- UartDefaultParams.TxMode.DataBits = STUART_8BITS_NO_PARITY;
- UartDefaultParams.TxMode.StopBits = STUART_STOP_1_0;
- UartDefaultParams.TxMode.FlowControl = STUART_NO_FLOW_CONTROL;
- UartDefaultParams.TxMode.BaudRate = 115200;
- UartDefaultParams.TxMode.TermString = NULL;
- UartDefaultParams.TxMode.TimeOut = 0; /* No time-out */
- UartDefaultParams.TxMode.NotifyFunction = NULL; /* No callback */
- UartDefaultParams.SmartCardModeEnabled = FALSE;
- UartDefaultParams.GuardTime = 0;
- /* Initialise UART */
- UartInitParams.UARTType = STUART_RTSCTS;
- UartInitParams.DriverPartition = SystemPartition;
- UartInitParams.BaseAddress = (U32 *) UART_BASE_ADDRESS;
- UartInitParams.InterruptNumber = UART_INTERRUPT;
- UartInitParams.InterruptLevel = UART_INTERRUPT_LEVEL;
- UartInitParams.ClockFrequency = ST_GetClockSpeed();
- printf("ST_GetClockSpeed() = %d n",ST_GetClockSpeed());
- UartInitParams.SwFIFOEnable = TRUE;
- UartInitParams.FIFOLength = 256;
-
- #ifdef ST_5105
- strcpy(UartInitParams.RXD.PortName, PIODeviceName[1]);
- UartInitParams.RXD.BitMask = UART_RXD_BIT;
- strcpy(UartInitParams.TXD.PortName, PIODeviceName[1]);
- UartInitParams.TXD.BitMask = UART_TXD_BIT;
-
- strcpy(UartInitParams.RTS.PortName, PIODeviceName[1]);
- strcpy(UartInitParams.CTS.PortName, PIODeviceName[1]);
- UartInitParams.RTS.BitMask = PIO_BIT_4;
- UartInitParams.CTS.BitMask = PIO_BIT_5;
- #elif defined(ST_5100)
- strcpy(UartInitParams.RXD.PortName, PIODeviceName[4]);
- UartInitParams.RXD.BitMask = UART_RXD_BIT;
- strcpy(UartInitParams.TXD.PortName, PIODeviceName[4]);
- UartInitParams.TXD.BitMask = UART_TXD_BIT;
-
- strcpy(UartInitParams.RTS.PortName, PIODeviceName[4]);
- strcpy(UartInitParams.CTS.PortName, PIODeviceName[4]);
- UartInitParams.RTS.BitMask = PIO_BIT_2;
- UartInitParams.CTS.BitMask = PIO_BIT_3;
- #endif
- UartInitParams.DefaultParams = &UartDefaultParams;
-
- ErrCode = STUART_Init(UARTDeviceName, &UartInitParams);
- #ifdef STTBX_PRINT
- printf("STUART_Init()=%sn", wts_GetErrorText(ErrCode));
- #endif
- return ( ErrCode );
- } /* end wts_UART_Init() */
- #if defined(TESTTOOL)
- /*-------------------------------------------------------------------------
- * Function : GetRevision
- * Function to return all driver revisions
- * Input :
- * Output :
- * Return : FALSE
- * ----------------------------------------------------------------------*/
- BOOL wts_TT_GetRevisions( STTST_Parse_t *pars_p, char *Result )
- {
- /* get revisions for all drivers used */
- STTBX_Print(("STBOOT = %sn", STBOOT_GetRevision()));
- STTBX_Print(("STFLASH = %sn", STFLASH_GetRevision()));
- STTBX_Print(("STPIO = %sn", STPIO_GetRevision()));
- STTBX_Print(("STTBX = %sn", STTBX_GetRevision()));
- STTBX_Print(("STUART = %sn", STUART_GetRevision()));
- return (FALSE);
- } /* end GetRevisions */
- #endif
- int wts_htod(const char *p /*nptr*/){
- int i,j,ss,sum=0 ;
- int nameLength ;
- char bit;
-
- nameLength = strlen( p ) ;
- if (*p =='0' && (*(p+1) == 'x' || *(p+1) == 'X'))
- for(i=2;i<nameLength;i++){
- switch (*(p+i)) {
- case 'A':
- bit = 10 ;
- break ;
- case 'a':
- bit = 10 ;
- break ;
- case 'B':
- bit = 11 ;
- break ;
- case 'b':
- bit = 11 ;
- break ;
- case 'C':
- bit = 12 ;
- break ;
- case 'c':
- bit = 12 ;
- break ;
- case 'D':
- bit = 13 ;
- break ;
- case 'd':
- bit = 13 ;
- break ;
- case 'E':
- bit = 14 ;
- break ;
- case 'e':
- bit = 14 ;
- break ;
- case 'F':
- bit = 15 ;
- break ;
- case 'f':
- bit = 15 ;
- break ;
- default:
- if(*(p+i)>='0' && *(p+i)<='9')
- bit = *(p+i)-0X30;
- else
- return 0;
- }/* end switch */
- ss=1;
- for(j=0;j<nameLength-i-1;j++)
- ss*=0x10;
- sum += bit*ss;
- }/* end for */
- else
- return atoi(p);
-
- return sum;
- }/* end wts_htod */
- /*-------------------------------------------------------------------------
- * Function : main
- * Main entry point
- * Input : command line arguments
- * Output :
- * Return : TRUE if error, FALSE if success
- * ----------------------------------------------------------------------*/
- int main(int argc, char *argv[])
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- char Filename[] = "flash.hex";
- char LogoName[] = "logo.bin";
- char LangName[] = "lang.bin";
- char LNBName[] = "lnb.bin";
- #ifdef rayf
- char buf[BUF_LEN];
- int valid ;
- BOOL prev_menu;
- int status = FALSE;
- BOOL help = FALSE ;
- #endif
-
- partition_init_simple(&TheInternalPartition, (U8 *)InternalMemory, sizeof(InternalMemory));
- partition_init_heap( &TheSystemPartition, (U8 *)SystemMemory, sizeof(SystemMemory));
- partition_init_heap( &TheNcachePartition, (U8 *)NcacheMemory , sizeof(NcacheMemory));
- /* Initialisation */
- if ( wts_BOOT_Init() != ST_NO_ERROR )
- return 2;
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_PIO_Init();
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_UART_Init(); /* Needs PIO */
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_TBX_Init(); /* Needs UART */
- #if 0
- printf("b4 FLASH_SetupBlockInfon");
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_FLASH_SetupBlockInfo();
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = wts_FLASH_Init(BANK0);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_FLASH_Open(BANK0);
- }
- #ifdef STFLASH_BANK_1_BASE
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = wts_FLASH_Init(BANK1);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_FLASH_Open(BANK1);
- }
- #endif
- #endif
- if ( ErrCode == ST_NO_ERROR )
- {
- STTBX_Print(("n==============================================n"));
- STTBX_Print(("t STAPI Demo Software n"));
- STTBX_Print(("t %s at %sn", __DATE__, __TIME__ ));
- STTBX_Print(("tChip %s in board %sn", __FRONTEND, __PLATFORM ));
- STTBX_Print(("t CPU Clock Speed = %dn", ST_GetClockSpeed() ));
- STTBX_Print(("==============================================nn"));
- }
- #ifdef rayf
- /* Initialise the OS20 kernel */
- debugmessage(Version);
- #if 1
- debugmessage( "nROMTOOL> Enter Flash Base address (default: STx5105--0x40000000): " );
- debuggets(buf, BUF_LEN);
- wtFlashBankBaseAddr = wts_htod(buf);
- if(wtFlashBankBaseAddr == 0)
- wtFlashBankBaseAddr=0x40000000;
-
- sprintf(buf1,"Flash Base address = [0x%x]n", wtFlashBankBaseAddr);
- debugmessage(buf1);
- #endif
- do{
- prev_menu = FALSE ;
- valid = FALSE ;
- while (!valid)
- {
- debugmessage("nROMTOOL>Operation: n");
- debugmessage(" 1) Erase n");
- debugmessage(" 2) Program n");
- debugmessage(" 3) Verify n");
- debugmessage(" 4) Read n");
- debugmessage(" 5) Exit n");
- debugmessage(" Enter a number : ");
- debuggets( buf, BUF_LEN ) ;
- switch (buf[0]) {
- case '1':
- rom_operation = ERASE ;
- valid = TRUE ;
- break ;
- case '2':
- rom_operation = PROGRAM ;
- valid = TRUE ;
- break ;
- case '3':
- rom_operation = VERIFY ;
- valid = TRUE ;
- break ;
- case '4':
- rom_operation = READ ;
- valid = TRUE ;
- break ;
- case '5':
- exit(0) ;
- default:
- debugmessage("nInvalid selection, try again : ");
- break ;
- }
- }
- if (rom_operation==PROGRAM || rom_operation==VERIFY)
- {
- valid = FALSE ;
- while (!valid) {
- debugmessage("nROMTOOL> image type: n");
- debugmessage(" 1) HexCode Image n");
- debugmessage(" 2) BinCode Image n");
- debugmessage(" 3) LNB List n");
- debugmessage(" 4) Logo Image n");
- debugmessage(" 5) Language Image n");
- debugmessage(" 6) Chnl List n");
- debugmessage(" 7) All FLASH n");
- #if 0
- debugmessage(" 8) PREV MENU n");
- #endif
- debugmessage(" 9) EXIT n");
- debugmessage(" Enter a number : ");
- debuggets( buf, BUF_LEN ) ;
- switch (buf[0]) {
- case '1':
- image_type = HexCode ;
- valid = TRUE ;
- break ;
- case '2':
- image_type = BinCode ;
- valid = TRUE ;
- break ;
- case '3':
- image_type = LNBList ;
- valid = TRUE ;
- break ;
- case '4' :
- image_type = LogoImage ;
- valid = TRUE ;
- break ;
- case '5' :
- image_type = LanguageImage ;
- valid = TRUE ;
- break ;
- case '6' :
- image_type = CHNList ;
- valid = TRUE ;
- break ;
- case '7' :
- image_type = All ;
- valid = TRUE ;
- break ;
- #if 0
- case '8' :
- prev_menu = TRUE;
- valid = TRUE ;
- break;
- #endif
- case '9' :
- exit(0);
- default:
- debugmessage("nInvalid selection, try again : ");
- break ;
- }
- }
- /* init partitions */
-
- if(image_type == HexCode){
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_FLASH_SetupBlockInfo();
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = wts_FLASH_Init(BANK0);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_FLASH_Open(BANK0);
- }
- #ifdef STFLASH_BANK_1_BASE
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = wts_FLASH_Init(BANK1);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_FLASH_Open(BANK1);
- }
- #endif
-
- if ( wts_FLASH_ReadFile(Filename) != 0 )
- if ( wts_VerifyFlash() == TRUE )
- if ( wts_EraseFlash(FALSE) == FALSE )
- if ( wts_ProgramFlash() == FALSE )
- wts_VerifyFlash();
- #ifdef STFLASH_BANK_1_BASE
- wts_FLASH_Close(BANK1);
- wts_FLASH_Term(TRUE, BANK1);
- #endif
- wts_FLASH_Close(BANK0);
- wts_FLASH_Term(TRUE, BANK0);
- return (0);
- }
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = FLASH_SetupBlockInfo();
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = FLASH_Init(BANK0);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = FLASH_Open(BANK0);
- }
- #ifdef STFLASH_BANK_1_BASE
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = FLASH_Init(BANK1);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = FLASH_Open(BANK1);
- }
- #endif
-
- debugmessage( "nROMTOOL> Enter filename Write into Flash : " );
- debuggets(buf, BUF_LEN);
- strcpy(rom_datafile, buf);
-
- if ( FLASH_ReadFile(rom_datafile) == 0 )
- {
- debugmessage("read file failedn") ;
- exit(1) ;
- }
-
- }
- else if(rom_operation==ERASE){
- valid = FALSE ;
- while (!valid) {
- debugmessage("nROMTOOL> Erase type: n");
- debugmessage(" 1) Erase All Flash n");
- debugmessage(" 2) Erase Code Image n");
- debugmessage(" 3) Erase LNB List n");
- debugmessage(" 4) Erase Logo Image n");
- debugmessage(" 5) Erase Language Image n");
- debugmessage(" 6) PREV MENU n");
- debugmessage(" 7) EXIT n");
- debugmessage(" Enter a number : ");
- debuggets( buf, BUF_LEN ) ;
- switch (buf[0]) {
- case '1':
- erase_type = ERASE_ALL ;
- valid = TRUE ;
- break ;
- case '2':
- erase_type = ERACODE ;
- valid = TRUE ;
- break ;
- case '3':
- erase_type = ERALNB ;
- valid = TRUE ;
- break ;
- case '4' :
- erase_type = ERALOGO ;
- valid = TRUE ;
- break ;
- case '5' :
- erase_type = ERALANGUAGE ;
- valid = TRUE ;
- break ;
- case '6' :
- prev_menu = TRUE;
- valid = TRUE ;
- break;
- case '7' :
- exit(0);
- default:
- debugmessage("nInvalid selection, try again : ");
- break ;
- }
- }
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_FLASH_SetupBlockInfo();
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = wts_FLASH_Init(BANK0);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_FLASH_Open(BANK0);
- }
- #ifdef STFLASH_BANK_1_BASE
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = wts_FLASH_Init(BANK1);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = wts_FLASH_Open(BANK1);
- }
- #endif
-
- }
- else if (rom_operation==READ)
- {
- debugmessage( "nROMTOOL> Enter Flash to filename : " );
- debuggets(buf, BUF_LEN);
- strcpy(rom_datafile, buf);
- debugmessage( "nROMTOOL> Enter Read start address : " );
- debuggets(buf, BUF_LEN);
- read_start_address = wts_htod(buf);
- sprintf(buf1,"read_start_address = 0x%xn", read_start_address);
- debugmessage(buf1);
-
- debugmessage( "nROMTOOL> Enter Read Size (byte) : " );
- debuggets(buf, BUF_LEN);
- read_size = wts_htod(buf);
- sprintf(buf1,"read_size = 0x%xn", read_size);
- debugmessage(buf1);
-
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = FLASH_SetupBlockInfo();
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = FLASH_Init(BANK0);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = FLASH_Open(BANK0);
- }
- #ifdef STFLASH_BANK_1_BASE
- if ( ErrCode == ST_NO_ERROR )
- {
- ErrCode = FLASH_Init(BANK1);
- if ( ErrCode == ST_NO_ERROR )
- ErrCode = FLASH_Open(BANK1);
- }
- #endif
- }
-
- }while(prev_menu);
- rom_report = FULL ;
- status = TRUE ;
- /*******************************************************/
- debugmessage("nFlash Programmer V2.0 .");
- debugmessage("n(c) WTMEC Microelectronics Ltd 2005.11.11nn");
- if(rom_operation==PROGRAM || rom_operation==VERIFY){
- if(image_type == LNBList)
- debugmessage("Image type: LNB Listnn");
- else if(image_type == LogoImage)
- debugmessage("Image type: Logonn");
- else if(image_type == LanguageImage)
- debugmessage("Image type: Languagenn");
- else if(image_type == CHNList)
- debugmessage("Image type: Channel Listnn");
- else if(image_type == HexCode)
- debugmessage("Image type: *.hex Codenn");
- else if(image_type == BinCode)
- debugmessage("Image type: *.bin Codenn");
- else
- debugmessage("Image type: Total flashnn");
- }
- else if(rom_operation == ERASE){
- debugmessage("Erase flash nn");
- }
- else{
- debugmessage("Read flash nn");
- }
- if (rom_datafile[0]!=' ')
- sprintf(buf1,"file = %sn", rom_datafile);
- debugmessage(buf1);
- #if 0
- if (TRUE)
- sprintf(buf1,"address = 0x%xn", address_load);
- debugmessage(buf1);
- #endif
- /***********************************************/
- if (rom_operation==ERASE)
- {
- if (erase_type==ERASE_ALL) {
- debugmessage("Erase Total flash nn");
- status = wts_EraseFlash(TRUE) ;
- if (status) {
- debugmessage("Erase failedn") ;
- exit(1) ;
- }
- }
- if(erase_type==ERACODE){
- debugmessage("Erase code nn");
- status = wts_EraseCodeFlash(TRUE) ;
- if (status) {
- debugmessage("Erase failedn") ;
- exit(1) ;
- }
- }
- if(erase_type==ERALOGO){
- debugmessage("Erase logo nn");
- status = wts_EraseLogoFlash(TRUE) ;
- if (status) {
- debugmessage("Erase failedn") ;
- exit(1) ;
- }
- }
- if(erase_type==ERALANGUAGE){
- debugmessage("Erase language nn");
- status = wts_EraseLanguageFlash(TRUE) ;
- if (status) {
- debugmessage("Erase failedn") ;
- exit(1) ;
- }
- }
-
- if(erase_type==ERALNB){
- debugmessage("Erase LNB nn");
- status = wts_EraseLNBFlash(TRUE) ;
- if (status) {
- debugmessage("Erase failedn") ;
- exit(1) ;
- }
- }
- debugmessage("Operation completed successfullyn");
-
- #ifdef STFLASH_BANK_1_BASE
- wts_FLASH_Close(BANK1);
- wts_FLASH_Term(TRUE, BANK1);
- #endif
- wts_FLASH_Close(BANK0);
- wts_FLASH_Term(TRUE, BANK0);
- return (0);
-
- }
- else if (rom_operation==PROGRAM || rom_operation==VERIFY)
- {
- if(image_type == BinCode ){
- if(rom_operation==PROGRAM){
- debugmessage("begin --------- Program/verify BinCode n") ;
- status = ProgramFlash() ;
- if (status)
- {
- debugmessage("Program failedn") ;
- exit (1) ;
- }
- status = VerifyFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- }
- else{
- debugmessage("begin --------- verify BinCode n") ;
- status = VerifyFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- }
- }
- else if(((image_type == LNBList) || (image_type == CHNList)) ){
- if( rom_operation==PROGRAM ){
- debugmessage("begin ----- Program/verify LNB or Channel listn") ;
- status = ProgramLNBFlash();
- if (status)
- {
- debugmessage("Program failedn") ;
- exit (1) ;
- }
- status = VerifyLNBFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- }
- else{
- debugmessage("begin --------- verify LNB or Channel list n") ;
- status = VerifyLNBFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- }
- }
- else if(image_type == LogoImage ){
- if( rom_operation==PROGRAM ){
- debugmessage("begin ----- Program/verify Logon") ;
- status = ProgramLogoFlash();
- if (status)
- {
- debugmessage("Program failedn") ;
- exit (1) ;
- }
- #if 0
- status = VerifyLogoFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- #endif
- }
- #if 0
- else{
- debugmessage("begin --------- verify Logo n") ;
- status = VerifyLogoFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- }
- #endif
- }
- else if(image_type == LanguageImage ){
- if( rom_operation==PROGRAM ){
- debugmessage("begin ----- Program/verify Language n") ;
- status = ProgramLanguageFlash();
- if (status)
- {
- debugmessage("Program failedn") ;
- exit (1) ;
- }
- status = VerifyLanguageFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- }
- else{
- debugmessage("begin --------- verify Language n") ;
- status = VerifyLanguageFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- }
- }
- else if( image_type == All ){
- if( rom_operation==PROGRAM ){
- debugmessage("begin ----- Program/verify 2M Flash n") ;
- status = ProgramAllFlash();
- if (status)
- {
- debugmessage("Program failedn") ;
- exit (1) ;
- }
- status = VerifyAllFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- }
- else{
- debugmessage("begin --------- verify 2M Flash n") ;
- status = VerifyAllFlash() ;
- if (status)
- {
- debugmessage("verify failedn") ;
- exit (1) ;
- }
- }
- }
- else
- return FALSE;
- debugmessage("Operation completed successfullyn");
- #ifdef STFLASH_BANK_1_BASE
- FLASH_Close(BANK1);
- FLASH_Term(TRUE, BANK1);
- #endif
- FLASH_Close(BANK0);
- FLASH_Term(TRUE, BANK0);
- exit (0);
-
- }
- else
- if (rom_operation==READ)
- {
- debugmessage("begin --------- read n") ;
- status = ReadProgram( rom_datafile, read_start_address, read_size );
- if (!status)
- {
- debugmessage("Read failedn") ;
- exit (1) ;
- }
- debugmessage("Operation completed successfullyn");
- #ifdef STFLASH_BANK_1_BASE
- FLASH_Close(BANK1);
- FLASH_Term(TRUE, BANK1);
- #endif
- FLASH_Close(BANK0);
- FLASH_Term(TRUE, BANK0);
- exit (0);
- }
- debugmessage("Operation completed successfullyn");
- exit (0);
- /*******************gleam****************************/
- #else
- #endif
- return (0);
- } /* end main */
- /* EOF --------------------------------------------------------------------- */