示例#1
0
EFI_STATUS
EFIAPI
UpdateDeviceSelectPage (
    IN EFI_CALLBACK_INFO                *Private,
    IN UINT16                           KeyValue,
    IN EFI_IFR_DATA_ARRAY               *Data
)
/*++

Routine Description:
  Prepare the first page to let user select the device controller which need to add mapping drivers

Arguments:

  KeyValue -  No use here.
  Data -         EFI_IFR_DATA_ARRAY data.
  Packet-       No use here.

  Returns -    Always successful

--*/
{
    EFI_HII_UPDATE_DATA                       *UpdateData;
    EFI_STATUS                                Status;
    UINTN                                     LangSize;
    UINTN                                     Index;
    UINT8                                     *Location;
    UINTN                                     DevicePathHandleCount;

    CHAR16                                    *NewString;
    STRING_REF                                NewStringToken;
    CHAR16                                    *ControllerName;
    EFI_DEVICE_PATH_PROTOCOL                  *ControllerDevicePath;
    EFI_PCI_IO_PROTOCOL                       *PciIo;
    EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *BusSpecificDriverOverride;

    mCurrentPage = 0x01;
    //
    // Following code will be run if user select 'Refresh' in first page
    // During first page, user will see all currnet controller device path in system,
    // select any device path will go to second page to select its overrides drivers
    //

    LangSize = 0x3;
    Status = gRT->GetVariable (
                 L"Lang",
                 &gEfiGlobalVariableGuid,
                 NULL,
                 &LangSize,
                 mLanguage
             );
    ASSERT_EFI_ERROR (Status);

    Status = GetCurrentLanguage (mLang);
    ASSERT_EFI_ERROR (Status);
    //
    // Initial the mapping database in memory
    //
    LibFreeMappingDatabase (&mMappingDataBase);
    Status = LibInitOverridesMapping (&mMappingDataBase);

    //
    // Clear all the content in the first page
    //
    UpdateData = NULL;
    UpdateData = EfiLibAllocateZeroPool (UPDATE_DATA_SIZE);
    ASSERT (UpdateData != NULL);

    UpdateData->FormSetUpdate       = FALSE;
    UpdateData->FormCallbackHandle  = 0;
    UpdateData->FormUpdate          = FALSE;
    UpdateData->FormTitle           = 0;
    UpdateData->DataCount           = 0xff;
    UpdateData->Data                = NULL;

    Private->Hii->UpdateForm (
        Private->Hii,
        Private->RegisteredHandle,
        (EFI_FORM_LABEL) 0x1234,  // Label 0x1234
        FALSE,                    // Remove Op-codes (will never remove form/endform)
        UpdateData                // Significant value is UpdateData->DataCount
    );
    //
    // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
    // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are  same after the replacement
    //
    NewStringToken = (STRING_REF) STR_FIRST_REFRESH;
    NewString = GetString (Private, (STRING_REF) STR_REFRESH);
    ASSERT (NewString != NULL);
    Status = Private->Hii->NewString (Private->Hii, mLang, Private->RegisteredHandle, &NewStringToken, NewString);
    ASSERT_EFI_ERROR (Status);
    gBS->FreePool (NewString);

    NewStringToken = (STRING_REF) STR_FIRST_REFRESH_HELP;
    NewString = GetString (Private, (STRING_REF) STR_REFRESH_HELP);
    ASSERT (NewString != NULL);
    Status = Private->Hii->NewString (Private->Hii, mLang, Private->RegisteredHandle, &NewStringToken, NewString);
    ASSERT_EFI_ERROR (Status);
    gBS->FreePool (NewString);
    //
    // created needed controller device item in first page
    //
    DevicePathHandleCount  = 0;
    Status = gBS->LocateHandleBuffer (
                 ByProtocol,
                 &gEfiDevicePathProtocolGuid,
                 NULL,
                 &DevicePathHandleCount,
                 &mDevicePathHandleBuffer
             );
    if (EFI_ERROR (Status) || (DevicePathHandleCount == 0)) {
        return EFI_SUCCESS;
    }

    for (Index = 0; Index < DevicePathHandleCount; Index++) {
        if (((MyIfrNVData *) Data->NvRamMap)->PciDeviceFilter == 0x01) {
            //
            // Only care PCI device which contain efi driver in its option rom.
            //

            //
            // Check whether it is a pci device
            //
            ControllerDevicePath = NULL;
            Status = gBS->OpenProtocol (
                         mDevicePathHandleBuffer[Index],
                         &gEfiPciIoProtocolGuid,
                         (VOID **) &PciIo,
                         NULL,
                         NULL,
                         EFI_OPEN_PROTOCOL_GET_PROTOCOL
                     );
            if (EFI_ERROR (Status)) {
                continue;
            }
            //
            // Check whether it contain efi driver in its option rom
            //
            Status = gBS->HandleProtocol(
                         mDevicePathHandleBuffer[Index],
                         &gEfiBusSpecificDriverOverrideProtocolGuid,
                         &BusSpecificDriverOverride
                     );
            if (EFI_ERROR (Status) || BusSpecificDriverOverride == NULL) {
                continue;
            }
        }

        ControllerDevicePath = NULL;
        Status = gBS->OpenProtocol (
                     mDevicePathHandleBuffer[Index],
                     &gEfiDevicePathProtocolGuid,
                     (VOID **) &ControllerDevicePath,
                     NULL,
                     NULL,
                     EFI_OPEN_PROTOCOL_GET_PROTOCOL
                 );
        ASSERT_EFI_ERROR (Status);
        //
        // Save the device path protocol interface
        //
        mControllerDevicePathProtocol[Index] = ControllerDevicePath;

        //
        // Get the driver name
        //
        ControllerName = DevicePathToStr (ControllerDevicePath);

        //
        // Create a item for the driver in set options page
        // Clear the Update buffer
        //
        UpdateData->FormSetUpdate       = FALSE;
        UpdateData->FormCallbackHandle  = 0;
        UpdateData->FormUpdate          = FALSE;
        UpdateData->FormTitle           = 0;
        UpdateData->DataCount           = 0;
        Location = (UINT8 *) &UpdateData->Data;
        //
        // Export the driver name string and create item in set options page
        //
        NewString = EfiLibAllocateZeroPool (EfiStrSize (ControllerName) + EfiStrSize (L"--"));
        if (EFI_ERROR (LibCheckMapping (ControllerDevicePath,NULL, &mMappingDataBase, NULL, NULL))) {
            EfiStrCat (NewString, L"--");
        } else {
            EfiStrCat (NewString, L"**");
        }
        EfiStrCat (NewString, ControllerName);

        NewStringToken = mControllerToken[Index];
        Status = Private->Hii->NewString (Private->Hii, NULL, Private->RegisteredHandle, &NewStringToken, NewString);
        ASSERT_EFI_ERROR (Status);
        gBS->FreePool (NewString);
        //
        // Save the device path string toke for next access use
        //
        mControllerToken[Index] = NewStringToken;

        CreateGotoOpCode (
            0x1200,
            NewStringToken,               // Description String Token
            STR_GOTO_HELP_DRIVER,         // Description Help String Token
            EFI_IFR_FLAG_INTERACTIVE,     // Flag designating callback is active
            (UINT16) Index + 0x100, // Callback key value
            Location                      // Buffer to fill with op-code
        );
        //
        // Update the buffer items number and adjust next item address to new one
        //
        UpdateData->DataCount +=1 ;
        Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;
        //
        // Update first page form
        //
        Private->Hii->UpdateForm (
            Private->Hii,
            Private->RegisteredHandle,
            (EFI_FORM_LABEL) 0x1234,
            TRUE,
            UpdateData
        );

    }

    gBS->FreePool (UpdateData);
    return EFI_SUCCESS;
}
示例#2
0
EFI_STATUS
EFIAPI
PlatOverMngrInit (
    IN EFI_HANDLE                   ImageHandle,
    IN EFI_SYSTEM_TABLE             *SystemTable
)
/*++

  Routine Description:
    The driver Entry Point.
    The funciton will export a disk device class formset and its callback function to hii database

  Arguments:
    ImageHandle - EFI_HANDLE
    SystemTable - EFI_SYSTEM_TABLE

  Returns:
    EFI_STATUS

--*/
{
    EFI_STATUS          Status;
    EFI_HII_PROTOCOL    *Hii;
    EFI_HII_PACKAGES    *PackageList;
    EFI_HII_HANDLE      HiiHandle;
    EFI_HII_UPDATE_DATA *UpdateData;
    EFI_CALLBACK_INFO   *CallbackInfo;
    EFI_HANDLE          Handle;
    UINTN               Index;
    EFI_GUID            PlatOverMngrGuid = PLAT_OVER_MNGR_GUID;

    //
    // Initialize the library and our protocol.
    //
    DxeInitializeDriverLib (ImageHandle, SystemTable);

    //
    // There should only be one HII protocol
    //
    Status = gBS->LocateProtocol (
                 &gEfiHiiProtocolGuid,
                 NULL,
                 &Hii
             );
    if (EFI_ERROR (Status)) {
        return Status ;
    }

    CallbackInfo = EfiLibAllocateZeroPool (sizeof (EFI_CALLBACK_INFO));
    if (CallbackInfo == NULL) {
        return EFI_BAD_BUFFER_SIZE;
    }

    CallbackInfo->Signature = EFI_CALLBACK_INFO_SIGNATURE;
    CallbackInfo->Hii       = Hii;

    //
    // This driver implement a NV write worker function and a callback evaluator
    //
    CallbackInfo->DriverCallback.NvRead   = NULL;
    CallbackInfo->DriverCallback.NvWrite  = PlatOverMngrNvWrite;
    CallbackInfo->DriverCallback.Callback = PlatOverMngrCallback;

    //
    // Install protocol interface
    //
    Handle = NULL;
    Status = gBS->InstallProtocolInterface (
                 &Handle,
                 &gEfiFormCallbackProtocolGuid,
                 EFI_NATIVE_INTERFACE,
                 &CallbackInfo->DriverCallback
             );

    ASSERT_EFI_ERROR (Status);

    CallbackInfo->CallbackHandle  = Handle;

    PackageList = PreparePackages (2, &PlatOverMngrGuid, VfrBin, PlatOverMngrStrings);
    Status      = Hii->NewPack (Hii, PackageList, &HiiHandle);
    gBS->FreePool (PackageList);

    CallbackInfo->RegisteredHandle = HiiHandle;

    //
    // Allocate space for creation of Buffer
    //
    UpdateData = EfiLibAllocateZeroPool (0x1000);
    ASSERT (UpdateData != NULL);

    //
    // Flag update pending in FormSet
    //
    UpdateData->FormSetUpdate = TRUE;
    //
    // Register CallbackHandle data for FormSet
    //
    UpdateData->FormCallbackHandle = (EFI_PHYSICAL_ADDRESS) (UINTN) CallbackInfo->CallbackHandle;
    UpdateData->FormUpdate  = FALSE;
    UpdateData->FormTitle   = 0;
    UpdateData->DataCount   = 0;

    Hii->UpdateForm (Hii, HiiHandle, (EFI_FORM_LABEL) 0x0, TRUE, UpdateData);
    gBS->FreePool (UpdateData);

    mDriverImageHandleCount = 0;
    mCurrentPage = 0;
    //
    // Clear all the globle variable
    //
    for (Index = 0; Index < MAX_CHOICE_NUM; Index++) {
        mDriverImageToken[Index] = 0;
        mDriverImageFilePathToken[Index] = 0;
        mControllerToken[Index] = 0;
        mDriverImageProtocol[Index] = NULL;
    }
    return EFI_SUCCESS;
}
示例#3
0
EFI_STATUS
EFIAPI
PlatOverMngrCallback (
    IN EFI_FORM_CALLBACK_PROTOCOL       *This,
    IN UINT16                           KeyValue,
    IN EFI_IFR_DATA_ARRAY               *Data,
    OUT EFI_HII_CALLBACK_PACKET         **Packet
)
/*++

Routine Description:

  This is the function that is called to provide results data to the driver.  This data
  consists of a unique key which is used to identify what data is either being passed back
  or being asked for.

Arguments:

  KeyValue - A unique Goto OpCode callback value which record user's selection

  0x100 <= KeyValue <0x500    : user select a controller item in the first page;
  KeyValue == 0x1234               : user select 'Refresh' in first page, or user select 'Go to Previous Menu' in second page
  KeyValue == 0x1235               : user select 'Pci device filter' in first page
  KeyValue == 0x1500               : user select 'order ... priority' item in second page
  KeyValue == 0x1800               : user select 'commint changes' in third page
  KeyValue == 0x2000              : user select 'Go to Previous Menu' in third page

  Data -         EFI_IFR_DATA_ARRAY data
  Packet-       No use here.

  Returns -    Always successful

--*/
{
    EFI_CALLBACK_INFO                         *Private;
    EFI_STATUS                                Status;
    STRING_REF                                NewStringToken;

    Private     = EFI_CALLBACK_INFO_FROM_THIS (This);

    if (KeyValue == 0x1234 || KeyValue == 0x1235) {
        UpdateDeviceSelectPage (Private, KeyValue, Data);
        //
        // Update page title string
        //
        NewStringToken = (STRING_REF) STR_TITLE;
        Status = Private->Hii->NewString (Private->Hii, mLang, Private->RegisteredHandle, &NewStringToken, L"First, Select the controller by device path");
        ASSERT_EFI_ERROR (Status);
    }

    if ((0x100 <= KeyValue) && (KeyValue < 0x500) || (KeyValue == 0x2000)) {
        if (KeyValue == 0x2000) {
            KeyValue = (UINT16)mSelectedCtrIndex + 0x100;
        }
        UpdateBindingDriverSelectPage (Private, KeyValue, Data);
        //
        // Update page title string
        //
        NewStringToken = (STRING_REF) STR_TITLE;
        Status = Private->Hii->NewString (Private->Hii, mLang, Private->RegisteredHandle, &NewStringToken, L"Second, Select drivers for the previous selected controller");
        ASSERT_EFI_ERROR (Status);
    }


    if (KeyValue == 0x1500) {
        UpdatePrioritySelectPage (Private, KeyValue, Data);
        //
        // Update page title string
        //
        NewStringToken = (STRING_REF) STR_TITLE;
        Status = Private->Hii->NewString (Private->Hii, mLang, Private->RegisteredHandle, &NewStringToken, L"Finally, Set the priority order for the drivers and save them");
        ASSERT_EFI_ERROR (Status);
    }

    if (KeyValue == 0x1800) {
        Status = CommintChanges (Private, KeyValue, Data);
        if (EFI_ERROR (Status)) {
            *Packet = EfiLibAllocateZeroPool (sizeof (EFI_HII_CALLBACK_PACKET) + sizeof ( L"Single Override Info too large, Saving Error!") + 2);
            EfiStrCpy ((*Packet)->String,  L"Single Override Info too large, Saving Error!");
            return EFI_DEVICE_ERROR;
        }
    }

    if (KeyValue == 0x1236) {
        //
        // Deletes all environment variable(s) that contain the override mappings info
        //
        LibFreeMappingDatabase (&mMappingDataBase);
        Status = LibSaveOverridesMapping (&mMappingDataBase);
        UpdateDeviceSelectPage (Private, KeyValue, Data);
    }

    return EFI_SUCCESS;
}
示例#4
0
CHAR8 *
ConvertComponentName2SupportLanguage (
    IN EFI_COMPONENT_NAME2_PROTOCOL    *ComponentName,
    IN CHAR8                           *Language
)
/*++

  Routine Description:

    Do some convertion for the ComponentName2 supported language. It do
    the convertion just for english language code currently.

  Arguments:

    ComponentName         - Pointer to the ComponentName2 protocl pointer.
    Language              - The language string.

  Returns:

    Return the duplication of Language if it is not english otherwise return
    the supported english language code.

--*/
{
    CHAR8                              *SupportedLanguages;
    CHAR8                              *LangCode;
    UINTN                              Index;

    LangCode           = NULL;
    SupportedLanguages = NULL;

    //
    // treat all the english language code (en-xx or eng) equally
    //
    if ((strncmpa(Language, "en-", 3) == 0) || (strcmpa(Language, "eng") == 0)) {
        SupportedLanguages = strstra(ComponentName->SupportedLanguages, "en-");
        if (SupportedLanguages == NULL) {
            SupportedLanguages = strstra(ComponentName->SupportedLanguages, "eng");
        }
    }

    //
    // duplicate the Language if it is not english
    //
    if (SupportedLanguages == NULL) {
        SupportedLanguages = Language;
    }

    //
    // duplicate the returned language code.
    //
    if (strstra(SupportedLanguages, "-") != NULL) {
        LangCode = EfiLibAllocateZeroPool(32);
        for(Index = 0; (Index < 31) && (SupportedLanguages[Index] != '\0') && (SupportedLanguages[Index] != ';'); Index++) {
            LangCode[Index] = SupportedLanguages[Index];
        }
        LangCode[Index] = '\0';
    } else {
        LangCode = EfiLibAllocateZeroPool(4);
        for(Index = 0; (Index < 3) && (SupportedLanguages[Index] != '\0'); Index++) {
            LangCode[Index] = SupportedLanguages[Index];
        }
        LangCode[Index] = '\0';
    }
    return LangCode;
}
示例#5
0
EFI_STATUS
AddString (
  IN      VOID                *StringBuffer,
  IN      CHAR16              *Language,
  IN      CHAR16              *String,
  IN OUT  STRING_REF          *StringToken
  )
