搜尋此網誌

2012年8月7日 星期二

(EFI_STRING Request)Extract block name from the array generated by VFR compiler. The name of this array is "Vfr + + BlockName", e.g. "VfrMyIfrNVDataBlockName".


/*The source code is from EFI Dev Kit(EDk).*/

EFI_STATUS
ExtractBlockName (
  IN UINT8                        *Buffer,
  OUT CHAR16                      **BlockName
  )
/*++
  Routine Description:

    Extract block name from the array generated by VFR compiler. The name of
  this array is "Vfr + + BlockName", e.g. "VfrMyIfrNVDataBlockName".
  Format of this array is:
     Array length | 4-bytes
       Offset     | 2-bytes
       Width      | 2-bytes
       Offset     | 2-bytes
       Width      | 2-bytes
       ... ...

  Arguments:
    Buffer                - Array generated by VFR compiler.
    BlockName             - The returned

  Returns:
    EFI_OUT_OF_RESOURCES  - Run out of memory resource.
    EFI_INVALID_PARAMETER - Buffer is NULL or BlockName is NULL.
    EFI_SUCCESS           - Operation successful.
--*/
{
  UINTN       Index;
  UINT32      Length;
  UINT32      BlockNameNumber;
  UINTN       HexStringBufferLen;
  CHAR16      *StringPtr;

  if ((Buffer == NULL) || (BlockName == NULL)) {
    return EFI_INVALID_PARAMETER;
  }

  //
  // Calculate number of Offset/Width pair
  //
  EfiCopyMem (&Length, Buffer, sizeof (UINT32));
  BlockNameNumber = (Length - sizeof (UINT32)) / (sizeof (UINT16) * 2);

  //
  // ::= &OFFSET=1234&WIDTH=1234
  //                 |   8  | 4 |  7   | 4 |
  //
  StringPtr = EfiLibAllocateZeroPool ((BlockNameNumber * (8 + 4 + 7 + 4) + 1) * sizeof (CHAR16));
  *BlockName = StringPtr;
  if (StringPtr == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  Buffer += sizeof (UINT32);
  for (Index = 0; Index < BlockNameNumber; Index++) {
    EfiStrCpy (StringPtr, L"&OFFSET=");
    StringPtr += 8;

    HexStringBufferLen = 5;
    BufToHexString (StringPtr, &HexStringBufferLen, Buffer, sizeof (UINT16));
    Buffer += sizeof (UINT16);
    StringPtr += 4;

    EfiStrCpy (StringPtr, L"&WIDTH=");
    StringPtr += 7;

    HexStringBufferLen = 5;
    BufToHexString (StringPtr, &HexStringBufferLen, Buffer, sizeof (UINT16));
    Buffer += sizeof (UINT16);
    StringPtr += 4;
  }

  return EFI_SUCCESS;
}

沒有留言:

張貼留言