EFI_STATUS EFIAPI FatDriverBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) /*++ Routine Description: Start this driver on ControllerHandle by opening a Block IO and Disk IO protocol, reading Device Path. Add a Simple File System protocol to ControllerHandle if the media contains a valid file system. Arguments: This - Protocol instance pointer. ControllerHandle - Handle of device to bind driver to. RemainingDevicePath - Not used. Returns: EFI_SUCCESS - This driver is added to DeviceHandle. EFI_ALREADY_STARTED - This driver is already running on DeviceHandle. EFI_OUT_OF_RESOURCES - Can not allocate the memory. other - This driver does not support this device. --*/ { EFI_STATUS Status; EFI_BLOCK_IO_PROTOCOL *BlockIo; EFI_DISK_IO_PROTOCOL *DiskIo; BOOLEAN LockedByMe; LockedByMe = FALSE; // // Acquire the lock. // If caller has already acquired the lock, cannot lock it again. // Status = FatAcquireLockOrFail (); if (!EFI_ERROR (Status)) { LockedByMe = TRUE; } Status = InitializeUnicodeCollationSupport (This->DriverBindingHandle); if (EFI_ERROR (Status)) { goto Exit; } // // Open our required BlockIo and DiskIo // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiBlockIoProtocolGuid, (VOID **) &BlockIo, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { goto Exit; } Status = gBS->OpenProtocol ( ControllerHandle, &gEfiDiskIoProtocolGuid, (VOID **) &DiskIo, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { goto Exit; } // // Allocate Volume structure. In FatAllocateVolume(), Resources // are allocated with protocol installed and cached initialized // Status = FatAllocateVolume (ControllerHandle, DiskIo, BlockIo); // // When the media changes on a device it will Reinstall the BlockIo interaface. // This will cause a call to our Stop(), and a subsequent reentrant call to our // Start() successfully. We should leave the device open when this happen. // if (EFI_ERROR (Status)) { Status = gBS->OpenProtocol ( ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, NULL, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL ); if (EFI_ERROR (Status)) { gBS->CloseProtocol ( ControllerHandle, &gEfiDiskIoProtocolGuid, This->DriverBindingHandle, ControllerHandle ); } } Exit: // // Unlock if locked by myself. // if (LockedByMe) { FatReleaseLock (); } return Status; }
VOID InitializeShellLib ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Initializes EFI library for use Arguments: ImageHandle - Image handle SystemTable - Firmware's EFI system table Returns: None --*/ { EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; EFI_STATUS Status; if (!ShellLibInitialized) { ShellLibInitialized = TRUE; // // Set up global pointer to the system table, boot services table, // and runtime services table // ST = SystemTable; BS = SystemTable->BootServices; RT = SystemTable->RuntimeServices; // // Initialize pool allocation type // if (ImageHandle) { Status = BS->HandleProtocol ( ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID *) &LoadedImage ); if (!EFI_ERROR (Status)) { PoolAllocationType = LoadedImage->ImageDataType; } } // // Initialize Guid table // InitializeLibPlatform (ImageHandle, SystemTable); } if ((ImageHandle != NULL) && (UnicodeInterface == &LibStubUnicodeInterface)) { InitializeUnicodeCollationSupport (ImageHandle); } DEBUG_CODE ( EFIDebugVariable (); EfiDebugAssertInit (); ) }