Ejemplo n.º 1
0
void setdebuglevel(char *host, long level)
{
  _loghost = host;
  _loglevel = level;

  if (level == FLIDEBUG_NONE)
  {
    debugclose();
    _logopen = 0;
    return;
  }

  if (!_logopen)
  {
    debugopen(host);
    _logopen = 1;
  }

  if (host != NULL)
    setlogmask(LOG_UPTO(sysloglevel(level)));

  return;
}
Ejemplo n.º 2
0
int BootFromFlash( void )
{
 
    long int    HexFile_p   = 0;            /* datafile descriptor          */
    long int    HexFileSize = 0;          /* size in bytes of the file    */
    int         ErrorCount  = 0;
    ST_ErrorCode_t ReturnError = ST_NO_ERROR;
    char Filename[]         = "flash.hex";
    U8                  Block;
    U32                 BlockStart;
    
    STFLASH_Print(( "\n" ));
    STFLASH_Print(( "============================================================\n" ));
    STFLASH_Print(( "Commencing Boot From Flash Test  ..\n" ));
    STFLASH_Print(( "============================================================\n" ));

   
    /* Init Bank 0, Vpp 0 */
    InitParams_s.DeviceType      = DEVICE_TYPE;
    InitParams_s.BaseAddress     = (U32*)STFLASH_BANK_0_BASE;
    InitParams_s.VppAddress      = (U32*)STFLASH_VPP_0_ENABLE;
    InitParams_s.MinAccessWidth  = MIN_ACCESS_WIDTH;
    InitParams_s.MaxAccessWidth  = MAX_ACCESS_WIDTH;
    InitParams_s.NumberOfBlocks  = NUM_BLOCKS;
    InitParams_s.Blocks          = BlockData_s;
#ifdef ST_OS21
    InitParams_s.DriverPartition = system_partition;
#else
    InitParams_s.DriverPartition = TEST_PARTITION_1;
#endif

    STFLASH_Print(( "FLASH_BANK_0_BASE = %x\n", STFLASH_BANK_0_BASE ));

    STFLASH_Print(( "Calling STFLASH_Init() Bank0 ..........\n" ));
    ReturnError = STFLASH_Init( "Bank0", &InitParams_s );
    ErrorReport( &ErrorCount, ReturnError, ST_NO_ERROR );
    
    /* Open Bank 0 */
    STFLASH_Print(( "Calling STFLASH_Open() Bank0 ..........\n" ));
    ReturnError = STFLASH_Open( "Bank0",
                                &OpenParams_s,
                                &FLASHHndl[0] );
    ErrorReport( &ErrorCount, ReturnError, ST_NO_ERROR );
    
    /* GetParams for Bank 0 */
    GetParams_s.InitParams.Blocks = GetBlkDat_s;
    STFLASH_Print(( "Calling STFLASH_GetParams() Bank 0 ....\n" ));
    ReturnError = STFLASH_GetParams( FLASHHndl[0], &GetParams_s );
    ErrorReport( &ErrorCount, ReturnError, ST_NO_ERROR );
    ParamsReport( &GetParams_s );
    
    BlockStart  = BaseAddress[BANK0] = (U32) InitParams_s.BaseAddress;
    for ( Block = 0; Block < InitParams_s.NumberOfBlocks; Block ++)
    {
        BlockInfo[Block].Bank    = 0;
        BlockInfo[Block].Address = BlockStart;
        BlockInfo[Block].Length  = InitParams_s.Blocks[Block].Length;
        BlockStart += InitParams_s.Blocks[Block].Length;
    }

    /* Open and Read file into memory */
    HexFile_p = debugopen(Filename, "rb");
    STFLASH_Print(("HexFile_p = 0x%8x\n",HexFile_p));
    
    if (HexFile_p < 0)
    {
        STFLASH_Print(("Error opening file \'%s\'\n", Filename ));
        return (0);
    }
    else
    {
        HexFileSize = debugfilesize(HexFile_p);
        STFLASH_Print(("HexFileSize = 0x%8x\n",HexFileSize));
        
        /* allocate File data buffer */
        FlashData_p = (char*) memory_allocate( system_partition, (U32) HexFileSize );
        if ( FlashData_p != NULL )
        {
            STFLASH_Print(("Loading \'%s\' into memory, wait .. ", Filename ));
            debugread(HexFile_p, FlashData_p, (size_t) HexFileSize);
            STFLASH_Print(("%d bytes\n", HexFileSize ));
        }
        else
        {
            STFLASH_Print(("Not enough memory for HEX file (%d bytes)\n", HexFileSize));
            HexFileSize = 0;
        }

        debugclose(HexFile_p);
    }

    if ( HexFileSize > 0 )
    {
        /* convert buffer to binary and resize memory */
        STFLASH_Print(("Converting file in memory, wait .. "));
        FlashSize = ConvertMemory( HexFileSize );
        if ( FlashSize > 0 )
        {
            STFLASH_Print(("%d bytes\n", FlashSize ));
            FlashData_p = (char*) memory_reallocate( system_partition, FlashData_p, FlashSize );
        }
        else
        {
            STFLASH_Print(("Invalid file\n"));
        }
    }
    
    if ( EraseFlash(FALSE) == FALSE )
    {
        if ( ProgramFlash() == FALSE )
        {
            VerifyFlash();
        }
    }
    
    /* Close Bank 0 */
    STFLASH_Print(( "Calling STFLASH_Close() Bank 0 ........\n" ));
    ReturnError = STFLASH_Close( FLASHHndl[0] );
    ErrorReport( &ErrorCount, ReturnError, ST_NO_ERROR );


    /* Term Bank 0 */
    TermParams_s.ForceTerminate = FALSE;
    STFLASH_Print(( "Calling STFLASH_Term() Bank 0 .........\n" ));
    ReturnError = STFLASH_Term( "Bank0", &TermParams_s );
    ErrorReport( &ErrorCount, ReturnError, ST_NO_ERROR );
    
    return( ErrorCount );
    
}