⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash_amd.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
{
    int             rcode = OK ;
    volatile UINT32 *pw ;

    return OK;		// *** kludge ***

    pw = (UINT32 *)0xbf800000;
	
   /* issue 'QUERY' command */
    REG32(pw + 0x55)  = 0x00980098;
	
#ifdef  FLASH_DEBUG
    sprintf( msg, "\n\r FLASH_AMD_test_systemflash: Adr= 0x%08x, Sta= 0x%08x\n\r", 
		(UINT32)pw, REG32( ((UINT32)pw+FLASH_BLOCKSTATUS_OFS) ) ) ;
    PUTS( DEFAULT_PORT, msg ) ;
#endif
	
    /* Verify 'Q' char of the Query-unique ASCII string, part of CFI spec. */
    if ( REG32(pw + 0x10) != FLASH_QUERYQCHAR )     
    {
        memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
        sprintf( flash_diag_msg, "Adr= %08x, (Adr)= %08x",(UINT32)pw+FLASH_QUERYQCHAR_OFS,
			REG32(((UINT32)pw+FLASH_QUERYQCHAR_OFS)) ) ;
        rcode = ERROR_FLASH_QRY_NOT_FOUND ;

    }
	
    /* Verify 'R' char of the Query-unique ASCII string, part of CFI spec. */
    if ( REG32(pw + 0x11) != FLASH_QUERYRCHAR )     
    {
        memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
        sprintf( flash_diag_msg, "Adr= %08x, (Adr)= %08x",(UINT32)pw+FLASH_QUERYRCHAR_OFS,
			REG32(((UINT32)pw+FLASH_QUERYRCHAR_OFS)) ) ;
        rcode = ERROR_FLASH_QRY_NOT_FOUND ;

    }
	
    /* Verify 'Y' char of the Query-unique ASCII string, part of CFI spec. */
    if ( REG32(pw + 0x12) != FLASH_QUERYYCHAR )     
    {
        memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
        sprintf( flash_diag_msg, "Adr= %08x, (Adr)= %08x",(UINT32)pw+FLASH_QUERYYCHAR_OFS,
			REG32(((UINT32)pw+FLASH_QUERYYCHAR_OFS)) ) ;
        rcode = ERROR_FLASH_QRY_NOT_FOUND ;

    }

	/* Issue Reset Command to return to read mode */
	
	REG32(pw) = 0x00f000f0;	
   
    return( rcode ) ;
}


/************************************************************************
*
*                          FLASH_AMD_test_monitorflash
*  Description :
*  -------------
*  Test and set lock bits of complete monitor flash (including file flash)
*   The lower 1 Mbytes hold YAMON and are locked (write protected) 
*   The upper 3 Mbytes are unlocked.
*  
*
*  Parameters :
*  ------------
*
*  -
*
*  Return values :
*  ---------------
*
* 'OK' = 0x00:                         System FLASH OK
*  ERROR_FLASH_LOCKED                  Some sector(s) locked
*  ERROR_FLASH_ERASE_ERROR             Some sector(s) have erase error
*
************************************************************************/
static
INT32 FLASH_AMD_test_monitorflash( void )
{
    int             rcode = OK ;
    volatile UINT32 *pw ;
    UINT32          pw_lock_end;
    UINT32          pw_unlock_end;

    return OK;		// *** kludge ***

    pw = (UINT32 *) 0xbf800000;


   /* issue 'QUERY' command */
    REG32(pw + 0x55)  = 0x00980098;
	
#ifdef  FLASH_DEBUG
    sprintf( msg, "\n\r FLASH_AMD_test_systemflash: Adr= 0x%08x, Sta= 0x%08x\n\r", 
		(UINT32)pw, REG32( ((UINT32)pw+FLASH_BLOCKSTATUS_OFS) ) ) ;
    PUTS( DEFAULT_PORT, msg ) ;
#endif
	
    /* Verify 'Q' char of the Query-unique ASCII string, part of CFI spec. */
    if ( REG32(pw + 0x10) != FLASH_QUERYQCHAR )     
    {
        memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
        sprintf( flash_diag_msg, "Adr= %08x, (Adr)= %08x",(UINT32)pw+FLASH_QUERYQCHAR_OFS,
			REG32(((UINT32)pw+FLASH_QUERYQCHAR_OFS)) ) ;
        rcode = ERROR_FLASH_QRY_NOT_FOUND ;

    }
	
    /* Verify 'R' char of the Query-unique ASCII string, part of CFI spec. */
    if ( REG32(pw + 0x11) != FLASH_QUERYRCHAR )     
    {
        memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
        sprintf( flash_diag_msg, "Adr= %08x, (Adr)= %08x",(UINT32)pw+FLASH_QUERYRCHAR_OFS,
			REG32(((UINT32)pw+FLASH_QUERYRCHAR_OFS)) ) ;
        rcode = ERROR_FLASH_QRY_NOT_FOUND ;

    }
	
    /* Verify 'Y' char of the Query-unique ASCII string, part of CFI spec. */
    if ( REG32(pw + 0x12) != FLASH_QUERYYCHAR )     
    {
        memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
        sprintf( flash_diag_msg, "Adr= %08x, (Adr)= %08x",(UINT32)pw+FLASH_QUERYYCHAR_OFS,
			REG32(((UINT32)pw+FLASH_QUERYYCHAR_OFS)) ) ;
        rcode = ERROR_FLASH_QRY_NOT_FOUND ;
        
    }

	/* Issue Reset Command to return to read mode */
	
	REG32(pw) = 0x00f000f0;	
   
    return( rcode ) ;
}


