示例#1
0
文件: hdisk.c 项目: 99years/plan9
int
hdebug(HConnect *c)
{
	char *scorestr, *op;
	u8int score[VtScoreSize];
	
	if(hsethtml(c) < 0)
		return -1;
	hprint(&c->hout, "<h1>venti debug</h1>\n");

	op = hargstr(c, "op", "");
	if(!op[0]){
		hprint(&c->hout, "no op\n");
		return 0;
	}
	
	if(strcmp(op, "amap") == 0){
		debugamap(c);
		return 0;
	}

	if(strcmp(op, "mem") == 0){
		debugmem(c);
		return 0;
	}

	if(strcmp(op, "read") == 0){
		scorestr = hargstr(c, "score", "");
		if(vtparsescore(scorestr, nil, score) < 0){
			hprint(&c->hout, "bad score %s: %r\n", scorestr);
			return 0;
		}
		debugread(c, score);
		return 0;
	}
	
	hprint(&c->hout, "unknown op %s", op);
	return 0;
}
示例#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 );
    
}