]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
1.0.04 release
authorlongpanda <admin@ventoy.net>
Fri, 10 Apr 2020 15:03:03 +0000 (23:03 +0800)
committerlongpanda <admin@ventoy.net>
Fri, 10 Apr 2020 15:03:05 +0000 (23:03 +0800)
19 files changed:
EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.c
EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.h
EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.inf
GRUB2/grub-2.04/grub-core/normal/menu.c
GRUB2/grub-2.04/grub-core/ventoy/ventoy.c
INSTALL/EFI/BOOT/BOOTX64.EFI
INSTALL/Ventoy2Disk.exe
INSTALL/Ventoy2Disk.sh
INSTALL/grub/grub.cfg
INSTALL/grub/i386-pc/core.img
INSTALL/grub/themes/ventoy/theme.txt
INSTALL/grub/x86_64-efi/normal.mod
INSTALL/ventoy/memdisk [new file with mode: 0644]
INSTALL/ventoy/ventoy.cpio
INSTALL/ventoy/ventoy_x64.efi
INSTALL/ventoy/vtoyjump32.exe
INSTALL/ventoy/vtoyjump64.exe
Ventoy2Disk/Ventoy2Disk/Utility.c
vtoyjump/vtoyjump/vtoyjump.c

index d3c8216b67558b872810221d158f8e35a92cbef0..dc73764d9fe8663c6bd6e2ce524b385637ede2ac 100644 (file)
 #include <Guid/FileInfo.h>
 #include <Guid/FileSystemInfo.h>
 #include <Protocol/BlockIo.h>
 #include <Guid/FileInfo.h>
 #include <Guid/FileSystemInfo.h>
 #include <Protocol/BlockIo.h>
+#include <Protocol/RamDisk.h>
 #include <Protocol/SimpleFileSystem.h>
 #include <Ventoy.h>
 
 #include <Protocol/SimpleFileSystem.h>
 #include <Ventoy.h>
 
+UINTN g_iso_buf_size = 0;
+BOOLEAN gMemdiskMode = FALSE;
 BOOLEAN gDebugPrint = FALSE;
 BOOLEAN gLoadIsoEfi = FALSE;
 BOOLEAN gDebugPrint = FALSE;
 BOOLEAN gLoadIsoEfi = FALSE;
+ventoy_ram_disk g_ramdisk_param;
 ventoy_chain_head *g_chain;
 ventoy_img_chunk *g_chunk;
 UINT32 g_img_chunk_num;
 ventoy_chain_head *g_chain;
 ventoy_img_chunk *g_chunk;
 UINT32 g_img_chunk_num;
@@ -353,6 +357,25 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
     return EFI_SUCCESS;    
 }
 
     return EFI_SUCCESS;    
 }
 
+EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read 
+(
+    IN EFI_BLOCK_IO_PROTOCOL          *This,
+    IN UINT32                          MediaId,
+    IN EFI_LBA                         Lba,
+    IN UINTN                           BufferSize,
+    OUT VOID                          *Buffer
+) 
+{
+    //debug("### ventoy_block_io_ramdisk_read sector:%u count:%u", (UINT32)Lba, (UINT32)BufferSize / 2048);
+
+    (VOID)This;
+    (VOID)MediaId;
+
+    CopyMem(Buffer, (char *)g_chain + (Lba * 2048), BufferSize);
+
+       return EFI_SUCCESS;
+}
+
 EFI_STATUS EFIAPI ventoy_block_io_read 
 (
     IN EFI_BLOCK_IO_PROTOCOL          *This,
 EFI_STATUS EFIAPI ventoy_block_io_read 
 (
     IN EFI_BLOCK_IO_PROTOCOL          *This,
@@ -497,6 +520,33 @@ EFI_STATUS EFIAPI ventoy_fill_device_path(VOID)
     return EFI_SUCCESS;
 }
 
     return EFI_SUCCESS;
 }
 
+EFI_STATUS EFIAPI ventoy_save_ramdisk_param(VOID)
+{
+    EFI_STATUS Status = EFI_SUCCESS;
+    EFI_GUID VarGuid = VENTOY_GUID;
+    
+    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);
+
+    return Status;
+}
+
+EFI_STATUS EFIAPI ventoy_del_ramdisk_param(VOID)
+{
+    EFI_STATUS Status = EFI_SUCCESS;
+    EFI_GUID VarGuid = VENTOY_GUID;
+    
+    Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid, 
+                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+                  0, NULL);
+    debug("delete efi variable %r", Status);
+
+    return Status;
+}
+
+
 EFI_STATUS EFIAPI ventoy_set_variable(VOID)
 {
     EFI_STATUS Status = EFI_SUCCESS;
 EFI_STATUS EFIAPI ventoy_set_variable(VOID)
 {
     EFI_STATUS Status = EFI_SUCCESS;
@@ -524,7 +574,7 @@ EFI_STATUS EFIAPI ventoy_delete_variable(VOID)
 }
 
 
 }
 
 
-EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle)
+EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize)
 {   
     EFI_STATUS Status = EFI_SUCCESS;
     EFI_BLOCK_IO_PROTOCOL *pBlockIo = &(gBlockData.BlockIo);
 {   
     EFI_STATUS Status = EFI_SUCCESS;
     EFI_BLOCK_IO_PROTOCOL *pBlockIo = &(gBlockData.BlockIo);
@@ -532,7 +582,7 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle)
     ventoy_fill_device_path();
     
     gBlockData.Media.BlockSize = 2048;
     ventoy_fill_device_path();
     
     gBlockData.Media.BlockSize = 2048;
-    gBlockData.Media.LastBlock = g_chain->virt_img_size_in_bytes / 2048 - 1;
+    gBlockData.Media.LastBlock = ImgSize / 2048 - 1;
     gBlockData.Media.ReadOnly = TRUE;
     gBlockData.Media.MediaPresent = 1;
     gBlockData.Media.LogicalBlocksPerPhysicalBlock = 1;
     gBlockData.Media.ReadOnly = TRUE;
     gBlockData.Media.MediaPresent = 1;
     gBlockData.Media.LogicalBlocksPerPhysicalBlock = 1;
@@ -540,7 +590,16 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle)
        pBlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION3;
        pBlockIo->Media = &(gBlockData.Media);
        pBlockIo->Reset = ventoy_block_io_reset;
        pBlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION3;
        pBlockIo->Media = &(gBlockData.Media);
        pBlockIo->Reset = ventoy_block_io_reset;
-       pBlockIo->ReadBlocks = ventoy_block_io_read;
+
+    if (gMemdiskMode)
+    {
+        pBlockIo->ReadBlocks = ventoy_block_io_ramdisk_read;
+    }
+    else
+    {
+       pBlockIo->ReadBlocks = ventoy_block_io_read;        
+    }
+    
        pBlockIo->WriteBlocks = ventoy_block_io_write;
        pBlockIo->FlushBlocks = ventoy_block_io_flush;
 
        pBlockIo->WriteBlocks = ventoy_block_io_write;
        pBlockIo->FlushBlocks = ventoy_block_io_flush;
 
@@ -827,6 +886,7 @@ static int ventoy_update_image_location(ventoy_os_param *param)
 STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
 {   
     UINT32 i = 0;
 STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
 {   
     UINT32 i = 0;
+    UINTN size = 0;
     UINT8 chksum = 0;
     CHAR16 *pPos = NULL;
     CHAR16 *pCmdLine = NULL;
     UINT8 chksum = 0;
     CHAR16 *pPos = NULL;
     CHAR16 *pCmdLine = NULL;
@@ -866,32 +926,44 @@ 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;
 
     pGrubParam = (ventoy_grub_param *)StrHexToUintn(pPos + StrLen(L"env_param="));
     grub_env_get = pGrubParam->grub_env_get;
 
-
     pPos = StrStr(pCmdLine, L"mem:");
     g_chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4);
 
     pPos = StrStr(pCmdLine, L"mem:");
     g_chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4);
 
-    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);
-    g_override_chunk_num = g_chain->override_chunk_num;
-    g_virt_chunk = (ventoy_virt_chunk *)((char *)g_chain + g_chain->virt_chunk_offset);
-    g_virt_chunk_num = g_chain->virt_chunk_num;
+    pPos = StrStr(pPos, L"size:");
+    size = StrDecimalToUintn(pPos + 5);
 
 
-    for (i = 0; i < sizeof(ventoy_os_param); i++)
-    {
-        chksum += *((UINT8 *)(&(g_chain->os_param)) + i);
-    }
+    debug("memory addr:%p size:%lu", g_chain, size);
 
 
-    if (gDebugPrint)
+    if (StrStr(pCmdLine, L"memdisk"))
     {
     {
-        debug("os param checksum: 0x%x %a", g_chain->os_param.chksum, chksum ? "FAILED" : "SUCCESS");
+        g_iso_buf_size = size;
+        gMemdiskMode = TRUE;
     }
     }
+    else
+    {
+        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);
+        g_override_chunk_num = g_chain->override_chunk_num;
+        g_virt_chunk = (ventoy_virt_chunk *)((char *)g_chain + g_chain->virt_chunk_offset);
+        g_virt_chunk_num = g_chain->virt_chunk_num;
+
+        for (i = 0; i < sizeof(ventoy_os_param); i++)
+        {
+            chksum += *((UINT8 *)(&(g_chain->os_param)) + i);
+        }
 
 
-    ventoy_update_image_location(&(g_chain->os_param));
+        if (gDebugPrint)
+        {
+            debug("os param checksum: 0x%x %a", g_chain->os_param.chksum, chksum ? "FAILED" : "SUCCESS");
+        }
 
 
-    if (gDebugPrint)
-    {
-        ventoy_dump_chain(g_chain);
+        ventoy_update_image_location(&(g_chain->os_param));
+
+        if (gDebugPrint)
+        {
+            ventoy_dump_chain(g_chain);
+        }
     }
 
     FreePool(pCmdLine);
     }
 
     FreePool(pCmdLine);
