mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-06-03 08:28:50 -04:00
update for new release
This commit is contained in:
parent
1bf3e73373
commit
8dce0adda6
110 changed files with 2610 additions and 103 deletions
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -664,6 +672,11 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
|||
|
||||
debug("memory addr:%p size:%lu", chain, size);
|
||||
|
||||
if (StrStr(pCmdLine, L"sector512"))
|
||||
{
|
||||
gSector512Mode = TRUE;
|
||||
}
|
||||
|
||||
if (StrStr(pCmdLine, L"memdisk"))
|
||||
{
|
||||
g_iso_data_buf = (UINT8 *)chain + sizeof(ventoy_chain_head);
|
||||
|
@ -906,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);
|
||||
}
|
||||
|
@ -972,6 +990,12 @@ EFI_STATUS EFIAPI VentoyEfiMain
|
|||
{
|
||||
gBS->UnloadImage(gBlockData.IsoDriverImage);
|
||||
}
|
||||
|
||||
gBS->DisconnectController(gBlockData.Handle, NULL, NULL);
|
||||
gBS->UninstallMultipleProtocolInterfaces(gBlockData.Handle,
|
||||
&gEfiBlockIoProtocolGuid, &gBlockData.BlockIo,
|
||||
&gEfiDevicePathProtocolGuid, gBlockData.Path,
|
||||
NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -995,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -227,6 +227,7 @@ if (gDebugPrint) \
|
|||
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &__Index);\
|
||||
}
|
||||
|
||||
typedef int (*grub_env_set_pf)(const char *name, const char *val);
|
||||
typedef const char * (*grub_env_get_pf)(const char *name);
|
||||
typedef int (*grub_env_printf_pf)(const char *fmt, ...);
|
||||
|
||||
|
@ -255,6 +256,7 @@ typedef struct ventoy_grub_param_file_replace
|
|||
typedef struct ventoy_grub_param
|
||||
{
|
||||
grub_env_get_pf grub_env_get;
|
||||
grub_env_set_pf grub_env_set;
|
||||
ventoy_grub_param_file_replace file_replace;
|
||||
grub_env_printf_pf grub_env_printf;
|
||||
}ventoy_grub_param;
|
||||
|
@ -338,6 +340,7 @@ extern ventoy_efi_file_replace g_efi_file_replace;
|
|||
extern ventoy_sector_flag *g_sector_flag;
|
||||
extern UINT32 g_sector_flag_num;
|
||||
extern BOOLEAN gMemdiskMode;
|
||||
extern BOOLEAN gSector512Mode;
|
||||
extern UINTN g_iso_buf_size;
|
||||
extern UINT8 *g_iso_data_buf;
|
||||
extern ventoy_grub_param_file_replace *g_file_replace_list;
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
UINT8 *g_iso_data_buf = NULL;
|
||||
UINTN g_iso_buf_size = 0;
|
||||
BOOLEAN gMemdiskMode = FALSE;
|
||||
BOOLEAN gSector512Mode = FALSE;
|
||||
|
||||
ventoy_sector_flag *g_sector_flag = NULL;
|
||||
UINT32 g_sector_flag_num = 0;
|
||||
|
@ -68,6 +69,9 @@ STATIC EFI_INPUT_READ_KEY g_org_read_key = NULL;
|
|||
|
||||
STATIC EFI_LOCATE_HANDLE g_org_locate_handle = NULL;
|
||||
|
||||
STATIC UINT8 g_sector_buf[2048];
|
||||
STATIC EFI_BLOCK_READ g_sector_2048_read = NULL;
|
||||
|
||||
BOOLEAN ventoy_is_cdrom_dp_exist(VOID)
|
||||
{
|
||||
UINTN i = 0;
|
||||
|
@ -571,6 +575,64 @@ end:
|
|||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI ventoy_block_io_read_512
|
||||
(
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
EFI_LBA Mod;
|
||||
UINTN ReadSize;
|
||||
UINT8 *CurBuf = NULL;
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
|
||||
debug("ventoy_block_io_read_512 %lu %lu\n", Lba, BufferSize / 512);
|
||||
|
||||
CurBuf = (UINT8 *)Buffer;
|
||||
|
||||
Mod = Lba % 4;
|
||||
if (Mod > 0)
|
||||
{
|
||||
Status |= g_sector_2048_read(This, MediaId, Lba / 4, 2048, g_sector_buf);
|
||||
|
||||
if (BufferSize <= (4 - Mod) * 512)
|
||||
{
|
||||
CopyMem(CurBuf, g_sector_buf + Mod * 512, BufferSize);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadSize = (4 - Mod) * 512;
|
||||
CopyMem(CurBuf, g_sector_buf + Mod * 512, ReadSize);
|
||||
CurBuf += ReadSize;
|
||||
Lba += (4 - Mod);
|
||||
BufferSize -= ReadSize;
|
||||
}
|
||||
}
|
||||
|
||||
if (BufferSize >= 2048)
|
||||
{
|
||||
ReadSize = BufferSize / 2048 * 2048;
|
||||
|
||||
Status |= g_sector_2048_read(This, MediaId, Lba / 4, ReadSize, CurBuf);
|
||||
CurBuf += ReadSize;
|
||||
|
||||
Lba += ReadSize / 512;
|
||||
BufferSize -= ReadSize;
|
||||
}
|
||||
|
||||
if (BufferSize > 0)
|
||||
{
|
||||
Status |= g_sector_2048_read(This, MediaId, Lba / 4, 2048, g_sector_buf);
|
||||
CopyMem(CurBuf, g_sector_buf, BufferSize);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize)
|
||||
{
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
|
@ -580,9 +642,18 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
|
|||
|
||||
debug("install block io protocol %p", ImageHandle);
|
||||
ventoy_debug_pause();
|
||||
|
||||
if (gSector512Mode)
|
||||
{
|
||||
gBlockData.Media.BlockSize = 512;
|
||||
gBlockData.Media.LastBlock = ImgSize / 512 - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
gBlockData.Media.BlockSize = 2048;
|
||||
gBlockData.Media.LastBlock = ImgSize / 2048 - 1;
|
||||
}
|
||||
|
||||
gBlockData.Media.BlockSize = 2048;
|
||||
gBlockData.Media.LastBlock = ImgSize / 2048 - 1;
|
||||
gBlockData.Media.ReadOnly = TRUE;
|
||||
gBlockData.Media.MediaPresent = 1;
|
||||
gBlockData.Media.LogicalBlocksPerPhysicalBlock = 1;
|
||||
|
@ -590,7 +661,17 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
|
|||
pBlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION3;
|
||||
pBlockIo->Media = &(gBlockData.Media);
|
||||
pBlockIo->Reset = ventoy_block_io_reset;
|
||||
pBlockIo->ReadBlocks = gMemdiskMode ? ventoy_block_io_ramdisk_read : ventoy_block_io_read;
|
||||
|
||||
if (gSector512Mode)
|
||||
{
|
||||
g_sector_2048_read = gMemdiskMode ? ventoy_block_io_ramdisk_read : ventoy_block_io_read;
|
||||
pBlockIo->ReadBlocks = ventoy_block_io_read_512;
|
||||
}
|
||||
else
|
||||
{
|
||||
pBlockIo->ReadBlocks = gMemdiskMode ? ventoy_block_io_ramdisk_read : ventoy_block_io_read;
|
||||
}
|
||||
|
||||
pBlockIo->WriteBlocks = ventoy_block_io_write;
|
||||
pBlockIo->FlushBlocks = ventoy_block_io_flush;
|
||||
|
||||
|
@ -603,10 +684,10 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
|
|||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
Status = ventoy_connect_driver(gBlockData.Handle, L"Disk I/O Driver");
|
||||
debug("Connect disk IO driver %r", Status);
|
||||
|
||||
|
||||
Status = ventoy_connect_driver(gBlockData.Handle, L"Partition Driver");
|
||||
debug("Connect partition driver %r", Status);
|
||||
if (EFI_ERROR(Status))
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#pragma pack(1)
|
||||
|
||||
typedef EFI_STATUS (*VTOY_UTIL_PROC_PF)(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine);
|
||||
typedef int (*grub_env_set_pf)(const char *name, const char *val);
|
||||
typedef const char * (*grub_env_get_pf)(const char *name);
|
||||
typedef int (*grub_env_printf_pf)(const char *fmt, ...);
|
||||
|
||||
|
@ -38,6 +39,7 @@ typedef struct ventoy_grub_param_file_replace
|
|||
typedef struct ventoy_grub_param
|
||||
{
|
||||
grub_env_get_pf grub_env_get;
|
||||
grub_env_set_pf grub_env_set;
|
||||
ventoy_grub_param_file_replace file_replace;
|
||||
grub_env_printf_pf grub_env_printf;
|
||||
}ventoy_grub_param;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue