EFI_DEVICE_PATH_PROTOCOL * CreatePciDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath, IN PCI_IO_DEVICE *PciIoDevice ) /*++ Routine Description: Arguments: Returns: None --*/ { PCI_DEVICE_PATH PciNode; // // Create PCI device path // PciNode.Header.Type = HARDWARE_DEVICE_PATH; PciNode.Header.SubType = HW_PCI_DP; SetDevicePathNodeLength (&PciNode.Header, sizeof (PciNode)); PciNode.Device = PciIoDevice->DeviceNumber; PciNode.Function = PciIoDevice->FunctionNumber; PciIoDevice->DevicePath = AppendDevicePathNode (ParentDevicePath, &PciNode.Header); return PciIoDevice->DevicePath; }
STATIC EFI_STATUS EFIAPI SasV1ExtScsiPassThruBuildDevicePath ( IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN UINT8 *Target, IN UINT64 Lun, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath ) { EFI_DEVICE_PATH_PROTOCOL *NewDevicePathNode; EFI_DEV_PATH EndNode; EFI_DEV_PATH Node; ZeroMem (&Node, sizeof (Node)); Node.DevPath.Type = HARDWARE_DEVICE_PATH; Node.DevPath.SubType = HW_PCI_DP; SetDevicePathNodeLength (&Node.DevPath, sizeof (PCI_DEVICE_PATH)); SetDevicePathEndNode (&EndNode.DevPath); NewDevicePathNode = AppendDevicePathNode (&EndNode.DevPath, &Node.DevPath); *DevicePath = NewDevicePathNode; return EFI_SUCCESS; }
EFI_STATUS BdsLoadOptionFileSystemCreateDevicePath ( IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes ) { EFI_STATUS Status; FILEPATH_DEVICE_PATH* FilePathDevicePath; CHAR16 BootFilePath[BOOT_DEVICE_FILEPATH_MAX]; UINTN BootFilePathSize; Print(L"File path of the %s: ", FileName); Status = GetHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX); if (EFI_ERROR(Status)) { return EFI_ABORTED; } BootFilePathSize = StrSize (BootFilePath); if (BootFilePathSize == 2) { *DevicePathNodes = NULL; return EFI_NOT_FOUND; } // Create the FilePath Device Path node FilePathDevicePath = (FILEPATH_DEVICE_PATH*)AllocatePool(SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize + END_DEVICE_PATH_LENGTH); FilePathDevicePath->Header.Type = MEDIA_DEVICE_PATH; FilePathDevicePath->Header.SubType = MEDIA_FILEPATH_DP; SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize); CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize); SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize)); *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)FilePathDevicePath; return Status; }
// // append file path // EFI_DEVICE_PATH_PROTOCOL* DevPathAppendFilePath(EFI_DEVICE_PATH_PROTOCOL* devicePath, CHAR16 CONST* fileName) { if(!devicePath || !fileName || !fileName[0]) return nullptr; UINTN devicePathSize = DevPathGetSize(devicePath); if(!devicePathSize) return nullptr; UINTN size = (wcslen(fileName) + 1) * sizeof(CHAR16); EFI_DEVICE_PATH_PROTOCOL* filePath = static_cast<EFI_DEVICE_PATH_PROTOCOL*>(MmAllocatePool(size + devicePathSize + SIZE_OF_FILEPATH_DEVICE_PATH)); if(!filePath) return nullptr; devicePathSize -= END_DEVICE_PATH_LENGTH; memcpy(filePath, devicePath, devicePathSize); FILEPATH_DEVICE_PATH* filePathNode = Add2Ptr(filePath, devicePathSize, FILEPATH_DEVICE_PATH*); filePathNode->Header.Type = MEDIA_DEVICE_PATH; filePathNode->Header.SubType = MEDIA_FILEPATH_DP; SetDevicePathNodeLength(&filePathNode->Header, size + SIZE_OF_FILEPATH_DEVICE_PATH); memcpy(filePathNode->PathName, fileName, size); EFI_DEVICE_PATH_PROTOCOL* endOfPath = NextDevicePathNode(&filePathNode->Header); SetDevicePathEndNode(endOfPath); return filePath; }
/** Build device path for device. @param BaseDevicePath Base device path. @param Drive Legacy drive. @param DevicePath Device path for output. **/ VOID SetBiosInitBlockIoDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL *BaseDevicePath, IN BIOS_LEGACY_DRIVE *Drive, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath ) { EFI_STATUS Status; BLOCKIO_VENDOR_DEVICE_PATH VendorNode; Status = EFI_UNSUPPORTED; // // BugBug: Check for memory leaks! // if (Drive->EddVersion == EDD_VERSION_30) { // // EDD 3.0 case. // Status = BuildEdd30DevicePath (BaseDevicePath, Drive, DevicePath); } if (EFI_ERROR (Status)) { // // EDD 1.1 device case or it is unrecognized EDD 3.0 device // ZeroMem (&VendorNode, sizeof (VendorNode)); VendorNode.DevicePath.Header.Type = HARDWARE_DEVICE_PATH; VendorNode.DevicePath.Header.SubType = HW_VENDOR_DP; SetDevicePathNodeLength (&VendorNode.DevicePath.Header, sizeof (VendorNode)); CopyMem (&VendorNode.DevicePath.Guid, &gBlockIoVendorGuid, sizeof (EFI_GUID)); VendorNode.LegacyDriveLetter = Drive->Number; *DevicePath = AppendDevicePathNode (BaseDevicePath, &VendorNode.DevicePath.Header); } }
EFI_DEVICE_PATH_PROTOCOL * FileDevicePath ( IN EFI_HANDLE Device OPTIONAL, IN CHAR16 *FileName ) /*++ Routine Description: Function allocates a device path for a file and appends it to an existing device path. Arguments: Device - A pointer to a device handle. FileName - A pointer to a Null-terminated Unicode string. Returns: If Device is not a valid device handle, then a device path for the file specified by FileName is allocated and returned. Results are allocated from pool. The caller must FreePool the resulting device path structure --*/ { UINTN Size; FILEPATH_DEVICE_PATH *FilePath; EFI_DEVICE_PATH_PROTOCOL *Eop, *DevicePath; Size = StrSize(FileName); FilePath = AllocateZeroPool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + sizeof(EFI_DEVICE_PATH_PROTOCOL)); DevicePath = NULL; if (FilePath) { // // Build a file path // FilePath->Header.Type = MEDIA_DEVICE_PATH; FilePath->Header.SubType = MEDIA_FILEPATH_DP; SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH); CopyMem (FilePath->PathName, FileName, Size); Eop = NextDevicePathNode(&FilePath->Header); SetDevicePathEndNode(Eop); // // Append file path to device's device path // DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) FilePath; if (Device) { DevicePath = AppendDevicePath ( DevicePathFromHandle(Device), DevicePath ); FreePool(FilePath); } } return DevicePath; }
EFI_DEVICE_PATH * UnpackDevicePath ( IN EFI_DEVICE_PATH *DevPath ) { EFI_DEVICE_PATH *Src, *Dest, *NewPath; UINTN Size; // // Walk device path and round sizes to valid boundries // Src = DevPath; Size = 0; for (; ;) { Size += DevicePathNodeLength(Src); Size += ALIGN_SIZE(Size); if (IsDevicePathEnd(Src)) { break; } Src = NextDevicePathNode(Src); } // // Allocate space for the unpacked path // NewPath = AllocateZeroPool (Size); if (NewPath) { ASSERT (((UINTN)NewPath) % MIN_ALIGNMENT_SIZE == 0); // // Copy each node // Src = DevPath; Dest = NewPath; for (; ;) { Size = DevicePathNodeLength(Src); CopyMem (Dest, Src, Size); Size += ALIGN_SIZE(Size); SetDevicePathNodeLength (Dest, Size); Dest->Type |= EFI_DP_TYPE_UNPACKED; Dest = (EFI_DEVICE_PATH *) (((UINT8 *) Dest) + Size); if (IsDevicePathEnd(Src)) { break; } Src = NextDevicePathNode(Src); } } return NewPath; }
EFI_DEVICE_PATH * FileDevicePath ( IN EFI_HANDLE Device OPTIONAL, IN CHAR16 *FileName ) /*++ N.B. Results are allocated from pool. The caller must FreePool the resulting device path structure --*/ { UINTN Size; FILEPATH_DEVICE_PATH *FilePath; EFI_DEVICE_PATH *Eop, *DevicePath; Size = StrSize(FileName); FilePath = (FILEPATH_DEVICE_PATH *) AllocateZeroPool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + sizeof(EFI_DEVICE_PATH)); DevicePath = (EFI_DEVICE_PATH *) NULL; if (FilePath) { // // Build a file path // FilePath->Header.Type = MEDIA_DEVICE_PATH; FilePath->Header.SubType = MEDIA_FILEPATH_DP; SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH); BS->CopyMem (FilePath->PathName, FileName, Size); Eop = NextDevicePathNode(&FilePath->Header); SetDevicePathEndNode(Eop); // // Append file path to device's device path // DevicePath = (EFI_DEVICE_PATH *) FilePath; if (Device) { DevicePath = AppendDevicePath ( DevicePathFromHandle(Device), DevicePath ); BS->FreePool(FilePath); } } return DevicePath; }
EFI_STATUS BdsLoadOptionFileSystemUpdateDevicePath ( IN EFI_DEVICE_PATH *OldDevicePath, IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath ) { EFI_STATUS Status; CHAR16 BootFilePath[BOOT_DEVICE_FILEPATH_MAX]; UINTN BootFilePathSize; FILEPATH_DEVICE_PATH* EndingDevicePath; FILEPATH_DEVICE_PATH* FilePathDevicePath; EFI_DEVICE_PATH* DevicePath; DevicePath = DuplicateDevicePath (OldDevicePath); EndingDevicePath = (FILEPATH_DEVICE_PATH*)GetLastDevicePathNode (DevicePath); Print(L"File path of the %s: ", FileName); StrnCpy (BootFilePath, EndingDevicePath->PathName, BOOT_DEVICE_FILEPATH_MAX); Status = EditHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX); if (EFI_ERROR(Status)) { return Status; } BootFilePathSize = StrSize(BootFilePath); if (BootFilePathSize == 2) { *NewDevicePath = NULL; return EFI_NOT_FOUND; } // Create the FilePath Device Path node FilePathDevicePath = (FILEPATH_DEVICE_PATH*)AllocatePool(SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize); if (NULL == FilePathDevicePath) { return EFI_INVALID_PARAMETER; } FilePathDevicePath->Header.Type = MEDIA_DEVICE_PATH; FilePathDevicePath->Header.SubType = MEDIA_FILEPATH_DP; SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize); CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize); // Generate the new Device Path by replacing the last node by the updated node SetDevicePathEndNode (EndingDevicePath); *NewDevicePath = AppendDevicePathNode (DevicePath, (CONST EFI_DEVICE_PATH_PROTOCOL *)FilePathDevicePath); FreePool(DevicePath); return EFI_SUCCESS; }
EFI_DEVICE_PATH_PROTOCOL * WinNtBusCreateDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath, IN EFI_GUID *Guid, IN UINT16 InstanceNumber ) /*++ Routine Description: Create a device path node using Guid and InstanceNumber and append it to the passed in RootDevicePath Arguments: RootDevicePath - Root of the device path to return. Guid - GUID to use in vendor device path node. InstanceNumber - Instance number to use in the vendor device path. This argument is needed to make sure each device path is unique. Returns: EFI_DEVICE_PATH_PROTOCOL --*/ { WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath; DevicePath.VendorDevicePath.Header.Type = HARDWARE_DEVICE_PATH; DevicePath.VendorDevicePath.Header.SubType = HW_VENDOR_DP; SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE)); // // The GUID defines the Class // CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID)); // // Add an instance number so we can make sure there are no Device Path // duplication. // DevicePath.Instance = InstanceNumber; return AppendDevicePathNode ( RootDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &DevicePath ); }
// Get the parent device in an EFI_DEVICE_PATH // Note: the returned device path is allocated and must be freed static EFI_DEVICE_PATH* GetParentDevice(CONST EFI_DEVICE_PATH* DevicePath) { EFI_DEVICE_PATH *dp, *ldp; dp = DuplicateDevicePath((EFI_DEVICE_PATH*)DevicePath); if (dp == NULL) return NULL; ldp = GetLastDevicePath(dp); if (ldp == NULL) return NULL; ldp->Type = END_DEVICE_PATH_TYPE; ldp->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE; SetDevicePathNodeLength(ldp, sizeof (*ldp)); return dp; }
/** Initialize a Firmware Volume (FV) Media Device Path node. The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification. This library function abstracts initializing a device path node. Initialize the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure. This device path changed in the DXE CIS version 0.92 in a non back ward compatible way to not conflict with the UEFI 2.0 specification. This function abstracts the differences from the caller. If FvDevicePathNode is NULL, then ASSERT(). If NameGuid is NULL, then ASSERT(). @param FvDevicePathNode The pointer to a FV device path node to initialize @param NameGuid FV file name to use in FvDevicePathNode **/ VOID EFIAPI EfiInitializeFwVolDevicepathNode ( IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode, IN CONST EFI_GUID *NameGuid ) { ASSERT (FvDevicePathNode != NULL); ASSERT (NameGuid != NULL); // // Use the new Device path that does not conflict with the UEFI // FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH; FvDevicePathNode->Header.SubType = MEDIA_PIWG_FW_FILE_DP; SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)); CopyGuid (&FvDevicePathNode->FvFileName, NameGuid); }
EFI_STATUS BdsLoadOptionFileSystemCreatePcdDevicePath ( OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes ) { EFI_STATUS Status=EFI_SUCCESS; FILEPATH_DEVICE_PATH* FilePathDevicePath; CHAR16* BootFilePath; UINTN BootFilePathSize; if (*(CHAR16*)PcdGetPtr (PcdDefaultBootDevicePath) == L'\0') { BootFilePath=(CHAR16*)PcdGetPtr(PcdDefaultBootInitrdPath); } else { BootFilePath=(CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath); } BootFilePathSize = StrSize (BootFilePath); if (BootFilePathSize == 2) { *DevicePathNodes = NULL; return EFI_NOT_FOUND; } // Create the FilePath Device Path node FilePathDevicePath = (FILEPATH_DEVICE_PATH*)AllocatePool(SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize + END_DEVICE_PATH_LENGTH); if (NULL == FilePathDevicePath) { Print(L"AllocatePool FilePathDevicePath fail!!!\n"); return EFI_OUT_OF_RESOURCES; } FilePathDevicePath->Header.Type = MEDIA_DEVICE_PATH; FilePathDevicePath->Header.SubType = MEDIA_FILEPATH_DP; SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize); //CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize); memcpy_s(FilePathDevicePath->PathName, BootFilePathSize,BootFilePath, BootFilePathSize); SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize)); *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)FilePathDevicePath; return Status; }
EFI_STATUS BdsLoadOptionMemMapCreateDevicePath ( IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes ) { EFI_STATUS Status; MEMMAP_DEVICE_PATH *MemMapDevicePath; CHAR16 StrStartingAddress[BOOT_DEVICE_ADDRESS_MAX]; CHAR16 StrEndingAddress[BOOT_DEVICE_ADDRESS_MAX]; Print(L"Starting Address of the %s: ", FileName); Status = GetHIInputStr (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX); if (EFI_ERROR(Status)) { return EFI_ABORTED; } Print(L"Ending Address of the %s: ", FileName); Status = GetHIInputStr (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX); if (EFI_ERROR(Status)) { return EFI_ABORTED; } // Create the MemMap Device Path Node MemMapDevicePath = (MEMMAP_DEVICE_PATH*)AllocatePool (sizeof(MEMMAP_DEVICE_PATH) + END_DEVICE_PATH_LENGTH); if (NULL == MemMapDevicePath) { return EFI_OUT_OF_RESOURCES; } MemMapDevicePath->Header.Type = HARDWARE_DEVICE_PATH; MemMapDevicePath->Header.SubType = HW_MEMMAP_DP; SetDevicePathNodeLength (MemMapDevicePath, sizeof(MEMMAP_DEVICE_PATH)); MemMapDevicePath->MemoryType = EfiBootServicesData; MemMapDevicePath->StartingAddress = StrHexToUint64 (StrStartingAddress); MemMapDevicePath->EndingAddress = StrHexToUint64 (StrEndingAddress); // Set a Device Path End Node after the Memory Map Device Path Node SetDevicePathEndNode (MemMapDevicePath + 1); *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)MemMapDevicePath; return Status; }
/** Initialize a Firmware Volume (FV) Media Device Path node. Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum so as we move to UEFI 2.0 support we must use a mechanism that conforms with the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed device path is defined for Tiano extensions of device path. If the code is compiled to conform with the UEFI 2.0 specification use the new device path else use the old form for backwards compatability. @param FvDevicePathNode Pointer to a FV device path node to initialize @param NameGuid FV file name to use in FvDevicePathNode **/ VOID EFIAPI EfiInitializeFwVolDevicepathNode ( IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode, IN CONST EFI_GUID *NameGuid ) { ASSERT (FvDevicePathNode != NULL); ASSERT (NameGuid != NULL); // // EFI Specification extension on Media Device Path. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH is adopted by UEFI later and added in UEFI2.10. // In EdkCompatibility Package, we only support MEDIA_FW_VOL_FILEPATH_DEVICE_PATH that complies with // EFI 1.10 and UEFI 2.10. // FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH; FvDevicePathNode->Header.SubType = MEDIA_PIWG_FW_FILE_DP; SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)); CopyGuid (&FvDevicePathNode->FvFileName, NameGuid); }
/** Update the parameters of a TFTP boot option The function asks sequentially to update the IPv4 parameters as well as the boot file path, providing the previously set value if any. @param[in] OldDevicePath Current complete device path of the Tftp boot option. This has to be a valid complete Tftp boot option path. By complete, we mean that it is not only the Tftp specific end part built by the "BdsLoadOptionTftpCreateDevicePath()" function. This path is handled as read only. @param[in] FileName Description of the file the path is asked for @param[out] NewDevicePath Pointer to the new complete device path. @retval EFI_SUCCESS Update completed @retval EFI_ABORTED Update aborted by the user @retval EFI_OUT_OF_RESOURCES Fail to perform the update due to lack of resource **/ EFI_STATUS BdsLoadOptionTftpUpdateDevicePath ( IN EFI_DEVICE_PATH *OldDevicePath, IN CHAR16 *FileName, OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath ) { EFI_STATUS Status; EFI_DEVICE_PATH *DevicePath; EFI_DEVICE_PATH *DevicePathNode; UINT8 *Ipv4NodePtr; IPv4_DEVICE_PATH Ipv4Node; BOOLEAN IsDHCP; EFI_IP_ADDRESS OldIp; EFI_IP_ADDRESS OldSubnetMask; EFI_IP_ADDRESS OldGatewayIp; EFI_IP_ADDRESS LocalIp; EFI_IP_ADDRESS SubnetMask; EFI_IP_ADDRESS GatewayIp; EFI_IP_ADDRESS RemoteIp; UINT8 *FileNodePtr; CHAR16 BootFilePath[BOOT_DEVICE_FILEPATH_MAX]; UINTN PathSize; UINTN BootFilePathSize; FILEPATH_DEVICE_PATH *NewFilePathNode; Ipv4NodePtr = NULL; // // Make a copy of the complete device path that is made of : // the device path of the device that support the Simple Network protocol // followed by an IPv4 node (type IPv4_DEVICE_PATH), // followed by a file path node (type FILEPATH_DEVICE_PATH) and ended up // by an end node. The IPv6 case is not handled yet. // DevicePath = DuplicateDevicePath (OldDevicePath); if (DevicePath == NULL) { Status = EFI_OUT_OF_RESOURCES; goto ErrorExit; } // // Because of the check done by "BdsLoadOptionTftpIsSupported()" prior to the // call to this function, we know that the device path ends with an IPv4 node // followed by a file path node and finally an end node. To get the address of // the last IPv4 node, we loop over the whole device path, noting down the // address of each encountered IPv4 node. // for (DevicePathNode = DevicePath; !IsDevicePathEnd (DevicePathNode); DevicePathNode = NextDevicePathNode (DevicePathNode)) { if (IS_DEVICE_PATH_NODE (DevicePathNode, MESSAGING_DEVICE_PATH, MSG_IPv4_DP)) { Ipv4NodePtr = (UINT8*)DevicePathNode; } } // Copy for alignment of the IPv4 node data CopyMem (&Ipv4Node, Ipv4NodePtr, sizeof (IPv4_DEVICE_PATH)); Print (L"Get the IP address from DHCP: "); Status = GetHIInputBoolean (&IsDHCP); if (EFI_ERROR (Status)) { goto ErrorExit; } if (!IsDHCP) { Print (L"Local static IP address: "); if (Ipv4Node.StaticIpAddress) { CopyMem (&OldIp.v4, &Ipv4Node.LocalIpAddress, sizeof (EFI_IPv4_ADDRESS)); Status = EditHIInputIP (&OldIp, &LocalIp); } else { Status = GetHIInputIP (&LocalIp); } if (EFI_ERROR (Status)) { goto ErrorExit; } Print (L"Get the network mask: "); if (Ipv4Node.StaticIpAddress) { CopyMem (&OldSubnetMask.v4, &Ipv4Node.SubnetMask, sizeof (EFI_IPv4_ADDRESS)); Status = EditHIInputIP (&OldSubnetMask, &SubnetMask); } else { Status = GetHIInputIP (&SubnetMask); } if (EFI_ERROR (Status)) { goto ErrorExit; } Print (L"Get the gateway IP address: "); if (Ipv4Node.StaticIpAddress) { CopyMem (&OldGatewayIp.v4, &Ipv4Node.GatewayIpAddress, sizeof (EFI_IPv4_ADDRESS)); Status = EditHIInputIP (&OldGatewayIp, &GatewayIp); } else { Status = GetHIInputIP (&GatewayIp); } if (EFI_ERROR (Status)) { goto ErrorExit; } } Print (L"TFTP server IP address: "); // Copy remote IPv4 address into IPv4 or IPv6 union CopyMem (&OldIp.v4, &Ipv4Node.RemoteIpAddress, sizeof (EFI_IPv4_ADDRESS)); Status = EditHIInputIP (&OldIp, &RemoteIp); if (EFI_ERROR (Status)) { goto ErrorExit; } // Get the path of the boot file and its size in number of bytes FileNodePtr = Ipv4NodePtr + sizeof (IPv4_DEVICE_PATH); BootFilePathSize = DevicePathNodeLength (FileNodePtr) - SIZE_OF_FILEPATH_DEVICE_PATH; // // Ask for update of the boot file path // do { // Copy for 2-byte alignment of the Unicode string CopyMem ( BootFilePath, FileNodePtr + SIZE_OF_FILEPATH_DEVICE_PATH, MIN (BootFilePathSize, BOOT_DEVICE_FILEPATH_MAX) ); BootFilePath[BOOT_DEVICE_FILEPATH_MAX - 1] = L'\0'; Print (L"File path of the %s: ", FileName); Status = EditHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX); if (EFI_ERROR (Status)) { goto ErrorExit; } PathSize = StrSize (BootFilePath); if (PathSize > 2) { break; } // Empty string, give the user another try Print (L"Empty string - Invalid path\n"); } while (PathSize <= 2) ; // // Update the IPv4 node. IPv6 case not handled yet. // if (IsDHCP) { Ipv4Node.StaticIpAddress = FALSE; ZeroMem (&Ipv4Node.LocalIpAddress, sizeof (EFI_IPv4_ADDRESS)); ZeroMem (&Ipv4Node.SubnetMask, sizeof (EFI_IPv4_ADDRESS)); ZeroMem (&Ipv4Node.GatewayIpAddress, sizeof (EFI_IPv4_ADDRESS)); } else { Ipv4Node.StaticIpAddress = TRUE; CopyMem (&Ipv4Node.LocalIpAddress, &LocalIp.v4, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&Ipv4Node.SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&Ipv4Node.GatewayIpAddress, &GatewayIp.v4, sizeof (EFI_IPv4_ADDRESS)); } CopyMem (&Ipv4Node.RemoteIpAddress, &RemoteIp.v4, sizeof (EFI_IPv4_ADDRESS)); CopyMem (Ipv4NodePtr, &Ipv4Node, sizeof (IPv4_DEVICE_PATH)); // // Create the new file path node // NewFilePathNode = (FILEPATH_DEVICE_PATH*)AllocatePool ( SIZE_OF_FILEPATH_DEVICE_PATH + PathSize ); NewFilePathNode->Header.Type = MEDIA_DEVICE_PATH; NewFilePathNode->Header.SubType = MEDIA_FILEPATH_DP; SetDevicePathNodeLength ( NewFilePathNode, SIZE_OF_FILEPATH_DEVICE_PATH + PathSize ); CopyMem (NewFilePathNode->PathName, BootFilePath, PathSize); // // Generate the new Device Path by replacing the file path node at address // "FileNodePtr" by the new one "NewFilePathNode" and return its address. // SetDevicePathEndNode (FileNodePtr); *NewDevicePath = AppendDevicePathNode ( DevicePath, (CONST EFI_DEVICE_PATH_PROTOCOL*)NewFilePathNode ); ErrorExit: if (DevicePath != NULL) { FreePool (DevicePath) ; } return Status; }
EFI_STATUS BdsLoadOptionTftpCreateDevicePath ( IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes ) { EFI_STATUS Status; BOOLEAN IsDHCP; EFI_IP_ADDRESS LocalIp; EFI_IP_ADDRESS SubnetMask; EFI_IP_ADDRESS GatewayIp; EFI_IP_ADDRESS RemoteIp; IPv4_DEVICE_PATH *IPv4DevicePathNode; FILEPATH_DEVICE_PATH *FilePathDevicePath; CHAR16 BootFilePath[BOOT_DEVICE_FILEPATH_MAX]; UINTN BootFilePathSize; Print (L"Get the IP address from DHCP: "); Status = GetHIInputBoolean (&IsDHCP); if (EFI_ERROR (Status)) { return EFI_ABORTED; } if (!IsDHCP) { Print (L"Local static IP address: "); Status = GetHIInputIP (&LocalIp); if (EFI_ERROR (Status)) { return EFI_ABORTED; } Print (L"Get the network mask: "); Status = GetHIInputIP (&SubnetMask); if (EFI_ERROR (Status)) { return EFI_ABORTED; } Print (L"Get the gateway IP address: "); Status = GetHIInputIP (&GatewayIp); if (EFI_ERROR (Status)) { return EFI_ABORTED; } } Print (L"Get the TFTP server IP address: "); Status = GetHIInputIP (&RemoteIp); if (EFI_ERROR (Status)) { return EFI_ABORTED; } Print (L"File path of the %s : ", FileName); Status = GetHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX); if (EFI_ERROR (Status)) { return EFI_ABORTED; } BootFilePathSize = StrSize(BootFilePath); if (BootFilePathSize == 2) { return EFI_NOT_FOUND; } // Allocate the memory for the IPv4 + File Path Device Path Nodes IPv4DevicePathNode = (IPv4_DEVICE_PATH*)AllocatePool(sizeof(IPv4_DEVICE_PATH) + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize + END_DEVICE_PATH_LENGTH); if (NULL == IPv4DevicePathNode) { return EFI_INVALID_PARAMETER; } // Create the IPv4 Device Path IPv4DevicePathNode->Header.Type = MESSAGING_DEVICE_PATH; IPv4DevicePathNode->Header.SubType = MSG_IPv4_DP; SetDevicePathNodeLength (&IPv4DevicePathNode->Header, sizeof(IPv4_DEVICE_PATH)); if (!IsDHCP) { CopyMem (&IPv4DevicePathNode->LocalIpAddress, &LocalIp.v4, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&IPv4DevicePathNode->SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&IPv4DevicePathNode->GatewayIpAddress, &GatewayIp.v4, sizeof (EFI_IPv4_ADDRESS)); } CopyMem (&IPv4DevicePathNode->RemoteIpAddress, &RemoteIp.v4, sizeof (EFI_IPv4_ADDRESS)); IPv4DevicePathNode->LocalPort = 0; IPv4DevicePathNode->RemotePort = 0; IPv4DevicePathNode->Protocol = EFI_IP_PROTO_TCP; IPv4DevicePathNode->StaticIpAddress = (IsDHCP != TRUE); // Create the FilePath Device Path node FilePathDevicePath = (FILEPATH_DEVICE_PATH*)(IPv4DevicePathNode + 1); FilePathDevicePath->Header.Type = MEDIA_DEVICE_PATH; FilePathDevicePath->Header.SubType = MEDIA_FILEPATH_DP; SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize); CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize); // Set the End Device Path Node SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize)); *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)IPv4DevicePathNode; return Status; }
/** Install child handles if the Handle supports Apple partition table format. @param[in] This Calling context. @param[in] Handle Parent Handle @param[in] DiskIo Parent DiskIo interface @param[in] BlockIo Parent BlockIo interface @param[in] DevicePath Parent Device Path @retval EFI_SUCCESS Child handle(s) was added @retval EFI_MEDIA_CHANGED Media changed Detected @retval other no child handle was added **/ EFI_STATUS PartitionInstallAppleChildHandles ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { EFI_STATUS Status; UINT32 Lba; EFI_BLOCK_IO_MEDIA *Media; // VOID *Block; //UINTN MaxIndex; /** @todo: wrong, as this PT can be on both HDD or CD */ CDROM_DEVICE_PATH CdDev; //EFI_DEVICE_PATH_PROTOCOL Dev; UINT32 Partition; UINT32 PartitionEntries; UINT32 VolSpaceSize; UINT32 SubBlockSize; UINT32 BlkPerSec; UINT32 MediaId; UINT32 BlockSize; EFI_LBA LastBlock; APPLE_PT_HEADER *AppleHeader; APPLE_PT_ENTRY *AppleEntry; UINT32 StartLba; UINT32 SizeLbs; Media = BlockIo->Media; BlockSize = BlockIo->Media->BlockSize; LastBlock = BlockIo->Media->LastBlock; MediaId = BlockIo->Media->MediaId; VolSpaceSize = 0; AppleHeader = AllocatePool (BlockSize); if (AppleHeader == NULL) return EFI_NOT_FOUND; do { Lba = 0; Status = DiskIo->ReadDisk ( DiskIo, MediaId, 0, BlockSize, AppleHeader ); if (EFI_ERROR (Status)) goto done; // Header = (APPLE_PT_HEADER *)Block; if (SwapBytes16(AppleHeader->sbSig) != 0x4552) { Status = EFI_NOT_FOUND; goto done; } SubBlockSize = SwapBytes16(AppleHeader->sbBlkSize); BlkPerSec = BlockSize / SubBlockSize; if (BlockSize != SubBlockSize * BlkPerSec) { Status = EFI_NOT_FOUND; goto done; } AppleEntry = AllocatePool (SubBlockSize); PartitionEntries = 1; for (Partition = 1; Partition <= PartitionEntries; Partition++) { Status = DiskIo->ReadDisk ( DiskIo, MediaId, MultU64x32 (Partition, SubBlockSize), SubBlockSize, AppleEntry ); if (EFI_ERROR (Status)) { Status = EFI_NOT_FOUND; goto done; /* would break, but ... */ } // Entry = (APPLE_PT_ENTRY *)Block; if (SwapBytes16(AppleEntry->signature) != 0x504D) continue; if (Partition == 1) PartitionEntries = SwapBytes32(AppleEntry->map_entries); StartLba = SwapBytes32(AppleEntry->pblock_start); SizeLbs = SwapBytes32(AppleEntry->pblocks); ZeroMem (&CdDev, sizeof (CdDev)); CdDev.Header.Type = MEDIA_DEVICE_PATH; CdDev.Header.SubType = MEDIA_CDROM_DP; SetDevicePathNodeLength (&CdDev.Header, sizeof (CdDev)); CdDev.BootEntry = 0; CdDev.PartitionStart = StartLba / BlkPerSec; /* start, LBA */ CdDev.PartitionSize = SizeLbs / BlkPerSec; /* size, LBs */ Status = PartitionInstallChildHandle ( This, Handle, DiskIo, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &CdDev, CdDev.PartitionStart, CdDev.PartitionStart + CdDev.PartitionSize - 1, SubBlockSize, FALSE ); } } while (0); done: FreePool (AppleHeader); FreePool (AppleEntry); return Status; }
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; }
/** Install HII Config Access protocol for network device and allocate resource. @param[in] Instance The IP4 Config instance. @retval EFI_SUCCESS The HII Config Access protocol is installed. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. @retval Others Other errors as indicated. **/ EFI_STATUS Ip4ConfigDeviceInit ( IN IP4_CONFIG_INSTANCE *Instance ) { EFI_STATUS Status; EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; VENDOR_DEVICE_PATH VendorDeviceNode; EFI_SERVICE_BINDING_PROTOCOL *MnpSb; CHAR16 *MacString; CHAR16 MenuString[128]; CHAR16 PortString[128]; CHAR16 *OldMenuString; ConfigAccess = &Instance->HiiConfigAccessProtocol; ConfigAccess->ExtractConfig = Ip4DeviceExtractConfig; ConfigAccess->RouteConfig = Ip4DeviceRouteConfig; ConfigAccess->Callback = Ip4FormCallback; // // Construct device path node for EFI HII Config Access protocol, // which consists of controller physical device path and one hardware // vendor guid node. // ZeroMem (&VendorDeviceNode, sizeof (VENDOR_DEVICE_PATH)); VendorDeviceNode.Header.Type = HARDWARE_DEVICE_PATH; VendorDeviceNode.Header.SubType = HW_VENDOR_DP; CopyGuid (&VendorDeviceNode.Guid, &gEfiNicIp4ConfigVariableGuid); SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH)); Instance->HiiVendorDevicePath = AppendDevicePathNode ( Instance->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &VendorDeviceNode ); Instance->ChildHandle = NULL; // // Install Device Path Protocol and Config Access protocol on new handle // Status = gBS->InstallMultipleProtocolInterfaces ( &Instance->ChildHandle, &gEfiDevicePathProtocolGuid, Instance->HiiVendorDevicePath, &gEfiHiiConfigAccessProtocolGuid, ConfigAccess, NULL ); if (!EFI_ERROR (Status)) { // // Open the Parent Handle for the child // Status = gBS->OpenProtocol ( Instance->Controller, &gEfiManagedNetworkServiceBindingProtocolGuid, (VOID **) &MnpSb, Instance->Image, Instance->ChildHandle, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); } ASSERT_EFI_ERROR (Status); // // Publish our HII data // Instance->RegisteredHandle = HiiAddPackages ( &mNicIp4ConfigNvDataGuid, Instance->ChildHandle, Ip4ConfigDxeStrings, Ip4ConfigDxeBin, NULL ); if (Instance->RegisteredHandle == NULL) { return EFI_OUT_OF_RESOURCES; } // // Append MAC string in the menu string and tile string // Status = NetLibGetMacString (Instance->Controller, Instance->Image, &MacString); if (!EFI_ERROR (Status)) { OldMenuString = HiiGetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), NULL); UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString); HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), MenuString, NULL); UnicodeSPrint (PortString, 128, L"MAC:%s", MacString); HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_DEVICE_FORM_TITLE), PortString, NULL); FreePool (MacString); } return Status; }
STATIC EFI_STATUS EFIAPI VirtioNetDriverBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE DeviceHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) { EFI_STATUS Status; VNET_DEV *Dev; EFI_DEVICE_PATH_PROTOCOL *DevicePath; MAC_ADDR_DEVICE_PATH MacNode; VOID *ChildVirtIo; // // allocate space for the driver instance // Dev = (VNET_DEV *) AllocateZeroPool (sizeof *Dev); if (Dev == NULL) { return EFI_OUT_OF_RESOURCES; } Dev->Signature = VNET_SIG; Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid, (VOID **)&Dev->VirtIo, This->DriverBindingHandle, DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER); if (EFI_ERROR (Status)) { goto FreeVirtioNet; } // // now we can run a basic one-shot virtio-net initialization required to // retrieve the MAC address // Status = VirtioNetSnpPopulate (Dev); if (EFI_ERROR (Status)) { goto CloseVirtIo; } // // get the device path of the virtio-net device -- one-shot open // Status = gBS->OpenProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath, This->DriverBindingHandle, DeviceHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (EFI_ERROR (Status)) { goto Evacuate; } // // create another device path that has the MAC address appended // MacNode.Header.Type = MESSAGING_DEVICE_PATH; MacNode.Header.SubType = MSG_MAC_ADDR_DP; SetDevicePathNodeLength (&MacNode, sizeof MacNode); CopyMem (&MacNode.MacAddress, &Dev->Snm.CurrentAddress, sizeof (EFI_MAC_ADDRESS)); MacNode.IfType = Dev->Snm.IfType; Dev->MacDevicePath = AppendDevicePathNode (DevicePath, &MacNode.Header); if (Dev->MacDevicePath == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Evacuate; } // // create a child handle with the Simple Network Protocol and the new // device path installed on it // Status = gBS->InstallMultipleProtocolInterfaces (&Dev->MacHandle, &gEfiSimpleNetworkProtocolGuid, &Dev->Snp, &gEfiDevicePathProtocolGuid, Dev->MacDevicePath, NULL); if (EFI_ERROR (Status)) { goto FreeMacDevicePath; } // // make a note that we keep this device open with VirtIo for the sake of this // child // Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid, &ChildVirtIo, This->DriverBindingHandle, Dev->MacHandle, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER); if (EFI_ERROR (Status)) { goto UninstallMultiple; } return EFI_SUCCESS; UninstallMultiple: gBS->UninstallMultipleProtocolInterfaces (Dev->MacHandle, &gEfiDevicePathProtocolGuid, Dev->MacDevicePath, &gEfiSimpleNetworkProtocolGuid, &Dev->Snp, NULL); FreeMacDevicePath: FreePool (Dev->MacDevicePath); Evacuate: VirtioNetSnpEvacuate (Dev); CloseVirtIo: gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid, This->DriverBindingHandle, DeviceHandle); FreeVirtioNet: FreePool (Dev); return Status; }
/** Create the opened instances based on IPv4. @param[in] This Pointer to EFI_DRIVER_BINDING_PROTOCOL. @param[in] ControllerHandle Handle of the child to destroy. @param[in] Private Handle Pointer to PXEBC_PRIVATE_DATA. @retval EFI_SUCCESS The instances based on IPv4 were all created successfully. @retval Others An unexpected error occurred. **/ EFI_STATUS PxeBcCreateIp4Children ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN PXEBC_PRIVATE_DATA *Private ) { EFI_STATUS Status; IPv4_DEVICE_PATH Ip4Node; EFI_PXE_BASE_CODE_MODE *Mode; EFI_UDP4_CONFIG_DATA *Udp4CfgData; EFI_IP4_CONFIG_DATA *Ip4CfgData; EFI_IP4_MODE_DATA Ip4ModeData; PXEBC_PRIVATE_PROTOCOL *Id; EFI_SIMPLE_NETWORK_PROTOCOL *Snp; if (Private->Ip4Nic != NULL) { // // Already created before. // return EFI_SUCCESS; } // // Create Dhcp4 child and open Dhcp4 protocol for PxeBc->Dhcp. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiDhcp4ServiceBindingProtocolGuid, &Private->Dhcp4Child ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Dhcp4Child, &gEfiDhcp4ProtocolGuid, (VOID **) &Private->Dhcp4, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Create Mtftp4 child and open Mtftp4 protocol for PxeBc->Mtftp. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiMtftp4ServiceBindingProtocolGuid, &Private->Mtftp4Child ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Mtftp4Child, &gEfiMtftp4ProtocolGuid, (VOID **) &Private->Mtftp4, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Create Udp4 child and open Udp4 protocol for PxeBc->UdpRead. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiUdp4ServiceBindingProtocolGuid, &Private->Udp4ReadChild ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Udp4ReadChild, &gEfiUdp4ProtocolGuid, (VOID **) &Private->Udp4Read, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Create Udp4 child and open Udp4 protocol for PxeBc->UdpWrite. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiUdp4ServiceBindingProtocolGuid, &Private->Udp4WriteChild ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Udp4WriteChild, &gEfiUdp4ProtocolGuid, (VOID **) &Private->Udp4Write, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Create Arp child and open Arp protocol for PxeBc->Arp. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiArpServiceBindingProtocolGuid, &Private->ArpChild ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->ArpChild, &gEfiArpProtocolGuid, (VOID **) &Private->Arp, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Create Ip4 child and open Ip4 protocol for background ICMP packets. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiIp4ServiceBindingProtocolGuid, &Private->Ip4Child ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Ip4Child, &gEfiIp4ProtocolGuid, (VOID **) &Private->Ip4, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Get max packet size from Ip4 to calculate block size for Tftp later. // Status = Private->Ip4->GetModeData (Private->Ip4, &Ip4ModeData, NULL, NULL); if (EFI_ERROR (Status)) { goto ON_ERROR; } Private->Ip4MaxPacketSize = Ip4ModeData.MaxPacketSize; Private->Ip4Nic = AllocateZeroPool (sizeof (PXEBC_VIRTUAL_NIC)); if (Private->Ip4Nic == NULL) { return EFI_OUT_OF_RESOURCES; } Private->Ip4Nic->Private = Private; Private->Ip4Nic->Signature = PXEBC_VIRTUAL_NIC_SIGNATURE; // // Create a device path node for Ipv4 virtual nic, and append it. // ZeroMem (&Ip4Node, sizeof (IPv4_DEVICE_PATH)); Ip4Node.Header.Type = MESSAGING_DEVICE_PATH; Ip4Node.Header.SubType = MSG_IPv4_DP; Ip4Node.StaticIpAddress = FALSE; SetDevicePathNodeLength (&Ip4Node.Header, sizeof (Ip4Node)); Private->Ip4Nic->DevicePath = AppendDevicePathNode (Private->DevicePath, &Ip4Node.Header); if (Private->Ip4Nic->DevicePath == NULL) { Status = EFI_OUT_OF_RESOURCES; goto ON_ERROR; } CopyMem ( &Private->Ip4Nic->LoadFile, &gLoadFileProtocolTemplate, sizeof (EFI_LOAD_FILE_PROTOCOL) ); // // Create a new handle for IPv4 virtual nic, // and install PxeBaseCode, LoadFile and DevicePath protocols. // Status = gBS->InstallMultipleProtocolInterfaces ( &Private->Ip4Nic->Controller, &gEfiDevicePathProtocolGuid, Private->Ip4Nic->DevicePath, &gEfiLoadFileProtocolGuid, &Private->Ip4Nic->LoadFile, &gEfiPxeBaseCodeProtocolGuid, &Private->PxeBc, NULL ); if (EFI_ERROR (Status)) { goto ON_ERROR; } if (Private->Snp != NULL) { // // Install SNP protocol on purpose is for some OS loader backward // compatibility consideration. // Status = gBS->InstallProtocolInterface ( &Private->Ip4Nic->Controller, &gEfiSimpleNetworkProtocolGuid, EFI_NATIVE_INTERFACE, Private->Snp ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Open SNP on the child handle BY_DRIVER. It will prevent any additionally // layering to perform the experiment. // Status = gBS->OpenProtocol ( Private->Ip4Nic->Controller, &gEfiSimpleNetworkProtocolGuid, (VOID **) &Snp, This->DriverBindingHandle, Private->Ip4Nic->Controller, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } } // // Open PxeBaseCodePrivate protocol by child to setup a parent-child relationship between // real NIC handle and the virtual IPv4 NIC handle. // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiCallerIdGuid, (VOID **) &Id, This->DriverBindingHandle, Private->Ip4Nic->Controller, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Set default configure data for Udp4Read and Ip4 instance. // Mode = Private->PxeBc.Mode; Udp4CfgData = &Private->Udp4CfgData; Ip4CfgData = &Private->Ip4CfgData; Udp4CfgData->AcceptBroadcast = FALSE; Udp4CfgData->AcceptAnyPort = TRUE; Udp4CfgData->AllowDuplicatePort = TRUE; Udp4CfgData->TypeOfService = Mode->ToS; Udp4CfgData->TimeToLive = Mode->TTL; Udp4CfgData->ReceiveTimeout = PXEBC_DEFAULT_LIFETIME; Udp4CfgData->TransmitTimeout = PXEBC_DEFAULT_LIFETIME; Ip4CfgData->AcceptIcmpErrors = TRUE; Ip4CfgData->DefaultProtocol = EFI_IP_PROTO_ICMP; Ip4CfgData->TypeOfService = Mode->ToS; Ip4CfgData->TimeToLive = Mode->TTL; Ip4CfgData->ReceiveTimeout = PXEBC_DEFAULT_LIFETIME; Ip4CfgData->TransmitTimeout = PXEBC_DEFAULT_LIFETIME; return EFI_SUCCESS; ON_ERROR: PxeBcDestroyIp4Children (This, Private); return Status; }
/** Install child handles if the Handle supports GPT partition structure. @param[in] This Calling context. @param[in] Handle Parent Handle. @param[in] DiskIo Parent DiskIo interface. @param[in] BlockIo Parent BlockIo interface. @param[in] BlockIo2 Parent BlockIo2 interface. @param[in] DevicePath Parent Device Path. @retval EFI_SUCCESS Valid GPT disk. @retval EFI_MEDIA_CHANGED Media changed Detected. @retval other Not a valid GPT disk. **/ EFI_STATUS PartitionInstallGptChildHandles ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { EFI_STATUS Status; UINT32 BlockSize; EFI_LBA LastBlock; MASTER_BOOT_RECORD *ProtectiveMbr; EFI_PARTITION_TABLE_HEADER *PrimaryHeader; EFI_PARTITION_TABLE_HEADER *BackupHeader; EFI_PARTITION_ENTRY *PartEntry; EFI_PARTITION_ENTRY *Entry; EFI_PARTITION_ENTRY_STATUS *PEntryStatus; UINTN Index; EFI_STATUS GptValidStatus; HARDDRIVE_DEVICE_PATH HdDev; UINT32 MediaId; VBoxLogFlowFuncMarkDP(DevicePath); ProtectiveMbr = NULL; PrimaryHeader = NULL; BackupHeader = NULL; PartEntry = NULL; PEntryStatus = NULL; BlockSize = BlockIo->Media->BlockSize; LastBlock = BlockIo->Media->LastBlock; MediaId = BlockIo->Media->MediaId; DEBUG ((EFI_D_INFO, " BlockSize : %d \n", BlockSize)); DEBUG ((EFI_D_INFO, " LastBlock : %lx \n", LastBlock)); GptValidStatus = EFI_NOT_FOUND; // // Allocate a buffer for the Protective MBR // ProtectiveMbr = AllocatePool (BlockSize); if (ProtectiveMbr == NULL) { return EFI_NOT_FOUND; } // // Read the Protective MBR from LBA #0 // Status = DiskIo->ReadDisk ( DiskIo, MediaId, 0, BlockSize, ProtectiveMbr ); if (EFI_ERROR (Status)) { GptValidStatus = Status; goto Done; } // // Verify that the Protective MBR is valid // for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) { if (ProtectiveMbr->Partition[Index].BootIndicator == 0x00 && ProtectiveMbr->Partition[Index].OSIndicator == PMBR_GPT_PARTITION && UNPACK_UINT32 (ProtectiveMbr->Partition[Index].StartingLBA) == 1 ) { break; } } if (Index == MAX_MBR_PARTITIONS) { goto Done; } // // Allocate the GPT structures // PrimaryHeader = AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER)); if (PrimaryHeader == NULL) { goto Done; } BackupHeader = AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER)); if (BackupHeader == NULL) { goto Done; } // // Check primary and backup partition tables // if (!PartitionValidGptTable (BlockIo, DiskIo, PRIMARY_PART_HEADER_LBA, PrimaryHeader)) { DEBUG ((EFI_D_INFO, " Not Valid primary partition table\n")); if (!PartitionValidGptTable (BlockIo, DiskIo, LastBlock, BackupHeader)) { DEBUG ((EFI_D_INFO, " Not Valid backup partition table\n")); goto Done; } else { DEBUG ((EFI_D_INFO, " Valid backup partition table\n")); DEBUG ((EFI_D_INFO, " Restore primary partition table by the backup\n")); if (!PartitionRestoreGptTable (BlockIo, DiskIo, BackupHeader)) { DEBUG ((EFI_D_INFO, " Restore primary partition table error\n")); } if (PartitionValidGptTable (BlockIo, DiskIo, BackupHeader->AlternateLBA, PrimaryHeader)) { DEBUG ((EFI_D_INFO, " Restore backup partition table success\n")); } } } else if (!PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) { DEBUG ((EFI_D_INFO, " Valid primary and !Valid backup partition table\n")); DEBUG ((EFI_D_INFO, " Restore backup partition table by the primary\n")); if (!PartitionRestoreGptTable (BlockIo, DiskIo, PrimaryHeader)) { DEBUG ((EFI_D_INFO, " Restore backup partition table error\n")); } if (PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) { DEBUG ((EFI_D_INFO, " Restore backup partition table success\n")); } } DEBUG ((EFI_D_INFO, " Valid primary and Valid backup partition table\n")); // // Read the EFI Partition Entries // PartEntry = AllocatePool (PrimaryHeader->NumberOfPartitionEntries * PrimaryHeader->SizeOfPartitionEntry); if (PartEntry == NULL) { DEBUG ((EFI_D_ERROR, "Allocate pool error\n")); goto Done; } Status = DiskIo->ReadDisk ( DiskIo, MediaId, MultU64x32(PrimaryHeader->PartitionEntryLBA, BlockSize), PrimaryHeader->NumberOfPartitionEntries * (PrimaryHeader->SizeOfPartitionEntry), PartEntry ); if (EFI_ERROR (Status)) { GptValidStatus = Status; DEBUG ((EFI_D_ERROR, " Partition Entry ReadDisk error\n")); goto Done; } DEBUG ((EFI_D_INFO, " Partition entries read block success\n")); DEBUG ((EFI_D_INFO, " Number of partition entries: %d\n", PrimaryHeader->NumberOfPartitionEntries)); PEntryStatus = AllocateZeroPool (PrimaryHeader->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)); if (PEntryStatus == NULL) { DEBUG ((EFI_D_ERROR, "Allocate pool error\n")); goto Done; } // // Check the integrity of partition entries // PartitionCheckGptEntry (PrimaryHeader, PartEntry, PEntryStatus); // // If we got this far the GPT layout of the disk is valid and we should return true // GptValidStatus = EFI_SUCCESS; // // Create child device handles // for (Index = 0; Index < PrimaryHeader->NumberOfPartitionEntries; Index++) { Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartEntry + Index * PrimaryHeader->SizeOfPartitionEntry); if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid) || PEntryStatus[Index].OutOfRange || PEntryStatus[Index].Overlap || PEntryStatus[Index].OsSpecific ) { // // Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific // partition Entries // continue; } ZeroMem (&HdDev, sizeof (HdDev)); HdDev.Header.Type = MEDIA_DEVICE_PATH; HdDev.Header.SubType = MEDIA_HARDDRIVE_DP; SetDevicePathNodeLength (&HdDev.Header, sizeof (HdDev)); HdDev.PartitionNumber = (UINT32) Index + 1; HdDev.MBRType = MBR_TYPE_EFI_PARTITION_TABLE_HEADER; HdDev.SignatureType = SIGNATURE_TYPE_GUID; HdDev.PartitionStart = Entry->StartingLBA; HdDev.PartitionSize = Entry->EndingLBA - Entry->StartingLBA + 1; CopyMem (HdDev.Signature, &Entry->UniquePartitionGUID, sizeof (EFI_GUID)); DEBUG ((EFI_D_INFO, " Index : %d\n", (UINT32) Index)); DEBUG ((EFI_D_INFO, " Start LBA : %lx\n", (UINT64) HdDev.PartitionStart)); DEBUG ((EFI_D_INFO, " End LBA : %lx\n", (UINT64) Entry->EndingLBA)); DEBUG ((EFI_D_INFO, " Partition size: %lx\n", (UINT64) HdDev.PartitionSize)); DEBUG ((EFI_D_INFO, " Start : %lx", MultU64x32 (Entry->StartingLBA, BlockSize))); DEBUG ((EFI_D_INFO, " End : %lx\n", MultU64x32 (Entry->EndingLBA, BlockSize))); Status = PartitionInstallChildHandle ( This, Handle, DiskIo, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, Entry->StartingLBA, Entry->EndingLBA, BlockSize, CompareGuid(&Entry->PartitionTypeGUID, &gEfiPartTypeSystemPartGuid) ); } DEBUG ((EFI_D_INFO, "Prepare to Free Pool\n")); Done: if (ProtectiveMbr != NULL) { FreePool (ProtectiveMbr); } if (PrimaryHeader != NULL) { FreePool (PrimaryHeader); } if (BackupHeader != NULL) { FreePool (BackupHeader); } if (PartEntry != NULL) { FreePool (PartEntry); } if (PEntryStatus != NULL) { FreePool (PEntryStatus); } return GptValidStatus; }
/** Create an interface for the descriptor IfDesc. Each device's configuration can have several interfaces. @param Device The device has the interface descriptor. @param IfDesc The interface descriptor. @return The created USB interface for the descriptor, or NULL. **/ USB_INTERFACE * UsbCreateInterface ( IN USB_DEVICE *Device, IN USB_INTERFACE_DESC *IfDesc ) { USB_DEVICE_PATH UsbNode; USB_INTERFACE *UsbIf; USB_INTERFACE *HubIf; EFI_STATUS Status; UsbIf = AllocateZeroPool (sizeof (USB_INTERFACE)); if (UsbIf == NULL) { return NULL; } UsbIf->Signature = USB_INTERFACE_SIGNATURE; UsbIf->Device = Device; UsbIf->IfDesc = IfDesc; // ASSERT (IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING); if (IfDesc->ActiveIndex >= USB_MAX_INTERFACE_SETTING) { FreePool(UsbIf); return NULL; } UsbIf->IfSetting = IfDesc->Settings[IfDesc->ActiveIndex]; CopyMem ( &(UsbIf->UsbIo), &mUsbIoProtocol, sizeof (EFI_USB_IO_PROTOCOL) ); // // Install protocols for USBIO and device path // UsbNode.Header.Type = MESSAGING_DEVICE_PATH; UsbNode.Header.SubType = MSG_USB_DP; UsbNode.ParentPortNumber = Device->ParentPort; UsbNode.InterfaceNumber = UsbIf->IfSetting->Desc.InterfaceNumber; SetDevicePathNodeLength (&UsbNode.Header, sizeof (UsbNode)); HubIf = Device->ParentIf; // ASSERT (HubIf != NULL); if (!HubIf) { return NULL; } UsbIf->DevicePath = AppendDevicePathNode (HubIf->DevicePath, &UsbNode.Header); if (UsbIf->DevicePath == NULL) { // DEBUG ((EFI_D_ERROR, "UsbCreateInterface: failed to create device path\n")); DBG("UsbCreateInterface: failed to create device path\n"); Status = EFI_OUT_OF_RESOURCES; goto ON_ERROR; } Status = gBS->InstallMultipleProtocolInterfaces ( &UsbIf->Handle, &gEfiDevicePathProtocolGuid, UsbIf->DevicePath, &gEfiUsbIoProtocolGuid, &UsbIf->UsbIo, NULL ); if (EFI_ERROR (Status)) { // DEBUG ((EFI_D_ERROR, "UsbCreateInterface: failed to install UsbIo - %r\n", Status)); goto ON_ERROR; } // // Open USB Host Controller Protocol by Child // Status = UsbOpenHostProtoByChild (Device->Bus, UsbIf->Handle); if (EFI_ERROR (Status)) { gBS->UninstallMultipleProtocolInterfaces ( &UsbIf->Handle, &gEfiDevicePathProtocolGuid, UsbIf->DevicePath, &gEfiUsbIoProtocolGuid, &UsbIf->UsbIo, NULL ); // DEBUG ((EFI_D_ERROR, "UsbCreateInterface: failed to open host for child - %r\n", Status)); DBG("UsbCreateInterface: failed to open host for child - %r\n", Status); goto ON_ERROR; } return UsbIf; ON_ERROR: if (UsbIf->DevicePath != NULL) { FreePool (UsbIf->DevicePath); } FreePool (UsbIf); return NULL; }
/** Install child handles if the Handle supports MBR format. @param This Calling context. @param Handle Parent Handle. @param DiskIo Parent DiskIo interface. @param BlockIo Parent BlockIo interface. @param DevicePath Parent Device Path. @retval EFI_SUCCESS A child handle was added. @retval EFI_MEDIA_CHANGED Media change was detected. @retval Others MBR partition was not found. **/ EFI_STATUS PartitionInstallMbrChildHandles ( 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 ) { EFI_STATUS Status; MASTER_BOOT_RECORD *Mbr; UINT32 ExtMbrStartingLba; UINTN Index; HARDDRIVE_DEVICE_PATH HdDev; HARDDRIVE_DEVICE_PATH ParentHdDev; EFI_STATUS Found; UINT32 PartitionNumber; EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; EFI_DEVICE_PATH_PROTOCOL *LastDevicePathNode; Found = EFI_NOT_FOUND; Mbr = AllocatePool (BlockIo->Media->BlockSize); if (Mbr == NULL) { return Found; } Status = DiskIo->ReadDisk ( DiskIo, BlockIo->Media->MediaId, 0, BlockIo->Media->BlockSize, Mbr ); if (EFI_ERROR (Status)) { Found = Status; goto Done; } if (!PartitionValidMbr (Mbr, BlockIo->Media->LastBlock)) { goto Done; } // // We have a valid mbr - add each partition // // // Get starting and ending LBA of the parent block device. // LastDevicePathNode = NULL; ZeroMem (&ParentHdDev, sizeof (ParentHdDev)); DevicePathNode = DevicePath; while (!IsDevicePathEnd (DevicePathNode)) { LastDevicePathNode = DevicePathNode; DevicePathNode = NextDevicePathNode (DevicePathNode); } if (LastDevicePathNode != NULL) { if (DevicePathType (LastDevicePathNode) == MEDIA_DEVICE_PATH && DevicePathSubType (LastDevicePathNode) == MEDIA_HARDDRIVE_DP ) { CopyMem (&ParentHdDev, LastDevicePathNode, sizeof (ParentHdDev)); } else { LastDevicePathNode = NULL; } } PartitionNumber = 1; ZeroMem (&HdDev, sizeof (HdDev)); HdDev.Header.Type = MEDIA_DEVICE_PATH; HdDev.Header.SubType = MEDIA_HARDDRIVE_DP; SetDevicePathNodeLength (&HdDev.Header, sizeof (HdDev)); HdDev.MBRType = MBR_TYPE_PCAT; HdDev.SignatureType = SIGNATURE_TYPE_MBR; if (LastDevicePathNode == NULL) { // // This is a MBR, add each partition // for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) { if (Mbr->Partition[Index].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA) == 0) { // // Don't use null MBR entries // continue; } if (Mbr->Partition[Index].OSIndicator == PMBR_GPT_PARTITION) { // // This is the guard MBR for the GPT. If you ever see a GPT disk with zero partitions you can get here. // We can not produce an MBR BlockIo for this device as the MBR spans the GPT headers. So formating // this BlockIo would corrupt the GPT structures and require a recovery that would corrupt the format // that corrupted the GPT partition. // continue; } HdDev.PartitionNumber = PartitionNumber ++; HdDev.PartitionStart = UNPACK_UINT32 (Mbr->Partition[Index].StartingLBA); HdDev.PartitionSize = UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA); CopyMem (HdDev.Signature, &(Mbr->UniqueMbrSignature[0]), sizeof (Mbr->UniqueMbrSignature)); Status = PartitionInstallChildHandle ( This, Handle, DiskIo, BlockIo, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, HdDev.PartitionStart, HdDev.PartitionStart + HdDev.PartitionSize - 1, MBR_SIZE, (BOOLEAN) (Mbr->Partition[Index].OSIndicator == EFI_PARTITION) ); if (!EFI_ERROR (Status)) { Found = EFI_SUCCESS; } } } else { // // It's an extended partition. Follow the extended partition // chain to get all the logical drives // ExtMbrStartingLba = 0; do { Status = DiskIo->ReadDisk ( DiskIo, BlockIo->Media->MediaId, MultU64x32 (ExtMbrStartingLba, BlockIo->Media->BlockSize), BlockIo->Media->BlockSize, Mbr ); if (EFI_ERROR (Status)) { Found = Status; goto Done; } if (UNPACK_UINT32 (Mbr->Partition[0].SizeInLBA) == 0) { break; } if ((Mbr->Partition[0].OSIndicator == EXTENDED_DOS_PARTITION) || (Mbr->Partition[0].OSIndicator == EXTENDED_WINDOWS_PARTITION)) { ExtMbrStartingLba = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA); continue; } HdDev.PartitionNumber = PartitionNumber ++; HdDev.PartitionStart = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA) + ExtMbrStartingLba + ParentHdDev.PartitionStart; HdDev.PartitionSize = UNPACK_UINT32 (Mbr->Partition[0].SizeInLBA); if ((HdDev.PartitionStart + HdDev.PartitionSize - 1 >= ParentHdDev.PartitionStart + ParentHdDev.PartitionSize) || (HdDev.PartitionStart <= ParentHdDev.PartitionStart)) { break; } // // The signature in EBR(Extended Boot Record) should always be 0. // *((UINT32 *) &HdDev.Signature[0]) = 0; Status = PartitionInstallChildHandle ( This, Handle, DiskIo, BlockIo, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, HdDev.PartitionStart - ParentHdDev.PartitionStart, HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1, MBR_SIZE, (BOOLEAN) (Mbr->Partition[0].OSIndicator == EFI_PARTITION) ); if (!EFI_ERROR (Status)) { Found = EFI_SUCCESS; } if ((Mbr->Partition[1].OSIndicator != EXTENDED_DOS_PARTITION) && (Mbr->Partition[1].OSIndicator != EXTENDED_WINDOWS_PARTITION) ) { break; } ExtMbrStartingLba = UNPACK_UINT32 (Mbr->Partition[1].StartingLBA); // // Don't allow partition to be self referencing // if (ExtMbrStartingLba == 0) { break; } } while (ExtMbrStartingLba < ParentHdDev.PartitionSize); } Done: FreePool (Mbr); return Found; }
/** Used to allocate and build a device path node for a SCSI device on a SCSI channel. @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance. @param[in] Target The Target is an array of size TARGET_MAX_BYTES and it specifies the Target ID of the SCSI device for which a device path node is to be allocated and built. Transport drivers may chose to utilize a subset of this size to suit the representation of targets. For example, a Fibre Channel driver may use only 8 bytes (WWN) in the array to represent a FC target. @param[in] Lun The LUN of the SCSI device for which a device path node is to be allocated and built. @param[in, out] DevicePath A pointer to a single device path node that describes the SCSI device specified by Target and Lun. This function is responsible for allocating the buffer DevicePath with the boot service AllocatePool(). It is the caller's responsibility to free DevicePath when the caller is finished with DevicePath. @retval EFI_SUCCESS The device path node that describes the SCSI device specified by Target and Lun was allocated and returned in DevicePath. @retval EFI_INVALID_PARAMETER DevicePath is NULL. @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist on the SCSI channel. @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath. **/ EFI_STATUS EFIAPI IScsiExtScsiPassThruBuildDevicePath ( IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN UINT8 *Target, IN UINT64 Lun, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath ) { ISCSI_DRIVER_DATA *Private; ISCSI_SESSION *Session; ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData; ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfig; EFI_DEV_PATH *Node; UINTN DevPathNodeLen; if (DevicePath == NULL) { return EFI_INVALID_PARAMETER; } if (Target[0] != 0) { return EFI_NOT_FOUND; } Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This); Session = &Private->Session; ConfigNvData = &Session->ConfigData.NvData; AuthConfig = &Session->AuthData.AuthConfig; if (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) != 0) { return EFI_NOT_FOUND; } DevPathNodeLen = sizeof (ISCSI_DEVICE_PATH) + AsciiStrLen (ConfigNvData->TargetName) + 1; Node = AllocatePool (DevPathNodeLen); if (Node == NULL) { return EFI_OUT_OF_RESOURCES; } Node->DevPath.Type = MESSAGING_DEVICE_PATH; Node->DevPath.SubType = MSG_ISCSI_DP; SetDevicePathNodeLength (&Node->DevPath, (UINT16)DevPathNodeLen); // // 0 for TCP, others are reserved. // Node->Iscsi.NetworkProtocol = 0; Node->Iscsi.LoginOption = 0; switch (AuthConfig->CHAPType) { case ISCSI_CHAP_NONE: Node->Iscsi.LoginOption |= 0x0800; break; case ISCSI_CHAP_UNI: Node->Iscsi.LoginOption |= 0x1000; break; default: break; } CopyMem (&Node->Iscsi.Lun, ConfigNvData->BootLun, sizeof (UINT64)); Node->Iscsi.TargetPortalGroupTag = Session->TargetPortalGroupTag; AsciiStrCpyS ((CHAR8 *) Node + sizeof (ISCSI_DEVICE_PATH), AsciiStrLen (ConfigNvData->TargetName) + 1, ConfigNvData->TargetName); *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node; return EFI_SUCCESS; }
/** Create the opened instances based on IPv6. @param[in] This Pointer to EFI_DRIVER_BINDING_PROTOCOL. @param[in] ControllerHandle Handle of the child to destroy. @param[in] Private Handle Pointer to PXEBC_PRIVATE_DATA. @retval EFI_SUCCESS The instances based on IPv6 were all created successfully. @retval Others An unexpected error occurred. **/ EFI_STATUS PxeBcCreateIp6Children ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN PXEBC_PRIVATE_DATA *Private ) { EFI_STATUS Status; IPv6_DEVICE_PATH Ip6Node; EFI_UDP6_CONFIG_DATA *Udp6CfgData; EFI_IP6_CONFIG_DATA *Ip6CfgData; EFI_IP6_MODE_DATA Ip6ModeData; PXEBC_PRIVATE_PROTOCOL *Id; EFI_SIMPLE_NETWORK_PROTOCOL *Snp; UINTN Index; if (Private->Ip6Nic != NULL) { // // Already created before. // return EFI_SUCCESS; } Private->Ip6Nic = AllocateZeroPool (sizeof (PXEBC_VIRTUAL_NIC)); if (Private->Ip6Nic == NULL) { return EFI_OUT_OF_RESOURCES; } Private->Ip6Nic->Private = Private; Private->Ip6Nic->Signature = PXEBC_VIRTUAL_NIC_SIGNATURE; // // Create Dhcp6 child and open Dhcp6 protocol for PxeBc->Dhcp. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiDhcp6ServiceBindingProtocolGuid, &Private->Dhcp6Child ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Dhcp6Child, &gEfiDhcp6ProtocolGuid, (VOID **) &Private->Dhcp6, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Generate a random IAID for the Dhcp6 assigned address. // Private->IaId = NET_RANDOM (NetRandomInitSeed ()); if (Private->Snp != NULL) { for (Index = 0; Index < Private->Snp->Mode->HwAddressSize; Index++) { Private->IaId |= (Private->Snp->Mode->CurrentAddress.Addr[Index] << ((Index << 3) & 31)); } } // // Create Mtftp6 child and open Mtftp6 protocol for PxeBc->Mtftp. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiMtftp6ServiceBindingProtocolGuid, &Private->Mtftp6Child ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Mtftp6Child, &gEfiMtftp6ProtocolGuid, (VOID **) &Private->Mtftp6, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Create Udp6 child and open Udp6 protocol for PxeBc->UdpRead. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiUdp6ServiceBindingProtocolGuid, &Private->Udp6ReadChild ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Udp6ReadChild, &gEfiUdp6ProtocolGuid, (VOID **) &Private->Udp6Read, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Create Udp6 child and open Udp6 protocol for PxeBc->UdpWrite. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiUdp6ServiceBindingProtocolGuid, &Private->Udp6WriteChild ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Udp6WriteChild, &gEfiUdp6ProtocolGuid, (VOID **) &Private->Udp6Write, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Create Ip6 child and open Ip6 protocol for background ICMP6 packets. // Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiIp6ServiceBindingProtocolGuid, &Private->Ip6Child ); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = gBS->OpenProtocol ( Private->Ip6Child, &gEfiIp6ProtocolGuid, (VOID **) &Private->Ip6, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Get max packet size from Ip6 to calculate block size for Tftp later. // Status = Private->Ip6->GetModeData (Private->Ip6, &Ip6ModeData, NULL, NULL); if (EFI_ERROR (Status)) { goto ON_ERROR; } Private->Ip6MaxPacketSize = Ip6ModeData.MaxPacketSize; // // Locate Ip6->Ip6Config and store it for set IPv6 address. // Status = gBS->HandleProtocol ( ControllerHandle, &gEfiIp6ConfigProtocolGuid, (VOID **) &Private->Ip6Cfg ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Create a device path node for Ipv6 virtual nic, and append it. // ZeroMem (&Ip6Node, sizeof (IPv6_DEVICE_PATH)); Ip6Node.Header.Type = MESSAGING_DEVICE_PATH; Ip6Node.Header.SubType = MSG_IPv6_DP; Ip6Node.PrefixLength = IP6_PREFIX_LENGTH; SetDevicePathNodeLength (&Ip6Node.Header, sizeof (Ip6Node)); Private->Ip6Nic->DevicePath = AppendDevicePathNode (Private->DevicePath, &Ip6Node.Header); if (Private->Ip6Nic->DevicePath == NULL) { Status = EFI_OUT_OF_RESOURCES; goto ON_ERROR; } CopyMem ( &Private->Ip6Nic->LoadFile, &gLoadFileProtocolTemplate, sizeof (EFI_LOAD_FILE_PROTOCOL) ); // // Create a new handle for IPv6 virtual nic, // and install PxeBaseCode, LoadFile and DevicePath protocols. // Status = gBS->InstallMultipleProtocolInterfaces ( &Private->Ip6Nic->Controller, &gEfiDevicePathProtocolGuid, Private->Ip6Nic->DevicePath, &gEfiLoadFileProtocolGuid, &Private->Ip6Nic->LoadFile, &gEfiPxeBaseCodeProtocolGuid, &Private->PxeBc, NULL ); if (EFI_ERROR (Status)) { goto ON_ERROR; } if (Private->Snp != NULL) { // // Install SNP protocol on purpose is for some OS loader backward // compatibility consideration. // Status = gBS->InstallProtocolInterface ( &Private->Ip6Nic->Controller, &gEfiSimpleNetworkProtocolGuid, EFI_NATIVE_INTERFACE, Private->Snp ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Open SNP on the child handle BY_DRIVER. It will prevent any additionally // layering to perform the experiment. // Status = gBS->OpenProtocol ( Private->Ip6Nic->Controller, &gEfiSimpleNetworkProtocolGuid, (VOID **) &Snp, This->DriverBindingHandle, Private->Ip6Nic->Controller, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } } // // Open PxeBaseCodePrivate protocol by child to setup a parent-child relationship between // real NIC handle and the virtual IPv6 NIC handle. // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiCallerIdGuid, (VOID **) &Id, This->DriverBindingHandle, Private->Ip6Nic->Controller, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); if (EFI_ERROR (Status)) { goto ON_ERROR; } // // Set IPv6 avaiable flag and set default configure data for // Udp6Read and Ip6 instance. // Private->Mode.Ipv6Available = TRUE; Udp6CfgData = &Private->Udp6CfgData; Ip6CfgData = &Private->Ip6CfgData; Udp6CfgData->AcceptAnyPort = TRUE; Udp6CfgData->AllowDuplicatePort = TRUE; Udp6CfgData->HopLimit = PXEBC_DEFAULT_HOPLIMIT; Udp6CfgData->ReceiveTimeout = PXEBC_DEFAULT_LIFETIME; Udp6CfgData->TransmitTimeout = PXEBC_DEFAULT_LIFETIME; Ip6CfgData->AcceptIcmpErrors = TRUE; Ip6CfgData->DefaultProtocol = IP6_ICMP; Ip6CfgData->HopLimit = PXEBC_DEFAULT_HOPLIMIT; Ip6CfgData->ReceiveTimeout = PXEBC_DEFAULT_LIFETIME; Ip6CfgData->TransmitTimeout = PXEBC_DEFAULT_LIFETIME; return EFI_SUCCESS; ON_ERROR: PxeBcDestroyIp6Children (This, Private); return Status; }
/** Initialize data for device that supports multiple LUNSs. @param This The Driver Binding Protocol instance. @param Controller The device to initialize. @param Transport Pointer to USB_MASS_TRANSPORT. @param Context Parameter for USB_MASS_DEVICE.Context. @param DevicePath The remaining device path. @param MaxLun The max LUN number. @retval EFI_SUCCESS At least one LUN is initialized successfully. @retval EFI_NOT_FOUND Fail to initialize any of multiple LUNs. **/ EFI_STATUS UsbMassInitMultiLun ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN USB_MASS_TRANSPORT *Transport, IN VOID *Context, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINT8 MaxLun ) { USB_MASS_DEVICE *UsbMass; EFI_USB_IO_PROTOCOL *UsbIo; DEVICE_LOGICAL_UNIT_DEVICE_PATH LunNode; UINT8 Index; EFI_STATUS Status; EFI_STATUS ReturnStatus; ASSERT (MaxLun > 0); ReturnStatus = EFI_NOT_FOUND; for (Index = 0; Index <= MaxLun; Index++) { DEBUG ((EFI_D_INFO, "UsbMassInitMultiLun: Start to initialize No.%d logic unit\n", Index)); UsbIo = NULL; UsbMass = AllocateZeroPool (sizeof (USB_MASS_DEVICE)); ASSERT (UsbMass != NULL); UsbMass->Signature = USB_MASS_SIGNATURE; UsbMass->UsbIo = UsbIo; UsbMass->BlockIo.Media = &UsbMass->BlockIoMedia; UsbMass->BlockIo.Reset = UsbMassReset; UsbMass->BlockIo.ReadBlocks = UsbMassReadBlocks; UsbMass->BlockIo.WriteBlocks = UsbMassWriteBlocks; UsbMass->BlockIo.FlushBlocks = UsbMassFlushBlocks; UsbMass->OpticalStorage = FALSE; UsbMass->Transport = Transport; UsbMass->Context = Context; UsbMass->Lun = Index; // // Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol. // Status = UsbMassInitMedia (UsbMass); if ((EFI_ERROR (Status)) && (Status != EFI_NO_MEDIA)) { DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: UsbMassInitMedia (%r)\n", Status)); FreePool (UsbMass); continue; } // // Create a device path node for device logic unit, and append it. // LunNode.Header.Type = MESSAGING_DEVICE_PATH; LunNode.Header.SubType = MSG_DEVICE_LOGICAL_UNIT_DP; LunNode.Lun = UsbMass->Lun; SetDevicePathNodeLength (&LunNode.Header, sizeof (LunNode)); UsbMass->DevicePath = AppendDevicePathNode (DevicePath, &LunNode.Header); if (UsbMass->DevicePath == NULL) { DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: failed to create device logic unit device path\n")); Status = EFI_OUT_OF_RESOURCES; FreePool (UsbMass); continue; } InitializeDiskInfo (UsbMass); // // Create a new handle for each LUN, and install Block I/O Protocol and Device Path Protocol. // Status = gBS->InstallMultipleProtocolInterfaces ( &UsbMass->Controller, &gEfiDevicePathProtocolGuid, UsbMass->DevicePath, &gEfiBlockIoProtocolGuid, &UsbMass->BlockIo, &gEfiDiskInfoProtocolGuid, &UsbMass->DiskInfo, NULL ); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: InstallMultipleProtocolInterfaces (%r)\n", Status)); FreePool (UsbMass->DevicePath); FreePool (UsbMass); continue; } // // Open USB I/O Protocol by child to setup a parent-child relationship. // Status = gBS->OpenProtocol ( Controller, &gEfiUsbIoProtocolGuid, (VOID **) &UsbIo, This->DriverBindingHandle, UsbMass->Controller, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: OpenUsbIoProtocol By Child (%r)\n", Status)); gBS->UninstallMultipleProtocolInterfaces ( &UsbMass->Controller, &gEfiDevicePathProtocolGuid, UsbMass->DevicePath, &gEfiBlockIoProtocolGuid, &UsbMass->BlockIo, &gEfiDiskInfoProtocolGuid, &UsbMass->DiskInfo, NULL ); FreePool (UsbMass->DevicePath); FreePool (UsbMass); continue; } ReturnStatus = EFI_SUCCESS; DEBUG ((EFI_D_INFO, "UsbMassInitMultiLun: Success to initialize No.%d logic unit\n", Index)); } return ReturnStatus; }
/** Install child handles if the Handle supports El Torito format. @param[in] This Calling context. @param[in] Handle Parent Handle. @param[in] DiskIo Parent DiskIo interface. @param[in] DiskIo2 Parent DiskIo2 interface. @param[in] BlockIo Parent BlockIo interface. @param[in] BlockIo2 Parent BlockIo2 interface. @param[in] DevicePath Parent Device Path @retval EFI_SUCCESS Child handle(s) was added. @retval EFI_MEDIA_CHANGED Media changed Detected. @retval other no child handle was added. **/ EFI_STATUS PartitionInstallElToritoChildHandles ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_DISK_IO2_PROTOCOL *DiskIo2, IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { 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; 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 = AllocatePool ((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 // // DBG("ELT: end of media\n") 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->Unknown.Type == CDVOL_TYPE_END || CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0 ) { // // end of Volume descriptor list // // DBG("ELT: end of Volume descriptor list\n"); 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->PrimaryVolume.Type == CDVOL_TYPE_CODED) { VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[0]; DBG("ELT: VolSpaceSize =%d\n", VolSpaceSize); } // // Is it an El Torito volume descriptor? // if (CompareMem (VolDescriptor->BootRecordVolume.SystemId, CDVOL_ELTORITO_ID, sizeof (CDVOL_ELTORITO_ID) - 1) != 0) { continue; } // // Read in the boot El Torito boot catalog // Lba = UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog); DBG("ELT: this is ELT at lba=%d\n", Lba); if (Lba > Media->LastBlock) { continue; } Status = DiskIo->ReadDisk ( DiskIo, Media->MediaId, MultU64x32 (Lba, Media->BlockSize), Media->BlockSize, Catalog ); if (EFI_ERROR (Status)) { DBG ("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) { DBG ("EltCheckBootCatalog: El Torito boot catalog header IDs=%x not correct\n", Catalog->Catalog.Indicator); continue; } Check = 0; CheckBuffer = (UINT16 *) Catalog; for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) { Check += CheckBuffer[Index]; } if ((Check & 0xFFFF) != 0) { DBG ( "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; DBG("ELT: SectorCount =%d\n", SectorCount); switch (Catalog->Boot.MediaType) { case ELTORITO_NO_EMULATION: SubBlockSize = Media->BlockSize; DBG("ELT: SubBlockSize =%d\n", SubBlockSize); 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: DBG("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; SectorCount = 0; //Slice } CdDev.BootEntry = (UINT32) BootEntry; BootEntry++; CdDev.PartitionStart = Catalog->Boot.Lba; DBG("ELT: Partition start %d\n", CdDev.PartitionStart); if (SectorCount < 2) { // // When the SectorCount < 2, set the Partition as the whole CD. // CdDev.PartitionStart = 0; //Slice if (VolSpaceSize > (Media->LastBlock + 1)) { CdDev.PartitionSize = (UINT32)(Media->LastBlock - Catalog->Boot.Lba + 1); } else { CdDev.PartitionSize = (UINT32)(VolSpaceSize - Catalog->Boot.Lba); } DBG("ELT: WholeCD PartitionSize=%d\n", CdDev.PartitionSize); } else { CdDev.PartitionSize = DivU64x32 ( MultU64x32 ( SectorCount, SubBlockSize ) + Media->BlockSize - 1, Media->BlockSize ); DBG("ELT: CD Partition%d Size=%d\n", Index, CdDev.PartitionSize); } Status = PartitionInstallChildHandle ( This, Handle, DiskIo, DiskIo2, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &CdDev, Catalog->Boot.Lba, Catalog->Boot.Lba + CdDev.PartitionSize - 1, SubBlockSize, FALSE ); if (!EFI_ERROR (Status)) { Found = EFI_SUCCESS; } } } FreePool (VolDescriptor); return Found; }
/** This function delete and build multi-instance device path for specified type of console device. This function clear the EFI variable defined by ConsoleName and gEfiGlobalVariableGuid. It then build the multi-instance device path by appending the device path of the Console (In/Out/Err) instance in ConsoleMenu. Then it scan all corresponding console device by scanning Terminal (built from device supporting Serial I/O instances) devices in TerminalMenu. At last, it save a EFI variable specifed by ConsoleName and gEfiGlobalVariableGuid. @param ConsoleName The name for the console device type. They are usually "ConIn", "ConOut" and "ErrOut". @param ConsoleMenu The console memu which is a list of console devices. @param UpdatePageId The flag specifying which type of console device to be processed. @retval EFI_SUCCESS The function complete successfully. @return The EFI variable can not be saved. See gRT->SetVariable for detail return information. **/ EFI_STATUS Var_UpdateConsoleOption ( IN UINT16 *ConsoleName, IN BM_MENU_OPTION *ConsoleMenu, IN UINT16 UpdatePageId ) { EFI_DEVICE_PATH_PROTOCOL *ConDevicePath; BM_MENU_ENTRY *NewMenuEntry; BM_CONSOLE_CONTEXT *NewConsoleContext; BM_TERMINAL_CONTEXT *NewTerminalContext; EFI_STATUS Status; VENDOR_DEVICE_PATH Vendor; EFI_DEVICE_PATH_PROTOCOL *TerminalDevicePath; UINTN Index; GetEfiGlobalVariable2 (ConsoleName, (VOID**)&ConDevicePath, NULL); if (ConDevicePath != NULL) { EfiLibDeleteVariable (ConsoleName, &gEfiGlobalVariableGuid); FreePool (ConDevicePath); ConDevicePath = NULL; }; // // First add all console input device from console input menu // for (Index = 0; Index < ConsoleMenu->MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (ConsoleMenu, Index); NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext; if (NewConsoleContext->IsActive) { ConDevicePath = AppendDevicePathInstance ( ConDevicePath, NewConsoleContext->DevicePath ); } } for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; if (((NewTerminalContext->IsConIn != 0) && (UpdatePageId == FORM_CON_IN_ID)) || ((NewTerminalContext->IsConOut != 0) && (UpdatePageId == FORM_CON_OUT_ID)) || ((NewTerminalContext->IsStdErr != 0) && (UpdatePageId == FORM_CON_ERR_ID)) ) { Vendor.Header.Type = MESSAGING_DEVICE_PATH; Vendor.Header.SubType = MSG_VENDOR_DP; ASSERT (NewTerminalContext->TerminalType < (sizeof (TerminalTypeGuid) / sizeof (TerminalTypeGuid[0]))); CopyMem ( &Vendor.Guid, &TerminalTypeGuid[NewTerminalContext->TerminalType], sizeof (EFI_GUID) ); SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH)); TerminalDevicePath = AppendDevicePathNode ( NewTerminalContext->DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &Vendor ); ASSERT (TerminalDevicePath != NULL); ChangeTerminalDevicePath (TerminalDevicePath, TRUE); ConDevicePath = AppendDevicePathInstance ( ConDevicePath, TerminalDevicePath ); } } if (ConDevicePath != NULL) { Status = gRT->SetVariable ( ConsoleName, &gEfiGlobalVariableGuid, VAR_FLAG, GetDevicePathSize (ConDevicePath), ConDevicePath ); if (EFI_ERROR (Status)) { return Status; } } return EFI_SUCCESS; }