/************************************************************************
*
*                          FLASH_AMD_wait_ready
*  Description :
*  -------------
*  
*  Await FLASH operation completes.
*  
*
*  Parameters :
*  ------------
*
*  -
*
*  Return values :
*  ---------------
*
* 'OK' = 0x00:                         File FLASH erased succesfully
*  ERROR_FLASH_PROGRAM_ERROR           Flash device failure
*
*
************************************************************************/
static
INT32 FLASH_AMD_wait_ready(void *pw, long data )
{
#ifndef FLASH_16BIT
#define CASTSIZE long
#else
#define CASTSIZE short
#endif
    volatile CASTSIZE temp, *pf = (volatile CASTSIZE *)pw;

    while(1)
    {
        temp = *pf;
        if( (temp & POLLING_MASK) == (data & POLLING_MASK))
        {
            return( OK );
        }
        else if((temp & TIMING_LIMIT_MASK) == TIMING_LIMIT_MASK)
        {
            temp = *pf;
            if((temp & POLLING_MASK) == (data & POLLING_MASK))
            {
                return( OK );
            }
            else
            {
                printf("Timed out programming flash, temp = %08lx, data = %08lx", temp, data);
                return( ERROR_FLASH_PROGRAM_ERROR );
            }
        }
    }

    /* keep diagnose message */
    memset( flash_diag_msg, 0, sizeof(flash_diag_msg) ) ;
    sprintf( flash_diag_msg, "Adr=0x%08x",(UINT32)pw) ;

    /* we should never end up here time-out */
    return( ERROR_FLASH_TIME_OUT ) ;

#if 0 //#else	// 16 bit flash
    
    volatile short	*pf = (volatile short *)pw;
    int			a, b;

    a = pf[0];			// initial status
    for(;;)
    {
        b = pf[0];		// read status
        if( ((a ^ b) & 0x0040) != 0 )	// if DQ6 toggles
        {
//            printf("<T>");
            if( (b & 0x0020) != 0 )		// if DQ5 set
            {
                a = pf[0];
                b = pf[0];
                if( ((a ^ b) & 0x0040) == 0 )	// if no toggle
                    return 0;			// show success
                else
                {
                    printf("<timeout>\n");
                    return ERROR_FLASH_PROGRAM_ERROR;	// else error
                }
            }
        }
        else
            return OK;		// show success if toggle stops
        a = b;			// prepare for next toggle check
    }

#endif
}