@@ -974,6 +1046,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
         if (EFI_ERROR(Status))
         {
             debug("Failed to start image %r", Status);
         if (EFI_ERROR(Status))
         {
             debug("Failed to start image %r", Status);
+            sleep(3);
             gBS->UnloadImage(Image);
             break;
         }
             gBS->UnloadImage(Image);
             break;
         }
@@ -1016,8 +1089,49 @@ EFI_STATUS EFIAPI ventoy_clean_env(VOID)
     return EFI_SUCCESS;
 }
 
     return EFI_SUCCESS;
 }
 
-EFI_STATUS EFIAPI VentoyEfiMain
+EFI_STATUS EFIAPI ventoy_ramdisk_boot(IN EFI_HANDLE ImageHandle)
+{
+    EFI_STATUS Status = EFI_SUCCESS;
+    EFI_RAM_DISK_PROTOCOL *RamDisk = NULL;
+    EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
+
+    debug("RamDisk Boot ...");
+
+    Status = gBS->LocateProtocol(&gEfiRamDiskProtocolGuid, NULL, (VOID **)&RamDisk);
+    if (EFI_ERROR(Status))
+    {
+        debug("Failed to locate ramdisk protocol %r", Status);
+        return Status;
+    }
+    debug("Locate RamDisk Protocol %r ...", Status);
+
+    Status = RamDisk->Register((UINTN)g_chain, (UINT64)g_iso_buf_size, &gEfiVirtualCdGuid, NULL, &DevicePath);
+    if (EFI_ERROR(Status))
+    {
+        debug("Failed to register ramdisk %r", Status);
+        return Status;
+    }
+    
+    debug("Register RamDisk %r ...", Status);
+    debug("RamDisk DevicePath:<%s> ...", ConvertDevicePathToText(DevicePath, FALSE, FALSE));
+
+    ventoy_debug_pause();
+
+    gBlockData.Path = DevicePath;
+    gBlockData.DevicePathCompareLen = GetDevicePathSize(DevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
+
+    Status = ventoy_boot(ImageHandle);
+    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(300);
+    }
+    
+    return EFI_SUCCESS;
+}
 
 
+EFI_STATUS EFIAPI VentoyEfiMain
 (
     IN EFI_HANDLE         ImageHandle,
     IN EFI_SYSTEM_TABLE  *SystemTable
 (
     IN EFI_HANDLE         ImageHandle,
     IN EFI_SYSTEM_TABLE  *SystemTable
@@ -1037,36 +1151,56 @@ EFI_STATUS EFIAPI VentoyEfiMain
     ventoy_clear_input();
 
     ventoy_parse_cmdline(ImageHandle);
     ventoy_clear_input();
 
     ventoy_parse_cmdline(ImageHandle);
-    ventoy_set_variable();
-    ventoy_find_iso_disk(ImageHandle);
 
 
-    if (gLoadIsoEfi)
+    if (gMemdiskMode)
     {
     {
-        ventoy_find_iso_disk_fs(ImageHandle);
-        ventoy_load_isoefi_driver(ImageHandle);
+        g_ramdisk_param.PhyAddr = (UINT64)(UINTN)g_chain;
+        g_ramdisk_param.DiskSize = (UINT64)g_iso_buf_size;
+
+        ventoy_save_ramdisk_param();
+        
+        ventoy_install_blockio(ImageHandle, g_iso_buf_size);
+        Status = ventoy_boot(ImageHandle);
+        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(300);
+        }
+
+        ventoy_del_ramdisk_param();
     }
     }
+    else
+    {
+        ventoy_set_variable();
+        ventoy_find_iso_disk(ImageHandle);
 
 
-    ventoy_debug_pause();
-    
-    ventoy_install_blockio(ImageHandle);
+        if (gLoadIsoEfi)
+        {
+            ventoy_find_iso_disk_fs(ImageHandle);
+            ventoy_load_isoefi_driver(ImageHandle);
+        }
 
 
-    ventoy_debug_pause();
+        ventoy_debug_pause();
+        
+        ventoy_install_blockio(ImageHandle, g_chain->virt_img_size_in_bytes);
 
 
-    Status = ventoy_boot(ImageHandle);
-    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(300);
-    }
+        ventoy_debug_pause();
 
 
-    ventoy_clean_env();
+        Status = ventoy_boot(ImageHandle);
+        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(300);
+        }
 
 
+        ventoy_clean_env();
+    }
+    
     ventoy_clear_input();
     gST->ConOut->ClearScreen(gST->ConOut);
 
     ventoy_clear_input();
     gST->ConOut->ClearScreen(gST->ConOut);
 
-    
-
     return EFI_SUCCESS;
 }
 
     return EFI_SUCCESS;
 }
 
index 988421cb23530a862954b6fb6bfb020b44c0ccbf..009863199f2a191b67255dbde4bbd45e4f8458dc 100644 (file)
@@ -223,6 +223,13 @@ typedef struct ventoy_grub_param
 {
     grub_env_get_pf grub_env_get;
 }ventoy_grub_param;
 {
     grub_env_get_pf grub_env_get;
 }ventoy_grub_param;
