wts_flash.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:101k
源码类别:

DVD

开发平台:

C/C++

  1. /****************************************************************************
  2. File Name   : tt_flash.c
  3. Description : Testtool FLASH Commands
  4. Copyright (C) 2004, ST Microelectronics
  5.  
  6. ****************************************************************************/
  7. /* Includes --------------------------------------------------------------- */
  8. /* Standard Includes */
  9. #include <stdio.h>
  10. #include <stddef.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <debug.h>
  14. #include "stack.h"
  15. #include "stlite.h"
  16. #include "stddefs.h"
  17. #include "stdevice.h"
  18. /* STAPI Includes */
  19. #include "stflash.h"
  20. #include "sttbx.h"
  21. #include "testtool.h"
  22. /* Local Includes */
  23. #include "wts_app_data.h"
  24. #include "wts_flash.h"
  25. /* Private Types ------------------------------------------------------ */
  26. /* Private Constants -------------------------------------------------- */
  27. /* Definitions for Flash */
  28. #if 0
  29. #define FLASH_BANK_0_BASE_ADDRESS_LOCAL 0x40000000 /* check this as it should be 7f80000 */
  30. #define STFLASH_BANK_0_BASE     FLASH_BANK_0_BASE_ADDRESS_LOCAL  /*FLASH_BANK_0_BASE_ADDRESS*/
  31. #endif
  32. #define STFLASH_MAIN_0_SIZE     STFLASH_MAIN_SIZE
  33. #define STFLASH_MAIN_1_SIZE     STFLASH_MAIN_SIZE
  34. #ifdef ST_5105
  35. #define STFLASH_VPP_0_ENABLE    0x45200000
  36. #elif defined(ST_5100)
  37. #define STFLASH_VPP_0_ENABLE    0x41400000
  38. #endif
  39. /* if BANK_1 defined it is available */
  40. #if defined(FLASH_BANK_1_BASE_ADDRESS)
  41.     #define STFLASH_BANK_1_BASE     FLASH_BANK_1_BASE_ADDRESS
  42.     #define NUM_BANKS               2
  43. #else
  44.     #define NUM_BANKS               1
  45. #endif
  46. /* if VPP not defined it is not needed */
  47. #if !defined(STFLASH_VPP_0_ENABLE)
  48.     #define STFLASH_VPP_0_ENABLE    (U32)NULL
  49. #endif
  50. #if !defined(STFLASH_VPP_1_ENABLE)
  51.     #define STFLASH_VPP_1_ENABLE    (U32)NULL
  52. #endif
  53. /***********leslie***********/
  54. /*M29W160DT*/
  55. #define DEVICE_TYPE             STFLASH_M29W320DT /*STFLASH_M29W800T*/
  56. #define MIN_ACCESS_WIDTH        STFLASH_ACCESS_16_BITS
  57. #define MAX_ACCESS_WIDTH        STFLASH_ACCESS_16_BITS
  58. #define NUM_BLOCKS              135
  59. /**********************/
  60. #define STFLASH_MAIN00_SIZE             0x00010000  /* 64Kb */
  61. #define STFLASH_MAIN01_SIZE             0x00008000  /* 32Kb */
  62. #define STFLASH_PARA_0_SIZE             0x00002000  /* 8Kb */
  63. #define STFLASH_BOOT_0_SIZE             0x00004000  /* 16Kb */
  64. #define NUM_SECTIONS            NUM_BLOCKS
  65. #define TOTAL_BLOCKS            (NUM_BANKS * NUM_BLOCKS)
  66. #ifdef rayf
  67. #define CODE_SECTIONS 0
  68. #define LANG_SECTIONS 16
  69. #define LNB_SECTIONS 24
  70. #define LOGO_SECTIONS 31
  71. #define CODE_BLOCKS 16
  72. #define FIRST_CODE_BLOCK 0
  73. #define LANG_BLOCKS 8
  74. #define FIRST_LANG_BLOCK 16
  75. #define LNB_BLOCKS 2
  76. #define FIRST_LNB_BLOCK 24
  77. #define LOGO_BLOCKS 1
  78. #define FIRST_LOGO_BLOCK 31
  79. #endif
  80. #define CR                      13
  81. #define LF                      10
  82. /* Private Variables -------------------------------------------------- */
  83. /* Bank sizes (bytes) */
  84. /* Each device is configured as 512kb x 16 bits */ STFLASH_Block_t      wts_BlockData_s[NUM_BLOCKS] =
  85.  {
  86.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 1 */
  87.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 2 */
  88.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 3 */
  89.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 4 */
  90.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 5 */
  91.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 6 */
  92.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 7 */
  93.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 8 */
  94.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 9 */
  95.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 10 */
  96.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 11 */
  97.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 12 */
  98.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 13 */
  99.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 14 */
  100.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 15 */
  101.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 16 */
  102.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 17 */
  103.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 18 */
  104.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 19 */
  105.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 20 */
  106.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 21 */
  107.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 22 */
  108.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 23 */
  109.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 24 */
  110.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 25 */
  111.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 26 */
  112.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 27 */
  113.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 28 */
  114.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 29 */
  115.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 30 */
  116.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 1 */
  117.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 2 */
  118.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 3 */
  119.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 4 */
  120.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 5 */
  121.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 6 */
  122.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 7 */
  123.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 8 */
  124.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 9 */
  125.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 10 */
  126.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 11 */
  127.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 12 */
  128.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 13 */
  129.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 14 */
  130.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 15 */
  131.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 16 */
  132.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 17 */
  133.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 18 */
  134.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 19 */
  135.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 20 */
  136.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 21 */
  137.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 22 */
  138.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 23 */
  139.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 24 */
  140.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 25 */
  141.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 26 */
  142.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 27 */
  143.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 28 */
  144.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 29 */
  145.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 60 */
  146.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 1 */
  147.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 2 */
  148.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 3 */
  149.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 4 */
  150.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 5 */
  151.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 6 */
  152.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 7 */
  153.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 8 */
  154.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 9 */
  155.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 10 */
  156.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 11 */
  157.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 12 */
  158.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 13 */
  159.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 14 */
  160.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 15 */
  161.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 16 */
  162.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 17 */
  163.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 18 */
  164.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 19 */
  165.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 20 */
  166.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 21 */
  167.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 22 */
  168.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 23 */
  169.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 24 */
  170.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 25 */
  171.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 26 */
  172.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 27 */
  173.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 28 */
  174.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 29 */
  175.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 90 */
  176.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 1 */
  177.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 2 */
  178.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 3 */
  179.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 4 */
  180.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 5 */
  181.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 6 */
  182.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 7 */
  183.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 8 */
  184.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 9 */
  185.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 10 */
  186.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 11 */
  187.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 12 */
  188.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 13 */
  189.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 14 */
  190.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 15 */
  191.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 16 */
  192.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 17 */
  193.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 18 */
  194.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 19 */
  195.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 20 */
  196.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 21 */
  197.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 22 */
  198.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 23 */
  199.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 24 */
  200.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 25 */
  201.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 26 */
  202.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 27 */
  203.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 28 */
  204.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 29 */
  205.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 120 */
  206.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 1 */
  207.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 2 */
  208.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 3 */
  209.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 4 */
  210.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 5 */
  211.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 6 */
  212.   {STFLASH_MAIN00_SIZE  , STFLASH_MAIN_BLOCK }, /* 7 */
  213.   {STFLASH_PARA_0_SIZE  , STFLASH_PARAMETER_BLOCK }, /* 8 */
  214.   {STFLASH_PARA_0_SIZE  , STFLASH_PARAMETER_BLOCK }, /* 9 */
  215.   {STFLASH_PARA_0_SIZE  , STFLASH_PARAMETER_BLOCK }, /* 10 */
  216.   {STFLASH_PARA_0_SIZE  , STFLASH_PARAMETER_BLOCK }, /* 11 */
  217.   {STFLASH_PARA_0_SIZE  , STFLASH_PARAMETER_BLOCK }, /* 12 */
  218.   {STFLASH_PARA_0_SIZE  , STFLASH_PARAMETER_BLOCK }, /* 13 */
  219.   {STFLASH_PARA_0_SIZE  , STFLASH_PARAMETER_BLOCK }, /* 14 */
  220.   {STFLASH_PARA_0_SIZE  , STFLASH_PARAMETER_BLOCK }  /* 135 */
  221.  };  /* 34 */
  222. /****************************/      
  223. static U32              FlashSize = 0;          /* Non-zero = file converted */
  224. static char             *FlashData_p = NULL;
  225. static SectionInfo_t    SectionInfo[NUM_SECTIONS];
  226. static BlockInfo_t      BlockInfo[TOTAL_BLOCKS + 1];
  227. static U32              BaseAddress[NUM_BANKS];
  228. static STFLASH_Block_t  GetBlkDat_s[NUM_BLOCKS];
  229. /* Private Macros ----------------------------------------------------- */
  230. extern U32 wtFlashBankBaseAddr;
  231. #define WTFLASH_BASE_ADDR2 wtFlashBankBaseAddr
  232. /* Global Variables ------------------------------------------------------- */
  233. STFLASH_Handle_t        wts_FLASHHndl[2];
  234. ST_DeviceName_t         wts_FLASHDeviceName[2] = {"Bank0", "Bank1"};
  235. /* Private Function prototypes ---------------------------------------- */
  236. /* Functions ---------------------------------------------------------- */
  237. /*-------------------------------------------------------------------------
  238.  * Function : wts_FLASH_Close
  239.  *            close FLASH
  240.  * Input    : None
  241.  * Output   :
  242.  * Return   : TRUE if error, FALSE if success
  243.  * ----------------------------------------------------------------------*/
  244. ST_ErrorCode_t wts_FLASH_Close( U8 BankNum )
  245. {
  246.     ST_ErrorCode_t          ErrCode;
  247.     ErrCode = STFLASH_Close(wts_FLASHHndl[BankNum]);
  248.     STTBX_Print(("STFLASH_Close()=%sn", wts_GetErrorText(ErrCode) ));
  249.     return ( ErrCode );
  250. } /* end wts_FLASH_Close */
  251. /*-------------------------------------------------------------------------
  252.  * Function : wts_FLASH_GetParams
  253.  *            Get Flash Parameters
  254.  * Input    : None
  255.  * Output   :
  256.  * Return   : TRUE if error, FALSE if success
  257.  * ----------------------------------------------------------------------*/
  258. ST_ErrorCode_t wts_FLASH_GetParams( U8 BankNum, STFLASH_Params_t *FLASHParams_p )
  259. {
  260.     ST_ErrorCode_t      ErrCode;
  261.     
  262.     /* assign structure for returning data */
  263.     FLASHParams_p->InitParams.Blocks = GetBlkDat_s;    
  264.     ErrCode = STFLASH_GetParams(wts_FLASHHndl[BankNum], FLASHParams_p );
  265.     STTBX_Print(("STFLASH_GetParams(%d)=%sn", BankNum, wts_GetErrorText(ErrCode)));
  266.     return ( ErrCode );
  267. } /* end wts_FLASH_Close */
  268. /*-------------------------------------------------------------------------
  269.  * Function : wts_FLASH_Init
  270.  *            Initialise FLASH
  271.  * Input    : None
  272.  * Output   :
  273.  * Return   : TRUE if error, FALSE if success
  274.  * ----------------------------------------------------------------------*/
  275. ST_ErrorCode_t wts_FLASH_Init( U8 BankNum )
  276. {
  277.     ST_ErrorCode_t          ErrCode;
  278.     STFLASH_InitParams_t    InitParams;
  279.     InitParams.DeviceType = DEVICE_TYPE;
  280.     if ( BankNum == BANK0 )
  281.     {
  282. #if 0
  283.         InitParams.BaseAddress = (U32*)STFLASH_BANK_0_BASE;
  284. #else
  285.         InitParams.BaseAddress = (U32*)WTFLASH_BASE_ADDR2;
  286. STTBX_Print(("nBaseAddress=[0x%x]n",InitParams.BaseAddress));
  287. #endif
  288.         InitParams.VppAddress  = (U32*)STFLASH_VPP_0_ENABLE;
  289.     }
  290.     else
  291.     {
  292.         #if defined(STFLASH_BANK_1_BASE)
  293.             InitParams.BaseAddress = (U32*)STFLASH_BANK_1_BASE;
  294.             InitParams.VppAddress  = (U32*)STFLASH_VPP_1_ENABLE;
  295.         #else
  296.             return ST_ERROR_FEATURE_NOT_SUPPORTED;
  297.         #endif
  298.     }
  299.     InitParams.MinAccessWidth  = MIN_ACCESS_WIDTH;
  300.     InitParams.MaxAccessWidth  = MAX_ACCESS_WIDTH;
  301.     InitParams.NumberOfBlocks  = NUM_BLOCKS;
  302.     InitParams.Blocks          = wts_BlockData_s;
  303.     InitParams.DriverPartition = SystemPartition;
  304.     ErrCode = STFLASH_Init(wts_FLASHDeviceName[BankNum], &InitParams );
  305.     STTBX_Print(("STFLASH_Init(%s)=%sn", wts_FLASHDeviceName[BankNum], wts_GetErrorText(ErrCode) ));
  306.     return ( ErrCode );
  307. } /* end wts_FLASH_Init */
  308. /*-------------------------------------------------------------------------
  309.  * Function : wts_FLASH_Open
  310.  *            Open FLASH
  311.  * Input    : None
  312.  * Output   :
  313.  * Return   : TRUE if error, FALSE if success
  314.  * ----------------------------------------------------------------------*/
  315. ST_ErrorCode_t wts_FLASH_Open( U8 BankNum )
  316. {
  317.     ST_ErrorCode_t          ErrCode;
  318.     STFLASH_OpenParams_t    OpenParams;
  319.     
  320.     memset((char*)&OpenParams,0,sizeof(STFLASH_OpenParams_t));
  321.     
  322.     ErrCode = STFLASH_Open(wts_FLASHDeviceName[BankNum], &OpenParams, &wts_FLASHHndl[BankNum]);
  323.     STTBX_Print(("STFLASH_Open(%s)=%sn", wts_FLASHDeviceName[BankNum], wts_GetErrorText(ErrCode) ));
  324.     return ( ErrCode );
  325. } /* end wts_FLASH_Open */
  326. /*-------------------------------------------------------------------------
  327.  * Function : wts_FLASH_Term
  328.  *            Terminate FLASH
  329.  * Input    : ForceTerminate
  330.  * Output   :
  331.  * Return   : TRUE if error, FALSE if success
  332.  * ----------------------------------------------------------------------*/
  333. ST_ErrorCode_t wts_FLASH_Term(  BOOL ForceTerminate, U8 BankNum )
  334. {
  335.     ST_ErrorCode_t          ErrCode;
  336.     STFLASH_TermParams_t    TermParams;
  337.     TermParams.ForceTerminate = ForceTerminate;
  338.     ErrCode = STFLASH_Term(wts_FLASHDeviceName[BankNum], &TermParams);
  339.     STTBX_Print(("STFLASH_Term(%s)=%sn", wts_FLASHDeviceName[BankNum], wts_GetErrorText(ErrCode) ));
  340.     return ( ErrCode );
  341. } /* end wts_FLASH_Term */
  342. /*-------------------------------------------------------------------------
  343.  * Function : wts_FLASH_SetupBlockInfo
  344.  *            Setup Block Info structure
  345.  * Input    :
  346.  * Output   :
  347.  * Return   : Error Code
  348.  * ----------------------------------------------------------------------*/
  349. ST_ErrorCode_t wts_FLASH_SetupBlockInfo( void )
  350. {
  351.     ST_ErrorCode_t      ErrCode = ST_NO_ERROR;
  352.     STFLASH_Params_t    FLASHParams;
  353.     U8  Bank=0, Block=0;
  354.     U32 BlockStart = 0;
  355.     static U8 Section = 0;
  356.     
  357.     memset((char*)&FLASHParams,0,sizeof(STFLASH_Params_t));
  358.     if ( Section == 0 )
  359.     {
  360.         /*
  361.         **  Set the address for each section
  362.         */
  363.         for ( Bank = 0; ( Bank < NUM_BANKS ) && ( ErrCode == ST_NO_ERROR ); Bank ++ )
  364.         {
  365.             ErrCode = wts_FLASH_Init( Bank );                /* Init Bank */
  366.             if ( ErrCode == ST_NO_ERROR )
  367.             {
  368.                 ErrCode = wts_FLASH_Open( Bank );
  369.                 if ( ErrCode == ST_NO_ERROR )
  370.                     ErrCode = wts_FLASH_GetParams( Bank, &FLASHParams );
  371.                 if ( ErrCode == ST_NO_ERROR )
  372.                 {
  373.                     BlockStart = BaseAddress[Bank] = (U32) FLASHParams.InitParams.BaseAddress;
  374.                     for ( Block = 0; Block < FLASHParams.InitParams.NumberOfBlocks; Block ++)
  375.                     {
  376.                         BlockInfo[Section].Bank    = Bank;
  377.                         BlockInfo[Section].Address = BlockStart;
  378.                         BlockInfo[Section].Length  = FLASHParams.InitParams.Blocks[Block].Length;
  379.                         #ifdef DEBUG_OUTPUT
  380.                             STTBX_Print(("Block %2d (%d) 0x%08x 0x%08x (%6d) bytesn",
  381.                                          Block, Section,
  382.                                          BlockInfo[Section].Address,
  383.                                          BlockInfo[Section].Length,
  384.                                          BlockInfo[Section].Length ));
  385.                         #endif
  386.                         Section ++;
  387.                         BlockStart += FLASHParams.InitParams.Blocks[Block].Length;
  388.                     }
  389.                 }
  390.                 ErrCode = wts_FLASH_Term( TRUE, Bank );
  391.             }
  392.         }
  393.         BlockInfo[Section].Address = BlockStart;
  394.     }
  395.     if ( ErrCode == ST_NO_ERROR )
  396.         STTBX_Print(("Flash setup Ok (%d blocks)n", Section ));
  397.     return( ErrCode );
  398. } /* end of wts_FLASH_SetupBlockInfo */
  399. /*-------------------------------------------------------------------------
  400.  * Function : wts_FLASH_Setup
  401.  *            Setup Block Info structure
  402.  * Input    :
  403.  * Output   :
  404.  * Return   : Error Code
  405.  * ----------------------------------------------------------------------*/
  406. ST_ErrorCode_t wts_FLASH_Setup( void )
  407. {
  408.     ST_ErrorCode_t      ErrCode = ST_NO_ERROR;
  409.     U8  Bank;
  410.     
  411.     /*    **  Set the address for each section*/
  412.        
  413.         for ( Bank = 0; ( Bank < NUM_BANKS ) && ( ErrCode == ST_NO_ERROR ); Bank ++ )
  414.         {
  415.             ErrCode = wts_FLASH_Init( Bank );                /* Init Bank */
  416.             if ( ErrCode == ST_NO_ERROR )
  417.             {
  418.                 ErrCode = wts_FLASH_Open( Bank );
  419.             }
  420.             if ( ErrCode == ST_NO_ERROR )
  421.             STTBX_Print(("Flash setup Ok.....n" ));        
  422.         }
  423.     return( ErrCode );
  424. } /* end of Flash_Setup */
  425. /*-------------------------------------------------------------------------
  426.  * Function : wts_FreeFileDataBuffer
  427.  *            as is
  428.  * Input    :
  429.  * Output   :
  430.  * Return   : None
  431.  * ----------------------------------------------------------------------*/
  432. static void wts_FreeFileDataBuffer(void)
  433. {
  434.     /* deallocate File data buffer */
  435.     if ( FlashData_p != NULL )
  436.         memory_deallocate( SystemPartition, FlashData_p );
  437. } /* end of wts_FreeFileDataBuffer() */
  438. /*-------------------------------------------------------------------------
  439.  * Function : wts_GetBlockNumber
  440.  *            Get block number from address
  441.  * Input    :
  442.  * Output   :
  443.  * Return   : Block number of address
  444.  * ----------------------------------------------------------------------*/
  445. static U8 wts_GetBlockNumber( U32 Address )
  446. {
  447.     U8  Block;
  448.     /* find the block this address is in */
  449.     for ( Block = 0; Block < TOTAL_BLOCKS; Block++ )
  450.     {
  451.         if (( Address >= BlockInfo[Block].Address ) &&
  452.             ( Address < (BlockInfo[Block].Address+BlockInfo[Block].Length)))
  453.         {
  454.             break;
  455.         }
  456.     }
  457.     return Block;
  458. } /* end wts_GetBlockNumber */
  459. /*-------------------------------------------------------------------------
  460.  * Function : wts_ConvertTotalMemory
  461.  *            Convert Raw Hex file into memory buffer suitable to write to
  462.  *            flash copying created data over data read from filem, the
  463.  *            created data will be smaller as each byte takes three bytes
  464.  *            in the Hex file.
  465.  * Input    :
  466.  * Output   :
  467.  * Return   : size of data in buffer
  468.  * ----------------------------------------------------------------------*/
  469. static U32 wts_ConvertTotalMemory( long unsigned int MemSize )
  470. {
  471.     char                *OldPtr, *NewPtr;
  472.     int                 Section;
  473.     U32                 InOffset;
  474.     U32                 OutOffset;
  475.     U32                 BlockOffset;
  476.     U32                 Value=0;
  477.     U8                  Count=0 , Block=0;
  478.     
  479.     for ( Section = 0; Section < NUM_BLOCKS; Section ++ )
  480.     {
  481.         SectionInfo[Section].Block = 0xff;
  482.         SectionInfo[Section].Address = 0;
  483.         SectionInfo[Section].Offset = 0;
  484.         SectionInfo[Section].Size = 0;
  485.     }
  486.     /* Convert File */
  487.     Section = 0;
  488.     OldPtr = FlashData_p;
  489.     NewPtr = (char*) NULL;
  490.     
  491.     for ( InOffset = 0, OutOffset = 0; InOffset < MemSize; )
  492.     {
  493.         /* Line format =
  494.         ** Address  Data  (both in hex)
  495.         ** 12345678 11 22 33 44 55 etc. CR/LF
  496.         */
  497.         Value = (U32) strtol( OldPtr, &NewPtr, 16 );
  498.         if ( NewPtr != OldPtr ) /* if conversion possible */
  499.         {
  500.             
  501.                 BlockOffset = OutOffset;
  502.                 for ( Count = 0; Count < Section; Count++ )
  503.                     BlockOffset -= SectionInfo[Count].Size;
  504.                 if (( BlockOffset+1 ) > BlockInfo[SectionInfo[Section].Block].Length )
  505.                 {
  506.                     Section++;
  507.                 }
  508.                 /* Start New Block */
  509.                 if ( SectionInfo[Section].Block == 0xff )
  510.                 {
  511.                     SectionInfo[Section].Address = BlockInfo[Block].Address + BlockOffset;
  512.                     SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
  513.                     SectionInfo[Section].Offset = OutOffset;
  514.                     SectionInfo[Section].Size = 0;
  515.                 }
  516.                 SectionInfo[Section].Size ++;
  517.                 FlashData_p[OutOffset++] = (char) Value;
  518.             InOffset += (U32)( NewPtr - OldPtr );
  519.             OldPtr = NewPtr;
  520.             if ( Section > NUM_BLOCKS )
  521.             {
  522.                 STTBX_Print(("Program Limitationn"));
  523.                 exit(0);
  524.             }
  525.        }
  526.         else
  527.             break;
  528.     } /* end of for loop */
  529.     STTBX_Print(("n"));
  530.     /* display the first few bytes of each section */
  531.     for ( Section = 0; Section < NUM_BLOCKS; Section ++ )
  532.     {
  533.         if ( SectionInfo[Section].Block != 0xFF )
  534.         {
  535.             STTBX_Print(("Section %2d, Block %3d, Addr 0x%08x, Offset 0x%08x, Size %6dn",
  536.                          Section,
  537.                          SectionInfo[Section].Block,
  538.                          SectionInfo[Section].Address,
  539.                          SectionInfo[Section].Offset,
  540.                          SectionInfo[Section].Size ));
  541.             #ifdef DEBUG_INFO
  542.                 for ( InOffset = 0;
  543.                       ( InOffset < 32 ) && ( InOffset < SectionInfo[Section].Size );
  544.                       InOffset ++ )
  545.                 {
  546.                     STTBX_Print((" %02x", FlashData_p[ SectionInfo[Section].Offset + InOffset ] ));
  547.                 }
  548.                 STTBX_Print(("n"));
  549.             #endif
  550.         }
  551.     }
  552.     return ( OutOffset );
  553. } /* end wts_ConvertTotalMemory */
  554. /*-------------------------------------------------------------------------
  555.  * Function : wts_ConvertMemory
  556.  *            Convert Raw Hex file into memory buffer suitable to write to
  557.  *            flash copying created data over data read from filem, the
  558.  *            created data will be smaller as each byte takes three bytes
  559.  *            in the Hex file.
  560.  * Input    :
  561.  * Output   :
  562.  * Return   : size of data in buffer
  563.  * ----------------------------------------------------------------------*/
  564. static U32 wts_ConvertMemory( long unsigned int MemSize )
  565. {
  566.     char                *OldPtr, *NewPtr;
  567.     int                 Section;
  568.     U32                 InOffset;
  569.     U32                 OutOffset;
  570.     U32                 BlockOffset;
  571.     U32                 Value=0;
  572.     U8                  Count=0 , Block=0;
  573.     
  574.     for ( Section = 0; Section < NUM_SECTIONS; Section ++ )
  575.     {
  576.         SectionInfo[Section].Block = 0xff;
  577.         SectionInfo[Section].Address = 0;
  578.         SectionInfo[Section].Offset = 0;
  579.         SectionInfo[Section].Size = 0;
  580.     }
  581.     /* Convert File */
  582. /*ray    Section = 0;*/
  583.     Section = 0;
  584.     OldPtr = FlashData_p;
  585.     NewPtr = (char*) NULL;
  586.     
  587.     for ( InOffset = 0, OutOffset = 0; InOffset < MemSize; )
  588.     {
  589.         /* Line format =
  590.         ** Address  Data  (both in hex)
  591.         ** 12345678 11 22 33 44 55 etc. CR/LF
  592.         */
  593.         Value = (U32) strtol( OldPtr, &NewPtr, 16 );
  594.         if ( NewPtr != OldPtr ) /* if conversion possible */
  595.         {
  596.             if ( Value > 255 )  /* which means it is an address */
  597.             {
  598.                 if (( Block = wts_GetBlockNumber( Value )) == TOTAL_BLOCKS )/*changed temp*/
  599.                 {
  600.                     STTBX_Print(("Invalid address 0x%xn", Value ));
  601.                     break;
  602.                 }
  603.                 else
  604.                 {
  605.                     /*
  606.                     ** check if the address is non-contiguous
  607.                     ** or if it is a new block
  608.                     */
  609.                     if ((( SectionInfo[Section].Address + SectionInfo[Section].Size ) != Value ) ||
  610.                         ( SectionInfo[Section].Block != Block ))
  611.                     {
  612.                         Section ++;
  613.                     }
  614.                     /* Start New Block */
  615.                     if ( SectionInfo[Section].Block == 0xff )
  616.                     {
  617.                         SectionInfo[Section].Address = Value;
  618.                         SectionInfo[Section].Block = Block;
  619.                         SectionInfo[Section].Offset = OutOffset;
  620.                         SectionInfo[Section].Size = 0;
  621.                     }
  622.                 }
  623.             }
  624.             else
  625.             {
  626.                 BlockOffset = OutOffset;
  627.                 for ( Count = 0; Count < Section; Count++ )
  628.                     BlockOffset -= SectionInfo[Count].Size;
  629.                 if (( BlockOffset+1 ) > BlockInfo[SectionInfo[Section].Block].Length )
  630.                 {
  631.                     Section++;
  632.                 }
  633.                 /* Start New Block */
  634.                 if ( SectionInfo[Section].Block == 0xff )
  635.                 {
  636.                     SectionInfo[Section].Address = BlockInfo[Block].Address + BlockOffset;
  637.                     SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
  638.                     SectionInfo[Section].Offset = OutOffset;
  639.                     SectionInfo[Section].Size = 0;
  640.                 }
  641.                 SectionInfo[Section].Size ++;
  642.                 FlashData_p[OutOffset++] = (char) Value;
  643.              }
  644.             InOffset += (U32)( NewPtr - OldPtr );
  645.             OldPtr = NewPtr;
  646.             if ( Section > NUM_SECTIONS )
  647.             {
  648.                 STTBX_Print(("Program Limitationn"));
  649.                 exit(0);
  650.             }
  651.        }
  652.         else
  653.             break;
  654.     } /* end of for loop */
  655.     STTBX_Print(("n"));
  656.     /* display the first few bytes of each section */
  657.     for ( Section = 0; Section < NUM_SECTIONS; Section ++ )
  658.     {
  659.         if ( SectionInfo[Section].Block != 0xFF )
  660.         {
  661.             STTBX_Print(("Section %2d, Block %3d, Addr 0x%08x, Offset 0x%08x, Size %6dn",
  662.                          Section,
  663.                          SectionInfo[Section].Block,
  664.                          SectionInfo[Section].Address,
  665.                          SectionInfo[Section].Offset,
  666.                          SectionInfo[Section].Size ));
  667.             #ifdef DEBUG_INFO
  668.                 for ( InOffset = 0;
  669.                       ( InOffset < 32 ) && ( InOffset < SectionInfo[Section].Size );
  670.                       InOffset ++ )
  671.                 {
  672.                     STTBX_Print((" %02x", FlashData_p[ SectionInfo[Section].Offset + InOffset ] ));
  673.                 }
  674.                 STTBX_Print(("n"));
  675.             #endif
  676.         }
  677.     }
  678.     return ( OutOffset );
  679. } /* end wts_ConvertMemory */
  680. /*-------------------------------------------------------------------------
  681.  * Function : wts_ConvertMemory
  682.  *            Convert Raw Hex file into memory buffer suitable to write to
  683.  *            flash copying created data over data read from filem, the
  684.  *            created data will be smaller as each byte takes three bytes
  685.  *            in the Hex file.
  686.  * Input    :
  687.  * Output   :
  688.  * Return   : size of data in buffer
  689.  * ----------------------------------------------------------------------*/
  690. static U32 wts_BinConvertMemory( long unsigned int MemSize )
  691. {
  692.     char                *OldPtr, *NewPtr;
  693.     int                 Section;
  694.     U32                 InOffset;
  695.     U32                 OutOffset;
  696.     U32                 BlockOffset;
  697.     U32                 Value=0;
  698.     U8                  Count=0 , Block=0;
  699.     
  700.     for ( Section = 0; Section < NUM_SECTIONS; Section ++ )
  701.     {
  702.         SectionInfo[Section].Block = 0xff;
  703.         SectionInfo[Section].Address = 0;
  704.         SectionInfo[Section].Offset = 0;
  705.         SectionInfo[Section].Size = 0;
  706.     }
  707.     /* Convert File */
  708. /*ray    Section = 0;*/
  709.     Section = 0;
  710.     OldPtr = FlashData_p;
  711.     NewPtr = (char*) NULL;
  712.     
  713.     for ( InOffset = 0, OutOffset = 0; InOffset < MemSize; )
  714.     {
  715.                 BlockOffset = OutOffset;
  716.                 for ( Count = 0; Count < Section; Count++ )
  717.                     BlockOffset -= SectionInfo[Count].Size;
  718.                 if (( BlockOffset+1 ) > BlockInfo[SectionInfo[Section].Block].Length )
  719.                 {
  720.                     Section++;
  721.                 }
  722.                 /* Start New Block */
  723.                 if ( SectionInfo[Section].Block == 0xff )
  724.                 {
  725.                     SectionInfo[Section].Address = BlockInfo[Block].Address + BlockOffset;
  726.                     SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
  727.                     SectionInfo[Section].Offset = OutOffset;
  728.                     SectionInfo[Section].Size = 0;
  729.                 }
  730.                 SectionInfo[Section].Size ++;
  731.                 FlashData_p[OutOffset++] = (char) Value;
  732.             InOffset += (U32)STFLASH_MAIN00_SIZE; /*( NewPtr - OldPtr );*/
  733.             OldPtr = NewPtr;
  734.             if ( Section > NUM_SECTIONS )
  735.             {
  736.                 STTBX_Print(("Program Limitationn"));
  737.                 exit(0);
  738.             }
  739.     } /* end of for loop */
  740.     STTBX_Print(("n"));
  741.     /* display the first few bytes of each section */
  742.     for ( Section = 0; Section < NUM_SECTIONS; Section ++ )
  743.     {
  744.         if ( SectionInfo[Section].Block != 0xFF )
  745.         {
  746.             STTBX_Print(("Section %2d, Block %3d, Addr 0x%08x, Offset 0x%08x, Size %6dn",
  747.                          Section,
  748.                          SectionInfo[Section].Block,
  749.                          SectionInfo[Section].Address,
  750.                          SectionInfo[Section].Offset,
  751.                          SectionInfo[Section].Size ));
  752.             #ifdef DEBUG_INFO
  753.                 for ( InOffset = 0;
  754.                       ( InOffset < 32 ) && ( InOffset < SectionInfo[Section].Size );
  755.                       InOffset ++ )
  756.                 {
  757.                     STTBX_Print((" %02x", FlashData_p[ SectionInfo[Section].Offset + InOffset ] ));
  758.                 }
  759.                 STTBX_Print(("n"));
  760.             #endif
  761.         }
  762.     }
  763.     return ( OutOffset );
  764. } /* end wts_ConvertMemory */
  765. #if 0 /*def rayf*/
  766. /*-------------------------------------------------------------------------
  767.  * Function : ReadFile
  768.  *            Read HEX file into memory
  769.  * Input    :
  770.  * Output   :
  771.  * Return   : File size
  772.  * ----------------------------------------------------------------------*/
  773. U32 wts_FLASH_ReadFile( char *Filename )
  774. {
  775. long int    ReadFile_p=0;            /* datafile descriptor          */
  776. long int    FileSize=0;          /* size in bytes of the file    */
  777. int            nameLength ;
  778.   nameLength = strlen( Filename ) ;
  779.   if (Filename[nameLength-1]=='n' &&
  780.     Filename[nameLength-2]=='i' &&
  781.     Filename[nameLength-3]=='b' &&
  782.     Filename[nameLength-4]=='.' ) {
  783.     binFile = TRUE ;
  784.   } else {
  785.     binFile = FALSE ;
  786.   }
  787.     /* Open and Read file into memory */
  788.     ReadFile_p = debugopen(Filename, "rb");
  789.     STTBX_Print(("ReadFile_p = 0x%8xn",ReadFile_p));
  790.     
  791.     if(ReadFile_p < 0)
  792.     {
  793.         STTBX_Print(("Error opening file '%s'n", Filename ));
  794.         return (0);
  795.     }
  796.     else
  797.     {
  798.         FileSize = debugfilesize(ReadFile_p);
  799.         STTBX_Print(("FileSize = 0x%8xn",FileSize));
  800.         /* allocate File data buffer */
  801.         wts_FreeFileDataBuffer();
  802.         FlashData_p = (char*) memory_allocate( SystemPartition, (U32) FileSize );
  803.         if ( FlashData_p != NULL )
  804.         {
  805.             STTBX_Print(("Loading '%s' into memory, wait .. ", Filename ));
  806.             debugread(ReadFile_p, FlashData_p, (size_t) FileSize);
  807.             STTBX_Print(("%d bytesn", FileSize ));
  808.         }
  809.         else
  810.         {
  811.             STTBX_Print(("Not enough memory for HEX file (%d bytes)n", FileSize));
  812.             FileSize = 0;
  813.         }
  814.         debugclose(ReadFile_p);
  815.     }
  816.     if ( FileSize > 0 )
  817.     {
  818.         /* convert buffer to binary and resize memory */
  819.         STTBX_Print(("Converting file in memory, wait .. "));
  820. if(binFile)
  821. FlashSize = (U32)FileSize;
  822. else
  823. FlashSize = wts_ConvertMemory( FileSize );
  824.         if ( FlashSize > 0 )
  825.         {
  826.             STTBX_Print(("%d bytesn", FlashSize ));
  827.             FlashData_p = (char*) memory_reallocate( SystemPartition, FlashData_p, FlashSize );
  828.         }
  829.         else
  830.             STTBX_Print(("Invalid filen"));
  831.     }
  832.     return( FlashSize );
  833. } /* end of wts_FLASH_ReadFile */
  834. #else
  835. /*-------------------------------------------------------------------------
  836.  * Function : ReadFile
  837.  *            Read HEX file into memory
  838.  * Input    :
  839.  * Output   :
  840.  * Return   : File size
  841.  * ----------------------------------------------------------------------*/
  842. U32 wts_FLASH_ReadFile( char *Filename )
  843. {
  844.     long int    HexFile_p=0;            /* datafile descriptor          */
  845.     long int    HexFileSize=0;          /* size in bytes of the file    */
  846.     /* Open and Read file into memory */
  847.     HexFile_p = debugopen(Filename, "rb");
  848.     STTBX_Print(("HexFile_p = 0x%8xn",HexFile_p));
  849.     
  850.     if(HexFile_p < 0)
  851.     {
  852.         STTBX_Print(("Error opening file '%s'n", Filename ));
  853.         return (0);
  854.     }
  855.     else
  856.     {
  857.         HexFileSize = debugfilesize(HexFile_p);
  858.         STTBX_Print(("HexFileSize = 0x%8xn",HexFileSize));
  859.         /* allocate File data buffer */
  860.         wts_FreeFileDataBuffer();
  861.         FlashData_p = (char*) memory_allocate( SystemPartition, (U32) HexFileSize );
  862.         if ( FlashData_p != NULL )
  863.         {
  864.             STTBX_Print(("Loading '%s' into memory, wait .. ", Filename ));
  865.             debugread(HexFile_p, FlashData_p, (size_t) HexFileSize);
  866.             STTBX_Print(("%d bytesn", HexFileSize ));
  867.         }
  868.         else
  869.         {
  870.             STTBX_Print(("Not enough memory for HEX file (%d bytes)n", HexFileSize));
  871.             HexFileSize = 0;
  872.         }
  873.         debugclose(HexFile_p);
  874.     }
  875.     if ( HexFileSize > 0 )
  876.     {
  877.         /* convert buffer to binary and resize memory */
  878.         STTBX_Print(("Converting file in memory, wait .. "));
  879.         FlashSize = wts_ConvertMemory( HexFileSize );
  880.         if ( FlashSize > 0 )
  881.         {
  882.             STTBX_Print(("%d bytesn", FlashSize ));
  883.             FlashData_p = (char*) memory_reallocate( SystemPartition, FlashData_p, FlashSize );
  884.         }
  885.         else
  886.             STTBX_Print(("Invalid filen"));
  887.     }
  888.     return( FlashSize );
  889. } /* end of wts_FLASH_ReadFile */
  890. #endif
  891. /*-------------------------------------------------------------------------
  892.  * Function : wts_EraseFlash
  893.  *            Function to Read Hex file and erase areas required
  894.  * Input    : EraseAll 
  895.  * Output   :
  896.  * Return   : EraseFailed = TRUE else FALSE
  897.  * ----------------------------------------------------------------------*/
  898. BOOL wts_EraseFlash( BOOL EraseAll )
  899. {
  900.     ST_ErrorCode_t ErrCode = ST_NO_ERROR;
  901.     U8   Section, Bank;
  902.     U32  EraseOffset;
  903.     BOOL EraseFailed = TRUE;
  904.     /* check data size */
  905.     if (( FlashSize != 0 ) || EraseAll )
  906.     {
  907.         EraseFailed = FALSE;
  908.         STTBX_Print(("tt+------------+------------+n"));
  909.         if ( EraseAll )
  910.         {
  911.             for ( /*Section = 0*/Section = 0;( Section < TOTAL_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
  912.             {
  913.                 Bank = BlockInfo[Section].Bank;
  914.                 EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
  915.                 STTBX_Print(("%d block %2dt| 0x%08x | 0x%08x | ",
  916.                              Bank, Section,
  917.                              BlockInfo[Section].Address,
  918.                              BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
  919.                 ErrCode = STFLASH_Erase( wts_FLASHHndl[Bank],
  920.                                          EraseOffset,
  921.                                          BlockInfo[Section].Length );
  922.                 if ( ErrCode != ST_NO_ERROR )
  923.                 {
  924.                     STTBX_Print(("Erase FAILEDn"));
  925.                     EraseFailed = TRUE;
  926.                 }
  927.                 else
  928.                     STTBX_Print(("ERASEDn"));
  929.             }
  930.         }
  931.         else
  932.         {
  933.             /* Find out which blocks are to be Erased */
  934.             for ( /*Section = 0*/Section = 0; ( Section < NUM_SECTIONS ) && ( EraseFailed == FALSE ); Section ++ )
  935.             {
  936.                 if ( SectionInfo[Section].Block != 0xFF )
  937.                 {
  938.                     /*
  939.                     ** Erase = erase whole block, valid parameters are block base address & block size
  940.                     */
  941.                     Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  942.                     EraseOffset = BlockInfo[ SectionInfo[Section].Block ].Address - BaseAddress[Bank];
  943.                     STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  944.                                  SectionInfo[Section].Block,
  945.                                  BlockInfo[ SectionInfo[Section].Block ].Address,
  946.                                  BlockInfo[ SectionInfo[Section].Block ].Address +
  947.                                  BlockInfo[ SectionInfo[Section].Block ].Length - 1 ));
  948.                                  
  949.                     ErrCode = STFLASH_Erase( wts_FLASHHndl[Bank],
  950.                                              EraseOffset,
  951.                                              BlockInfo[ SectionInfo[Section].Block ].Length );
  952.                     if ( ErrCode != ST_NO_ERROR )
  953.                     {
  954.                         STTBX_Print(("ErrCode = 0x%8xn",ErrCode));
  955.                         STTBX_Print(("Erase FAILEDn"));
  956.                         STTBX_Print(("wts_FLASHHndl[Bank] = 0x%8Xn",wts_FLASHHndl[Bank]));
  957.                         EraseFailed = TRUE;
  958.                     }
  959.                     else
  960.                         STTBX_Print(("ERASEDn"));
  961.                 }
  962.             }
  963.         }
  964.         STTBX_Print(("tt+------------+------------+n"));
  965.     }
  966.     if ( EraseFailed == TRUE )
  967.     {
  968.         wts_FreeFileDataBuffer();
  969.         STTBX_Print(("!!!! ERASE Failed !!!!n"));
  970.         return TRUE;
  971.     }
  972.     return EraseFailed;
  973. } /* end wts_ProgramFlash */
  974. /*-------------------------------------------------------------------------
  975.  * Function : wts_ProgramFlash
  976.  *            Function to Read Hex file and program flash with contents
  977.  * Input    :
  978.  * Output   :
  979.  * Return   : None
  980.  * ----------------------------------------------------------------------*/
  981. BOOL wts_ProgramFlash( void )
  982. {
  983.     ST_ErrorCode_t      ErrCode;
  984.     int                 Section, Bank;
  985.     U32                 NumberOfBytes;
  986.     BOOL                ProgramFailed;
  987.     /* check data size */
  988.     if ( FlashSize == 0 )
  989.         ProgramFailed = TRUE;
  990.     else
  991.     {
  992.         ProgramFailed = FALSE;
  993.         STTBX_Print(("tt+------------+------------+n"));
  994.     }
  995.     /* Find out which blocks are to be written to */
  996.     /* Write the data to the Flash */
  997.     /*STTBX_Print(("Printing the contents of BlockInfo n"));
  998.     for ( Section = 0; ( Section < NUM_SECTIONS ) ; Section ++ )
  999.     {
  1000.         STTBX_Print(("Section=%dt", Section ));
  1001.         STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  1002.         STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  1003.         STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  1004.     }*/
  1005.     for ( Section = 0; ( Section < NUM_SECTIONS ) && ( ProgramFailed == FALSE ); Section ++ )
  1006.     {
  1007.         if ( SectionInfo[Section].Block != 0xFF )
  1008.         {
  1009.             U32  WriteOffset;
  1010.             /*
  1011.             ** Write = write bytes from Offset
  1012.             */
  1013.             Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  1014.             STTBX_Print(("Section=%dt", Section ));
  1015.             STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  1016.             STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  1017.             STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  1018.             WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
  1019.             /*SectionInfo[Section].Address += 0x4; Tara*/
  1020.             STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  1021.                          SectionInfo[Section].Block,
  1022.                          SectionInfo[Section].Address,
  1023.                          SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
  1024.             ErrCode = STFLASH_Write( wts_FLASHHndl[Bank],
  1025.                                      WriteOffset,
  1026.                                      (U8*)&FlashData_p[SectionInfo[Section].Offset],
  1027.                                      SectionInfo[Section].Size,
  1028.                                      &NumberOfBytes );
  1029.             if ( ErrCode != ST_NO_ERROR )
  1030.             {
  1031.                 STTBX_Print(("Program FAILEDn"));
  1032.                 ProgramFailed = TRUE;
  1033.             }
  1034.             else
  1035.                 STTBX_Print(("PROGRAMMEDn"));
  1036.         }
  1037.     }
  1038.     if ( ProgramFailed == TRUE )
  1039.     {
  1040.         wts_FreeFileDataBuffer();
  1041.         STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
  1042.         return TRUE;
  1043.     }
  1044.     else
  1045.     {
  1046.         STTBX_Print(("tt+------------+------------+n"));
  1047.         return FALSE;
  1048.     }
  1049. } /* end wts_ProgramFlash */
  1050. /*-------------------------------------------------------------------------
  1051.  * Function : wts_ProgramFlash
  1052.  *            Function to Read Hex file and program flash with contents
  1053.  * Input    :
  1054.  * Output   :
  1055.  * Return   : None
  1056.  * ----------------------------------------------------------------------*/
  1057. BOOL wts_BinProgramFlash( void )
  1058. {
  1059.     ST_ErrorCode_t      ErrCode;
  1060.     int                 Section, Bank=0;
  1061.     U32                 NumberOfBytes;
  1062.     BOOL                ProgramFailed;
  1063. U32 FlashOffset=0;
  1064.     /* check data size */
  1065.     if ( FlashSize == 0 )
  1066.         ProgramFailed = TRUE;
  1067.     else
  1068.     {
  1069.         ProgramFailed = FALSE;
  1070.         STTBX_Print(("tt+------------+------------+n"));
  1071.     }
  1072. if(binFile){
  1073. ErrCode = STFLASH_Write( wts_FLASHHndl[Bank],
  1074.                                      FlashOffset,
  1075.                                      (U8*)&FlashData_p,
  1076.                                      FlashSize,
  1077.                                      &NumberOfBytes );
  1078.             if ( ErrCode != ST_NO_ERROR )
  1079.             {
  1080.                 STTBX_Print(("Program FAILEDn"));
  1081.                 ProgramFailed = TRUE;
  1082.             }
  1083.             else
  1084.                 STTBX_Print(("PROGRAMMEDn"));
  1085. }
  1086. else{
  1087.     for ( Section = 0; ( Section < NUM_SECTIONS ) && ( ProgramFailed == FALSE ); Section ++ )
  1088.     {
  1089.         if ( SectionInfo[Section].Block != 0xFF )
  1090.         {
  1091.             U32  WriteOffset;
  1092.             /*
  1093.             ** Write = write bytes from Offset
  1094.             */
  1095.             Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  1096.             STTBX_Print(("Section=%dt", Section ));
  1097.             STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  1098.             STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  1099.             STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  1100.             WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
  1101.             /*SectionInfo[Section].Address += 0x4; Tara*/
  1102.             STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  1103.                          SectionInfo[Section].Block,
  1104.                          SectionInfo[Section].Address,
  1105.                          SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
  1106.             ErrCode = STFLASH_Write( wts_FLASHHndl[Bank],
  1107.                                      WriteOffset,
  1108.                                      (U8*)&FlashData_p[SectionInfo[Section].Offset],
  1109.                                      SectionInfo[Section].Size,
  1110.                                      &NumberOfBytes );
  1111.             if ( ErrCode != ST_NO_ERROR )
  1112.             {
  1113.                 STTBX_Print(("Program FAILEDn"));
  1114.                 ProgramFailed = TRUE;
  1115.             }
  1116.             else
  1117.                 STTBX_Print(("PROGRAMMEDn"));
  1118.         }
  1119.     }
  1120. }
  1121.     if ( ProgramFailed == TRUE )
  1122.     {
  1123.         wts_FreeFileDataBuffer();
  1124.         STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
  1125.         return TRUE;
  1126.     }
  1127.     else
  1128.     {
  1129.         STTBX_Print(("tt+------------+------------+n"));
  1130.         return FALSE;
  1131.     }
  1132. } /* end wts_ProgramFlash */
  1133. /*-------------------------------------------------------------------------
  1134.  * Function : wts_VerifyFlash
  1135.  *            Function to Read Hex file and verify flash with contents
  1136.  * Input    :
  1137.  * Output   :
  1138.  * Return   : None
  1139.  * ----------------------------------------------------------------------*/
  1140. BOOL wts_VerifyFlash( void )
  1141. {
  1142.     ST_ErrorCode_t      ErrCode = ST_NO_ERROR;
  1143.     int                 Section, Bank;
  1144.     U32                 Length;
  1145.     U32                 ReadOffset;
  1146.     U32                 NumberOfBytes;
  1147.     U8                  *Buffer_p;
  1148.     BOOL                VerifyFailed;
  1149.     /* check data size */
  1150.     if ( FlashSize == 0 )
  1151.         VerifyFailed = TRUE;
  1152.     else
  1153.     {
  1154.         VerifyFailed = FALSE;
  1155.         STTBX_Print(("tt+------------+------------+n"));
  1156.     }
  1157.     /* Find out which blocks are to be verified */
  1158.     /* Read the data and compare */
  1159.     for ( /*Section = 0*/Section = 0; ( Section < NUM_SECTIONS ) && ( VerifyFailed == FALSE ); Section ++ )
  1160.     {
  1161.         if ( SectionInfo[Section].Block != 0xFF )
  1162.         {
  1163.             Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  1164.             Length = BlockInfo[ SectionInfo[Section].Block ].Length;
  1165.             ReadOffset = SectionInfo[Section].Address - BaseAddress[Bank];
  1166.             /* allocate temp buffer to put flash data in */
  1167.             Buffer_p = memory_allocate( SystemPartition, Length );
  1168.             if ( Buffer_p != NULL )
  1169.             {
  1170.                 STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  1171.                          SectionInfo[Section].Block,
  1172.                          SectionInfo[Section].Address,
  1173.                          SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
  1174.                 ErrCode = STFLASH_Read( wts_FLASHHndl[Bank],
  1175.                                         ReadOffset,
  1176.                                         Buffer_p,
  1177.                                         SectionInfo[Section].Size,
  1178.                                         &NumberOfBytes );
  1179.                 if(ErrCode != ST_NO_ERROR)
  1180.                 {
  1181.                     STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
  1182.                 }
  1183.                 if ( memcmp( Buffer_p,(U8*)&FlashData_p[SectionInfo[Section].Offset],
  1184.                              SectionInfo[Section].Size ) != 0 )
  1185.                 {
  1186.                     STTBX_Print(("Verify FAILEDn"));
  1187.                     VerifyFailed = TRUE;
  1188.                 }
  1189.                 else
  1190.                     STTBX_Print(("VERIFIEDn"));
  1191.                 /* deallocate temp buffer */
  1192.                 memory_deallocate( SystemPartition, Buffer_p );
  1193.             }
  1194.         }
  1195.     }
  1196.     wts_FreeFileDataBuffer();
  1197.     
  1198.     if ( VerifyFailed == TRUE )
  1199.     {
  1200.         STTBX_Print(("!!!! VERIFY Failed !!!!n"));
  1201.         return TRUE;
  1202.     }
  1203.     else
  1204.     {
  1205.         STTBX_Print(("tt+------------+------------+n"));
  1206.         return FALSE;
  1207.     }
  1208. } /* end wts_VerifyFlash */
  1209. #ifdef rayf
  1210. BOOL wts_ReadProgram(char *Filename ,U32 StartAddress ,U32 Length )
  1211. {
  1212.     ST_ErrorCode_t      ErrCode = ST_NO_ERROR;
  1213.     int                 Section, Bank;
  1214.     U32                 ReadOffset;
  1215.     U32                 NumberOfBytes;
  1216.     U8                  *Buffer_p;
  1217.     int            nameLength,numBytes ;
  1218.     long int    ReadFile_p=0;            /* datafile descriptor          */
  1219.   volatile char    *ptr_to_m;
  1220.   nameLength = strlen( Filename ) ;
  1221.   if (Filename[nameLength-1]=='n' &&
  1222.     Filename[nameLength-2]=='i' &&
  1223.     Filename[nameLength-3]=='b' &&
  1224.     Filename[nameLength-4]=='.' ) {
  1225.     binFile = TRUE ;
  1226.     ReadFile_p = debugopen(Filename, "wb");
  1227.   } else {
  1228.    Filename[nameLength  ]= '.' ;
  1229.     Filename[nameLength+1]= 'b' ;
  1230.     Filename[nameLength+2]= 'i' ;
  1231.     Filename[nameLength+3]= 'n' ;
  1232.     binFile = FALSE ;
  1233.     ReadFile_p = debugopen(Filename, "wb");
  1234.   }
  1235.   if (ReadFile_p<=0) {
  1236.         STTBX_Print(("nCannot Create data file '%s'n", Filename ));
  1237.         return FALSE;
  1238.   }
  1239.     /* Read the data and compare */
  1240.             Bank = BlockInfo[ SectionInfo[0].Block ].Bank;
  1241.             ReadOffset = StartAddress - BaseAddress[Bank];
  1242.             /* allocate temp buffer to put flash data in */
  1243.             Buffer_p = memory_allocate( SystemPartition, Length );
  1244.             if ( Buffer_p != NULL )
  1245.             {
  1246.                 STTBX_Print(("Address t| 0x%08x | 0x%08x |ReadOffset = 0x%08x |n ",
  1247.                          StartAddress,
  1248.                          StartAddress + Length-1,
  1249.                          ReadOffset));
  1250.                 ErrCode = STFLASH_Read( wts_FLASHHndl[Bank],
  1251.                                         ReadOffset,
  1252.                                         Buffer_p,
  1253.                                         Length,
  1254.                                         &NumberOfBytes );
  1255.                 if(ErrCode != ST_NO_ERROR)
  1256.                 {
  1257.                     STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
  1258.                     return FALSE;
  1259.                 }
  1260.          numBytes = (int) debugwrite( (long int)ReadFile_p, (void*)Buffer_p, Length);
  1261.                STTBX_Print(("write file size  = %d bytesn", numBytes ));
  1262. #if 0
  1263.   /* ===================== check whether array is erased================== */
  1264.   ptr_to_m = (char *)0x40000000;           /* point to lowest _add in FlashROM     */
  1265.   *ptr_to_m = (char) 0xf0f0;         /* read_array command                   */
  1266.     for(ptr_to_m = (char *)0x40000000;      /* point to flash_start and change type */
  1267.        ptr_to_m < (char *)0x40200000;     /* point to flash_end and change type   */
  1268.        ptr_to_m++,Buffer_p++) {                    /* inc pointer                          */
  1269.        *Buffer_p =  *ptr_to_m;
  1270.          if (*ptr_to_m != *Buffer_p){             /* check all bits are set to 1          */
  1271.             debugmessage("ROMTOOL>  ERROR!!! EPROM not erased properlyn");
  1272.             return 0;
  1273.             }
  1274.        }
  1275.   
  1276.   /* ===================== check whether array is erased================== */
  1277.          numBytes = (int) debugwrite( (long int)ReadFile_p, (U8 *)Buffer_p, Length);
  1278.                STTBX_Print(("write file size  = %d bytesn", numBytes ));
  1279. #endif
  1280.                 /* deallocate temp buffer */
  1281.                 memory_deallocate( SystemPartition, Buffer_p );
  1282.             }
  1283.         STTBX_Print(("!!!! Read file successfully!!!!n"));
  1284.         return TRUE;
  1285. }
  1286. BOOL wts_EraseLogoFlash( BOOL Erase )
  1287. {
  1288.     ST_ErrorCode_t ErrCode = ST_NO_ERROR;
  1289.     U8   Section, Bank;
  1290.     U32  EraseOffset;
  1291.     BOOL EraseFailed = TRUE;
  1292.     /* check data size */
  1293.     if ( Erase )
  1294.     {
  1295.         EraseFailed = FALSE;
  1296.         STTBX_Print(("tt+------------+------------+n"));
  1297.         if ( Erase )
  1298.         {
  1299.             for ( Section = FIRST_LOGO_BLOCK;( Section < FIRST_LOGO_BLOCK+LOGO_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
  1300.             {
  1301.                 Bank = BlockInfo[Section].Bank;
  1302. #ifdef DEBUG
  1303.                 STTBX_Print(("tBaseAddress[Bank]=0x%08x n",BaseAddress[Bank]));
  1304.                 STTBX_Print(("tBlockInfo[Section].Address=0x%08x n",BlockInfo[Section].Address));
  1305. #endif
  1306.                 EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
  1307.                 STTBX_Print(("bank %d block %2dt| 0x%08x | 0x%08x | ",
  1308.                              Bank, Section,
  1309.                              BlockInfo[Section].Address,
  1310.                              BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
  1311.                 ErrCode = STFLASH_Erase( wts_FLASHHndl[Bank],
  1312.                                          EraseOffset,
  1313.                                          BlockInfo[Section].Length );
  1314.                 if ( ErrCode != ST_NO_ERROR )
  1315.                 {
  1316.                     STTBX_Print(("Erase FAILEDn"));
  1317.                     EraseFailed = TRUE;
  1318.                 }
  1319.                 else
  1320.                     STTBX_Print(("ERASEDn"));
  1321.             }
  1322.         }
  1323.         
  1324.         STTBX_Print(("tt+------------+------------+n"));
  1325.     }
  1326.     if ( EraseFailed == TRUE )
  1327.     {
  1328.         wts_FreeFileDataBuffer();
  1329.         STTBX_Print(("!!!! ERASE Failed !!!!n"));
  1330.         return TRUE;
  1331.     }
  1332.     return EraseFailed;
  1333. }
  1334. BOOL wts_EraseLanguageFlash( BOOL Erase )
  1335. {
  1336.     ST_ErrorCode_t ErrCode = ST_NO_ERROR;
  1337.     U8   Section, Bank;
  1338.     U32  EraseOffset;
  1339.     BOOL EraseFailed = TRUE;
  1340.     /* check data size */
  1341.     if ( Erase )
  1342.     {
  1343.         EraseFailed = FALSE;
  1344.         STTBX_Print(("tt+------------+------------+n"));
  1345.         if ( Erase )
  1346.         {
  1347.             for ( Section = FIRST_LANG_BLOCK;( Section < FIRST_LANG_BLOCK+LANG_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
  1348.             {
  1349.                 Bank = BlockInfo[Section].Bank;
  1350. #ifdef DEBUG
  1351.                 STTBX_Print(("tBaseAddress[Bank]=0x%08x n",BaseAddress[Bank]));
  1352.                 STTBX_Print(("tBlockInfo[Section].Address=0x%08x n",BlockInfo[Section].Address));
  1353. #endif
  1354.                 EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
  1355.                 STTBX_Print(("bank %d block %2dt| 0x%08x | 0x%08x | ",
  1356.                              Bank, Section,
  1357.                              BlockInfo[Section].Address,
  1358.                              BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
  1359.                 ErrCode = STFLASH_Erase( wts_FLASHHndl[Bank],
  1360.                                          EraseOffset,
  1361.                                          BlockInfo[Section].Length );
  1362.                 if ( ErrCode != ST_NO_ERROR )
  1363.                 {
  1364.                     STTBX_Print(("Erase FAILEDn"));
  1365.                     EraseFailed = TRUE;
  1366.                 }
  1367.                 else
  1368.                     STTBX_Print(("ERASEDn"));
  1369.             }
  1370.         }
  1371.         
  1372.         STTBX_Print(("tt+------------+------------+n"));
  1373.     }
  1374.     if ( EraseFailed == TRUE )
  1375.     {
  1376.         wts_FreeFileDataBuffer();
  1377.         STTBX_Print(("!!!! ERASE Failed !!!!n"));
  1378.         return TRUE;
  1379.     }
  1380.     return EraseFailed;
  1381. }
  1382. /*-------------------------------------------------------------------------
  1383.  * Function : wts_EraseLNBFlash
  1384.  *            Function to Read Hex file and erase areas required
  1385.  * Input    : EraselLNB 
  1386.  * Output   :
  1387.  * Return   : EraseFailed = TRUE else FALSE
  1388.  * ----------------------------------------------------------------------*/
  1389. BOOL wts_EraseLNBFlash( BOOL Erase )
  1390. {
  1391.     ST_ErrorCode_t ErrCode = ST_NO_ERROR;
  1392.     U8   Section, Bank;
  1393.     U32  EraseOffset;
  1394.     BOOL EraseFailed = TRUE;
  1395.     /* check data size */
  1396.     if ( Erase )
  1397.     {
  1398.         EraseFailed = FALSE;
  1399.         STTBX_Print(("tt+------------+------------+n"));
  1400.         if ( Erase )
  1401.         {
  1402.             for ( Section = FIRST_LNB_BLOCK;( Section < FIRST_LNB_BLOCK+LNB_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
  1403.             {
  1404.                 Bank = BlockInfo[Section].Bank;
  1405. #ifdef DEBUG
  1406.                 STTBX_Print(("tBaseAddress[Bank]=0x%08x n",BaseAddress[Bank]));
  1407.                 STTBX_Print(("tBlockInfo[Section].Address=0x%08x n",BlockInfo[Section].Address));
  1408. #endif
  1409.                 EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
  1410.                 STTBX_Print(("bank %d block %2dt| 0x%08x | 0x%08x | ",
  1411.                              Bank, Section,
  1412.                              BlockInfo[Section].Address,
  1413.                              BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
  1414.                 ErrCode = STFLASH_Erase( wts_FLASHHndl[Bank],
  1415.                                          EraseOffset,
  1416.                                          BlockInfo[Section].Length );
  1417.                 if ( ErrCode != ST_NO_ERROR )
  1418.                 {
  1419.                     STTBX_Print(("Erase FAILEDn"));
  1420.                     EraseFailed = TRUE;
  1421.                 }
  1422.                 else
  1423.                     STTBX_Print(("ERASEDn"));
  1424.             }
  1425.         }
  1426.         
  1427.         STTBX_Print(("tt+------------+------------+n"));
  1428.     }
  1429.     if ( EraseFailed == TRUE )
  1430.     {
  1431.         wts_FreeFileDataBuffer();
  1432.         STTBX_Print(("!!!! ERASE Failed !!!!n"));
  1433.         return TRUE;
  1434.     }
  1435.     return EraseFailed;
  1436. } /* end wts_ProgramFlash */
  1437. /*-------------------------------------------------------------------------
  1438.  * Function : wts_EraseCodeFlash
  1439.  *            Function to Read Hex file and erase areas required
  1440.  * Input    : EraseCode 
  1441.  * Output   :
  1442.  * Return   : EraseFailed = TRUE else FALSE
  1443.  * ----------------------------------------------------------------------*/
  1444. BOOL wts_EraseCodeFlash( BOOL EraseCode )
  1445. {
  1446.     ST_ErrorCode_t ErrCode = ST_NO_ERROR;
  1447.     U8   Section, Bank;
  1448.     U32  EraseOffset;
  1449.     BOOL EraseFailed = TRUE;
  1450.     /* check data size */
  1451.     if ( EraseCode )
  1452.     {
  1453.         EraseFailed = FALSE;
  1454.         STTBX_Print(("tt+------------+------------+n"));
  1455.         if ( EraseCode )
  1456.         {
  1457.             for ( Section = FIRST_CODE_BLOCK;( Section < FIRST_CODE_BLOCK+CODE_BLOCKS ) && ( ErrCode == ST_NO_ERROR ); Section ++)
  1458.             {
  1459.                 Bank = BlockInfo[Section].Bank;
  1460. #ifdef DEBUG
  1461.                 STTBX_Print(("tBaseAddress[Bank]=0x%08x n",BaseAddress[Bank]));
  1462.                 STTBX_Print(("tBlockInfo[Section].Address=0x%08x n",BlockInfo[Section].Address));
  1463. #endif
  1464.                 EraseOffset = BlockInfo[Section].Address - BaseAddress[Bank];
  1465.                 STTBX_Print(("bank %d block %2dt| 0x%08x | 0x%08x | ",
  1466.                              Bank, Section,
  1467.                              BlockInfo[Section].Address,
  1468.                              BlockInfo[Section].Address + BlockInfo[Section].Length - 1 ));
  1469.                 ErrCode = STFLASH_Erase( wts_FLASHHndl[Bank],
  1470.                                          EraseOffset,
  1471.                                          BlockInfo[Section].Length );
  1472.                 if ( ErrCode != ST_NO_ERROR )
  1473.                 {
  1474.                     STTBX_Print(("Erase FAILEDn"));
  1475.                     EraseFailed = TRUE;
  1476.                 }
  1477.                 else
  1478.                     STTBX_Print(("ERASEDn"));
  1479.             }
  1480.         }
  1481.         
  1482.         STTBX_Print(("tt+------------+------------+n"));
  1483.     }
  1484.     if ( EraseFailed == TRUE )
  1485.     {
  1486.         wts_FreeFileDataBuffer();
  1487.         STTBX_Print(("!!!! ERASE Failed !!!!n"));
  1488.         return TRUE;
  1489.     }
  1490.     return EraseFailed;
  1491. } /* end wts_ProgramFlash */
  1492. /*-------------------------------------------------------------------------
  1493.  * Function : wts_ConvertMemory
  1494.  *            Convert Raw Hex file into memory buffer suitable to write to
  1495.  *            flash copying created data over data read from filem, the
  1496.  *            created data will be smaller as each byte takes three bytes
  1497.  *            in the Hex file.
  1498.  * Input    :
  1499.  * Output   :
  1500.  * Return   : size of data in buffer
  1501.  * ----------------------------------------------------------------------*/
  1502. static U32 wts_LogoConvertMemory( long unsigned int MemSize )
  1503. {
  1504.     int                 Section;
  1505.     U32                 InOffset;
  1506.     
  1507.     for ( Section = 31; Section < NUM_SECTIONS; Section ++ )
  1508.     {
  1509.         SectionInfo[Section].Block = 0xff;
  1510.         SectionInfo[Section].Address = 0;
  1511.         SectionInfo[Section].Offset = 0;
  1512.         SectionInfo[Section].Size = 0;
  1513.     }
  1514.     /* Convert File */
  1515.     Section = 31;
  1516.     
  1517.     for ( InOffset = 0;InOffset < MemSize; )
  1518.     {
  1519. InOffset += 0x8000;
  1520. if(InOffset < MemSize){
  1521. SectionInfo[Section].Address = wtFlashBankBaseAddr + 0x10000*Section;
  1522. SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
  1523. SectionInfo[Section].Offset = InOffset - 0x8000; /*0x10000*Section;*/
  1524. SectionInfo[Section].Size = 0x8000;
  1525. }
  1526. else{
  1527. SectionInfo[Section].Address = wtFlashBankBaseAddr + 0x10000*Section;
  1528. SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
  1529. SectionInfo[Section].Offset = InOffset - 0x8000; /*0x10000*Section;*/
  1530. SectionInfo[Section].Size = MemSize - (InOffset - 0x8000);
  1531. }
  1532.        STTBX_Print(("Section %2d, Block %3d, Addr 0x%08x, Offset 0x%08x, Size %6dn",
  1533.                          Section,
  1534.                          SectionInfo[Section].Block,
  1535.                          SectionInfo[Section].Address,
  1536.                          SectionInfo[Section].Offset,
  1537.                          SectionInfo[Section].Size ));
  1538. Section++;
  1539.     }
  1540. return MemSize;
  1541. } /* end wts_ConvertMemory */
  1542. BOOL wts_ProgramLogoFlash( void)
  1543. {
  1544.     ST_ErrorCode_t      ErrCode;
  1545.     long int    File_p=0;            /* datafile descriptor          */
  1546.     long int    FileSize=0;          /* size in bytes of the file    */
  1547.     BOOL                ProgramFailed;
  1548.     U32                 NumberOfBytes;
  1549.     int                 Section, Bank;
  1550.     U32  EraseOffset;
  1551.     BOOL EraseFailed = FALSE;
  1552. char Filename[] = "logo.bin";
  1553.     U32  EarLength = 0x5000;
  1554.     U32  WriteOffset =  0x401F0000;
  1555.     /* Open and Read file into memory */
  1556.     File_p = debugopen(Filename, "rb");
  1557.     STTBX_Print(("File_p = 0x%8xn",File_p));
  1558.     
  1559.     if(File_p < 0)
  1560.     {
  1561.         STTBX_Print(("Error opening file '%s'n", Filename ));
  1562.         return (0);
  1563.     }
  1564.     else
  1565.     {
  1566.         FileSize = debugfilesize(File_p);
  1567.         STTBX_Print(("FileSize = 0x%8xn",FileSize));
  1568.         /* allocate File data buffer */
  1569.              STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
  1570.         wts_FreeFileDataBuffer();
  1571.               STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
  1572.        FlashData_p = (char*) memory_allocate( SystemPartition, (U32) FileSize );
  1573.                STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
  1574.       if ( FlashData_p != NULL )
  1575.         {
  1576.             STTBX_Print(("Loading '%s' into memory, wait .. ", Filename ));
  1577.             debugread(File_p, FlashData_p, (size_t) FileSize);
  1578.             STTBX_Print(("%d bytesn", FileSize ));
  1579.              STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
  1580.         }
  1581.         else
  1582.         {
  1583.             STTBX_Print(("Not enough memory for bin file (%d bytes)n", FileSize));
  1584.             FileSize = 0;
  1585.         }
  1586.         debugclose(File_p);
  1587.     }
  1588.     if ( FileSize > 0 )
  1589.     {
  1590.         /* convert buffer to binary and resize memory */
  1591.         STTBX_Print(("Converting file in memory, wait .. nn"));
  1592.         FlashSize = wts_LogoConvertMemory( FileSize );
  1593.         if ( FlashSize > 0 )
  1594.         {
  1595.             STTBX_Print(("%d bytesn", FlashSize ));
  1596.             FlashData_p = (char*) memory_reallocate( SystemPartition, FlashData_p, FlashSize );
  1597.         }
  1598.         else
  1599.             STTBX_Print(("Invalid filen"));
  1600.     }
  1601.             for ( Section = 31; ( Section < NUM_SECTIONS ) && ( EraseFailed == FALSE ); Section ++ )
  1602.             {
  1603.                 if ( SectionInfo[Section].Block != 0xFF )
  1604.                 {
  1605.                     /*
  1606.                     ** Erase = erase whole block, valid parameters are block base address & block size
  1607.                     */
  1608.                     Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  1609.                     EraseOffset = BlockInfo[ SectionInfo[Section].Block ].Address - BaseAddress[Bank];
  1610.                     STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  1611.                                  SectionInfo[Section].Block,
  1612.                                  BlockInfo[ SectionInfo[Section].Block ].Address,
  1613.                                  BlockInfo[ SectionInfo[Section].Block ].Address +
  1614.                                  BlockInfo[ SectionInfo[Section].Block ].Length - 1 ));
  1615.                                  
  1616.                     ErrCode = STFLASH_Erase( wts_FLASHHndl[Bank],
  1617.                                              EraseOffset,
  1618.                                              BlockInfo[ SectionInfo[Section].Block ].Length );
  1619.                     if ( ErrCode != ST_NO_ERROR )
  1620.                     {
  1621.                         STTBX_Print(("ErrCode = 0x%8xn",ErrCode));
  1622.                         STTBX_Print(("Erase FAILEDn"));
  1623.                         STTBX_Print(("wts_FLASHHndl[Bank] = 0x%8Xn",wts_FLASHHndl[Bank]));
  1624.                         EraseFailed = TRUE;
  1625.                     }
  1626.                     else
  1627.                         STTBX_Print(("ERASEDn"));
  1628.                 }
  1629.             }
  1630.  
  1631.     /* check data size */
  1632.     if ( FlashSize == 0 )
  1633.         ProgramFailed = TRUE;
  1634.     else
  1635.     {
  1636.         ProgramFailed = FALSE;
  1637.         STTBX_Print(("tt+------------+------------+n"));
  1638.     }
  1639.     /* Find out which blocks are to be written to */
  1640.     /* Write the data to the Flash */
  1641.     /*STTBX_Print(("Printing the contents of BlockInfo n"));
  1642.     for ( Section = 0; ( Section < NUM_SECTIONS ) ; Section ++ )
  1643.     {
  1644.         STTBX_Print(("Section=%dt", Section ));
  1645.         STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  1646.         STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  1647.         STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  1648.     }*/
  1649.     for ( Section = 31; ( Section < NUM_SECTIONS ) && ( ProgramFailed == FALSE ); Section ++ )
  1650.     {
  1651.         if ( SectionInfo[Section].Block != 0xFF )
  1652.         {
  1653.             /*
  1654.             ** Write = write bytes from Offset
  1655.             */
  1656.             Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  1657.             STTBX_Print(("Section=%dt", Section ));
  1658.             STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  1659.             STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  1660.             STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  1661.             WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
  1662.             /*SectionInfo[Section].Address += 0x4; Tara*/
  1663.             STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  1664.                          SectionInfo[Section].Block,
  1665.                          SectionInfo[Section].Address,
  1666.                          SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
  1667.             ErrCode = STFLASH_Write( wts_FLASHHndl[Bank],
  1668.                                      WriteOffset,
  1669.                                      (U8*)&FlashData_p[SectionInfo[Section].Offset],
  1670.                                      SectionInfo[Section].Size,
  1671.                                      &NumberOfBytes );
  1672.             if ( ErrCode != ST_NO_ERROR )
  1673.             {
  1674.                 STTBX_Print(("Program FAILEDn"));
  1675.                 ProgramFailed = TRUE;
  1676.             }
  1677.             else
  1678.                 STTBX_Print(("PROGRAMMEDn"));
  1679.         }
  1680.     }
  1681.     if ( ProgramFailed == TRUE )
  1682.     {
  1683.         wts_FreeFileDataBuffer();
  1684.         STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
  1685.         return TRUE;
  1686.     }
  1687.     else
  1688.     {
  1689.         STTBX_Print(("tt+------------+------------+n"));
  1690.         return FALSE;
  1691.     }
  1692. }
  1693. #if 1
  1694. /*-------------------------------------------------------------------------
  1695.  * Function : wts_ConvertMemory
  1696.  *            Convert Raw Hex file into memory buffer suitable to write to
  1697.  *            flash copying created data over data read from filem, the
  1698.  *            created data will be smaller as each byte takes three bytes
  1699.  *            in the Hex file.
  1700.  * Input    :
  1701.  * Output   :
  1702.  * Return   : size of data in buffer
  1703.  * ----------------------------------------------------------------------*/
  1704. static U32 wts_LangConvertMemory( long unsigned int MemSize )
  1705. {
  1706.     int                 Section;
  1707.     U32                 InOffset;
  1708.     
  1709.     for ( Section = 16; Section < NUM_SECTIONS; Section ++ )
  1710.     {
  1711.         SectionInfo[Section].Block = 0xff;
  1712.         SectionInfo[Section].Address = 0;
  1713.         SectionInfo[Section].Offset = 0;
  1714.         SectionInfo[Section].Size = 0;
  1715.     }
  1716.     /* Convert File */
  1717.     Section = 16;
  1718.     
  1719.     for ( InOffset = 0;InOffset < MemSize; )
  1720.     {
  1721. InOffset += 0x10000;
  1722. if(InOffset < MemSize){
  1723. SectionInfo[Section].Address = wtFlashBankBaseAddr + 0x10000*Section;
  1724. SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
  1725. SectionInfo[Section].Offset = InOffset - 0x10000; /*0x10000*Section;*/
  1726. SectionInfo[Section].Size = 0x10000;
  1727. }
  1728. else{
  1729. SectionInfo[Section].Address = wtFlashBankBaseAddr + 0x10000*Section;
  1730. SectionInfo[Section].Block = wts_GetBlockNumber(SectionInfo[Section].Address);
  1731. SectionInfo[Section].Offset = InOffset - 0x10000; /*0x10000*Section;*/
  1732. SectionInfo[Section].Size = MemSize - (InOffset - 0x10000);
  1733. }
  1734.        STTBX_Print(("Section %2d, Block %3d, Addr 0x%08x, Offset 0x%08x, Size %6dn",
  1735.                          Section,
  1736.                          SectionInfo[Section].Block,
  1737.                          SectionInfo[Section].Address,
  1738.                          SectionInfo[Section].Offset,
  1739.                          SectionInfo[Section].Size ));
  1740. Section++;
  1741.     }
  1742. return MemSize;
  1743. } /* end wts_ConvertMemory */
  1744. BOOL wts_ProgramLanguageFlash(  char *Filename )
  1745. {
  1746.     ST_ErrorCode_t      ErrCode;
  1747.     long int    File_p=0;            /* datafile descriptor          */
  1748.     long int    FileSize=0;          /* size in bytes of the file    */
  1749.     BOOL                ProgramFailed;
  1750.     U32                 NumberOfBytes;
  1751.     int                 Section, Bank;
  1752.     U32  EraseOffset;
  1753.     BOOL EraseFailed = FALSE;
  1754.     U32  EarLength = 0x80000;
  1755.     U32  WriteOffset =  0x40100000;
  1756.     /* Open and Read file into memory */
  1757.     File_p = debugopen(Filename, "rb");
  1758.     STTBX_Print(("File_p = 0x%8xn",File_p));
  1759.     
  1760.     if(File_p < 0)
  1761.     {
  1762.         STTBX_Print(("Error opening file '%s'n", Filename ));
  1763.         return (0);
  1764.     }
  1765.     else
  1766.     {
  1767.         FileSize = debugfilesize(File_p);
  1768.         STTBX_Print(("FileSize = 0x%8xn",FileSize));
  1769.         /* allocate File data buffer */
  1770.              STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
  1771.         wts_FreeFileDataBuffer();
  1772.               STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
  1773.        FlashData_p = (char*) memory_allocate( SystemPartition, (U32) FileSize );
  1774.                STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
  1775.       if ( FlashData_p != NULL )
  1776.         {
  1777.             STTBX_Print(("Loading '%s' into memory, wait .. ", Filename ));
  1778.             debugread(File_p, FlashData_p, (size_t) FileSize);
  1779.             STTBX_Print(("%d bytesn", FileSize ));
  1780.              STTBX_Print(("FlashData_p addr 0x%x ,FlashSize = %d !n",FlashData_p,FileSize));
  1781.         }
  1782.         else
  1783.         {
  1784.             STTBX_Print(("Not enough memory for bin file (%d bytes)n", FileSize));
  1785.             FileSize = 0;
  1786.         }
  1787.         debugclose(File_p);
  1788.     }
  1789.     if ( FileSize > 0 )
  1790.     {
  1791.         /* convert buffer to binary and resize memory */
  1792.         STTBX_Print(("Converting file in memory, wait .. nn"));
  1793.         FlashSize = wts_LangConvertMemory( FileSize );
  1794.         if ( FlashSize > 0 )
  1795.         {
  1796.             STTBX_Print(("%d bytesn", FlashSize ));
  1797.             FlashData_p = (char*) memory_reallocate( SystemPartition, FlashData_p, FlashSize );
  1798.         }
  1799.         else
  1800.             STTBX_Print(("Invalid filen"));
  1801.     }
  1802.             for ( Section = 16; ( Section < NUM_SECTIONS ) && ( EraseFailed == FALSE ); Section ++ )
  1803.             {
  1804.                 if ( SectionInfo[Section].Block != 0xFF )
  1805.                 {
  1806.                     /*
  1807.                     ** Erase = erase whole block, valid parameters are block base address & block size
  1808.                     */
  1809.                     Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  1810.                     EraseOffset = BlockInfo[ SectionInfo[Section].Block ].Address - BaseAddress[Bank];
  1811.                     STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  1812.                                  SectionInfo[Section].Block,
  1813.                                  BlockInfo[ SectionInfo[Section].Block ].Address,
  1814.                                  BlockInfo[ SectionInfo[Section].Block ].Address +
  1815.                                  BlockInfo[ SectionInfo[Section].Block ].Length - 1 ));
  1816.                                  
  1817.                     ErrCode = STFLASH_Erase( wts_FLASHHndl[Bank],
  1818.                                              EraseOffset,
  1819.                                              BlockInfo[ SectionInfo[Section].Block ].Length );
  1820.                     if ( ErrCode != ST_NO_ERROR )
  1821.                     {
  1822.                         STTBX_Print(("ErrCode = 0x%8xn",ErrCode));
  1823.                         STTBX_Print(("Erase FAILEDn"));
  1824.                         STTBX_Print(("wts_FLASHHndl[Bank] = 0x%8Xn",wts_FLASHHndl[Bank]));
  1825.                         EraseFailed = TRUE;
  1826.                     }
  1827.                     else
  1828.                         STTBX_Print(("ERASEDn"));
  1829.                 }
  1830.             }
  1831.  
  1832.     /* check data size */
  1833.     if ( FlashSize == 0 )
  1834.         ProgramFailed = TRUE;
  1835.     else
  1836.     {
  1837.         ProgramFailed = FALSE;
  1838.         STTBX_Print(("tt+------------+------------+n"));
  1839.     }
  1840.     /* Find out which blocks are to be written to */
  1841.     /* Write the data to the Flash */
  1842.     /*STTBX_Print(("Printing the contents of BlockInfo n"));
  1843.     for ( Section = 0; ( Section < NUM_SECTIONS ) ; Section ++ )
  1844.     {
  1845.         STTBX_Print(("Section=%dt", Section ));
  1846.         STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  1847.         STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  1848.         STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  1849.     }*/
  1850.     for ( Section = 16; ( Section < NUM_SECTIONS ) && ( ProgramFailed == FALSE ); Section ++ )
  1851.     {
  1852.         if ( SectionInfo[Section].Block != 0xFF )
  1853.         {
  1854.             /*
  1855.             ** Write = write bytes from Offset
  1856.             */
  1857.             Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  1858.             STTBX_Print(("Section=%dt", Section ));
  1859.             STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  1860.             STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  1861.             STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  1862.             WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
  1863.             /*SectionInfo[Section].Address += 0x4; Tara*/
  1864.             STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  1865.                          SectionInfo[Section].Block,
  1866.                          SectionInfo[Section].Address,
  1867.                          SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
  1868.             ErrCode = STFLASH_Write( wts_FLASHHndl[Bank],
  1869.                                      WriteOffset,
  1870.                                      (U8*)&FlashData_p[SectionInfo[Section].Offset],
  1871.                                      SectionInfo[Section].Size,
  1872.                                      &NumberOfBytes );
  1873.             if ( ErrCode != ST_NO_ERROR )
  1874.             {
  1875.                 STTBX_Print(("Program FAILEDn"));
  1876.                 ProgramFailed = TRUE;
  1877.             }
  1878.             else
  1879.                 STTBX_Print(("PROGRAMMEDn"));
  1880.         }
  1881.     }
  1882.     if ( ProgramFailed == TRUE )
  1883.     {
  1884.         wts_FreeFileDataBuffer();
  1885.         STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
  1886.         return TRUE;
  1887.     }
  1888.     else
  1889.     {
  1890.         STTBX_Print(("tt+------------+------------+n"));
  1891.         return FALSE;
  1892.     }
  1893. }
  1894. #else
  1895. BOOL wts_ProgramLanguageFlash( char *Filename )
  1896. {
  1897.     int            nameLength ;
  1898.     BOOL           binFile,ProgramFailed ;
  1899.     ST_ErrorCode_t      ErrCode;
  1900. long int    ReadFile_p=0;            /* datafile descriptor          */
  1901. U32   FileSize=0;          /* size in bytes of the file    */
  1902. U32 WriteOffset = 0x40100000;
  1903.     U32                 NumberOfBytes;
  1904.     nameLength = strlen( Filename ) ;
  1905.     if (Filename[nameLength-1]=='n' && Filename[nameLength-2]=='i' &&
  1906.         Filename[nameLength-3]=='b' && Filename[nameLength-4]=='.' )
  1907.     {
  1908.         binFile = TRUE ;
  1909.     }    
  1910.     /* Open and Read file into memory */
  1911.     ReadFile_p = debugopen(Filename, "rb");
  1912.     STTBX_Print(("ReadFile_p = 0x%8xn",ReadFile_p));
  1913.     
  1914.     if(ReadFile_p < 0)
  1915.     {
  1916.         STTBX_Print(("Error opening file '%s'n", Filename ));
  1917.         return (0);
  1918.     }
  1919.     else
  1920.     {
  1921.         FileSize = debugfilesize(ReadFile_p);
  1922.         STTBX_Print(("FileSize = 0x%8xn",FileSize));
  1923.         /* allocate File data buffer */
  1924.         wts_FreeFileDataBuffer();
  1925.         FlashData_p = (char*) memory_allocate( SystemPartition, FileSize );
  1926.         if ( FlashData_p != NULL )
  1927.         {
  1928.             STTBX_Print(("Loading '%s' into memory, wait .. ", Filename ));
  1929.             debugread(ReadFile_p, FlashData_p, (size_t) FileSize);
  1930.             STTBX_Print(("%d bytesn", FileSize ));
  1931.         }
  1932.         else
  1933.         {
  1934.             STTBX_Print(("Not enough memory for HEX file (%d bytes)n", FileSize));
  1935.             FileSize = 0;
  1936.         }
  1937.             FlashData_p = (char*) memory_reallocate( SystemPartition, FlashData_p, FileSize );
  1938.                 STTBX_Print(("FlashData_p memory_reallocaten"));
  1939.         debugclose(ReadFile_p);
  1940.     }
  1941. if(FileSize > 0){
  1942.             ErrCode = STFLASH_Write( wts_FLASHHndl[BANK0],
  1943.                                      WriteOffset,
  1944.                                      (U8*)FlashData_p,
  1945.                                      FileSize,
  1946.                                      &NumberOfBytes );
  1947.             if ( ErrCode != ST_NO_ERROR )
  1948.             {
  1949.                 STTBX_Print(("Program FAILEDn"));
  1950.                 ProgramFailed = TRUE;
  1951.             }
  1952.             else
  1953.                 STTBX_Print(("PROGRAMMEDn"));
  1954.         }
  1955. else
  1956. return 0;
  1957.     if ( ProgramFailed == TRUE )
  1958.     {
  1959.         wts_FreeFileDataBuffer();
  1960.         STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
  1961.         return TRUE;
  1962.     }
  1963.     else
  1964.     {
  1965.         STTBX_Print(("tt+------------+------------+n"));
  1966.         return FALSE;
  1967.     }
  1968.  
  1969.     /* loop thru the data file */
  1970.     return 1;
  1971. }
  1972. #endif
  1973. #if 0
  1974. BOOL wts_ProgramLanguageFlash( void )
  1975. {
  1976. ST_ErrorCode_t      ErrCode;
  1977.     int                 Section, Bank=0;
  1978.     U32                 NumberOfBytes;
  1979.     BOOL                ProgramFailed;
  1980. U32 FlashOffset=0;
  1981.     /* check data size */
  1982.     if ( FlashSize == 0 )
  1983.         ProgramFailed = TRUE;
  1984.     else
  1985.     {
  1986.         ProgramFailed = FALSE;
  1987.         STTBX_Print(("tt+------------+------------+n"));
  1988.     }
  1989. FlashOffset = (U32)0x40100000;
  1990. ErrCode = STFLASH_Write( wts_FLASHHndl[1],
  1991.                                      FlashOffset,
  1992.                                      (U8 *)FlashData_p,
  1993.                                      FlashSize,
  1994.                                      &NumberOfBytes );
  1995.             if ( ErrCode != ST_NO_ERROR )
  1996.             {
  1997.                 STTBX_Print(("Program FAILEDn"));
  1998.                 ProgramFailed = TRUE;
  1999.             }
  2000.             else
  2001.                 STTBX_Print(("PROGRAMMEDn"));
  2002.     if ( ProgramFailed == TRUE )
  2003.     {
  2004.         wts_FreeFileDataBuffer();
  2005.         STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
  2006.         return TRUE;
  2007.     }
  2008.     else
  2009.     {
  2010.         STTBX_Print(("tt+------------+------------+n"));
  2011.         return FALSE;
  2012.     }
  2013. } /* end wts_ProgramFlash */
  2014. #endif
  2015. /*-------------------------------------------------------------------------
  2016.  * Function : wts_ProgramAllFlash
  2017.  *            Function to Read Hex file and program flash with contents
  2018.  * Input    :
  2019.  * Output   :
  2020.  * Return   : None
  2021.  * ----------------------------------------------------------------------*/
  2022. BOOL wts_ProgramAllFlash( void )
  2023. {
  2024.     ST_ErrorCode_t      ErrCode;
  2025.     int                 Section, Bank;
  2026.     U32                 NumberOfBytes;
  2027.     BOOL                ProgramFailed;
  2028.     /* check data size */
  2029.     if ( FlashSize == 0 )
  2030.         ProgramFailed = TRUE;
  2031.     else
  2032.     {
  2033.         ProgramFailed = FALSE;
  2034.         STTBX_Print(("tt+------------+------------+n"));
  2035.     }
  2036.     /* Find out which blocks are to be written to */
  2037.     /* Write the data to the Flash */
  2038.     /*STTBX_Print(("Printing the contents of BlockInfo n"));
  2039.     for ( Section = 0; ( Section < NUM_SECTIONS ) ; Section ++ )
  2040.     {
  2041.         STTBX_Print(("Section=%dt", Section ));
  2042.         STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  2043.         STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  2044.         STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  2045.     }*/
  2046.     for ( Section = 0; ( Section < TOTAL_BLOCKS ) && ( ProgramFailed == FALSE ); Section ++ )
  2047.     {
  2048.         if ( SectionInfo[Section].Block != 0xFF )
  2049.         {
  2050.             U32  WriteOffset;
  2051.             /*
  2052.             ** Write = write bytes from Offset
  2053.             */
  2054.             Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  2055. #ifdef DEBUG
  2056.             STTBX_Print(("Section=%dt", Section ));
  2057.             STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  2058.             STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  2059.             STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  2060. #endif
  2061.             WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
  2062.             /*SectionInfo[Section].Address += 0x4; Tara*/
  2063.             STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  2064.                          SectionInfo[Section].Block,
  2065.                          SectionInfo[Section].Address,
  2066.                          SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
  2067.             ErrCode = STFLASH_Write( wts_FLASHHndl[Bank],
  2068.                                      WriteOffset,
  2069.                                      (U8*)&FlashData_p[SectionInfo[Section].Offset],
  2070.                                      SectionInfo[Section].Size,
  2071.                                      &NumberOfBytes );
  2072.             if ( ErrCode != ST_NO_ERROR )
  2073.             {
  2074.                 STTBX_Print(("Program FAILEDn"));
  2075.                 ProgramFailed = TRUE;
  2076.             }
  2077.             else
  2078.                 STTBX_Print(("PROGRAMMEDn"));
  2079.         }
  2080.     }
  2081.     if ( ProgramFailed == TRUE )
  2082.     {
  2083.         wts_FreeFileDataBuffer();
  2084.         STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
  2085.         return TRUE;
  2086.     }
  2087.     else
  2088.     {
  2089.         STTBX_Print(("tt+------------+------------+n"));
  2090.         return FALSE;
  2091.     }
  2092. } /* end wts_ProgramAllFlash */
  2093. /*-------------------------------------------------------------------------
  2094.  * Function : wts_ProgramLNBFlash
  2095.  *            Function to Read Hex file and program flash with contents
  2096.  * Input    :
  2097.  * Output   :
  2098.  * Return   : None
  2099.  * ----------------------------------------------------------------------*/
  2100. BOOL wts_ProgramLNBFlash( void )
  2101. {
  2102.     ST_ErrorCode_t      ErrCode;
  2103.     int                 Section, Bank;
  2104.     U32                 NumberOfBytes;
  2105.     BOOL                ProgramFailed;
  2106.     /* check data size */
  2107.     if ( FlashSize == 0 )
  2108.         ProgramFailed = TRUE;
  2109.     else
  2110.     {
  2111.         ProgramFailed = FALSE;
  2112.         STTBX_Print(("tt+------------+------------+n"));
  2113.     }
  2114.     /* Find out which blocks are to be written to */
  2115.     /* Write the data to the Flash */
  2116.     /*STTBX_Print(("Printing the contents of BlockInfo n"));
  2117.     for ( Section = 0; ( Section < NUM_SECTIONS ) ; Section ++ )
  2118.     {
  2119.         STTBX_Print(("Section=%dt", Section ));
  2120.         STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  2121.         STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  2122.         STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  2123.     }*/
  2124.     for ( Section = CODE_BLOCKS; ( Section < TOTAL_BLOCKS ) && ( ProgramFailed == FALSE ); Section ++ )
  2125.     {
  2126.         if ( SectionInfo[Section].Block != 0xFF )
  2127.         {
  2128.             U32  WriteOffset;
  2129.             /*
  2130.             ** Write = write bytes from Offset
  2131.             */
  2132.             Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  2133. #ifdef DEBUG
  2134.             STTBX_Print(("Section=%dt", Section ));
  2135.             STTBX_Print(("SectionInfo[Section]=%dn", SectionInfo[Section] ));
  2136.             STTBX_Print(("SectionInfo[Section].Block=%dt", SectionInfo[Section].Block ));
  2137.             STTBX_Print(("BlockInfo[ SectionInfo[Section].Block ].Bank=%dn",BlockInfo[ SectionInfo[Section].Block ].Bank));
  2138. #endif
  2139.             WriteOffset = SectionInfo[Section].Address - BaseAddress[Bank];
  2140.             /*SectionInfo[Section].Address += 0x4; Tara*/
  2141.             STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  2142.                          SectionInfo[Section].Block,
  2143.                          SectionInfo[Section].Address,
  2144.                          SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
  2145.             ErrCode = STFLASH_Write( wts_FLASHHndl[Bank],
  2146.                                      WriteOffset,
  2147.                                      (U8*)&FlashData_p[SectionInfo[Section].Offset],
  2148.                                      SectionInfo[Section].Size,
  2149.                                      &NumberOfBytes );
  2150.             if ( ErrCode != ST_NO_ERROR )
  2151.             {
  2152.                 STTBX_Print(("Program FAILEDn"));
  2153.                 ProgramFailed = TRUE;
  2154.             }
  2155.             else
  2156.                 STTBX_Print(("PROGRAMMEDn"));
  2157.         }
  2158.     }
  2159.     if ( ProgramFailed == TRUE )
  2160.     {
  2161.         wts_FreeFileDataBuffer();
  2162.         STTBX_Print(("!!!! PROGRAM Failed !!!!n"));
  2163.         return TRUE;
  2164.     }
  2165.     else
  2166.     {
  2167.         STTBX_Print(("tt+------------+------------+n"));
  2168.         return FALSE;
  2169.     }
  2170. } /* end wts_ProgramLNBFlash */
  2171. BOOL wts_VerifyLogoFlash( void )
  2172. {}
  2173. BOOL wts_VerifyLanguageFlash( void )
  2174. {}
  2175. /*-------------------------------------------------------------------------
  2176.  * Function : wts_VerifyAllFlash
  2177.  *            Function to Read Hex file and verify flash with contents
  2178.  * Input    :
  2179.  * Output   :
  2180.  * Return   : None
  2181.  * ----------------------------------------------------------------------*/
  2182. BOOL wts_VerifyAllFlash( void )
  2183. {
  2184.     ST_ErrorCode_t      ErrCode = ST_NO_ERROR;
  2185.     int                 Section, Bank;
  2186.     U32                 Length;
  2187.     U32                 ReadOffset;
  2188.     U32                 NumberOfBytes;
  2189.     U8                  *Buffer_p;
  2190.     BOOL                VerifyFailed;
  2191.     /* check data size */
  2192.     if ( FlashSize == 0 )
  2193.         VerifyFailed = TRUE;
  2194.     else
  2195.     {
  2196.         VerifyFailed = FALSE;
  2197.         STTBX_Print(("tt+------------+------------+n"));
  2198.     }
  2199.     /* Find out which blocks are to be verified */
  2200.     /* Read the data and compare */
  2201.     for ( Section = 0; ( Section < TOTAL_BLOCKS ) && ( VerifyFailed == FALSE ); Section ++ )
  2202.     {
  2203.         if ( SectionInfo[Section].Block != 0xFF )
  2204.         {
  2205.             Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  2206.             Length = BlockInfo[ SectionInfo[Section].Block ].Length;
  2207.             ReadOffset = SectionInfo[Section].Address - BaseAddress[Bank];
  2208.             /* allocate temp buffer to put flash data in */
  2209.             Buffer_p = memory_allocate( SystemPartition, Length );
  2210.             if ( Buffer_p != NULL )
  2211.             {
  2212.                 STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  2213.                          SectionInfo[Section].Block,
  2214.                          SectionInfo[Section].Address,
  2215.                          SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
  2216.                 ErrCode = STFLASH_Read( wts_FLASHHndl[Bank],
  2217.                                         ReadOffset,
  2218.                                         Buffer_p,
  2219.                                         SectionInfo[Section].Size,
  2220.                                         &NumberOfBytes );
  2221.                 if(ErrCode != ST_NO_ERROR)
  2222.                 {
  2223.                     STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
  2224.                 }
  2225.                 if ( memcmp( Buffer_p,(U8*)&FlashData_p[SectionInfo[Section].Offset],
  2226.                              SectionInfo[Section].Size ) != 0 )
  2227.                 {
  2228.                     STTBX_Print(("Verify FAILEDn"));
  2229.                     VerifyFailed = TRUE;
  2230.                 }
  2231.                 else
  2232.                     STTBX_Print(("VERIFIEDn"));
  2233.                 /* deallocate temp buffer */
  2234.                 memory_deallocate( SystemPartition, Buffer_p );
  2235.             }
  2236.         }
  2237.     }
  2238.     wts_FreeFileDataBuffer();
  2239.     
  2240.     if ( VerifyFailed == TRUE )
  2241.     {
  2242.         STTBX_Print(("!!!! VERIFY Failed !!!!n"));
  2243.         return TRUE;
  2244.     }
  2245.     else
  2246.     {
  2247.         STTBX_Print(("tt+------------+------------+n"));
  2248.         return FALSE;
  2249.     }
  2250. } /* end wts_VerifyAllFlash */
  2251. /*-------------------------------------------------------------------------
  2252.  * Function : wts_VerifyLNBFlash
  2253.  *            Function to Read Hex file and verify flash with contents
  2254.  * Input    :
  2255.  * Output   :
  2256.  * Return   : None
  2257.  * ----------------------------------------------------------------------*/
  2258. BOOL wts_VerifyLNBFlash( void )
  2259. {
  2260.     ST_ErrorCode_t      ErrCode = ST_NO_ERROR;
  2261.     int                 Section, Bank;
  2262.     U32                 Length;
  2263.     U32                 ReadOffset;
  2264.     U32                 NumberOfBytes;
  2265.     U8                  *Buffer_p;
  2266.     BOOL                VerifyFailed;
  2267.     /* check data size */
  2268.     if ( FlashSize == 0 )
  2269.         VerifyFailed = TRUE;
  2270.     else
  2271.     {
  2272.         VerifyFailed = FALSE;
  2273.         STTBX_Print(("tt+------------+------------+n"));
  2274.     }
  2275.     /* Find out which blocks are to be verified */
  2276.     /* Read the data and compare */
  2277.     for ( Section = CODE_BLOCKS; ( Section < TOTAL_BLOCKS ) && ( VerifyFailed == FALSE ); Section ++ )
  2278.     {
  2279.         if ( SectionInfo[Section].Block != 0xFF )
  2280.         {
  2281.             Bank = BlockInfo[ SectionInfo[Section].Block ].Bank;
  2282.             Length = BlockInfo[ SectionInfo[Section].Block ].Length;
  2283.             ReadOffset = SectionInfo[Section].Address - BaseAddress[Bank];
  2284.             /* allocate temp buffer to put flash data in */
  2285.             Buffer_p = memory_allocate( SystemPartition, Length );
  2286.             if ( Buffer_p != NULL )
  2287.             {
  2288.                 STTBX_Print(("block %2dt| 0x%08x | 0x%08x | ",
  2289.                          SectionInfo[Section].Block,
  2290.                          SectionInfo[Section].Address,
  2291.                          SectionInfo[Section].Address + SectionInfo[Section].Size - 1 ));
  2292.                 ErrCode = STFLASH_Read( wts_FLASHHndl[Bank],
  2293.                                         ReadOffset,
  2294.                                         Buffer_p,
  2295.                                         SectionInfo[Section].Size,
  2296.                                         &NumberOfBytes );
  2297.                 if(ErrCode != ST_NO_ERROR)
  2298.                 {
  2299.                     STTBX_Print(("STFLASH_Read %sn",wts_GetErrorText(ErrCode)));
  2300.                 }
  2301.                 if ( memcmp( Buffer_p,(U8*)&FlashData_p[SectionInfo[Section].Offset],
  2302.                              SectionInfo[Section].Size ) != 0 )
  2303.                 {
  2304.                     STTBX_Print(("Verify FAILEDn"));
  2305.                     VerifyFailed = TRUE;
  2306.                 }
  2307.                 else
  2308.                     STTBX_Print(("VERIFIEDn"));
  2309.                 /* deallocate temp buffer */
  2310.                 memory_deallocate( SystemPartition, Buffer_p );
  2311.             }
  2312.         }
  2313.     }
  2314.     wts_FreeFileDataBuffer();
  2315.     
  2316.     if ( VerifyFailed == TRUE )
  2317.     {
  2318.         STTBX_Print(("!!!! VERIFY Failed !!!!n"));
  2319.         return TRUE;
  2320.     }
  2321.     else
  2322.     {
  2323.         STTBX_Print(("tt+------------+------------+n"));
  2324.         return FALSE;
  2325.     }
  2326. } /* end wts_VerifyLNBFlash */
  2327. #endif
  2328. /* Testtool Functions --------------------------------------------------- */
  2329. #ifdef TESTTOOL
  2330. /*-------------------------------------------------------------------------
  2331.  * Function : wts_TTFLASH_GetParams
  2332.  *            
  2333.  * Input    : *pars_p, *result_sym_p
  2334.  * Output   :
  2335.  * Return   : TRUE if error, FALSE if success
  2336.  * ----------------------------------------------------------------------*/
  2337. static BOOL wts_TTFLASH_GetParams( STTST_Parse_t *pars_p, char *Result )
  2338. {
  2339.     ST_ErrorCode_t      ErrCode;
  2340.     STFLASH_Params_t    FLASHParams;
  2341.     STFLASH_Params_t    *FLASHParams_p;
  2342.     U8                  BankNum;
  2343.     U8                  Block;
  2344.     U32                 BlockStart;
  2345.     /* Get Flash bank parameter from command line */
  2346.     STTST_GetInteger( pars_p, BANK0, (S32 *)&BankNum );
  2347.     ErrCode = wts_FLASH_GetParams(BankNum, &FLASHParams);
  2348.     FLASHParams_p = &FLASHParams;
  2349.     BlockStart = (U32) FLASHParams_p->InitParams.BaseAddress;
  2350.     STTBX_Print(("Bank %d, Blocks %dn", BankNum,
  2351.                  FLASHParams_p->InitParams.NumberOfBlocks ));
  2352.     STTBX_Print(("Base Address      0x%08xn", FLASHParams_p->InitParams.BaseAddress ));
  2353.     STTBX_Print(("VppAddress        0x%08xn",FLASHParams_p->InitParams.VppAddress ));
  2354.     STTBX_Print(("Manufacturer Code 0x%08Xn", FLASHParams_p->ManufactCode ));
  2355.     STTBX_Print(("Device Code       0x%08Xn", FLASHParams_p->DeviceCode ));
  2356.     STTBX_Print(("AccessWidths      Min %d, Max %dn",
  2357.                  FLASHParams_p->InitParams.MinAccessWidth,
  2358.                  FLASHParams_p->InitParams.MaxAccessWidth ));
  2359.     STTBX_Print(("Block Start      Size     Typen"));
  2360.     for ( Block = 0; Block < FLASHParams_p->InitParams.NumberOfBlocks; Block ++)
  2361.     {
  2362.         STTBX_Print(("%5d 0x%08x %8d ",
  2363.                      Block,
  2364.                      BlockStart,
  2365.                      FLASHParams_p->InitParams.Blocks[Block].Length ));
  2366.         switch( FLASHParams_p->InitParams.Blocks[Block].Type )
  2367.         {
  2368.         case STFLASH_EMPTY_BLOCK:
  2369.             STTBX_Print(("Emptyn"));
  2370.             break;
  2371.         case STFLASH_BOOT_BLOCK:
  2372.             STTBX_Print(("Bootn"));
  2373.             break;
  2374.         case STFLASH_PARAMETER_BLOCK:
  2375.             STTBX_Print(("Parametern"));
  2376.             break;
  2377.         case STFLASH_MAIN_BLOCK:
  2378.             STTBX_Print(("Mainn"));
  2379.             break;
  2380.         default:
  2381.             STTBX_Print(("Unknownn"));
  2382.             break;
  2383.             
  2384.         }
  2385.         BlockStart += FLASHParams_p->InitParams.Blocks[Block].Length;
  2386.     }
  2387.     return ( ErrCode == ST_NO_ERROR ? FALSE : TRUE);
  2388. } /* end wts_TTFLASH_GetParams */
  2389. /*-------------------------------------------------------------------------
  2390.  * Function : wts_TT_SetupBlockInfo
  2391.  *            Setup FLASH Block Info
  2392.  * Input    :
  2393.  * Output   :
  2394.  * Return   : None
  2395.  * ----------------------------------------------------------------------*/
  2396. static BOOL wts_TT_SetupBlockInfo( STTST_Parse_t *pars_p, char *Result )
  2397. {
  2398.     ST_ErrorCode_t      ErrCode;
  2399.     
  2400.     ErrCode = wts_FLASH_SetupBlockInfo();
  2401.     
  2402.     return ( ErrCode != ST_NO_ERROR ? TRUE : FALSE );
  2403. }
  2404. /*-------------------------------------------------------------------------
  2405.  * Function : wts_TT_FlashSetup
  2406.  *            Setup FLASH Block Info
  2407.  * Input    :
  2408.  * Output   :
  2409.  * Return   : None
  2410.  * ----------------------------------------------------------------------*/
  2411. static BOOL wts_TT_FlashSetup( STTST_Parse_t *pars_p, char *Result )
  2412. {
  2413.     ST_ErrorCode_t      ErrCode;
  2414.     
  2415.     ErrCode = wts_FLASH_Setup();
  2416.     
  2417.     return ( ErrCode != ST_NO_ERROR ? TRUE : FALSE );
  2418. }
  2419. /*-------------------------------------------------------------------------
  2420.  * Function : wts_TT_ReadFile
  2421.  *            Function to Read Hex file
  2422.  * Input    :
  2423.  * Output   :
  2424.  * Return   : None
  2425.  * ----------------------------------------------------------------------*/
  2426. static BOOL wts_TT_ReadFile( STTST_Parse_t *pars_p, char *Result )
  2427. {
  2428.     char        Filename[81];
  2429.     STTST_GetString( pars_p, "flash.hex", Filename, 80 );
  2430.     /* Read File */
  2431.     /* Convert from file format to memory format */
  2432.     
  2433.     STTBX_Print(("filename = %sn",Filename));
  2434.     if ( FlashSize == 0 )
  2435.         FlashSize = wts_FLASH_ReadFile( Filename );
  2436.     
  2437.     return ( FlashSize == 0 ? TRUE : FALSE );
  2438. }
  2439. /*-------------------------------------------------------------------------
  2440.  * Function : wts_TT_EraseFlash
  2441.  *            Function to erase flash for loaded data
  2442.  * Input    :
  2443.  * Output   :
  2444.  * Return   : None
  2445.  * ----------------------------------------------------------------------*/
  2446. static BOOL wts_TT_EraseFlash( STTST_Parse_t *pars_p, char *Result )
  2447. {
  2448.     char        Text[11];
  2449.     BOOL        EraseAll;
  2450.     STTST_GetString( pars_p, "", Text, 10 );
  2451.     if ( strcmp( Text, "ALL" ) == 0 )
  2452.     {
  2453.         EraseAll = TRUE;
  2454.         STTBX_Print(("EraseAll = TRUEn"));
  2455.     }
  2456.     else
  2457.     {
  2458.         EraseAll = FALSE;
  2459.         STTBX_Print(("EraseAll = FALSEn"));
  2460.     }    
  2461.     return wts_EraseFlash( EraseAll );
  2462. }
  2463. /*-------------------------------------------------------------------------
  2464.  * Function : wts_TT_ProgramFlash
  2465.  *            Function to program flash with loaded data
  2466.  * Input    :
  2467.  * Output   :
  2468.  * Return   : None
  2469.  * ----------------------------------------------------------------------*/
  2470. static BOOL wts_TT_ProgramFlash( STTST_Parse_t *pars_p, char *Result )
  2471. {
  2472.     return wts_ProgramFlash();
  2473. }
  2474. /*-------------------------------------------------------------------------
  2475.  * Function : wts_TT_VerifyFlash
  2476.  *            Function to verify flash with loaded data
  2477.  * Input    :
  2478.  * Output   :
  2479.  * Return   : None
  2480.  * ----------------------------------------------------------------------*/
  2481. static BOOL wts_TT_VerifyFlash( STTST_Parse_t *pars_p, char *Result )
  2482. {
  2483.     return wts_VerifyFlash();
  2484. }
  2485. #endif /* TESTTOOL */
  2486. /*-------------------------------------------------------------------------
  2487.  * Function : FLASH_InitCommands
  2488.  *            Definition of the macros
  2489.  *            (commands and constants to be used with Testtool)
  2490.  * Input    :
  2491.  * Output   :
  2492.  * Return   : TRUE if error, FALSE if success
  2493.  * ----------------------------------------------------------------------*/
  2494. BOOL wts_FLASH_InitCommand( void )
  2495. {
  2496.     BOOL RetErr;
  2497.     RetErr = FALSE;
  2498.     
  2499.   #ifdef TESTTOOL  
  2500.     RetErr |= STTST_RegisterCommand("FLASH_GETPARMS", wts_TTFLASH_GetParams, "Get FLASH Parameters");
  2501.     RetErr |= STTST_RegisterCommand("FLASH_BLOCKINFO",    wts_TT_SetupBlockInfo, "Get Flash Block Data");
  2502.     RetErr |= STTST_RegisterCommand("FLASH_SETUP",    wts_TT_FlashSetup, "Setup Flash Bank(Init&Open) Data");
  2503.     RetErr |= STTST_RegisterCommand("FLASH_ERASE",    wts_TT_EraseFlash, "<ALL> Erase Flash");
  2504.     RetErr |= STTST_RegisterCommand("FLASH_PROGRAM",  wts_TT_ProgramFlash, "Program Flash");
  2505.     RetErr |= STTST_RegisterCommand("FLASH_READ", wts_TT_ReadFile, "<Filename> Read Flash Data");
  2506.     RetErr |= STTST_RegisterCommand("FLASH_VERIFY",   wts_TT_VerifyFlash, "Verify Flash");
  2507.   #endif
  2508.     
  2509.     return( RetErr );
  2510. } /* end wts_FLASH_InitCommand */
  2511. /* EOF --------------------------------------------------------------------- */