/** Convert FvHandle and DriverName into an EFI device path @param Fv Fv protocol, needed to read Depex info out of FLASH. @param FvHandle Handle for Fv, needed in the EFI_SMM_DRIVER_ENTRY so that the PE image can be read out of the FV at a later time. @param DriverName Name of driver to add to mDiscoveredList. @return Pointer to device path constructed from FvHandle and DriverName **/ EFI_DEVICE_PATH_PROTOCOL * SmmFvToDevicePath ( IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv, IN EFI_HANDLE FvHandle, IN EFI_GUID *DriverName ) { EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *FvDevicePath; EFI_DEVICE_PATH_PROTOCOL *FileNameDevicePath; // // Remember the device path of the FV // Status = gBS->HandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath); if (EFI_ERROR (Status)) { FileNameDevicePath = NULL; } else { // // Build a device path to the file in the FV to pass into gBS->LoadImage // EfiInitializeFwVolDevicepathNode (&mFvDevicePath.File, DriverName); SetDevicePathEndNode (&mFvDevicePath.End); // // Note: FileNameDevicePath is in DXE memory // FileNameDevicePath = AppendDevicePath ( FvDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath ); } return FileNameDevicePath; }
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_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; }
/** Register image to memory profile. @param FileName File name of the image. @param ImageBase Image base address. @param ImageSize Image size. @param FileType File type of the image. **/ VOID RegisterMemoryProfileImage ( IN EFI_GUID *FileName, IN PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize, IN EFI_FV_FILETYPE FileType ) { EFI_STATUS Status; EDKII_MEMORY_PROFILE_PROTOCOL *ProfileProtocol; MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath; UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)]; if ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0) { FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer; Status = gBS->LocateProtocol (&gEdkiiMemoryProfileGuid, NULL, (VOID **) &ProfileProtocol); if (!EFI_ERROR (Status)) { EfiInitializeFwVolDevicepathNode (FilePath, FileName); SetDevicePathEndNode (FilePath + 1); Status = ProfileProtocol->RegisterImage ( ProfileProtocol, (EFI_DEVICE_PATH_PROTOCOL *) FilePath, ImageBase, ImageSize, FileType ); } } }
// // 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; }
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_DEVICE_PATH * LibDuplicateDevicePathInstance ( IN EFI_DEVICE_PATH *DevPath ) { EFI_DEVICE_PATH *NewDevPath,*DevicePathInst,*Temp; UINTN Size = 0; // // get the size of an instance from the input // Temp = DevPath; DevicePathInst = DevicePathInstance (&Temp, &Size); // // Make a copy and set proper end type // NewDevPath = NULL; if (Size) { NewDevPath = AllocatePool (Size + sizeof(EFI_DEVICE_PATH)); } if (NewDevPath) { CopyMem (NewDevPath, DevicePathInst, Size); Temp = NextDevicePathNode(NewDevPath); SetDevicePathEndNode(Temp); } return NewDevPath; }
EFI_DEVICE_PATH * AppendDevicePathNode ( IN EFI_DEVICE_PATH *Src1, IN EFI_DEVICE_PATH *Src2 ) // Src1 may have multiple "instances" and each instance is appended // Src2 is a signal device path node (without a terminator) that is // appended to each instance is Src1. { EFI_DEVICE_PATH *Temp, *Eop; UINTN Length; // // Build a Src2 that has a terminator on it // Length = DevicePathNodeLength(Src2); Temp = AllocatePool (Length + sizeof(EFI_DEVICE_PATH)); if (!Temp) { return NULL; } CopyMem (Temp, Src2, Length); Eop = NextDevicePathNode(Temp); SetDevicePathEndNode(Eop); // // Append device paths // Src1 = AppendDevicePath (Src1, Temp); FreePool (Temp); return Src1; }
EFI_STATUS BdsLoadOptionPxeCreateDevicePath ( IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes ) { *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH); SetDevicePathEndNode (*DevicePathNodes); return EFI_SUCCESS; }
EFI_DEVICE_PATH_PROTOCOL * AppendDevicePathNode ( IN EFI_DEVICE_PATH_PROTOCOL *Src1, IN EFI_DEVICE_PATH_PROTOCOL *Src2 ) /*++ Routine Description: Function is used to append a device path node to all the instances in another device path. Arguments: Src1 - A pointer to a device path data structure. Src2 - A pointer to a device path data structure. Returns: This function returns a pointer to the new device path. If there is not enough temporary pool memory available to complete this function, then NULL is returned. Src1 may have multiple "instances" and each instance is appended Src2 is a signal device path node (without a terminator) that is appended to each instance is Src1. --*/ { EFI_DEVICE_PATH_PROTOCOL *Temp, *Eop; UINTN Length; // // Build a Src2 that has a terminator on it // Length = DevicePathNodeLength(Src2); Temp = AllocatePool (Length + sizeof(EFI_DEVICE_PATH_PROTOCOL)); if (!Temp) { return NULL; } CopyMem (Temp, Src2, Length); Eop = NextDevicePathNode(Temp); SetDevicePathEndNode(Eop); // // Append device paths // Src1 = AppendDevicePath (Src1, Temp); FreePool (Temp); return Src1; }
EFI_DEVICE_PATH_PROTOCOL * DevicePathInstanceDup ( IN EFI_DEVICE_PATH_PROTOCOL *DevPath ) /*++ Routine Description: Function creates a device path data structure that identically matches the device path passed in. Arguments: DevPath - A pointer to a device path data structure. Returns: The new copy of DevPath is created to identically match the input. Otherwise, NULL is returned. --*/ { EFI_DEVICE_PATH_PROTOCOL *NewDevPath; EFI_DEVICE_PATH_PROTOCOL *DevicePathInst; EFI_DEVICE_PATH_PROTOCOL *Temp; UINT8 *Ptr; UINTN Size; // // get the size of an instance from the input // Temp = DevPath; DevicePathInst = EfiDevicePathInstance (&Temp, &Size); // // Make a copy and set proper end type // NewDevPath = NULL; if (Size) { NewDevPath = EfiAllocateZeroPool (Size); ASSERT (NewDevPath != NULL); } if (NewDevPath) { EfiCopyMem (NewDevPath, DevicePathInst, Size); Ptr = (UINT8 *) NewDevPath; Ptr += Size - sizeof (EFI_DEVICE_PATH_PROTOCOL); Temp = (EFI_DEVICE_PATH_PROTOCOL *) Ptr; SetDevicePathEndNode (Temp); } return NewDevPath; }
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; }
VOID CreateVendorDevicePath ( OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, IN EFI_GUID Guid ) { UINTN Length; EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; EFI_DEVICE_PATH_PROTOCOL *DevPointer; EFI_STATUS Status; // // init // *DevicePath = NULL; Length = sizeof (VENDOR_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL); Status = gtBS->AllocatePool ( EfiBootServicesData, Length, (VOID**)DevicePath ); if (EFI_ERROR(Status)) { return; } DevicePathNode = NULL; CreateVendorDevicePathNode (&DevicePathNode, Guid); DevPointer = *DevicePath; gtBS->CopyMem (DevPointer, DevicePathNode, sizeof (VENDOR_DEVICE_PATH)); // // points to next node // DevPointer = (EFI_DEVICE_PATH_PROTOCOL*)((UINT8*)DevPointer + sizeof (VENDOR_DEVICE_PATH)); // // End Node // SetDevicePathEndNode (DevPointer); // // release resource // FreeVendorDevicePathNode (DevicePathNode); return; }
EFIAPI GetHIDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { UINTN NonHIDevicePathNodeCount; UINTN Index; EFI_DEV_PATH Node; EFI_DEVICE_PATH_PROTOCOL *HIDevicePath; EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; ASSERT(DevicePath != NULL); NonHIDevicePathNodeCount = 0; HIDevicePath = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL)); SetDevicePathEndNode (HIDevicePath); Node.DevPath.Type = END_DEVICE_PATH_TYPE; Node.DevPath.SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE; Node.DevPath.Length[0] = (UINT8)sizeof (EFI_DEVICE_PATH_PROTOCOL); Node.DevPath.Length[1] = 0; while (!IsDevicePathEnd (DevicePath)) { if (IsHIDevicePathNode (DevicePath)) { for (Index = 0; Index < NonHIDevicePathNodeCount; Index++) { TempDevicePath = AppendDevicePathNode (HIDevicePath, &Node.DevPath); FreePool (HIDevicePath); HIDevicePath = TempDevicePath; } TempDevicePath = AppendDevicePathNode (HIDevicePath, DevicePath); FreePool (HIDevicePath); HIDevicePath = TempDevicePath; } else { NonHIDevicePathNodeCount++; } // // Next device path node // DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) NextDevicePathNode (DevicePath); } return HIDevicePath; }
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; }
/** Connect the console device base on the variable ConVarName, if device path of the ConVarName is multi-instance device path and anyone of the instances is connected success, then this function will return success. If the handle associate with one device path node can not be created successfully, then still give chance to do the dispatch, which load the missing drivers if possible.. @param ConVarName Console related variable name, ConIn, ConOut, ErrOut. @retval EFI_NOT_FOUND There is not any console devices connected success @retval EFI_SUCCESS Success connect any one instance of the console device path base on the variable ConVarName. **/ EFI_STATUS EFIAPI BdsLibConnectConsoleVariable ( IN CHAR16 *ConVarName ) { EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *StartDevicePath; UINTN VariableSize; EFI_DEVICE_PATH_PROTOCOL *Instance; EFI_DEVICE_PATH_PROTOCOL *Next; EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath; UINTN Size; BOOLEAN DeviceExist; Status = EFI_SUCCESS; DeviceExist = FALSE; // // Check if the console variable exist // StartDevicePath = BdsLibGetVariableAndSize ( ConVarName, &gEfiGlobalVariableGuid, &VariableSize ); if (StartDevicePath == NULL) { return EFI_UNSUPPORTED; } CopyOfDevicePath = StartDevicePath; do { // // Check every instance of the console variable // Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size); if (Instance == NULL) { FreePool (StartDevicePath); return EFI_UNSUPPORTED; } Next = Instance; while (!IsDevicePathEndType (Next)) { Next = NextDevicePathNode (Next); } SetDevicePathEndNode (Next); // // Connect the USB console // USB console device path is a short-form device path that // starts with the first element being a USB WWID // or a USB Class device path // if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) && ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP) || (DevicePathSubType (Instance) == MSG_USB_WWID_DP) )) { Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance); if (!EFI_ERROR (Status)) { DeviceExist = TRUE; } } else { // // Connect the instance device path // Status = BdsLibConnectDevicePath (Instance); if (EFI_ERROR (Status)) { // // Delete the instance from the console varialbe // BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance); } else { DeviceExist = TRUE; } } FreePool(Instance); } while (CopyOfDevicePath != NULL); FreePool (StartDevicePath); if (!DeviceExist) { return EFI_NOT_FOUND; } return EFI_SUCCESS; }
static int efipart_init(void) { EFI_BLOCK_IO *blkio; EFI_DEVICE_PATH *devpath, *devpathcpy, *tmpdevpath, *node; EFI_HANDLE *hin, *hout, *aliases, handle; EFI_STATUS status; UINTN sz; u_int n, nin, nout; int err; size_t devpathlen; sz = 0; hin = NULL; status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, 0); if (status == EFI_BUFFER_TOO_SMALL) { hin = (EFI_HANDLE *)malloc(sz * 3); status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, hin); if (EFI_ERROR(status)) free(hin); } if (EFI_ERROR(status)) return (efi_status_to_errno(status)); /* Filter handles to only include FreeBSD partitions. */ nin = sz / sizeof(EFI_HANDLE); hout = hin + nin; aliases = hout + nin; nout = 0; bzero(aliases, nin * sizeof(EFI_HANDLE)); for (n = 0; n < nin; n++) { status = BS->HandleProtocol(hin[n], &devpath_guid, (void **)&devpath); if (EFI_ERROR(status)) { continue; } node = devpath; devpathlen = DevicePathNodeLength(node); while (!IsDevicePathEnd(NextDevicePathNode(node))) { node = NextDevicePathNode(node); devpathlen += DevicePathNodeLength(node); } devpathlen += DevicePathNodeLength(NextDevicePathNode(node)); status = BS->HandleProtocol(hin[n], &blkio_guid, (void**)&blkio); if (EFI_ERROR(status)) continue; if (!blkio->Media->LogicalPartition) continue; /* * If we come across a logical partition of subtype CDROM * it doesn't refer to the CD filesystem itself, but rather * to any usable El Torito boot image on it. In this case * we try to find the parent device and add that instead as * that will be the CD filesystem. */ if (DevicePathType(node) == MEDIA_DEVICE_PATH && DevicePathSubType(node) == MEDIA_CDROM_DP) { devpathcpy = malloc(devpathlen); memcpy(devpathcpy, devpath, devpathlen); node = devpathcpy; while (!IsDevicePathEnd(NextDevicePathNode(node))) node = NextDevicePathNode(node); SetDevicePathEndNode(node); tmpdevpath = devpathcpy; status = BS->LocateDevicePath(&blkio_guid, &tmpdevpath, &handle); free(devpathcpy); if (EFI_ERROR(status)) continue; hout[nout] = handle; aliases[nout] = hin[n]; } else hout[nout] = hin[n]; nout++; } err = efi_register_handles(&efipart_dev, hout, aliases, nout); free(hin); return (err); }
/** Internal work function to fill in EFI_OPEN_FILE information for the Fs and BlkIo @param File Open file handle @param FileName Name of file after device stripped off **/ EFI_STATUS EblFileDevicePath ( IN OUT EFI_OPEN_FILE *File, IN CHAR8 *FileName, IN CONST UINT64 OpenMode ) { EFI_STATUS Status; UINTN Size; FILEPATH_DEVICE_PATH *FilePath; EFI_DEVICE_PATH_PROTOCOL *FileDevicePath; CHAR16 UnicodeFileName[MAX_PATHNAME]; EFI_BLOCK_IO_PROTOCOL *BlkIo; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs; EFI_FILE_HANDLE Root; if ( *FileName != 0 ) { AsciiStrToUnicodeStr (FileName, UnicodeFileName); } else { AsciiStrToUnicodeStr ("\\", UnicodeFileName); } Size = StrSize (UnicodeFileName); FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + sizeof (EFI_DEVICE_PATH_PROTOCOL)); if (FileDevicePath != NULL) { FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath; FilePath->Header.Type = MEDIA_DEVICE_PATH; FilePath->Header.SubType = MEDIA_FILEPATH_DP; CopyMem (&FilePath->PathName, UnicodeFileName, Size); SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH); SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header)); if (File->EfiHandle != NULL) { File->DevicePath = DevicePathFromHandle (File->EfiHandle); } File->DevicePath = AppendDevicePath (File->DevicePath, FileDevicePath); FreePool (FileDevicePath); } Status = gBS->HandleProtocol (File->EfiHandle, &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo); if (!EFI_ERROR (Status)) { File->FsBlockIoMedia = BlkIo->Media; File->FsBlockIo = BlkIo; // If we are not opening the device this will get over written with file info File->MaxPosition = MultU64x32 (BlkIo->Media->LastBlock + 1, BlkIo->Media->BlockSize); } if (File->Type == EfiOpenFileSystem) { Status = gBS->HandleProtocol (File->EfiHandle, &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs); if (!EFI_ERROR (Status)) { Status = Fs->OpenVolume (Fs, &Root); if (!EFI_ERROR (Status)) { // Get information about the volume Size = 0; Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo); if (Status == EFI_BUFFER_TOO_SMALL) { File->FsInfo = AllocatePool (Size); Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo); } // Get information about the file Status = Root->Open (Root, &File->FsFileHandle, UnicodeFileName, OpenMode, 0); if (!EFI_ERROR (Status)) { Size = 0; Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, NULL); if (Status == EFI_BUFFER_TOO_SMALL) { File->FsFileInfo = AllocatePool (Size); Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, File->FsFileInfo); if (!EFI_ERROR (Status)) { File->Size = (UINTN)File->FsFileInfo->FileSize; File->MaxPosition = (UINT64)File->Size; } } } Root->Close (Root); } } } else if (File->Type == EfiOpenBlockIo) { File->Size = (UINTN)File->MaxPosition; } return Status; }
/** 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 BootMenuUpdateBootOption ( IN LIST_ENTRY *BootOptionsList ) { EFI_STATUS Status; BDS_LOAD_OPTION_ENTRY *BootOptionEntry; BDS_LOAD_OPTION *BootOption; BDS_LOAD_OPTION_SUPPORT* DeviceSupport; ARM_BDS_LOADER_ARGUMENTS* BootArguments; CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX]; CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX]; CHAR16 UnicodeCmdLine[BOOT_DEVICE_OPTION_MAX]; EFI_DEVICE_PATH *DevicePath; EFI_DEVICE_PATH *TempInitrdPath; ARM_BDS_LOADER_TYPE BootType; ARM_BDS_LOADER_OPTIONAL_DATA* LoaderOptionalData; ARM_BDS_LINUX_ARGUMENTS* LinuxArguments; EFI_DEVICE_PATH *InitrdPathNodes; EFI_DEVICE_PATH *InitrdPath; UINTN InitrdSize; UINTN CmdLineSize; BOOLEAN InitrdSupport; UINT8* OptionalData; UINTN OptionalDataSize; BOOLEAN IsPrintable; BOOLEAN IsUnicode; DisplayBootOptions (BootOptionsList); Status = SelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, &BootOptionEntry); if (EFI_ERROR (Status)) { return Status; } BootOption = BootOptionEntry->BdsLoadOption; // Get the device support for this Boot Option Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport); if (EFI_ERROR(Status)) { Print(L"Not possible to retrieve the supported device for the update\n"); return EFI_UNSUPPORTED; } Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath); if (EFI_ERROR(Status)) { Status = EFI_ABORTED; goto EXIT; } if (DeviceSupport->RequestBootType) { Status = BootDeviceGetType (DevicePath, &BootType, &BootOption->Attributes); if (EFI_ERROR(Status)) { Status = EFI_ABORTED; goto EXIT; } } LoaderOptionalData = BootOption->OptionalData; if (LoaderOptionalData != NULL) { BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&LoaderOptionalData->Header.LoaderType)); } else { BootType = BDS_LOADER_EFI_APPLICATION; } if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) { LinuxArguments = &LoaderOptionalData->Arguments.LinuxArguments; CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize); InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize); if (InitrdSize > 0) { Print(L"Keep the initrd: "); } else { Print(L"Add an initrd: "); } Status = GetHIInputBoolean (&InitrdSupport); if (EFI_ERROR(Status)) { Status = EFI_ABORTED; goto EXIT; } if (InitrdSupport) { if (InitrdSize > 0) { // Case we update the initrd device path Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath); if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd Status = EFI_ABORTED; goto EXIT; } InitrdSize = GetDevicePathSize (InitrdPath); } else { // Case we create the initrd device path Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes); if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd Status = EFI_ABORTED; goto EXIT; } if (InitrdPathNodes != NULL) { // Duplicate Linux kernel Device Path TempInitrdPath = DuplicateDevicePath (BootOption->FilePathList); // Replace Linux kernel Node by EndNode SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath)); // Append the Device Path to the selected device path InitrdPath = AppendDevicePath (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes); FreePool (TempInitrdPath); // Free the InitrdPathNodes created by Support->CreateDevicePathNode() FreePool (InitrdPathNodes); if (InitrdPath == NULL) { Status = EFI_OUT_OF_RESOURCES; goto EXIT; } InitrdSize = GetDevicePathSize (InitrdPath); } else { InitrdPath = NULL; } } } else { InitrdSize = 0; } Print(L"Arguments to pass to the binary: "); if (CmdLineSize > 0) { AsciiStrnCpy (CmdLine, (CONST CHAR8*)(LinuxArguments + 1), sizeof (CmdLine)); CmdLine[sizeof (CmdLine) - 1] = '\0'; } else { CmdLine[0] = '\0'; } Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX); if (EFI_ERROR(Status)) { Status = EFI_ABORTED; goto FREE_DEVICE_PATH; } CmdLineSize = AsciiStrSize (CmdLine); OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize; BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize); BootArguments->LinuxArguments.CmdLineSize = CmdLineSize; BootArguments->LinuxArguments.InitrdSize = InitrdSize; CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize); CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize); OptionalData = (UINT8*)BootArguments; } else { Print (L"Arguments to pass to the EFI Application: "); if (BootOption->OptionalDataSize > 0) { IsPrintable = IsPrintableString (BootOption->OptionalData, &IsUnicode); if (IsPrintable) { // // The size in bytes of the string, final zero included, should // be equal to or at least lower than "BootOption->OptionalDataSize" // and the "IsPrintableString()" has already tested that the length // in number of characters is smaller than BOOT_DEVICE_OPTION_MAX, // final '\0' included. We can thus copy the string for editing // using "CopyMem()". Furthermore, note that in the case of an Unicode // string "StrnCpy()" and "StrCpy()" can not be used to copy the // string because the data pointed to by "BootOption->OptionalData" // is not necessarily 2-byte aligned. // if (IsUnicode) { CopyMem ( UnicodeCmdLine, BootOption->OptionalData, MIN (sizeof (UnicodeCmdLine), BootOption->OptionalDataSize) ); } else { CopyMem ( CmdLine, BootOption->OptionalData, MIN (sizeof (CmdLine), BootOption->OptionalDataSize) ); } } } else { UnicodeCmdLine[0] = L'\0'; IsPrintable = TRUE; IsUnicode = TRUE; } // We do not request arguments for OptionalData that cannot be printed if (IsPrintable) { if (IsUnicode) { Status = EditHIInputStr (UnicodeCmdLine, BOOT_DEVICE_OPTION_MAX); if (EFI_ERROR (Status)) { Status = EFI_ABORTED; goto FREE_DEVICE_PATH; } OptionalData = (UINT8*)UnicodeCmdLine; OptionalDataSize = StrSize (UnicodeCmdLine); } else { Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX); if (EFI_ERROR (Status)) { Status = EFI_ABORTED; goto FREE_DEVICE_PATH; } OptionalData = (UINT8*)CmdLine; OptionalDataSize = AsciiStrSize (CmdLine); } } else { // We keep the former OptionalData OptionalData = BootOption->OptionalData; OptionalDataSize = BootOption->OptionalDataSize; } } Print(L"Description for this new Entry: "); StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX); Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX); if (EFI_ERROR(Status)) { Status = EFI_ABORTED; goto FREE_DEVICE_PATH; } // Update the entry Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize); FREE_DEVICE_PATH: FreePool (DevicePath); EXIT: if (Status == EFI_ABORTED) { Print(L"\n"); } 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; }
/** Do a connect from an EFI variable via it's key name. @param[in] Key The name of the EFI Variable. @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS ShellConnectFromDevPaths ( IN CONST CHAR16 *Key ) { EFI_DEVICE_PATH_PROTOCOL *DevPath; EFI_DEVICE_PATH_PROTOCOL *CopyOfDevPath; EFI_DEVICE_PATH_PROTOCOL *Instance; EFI_DEVICE_PATH_PROTOCOL *Next; UINTN Length; UINTN Index; UINTN HandleArrayCount; UINTN Size; EFI_HANDLE *HandleArray; EFI_STATUS Status; BOOLEAN AtLeastOneConnected; EFI_PCI_IO_PROTOCOL *PciIo; UINT8 Class[3]; DevPath = NULL; Length = 0; AtLeastOneConnected = FALSE; // // Get the DevicePath buffer from the variable... // Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath); if (Status == EFI_BUFFER_TOO_SMALL) { DevPath = AllocateZeroPool(Length); if (DevPath == NULL) { return EFI_OUT_OF_RESOURCES; } Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath); if (EFI_ERROR (Status)) { if (DevPath != NULL) { FreePool (DevPath); } return Status; } } else if (EFI_ERROR (Status)) { return Status; } Status = EFI_NOT_FOUND; CopyOfDevPath = DevPath; // // walk the list of devices and connect them // do { // // Check every instance of the console variable // Instance = GetNextDevicePathInstance (&CopyOfDevPath, &Size); if (Instance == NULL) { if (DevPath != NULL) { FreePool (DevPath); } return EFI_UNSUPPORTED; } Next = Instance; while (!IsDevicePathEndType (Next)) { Next = NextDevicePathNode (Next); } SetDevicePathEndNode (Next); // // connect short form device path // if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) && ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP) || (DevicePathSubType (Instance) == MSG_USB_WWID_DP) )) { Status = ShellConnectPciRootBridge (); if (EFI_ERROR(Status)) { FreePool(Instance); FreePool(DevPath); return Status; } Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiPciIoProtocolGuid, NULL, &HandleArrayCount, &HandleArray ); if (!EFI_ERROR (Status)) { for (Index = 0; Index < HandleArrayCount; Index++) { Status = gBS->HandleProtocol ( HandleArray[Index], &gEfiPciIoProtocolGuid, (VOID **)&PciIo ); if (!EFI_ERROR (Status)) { Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class); if (!EFI_ERROR (Status)) { if ((PCI_CLASS_SERIAL == Class[2]) && (PCI_CLASS_SERIAL_USB == Class[1])) { Status = gBS->ConnectController ( HandleArray[Index], NULL, Instance, FALSE ); if (!EFI_ERROR(Status)) { AtLeastOneConnected = TRUE; } } } } } } if (HandleArray != NULL) { FreePool (HandleArray); } } else { // // connect the entire device path // Status = ShellConnectDevicePath (Instance); if (!EFI_ERROR (Status)) { AtLeastOneConnected = TRUE; } } FreePool (Instance); } while (CopyOfDevPath != NULL); if (DevPath != NULL) { FreePool(DevPath); } if (AtLeastOneConnected) { return EFI_SUCCESS; } else { return EFI_NOT_FOUND; } }
/** Connect the console device base on the variable ConsoleType. @param ConsoleType ConIn, ConOut or ErrOut. @retval EFI_NOT_FOUND There is not any console devices connected success @retval EFI_SUCCESS Success connect any one instance of the console device path base on the variable ConVarName. **/ EFI_STATUS EFIAPI EfiBootManagerConnectConsoleVariable ( IN CONSOLE_TYPE ConsoleType ) { EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *StartDevicePath; EFI_DEVICE_PATH_PROTOCOL *Instance; EFI_DEVICE_PATH_PROTOCOL *Next; EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath; UINTN Size; BOOLEAN DeviceExist; EFI_HANDLE Handle; if ((ConsoleType != ConIn) && (ConsoleType != ConOut) && (ConsoleType != ErrOut)) { return EFI_INVALID_PARAMETER; } Status = EFI_SUCCESS; DeviceExist = FALSE; Handle = NULL; // // Check if the console variable exist // GetEfiGlobalVariable2 (mConVarName[ConsoleType], (VOID **) &StartDevicePath, NULL); if (StartDevicePath == NULL) { return EFI_UNSUPPORTED; } CopyOfDevicePath = StartDevicePath; do { // // Check every instance of the console variable // Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size); if (Instance == NULL) { FreePool (StartDevicePath); return EFI_UNSUPPORTED; } Next = Instance; while (!IsDevicePathEndType (Next)) { Next = NextDevicePathNode (Next); } SetDevicePathEndNode (Next); // // Connect the USB console // USB console device path is a short-form device path that // starts with the first element being a USB WWID // or a USB Class device path // if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) && ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP) || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)) ) { Status = BmConnectUsbShortFormDevicePath (Instance); if (!EFI_ERROR (Status)) { DeviceExist = TRUE; } } else { for (Next = Instance; !IsDevicePathEnd (Next); Next = NextDevicePathNode (Next)) { if (DevicePathType (Next) == ACPI_DEVICE_PATH && DevicePathSubType (Next) == ACPI_ADR_DP) { break; } else if (DevicePathType (Next) == HARDWARE_DEVICE_PATH && DevicePathSubType (Next) == HW_CONTROLLER_DP && DevicePathType (NextDevicePathNode (Next)) == ACPI_DEVICE_PATH && DevicePathSubType (NextDevicePathNode (Next)) == ACPI_ADR_DP ) { break; } } if (!IsDevicePathEnd (Next)) { // // For GOP device path, start the video driver with NULL remaining device path // SetDevicePathEndNode (Next); Status = EfiBootManagerConnectDevicePath (Instance, &Handle); if (!EFI_ERROR (Status)) { gBS->ConnectController (Handle, NULL, NULL, TRUE); } } else { Status = EfiBootManagerConnectDevicePath (Instance, NULL); } if (EFI_ERROR (Status)) { // // Delete the instance from the console varialbe // EfiBootManagerUpdateConsoleVariable (ConsoleType, NULL, Instance); } else { DeviceExist = TRUE; } } FreePool(Instance); } while (CopyOfDevicePath != NULL); FreePool (StartDevicePath); if (!DeviceExist) { return EFI_NOT_FOUND; } 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; }
/** Binds exclusively to serial io on the controller handle, Produces DebugPort protocol and DevicePath on new handle. @param This Protocol instance pointer. @param ControllerHandle Handle of device to bind driver to. @param RemainingDevicePath Optional parameter use to pick a specific child device to start. @retval EFI_SUCCESS This driver is added to ControllerHandle. @retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device. @retval others Some error occurs. **/ EFI_STATUS EFIAPI DebugPortStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) { EFI_STATUS Status; DEBUGPORT_DEVICE_PATH DebugPortDP; EFI_DEVICE_PATH_PROTOCOL EndDP; EFI_DEVICE_PATH_PROTOCOL *Dp1; Status = gBS->OpenProtocol ( ControllerHandle, &gEfiSerialIoProtocolGuid, (VOID **) &mDebugPortDevice.SerialIoBinding, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE ); if (EFI_ERROR (Status)) { return Status; } mDebugPortDevice.SerialIoDeviceHandle = ControllerHandle; // // Initialize the Serial Io interface... // Status = mDebugPortDevice.SerialIoBinding->SetAttributes ( mDebugPortDevice.SerialIoBinding, mDebugPortDevice.BaudRate, mDebugPortDevice.ReceiveFifoDepth, mDebugPortDevice.Timeout, mDebugPortDevice.Parity, mDebugPortDevice.DataBits, mDebugPortDevice.StopBits ); if (EFI_ERROR (Status)) { mDebugPortDevice.BaudRate = 0; mDebugPortDevice.Parity = DefaultParity; mDebugPortDevice.DataBits = 0; mDebugPortDevice.StopBits = DefaultStopBits; mDebugPortDevice.ReceiveFifoDepth = 0; Status = mDebugPortDevice.SerialIoBinding->SetAttributes ( mDebugPortDevice.SerialIoBinding, mDebugPortDevice.BaudRate, mDebugPortDevice.ReceiveFifoDepth, mDebugPortDevice.Timeout, mDebugPortDevice.Parity, mDebugPortDevice.DataBits, mDebugPortDevice.StopBits ); if (EFI_ERROR (Status)) { gBS->CloseProtocol ( ControllerHandle, &gEfiSerialIoProtocolGuid, This->DriverBindingHandle, ControllerHandle ); return Status; } } mDebugPortDevice.SerialIoBinding->Reset (mDebugPortDevice.SerialIoBinding); // // Create device path instance for DebugPort // DebugPortDP.Header.Type = MESSAGING_DEVICE_PATH; DebugPortDP.Header.SubType = MSG_VENDOR_DP; SetDevicePathNodeLength (&(DebugPortDP.Header), sizeof (DebugPortDP)); CopyGuid (&DebugPortDP.Guid, &gEfiDebugPortDevicePathGuid); Dp1 = DevicePathFromHandle (ControllerHandle); if (Dp1 == NULL) { Dp1 = &EndDP; SetDevicePathEndNode (Dp1); } mDebugPortDevice.DebugPortDevicePath = AppendDevicePathNode (Dp1, (EFI_DEVICE_PATH_PROTOCOL *) &DebugPortDP); if (mDebugPortDevice.DebugPortDevicePath == NULL) { return EFI_OUT_OF_RESOURCES; } // // Publish DebugPort and Device Path protocols // Status = gBS->InstallMultipleProtocolInterfaces ( &mDebugPortDevice.DebugPortDeviceHandle, &gEfiDevicePathProtocolGuid, mDebugPortDevice.DebugPortDevicePath, &gEfiDebugPortProtocolGuid, &mDebugPortDevice.DebugPortInterface, NULL ); if (EFI_ERROR (Status)) { gBS->CloseProtocol ( ControllerHandle, &gEfiSerialIoProtocolGuid, This->DriverBindingHandle, ControllerHandle ); return Status; } // // Connect debugport child to serial io // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiSerialIoProtocolGuid, (VOID **) &mDebugPortDevice.SerialIoBinding, This->DriverBindingHandle, mDebugPortDevice.DebugPortDeviceHandle, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); if (EFI_ERROR (Status)) { gBS->CloseProtocol ( ControllerHandle, &gEfiSerialIoProtocolGuid, This->DriverBindingHandle, ControllerHandle ); return Status; } return EFI_SUCCESS; }
// // TDS 3.4.3 // EFI_STATUS DevicePathUtilitiesAppendDevicePathConformanceTest ( 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; UINTN DevicePathLen1; UINTN DevicePathLen2; UINTN DevicePathLen3; // // 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.3.2.1 // pDevicePath1 = (EFI_DEVICE_PATH *) AllocatePool (END_DEVICE_PATH_LENGTH); SetDevicePathEndNode (pDevicePath1); pDevicePath3 = DevicePathUtilities->CreateDeviceNode (USBNodeType, USBNodeSubType, USBNodeLength); pDevicePath4 = DevicePathUtilities->AppendDeviceNode (pDevicePath1, pDevicePath3); FreePool (pDevicePath1); FreePool (pDevicePath3); DevicePathLen2 = DevicePathUtilities->GetDevicePathSize (pDevicePath4); pDevicePath1 = DevicePathUtilities->AppendDevicePath (NULL, pDevicePath4); FreePool (pDevicePath4); DevicePathLen3 = DevicePathUtilities->GetDevicePathSize (pDevicePath1); FreePool (pDevicePath1); if (DevicePathLen2 == DevicePathLen3) { AssertionType = EFI_TEST_ASSERTION_PASSED; } else { AssertionType = EFI_TEST_ASSERTION_FAILED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gDevicePathUtilitiesBBTestFunctionAssertionGuid059, L"EFI_DEVICE_PATH_UTILITIES_PROTOCOL - AppendDevicePath should ignore Src1 when it is set NULL", L"%a:%d:Status - %r", __FILE__, (UINTN)__LINE__ ); // // TDS 3.4.3.2.2 // pDevicePath1 = (EFI_DEVICE_PATH *) AllocatePool (END_DEVICE_PATH_LENGTH); if (pDevicePath1 == NULL) { return EFI_OUT_OF_RESOURCES; } SetDevicePathEndNode (pDevicePath1); DevicePathLen1 = DevicePathUtilities->GetDevicePathSize (pDevicePath1); pDevicePath2 = DevicePathUtilities->CreateDeviceNode (PCIRootNodeType, PCIRootNodeSubType, PCIRootNodeLength); pDevicePath3 = DevicePathUtilities->AppendDeviceNode (pDevicePath1, pDevicePath2); FreePool (pDevicePath1); FreePool (pDevicePath2); pDevicePath1 = DevicePathUtilities->CreateDeviceNode (PCINodeType, PCINodeSubType, PCINodeLength); pDevicePath2 = DevicePathUtilities->AppendDeviceNode (pDevicePath3, pDevicePath1); FreePool (pDevicePath3); FreePool (pDevicePath1); DevicePathLen1 = DevicePathUtilities->GetDevicePathSize (pDevicePath2); pDevicePath1 = DevicePathUtilities->AppendDevicePath (pDevicePath2, NULL); FreePool (pDevicePath2); DevicePathLen3 = DevicePathUtilities->GetDevicePathSize (pDevicePath1); FreePool (pDevicePath1); if (DevicePathLen1 == DevicePathLen3) { AssertionType = EFI_TEST_ASSERTION_PASSED; } else { AssertionType = EFI_TEST_ASSERTION_FAILED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gDevicePathUtilitiesBBTestFunctionAssertionGuid060, L"EFI_DEVICE_PATH_UTILITIES_PROTOCOL - AppendDevicePath should ignore Src2 when it is set NULL", L"%a:%d:Status - %r", __FILE__, (UINTN)__LINE__ ); pDevicePath1 = DevicePathUtilities->AppendDevicePath (NULL, NULL); if ((pDevicePath1 != NULL) && (IsDevicePathEnd(pDevicePath1))) { AssertionType = EFI_TEST_ASSERTION_PASSED; } else { AssertionType = EFI_TEST_ASSERTION_FAILED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gDevicePathUtilitiesBBTestFunctionAssertionGuid068, L"EFI_DEVICE_PATH_UTILITIES_PROTOCOL - AppendDevicePath should return end-of-device-path if both Src1 and Src2 are NULL", L"%a:%d", __FILE__, (UINTN)__LINE__ ); return EFI_SUCCESS; }
EFI_STATUS EFIAPI BdsLibConnectDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect ) { EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath; EFI_DEVICE_PATH_PROTOCOL *Instance; EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath; EFI_DEVICE_PATH_PROTOCOL *Next; EFI_HANDLE Handle; EFI_HANDLE PreviousHandle; UINTN Size; if (DevPathToTxt == NULL) { Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevPathToTxt); ASSERT((!EFI_ERROR(Status))); } if (DevicePathToConnect == NULL) { return EFI_SUCCESS; } DEBUG((DEBUG_INFO, "%a:%d dev path '%s' to connect\n", __FILE__, __LINE__, DevPathToTxt->ConvertDevicePathToText(DevicePathToConnect, TRUE, FALSE))); DevicePath = DuplicateDevicePath (DevicePathToConnect); if (DevicePath == NULL) { return EFI_OUT_OF_RESOURCES; } CopyOfDevicePath = DevicePath; do { // // The outer loop handles multi instance device paths. // Only console variables contain multiple instance device paths. // // After this call DevicePath points to the next Instance // Instance = GetNextDevicePathInstance (&DevicePath, &Size); if (Instance == NULL) { FreePool (CopyOfDevicePath); return EFI_OUT_OF_RESOURCES; } Next = Instance; while (!IsDevicePathEndType (Next)) { Next = NextDevicePathNode (Next); } SetDevicePathEndNode (Next); // // Start the real work of connect with RemainingDevicePath // PreviousHandle = NULL; do { // // Find the handle that best matches the Device Path. If it is only a // partial match the remaining part of the device path is returned in // RemainingDevicePath. // RemainingDevicePath = Instance; Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle); if (!EFI_ERROR (Status)) { if (Handle == PreviousHandle) { // // If no forward progress is made try invoking the Dispatcher. // A new FV may have been added to the system an new drivers // may now be found. // Status == EFI_SUCCESS means a driver was dispatched // Status == EFI_NOT_FOUND means no new drivers were dispatched // Status = gDS->Dispatch (); } if (!EFI_ERROR (Status)) { PreviousHandle = Handle; // // Connect all drivers that apply to Handle and RemainingDevicePath, // the Recursive flag is FALSE so only one level will be expanded. // // Do not check the connect status here, if the connect controller fail, // then still give the chance to do dispatch, because partial // RemainingDevicepath may be in the new FV // // 1. If the connect fail, RemainingDevicepath and handle will not // change, so next time will do the dispatch, then dispatch's status // will take effect // 2. If the connect success, the RemainingDevicepath and handle will // change, then avoid the dispatch, we have chance to continue the // next connection // gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE); } } // // Loop until RemainingDevicePath is an empty device path // } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath)); } while (DevicePath != NULL); if (CopyOfDevicePath != NULL) { FreePool (CopyOfDevicePath); } // // All handle with DevicePath exists in the handle database // return Status; }
// // TDS 3.4.4 // EFI_STATUS DevicePathUtilitiesAppendDevicePathInstanceConformanceTest ( 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; // // 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.4.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); pDevicePath3 = DevicePathUtilities->AppendDeviceNode (pDevicePath1, pDevicePath2); FreePool (pDevicePath1); FreePool (pDevicePath2); pDevicePath1 = DevicePathUtilities->CreateDeviceNode (PCINodeType, PCINodeSubType, PCINodeLength); pDevicePath2 = DevicePathUtilities->AppendDeviceNode (pDevicePath3, pDevicePath1); FreePool (pDevicePath3); FreePool (pDevicePath1); pDevicePath1 = DevicePathUtilities->AppendDevicePathInstance (pDevicePath2, NULL); FreePool (pDevicePath2); if (pDevicePath1 == NULL) { AssertionType = EFI_TEST_ASSERTION_PASSED; } else { AssertionType = EFI_TEST_ASSERTION_FAILED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gDevicePathUtilitiesBBTestFunctionAssertionGuid062, L"EFI_DEVICE_PATH_UTILITIES_PROTOCOL - AppendDevicePathInstance should not succeed with DevicePathInstance set to be NULL", L"%a:%d:Status - %r", __FILE__, (UINTN)__LINE__ ); return EFI_SUCCESS; }