+
+typedef struct ventoy_ram_disk
+{
+    UINT64 PhyAddr;
+    UINT64 DiskSize;
+}ventoy_ram_disk;
+
 #pragma pack()
 
 
 #pragma pack()
 
 
index 057577eb06f70755f45dbcc7f0ee83888155ef15..98f999ad9e5e658f3594a000eb62eca96a194cb0 100644 (file)
 
 [Guids]
   gShellVariableGuid
 
 [Guids]
   gShellVariableGuid
+  gEfiVirtualCdGuid
   
 [Protocols]
   gEfiLoadedImageProtocolGuid
   gEfiBlockIoProtocolGuid
   gEfiDevicePathProtocolGuid
   gEfiSimpleFileSystemProtocolGuid
   
 [Protocols]
   gEfiLoadedImageProtocolGuid
   gEfiBlockIoProtocolGuid
   gEfiDevicePathProtocolGuid
   gEfiSimpleFileSystemProtocolGuid
+  gEfiRamDiskProtocolGuid
index a52318188c29c87329fb055f06e2ec0a2dc0fecc..4df03bfde8424025e6232aac5346b97f6c9451f3 100644 (file)
@@ -32,6 +32,7 @@
 #include <grub/script_sh.h>
 #include <grub/gfxterm.h>
 #include <grub/dl.h>
 #include <grub/script_sh.h>
 #include <grub/gfxterm.h>
 #include <grub/dl.h>
+#include <grub/env.h>
 
 /* Time to delay after displaying an error message about a default/fallback
    entry failing to boot.  */
 
 /* Time to delay after displaying an error message about a default/fallback
    entry failing to boot.  */
@@ -786,6 +787,36 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
                }
              goto refresh;
 
                }
              goto refresh;
 
