]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.c
Update README.md
[Ventoy.git] / EDK2 / edk2_mod / edk2-edk2-stable201911 / MdeModulePkg / Application / Ventoy / Ventoy.c
index 4a3a98c91f750d15f40d858e0e3b1d4c224c2848..3bbfd9efe1e508586fe2926b8c0f30d99c4ea732 100644 (file)
 #include <Ventoy.h>
 
 BOOLEAN gDebugPrint = FALSE;
+BOOLEAN gBootFallBack = FALSE;
 BOOLEAN gDotEfiBoot = FALSE;
 BOOLEAN gLoadIsoEfi = FALSE;
+BOOLEAN gIsoUdf = FALSE;
 ventoy_ram_disk g_ramdisk_param;
 ventoy_chain_head *g_chain;
+void *g_vtoy_img_location_buf;
 ventoy_img_chunk *g_chunk;
 UINT8 *g_os_param_reserved;
 UINT32 g_img_chunk_num;
@@ -56,6 +59,7 @@ ventoy_grub_param_file_replace *g_file_replace_list = NULL;
 ventoy_efi_file_replace g_efi_file_replace;
 
 CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
+CONST CHAR16 gUdfEfiDriverPath[] = UDF_EFI_DRIVER_PATH;
 
 BOOLEAN g_fix_windows_1st_cdrom_issue = FALSE;
 
@@ -69,10 +73,28 @@ CONST CHAR16 *gEfiBootFileName[] =
 {
     L"@",
     EFI_REMOVABLE_MEDIA_FILE_NAME,
+#if   defined (MDE_CPU_IA32)
+    L"\\EFI\\BOOT\\GRUBIA32.EFI",
+    L"\\EFI\\BOOT\\BOOTia32.EFI",
+    L"\\EFI\\BOOT\\bootia32.efi",
+    L"\\efi\\boot\\bootia32.efi",
+#elif defined (MDE_CPU_X64)
     L"\\EFI\\BOOT\\GRUBX64.EFI",
     L"\\EFI\\BOOT\\BOOTx64.EFI",
     L"\\EFI\\BOOT\\bootx64.efi",
     L"\\efi\\boot\\bootx64.efi",
+#elif defined (MDE_CPU_ARM)
+    L"\\EFI\\BOOT\\GRUBARM.EFI",
+    L"\\EFI\\BOOT\\BOOTarm.EFI",
+    L"\\EFI\\BOOT\\bootarm.efi",
+    L"\\efi\\boot\\bootarm.efi",
+#elif defined (MDE_CPU_AARCH64)
+    L"\\EFI\\BOOT\\GRUBAA64.EFI",
+    L"\\EFI\\BOOT\\BOOTaa64.EFI",
+    L"\\EFI\\BOOT\\bootaa64.efi",
+    L"\\efi\\boot\\bootaa64.efi",
+#endif
+    
 };
 
 VOID EFIAPI VtoyDebug(IN CONST CHAR8  *Format, ...)
@@ -249,6 +271,7 @@ static int ventoy_update_image_location(ventoy_os_param *param)
     }
 
     address = (UINTN)buffer;
+    g_vtoy_img_location_buf = buffer;
 
     if (address % 4096)
     {
@@ -608,12 +631,23 @@ STATIC EFI_STATUS EFIAPI ventoy_load_isoefi_driver(IN EFI_HANDLE ImageHandle)
     EFI_HANDLE Image = NULL;
     EFI_STATUS Status = EFI_SUCCESS;
     CHAR16 LogVar[4] = L"5";
-            
-    Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath, 
-                               gIso9660EfiDriverPath, 
-                               sizeof(gIso9660EfiDriverPath), 
-                               &Image);
-    debug("load iso efi driver status:%r", Status);
+
+    if (gIsoUdf)
+    {
+        Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath, 
+                                   gUdfEfiDriverPath, 
+                                   sizeof(gUdfEfiDriverPath), 
+                                   &Image);
+        debug("load iso UDF efi driver status:%r", Status);
+    }
+    else
+    {
+        Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath, 
+                                   gIso9660EfiDriverPath, 
+                                   sizeof(gIso9660EfiDriverPath), 
+                                   &Image);
+        debug("load iso 9660 efi driver status:%r", Status);        
+    }
 
     if (gDebugPrint)
     {
@@ -663,6 +697,11 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
         gDebugPrint = TRUE;
     }
     
+    if (StrStr(pCmdLine, L"fallback"))
+    {
+        gBootFallBack = TRUE;
+    }
+    
     if (StrStr(pCmdLine, L"dotefi"))
     {
         gDotEfiBoot = TRUE;
@@ -672,6 +711,11 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
     {
         gLoadIsoEfi = TRUE;
     }
+    
+    if (StrStr(pCmdLine, L"iso_udf"))
+    {
+        gIsoUdf = TRUE;
+    }
 
     pPos = StrStr(pCmdLine, L"FirstTry=@");
     if (pPos)
@@ -837,12 +881,15 @@ EFI_STATUS EFIAPI ventoy_clean_env(VOID)
 
     ventoy_delete_variable();
 
-    if (g_chain->os_param.vtoy_img_location_addr)
+    if (g_vtoy_img_location_buf)
     {
-        FreePool((VOID *)(UINTN)g_chain->os_param.vtoy_img_location_addr);
+        FreePool(g_vtoy_img_location_buf);
     }
 
-    FreePool(g_chain);
+    if (!gMemdiskMode)
+    {
+        FreePool(g_chain);        
+    }
 
     return EFI_SUCCESS;
 }
@@ -994,7 +1041,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
             }
         
             debug("Fs not found, now wait and retry...");
-            sleep(2);
+            sleep(1);
         }
     }
 
@@ -1094,7 +1141,7 @@ EFI_STATUS EFIAPI VentoyEfiMain
         ventoy_clean_env();
     }
 
-    if (FALSE == gDotEfiBoot)
+    if (FALSE == gDotEfiBoot && FALSE == gBootFallBack)
     {
         if (EFI_NOT_FOUND == Status)
         {