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

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