Пример #1
0
EFI_GUID *
StslGuidsDuplicate (
  IN EFI_GUID           *Guids
  )
{
  EFI_STATUS  Status;
  UINTN       NoGuids;
  EFI_GUID    *Guid;
  EFI_GUID    *Buffer;

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

  NoGuids = 0;
  Guid    = Guids;

  while (EfiCompareMem (Guid, &gEfiNullGuid, sizeof(EFI_GUID)) != 0) {
    NoGuids ++;
    Guid ++;
  }

  Status = gBS->AllocatePool (
                  EfiBootServicesData,
                  (NoGuids + 1) * sizeof(EFI_GUID),
                  &Buffer
                  );
  if (EFI_ERROR (Status)) {
    return NULL;
  }

  EfiCopyMem (Buffer, Guids, (NoGuids + 1) * sizeof(EFI_GUID));

  return Buffer;
}
Пример #2
0
BOOLEAN
RetrieveUartUid (
    IN EFI_HANDLE   Handle,
    IN OUT UINT32   *AcpiUid
)
/*++

Routine Description:
  Retrieve ACPI UID of UART from device path

Arguments:
  Handles   -   EFI_SERIAL_IO_PROTOCOL handle

Returns:
  TRUE  - Find valid UID from device path
  FALSE - Can't find

--*/
{
    UINT32                    Match;
    UINT8                     *Ptr;
    ACPI_HID_DEVICE_PATH      *Acpi;
    EFI_DEVICE_PATH_PROTOCOL  *DevicePath;

    gBS->HandleProtocol (
        Handle,
        &gEfiDevicePathProtocolGuid,
        &DevicePath
    );
    Ptr = (UINT8 *) DevicePath;

    while (*Ptr != END_DEVICE_PATH_TYPE) {
        Ptr++;
    }

    Ptr   = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH);
    Acpi  = (ACPI_HID_DEVICE_PATH *) Ptr;
    Match = EISA_PNP_ID (0x0501);

    if (EfiCompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
        if (AcpiUid != NULL) {
            *AcpiUid = Acpi->UID;
        }
        return TRUE;
    } else {
        return FALSE;
    }
}
/**
 *  @brief This function caculates the number of supported languages
 *  @param SupportedLanguges This a string indicating supported languages
 *  @param NextHandle This a point indicating starting position in IsoLatin table
 *  @param UnsupportedLangugeCode This a string containing returned unsupported language code
 *  @return EFI_SUCESS
 *  @return EFI_NOT_FOUND
 */
