]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.c
LiveCD
[Ventoy.git] / EDK2 / edk2_mod / edk2-edk2-stable201911 / MdeModulePkg / Application / Ventoy / Ventoy.c
index bd28ca268993583f1c448cd0721db237ff254b7b..0d67b31ef1df9e3f9eb2d1a4e89725c911d1071e 100644 (file)
@@ -37,6 +37,7 @@
 #include <Ventoy.h>
 
 BOOLEAN gDebugPrint = FALSE;
+BOOLEAN gDotEfiBoot = FALSE;
 BOOLEAN gLoadIsoEfi = FALSE;
 ventoy_ram_disk g_ramdisk_param;
 ventoy_chain_head *g_chain;
@@ -49,6 +50,7 @@ ventoy_virt_chunk *g_virt_chunk;
 UINT32 g_virt_chunk_num;
 vtoy_block_data gBlockData;
 static grub_env_get_pf grub_env_get = NULL;
+static grub_env_set_pf grub_env_set = NULL;
 
 ventoy_grub_param_file_replace *g_file_replace_list = NULL;
 ventoy_efi_file_replace g_efi_file_replace;
@@ -331,7 +333,7 @@ EFI_STATUS EFIAPI ventoy_save_ramdisk_param(VOID)
     Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid, 
                   EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
                   sizeof(g_ramdisk_param), &(g_ramdisk_param));
-    debug("set efi variable %r", Status);
+    debug("set ramdisk variable %r", Status);
 
     return Status;
 }
@@ -602,6 +604,11 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
     {
         gDebugPrint = TRUE;
     }
+    
+    if (StrStr(pCmdLine, L"dotefi"))
+    {
+        gDotEfiBoot = TRUE;
+    }
 
     if (StrStr(pCmdLine, L"isoefi=on"))
     {
@@ -643,6 +650,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
     
     pGrubParam = (ventoy_grub_param *)StrHexToUintn(pPos + StrLen(L"env_param="));
     grub_env_get = pGrubParam->grub_env_get;
+    grub_env_set = pGrubParam->grub_env_set;
 
     g_file_replace_list = &pGrubParam->file_replace;
     old_cnt = g_file_replace_list->old_file_cnt;
@@ -663,17 +671,27 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
     size = StrDecimalToUintn(pPos + 5);
 
     debug("memory addr:%p size:%lu", chain, size);
-    
-    g_chain = AllocatePool(size);
-    CopyMem(g_chain, chain, size);
+
+    if (StrStr(pCmdLine, L"sector512"))
+    {
+        gSector512Mode = TRUE;
+    }
 
     if (StrStr(pCmdLine, L"memdisk"))
     {
-        g_iso_buf_size = size;
+        g_iso_data_buf = (UINT8 *)chain + sizeof(ventoy_chain_head);
+        g_iso_buf_size = size - sizeof(ventoy_chain_head);
+        debug("memdisk mode iso_buf_size:%u", g_iso_buf_size);
+
+        g_chain = chain;
         gMemdiskMode = TRUE;
     }
     else
     {
+        debug("This is normal mode");
+        g_chain = AllocatePool(size);
+        CopyMem(g_chain, chain, size);
+    
         g_chunk = (ventoy_img_chunk *)((char *)g_chain + g_chain->img_chunk_offset);
         g_img_chunk_num = g_chain->img_chunk_num;
         g_override_chunk = (ventoy_override_chunk *)((char *)g_chain + g_chain->override_chunk_offset);
@@ -725,6 +743,8 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
         }
     }
 
+    ventoy_debug_pause();
+
     FreePool(pCmdLine);
     return EFI_SUCCESS;
 }
@@ -899,6 +919,11 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
 
         if (Find == 0)
         {
+            if (gDotEfiBoot)
+            {
+                break;
+            }
+        
             debug("Fs not found, now wait and retry...");
             sleep(2);
         }
@@ -942,15 +967,35 @@ EFI_STATUS EFIAPI VentoyEfiMain
 
     if (gMemdiskMode)
     {
-        g_ramdisk_param.PhyAddr = (UINT64)(UINTN)g_chain;
+        g_ramdisk_param.PhyAddr = (UINT64)(UINTN)g_iso_data_buf;
         g_ramdisk_param.DiskSize = (UINT64)g_iso_buf_size;
 
         ventoy_save_ramdisk_param();
+
+        if (gLoadIsoEfi)
+        {
+            ventoy_find_iso_disk(ImageHandle);
+            ventoy_find_iso_disk_fs(ImageHandle);
+            ventoy_load_isoefi_driver(ImageHandle);
+        }
         
         ventoy_install_blockio(ImageHandle, g_iso_buf_size);
+        ventoy_debug_pause();
+
         Status = ventoy_boot(ImageHandle);
         
         ventoy_delete_ramdisk_param();
+
+        if (gLoadIsoEfi && gBlockData.IsoDriverImage)
+        {
+            gBS->UnloadImage(gBlockData.IsoDriverImage);
+        }
+
+        gBS->DisconnectController(gBlockData.Handle, NULL, NULL);
+        gBS->UninstallMultipleProtocolInterfaces(gBlockData.Handle,
+                &gEfiBlockIoProtocolGuid, &gBlockData.BlockIo,
+                &gEfiDevicePathProtocolGuid, gBlockData.Path,
+                NULL);
     }
     else
     {
@@ -974,16 +1019,24 @@ EFI_STATUS EFIAPI VentoyEfiMain
         ventoy_clean_env();
     }
 
-    if (EFI_NOT_FOUND == Status)
+    if (FALSE == gDotEfiBoot)
     {
-        gST->ConOut->OutputString(gST->ConOut, L"No bootfile found for UEFI!\r\n");
-        gST->ConOut->OutputString(gST->ConOut, L"Maybe the image does not support " VENTOY_UEFI_DESC  L"!\r\n");
-        sleep(30);
+        if (EFI_NOT_FOUND == Status)
+        {
+            gST->ConOut->OutputString(gST->ConOut, L"No bootfile found for UEFI!\r\n");
+            gST->ConOut->OutputString(gST->ConOut, L"Maybe the image does not support " VENTOY_UEFI_DESC  L"!\r\n");
+            sleep(30);
+        }
     }
-
+    
     ventoy_clear_input();
     gST->ConOut->ClearScreen(gST->ConOut);
 
+    if (gDotEfiBoot && (EFI_NOT_FOUND == Status))
+    {
+        grub_env_set("vtoy_dotefi_retry", "YES");            
+    }
+
     return EFI_SUCCESS;
 }