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

📄 nvm.c

📁 Next BIOS Source code : Extensible Firmware Interface
💻 C
📖 第 1 页 / 共 2 页
字号:
    BIS_DATA_PTR bisData;
    UINT8        *tmpData;
    UINT8        dummyData;
	BISBC_INSTANCEDATA  *BISID= getInstanceData( BISBC );


    // Make sure tmpData points to something safe
    // GWG & PD:
    if (dataLength == 0)
    {
        tmpData = &dummyData;
    }
    else {
        tmpData = data;
    }

    //Check offset and length for validity
    rv= NVM_CheckParms( areaHandle, tmpData, dataLength, offset );
    if (  rv != EFI_SUCCESS)
    {
        return rv;
    }

    //Cast the areaHandle to a BIS_DATA_PTR and extract buffer ptr.
    bisData= (BIS_DATA_PTR)areaHandle;
    buffer=  (UINT8*)bisData->data;

    //Copy to data from 'p' to user's buffer 'data' at specified offset
    //and length.
    EfiCopyMem( buffer+offset, tmpData, dataLength );
    BISID->flashDataChanged=  BIS_TRUE;
    return EFI_SUCCESS;
}



    //-------------------------------------------------------------//
    // NVM_Close - write the buffer associated with 'areaHandle'   //
    //   back to underlying storage, delete handle.                //
    //-------------------------------------------------------------//

EFI_STATUS
NVM_Close( BIS_APPINFO *appInfo, NVM_AREA_HANDLE areaHandle )
{
  BIS_DATA_PTR bisData;
  UINT8        *areaBuffer;
  EFI_STATUS   rv=            EFI_SUCCESS;
  EFI_STATUS   efiStatus=     EFI_SUCCESS;
  UINT32       computedDigest;
	BISBC_INSTANCEDATA  *BISID= getInstanceData( BISBC );

  bisData=    (BIS_DATA_PTR)areaHandle;

    //Check handle for validity, return error if not valid.
    if ( BISID->Persist==BIS_NULL)  return BIS_INIT_FAILURE;
    if ( !IS_APPINFO_VALID(appInfo) ) return BIS_BAD_APPHANDLE;
    if ( areaHandle==BIS_NULL )       return BIS_BAD_PARM;

    //If buffer copy of flash data has changed, write it out.
    if (BISID->flashDataChanged == BIS_TRUE )
    {
        //Cast handle to BIS_DATA_PTR. Extract buffer pointer.
        //Get actual area length.
        bisData=    (BIS_DATA_PTR)areaHandle;
        areaBuffer= bisData->data;

        //Recalc digest of NVM contents.
        rv= digestNVM( appInfo, &computedDigest );
        if ( rv==BIS_OK )
        {
            //put the computed digest into nvm
            rv= NVM_Write(
                areaHandle,                   //nvm handle
                (UINT8*)&computedDigest,      //buffer to read into
                GET_NVM_FIELD_SIZE( truncatedDigest ),    //nvm field length
                GET_NVM_FIELD_OFFSET( truncatedDigest ) //nvm field offset
                );

        }


        //Dont update flash,  if digest calculation or write failed.
        //Error should be propagated up to BIS_Shutdown.
        if (rv==EFI_SUCCESS)
        {
            //Call PersistentStorage_Write to put buffer to persistent storage.
            efiStatus= BISID->Persist->Write(
					                                    BISID->Persist,
                	                           (UINT8*)areaBuffer,
					                                    NULL);

            rv = efiStatus;

            BISID->flashDataChanged= BIS_FALSE;
        }
    }

    //Free the memory 'handle'. Only the appInfo BIS_DATA structure
    //is being freed. The data pointer that it constains was allocated
    //by NVM_Init.
    MEM_free( appInfo, bisData);

    return rv;

}


    //---------------------------------------------------------//
    //  checkForBisGUID - compare parms to NVM_BIS_AREA_ID.    //
    //---------------------------------------------------------//

static  EFI_GUID bisGUID= NVM_BIS_AREA_ID;


BIS_BOOLEAN
    checkForBisGUID( NVM_AREA_ID *callerGUID )
{

    BIS_BOOLEAN rv= BIS_FALSE;

    if ( EfiCompareGuid( (EFI_GUID*)callerGUID, &bisGUID )) {
		rv= BIS_TRUE;
	}

    return rv;

}





    //--------------------------------------------------//
    //  NVM_CheckParms - common read / write parm check //
    //                                                  //
    //--------------------------------------------------//

EFI_STATUS
NVM_CheckParms(  
  NVM_AREA_HANDLE areaHandle,
  UINT8           *data,
  UINT32          dataLength,
  UINT32          offset 
  )
{
    BIS_DATA_PTR bisData;
    UINT32   areaLength;

    //Check handle and data pointer for validity, return error if not valid.
    if ( areaHandle == BIS_NULL )     return EFI_DEVICE_ERROR;
    if ( data       == BIS_NULL )     return EFI_INVALID_PARAMETER;

    //Check area and offset.
    bisData= (BIS_DATA_PTR)areaHandle;
    areaLength= bisData->length;

    //Check offset and length combinations.
    if ( offset >= areaLength) return EFI_DEVICE_ERROR;
    areaLength= areaLength - offset;
    if ( dataLength > areaLength)  return EFI_DEVICE_ERROR;

    return EFI_SUCCESS;
}





//--------------------------------------------------------------------------------//
//  digestNVM - compute a SHA1 digest of the
//
//  PARMS:
//    BIS_APPINFO_PTR  appInfo     - appInfo structure.
//    UINT32          *digestOut   - [OUT] pointer to trucated digest
//
//  returns: BIS_OK on success.//
//----------------------------------------------------------------------------------//

EFI_STATUS
digestNVM(
    BIS_APPINFO_PTR  appInfo,
    UINT32          *truncDigestOut
    )
{
    BISBC_INSTANCEDATA  *BISID= getInstanceData( BISBC );
    EFI_STATUS    		rv=     EFI_SUCCESS;
    BIS_DATA_PTR  		fullDigest;
    UINT32        		offset;
    CSSM_DATA     		cssmData[1];


    //The truncatedDigest  field must be the first thing
    //in the NVM area and we enforce that constraint.
    offset= GET_NVM_FIELD_OFFSET( truncatedDigest );
    if ( offset != 0 )
    {
        rv= EFI_DEVICE_ERROR;
    }


    //Setup and create the digest.
    if ( rv==EFI_SUCCESS )
    {
        //Prep to digest everything after the digestField in the NVM cache.

        cssmData[0].Data=
        	BISID->flashData + GET_NVM_FIELD_SIZE( truncatedDigest );
        cssmData[0].Length=
        	BISID->flashDataLength - GET_NVM_FIELD_SIZE( truncatedDigest );


        //Prep to digest everything after the digestField in the NVM cache.
        //Digest the NVM
        rv= sha1Digest(
                appInfo,        //app control block
                cssmData,       //vector to NVM data
                1,              //one element in vector.
                &fullDigest);   //output, complete sha1 digest.

    	//Extract the 1st 4 bytes from the digest
    	if (rv==EFI_SUCCESS)
    	{
    	    //extract 1st 32bits of digest, to user's outparm.
    	    *truncDigestOut=(*(UINT32*)fullDigest->data);

    	    //Free the memory allocated by sha1Digest.
    	    MEM_free( appInfo, fullDigest );
	   	}

    }


    return rv;

}


//History:
//Branched from smbios bis file...
//	Archive: /SMA/Src/bis/util/nvm.c
//	Revision: 18
//  Date: 2/02/99 6:16p


//eof

⌨️ 快捷键说明

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