STATIC
EFI_STATUS
SearchNextUnsupportedLanguageCode (
  IN OUT CHAR8         *SupportedLanguageCodeList,
  IN OUT UINTN         *NextHandle,
     OUT CHAR8         *UnsupportedLanguageCode
  )
{
  UINTN                 TableItem;
  UINTN                 StartIndex;
  UINTN                 SupportedNumber;
  CHAR8                 *Pointer;
  UINTN                 Indexi, Indexj;

  StartIndex = *NextHandle;

  TableItem = sizeof (IsoLatinTable) / sizeof (*IsoLatinTable);

  if (StartIndex >= TableItem) {
    return EFI_NOT_FOUND;
  }

  SupportedNumber = GetNumberOfSupportedLanguages (SupportedLanguageCodeList);

  for (Indexi = StartIndex; Indexi < TableItem; Indexi++) {

    Pointer = SupportedLanguageCodeList;
    for (Indexj = 0; Indexj < SupportedNumber; Indexj++) {
      if (EfiCompareMem (Pointer, IsoLatinTable[Indexi], 3) == 0) {
        break ;
      }
      Pointer += 3;
    }

    if(SupportedNumber == Indexj){
      *NextHandle = Indexi + 1;
      gtBS->CopyMem (UnsupportedLanguageCode, IsoLatinTable[Indexi], 3);
      return EFI_SUCCESS;
    }

  }

  return EFI_NOT_FOUND;
}
Пример #4
0
BOOLEAN
IsTerminalDevicePath (
    IN  EFI_DEVICE_PATH_PROTOCOL *DevicePath,
    OUT TYPE_OF_TERMINAL         *Termi,
    OUT UINTN                    *Com
)
/*++

Routine Description:
  Test whether DevicePath is a valid Terminal

Arguments:
  DevicePath  -   DevicePath to be checked
  Termi       -   If is terminal, give its type
  Com         -   If is Com Port, give its type

Returns:
  TRUE        -   If DevicePath point to a Terminal
  FALSE

--*/
{
    UINT8                 *Ptr;
    BOOLEAN               IsTerminal;
    VENDOR_DEVICE_PATH    *Vendor;
    ACPI_HID_DEVICE_PATH  *Acpi;
    UINT32                Match;
    EFI_GUID              TempGuid;

    IsTerminal = FALSE;

    //
    // Parse the Device Path, should be change later!!!
    //
    Ptr = (UINT8 *) DevicePath;
    while (*Ptr != END_DEVICE_PATH_TYPE) {
        Ptr++;
    }

    Ptr     = Ptr - sizeof (VENDOR_DEVICE_PATH);
    Vendor  = (VENDOR_DEVICE_PATH *) Ptr;

    //
    // There are four kinds of Terminal types
    // check to see whether this devicepath
    // is one of that type
    //
    EfiCopyMem (&TempGuid, &Vendor->Guid, sizeof (EFI_GUID));

    if (EfiCompareGuid (&TempGuid, &Guid[0])) {
        *Termi      = PC_ANSI;
        IsTerminal  = TRUE;
    } else {
        if (EfiCompareGuid (&TempGuid, &Guid[1])) {
            *Termi      = VT_100;
            IsTerminal  = TRUE;
        } else {
            if (EfiCompareGuid (&TempGuid, &Guid[2])) {
                *Termi      = VT_100_PLUS;
                IsTerminal  = TRUE;
            } else {
                if (EfiCompareGuid (&TempGuid, &Guid[3])) {
                    *Termi      = VT_UTF8;
                    IsTerminal  = TRUE;
                } else {
                    IsTerminal = FALSE;
                }
            }
        }
    }

    if (!IsTerminal) {
        return FALSE;
    }

    Ptr   = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH);
    Acpi  = (ACPI_HID_DEVICE_PATH *) Ptr;
    Match = EISA_PNP_ID (0x0501);
    if (EfiCompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
        EfiCopyMem (Com, &Acpi->UID, sizeof (UINT32));
    } else {
        return FALSE;
    }

    return TRUE;
}
Пример #5
0
EFI_STATUS
UpdateComAttributeFromVariable (
    EFI_DEVICE_PATH_PROTOCOL  *DevicePath
)
/*++

Routine Description:
  Update Com Ports attributes from DevicePath

Arguments:
  DevicePath  -   DevicePath that contains Com ports

Returns:

--*/
{
    EFI_DEVICE_PATH_PROTOCOL  *Node;
    EFI_DEVICE_PATH_PROTOCOL  *SerialNode;
    ACPI_HID_DEVICE_PATH      *Acpi;
    UART_DEVICE_PATH          *Uart;
    UART_DEVICE_PATH          *Uart1;
    UINT32                    Match;
    UINTN                     TerminalNumber;
    BM_MENU_ENTRY             *NewMenuEntry;
    BM_TERMINAL_CONTEXT       *NewTerminalContext;
    UINTN                     Index;

    Match           = EISA_PNP_ID (0x0501);
    Node            = DevicePath;
    Node            = NextDevicePathNode (Node);
    TerminalNumber  = 0;
    for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
        while (!IsDevicePathEnd (Node)) {
            if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) {
                Acpi = (ACPI_HID_DEVICE_PATH *) Node;
                if (EfiCompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
                    EfiCopyMem (&TerminalNumber, &Acpi->UID, sizeof (UINT32));
                }
            }

            if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
                Uart          = (UART_DEVICE_PATH *) Node;
                NewMenuEntry  = BOpt_GetMenuEntry (&TerminalMenu, TerminalNumber);
                if (NULL == NewMenuEntry) {
                    return EFI_NOT_FOUND;
                }

                NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
                EfiCopyMem (
                    &NewTerminalContext->BaudRate,
                    &Uart->BaudRate,
                    sizeof (UINT64)
                );

                EfiCopyMem (
                    &NewTerminalContext->DataBits,
                    &Uart->DataBits,
                    sizeof (UINT8)
                );

                EfiCopyMem (
                    &NewTerminalContext->Parity,
                    &Uart->Parity,
                    sizeof (UINT8)
                );

                EfiCopyMem (
                    &NewTerminalContext->StopBits,
                    &Uart->StopBits,
                    sizeof (UINT8)
                );

                SerialNode  = NewTerminalContext->DevicePath;
                SerialNode  = NextDevicePathNode (SerialNode);
                while (!IsDevicePathEnd (SerialNode)) {
                    if ((DevicePathType (SerialNode) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (SerialNode) == MSG_UART_DP)) {
                        //
                        // Update following device paths according to
                        // previous acquired uart attributes
                        //
                        Uart1 = (UART_DEVICE_PATH *) SerialNode;
                        EfiCopyMem (
                            &Uart1->BaudRate,
                            &NewTerminalContext->BaudRate,
                            sizeof (UINT64)
                        );

                        EfiCopyMem (
                            &Uart1->DataBits,
                            &NewTerminalContext->DataBits,
                            sizeof (UINT8)
                        );
                        EfiCopyMem (
                            &Uart1->Parity,
                            &NewTerminalContext->Parity,
                            sizeof (UINT8)
                        );
                        EfiCopyMem (
                            &Uart1->StopBits,
                            &NewTerminalContext->StopBits,
                            sizeof (UINT8)
                        );

                        break;
                    }

                    SerialNode = NextDevicePathNode (SerialNode);
                }
                //
                // end while
                //
            }

            Node = NextDevicePathNode (Node);
        }
        //
        // end while
        //
    }

    return EFI_SUCCESS;
}
Пример #6
0
EFI_STATUS
ChangeTerminalDevicePath (
    EFI_DEVICE_PATH_PROTOCOL  *DevicePath,
    BOOLEAN                   ChangeTerminal
)
{
    EFI_DEVICE_PATH_PROTOCOL  *Node;
    EFI_DEVICE_PATH_PROTOCOL  *Node1;
    ACPI_HID_DEVICE_PATH      *Acpi;
    UART_DEVICE_PATH          *Uart;
    UART_DEVICE_PATH          *Uart1;
    UINTN                     Com;
    UINT32                    Match;
    BM_TERMINAL_CONTEXT       *NewTerminalContext;
    BM_MENU_ENTRY             *NewMenuEntry;

    Match = EISA_PNP_ID (0x0501);
    Node  = DevicePath;
    Node  = NextDevicePathNode (Node);
    Com   = 0;
    while (!IsDevicePathEnd (Node)) {
        if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) {
            Acpi = (ACPI_HID_DEVICE_PATH *) Node;
            if (EfiCompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
                EfiCopyMem (&Com, &Acpi->UID, sizeof (UINT32));
            }
        }

        NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Com);
        if (NULL == NewMenuEntry) {
            return EFI_NOT_FOUND;
        }

        NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
        if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
            Uart = (UART_DEVICE_PATH *) Node;
            EfiCopyMem (
                &Uart->BaudRate,
                &NewTerminalContext->BaudRate,
                sizeof (UINT64)
            );

            EfiCopyMem (
                &Uart->DataBits,
                &NewTerminalContext->DataBits,
                sizeof (UINT8)
            );

            EfiCopyMem (
                &Uart->Parity,
                &NewTerminalContext->Parity,
                sizeof (UINT8)
            );

            EfiCopyMem (
                &Uart->StopBits,
                &NewTerminalContext->StopBits,
                sizeof (UINT8)
            );
            //
            // Change the device path in the ComPort
            //
            if (ChangeTerminal) {
                Node1 = NewTerminalContext->DevicePath;
                Node1 = NextDevicePathNode (Node1);
                while (!IsDevicePathEnd (Node1)) {
                    if ((DevicePathType (Node1) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node1) == MSG_UART_DP)) {
                        Uart1 = (UART_DEVICE_PATH *) Node1;
                        EfiCopyMem (
                            &Uart1->BaudRate,
                            &NewTerminalContext->BaudRate,
                            sizeof (UINT64)
                        );

                        EfiCopyMem (
                            &Uart1->DataBits,
                            &NewTerminalContext->DataBits,
                            sizeof (UINT8)
                        );

                        EfiCopyMem (
                            &Uart1->Parity,
                            &NewTerminalContext->Parity,
                            sizeof (UINT8)
                        );

                        EfiCopyMem (
                            &Uart1->StopBits,
                            &NewTerminalContext->StopBits,
                            sizeof (UINT8)
                        );
                        break;
                    }
                    //
                    // end if
                    //
                    Node1 = NextDevicePathNode (Node1);
                }
                //
                // end while
                //
                break;
            }
        }

        Node = NextDevicePathNode (Node);
    }

    return EFI_SUCCESS;

}
Пример #7
0
EFI_STATUS
LocateSerialIo (
    VOID
)
/*++

Routine Description:
  Build a list containing all serial devices

Arguments:

Returns:

--*/
{
    UINT8                     *Ptr;
    UINTN                     Index;
    UINTN                     Index2;
    UINTN                     NoHandles;
    EFI_HANDLE                *Handles;
    EFI_STATUS                Status;
    ACPI_HID_DEVICE_PATH      *Acpi;
    EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
    UINT32                    Match;
    EFI_SERIAL_IO_PROTOCOL    *SerialIo;
    EFI_DEVICE_PATH_PROTOCOL  *OutDevicePath;
    EFI_DEVICE_PATH_PROTOCOL  *InpDevicePath;
    EFI_DEVICE_PATH_PROTOCOL  *ErrDevicePath;
    BM_MENU_ENTRY             *NewMenuEntry;
    BM_TERMINAL_CONTEXT       *NewTerminalContext;
    EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;
    VENDOR_DEVICE_PATH        Vendor;
    //
    // Get all handles that have SerialIo protocol installed
    //
    InitializeListHead (&TerminalMenu.Head);
    TerminalMenu.MenuNumber = 0;
    Status = gBS->LocateHandleBuffer (
                 ByProtocol,
                 &gEfiSerialIoProtocolGuid,
                 NULL,
                 &NoHandles,
                 &Handles
             );
    if (EFI_ERROR (Status)) {
        //
        // No serial ports present
        //
        return EFI_UNSUPPORTED;
    }

    //
    // Sort Uart handles array with Acpi->UID from low to high
    // then Terminal menu can be built from low Acpi->UID to high Acpi->UID
    //
    SortedUartHandle (Handles, NoHandles);

    for (Index = 0; Index < NoHandles; Index++) {
        //
        // Check to see whether the handle has DevicePath Protocol installed
        //
        gBS->HandleProtocol (
            Handles[Index],
            &gEfiDevicePathProtocolGuid,
            &DevicePath
        );
        Ptr = (UINT8 *) DevicePath;
        while (*Ptr != END_DEVICE_PATH_TYPE) {
            Ptr++;
        }

        Ptr   = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH);
        Acpi  = (ACPI_HID_DEVICE_PATH *) Ptr;
        Match = EISA_PNP_ID (0x0501);

        if (EfiCompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
            NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT);
            if (!NewMenuEntry) {
                SafeFreePool (Handles);
                return EFI_OUT_OF_RESOURCES;
            }

            NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
            EfiCopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32));
            NewTerminalContext->DevicePath = DevicePathInstanceDup (DevicePath);
            //
            // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system!
            // coz' the misc data for each platform is not correct, actually it's the device path stored in
            // datahub which is not completed, so a searching for end of device path will enter a
            // dead-loop.
            //
            NewMenuEntry->DisplayString = EfiLibStrFromDatahub (DevicePath);
            if (NULL == NewMenuEntry->DisplayString) {
                NewMenuEntry->DisplayString = DevicePathToStr (DevicePath);
            }

            NewMenuEntry->HelpString = NULL;

            gBS->HandleProtocol (
                Handles[Index],
                &gEfiSerialIoProtocolGuid,
                &SerialIo
            );

            EfiCopyMem (
                &NewTerminalContext->BaudRate,
                &SerialIo->Mode->BaudRate,
                sizeof (UINT64)
            );

            EfiCopyMem (
                &NewTerminalContext->DataBits,
                &SerialIo->Mode->DataBits,
                sizeof (UINT8)
            );

            EfiCopyMem (
                &NewTerminalContext->Parity,
                &SerialIo->Mode->Parity,
                sizeof (UINT8)
            );

            EfiCopyMem (
                &NewTerminalContext->StopBits,
                &SerialIo->Mode->StopBits,
                sizeof (UINT8)
            );
            InsertTailList (&TerminalMenu.Head, &NewMenuEntry->Link);
            TerminalMenu.MenuNumber++;
        }
    }
    SafeFreePool (Handles);

    //
    // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var
    //
    OutDevicePath = EfiLibGetVariable (L"ConOut", &gEfiGlobalVariableGuid);
    InpDevicePath = EfiLibGetVariable (L"ConIn", &gEfiGlobalVariableGuid);
    ErrDevicePath = EfiLibGetVariable (L"ErrOut", &gEfiGlobalVariableGuid);
    if (OutDevicePath) {
        UpdateComAttributeFromVariable (OutDevicePath);
    }

    if (InpDevicePath) {
        UpdateComAttributeFromVariable (InpDevicePath);
    }

    if (ErrDevicePath) {
        UpdateComAttributeFromVariable (ErrDevicePath);
    }

    for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
        NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
        if (NULL == NewMenuEntry) {
            return EFI_NOT_FOUND;
        }

        NewTerminalContext                = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;

        NewTerminalContext->TerminalType  = 0;
        NewTerminalContext->IsConIn       = FALSE;
        NewTerminalContext->IsConOut      = FALSE;
        NewTerminalContext->IsStdErr      = FALSE;

        Vendor.Header.Type                = MESSAGING_DEVICE_PATH;
        Vendor.Header.SubType             = MSG_VENDOR_DP;

        for (Index2 = 0; Index2 < 4; Index2++) {
            EfiCopyMem (&Vendor.Guid, &Guid[Index2], sizeof (EFI_GUID));
            SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH));
            NewDevicePath = EfiAppendDevicePathNode (
                                NewTerminalContext->DevicePath,
                                (EFI_DEVICE_PATH_PROTOCOL *) &Vendor
                            );
            SafeFreePool (NewMenuEntry->HelpString);
            //
            // NewMenuEntry->HelpString = DevicePathToStr (NewDevicePath);
            // NewMenuEntry->DisplayString = NewMenuEntry->HelpString;
            //
            NewMenuEntry->HelpString = NULL;

            if (BdsLibMatchDevicePaths (OutDevicePath, NewDevicePath)) {
                NewTerminalContext->IsConOut      = TRUE;
                NewTerminalContext->TerminalType  = (UINT8) Index2;
            }

            if (BdsLibMatchDevicePaths (InpDevicePath, NewDevicePath)) {
                NewTerminalContext->IsConIn       = TRUE;
                NewTerminalContext->TerminalType  = (UINT8) Index2;
            }

            if (BdsLibMatchDevicePaths (ErrDevicePath, NewDevicePath)) {
                NewTerminalContext->IsStdErr      = TRUE;
                NewTerminalContext->TerminalType  = (UINT8) Index2;
            }
        }
    }

    return EFI_SUCCESS;
}
Пример #8
0
VOID
ChangeVariableDevicePath (
    EFI_DEVICE_PATH_PROTOCOL  *DevicePath
)
{
    EFI_DEVICE_PATH_PROTOCOL  *Node;
    ACPI_HID_DEVICE_PATH      *Acpi;
    UART_DEVICE_PATH          *Uart;
    UINTN                     Com;
    UINT32                    Match;
    BM_TERMINAL_CONTEXT       *NewTerminalContext;
    BM_MENU_ENTRY             *NewMenuEntry;

    Match = EISA_PNP_ID (0x0501);
    Node  = DevicePath;
    Node  = NextDevicePathNode (Node);
    Com   = 0;
    while (!IsDevicePathEnd (Node)) {
        if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) {
            Acpi = (ACPI_HID_DEVICE_PATH *) Node;
            if (EfiCompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
                EfiCopyMem (&Com, &Acpi->UID, sizeof (UINT32));
            }
        }

        if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
            NewMenuEntry = BOpt_GetMenuEntry (
                               &TerminalMenu,
                               Com
                           );
            ASSERT (NewMenuEntry != NULL);
            NewTerminalContext  = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
            Uart                = (UART_DEVICE_PATH *) Node;
            EfiCopyMem (
                &Uart->BaudRate,
                &NewTerminalContext->BaudRate,
                sizeof (UINT64)
            );

            EfiCopyMem (
                &Uart->DataBits,
                &NewTerminalContext->DataBits,
                sizeof (UINT8)
            );

            EfiCopyMem (
                &Uart->Parity,
                &NewTerminalContext->Parity,
                sizeof (UINT8)
            );

            EfiCopyMem (
                &Uart->StopBits,
                &NewTerminalContext->StopBits,
                sizeof (UINT8)
            );
        }

        Node = NextDevicePathNode (Node);
    }

    return ;
}
Пример #9
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;

  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
    //
    StringPackBuffer->Header.Length = (UINT32)
      (
        sizeof (EFI_HII_STRING_PACK) -
        sizeof (EFI_STRING) +
        sizeof (RELOFST) +
        sizeof (RELOFST) +
        EfiStrSize (Language) +
        EfiStrSize (String)
      );
    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;
}
//
// TDS 3.4.2
//
EFI_STATUS
DevicePathUtilitiesAppendDeviceNodeConformanceTest (
  IN EFI_BB_TEST_PROTOCOL       *This,
  IN VOID                       *ClientInterface,
  IN EFI_TEST_LEVEL             TestLevel,
  IN EFI_HANDLE                 SupportHandle
  )
{
  EFI_STANDARD_TEST_LIBRARY_PROTOCOL  *StandardLib;
  EFI_STATUS                          Status;
  EFI_DEVICE_PATH_UTILITIES_PROTOCOL  *DevicePathUtilities;
  EFI_TEST_ASSERTION                  AssertionType;
  EFI_DEVICE_PATH_PROTOCOL            *pDevicePath1;
  EFI_DEVICE_PATH_PROTOCOL            *pDevicePath2;
  EFI_DEVICE_PATH_PROTOCOL            *pDevicePath3;
  EFI_DEVICE_PATH_PROTOCOL            *pDevicePath4;

  //
  // Get the Standard Library Interface
  //
  Status = gtBS->HandleProtocol (
                  SupportHandle,
                  &gEfiStandardTestLibraryGuid,
                  &StandardLib
                  );

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

  DevicePathUtilities = (EFI_DEVICE_PATH_UTILITIES_PROTOCOL *) ClientInterface;

  //
  // TDS 3.4.2.2.1
  //
  pDevicePath1 = (EFI_DEVICE_PATH *) AllocatePool (END_DEVICE_PATH_LENGTH);
  if (pDevicePath1 == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }
  SetDevicePathEndNode (pDevicePath1);

  pDevicePath2  = DevicePathUtilities->CreateDeviceNode (PCIRootNodeType, PCIRootNodeSubType, PCIRootNodeLength);
  pDevicePath4  = DevicePathUtilities->AppendDeviceNode (pDevicePath1, pDevicePath2);

  pDevicePath3  = DevicePathUtilities->AppendDeviceNode (NULL, pDevicePath2);
  if ((pDevicePath3 != NULL) && (EfiCompareMem(pDevicePath3, pDevicePath4, DevicePathUtilities->GetDevicePathSize (pDevicePath3)) == 0)) {
    AssertionType = EFI_TEST_ASSERTION_PASSED;
  } else {
    AssertionType = EFI_TEST_ASSERTION_FAILED;
  }

  if (pDevicePath3 != NULL) {
    FreePool (pDevicePath3);
  }

  StandardLib->RecordAssertion (
                StandardLib,
                AssertionType,
                gDevicePathUtilitiesBBTestFunctionAssertionGuid054,
                L"EFI_DEVICE_PATH_UTILITIES_PROTOCOL - AppendDeviceNode should return a copy of DeviceNode if DevicePath is NULL",
                L"%a:%d",
                __FILE__,
                (UINTN)__LINE__
                );

  //
  // TDS 3.4.2.2.2
  //
  pDevicePath3 = DevicePathUtilities->AppendDeviceNode (pDevicePath4, NULL);
  if ((pDevicePath3 != NULL) && (EfiCompareMem(pDevicePath3, pDevicePath4, DevicePathUtilities->GetDevicePathSize (pDevicePath3)) == 0)) {
    AssertionType = EFI_TEST_ASSERTION_PASSED;
  } else {
    AssertionType = EFI_TEST_ASSERTION_FAILED;
  }

  if (pDevicePath2 != NULL) {
    FreePool(pDevicePath2);
  }
  if (pDevicePath3 != NULL) {
    FreePool(pDevicePath3);
  }
  if (pDevicePath4 != NULL) {
    FreePool(pDevicePath4);
  }

  StandardLib->RecordAssertion (
                StandardLib,
                AssertionType,
                gDevicePathUtilitiesBBTestFunctionAssertionGuid055,
                L"EFI_DEVICE_PATH_UTILITIES_PROTOCOL - AppendDeviceNode should return a copy of DevicePath if DeviceNode is NULL",
                L"%a:%d",
                __FILE__,
                (UINTN)__LINE__
                );

  pDevicePath3 = DevicePathUtilities->AppendDeviceNode (NULL, NULL);
  if ((pDevicePath3 != NULL) && (EfiCompareMem(pDevicePath3, pDevicePath1, DevicePathUtilities->GetDevicePathSize (pDevicePath3)) == 0)) {
    AssertionType = EFI_TEST_ASSERTION_PASSED;
  } else {
    AssertionType = EFI_TEST_ASSERTION_FAILED;
  }

  FreePool(pDevicePath1);
  if (pDevicePath3 != NULL) {
    FreePool(pDevicePath3);
  }

  StandardLib->RecordAssertion (
                StandardLib,
                AssertionType,
                gDevicePathUtilitiesBBTestFunctionAssertionGuid069,
                L"EFI_DEVICE_PATH_UTILITIES_PROTOCOL - AppendDeviceNode should return end-of-device-path device node if both DevicePath and DeviceNode are NULL",
                L"%a:%d",
                __FILE__,
                (UINTN)__LINE__
                );

  return EFI_SUCCESS;
}
//
// TDS 4.2.2
//
EFI_STATUS
BBTestSetModeConformanceAutoTest (
  IN EFI_BB_TEST_PROTOCOL       *This,
  IN VOID                       *ClientInterface,
  IN EFI_TEST_LEVEL             TestLevel,
  IN EFI_HANDLE                 SupportHandle
  )
