]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Ebl/Main.c
Added a PCD to turn on/off probing Block IO devices to detect add/remove/change....
[mirror_edk2.git] / EmbeddedPkg / Ebl / Main.c
index 6d536fd79c242dad4b7c4d760c9e4216e8afb9a7..98097e4be1a726438a7d8b944784ef83809c1b38 100644 (file)
@@ -455,6 +455,45 @@ EblPrintStartupBanner (
 }\r
 \r
 \r
+/**\r
+  Send null requests to all removable media block IO devices so the a media add/remove/change\r
+  can be detected in real before we execute a command. \r
+\r
+  This is mainly due to the fact that the FAT driver does not do this today so you can get stale \r
+  dir commands after an SD Card has been removed.\r
+**/\r
+VOID\r
+EblProbeRemovableMedia (\r
+  VOID\r
+  )\r
+{\r
+  UINTN         Index;\r
+  UINTN         Max;\r
+  EFI_OPEN_FILE *File;\r
+\r
+  //\r
+  // Probe for media insertion/removal in removable media devices\r
+  //\r
+  Max = EfiGetDeviceCounts (EfiOpenBlockIo);\r
+  if (Max != 0) {\r
+    for (Index = 0; Index < Max; Index++) {\r
+      File = EfiDeviceOpenByType (EfiOpenBlockIo, Index);\r
+      if (File != NULL) {\r
+        if (File->FsBlockIoMedia->RemovableMedia) {\r
+          // Probe to see if media is present (or not) or media changed\r
+          //  this causes the ReinstallProtocolInterface() to fire in the\r
+          //  block io driver to update the system about media change events\r
+          File->FsBlockIo->ReadBlocks (File->FsBlockIo, File->FsBlockIo->Media->MediaId, (EFI_LBA)0, 0, NULL);\r
+        }\r
+        EfiClose (File);\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+\r
+\r
+\r
 /**\r
   Print the prompt for the EBL.\r
 **/\r
@@ -611,6 +650,11 @@ EdkBootLoaderEntry (
     EblPrompt ();\r
     GetCmd (CmdLine, MAX_CMD_LINE);\r
     SetCmdHistory (CmdLine);\r
+\r
+    if (FeaturePcdGet (PcdEmbeddedProbeRemovable)) {\r
+      // Probe removable media devices to see if media has been inserted or removed.\r
+      EblProbeRemovableMedia ();\r
+    }\r
   }\r
 }\r
 \r