/*++

Routine Description:

  Add a string to the incoming buffer and return the token and offset data
  
Arguments:
  
  StringBuffer      - The incoming buffer
  
  Language          - Currrent language
  
  String            - The string to be added
  
  StringToken       - The index where the string placed
  
Returns: 

  EFI_OUT_OF_RESOURCES    - No enough buffer to allocate
  
  EFI_SUCCESS             - String successfully added to the incoming buffer

--*/
{
  EFI_HII_STRING_PACK *StringPack;
  EFI_HII_STRING_PACK *StringPackBuffer;
  VOID                *NewBuffer;
  RELOFST             *PackSource;
  RELOFST             *PackDestination;
  UINT8               *Source;
  UINT8               *Destination;
  UINTN               Index;
  BOOLEAN             Finished;
  UINTN               SizeofLanguage;
  UINTN               SizeofString;

  StringPack  = (EFI_HII_STRING_PACK *) StringBuffer;
  Finished    = FALSE;

  //
  // Pre-allocate a buffer sufficient for us to work on.
  // We will use it as a destination scratch pad to build data on
  // and when complete shift the data back to the original buffer
  //
  NewBuffer = EfiLibAllocateZeroPool (DEFAULT_STRING_BUFFER_SIZE);
  if (NewBuffer == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  StringPackBuffer = (EFI_HII_STRING_PACK *) NewBuffer;

  //
  // StringPack is terminated with a length 0 entry
  //
  for (; StringPack->Header.Length != 0;) {
    //
    // If this stringpack's language is same as CurrentLanguage, use it
    //
    if (EfiCompareMem ((VOID *) ((CHAR8 *) (StringPack) + StringPack->LanguageNameString), Language, 3) == 0) {
      //
      // We have some data in this string pack, copy the string package up to the string data
      //
      EfiCopyMem (&StringPackBuffer->Header, &StringPack->Header, sizeof (StringPack));

      //
      // These are references in the structure to tokens, need to increase them by the space occupied by an additional StringPointer
      //
      StringPackBuffer->LanguageNameString = (UINT16) (StringPackBuffer->LanguageNameString + (UINT16) sizeof (RELOFST));
      StringPackBuffer->PrintableLanguageName = (UINT16) (StringPackBuffer->PrintableLanguageName + (UINT16) sizeof (RELOFST));

      PackSource      = (RELOFST *) (StringPack + 1);
      PackDestination = (RELOFST *) (StringPackBuffer + 1);
      for (Index = 0; PackSource[Index] != 0x0000; Index++) {
        //
        // Copy the stringpointers from old to new buffer
        // remember that we are adding a string, so the string offsets will all go up by sizeof (RELOFST)
        //
        PackDestination[Index] = (UINT16) (PackDestination[Index] + sizeof (RELOFST));
      }
      
      //
      // Add a new stringpointer in the new buffer since we are adding a string.  Null terminate it
      //
      PackDestination[Index] = (UINT16)(PackDestination[Index-1] + 
                                        EfiStrSize((CHAR16 *)((CHAR8 *)(StringPack) + PackSource[Index-1])));
      PackDestination[Index + 1] = (UINT16) 0;

      //
      // Index is the token value for the new string
      //
      *StringToken = (UINT16) Index;

      //
      // Source now points to the beginning of the old buffer strings
      // Destination now points to the beginning of the new buffer strings
      //
      Source      = (UINT8 *) &PackSource[Index + 1];
      Destination = (UINT8 *) &PackDestination[Index + 2];

      //
      // This should copy all the strings from the old buffer to the new buffer
      //
      for (; Index != 0; Index--) {
        //
        // Copy Source string to destination buffer
        //
        EfiStrCpy ((CHAR16 *) Destination, (CHAR16 *) Source);

        //
        // Adjust the source/destination to the next string location
        //
        Destination = Destination + EfiStrSize ((CHAR16 *) Source);
        Source      = Source + EfiStrSize ((CHAR16 *) Source);
      }
      
      //
      // This copies the new string to the destination buffer
      //
      EfiStrCpy ((CHAR16 *) Destination, (CHAR16 *) String);

      //
      // Adjust the size of the changed string pack by adding the size of the new string
      // along with the size of the additional offset entry for the new string
      //
      StringPackBuffer->Header.Length = (UINT32) ((UINTN) StringPackBuffer->Header.Length + EfiStrSize (String) + sizeof (RELOFST));

      //
      // Advance the buffers to point to the next spots.
      //
      StringPackBuffer  = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPackBuffer) + StringPackBuffer->Header.Length);
      StringPack        = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + StringPack->Header.Length);
      Finished          = TRUE;
      continue;
    }
    //
    // This isn't the language of the stringpack we were asked to add a string to
    // so we need to copy it to the new buffer.
    //
    EfiCopyMem (&StringPackBuffer->Header, &StringPack->Header, StringPack->Header.Length);

    //
    // Advance the buffers to point to the next spots.
    //
    StringPackBuffer  = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPackBuffer) + StringPack->Header.Length);
    StringPack        = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + StringPack->Header.Length);
  }
  
  //
  // If we didn't copy the new data to a stringpack yet
  //
  if (!Finished) {
    PackDestination = (RELOFST *) (StringPackBuffer + 1);
    //
    // Pointing to a new string pack location
    //
    SizeofLanguage = EfiStrSize (Language);
    SizeofString   = EfiStrSize (String);
    StringPackBuffer->Header.Length = (UINT32)
      (
        sizeof (EFI_HII_STRING_PACK) -
        sizeof (EFI_STRING) +
        sizeof (RELOFST) +
        sizeof (RELOFST) +
        SizeofLanguage +
        SizeofString
      );
    StringPackBuffer->Header.Type           = EFI_HII_STRING;
    StringPackBuffer->LanguageNameString    = (UINT16) ((UINTN) &PackDestination[3] - (UINTN) StringPackBuffer);
    StringPackBuffer->PrintableLanguageName = (UINT16) ((UINTN) &PackDestination[3] - (UINTN) StringPackBuffer);
    StringPackBuffer->Attributes            = 0;
    PackDestination[0]                      = (UINT16) ((UINTN) &PackDestination[3] - (UINTN) StringPackBuffer);
    PackDestination[1]                      = (UINT16) (PackDestination[0] + EfiStrSize (Language));
    PackDestination[2]                      = (UINT16) 0;

    //
    // The first string location will be set to destination.  The minimum number of strings
    // associated with a stringpack will always be token 0 stored as the languagename (e.g. ENG, SPA, etc)
    // and token 1 as the new string being added and and null entry for the stringpointers
    //
    Destination = (CHAR8 *) &PackDestination[3];

    //
    // Copy the language name string to the new buffer
    //
    EfiStrCpy ((CHAR16 *) Destination, Language);

    //
    // Advance the destination to the new empty spot
    //
    Destination = Destination + EfiStrSize (Language);

    //
    // Copy the string to the new buffer
    //
    EfiStrCpy ((CHAR16 *) Destination, String);

    //
    // Since we are starting with a new string pack - we know the new string is token 1
    //
    *StringToken = (UINT16) 1;
  }

  //
  // Zero out the original buffer and copy the updated data in the new buffer to the old buffer
  //
  EfiZeroMem (StringBuffer, DEFAULT_STRING_BUFFER_SIZE);
  EfiCopyMem (StringBuffer, NewBuffer, DEFAULT_STRING_BUFFER_SIZE);

  //
  // Free the newly created buffer since we don't need it anymore
  //
  gBS->FreePool (NewBuffer);
  return EFI_SUCCESS;
}
示例#6
0
EFI_STATUS
EFIAPI
UpdatePrioritySelectPage (
    IN EFI_CALLBACK_INFO                *Private,
    IN UINT16                           KeyValue,
    IN EFI_IFR_DATA_ARRAY               *Data
)
/*++

Routine Description:
  Prepare to let user select the priority order of the drivers which are selected in second page

Arguments:

  KeyValue - No use here.
  Data -         EFI_IFR_DATA_ARRAY data.
  Packet-       No use here.

  Returns -    Always successful

--*/
{
    EFI_HII_UPDATE_DATA                       *UpdateData;
    EFI_STATUS                                Status;
    UINTN                                     Index;
    UINT8                                     *Location;


    EFI_DEVICE_PATH_PROTOCOL                  *LoadedImageHandleDevicePath;
    EFI_DEVICE_PATH_PROTOCOL                  *TatalFilePath;

    IFR_OPTION                                *IfrOptionList;
    UINTN                                     SelectedDriverImageNum;
    UINT32                                    DriverImageNO;
    UINTN                                     MinNO;
    UINTN                                     Index1;
    UINTN                                     TempNO[100];

    //
    //  Following code will be run if user select 'order ... priority' item in second page
    // Prepare third page.  In third page, user will order the  drivers priority which are selected in second page
    //
    mCurrentPage = 0x03;

    UpdateData = NULL;
    UpdateData = EfiLibAllocateZeroPool (UPDATE_DATA_SIZE);
    ASSERT (UpdateData != NULL);
    //
    // Clear all the content in dynamic page
    //
    UpdateData->FormSetUpdate       = FALSE;
    UpdateData->FormCallbackHandle  = 0;
    UpdateData->FormUpdate          = FALSE;
    UpdateData->FormTitle           = 0;
    UpdateData->DataCount           = 0xff;
    UpdateData->Data                = NULL;

    Private->Hii->UpdateForm (
        Private->Hii,
        Private->RegisteredHandle,
        (EFI_FORM_LABEL) 0x1500,
        FALSE,                    // Remove Op-codes (will never remove form/endform)
        UpdateData                // Significant value is UpdateData->DataCount
    );

    //
    // Clear the Update buffer
    //
    UpdateData->FormSetUpdate       = FALSE;
    UpdateData->FormCallbackHandle  = 0;
    UpdateData->FormUpdate          = FALSE;
    UpdateData->FormTitle           = 0;
    UpdateData->DataCount           = 0;
    Location = (UINT8 *) &UpdateData->Data;
    //
    // Check how many drivers have been selected
    //
    SelectedDriverImageNum = 0;
    for (Index = 0; Index < mDriverImageHandleCount; Index++) {
        if (((MyIfrNVData *) Data->NvRamMap)->DriSelection[Index] != 0) {
            SelectedDriverImageNum ++;
        }
    }

    mSelectedDriverImageNum = SelectedDriverImageNum;
    if (SelectedDriverImageNum == 0) {
        return EFI_SUCCESS;
    }

    IfrOptionList = EfiLibAllocateZeroPool (0x200);
    ASSERT_EFI_ERROR (IfrOptionList != NULL);
    //
    // Create order list for those selected drivers
    //
    SelectedDriverImageNum = 0;
    for (Index = 0; Index < mDriverImageHandleCount; Index++) {
        if (((MyIfrNVData *) Data->NvRamMap)->DriSelection[Index] != 0) {
            IfrOptionList[SelectedDriverImageNum].StringToken = mDriverImageToken[Index];
            //
            // Use the NO. in driver binding buffer as value, will use it later
            //
            IfrOptionList[SelectedDriverImageNum].Value = (UINT16) Index + 1;
            IfrOptionList[SelectedDriverImageNum].OptionString = NULL;
            IfrOptionList[SelectedDriverImageNum].Flags       = EFI_IFR_FLAG_INTERACTIVE|EFI_IFR_FLAG_RESET_REQUIRED;
            IfrOptionList[SelectedDriverImageNum].Key  = (UINT16) (0x500 + Index);

            //
            // Get the driver image total file path
            //
            LoadedImageHandleDevicePath = NULL;
            Status = gBS->HandleProtocol (
                         mDriverImageProtocol[Index]->DeviceHandle,
                         &gEfiDevicePathProtocolGuid,
                         &LoadedImageHandleDevicePath
                     );
            TatalFilePath = NULL;
            TatalFilePath = EfiAppendDevicePath (LoadedImageHandleDevicePath, mDriverImageProtocol[Index]->FilePath);
            ASSERT (TatalFilePath != NULL);
            //
            // Check the driver DriverImage's order number in mapping database
            //
            DriverImageNO = 0;
            LibCheckMapping (
                mControllerDevicePathProtocol[mSelectedCtrIndex],
                TatalFilePath,
                &mMappingDataBase,
                NULL,
                &DriverImageNO
            );
            if (DriverImageNO == 0) {
                DriverImageNO = (UINT32) mLastSavedDriverImageNum + 1;
                mLastSavedDriverImageNum++;
            }
            TempNO[SelectedDriverImageNum] = DriverImageNO;
            SelectedDriverImageNum ++;
        }
    }

    ASSERT (SelectedDriverImageNum == mSelectedDriverImageNum);
    //
    // NvRamMap Must be clear firstly
    //
    for (Index=0; Index < 100; Index++) {
        ((MyIfrNVData *) Data->NvRamMap)->DriOrder[Index] = 0;
    }

    //
    // Order the selected drivers according to the info already in mapping database
    // the less order number in mapping database the less order number in NvRamMap
    //
    for (Index=0; Index < SelectedDriverImageNum; Index++) {
        //
        // Find the minimal order number in TempNO array,  its index in TempNO is same as IfrOptionList array
        //
        MinNO = 0;
        for (Index1=0; Index1 < SelectedDriverImageNum; Index1++) {
            if (TempNO[Index1] < TempNO[MinNO]) {
                MinNO = Index1;
            }
        }
        //
        // the IfrOptionList[MinNO].Value = the driver NO. in driver binding buffer
        //
        ((MyIfrNVData *) Data->NvRamMap)->DriOrder[Index] =(UINT8) IfrOptionList[MinNO].Value;
        TempNO[MinNO] = 101;
    }

    CreateOrderedListOpCode (
        (UINT16) DRIVER_ORDER_QUESTION_ID,
        (UINT8) 100,
        mControllerToken[mSelectedCtrIndex],
        mControllerToken[mSelectedCtrIndex],
        IfrOptionList,
        SelectedDriverImageNum,
        Location
    );

    for (Index = 0; Index < SelectedDriverImageNum + 2; Index++) {
        Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;
    }

    UpdateData->DataCount = (UINT16) (UpdateData->DataCount + SelectedDriverImageNum + 2);

    //
    // Update third page form
    //
    Private->Hii->UpdateForm (
        Private->Hii,
        Private->RegisteredHandle,
        (EFI_FORM_LABEL) 0x1500,
        TRUE,
        UpdateData
    );

    gBS->FreePool (IfrOptionList);
    gBS->FreePool (UpdateData);
    return EFI_SUCCESS;
}
示例#7
0
EFI_STATUS
ValidateDataFromHiiHandle (
  IN      EFI_HII_HANDLE      HiiHandle,
  OUT     BOOLEAN             *Results
  )
