Exemplo n.º 1
0
EFIAPI
StrnCatGrowLeft (
  IN OUT CHAR16           **Destination,
  IN OUT UINTN            *CurrentSize,
  IN     CONST CHAR16     *Source,
  IN     UINTN            Count
  )
{
  UINTN DestinationStartSize;
  UINTN NewSize;
  UINTN CopySize;

  if (Destination == NULL) {
    return (NULL);
  }

  //
  // If there's nothing to do then just return Destination
  //
  if (Source == NULL) {
    return (*Destination);
  }

  //
  // allow for NULL pointers address as Destination
  //
  if (*Destination != NULL) {
    ASSERT(CurrentSize != 0);
    DestinationStartSize = StrSize(*Destination);
    ASSERT(DestinationStartSize <= *CurrentSize);
  } else {
    DestinationStartSize = 0;
//    ASSERT(*CurrentSize == 0);
  }

  //
  // Append all of Source?
  //
  if (Count == 0) {
    Count = StrSize(Source);
  }

  //
  // Test and grow if required
  //
  if (CurrentSize != NULL) {
    NewSize = *CurrentSize;
    while (NewSize < (DestinationStartSize + Count)) {
      NewSize += 2 * Count;
    }
    *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);
    *CurrentSize = NewSize;
  } else {
    *Destination = AllocateZeroPool(Count+sizeof(CHAR16));
  }
  if (*Destination == NULL) {
    return NULL;
  }

  CopySize = StrSize(*Destination);
  CopyMem((*Destination)+((Count-2)/sizeof(CHAR16)), *Destination, CopySize);
  CopyMem(*Destination, Source, Count-2);
  return (*Destination);
}
Exemplo n.º 2
0
Arquivo: Bds.c Projeto: hzhuang1/uefi
EFI_STATUS
GetBootDeviceTypeInfo (
  VOID
  )
{
    EFI_STATUS        Status = EFI_SUCCESS;
    LIST_ENTRY        BootOptionsList;
    LIST_ENTRY*       Entry;    
    UINT16            *SataDes = NULL;
    UINT16            *MacDes = NULL;
    UINTN             SataDesSize = 0;
    UINTN             MacDesSize = 0; 
    BDS_LOAD_OPTION*  BootOption;
    UINTN             OptionCount = 0;
    CHAR16*           SataStr = L"Sata";
    CHAR16*           MacStr = L"MAC";
    CHAR16*           DevicePathTxt = NULL;
    EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol = NULL;    
    
    // Get Boot#### list
    BootOptionList (&BootOptionsList);
    // Display the Boot options
    for (Entry = GetFirstNode (&BootOptionsList);
     !IsNull (&BootOptionsList,Entry);
     Entry = GetNextNode (&BootOptionsList,Entry)
     )
    {
        BootOption = LOAD_OPTION_FROM_LINK(Entry);
        //Print(L"[%d] %s\n", OptionCount, BootOption->Description);
        //DEBUG_CODE_BEGIN();
        Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
        if (EFI_ERROR(Status)) {
            // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)
            DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));
            return Status;
        }
        DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);
         //Print(L"\t- %s\n",DevicePathTxt);
        //DEBUG_CODE_END();        
         //FIND SATA BOOT DEVICES       
        if(!(StringFind(DevicePathTxt, SataStr)))
        {                        
            if(SataDesSize != 0)
            {
                SataDes = ReallocatePool (SataDesSize, SataDesSize + sizeof(UINT16), SataDes);
                SataDes[SataDesSize / sizeof(UINT16)] = BootOption->LoadOptionIndex;
                SataDesSize += sizeof(UINT16);
            }else{
                SataDesSize = sizeof(UINT16);
                SataDes = &(BootOption->LoadOptionIndex);
            }
           // Print(L"liuhuan SATA boot num: %d\n",SataDesSize / sizeof(UINT16));
        }        
        //FIND PXE BOOT DEVICES
        if(!(StringFind(DevicePathTxt, MacStr) ))            
        {                        
            if(MacDesSize != 0)
            {
                MacDes = ReallocatePool (MacDesSize, MacDesSize + sizeof(UINT16), MacDes);
                MacDes[MacDesSize / sizeof(UINT16)] = BootOption->LoadOptionIndex;
                MacDesSize += sizeof(UINT16);
            }else{
                MacDesSize = sizeof(UINT16);
                MacDes = &(BootOption->LoadOptionIndex);
            }
         //   Print(L"liuhuan PXE boot num: %d\n",MacDesSize / sizeof(UINT16));
        }
        //FreePool(DevicePathTxt);    
        OptionCount++;
    }
     
    OemGetSataBootNum(SataDesSize);
    OemGetPXEBootNum(MacDesSize);

    if(SataDes != NULL)
    {
        FreePool(SataDes);
    }
    if(MacDes != NULL)
    {
        FreePool(MacDes);
    }
    if(DevicePathTxt != NULL)
    {
        FreePool(DevicePathTxt);
    }
    return EFI_SUCCESS;
}