/*++

Routine Description:

  Entrypoint for EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode() Conformance Test

Arguments:

  This            - A pointer of EFI_BB_TEST_PROTOCOL
  ClientInterface - A pointer to the interface to be tested
  TestLevel       - Test "thoroughness" control
  SupportHandle   - A handle containing protocols required

Returns:

  EFI_SUCCESS - Finish the test successfully

--*/
{
  EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib;
  EFI_STATUS                            Status;
  EFI_GRAPHICS_OUTPUT_PROTOCOL          *GraphicsOutput;

  EFI_TEST_ASSERTION                    AssertionType;

  UINT32                                Index;

  UINT32                                CurrentMode;
  UINT32                                MaxMode;
  UINTN                                 sizeofInfo;
  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *info;

  GraphicsOutput  = (EFI_GRAPHICS_OUTPUT_PROTOCOL *) ClientInterface;

  CurrentMode     = GraphicsOutput->Mode->Mode;

  if ((Status = InitTestEnv (SupportHandle, &StandardLib, GraphicsOutput)) != EFI_SUCCESS) {
    return Status;

  }
  //
  // Assertion Point
  //
  //
  MaxMode = GraphicsOutput->Mode->MaxMode;
  for (Index = 0; Index < MaxMode; Index++) {

    Status = GraphicsOutput->SetMode (
                              GraphicsOutput,
                              Index
                              );

    if (Status == EFI_UNSUPPORTED) {
      AssertionType = EFI_TEST_ASSERTION_FAILED;
    } else {
      AssertionType = EFI_TEST_ASSERTION_PASSED;
    }

    StandardLib->RecordAssertion (
                   StandardLib,
                   AssertionType,
                   gGraphicsOutputSetModeConformanceTestAssertionGuid001,
                   L"EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode - SetMode() with valid mode",
                   L"%a:%d: mode:%d,Status = %r,Expected = not EFI_UNSUPPORTED ",
                   __FILE__,
                   (UINTN)__LINE__,
                   Index,
                   Status
                   );
    //
    // Check the content of info
    //
    if (Status == EFI_SUCCESS) {
      sizeofInfo = 0;
      info       = NULL;
      Status = GraphicsOutput->QueryMode (
                                 GraphicsOutput,
                                 Index,
                                 &sizeofInfo,
                                 &info
                                 );
      if (Status != EFI_SUCCESS) {
        AssertionType = EFI_TEST_ASSERTION_FAILED;
      }   else {
        AssertionType = EFI_TEST_ASSERTION_PASSED;
      }

      if (EfiCompareMem (
          (void *) info,
          (void *) GraphicsOutput->Mode->Info,
          sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION)
          ) != 0) {
        AssertionType = EFI_TEST_ASSERTION_FAILED;
      }

      if (info != NULL) {
        StandardLib->RecordAssertion (
                       StandardLib,
                       AssertionType,
                       gGraphicsOutputSetModeConformanceTestAssertionGuid002,
                       L"EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode - SetMode() then QueryMode(), compare Info structure",
                       L"%a:%d: dump of query result:ver:%d, hRes:%d, VRes:%d, PixelFmt:%d, RMsk:%x,GMsk:%x,BMsk:%x,ReserveMask:%x,PixelPerScanline:%d\n dump of GOP->Info:ver:%d, hRes:%d, VRes:%d, PixelFmt:%d, RMsk:%x,GMsk:%x,BMsk:%x,ReserveMask:%x,PixelPerScanline:%d",
                       (UINTN) __FILE__,
                       (UINTN) (UINTN)__LINE__,
                       (UINTN) info->Version,
                       (UINTN) info->HorizontalResolution,
                       (UINTN) info->VerticalResolution,
                       (UINTN) info->PixelFormat,
                       (UINTN) info->PixelInformation.RedMask,
                       (UINTN) info->PixelInformation.GreenMask,
                       (UINTN) info->PixelInformation.BlueMask,
                       (UINTN) info->PixelInformation.ReservedMask,
                       (UINTN) info->PixelsPerScanLine,
                       (UINTN) GraphicsOutput->Mode->Info->Version,
                       (UINTN) GraphicsOutput->Mode->Info->HorizontalResolution,
                       (UINTN) GraphicsOutput->Mode->Info->VerticalResolution,
                       (UINTN) GraphicsOutput->Mode->Info->PixelFormat,
                       (UINTN) GraphicsOutput->Mode->Info->PixelInformation.RedMask,
                       (UINTN) GraphicsOutput->Mode->Info->PixelInformation.GreenMask,
                       (UINTN) GraphicsOutput->Mode->Info->PixelInformation.BlueMask,
                       (UINTN) GraphicsOutput->Mode->Info->PixelInformation.ReservedMask,
                       (UINTN) GraphicsOutput->Mode->Info->PixelsPerScanLine
                       );
        gtBS->FreePool(info);
      }
    }
  }

  Status = GraphicsOutput->SetMode (
                            GraphicsOutput,
                            MaxMode
                            );

  if (Status != EFI_UNSUPPORTED) {
    AssertionType = EFI_TEST_ASSERTION_FAILED;
  } else {
    AssertionType = EFI_TEST_ASSERTION_PASSED;
  }

  StandardLib->RecordAssertion (
                 StandardLib,
                 AssertionType,
                 gGraphicsOutputSetModeConformanceTestAssertionGuid003,
                 L"EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode - SetMode() with invalid (max)mode",
                 L"%a:%d: mode:%d,Status = %r,Expected =  EFI_UNSUPPORTED ",
                 __FILE__,
                 (UINTN)__LINE__,
                 MaxMode,
                 Status
                 );

  //
  // restore
  // restore the orignal Mode
  //
  Status = GraphicsOutput->SetMode (GraphicsOutput, CurrentMode);

  if (Status == EFI_SUCCESS) {
    AssertionType = EFI_TEST_ASSERTION_PASSED;
  } else {
    AssertionType = EFI_TEST_ASSERTION_FAILED;
  }

  StandardLib->RecordAssertion (
                 StandardLib,
                 AssertionType,
                 gTestGenericFailureGuid,
                 L"EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode - SetMode() Function Test,restore the orignal Mode",
                 L"%a:%d:Status:%r, Expected:EFI_SUCCESS",
                 __FILE__,
                 (UINTN)__LINE__,
                 Status
                 );

  return EFI_SUCCESS;
}
Пример #12
0
EFI_STATUS
PartitionInstallElToritoChildHandles (
  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
  IN  EFI_HANDLE                   Handle,
  IN  EFI_DISK_IO_PROTOCOL         *DiskIo,
  IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,
  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath
  )
/*++

Routine Description:
  Install child handles if the Handle supports El Torito format.

Arguments:
  This       - Calling context.       
  Handle     - Parent Handle 
  DiskIo     - Parent DiskIo interface
  BlockIo    - Parent BlockIo interface
  DevicePath - Parent Device Path

Returns:
  EFI_SUCCESS       - some child handle(s) was added
  EFI_MEDIA_CHANGED - Media changed Detected
  !EFI_SUCCESS      - no child handle was added

--*/
{
  EFI_STATUS              Status;
  UINT32                  VolDescriptorLba;
  UINT32                  Lba;
  EFI_BLOCK_IO_MEDIA      *Media;
  CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
  ELTORITO_CATALOG        *Catalog;
  UINTN                   Check;
  UINTN                   Index;
  UINTN                   BootEntry;
  UINTN                   MaxIndex;
  UINT16                  *CheckBuffer;
  CDROM_DEVICE_PATH       CdDev;
  UINT32                  SubBlockSize;
  UINT32                  SectorCount;
  EFI_STATUS              Found;
  UINTN                   Dummy;
  UINT32                  VolSpaceSize;

  Found         = EFI_NOT_FOUND;
  Media         = BlockIo->Media;
  VolSpaceSize  = 0;

  //
  // CD_ROM has the fixed block size as 2048 bytes
  //
  if (Media->BlockSize != 2048) {
    return EFI_NOT_FOUND;
  }

  VolDescriptor = EfiLibAllocatePool ((UINTN) Media->BlockSize);

  if (VolDescriptor == NULL) {
    return EFI_NOT_FOUND;
  }

  Catalog = (ELTORITO_CATALOG *) VolDescriptor;

  //
  // the ISO-9660 volume descriptor starts at 32k on the media
  // and CD_ROM has the fixed block size as 2048 bytes, so...
  //
  //
  // ((16*2048) / Media->BlockSize) - 1;
  //
  VolDescriptorLba = 15;
  //
  // Loop: handle one volume descriptor per time
  //
  while (TRUE) {

    VolDescriptorLba += 1;
    if (VolDescriptorLba > Media->LastBlock) {
      //
      // We are pointing past the end of the device so exit
      //
      break;
    }

    Status = DiskIo->ReadDisk (
                        DiskIo,
                        Media->MediaId,
                        MultU64x32 (VolDescriptorLba, Media->BlockSize),
                        Media->BlockSize,
                        VolDescriptor
                        );
    if (EFI_ERROR (Status)) {
      Found = Status;
      break;
    }
    //
    // Check for valid volume descriptor signature
    //
    if (VolDescriptor->Type == CDVOL_TYPE_END ||
        EfiCompareMem (VolDescriptor->Id, CDVOL_ID, sizeof (VolDescriptor->Id)) != 0
        ) {
      //
      // end of Volume descriptor list
      //
      break;
    }
    //
    // Read the Volume Space Size from Primary Volume Descriptor 81-88 byte,
    // the 32-bit numerical values is stored in Both-byte orders
    //
    if (VolDescriptor->Type == CDVOL_TYPE_CODED) {
      VolSpaceSize = VolDescriptor->VolSpaceSize[0];
    }
    //
    // Is it an El Torito volume descriptor?
    //
    if (EfiCompareMem (VolDescriptor->SystemId, CDVOL_ELTORITO_ID, sizeof (CDVOL_ELTORITO_ID) - 1) != 0) {
      continue;
    }
    //
    // Read in the boot El Torito boot catalog
    //
    Lba = UNPACK_INT32 (VolDescriptor->EltCatalog);
    if (Lba > Media->LastBlock) {
      continue;
    }

    Status = DiskIo->ReadDisk (
                        DiskIo,
                        Media->MediaId,
                        MultU64x32 (Lba, Media->BlockSize),
                        Media->BlockSize,
                        Catalog
                        );
    if (EFI_ERROR (Status)) {
      DEBUG ((EFI_D_ERROR, "EltCheckDevice: error reading catalog %r\n", Status));
      continue;
    }
    //
    // We don't care too much about the Catalog header's contents, but we do want
    // to make sure it looks like a Catalog header
    //
    if (Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG || Catalog->Catalog.Id55AA != 0xAA55) {
      DEBUG ((EFI_D_ERROR, "EltCheckBootCatalog: El Torito boot catalog header IDs not correct\n"));
      continue;
    }

    Check       = 0;
    CheckBuffer = (UINT16 *) Catalog;
    for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) {
      Check += CheckBuffer[Index];
    }

    if (Check & 0xFFFF) {
      DEBUG ((EFI_D_ERROR, "EltCheckBootCatalog: El Torito boot catalog header checksum failed\n"));
      continue;
    }

    MaxIndex = Media->BlockSize / sizeof (ELTORITO_CATALOG);
    for (Index = 1, BootEntry = 1; Index < MaxIndex; Index += 1) {
      //
      // Next entry
      //
      Catalog += 1;

      //
      // Check this entry
      //
      if (Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE || Catalog->Boot.Lba == 0) {
        continue;
      }

      SubBlockSize  = 512;
      SectorCount   = Catalog->Boot.SectorCount;

      switch (Catalog->Boot.MediaType) {

      case ELTORITO_NO_EMULATION:
        SubBlockSize = Media->BlockSize;
        break;

      case ELTORITO_HARD_DISK:
        break;

      case ELTORITO_12_DISKETTE:
        SectorCount = 0x50 * 0x02 * 0x0F;
        break;

      case ELTORITO_14_DISKETTE:
        SectorCount = 0x50 * 0x02 * 0x12;
        break;

      case ELTORITO_28_DISKETTE:
        SectorCount = 0x50 * 0x02 * 0x24;
        break;

      default:
        DEBUG ((EFI_D_INIT, "EltCheckDevice: unsupported El Torito boot media type %x\n", Catalog->Boot.MediaType));
        SectorCount   = 0;
        SubBlockSize  = Media->BlockSize;
        break;
      }
      //
      // Create child device handle
      //
      CdDev.Header.Type     = MEDIA_DEVICE_PATH;
      CdDev.Header.SubType  = MEDIA_CDROM_DP;
      SetDevicePathNodeLength (&CdDev.Header, sizeof (CdDev));

      if (Index == 1) {
        //
        // This is the initial/default entry
        //
        BootEntry = 0;
      }

      CdDev.BootEntry = (UINT32) BootEntry;
      BootEntry++;
      CdDev.PartitionStart = Catalog->Boot.Lba;
      if (SectorCount < 2) {
        //
        //When the SectorCount < 2, set the Partition as the whole CD.
        //
        CdDev.PartitionSize = (VolSpaceSize > Media->LastBlock + 1) ? 
          (UINT32)(Media->LastBlock - Catalog->Boot.Lba + 1) : (UINT32)(VolSpaceSize - Catalog->Boot.Lba);
      } else {
        CdDev.PartitionSize = DivU64x32 (
                                MultU64x32 (SectorCount,
                                SubBlockSize) + Media->BlockSize - 1,
                                Media->BlockSize,
                                &Dummy
                                );
      }

      Status = PartitionInstallChildHandle (
                This,
                Handle,
                DiskIo,
                BlockIo,
                DevicePath,
                (EFI_DEVICE_PATH_PROTOCOL *) &CdDev,
                Catalog->Boot.Lba,
                Catalog->Boot.Lba + CdDev.PartitionSize - 1,
                SubBlockSize,
                FALSE
                );
      if (!EFI_ERROR (Status)) {
        Found = EFI_SUCCESS;
      }
    }
  }

  gBS->FreePool (VolDescriptor);

  return Found;
}
Пример #13
0
EFI_STATUS
EFIAPI
StslBeginLogging (
  IN EFI_STANDARD_TSL_PRIVATE_INTERFACE     *This
  )