+        case GRUB_TERM_KEY_F1:
+            menu_fini ();
+            if (grub_env_get("VTOY_MEM_DISK")) {
+                grub_env_unset("VTOY_MEM_DISK");
+            }else {
+                grub_env_set("VTOY_MEM_DISK", grub_env_get("VTOY_MEM_DISK_STR"));
+            }
+            grub_env_set("VTOY_MENU_REFRESH", "1");
+            goto refresh;
+            
+        case GRUB_TERM_KEY_F3:
+            menu_fini ();
+            if (grub_env_get("VTOY_ISO_RAW")) {
+                grub_env_unset("VTOY_ISO_RAW");
+            }else {
+                grub_env_set("VTOY_ISO_RAW", grub_env_get("VTOY_ISO_RAW_STR"));
+            }
+            grub_env_set("VTOY_MENU_REFRESH", "1");
+            goto refresh;
+            
+        case GRUB_TERM_KEY_F4:
+            menu_fini ();
+            if (grub_env_get("VTOY_ISO_UEFI_DRV")) {
+                grub_env_unset("VTOY_ISO_UEFI_DRV");
+            }else {
+                grub_env_set("VTOY_ISO_UEFI_DRV", grub_env_get("VTOY_ISO_UEFI_DRV_STR"));
+            }
+            grub_env_set("VTOY_MENU_REFRESH", "1");
+            goto refresh;
+
            default:
              {
                int entry;
            default:
              {
                int entry;
index 15b7f54fb9360e497d2ebad44399ff3fa0048750..bf1694dc2d741bc41d32a785321074e293701f5b 100644 (file)
@@ -33,6 +33,9 @@
 #include <grub/datetime.h>
 #include <grub/i18n.h>
 #include <grub/net.h>
 #include <grub/datetime.h>
 #include <grub/i18n.h>
 #include <grub/net.h>
+#ifdef GRUB_MACHINE_EFI
+#include <grub/efi/efi.h>
+#endif
 #include <grub/time.h>
 #include <grub/ventoy.h>
 #include "ventoy_def.h"
 #include <grub/time.h>
 #include <grub/ventoy.h>
 #include "ventoy_def.h"
@@ -261,6 +264,84 @@ static grub_err_t ventoy_cmd_incr(grub_extcmd_context_t ctxt, int argc, char **a
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
+static grub_err_t ventoy_cmd_file_size(grub_extcmd_context_t ctxt, int argc, char **args)
+{
+    int rc = 1;
+    char buf[32];
+    grub_file_t file;
+    
+    (void)ctxt;
+    (void)argc;
+    (void)args;
+
+    if (argc != 2)
+    {
+        return rc;
+    }
+
+    file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
+    if (file == NULL)
+    {
+        debug("failed to open file <%s> for udf check\n", args[0]);
+        return 1;
+    }
+
+    grub_snprintf(buf, sizeof(buf), "%llu", (unsigned long long)file->size);
+
+    grub_env_set(args[1], buf);
+
+    grub_file_close(file); 
+    rc = 0;
+    
+    return rc;
+}
+
+static grub_err_t ventoy_cmd_load_iso_to_mem(grub_extcmd_context_t ctxt, int argc, char **args)
+{
+    int rc = 1;
+    char name[32];
+    char value[32];
+    char *buf = NULL;
+    grub_file_t file;
+    
+    (void)ctxt;
+    (void)argc;
+    (void)args;
+
+    if (argc != 2)
+    {
+        return rc;
+    }
+
+    file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
+    if (file == NULL)
+    {
+        debug("failed to open file <%s> for udf check\n", args[0]);
+        return 1;
+    }
+
+#ifdef GRUB_MACHINE_EFI
+    buf = (char *)grub_efi_allocate_iso_buf(file->size);
+#else
+    buf = (char *)grub_malloc(file->size);
+#endif   
+
+    grub_file_read(file, buf, file->size);
+
+    grub_snprintf(name, sizeof(name), "%s_addr", args[1]);
+    grub_snprintf(value, sizeof(value), "0x%llx", (unsigned long long)(unsigned long)buf);
+    grub_env_set(name, value);
+    
+    grub_snprintf(name, sizeof(name), "%s_size", args[1]);
+    grub_snprintf(value, sizeof(value), "%llu", (unsigned long long)file->size);
+    grub_env_set(name, value);
+
+    grub_file_close(file); 
+    rc = 0;
+    
+    return rc;
+}
+
 static grub_err_t ventoy_cmd_is_udf(grub_extcmd_context_t ctxt, int argc, char **args)
 {
     int i;
 static grub_err_t ventoy_cmd_is_udf(grub_extcmd_context_t ctxt, int argc, char **args)
 {
     int i;
@@ -1107,6 +1188,8 @@ static cmd_para ventoy_cmds[] =
     { "vt_load_cpio", ventoy_cmd_load_cpio, 0, NULL, "", "", NULL },
 
     { "vt_is_udf", ventoy_cmd_is_udf, 0, NULL, "", "", NULL },
     { "vt_load_cpio", ventoy_cmd_load_cpio, 0, NULL, "", "", NULL },
 
     { "vt_is_udf", ventoy_cmd_is_udf, 0, NULL, "", "", NULL },
+    { "vt_file_size", ventoy_cmd_file_size, 0, NULL, "", "", NULL },
+    { "vt_load_iso_to_mem", ventoy_cmd_load_iso_to_mem, 0, NULL, "", "", NULL },
     
     { "vt_linux_parse_initrd_isolinux", ventoy_cmd_isolinux_initrd_collect, 0, NULL, "{cfgfile}", "", NULL },
     { "vt_linux_parse_initrd_grub", ventoy_cmd_grub_initrd_collect, 0, NULL, "{cfgfile}", "", NULL },
     
     { "vt_linux_parse_initrd_isolinux", ventoy_cmd_isolinux_initrd_collect, 0, NULL, "{cfgfile}", "", NULL },
     { "vt_linux_parse_initrd_grub", ventoy_cmd_grub_initrd_collect, 0, NULL, "{cfgfile}", "", NULL },
index 9d5c2c98f1d5ca587c56fb03fb8025c93af2e429..c95e19682988614d1265789e9a216e2dfb8d7962 100644 (file)
Binary files a/INSTALL/EFI/BOOT/BOOTX64.EFI and b/INSTALL/EFI/BOOT/BOOTX64.EFI differ
index 8fdae8e17e0062089d674367919584522194f870..693a9b5f141dcf0edecc00bcbf11e789ca58b76b 100644 (file)
Binary files a/INSTALL/Ventoy2Disk.exe and b/INSTALL/Ventoy2Disk.exe differ
index 38cd002438c56c458eb5fb28eca93f96b8ecb435..9e6deef2e6b48c8c0763bf8e2d666a87ca3cfb6c 100644 (file)
@@ -119,7 +119,7 @@ if [ "$MODE" = "install" ]; then
 
     #Print disk info
     echo "Disk : $DISK"
 
     #Print disk info
     echo "Disk : $DISK"
-    parted $DISK p 2>&1 | grep Model
+    parted -s $DISK p 2>&1 | grep Model
     echo "Size : $disk_size_gb GB"
     echo ''
 
     echo "Size : $disk_size_gb GB"
     echo ''
 
@@ -176,13 +176,17 @@ if [ "$MODE" = "install" ]; then
 
     $cmd -n ventoy -s $cluster_sectors ${DISK}1
 
 
     $cmd -n ventoy -s $cluster_sectors ${DISK}1
 
-    dd status=none if=./boot/boot.img of=$DISK bs=1 count=446 
+    chmod +x ./tool/vtoy_gen_uuid
+
+    dd status=none if=./boot/boot.img of=$DISK bs=1 count=446
     ./tool/xzcat ./boot/core.img.xz | dd status=none of=$DISK bs=512 count=2047 seek=1
     ./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector
     ./tool/xzcat ./boot/core.img.xz | dd status=none of=$DISK bs=512 count=2047 seek=1
     ./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector
-
-
-    chmod +x ./tool/vtoy_gen_uuid
+    
+    #disk uuid
     ./tool/vtoy_gen_uuid | dd status=none of=${DISK} seek=384 bs=1 count=16
     ./tool/vtoy_gen_uuid | dd status=none of=${DISK} seek=384 bs=1 count=16
+    
+    #disk signature
+    ./tool/vtoy_gen_uuid | dd status=none of=${DISK} skip=12 seek=440 bs=1 count=4
 
     sync
 
 
     sync
 
@@ -216,7 +220,7 @@ else
 
     PART2=$(get_disk_part_name $DISK 2)
     
 
     PART2=$(get_disk_part_name $DISK 2)
     
-    dd status=none if=./boot/boot.img of=$DISK bs=1 count=44
+    dd status=none if=./boot/boot.img of=$DISK bs=1 count=440
     
     ./tool/xzcat ./boot/core.img.xz | dd status=none of=$DISK bs=512 count=2047 seek=1  
 
     
     ./tool/xzcat ./boot/core.img.xz | dd status=none of=$DISK bs=512 count=2047 seek=1  
 
index d89f45e0c242a96d18daeb5e0915ca777d0fb8f4..2a71af3664243b0e8baa1a401e2edb0dfe9df7f4 100644 (file)
@@ -146,6 +146,9 @@ function uefi_iso_menu_func {
 
     if [ -n "$vtisouefi" ]; then
         set LoadIsoEfiDriver=on
 
     if [ -n "$vtisouefi" ]; then
         set LoadIsoEfiDriver=on
+        unset vtisouefi
+    elif [ -n "$VTOY_ISO_UEFI_DRV" ]; then
+        set LoadIsoEfiDriver=on
     else
         unset LoadIsoEfiDriver
     fi
     else
         unset LoadIsoEfiDriver
     fi
@@ -161,7 +164,14 @@ function uefi_iso_menu_func {
     loopback loop ${1}${chosen_path}
     get_os_type (loop)
     
     loopback loop ${1}${chosen_path}
     get_os_type (loop)
     
-    vt_check_compatible (loop)
+    if [ -n "$vtcompat" ]; then
+        set ventoy_compatible=YES
+        unset vtcompat
+    elif [ -n "$VTOY_ISO_RAW" ]; then
+        set ventoy_compatible=YES
+    else
+        vt_check_compatible (loop)
+    fi
     
     vt_img_sector ${1}${chosen_path}
     
     
     vt_img_sector ${1}${chosen_path}
     
@@ -178,6 +188,21 @@ function uefi_iso_menu_func {
     terminal_output  gfxterm    
 }
 
     terminal_output  gfxterm    
 }
 
+function uefi_iso_memdisk {    
+    vt_chosen_img_path chosen_path
+
+    echo 'Loading ISO file to memory ...'
+    vt_load_iso_to_mem ${1}${chosen_path} vtoy_iso_buf
+    
+    terminal_output  console
+    chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
+    boot
+}
+
+
+
+
+
 function legacy_windows_menu_func {
     vt_windows_reset
     
 function legacy_windows_menu_func {
     vt_windows_reset
     
@@ -280,7 +305,14 @@ function legacy_iso_menu_func {
     
     get_os_type (loop)
     
     
     get_os_type (loop)
     
-    vt_check_compatible (loop)
+    if [ -n "$vtcompat" ]; then
+        set ventoy_compatible=YES
+        unset vtcompat
+    elif [ -n "$VTOY_ISO_RAW" ]; then
+        set ventoy_compatible=YES
+    else
+        vt_check_compatible (loop)
+    fi
     
     vt_img_sector ${1}${chosen_path}
 
     
     vt_img_sector ${1}${chosen_path}
 
@@ -294,8 +326,14 @@ function legacy_iso_menu_func {
     fi
 }
 
     fi
 }
 
+function legacy_iso_memdisk {
+    vt_chosen_img_path chosen_path
 
 
-
+    linux16   $vtoy_path/memdisk iso raw    
+    echo "Loading ISO file to memory ..."
+    initrd16  ${1}${chosen_path}
+    boot
+}
 
 
 #############################################################
 
 
 #############################################################
@@ -306,11 +344,15 @@ function legacy_iso_menu_func {
 #############################################################
 #############################################################
 
 #############################################################
 #############################################################
 
-set VENTOY_VERSION="1.0.02"
+set VENTOY_VERSION="1.0.04"
 
 #disable timeout
 unset timeout
 
 
 #disable timeout
 unset timeout
 
+set VTOY_MEM_DISK_STR="MEMDISK"
+set VTOY_ISO_RAW_STR="ISO RAW"
+set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
+
 vt_device $root  vtoy_dev
 
 if [ "$vtoy_dev" = "tftp" ]; then
 vt_device $root  vtoy_dev
 
 if [ "$vtoy_dev" = "tftp" ]; then
@@ -357,9 +399,17 @@ if vt_cmp $ventoy_img_count ne 0; then
         vt_img_name $imgid img_name
         menuentry "$img_name" {  
             if [ "$grub_platform" = "pc" ]; then
         vt_img_name $imgid img_name
         menuentry "$img_name" {  
             if [ "$grub_platform" = "pc" ]; then
-                legacy_iso_menu_func $iso_path
+                if [ -n "$VTOY_MEM_DISK" ]; then
+                    legacy_iso_memdisk $iso_path
+                else
+                    legacy_iso_menu_func $iso_path
+                fi
             else
             else
-                uefi_iso_menu_func $iso_path                
+                if [ -n "$VTOY_MEM_DISK" ]; then
+                    uefi_iso_memdisk $iso_path 
+                else
+                    uefi_iso_menu_func $iso_path                
+                fi
             fi            
         }
         
             fi            
         }
         
index c97d4a1488ff6b788df8b8ca565616dc67d22106..f7792e7872fb49f6f2ee05775f696387aef31ea7 100644 (file)
Binary files a/INSTALL/grub/i386-pc/core.img and b/INSTALL/grub/i386-pc/core.img differ
index bf794ec620b4a905c918cebc207ff75b374617ce..dddce556f221f42aea05004f1684ba2848a77574 100644 (file)
@@ -48,3 +48,31 @@ terminal-box: "terminal_box_*.png"
   bar_style = "*"
   highlight_style = "*"
 }
   bar_style = "*"
   highlight_style = "*"
 }
+
+
++ hbox{ 
+    left = 90%
+    top = 5 
+    width = 10%
+    height = 25
+    + label {text = "@VTOY_MEM_DISK@" color = "red" align = "left"} 
+}
+
+
++ hbox{ 
+    left = 90%
+    top = 30 
+    width = 10%
+    height = 25
+    + label {text = "@VTOY_ISO_RAW@" color = "red" align = "left"} 
+}
+
+
++ hbox{ 
+    left = 90%
+    top = 55 
+    width = 10%
+    height = 25
+    + label {text = "@VTOY_ISO_UEFI_DRV@" color = "red" align = "left"} 
+}
+
index 58d29ee9851a6759d6219a5034831ad9ac63d994..2a85a503b114d169ac4facb296c9b13a3ecf0586 100644 (file)
Binary files a/INSTALL/grub/x86_64-efi/normal.mod and b/INSTALL/grub/x86_64-efi/normal.mod differ
diff --git a/INSTALL/ventoy/memdisk b/INSTALL/ventoy/memdisk
new file mode 100644 (file)
index 0000000..3ada56c
Binary files /dev/null and b/INSTALL/ventoy/memdisk differ
index 5dfd6c4988850c233bdb8b79a2594ec3e65888a4..f4330b5be91e3d0f0092833e6c440a8f57569ecb 100644 (file)
Binary files a/INSTALL/ventoy/ventoy.cpio and b/INSTALL/ventoy/ventoy.cpio differ
index 342fca4c79697b3ee77e9ec652cb570d8b333704..c508090c2aeaeb775354fbd69af9011999ee56ed 100644 (file)
Binary files a/INSTALL/ventoy/ventoy_x64.efi and b/INSTALL/ventoy/ventoy_x64.efi differ
index 6213ed59ecb25da526f6c9f78be85a0fce0d1ca1..abe951d1e15dff30eecb36f0c3ed703ab7d8a22a 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump32.exe and b/INSTALL/ventoy/vtoyjump32.exe differ
index c28c7fd28c96a33780c815cb547f826b0ea19802..c3e213024897d344049b7f126dcca176d1e4e8d1 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump64.exe and b/INSTALL/ventoy/vtoyjump64.exe differ
index f3357d8129dac77e9cef7952bd5990dbf88b5dbb..356b4ab73dd8ce8da61a4e92ae1a1423c3b84583 100644 (file)
@@ -426,12 +426,22 @@ static int VentoyFillLocation(UINT64 DiskSizeInBytes, UINT32 StartSectorId, UINT
 
 int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR)
 {
 
 int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR)
 {
+    GUID Guid;
+    UINT32 DiskSignature;
     UINT32 DiskSectorCount;
     UINT32 PartSectorCount;
     UINT32 PartStartSector;
 
     VentoyGetLocalBootImg(pMBR);
 
     UINT32 DiskSectorCount;
     UINT32 PartSectorCount;
     UINT32 PartStartSector;
 
     VentoyGetLocalBootImg(pMBR);
 
+    CoCreateGuid(&Guid);
+
+    memcpy(&DiskSignature, &Guid, sizeof(UINT32));
+
+    Log("Disk signature: 0x%08x", DiskSignature);
+
+    *((UINT32 *)(pMBR->BootCode + 0x1B8)) = DiskSignature;
+
     DiskSectorCount = (UINT32)(DiskSizeBytes / 512);
 
     //Part1
     DiskSectorCount = (UINT32)(DiskSizeBytes / 512);
 
     //Part1
index 1054ef06a1356fe74383023b8b7f86ed83e7c02b..d4aebce5bab109d79a13cbc14d051c7e3a3892cb 100644 (file)
@@ -28,6 +28,7 @@
 #include "vtoyjump.h"
 #include "fat_filelib.h"
 
 #include "vtoyjump.h"
 #include "fat_filelib.h"
 
+static UINT8 g_os_param_reserved[32];
 static BOOL g_64bit_system = FALSE;
 static ventoy_guid g_ventoy_guid = VENTOY_GUID;
 
 static BOOL g_64bit_system = FALSE;
 static ventoy_guid g_ventoy_guid = VENTOY_GUID;
 
@@ -714,23 +715,26 @@ static int VentoyHook(ventoy_os_param *param)
 
        while (Drives)
        {
 
        while (Drives)
        {
-               sprintf_s(IsoPath, sizeof(IsoPath), "%C:\\%s", Letter, param->vtoy_img_path);
-               if (IsPathExist(FALSE, "%s", IsoPath))
-               {
-                       Log("File exist under %C:", Letter);
-                       if (GetPhyDiskUUID(Letter, UUID, &DiskExtent) == 0)
-                       {
-                               if (memcmp(UUID, param->vtoy_disk_guid, 16) == 0)
-                               {
-                                       Log("Disk UUID match");
-                                       break;
-                               }
-                       }
-               }
-               else
-               {
-                       Log("File NOT exist under %C:", Letter);
-               }
+        if (Drives & 0x01)
+        {
+            sprintf_s(IsoPath, sizeof(IsoPath), "%C:\\%s", Letter, param->vtoy_img_path);
+            if (IsPathExist(FALSE, "%s", IsoPath))
+            {
+                Log("File exist under %C:", Letter);
+                if (GetPhyDiskUUID(Letter, UUID, &DiskExtent) == 0)
+                {
+                    if (memcmp(UUID, param->vtoy_disk_guid, 16) == 0)
+                    {
+                        Log("Disk UUID match");
+                        break;
+                    }
+                }
+            }
+            else
+            {
+                Log("File NOT exist under %C:", Letter);
+            }
+        }
 
                Drives >>= 1;
                Letter++;
 
                Drives >>= 1;
                Letter++;
@@ -816,7 +820,9 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
                        Log("Find os pararm at %u", PeStart);
                        memcpy(&os_param, Buffer + PeStart, sizeof(ventoy_os_param));
 
                        Log("Find os pararm at %u", PeStart);
                        memcpy(&os_param, Buffer + PeStart, sizeof(ventoy_os_param));
 
-                       if (os_param.vtoy_reserved[0] == 1)
+            memcpy(g_os_param_reserved, os_param.vtoy_reserved, sizeof(g_os_param_reserved));
+
+            if (g_os_param_reserved[0] == 1)
                        {
                                Log("break here for debug .....");
                                goto End;
                        {
                                Log("break here for debug .....");
                                goto End;
@@ -844,7 +850,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
                goto End;
        }
 
                goto End;
        }
 
-    if (os_param.vtoy_reserved[0] == 2)
+    if (g_os_param_reserved[0] == 2)
     {
         Log("skip hook for debug .....");
         rc = 0;
     {
         Log("skip hook for debug .....");
         rc = 0;
@@ -865,6 +871,8 @@ End:
 
 int main(int argc, char **argv)
 {
 
 int main(int argc, char **argv)
 {
+    int i = 0;
+    int rc = 0;
        CHAR *Pos = NULL;
        CHAR CurDir[MAX_PATH];
        CHAR LunchFile[MAX_PATH];
        CHAR *Pos = NULL;
        CHAR CurDir[MAX_PATH];
        CHAR LunchFile[MAX_PATH];
@@ -904,20 +912,35 @@ int main(int argc, char **argv)
 
     GetStartupInfoA(&Si);
 
 
     GetStartupInfoA(&Si);
 
-       memset(LunchFile, 0, sizeof(LunchFile));
-       if (VentoyJump(argc, argv, LunchFile) == 0)
-       {
-        Log("Ventoy jump success ...");
-        Si.dwFlags |= STARTF_USESHOWWINDOW;
-        Si.wShowWindow = SW_HIDE;
-       }
-    else
+    for (i = 0; i < 10; i++)
     {
     {
-        Log("Ventoy jump fail, now lunch cmd...");
-        sprintf_s(LunchFile, sizeof(LunchFile), "%s", "cmd.exe");
+        Log("VentoyJump loop %d", i + 1); 
+
+        memset(LunchFile, 0, sizeof(LunchFile));
+        rc = VentoyJump(argc, argv, LunchFile);
+
+        if (g_os_param_reserved[0] == 3)
+        {
+            Log("Open log for debug ...");
+            sprintf_s(LunchFile, sizeof(LunchFile), "%s", "notepad.exe ventoy.log");
+            break;
+        }
+        else if (rc == 0)
+        {
+            Log("Ventoy jump success ...");
+            Si.dwFlags |= STARTF_USESHOWWINDOW;
+            Si.wShowWindow = SW_HIDE;
+            break;
+        }
+        else
+        {
+            Log("Ventoy jump fail, now wait ...");
+            sprintf_s(LunchFile, sizeof(LunchFile), "%s", "cmd.exe");
+            Sleep(3000);
+        }
     }
 
     }
 
-       CreateProcessA(NULL, LunchFile, NULL, NULL, FALSE, 0, NULL, NULL, &Si, &Pi);
+       CreateProcessA(NULL, LunchFile, NULL, NULL, FALSE, 0, NULL, NULL, &Si, &Pi);   
        WaitForSingleObject(Pi.hProcess, INFINITE);
 
        return 0;
        WaitForSingleObject(Pi.hProcess, INFINITE);
 
        return 0;