/*++

Routine Description:

  Validate that the data associated with the HiiHandle in NVRAM is within
  the reasonable parameters for that FormSet.  Values for strings and passwords
  are not verified due to their not having the equivalent of valid range settings.
  
Arguments:

  HiiHandle -   Handle of the HII database entry to query

  Results -     If return Status is EFI_SUCCESS, Results provides valid data
                TRUE  = NVRAM Data is within parameters
                FALSE = NVRAM Data is NOT within parameters
  
Returns: 

  EFI_OUT_OF_RESOURCES      - No enough buffer to allocate
  
  EFI_SUCCESS               - Data successfully validated
--*/
{
  EFI_STATUS        Status;
  EFI_HII_PROTOCOL  *Hii;
  EFI_GUID          Guid;
  UINT8             *RawData;
  UINT8             *OldData;
  UINTN             RawDataLength;
  UINT8             *VariableData;
  UINTN             Index;
  UINTN             Temp;
  UINTN             SizeOfNvStore;
  UINTN             CachedStart;
  BOOLEAN           GotMatch;

  RawDataLength = DEFAULT_FORM_BUFFER_SIZE;
  SizeOfNvStore = 0;
  CachedStart   = 0;
  GotMatch      = FALSE;
  *Results      = TRUE;

  Status        = GetHiiInterface (&Hii);

  if (EFI_ERROR (Status)) {
    return Status;
  }

  //
  // Allocate space for retrieval of IFR data
  //
  RawData = EfiLibAllocateZeroPool (RawDataLength);
  if (RawData == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  //
  // Get all the forms associated with this HiiHandle
  //
  Status = Hii->GetForms (Hii, HiiHandle, 0, &RawDataLength, RawData);

  if (EFI_ERROR (Status)) {
    gBS->FreePool (RawData);

    //
    // Allocate space for retrieval of IFR data
    //
    RawData = EfiLibAllocateZeroPool (RawDataLength);
    if (RawData == NULL) {
      return EFI_OUT_OF_RESOURCES;
    }

    //
    // Get all the forms associated with this HiiHandle
    //
    Status = Hii->GetForms (Hii, HiiHandle, 0, &RawDataLength, RawData);
  }

  OldData = RawData;

  //
  // Point RawData to the beginning of the form data
  //
  RawData = (UINT8 *) ((UINTN) RawData + sizeof (EFI_HII_PACK_HEADER));

  for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {
    if (RawData[Index] == EFI_IFR_FORM_SET_OP) {
      EfiCopyMem (&Guid, &((EFI_IFR_FORM_SET *) &RawData[Index])->Guid, sizeof (EFI_GUID));
      break;
    }

    Index = RawData[Index + 1] + Index;
  }

  for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {
    switch (RawData[Index]) {
    case EFI_IFR_FORM_SET_OP:
      break;

    case EFI_IFR_ONE_OF_OP:
    case EFI_IFR_CHECKBOX_OP:
    case EFI_IFR_NUMERIC_OP:
    case EFI_IFR_DATE_OP:
    case EFI_IFR_TIME_OP:
    case EFI_IFR_PASSWORD_OP:
    case EFI_IFR_STRING_OP:
      //
      // Remember, multiple op-codes may reference the same item, so let's keep a running
      // marker of what the highest QuestionId that wasn't zero length.  This will accurately
      // maintain the Size of the NvStore
      //
      if (((EFI_IFR_ONE_OF *) &RawData[Index])->Width != 0) {
        Temp = ((EFI_IFR_ONE_OF *) &RawData[Index])->QuestionId + ((EFI_IFR_ONE_OF *) &RawData[Index])->Width;
        if (SizeOfNvStore < Temp) {
          SizeOfNvStore = ((EFI_IFR_ONE_OF *) &RawData[Index])->QuestionId + ((EFI_IFR_ONE_OF *) &RawData[Index])->Width;
        }
      }
    }

    Index = RawData[Index + 1] + Index;
  }
    
  //
  // Allocate memory for our File Form Tags
  //
  VariableData = EfiLibAllocateZeroPool (SizeOfNvStore);
  if (VariableData == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  Status = gRT->GetVariable (
                  L"Setup",
                  &Guid,
                  NULL,
                  &SizeOfNvStore,
                  (VOID *) VariableData
                  );

  if (EFI_ERROR (Status)) {

    //
    // If there is a variable that exists already and it is larger than what we calculated the
    // storage needs to be, we must assume the variable size from GetVariable is correct and not
    // allow the truncation of the variable.  It is very possible that the user who created the IFR
    // we are cracking is not referring to a variable that was in a previous map, however we cannot
    // allow it's truncation.
    //
    if (Status == EFI_BUFFER_TOO_SMALL) {
      //
      // Free the buffer that was allocated that was too small
      //
      gBS->FreePool (VariableData);

      VariableData = EfiLibAllocatePool (SizeOfNvStore);
      if (VariableData == NULL) {
        return EFI_OUT_OF_RESOURCES;
      }

      Status = gRT->GetVariable (
                      L"Setup",
                      &Guid,
                      NULL,
                      &SizeOfNvStore,
                      (VOID *) VariableData
                      );
    }
  }

  //
  // Walk through the form and see that the variable data it refers to is ok.
  // This allows for the possibility of stale (obsoleted) data in the variable
  // can be overlooked without causing an error
  //
  for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {
    switch (RawData[Index]) {
    case EFI_IFR_ONE_OF_OP:
      //
      // A one_of has no data, its the option that does - cache the storage Id
      //
      CachedStart = ((EFI_IFR_ONE_OF *) &RawData[Index])->QuestionId;
      break;

    case EFI_IFR_ONE_OF_OPTION_OP:
      //
      // A one_of_option can be any value
      //
      if (VariableData[CachedStart] == ((EFI_IFR_ONE_OF_OPTION *) &RawData[Index])->Value) {
        GotMatch = TRUE;
      }
      break;

    case EFI_IFR_END_ONE_OF_OP:
      //
      // At this point lets make sure that the data value in the NVRAM matches one of the options
      //
      if (!GotMatch) {
        *Results = FALSE;
        return EFI_SUCCESS;
      }
      break;

    case EFI_IFR_CHECKBOX_OP:
      //
      // A checkbox is a boolean, so 0 and 1 are valid
      // Remember, QuestionId corresponds to the offset location of the data in the variable
      //
      if (VariableData[((EFI_IFR_CHECK_BOX *) &RawData[Index])->QuestionId] > 1) {
        *Results = FALSE;
        return EFI_SUCCESS;
      }
      break;

    case EFI_IFR_NUMERIC_OP:
        if ((VariableData[((EFI_IFR_NUMERIC *)&RawData[Index])->QuestionId] < ((EFI_IFR_NUMERIC *)&RawData[Index])->Minimum) ||
            (VariableData[((EFI_IFR_NUMERIC *)&RawData[Index])->QuestionId] > ((EFI_IFR_NUMERIC *)&RawData[Index])->Maximum)) {
        *Results = FALSE;
        return EFI_SUCCESS;
      }
      break;

    }

    Index = RawData[Index + 1] + Index;
  }

  //
  // Free our temporary repository of form data
  //
  gBS->FreePool (OldData);
  gBS->FreePool (VariableData);

  return EFI_SUCCESS;
}
示例#8
0
EFI_STATUS
ExtractDataFromHiiHandle (
  IN      EFI_HII_HANDLE      HiiHandle,
  IN OUT  UINT16              *ImageLength,
  OUT     UINT8               *DefaultImage,
  OUT     EFI_GUID            *Guid
  )
/*++

Routine Description:

  Extract information pertaining to the HiiHandle
  
Arguments:
  
  HiiHandle       - Hii handle
  
  ImageLength     - For input, length of DefaultImage;
                    For output, length of actually required
                    
  DefaultImage    - Image buffer prepared by caller
  
  Guid            - Guid information about the form
  
Returns: 

  EFI_OUT_OF_RESOURCES    - No enough buffer to allocate
  
  EFI_BUFFER_TOO_SMALL    - DefualtImage has no enough ImageLength
  
  EFI_SUCCESS             - Successfully extract data from Hii database.
  
  
--*/
{
  EFI_STATUS        Status;
  EFI_HII_PROTOCOL  *Hii;
  UINTN             DataLength;
  UINT8             *RawData;
  UINT8             *OldData;
  UINTN             Index;
  UINTN             Temp;
  UINTN             SizeOfNvStore;
  UINTN             CachedStart;

  DataLength    = DEFAULT_FORM_BUFFER_SIZE;
  SizeOfNvStore = 0;
  CachedStart   = 0;

  Status        = GetHiiInterface (&Hii);

  if (EFI_ERROR (Status)) {
    return Status;
  }

  //
  // Allocate space for retrieval of IFR data
  //
  RawData = EfiLibAllocateZeroPool ((UINTN) DataLength);
  if (RawData == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  //
  // Get all the forms associated with this HiiHandle
  //
  Status = Hii->GetForms (Hii, HiiHandle, 0, &DataLength, RawData);

  if (EFI_ERROR (Status)) {
    gBS->FreePool (RawData);

    //
    // Allocate space for retrieval of IFR data
    //
    RawData = EfiLibAllocateZeroPool ((UINTN) DataLength);
    if (RawData == NULL) {
      return EFI_OUT_OF_RESOURCES;
    }

    //
    // Get all the forms associated with this HiiHandle
    //
    Status = Hii->GetForms (Hii, HiiHandle, 0, &DataLength, RawData);
  }

  OldData = RawData;

  //
  // Point RawData to the beginning of the form data
  //
  RawData = (UINT8 *) ((UINTN) RawData + sizeof (EFI_HII_PACK_HEADER));

  for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {
    switch (RawData[Index]) {
    case EFI_IFR_FORM_SET_OP:
      //
      // Copy the GUID information from this handle
      //
      EfiCopyMem (Guid, &((EFI_IFR_FORM_SET *) &RawData[Index])->Guid, sizeof (EFI_GUID));
      break;

    case EFI_IFR_ONE_OF_OP:
    case EFI_IFR_CHECKBOX_OP:
    case EFI_IFR_NUMERIC_OP:
    case EFI_IFR_DATE_OP:
    case EFI_IFR_TIME_OP:
    case EFI_IFR_PASSWORD_OP:
    case EFI_IFR_STRING_OP:
      //
      // Remember, multiple op-codes may reference the same item, so let's keep a running
      // marker of what the highest QuestionId that wasn't zero length.  This will accurately
      // maintain the Size of the NvStore
      //
      if (((EFI_IFR_ONE_OF *) &RawData[Index])->Width != 0) {
        Temp = ((EFI_IFR_ONE_OF *) &RawData[Index])->QuestionId + ((EFI_IFR_ONE_OF *) &RawData[Index])->Width;
        if (SizeOfNvStore < Temp) {
          SizeOfNvStore = ((EFI_IFR_ONE_OF *) &RawData[Index])->QuestionId + ((EFI_IFR_ONE_OF *) &RawData[Index])->Width;
        }
      }
    }

    Index = RawData[Index + 1] + Index;
  }
    
  //
  // Return an error if buffer is too small
  //
  if (SizeOfNvStore > *ImageLength || DefaultImage == NULL) {
    gBS->FreePool (OldData);
    *ImageLength = (UINT16) SizeOfNvStore;
    return EFI_BUFFER_TOO_SMALL;
  }

  EfiZeroMem (DefaultImage, SizeOfNvStore);

  //
  // Copy the default image information to the user's buffer
  //
  for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {
    switch (RawData[Index]) {
    case EFI_IFR_ONE_OF_OP:
      CachedStart = ((EFI_IFR_ONE_OF *) &RawData[Index])->QuestionId;
      break;

    case EFI_IFR_ONE_OF_OPTION_OP:
      if (((EFI_IFR_ONE_OF_OPTION *) &RawData[Index])->Flags & EFI_IFR_FLAG_DEFAULT) {
        EfiCopyMem (&DefaultImage[CachedStart], &((EFI_IFR_ONE_OF_OPTION *) &RawData[Index])->Value, 2);
      }
      break;

    case EFI_IFR_CHECKBOX_OP:
      DefaultImage[((EFI_IFR_ONE_OF *) &RawData[Index])->QuestionId] = ((EFI_IFR_CHECK_BOX *) &RawData[Index])->Flags;
      break;

    case EFI_IFR_NUMERIC_OP:
      EfiCopyMem (
        &DefaultImage[((EFI_IFR_ONE_OF *) &RawData[Index])->QuestionId],
        &((EFI_IFR_NUMERIC *) &RawData[Index])->Default,
        2
        );
      break;

    }

    Index = RawData[Index + 1] + Index;
  }

  *ImageLength = (UINT16) SizeOfNvStore;

  //
  // Free our temporary repository of form data
  //
  gBS->FreePool (OldData);

  return EFI_SUCCESS;
}
示例#9
0
EFI_STATUS
AddOpCode (
  IN      VOID                *FormBuffer,
  IN OUT  VOID                *OpCodeData
  )
/*++

Routine Description:

  Add op-code data to the FormBuffer
  
Arguments:
  
  FormBuffer      - Form buffer to be inserted to
  
  OpCodeData      - Op-code data to be inserted
  
Returns: 

  EFI_OUT_OF_RESOURCES    - No enough buffer to allocate
  
  EFI_SUCCESS             - Op-code data successfully inserted

--*/
{
  EFI_HII_PACK_HEADER *NewBuffer;
  UINT8               *Source;
  UINT8               *Destination;

  //
  // Pre-allocate a buffer sufficient for us to work on.
  // We will use it as a destination scratch pad to build data on
  // and when complete shift the data back to the original buffer
  //
  NewBuffer = EfiLibAllocateZeroPool (DEFAULT_FORM_BUFFER_SIZE);
  if (NewBuffer == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  Source      = (UINT8 *) FormBuffer;
  Destination = (UINT8 *) NewBuffer;

  //
  // Copy the IFR Package header to the new buffer
  //
  EfiCopyMem (Destination, Source, sizeof (EFI_HII_PACK_HEADER));

  //
  // Advance Source and Destination to next op-code
  //
  Source      = Source + sizeof (EFI_HII_PACK_HEADER);
  Destination = Destination + sizeof (EFI_HII_PACK_HEADER);

  //
  // Copy data to the new buffer until we run into the end_form
  //
  for (; ((EFI_IFR_OP_HEADER *) Source)->OpCode != EFI_IFR_END_FORM_OP;) {
    //
    // If the this opcode is an end_form_set we better be creating and endform
    // Nonetheless, we will add data before the end_form_set.  This also provides
    // for interesting behavior in the code we will run, but has no bad side-effects
    // since we will possibly do a 0 byte copy in this particular end-case.
    //
    if (((EFI_IFR_OP_HEADER *) Source)->OpCode == EFI_IFR_END_FORM_SET_OP) {
      break;
    }

    //
    // Copy data to new buffer
    //
    EfiCopyMem (Destination, Source, ((EFI_IFR_OP_HEADER *) Source)->Length);

    //
    // Adjust Source/Destination to next op-code location
    //
    Destination = Destination + (UINTN) ((EFI_IFR_OP_HEADER *) Source)->Length;
    Source      = Source + (UINTN) ((EFI_IFR_OP_HEADER *) Source)->Length;
  }

  //
  // Prior to the end_form is where we insert the new op-code data
  //
  EfiCopyMem (Destination, OpCodeData, ((EFI_IFR_OP_HEADER *) OpCodeData)->Length);
  Destination       = Destination + (UINTN) ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;

  NewBuffer->Length = (UINT32) (NewBuffer->Length + (UINT32) (((EFI_IFR_OP_HEADER *) OpCodeData)->Length));

  //
  // Copy end-form data to new buffer
  //
  EfiCopyMem (Destination, Source, ((EFI_IFR_OP_HEADER *) Source)->Length);

  //
  // Adjust Source/Destination to next op-code location
  //
  Destination = Destination + (UINTN) ((EFI_IFR_OP_HEADER *) Source)->Length;
  Source      = Source + (UINTN) ((EFI_IFR_OP_HEADER *) Source)->Length;

  //
  // Copy end-formset data to new buffer
  //
  EfiCopyMem (Destination, Source, ((EFI_IFR_OP_HEADER *) Source)->Length);

  //
  // Zero out the original buffer and copy the updated data in the new buffer to the old buffer
  //
  EfiZeroMem (FormBuffer, DEFAULT_FORM_BUFFER_SIZE);
  EfiCopyMem (FormBuffer, NewBuffer, DEFAULT_FORM_BUFFER_SIZE);

  //
  // Free the newly created buffer since we don't need it anymore
  //
  gBS->FreePool (NewBuffer);
  return EFI_SUCCESS;
}
示例#10
0
文件: GetInfo.c 项目: Kohrara/edk
VOID
AlignmentItem (
  IN        CHAR16   *ControllerHandleName,
  IN        CHAR16   *PrefixString,
  IN OUT    CHAR16   **NewString
  )
/*++

Routine Description:
  Do controller item string swap and alignment if needed. The alignment is the length of PrefixString.
  Because controller device path is too long sometime and cannot be presented in one line,
  and the browser automatic swap will break the necessary alignment, so do some additional
  process  for the problem.

Arguments:
 ControllerHandleName - a pointer to the controller real device path string
 PrefixString- a pointer to the prefix string
 NewString - a pointer to the string which will be presented by the browser

Returns:
  None

--*/
{

  CHAR16                                    *PadString;
  UINTN                                     PtrIndex;
  UINTN                                     IndexOffset;
  UINTN                                     Width;
  CHAR16                                    *NewStringSwapped;
  UINTN                                     SwapLineNum;
  UINTN                                     SwapLine;

  //
  // Register the device name string and create item in set options page
  //
  *NewString = EfiLibAllocateZeroPool (EfiStrSize (ControllerHandleName) + EfiStrSize (PrefixString));
  EfiStrCat (*NewString, PrefixString);
  EfiStrCat (*NewString, ControllerHandleName);
  //
  // Add pad chars into the string  for string swap in set options page to solve following two issue:
  // Issue1: Our form browser will do the string swap according to the spaces in the string, so
  //              if a string is too long and without space in it, the string position will be ugly.
  //              The driver need add some spaces to control the swap in the long and no space string.
  // Issue2:  If browser find a space to do swap, it will not show any other space directly followed it in swap position.
  //                So if you want to use the space to do the alignment in swapped new line, you need add another char(e.g '.')  in it.
  // e.g. if the item max lenth is 5, then the following string need add some space and '.' to get right presentation
  // '12345678901234567890' --------> '      12345 .    67890 .    12345 .    67890' , and presentation is below
  // |     12345
  // |.    67890
  // |.    12345
  // |.    67890
  //
  if ((EfiStrLen (*NewString)/SWAP_LENGTH > 0) && (EfiStrLen (PrefixString) > 0)) {
    //
    // Prepare the pad string according to the PrefixString length
    // the pad string is string of ' ', except of the NO2 charater which is '.'
    //
    PadString = EfiLibAllocateZeroPool (EfiStrSize (PrefixString) + 2);
    for (PtrIndex = 0; PtrIndex < (EfiStrLen (PrefixString) + 1); PtrIndex++) {
      PadString[PtrIndex] = ' ';
    }
    PadString[1] = '.';

    Width = SWAP_LENGTH - EfiStrLen (PrefixString);
    SwapLineNum = EfiStrLen (ControllerHandleName)/Width;

    NewStringSwapped = EfiLibAllocateZeroPool (EfiStrSize (ControllerHandleName) +
                       EfiStrSize (PrefixString) +
                       SwapLineNum * EfiStrSize (PadString));
    ASSERT (NewStringSwapped != NULL);

    IndexOffset = 0;
    EfiStrCpy (NewStringSwapped, PrefixString);
    IndexOffset += EfiStrLen (PrefixString);

    for (SwapLine = 0; SwapLine < SwapLineNum; SwapLine++) {
      EfiStrnCpy (&NewStringSwapped[IndexOffset],
                  &ControllerHandleName[SwapLine * Width],
                  Width
                 );
      IndexOffset += Width;

      EfiStrnCpy (&NewStringSwapped[IndexOffset],
                  PadString,
                  EfiStrLen (PadString)
                 );
      IndexOffset += EfiStrLen (PadString);
    }
    EfiStrCat (NewStringSwapped, &ControllerHandleName[SwapLine * Width]);
    gBS->FreePool (PadString);
    gBS->FreePool (*NewString);
    *NewString = NewStringSwapped;
  }
  return;
}
示例#11
0
文件: GetInfo.c 项目: Kohrara/edk
EFI_STATUS
GetDeviceHandlesManagedByDriver (
  IN  EFI_HANDLE  DriverBindingHandle,
  OUT UINTN       *ControllerHandleCount,
  OUT EFI_HANDLE  **ControllerHandleBuffer
  )
/*++

Routine Description:
  Get all device handles which are being opened by a specific driver.
  The rountine will allocate pool buffer for the found device handles, and it is the caller's responsibility to safe
  free the buffer

Arguments:
  DriverBindingHandle - the handle of a driver which contains the binding protocol
  ControllerHandleCount - the number of available device handles returned in ControllerHandleBuffer
  ControllerHandleBuffer - a pointer to the buffer to return the array of device handles

Returns:
  EFI_STATUS
  If returned status is not succeful or find no available device , the *ControllerHandleBuffer will be NULL

--*/
{
  UINTN                               HandleCount;
  EFI_HANDLE                          *HandleBuffer;
  BOOLEAN                             *HandleBufferMap;
  EFI_STATUS                          Status;
  UINTN                               HandleIndex;
  UINTN                               AvailableIndex;
  EFI_GUID                            **ProtocolGuidArray;
  UINTN                               ArrayCount;
  UINTN                               ProtocolIndex;
  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
  UINTN                               OpenInfoCount;
  UINTN                               OpenInfoIndex;

  *ControllerHandleCount  = 0;
  *ControllerHandleBuffer = NULL;
  HandleCount = 0;
  HandleBuffer = NULL;

  if (DriverBindingHandle == NULL) {
    Status = EFI_INVALID_PARAMETER;
    goto Error;
  }

  //
  // Retrieve the list of all handles from the handle database
  //
  Status = gBS->LocateHandleBuffer (
                  AllHandles,
                  NULL,
                  NULL,
                  &HandleCount,
                  &HandleBuffer
                  );
  if (EFI_ERROR (Status)) {
    goto Error;
  }

  //
  //Create a map for HandleBuffer. If a handle in HandleBuffer is the wanted device handle, its map item is true.
  //
  HandleBufferMap = EfiLibAllocateZeroPool (sizeof (BOOLEAN) * HandleCount);
  ASSERT (HandleBufferMap != NULL);
  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
    HandleBufferMap[HandleIndex] = FALSE;
  }

  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
    //
    // Check if it is a device handle
    //
    Status = gBS->OpenProtocol (
                    HandleBuffer[HandleIndex],
                    &gEfiDevicePathProtocolGuid,
                    NULL,
                    NULL,
                    NULL,
                    EFI_OPEN_PROTOCOL_TEST_PROTOCOL
                    );
    if (EFI_ERROR (Status)) {
      continue;
    }
    //
    // Retrieve the list of all the protocols on each handle
    //
    Status = gBS->ProtocolsPerHandle (
                    HandleBuffer[HandleIndex],
                    &ProtocolGuidArray,
                    &ArrayCount
                    );

    if (!EFI_ERROR (Status)) {
      for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
        //
        // Retrieve the list of agents that have opened each protocol
        //
        Status = gBS->OpenProtocolInformation (
                        HandleBuffer[HandleIndex],
                        ProtocolGuidArray[ProtocolIndex],
                        &OpenInfo,
                        &OpenInfoCount
                        );
        if (!EFI_ERROR (Status)) {
          for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
            if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
              if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER)
                  == EFI_OPEN_PROTOCOL_BY_DRIVER
                 ){
                //
                // HandleBufferMap[HandleIndex] is the wanted device handle, find it in the handlebuffer
                // A bus driver maybe open a Controller with BY_DRIVER attribute for different protocol  many times,
                //
                HandleBufferMap[HandleIndex] = TRUE;
              }
            }
          }
          gBS->FreePool (OpenInfo);
        }
      }
      gBS->FreePool (ProtocolGuidArray);
    }
  }
  //
  // count how many device handles are found
  //
  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
    if (HandleBufferMap[HandleIndex]) {
      (*ControllerHandleCount)++;
    }
  }

  if (*ControllerHandleCount > 0) {
    //
    // Copy the found device handle to returned buffer
    //
    *ControllerHandleBuffer = EfiLibAllocateZeroPool (sizeof (EFI_HANDLE) * (*ControllerHandleCount));
    ASSERT (*ControllerHandleBuffer != NULL);
    for (HandleIndex = 0, AvailableIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
      if (HandleBufferMap[HandleIndex]) {
        (*ControllerHandleBuffer)[AvailableIndex] = HandleBuffer[HandleIndex];
        AvailableIndex++;
      }
    }
  }

  if (HandleBuffer != NULL) {
    gBS->FreePool (HandleBuffer);
  }

  return EFI_SUCCESS;

Error:

  if (HandleBuffer != NULL) {
    gBS->FreePool (HandleBuffer);
  }

  return Status;
}