/*++

Routine Description:

  One private interface function of the StandardTestLibrary to begin logging.

Arguments:

  This          - the private interface instance structure.

Returns:

  EFI_SUCCESS   - begin logging successfully.

--*/
{
  EFI_STATUS                        Status;
  STANDARD_TEST_PRIVATE_DATA        *Private;
  CHAR16                            Buffer[EFI_MAX_PRINT_BUFFER];
  EFI_TEST_OUTPUT_LIBRARY_PROTOCOL  *Output;
  EFI_LIB_CONFIG_FILE_HANDLE        *FileConf;
  EFI_GUID                          *Guid;
  EFI_TIME                          *CurrentTime;

  Private = STANDARD_TEST_PRIVATE_DATA_FROM_PI (This);
  Output = Private->OutputProtocol;

  StslCloseAllFiles (Private);

  //
  // Open log and key files
  //

  //
  // Open system log file
  //
  FileConf = &Private->SystemLogFile;
  Status = Output->Open (
                     Output,
                     FileConf->DevicePath,
                     FileConf->FileName,
                     FileConf->OverwriteFile,
                     &FileConf->FileHandle
                     );
  if (EFI_ERROR (Status)) {
    StslCloseAllFiles (Private);
    return Status;
  }

  //
  // Open system key file
  //
  FileConf = &Private->SystemKeyFile;
  Status = Output->Open (
                     Output,
                     FileConf->DevicePath,
                     FileConf->FileName,
                     FileConf->OverwriteFile,
                     &FileConf->FileHandle
                     );
  if (EFI_ERROR (Status)) {
    StslCloseAllFiles (Private);
    return Status;
  }

  //
  // Open case log file
  //
  FileConf = &Private->CaseLogFile;
  Status = Output->Open (
                     Output,
                     FileConf->DevicePath,
                     FileConf->FileName,
                     FileConf->OverwriteFile,
                     &FileConf->FileHandle
                     );
  if (EFI_ERROR (Status)) {
    StslCloseAllFiles (Private);
    return Status;
  }

  //
  // Open case key file
  //
  FileConf = &Private->CaseKeyFile;
  Status = Output->Open (
                     Output,
                     FileConf->DevicePath,
                     FileConf->FileName,
                     FileConf->OverwriteFile,
                     &FileConf->FileHandle
                     );
  if (EFI_ERROR (Status)) {
    StslCloseAllFiles (Private);
    return Status;
  }

  //
  // Write log file header data
  //

  if (Private->IsRecovery) {
    //
    // ----------------------------------
    //
    StslWriteLogFile (Private, DashLine);

    SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"      *********RECOVERY*********\n");
    StslWriteLogFile (Private, Buffer);

    //
    // ----------------------------------
    //
    StslWriteLogFile (Private, DashLine);

    CurrentTime = &Private->StartTime;
    gRT->GetTime (CurrentTime, NULL);

  } else {
    //
    // ----------------------------------
    //
    StslWriteLogFile (Private, DashLine);

    SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"%s\n", Private->EntryName);
    StslWriteLogFile (Private, Buffer);
    SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"Revision 0x%08x\n", Private->TestRevision);
    StslWriteLogFile (Private, Buffer);
    SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"Test Entry Point GUID: %g\n", &Private->EntryId);
    StslWriteLogFile (Private, Buffer);
    SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"Test Support Library GUIDs: \n");
    StslWriteLogFile (Private, Buffer);

    Guid = Private->SupportProtocols;
    while (EfiCompareMem (Guid, &gEfiNullGuid, sizeof(EFI_GUID) ) != 0) {
      SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"  %g\n", Guid);
      StslWriteLogFile (Private, Buffer);
      Guid ++;
    }

    //
    // ----------------------------------
    //
    StslWriteLogFile (Private, DashLine);

    SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"%s\n", Private->BiosId);
    StslWriteLogFile (Private, Buffer);
    SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"Test Configuration #%d\n", Private->ConfigurationNumber);
    StslWriteLogFile (Private, Buffer);

    //
    // ----------------------------------
    //
    StslWriteLogFile (Private, DashLine);

    SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"%s\n", Private->EntryDescription);
    StslWriteLogFile (Private, Buffer);

    //
    // ----------------------------------
    //
    StslWriteLogFile (Private, DashLine);

    StslWriteLogFileName (Private);
    CurrentTime = &Private->StartTime;
    gRT->GetTime (CurrentTime, NULL);
    SPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"Test Started: %t\n", CurrentTime);
    StslWriteLogFile (Private, Buffer);

    //
    // ----------------------------------
    //
    StslWriteLogFile (Private, DashLine);

    //
    // Write key file header line
    //
    SPrint (
      Buffer, EFI_MAX_PRINT_BUFFER, L"|HEAD|||%d|%s|%02d-%02d-%04d|%02d:%02d:%02d|%g|0x%08lx|%s|%s|%s|%s\n",
      Private->ConfigurationNumber,
      Private->ScenarioString,
      CurrentTime->Day,
      CurrentTime->Month,
      CurrentTime->Year,
      CurrentTime->Hour,
      CurrentTime->Minute,
      CurrentTime->Second,
      &Private->EntryId,
      Private->TestRevision,
      Private->EntryName,
      Private->TestName,
      Private->TestCategory,
      Private->DevicePath
      );

    StslWriteKeyFile (Private, Buffer);
  }

  //
  // Initial private data
  //
  Private->BeginLogging   = TRUE;

  return EFI_SUCCESS;
}