diff --git a/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.c b/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.c index d3c8216b..dc73764d 100644 --- a/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.c +++ b/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.c @@ -32,11 +32,15 @@ #include #include #include +#include #include #include +UINTN g_iso_buf_size = 0; +BOOLEAN gMemdiskMode = 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; @@ -353,6 +357,25 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector 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, @@ -497,6 +520,33 @@ EFI_STATUS EFIAPI ventoy_fill_device_path(VOID) 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; @@ -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); @@ -532,7 +582,7 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle) 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; @@ -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->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; @@ -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; + UINTN size = 0; 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; - 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); @@ -974,6 +1046,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle) if (EFI_ERROR(Status)) { debug("Failed to start image %r", Status); + sleep(3); gBS->UnloadImage(Image); break; } @@ -1016,8 +1089,49 @@ EFI_STATUS EFIAPI ventoy_clean_env(VOID) 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 @@ -1037,36 +1151,56 @@ EFI_STATUS EFIAPI VentoyEfiMain 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); - - return EFI_SUCCESS; } diff --git a/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.h b/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.h index 988421cb..00986319 100644 --- a/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.h +++ b/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.h @@ -223,6 +223,13 @@ typedef struct 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() diff --git a/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.inf b/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.inf index 057577eb..98f999ad 100644 --- a/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.inf +++ b/EDK2/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/Ventoy.inf @@ -41,9 +41,11 @@ [Guids] gShellVariableGuid + gEfiVirtualCdGuid [Protocols] gEfiLoadedImageProtocolGuid gEfiBlockIoProtocolGuid gEfiDevicePathProtocolGuid gEfiSimpleFileSystemProtocolGuid + gEfiRamDiskProtocolGuid diff --git a/GRUB2/grub-2.04/grub-core/normal/menu.c b/GRUB2/grub-2.04/grub-core/normal/menu.c index a5231818..4df03bfd 100644 --- a/GRUB2/grub-2.04/grub-core/normal/menu.c +++ b/GRUB2/grub-2.04/grub-core/normal/menu.c @@ -32,6 +32,7 @@ #include #include #include +#include /* 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; + 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; diff --git a/GRUB2/grub-2.04/grub-core/ventoy/ventoy.c b/GRUB2/grub-2.04/grub-core/ventoy/ventoy.c index 15b7f54f..bf1694dc 100644 --- a/GRUB2/grub-2.04/grub-core/ventoy/ventoy.c +++ b/GRUB2/grub-2.04/grub-core/ventoy/ventoy.c @@ -33,6 +33,9 @@ #include #include #include +#ifdef GRUB_MACHINE_EFI +#include +#endif #include #include #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); } +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; @@ -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_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 }, diff --git a/INSTALL/EFI/BOOT/BOOTX64.EFI b/INSTALL/EFI/BOOT/BOOTX64.EFI index 9d5c2c98..c95e1968 100644 Binary files a/INSTALL/EFI/BOOT/BOOTX64.EFI and b/INSTALL/EFI/BOOT/BOOTX64.EFI differ diff --git a/INSTALL/Ventoy2Disk.exe b/INSTALL/Ventoy2Disk.exe index 8fdae8e1..693a9b5f 100644 Binary files a/INSTALL/Ventoy2Disk.exe and b/INSTALL/Ventoy2Disk.exe differ diff --git a/INSTALL/Ventoy2Disk.sh b/INSTALL/Ventoy2Disk.sh index 38cd0024..9e6deef2 100644 --- a/INSTALL/Ventoy2Disk.sh +++ b/INSTALL/Ventoy2Disk.sh @@ -119,7 +119,7 @@ if [ "$MODE" = "install" ]; then #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 '' @@ -176,13 +176,17 @@ if [ "$MODE" = "install" ]; then $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 - - - chmod +x ./tool/vtoy_gen_uuid + + #disk uuid ./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 @@ -216,7 +220,7 @@ else PART2=$(get_disk_part_name $DISK 2) - dd status=none if=./boot/boot.img of=$DISK bs=1 count=446 + 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 diff --git a/INSTALL/grub/grub.cfg b/INSTALL/grub/grub.cfg index d89f45e0..2a71af36 100644 --- a/INSTALL/grub/grub.cfg +++ b/INSTALL/grub/grub.cfg @@ -146,6 +146,9 @@ function uefi_iso_menu_func { if [ -n "$vtisouefi" ]; then set LoadIsoEfiDriver=on + unset vtisouefi + elif [ -n "$VTOY_ISO_UEFI_DRV" ]; then + set LoadIsoEfiDriver=on else unset LoadIsoEfiDriver fi @@ -161,7 +164,14 @@ function uefi_iso_menu_func { 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} @@ -178,6 +188,21 @@ function uefi_iso_menu_func { 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 @@ -280,7 +305,14 @@ function legacy_iso_menu_func { 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} @@ -294,8 +326,14 @@ function legacy_iso_menu_func { 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 +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 @@ -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 - 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 - 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 } diff --git a/INSTALL/grub/i386-pc/core.img b/INSTALL/grub/i386-pc/core.img index c97d4a14..f7792e78 100644 Binary files a/INSTALL/grub/i386-pc/core.img and b/INSTALL/grub/i386-pc/core.img differ diff --git a/INSTALL/grub/themes/ventoy/theme.txt b/INSTALL/grub/themes/ventoy/theme.txt index bf794ec6..dddce556 100644 --- a/INSTALL/grub/themes/ventoy/theme.txt +++ b/INSTALL/grub/themes/ventoy/theme.txt @@ -48,3 +48,31 @@ terminal-box: "terminal_box_*.png" 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"} +} + diff --git a/INSTALL/grub/x86_64-efi/normal.mod b/INSTALL/grub/x86_64-efi/normal.mod index 58d29ee9..2a85a503 100644 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 index 00000000..3ada56c0 Binary files /dev/null and b/INSTALL/ventoy/memdisk differ diff --git a/INSTALL/ventoy/ventoy.cpio b/INSTALL/ventoy/ventoy.cpio index 5dfd6c49..f4330b5b 100644 Binary files a/INSTALL/ventoy/ventoy.cpio and b/INSTALL/ventoy/ventoy.cpio differ diff --git a/INSTALL/ventoy/ventoy_x64.efi b/INSTALL/ventoy/ventoy_x64.efi index 342fca4c..c508090c 100644 Binary files a/INSTALL/ventoy/ventoy_x64.efi and b/INSTALL/ventoy/ventoy_x64.efi differ diff --git a/INSTALL/ventoy/vtoyjump32.exe b/INSTALL/ventoy/vtoyjump32.exe index 6213ed59..abe951d1 100644 Binary files a/INSTALL/ventoy/vtoyjump32.exe and b/INSTALL/ventoy/vtoyjump32.exe differ diff --git a/INSTALL/ventoy/vtoyjump64.exe b/INSTALL/ventoy/vtoyjump64.exe index c28c7fd2..c3e21302 100644 Binary files a/INSTALL/ventoy/vtoyjump64.exe and b/INSTALL/ventoy/vtoyjump64.exe differ diff --git a/Ventoy2Disk/Ventoy2Disk/Utility.c b/Ventoy2Disk/Ventoy2Disk/Utility.c index f3357d81..356b4ab7 100644 --- a/Ventoy2Disk/Ventoy2Disk/Utility.c +++ b/Ventoy2Disk/Ventoy2Disk/Utility.c @@ -426,12 +426,22 @@ static int VentoyFillLocation(UINT64 DiskSizeInBytes, UINT32 StartSectorId, UINT int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR) { + GUID Guid; + UINT32 DiskSignature; 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 diff --git a/vtoyjump/vtoyjump/vtoyjump.c b/vtoyjump/vtoyjump/vtoyjump.c index 1054ef06..d4aebce5 100644 --- a/vtoyjump/vtoyjump/vtoyjump.c +++ b/vtoyjump/vtoyjump/vtoyjump.c @@ -28,6 +28,7 @@ #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; @@ -714,23 +715,26 @@ static int VentoyHook(ventoy_os_param *param) 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++; @@ -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)); - 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; @@ -844,7 +850,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile) goto End; } - if (os_param.vtoy_reserved[0] == 2) + if (g_os_param_reserved[0] == 2) { Log("skip hook for debug ....."); rc = 0; @@ -865,6 +871,8 @@ End: int main(int argc, char **argv) { + int i = 0; + int rc = 0; CHAR *Pos = NULL; CHAR CurDir[MAX_PATH]; CHAR LunchFile[MAX_PATH]; @@ -904,20 +912,35 @@ int main(int argc, char **argv) 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;