/************************************************************************
*
*                          FLASH_AMD_error_lookup
*  Description :
*  -------------
*  Lookup error code to error string(s)
*  
*
*  Parameters :
*  ------------
* 
*  'p_param',   INOUT,    variable of type, t_sys_error_string.
*
*
*  Return values :
*  ---------------
*
* 'OK' = 0x00:  
*
*
************************************************************************/
static
INT32 FLASH_AMD_error_lookup( t_sys_error_string *p_param )
{
    UINT32 t, i ;
	
    i = 0 ;
    p_param->count = 0 ;
    t = SYSERROR_ID( p_param->syserror ) ;
    if ( flash_last_error == p_param->syserror )
    {
        /* check for recognized error code */
        if (t < sizeof(flash_error_string)/sizeof(char*) )
        {
            /* fill in mandatory error message string */
            p_param->strings[SYSCON_ERRORMSG_IDX] = flash_error_string[t] ;
            i++ ;
			
            /* check for diagnose message */
            if ( flash_diag_msg[0] != 0 )
            {
                /* fill in optional diagnose message string */
                p_param->strings[SYSCON_DIAGMSG_IDX] = flash_diag_msg ;
                i++ ;
            }
			
            /* check for hint message */
            if ( flash_error_hint_string[t] != NULL)
            {
                /* fill in optional hint message string */
                p_param->strings[SYSCON_HINTMSG_IDX] = flash_error_hint_string[t] ;
                i++ ;
            }
        }
        p_param->count      = i ;
    }
	
    /* delete context */
    flash_last_error  = OK ;
    return(OK) ;
}

/************************************************************************
*
*                          FLASH_AMD_is_system_flash_write_protected
*  Description :
*  -------------
*  Check if system flash id write protected
*  
*
*  Parameters :
*  ------------
*
*
*
*  Return values :
*  ---------------
*
*  FALSE: not write protected
*  TRUE:  write protected
*
*
************************************************************************/
static
bool FLASH_AMD_is_system_flash_write_protected( void )
{
    UINT32 rcode ;
    UINT32 wr_protect ;

    return FALSE;		// *** Kludge ***
    
    /* check in SYSCON */
    rcode = SYSCON_read( SYSCON_BOARD_SYSTEMFLASH_WRITE_PROTECTED_ID,
		&wr_protect,
		sizeof(wr_protect) ) ;
    if (wr_protect)
    {
        return( TRUE ) ;
    }
    else
    {
        return( FALSE ) ;
    }
}


/************************************************************************
*
*                          FLASH_AMD_is_file_flash_write_protected
*  Description :
*  -------------
*  Check if file flash id write protected
*  
*
*  Parameters :
*  ------------
*
*
*
*  Return values :
*  ---------------
*
*  FALSE: not write protected
*  TRUE:  write protected
*
*
************************************************************************/
static
bool FLASH_AMD_is_file_flash_write_protected( void )
{
    UINT32 rcode ;
    UINT32 wr_protect ;

    return FALSE;		// *** Kludge ***

    /* check in SYSCON */
    rcode = SYSCON_read( SYSCON_BOARD_FILEFLASH_WRITE_PROTECTED_ID,
		&wr_protect,
		sizeof(wr_protect) ) ;
    if (wr_protect)
    {
        return( TRUE ) ;
    }
    else
    {
        return( FALSE ) ;
    }
}


/************************************************************************
*
*                          FLASH_AMD_is_monitor_flash_write_protected
*  Description :
*  -------------
*  Check if file flash id write protected
*  
*
*  Parameters :
*  ------------
*
*
*
*  Return values :
*  ---------------
*
*  FALSE: not write protected
*  TRUE:  write protected
*
*
************************************************************************/
static
bool FLASH_AMD_is_monitor_flash_write_protected( void )
{
    UINT32 rcode ;
    UINT32 wr_protect ;

    return FALSE;		// *** Kludge ***

    /* check in SYSCON */
    rcode = SYSCON_read( SYSCON_BOARD_MONITORFLASH_WRITE_PROTECTED_ID,
		&wr_protect,
		sizeof(wr_protect) ) ;
    if (wr_protect)
    {
        return( TRUE ) ;
    }
    else
    {
        return( FALSE ) ;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -