-//
-// pre-boot driver functions
-//
-
-static UINTN ScanDriverDir(IN CHAR16 *Path)
-{
- EFI_STATUS Status;
- REFIT_DIR_ITER DirIter;
- UINTN NumFound = 0;
- EFI_FILE_INFO *DirEntry;
- CHAR16 FileName[256];
-
- CleanUpPathNameSlashes(Path);
- // look through contents of the directory
- DirIterOpen(SelfRootDir, Path, &DirIter);
- while (DirIterNext(&DirIter, 2, LOADER_MATCH_PATTERNS, &DirEntry)) {
- if (DirEntry->FileName[0] == '.')
- continue; // skip this
-
- SPrint(FileName, 255, L"%s\\%s", Path, DirEntry->FileName);
- NumFound++;
- Status = StartEFIImage(FileDevicePath(SelfLoadedImage->DeviceHandle, FileName),
- L"", TYPE_EFI, DirEntry->FileName, 0, NULL, FALSE, TRUE);
- }
- Status = DirIterClose(&DirIter);
- if ((Status != EFI_NOT_FOUND) && (Status != EFI_INVALID_PARAMETER)) {
- SPrint(FileName, 255, L"while scanning the %s directory", Path);
- CheckError(Status, FileName);
- }
- return (NumFound);
-}
-
-#ifdef __MAKEWITH_GNUEFI
-static EFI_STATUS ConnectAllDriversToAllControllers(VOID)
-{
- EFI_STATUS Status;
- UINTN AllHandleCount;
- EFI_HANDLE *AllHandleBuffer;
- UINTN Index;
- UINTN HandleCount;
- EFI_HANDLE *HandleBuffer;
- UINT32 *HandleType;
- UINTN HandleIndex;
- BOOLEAN Parent;
- BOOLEAN Device;
-
- Status = LibLocateHandle(AllHandles,
- NULL,
- NULL,
- &AllHandleCount,
- &AllHandleBuffer);
- if (EFI_ERROR(Status))
- return Status;
-
- for (Index = 0; Index < AllHandleCount; Index++) {
- //
- // Scan the handle database
- //
- Status = LibScanHandleDatabase(NULL,
- NULL,
- AllHandleBuffer[Index],
- NULL,
- &HandleCount,
- &HandleBuffer,
- &HandleType);
- if (EFI_ERROR (Status))
- goto Done;
-
- Device = TRUE;
- if (HandleType[Index] & EFI_HANDLE_TYPE_DRIVER_BINDING_HANDLE)
- Device = FALSE;
- if (HandleType[Index] & EFI_HANDLE_TYPE_IMAGE_HANDLE)
- Device = FALSE;
-
- if (Device) {
- Parent = FALSE;
- for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
- if (HandleType[HandleIndex] & EFI_HANDLE_TYPE_PARENT_HANDLE)
- Parent = TRUE;
- } // for
-
- if (!Parent) {
- if (HandleType[Index] & EFI_HANDLE_TYPE_DEVICE_HANDLE) {
- Status = refit_call4_wrapper(BS->ConnectController,
- AllHandleBuffer[Index],
- NULL,
- NULL,
- TRUE);
- }
- }
- }
-
- MyFreePool (HandleBuffer);
- MyFreePool (HandleType);
- }
-
-Done:
- MyFreePool (AllHandleBuffer);
- return Status;
-} /* EFI_STATUS ConnectAllDriversToAllControllers() */
-#else
-static EFI_STATUS ConnectAllDriversToAllControllers(VOID) {
- BdsLibConnectAllDriversToAllControllers();
- return 0;
-}
-#endif
-
-// Load all EFI drivers from rEFInd's "drivers" subdirectory and from the
-// directories specified by the user in the "scan_driver_dirs" configuration
-// file line.
-static VOID LoadDrivers(VOID)
-{
- CHAR16 *Directory, *SelfDirectory;
- UINTN i = 0, Length, NumFound = 0;
-
- // load drivers from the subdirectories of rEFInd's home directory specified
- // in the DRIVER_DIRS constant.
- while ((Directory = FindCommaDelimited(DRIVER_DIRS, i++)) != NULL) {
- SelfDirectory = SelfDirPath ? StrDuplicate(SelfDirPath) : NULL;
- CleanUpPathNameSlashes(SelfDirectory);
- MergeStrings(&SelfDirectory, Directory, L'\\');
- NumFound += ScanDriverDir(SelfDirectory);
- MyFreePool(Directory);
- MyFreePool(SelfDirectory);
- }
-
- // Scan additional user-specified driver directories....
- i = 0;
- while ((Directory = FindCommaDelimited(GlobalConfig.DriverDirs, i++)) != NULL) {
- CleanUpPathNameSlashes(Directory);
- Length = StrLen(Directory);
- if (Length > 0) {
- NumFound += ScanDriverDir(Directory);
- } // if
- MyFreePool(Directory);
- } // while
-
- // connect all devices
- if (NumFound > 0) {
- ConnectAllDriversToAllControllers();
- }
-} /* static VOID LoadDrivers() */
-