Skip to content

Commit

Permalink
1.0.14 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ventoy committed Jun 25, 2020
1 parent 4299005 commit 1cbe4c8
Show file tree
Hide file tree
Showing 58 changed files with 1,077 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ static grub_env_get_pf grub_env_get = NULL;
ventoy_grub_param_file_replace *g_file_replace_list = NULL;
ventoy_efi_file_replace g_efi_file_replace;

STATIC BOOLEAN g_hook_keyboard = FALSE;

CHAR16 gFirstTryBootFile[256] = {0};

/* Boot filename */
Expand Down Expand Up @@ -191,11 +193,12 @@ static void EFIAPI ventoy_dump_chain(ventoy_chain_head *chain)
debug("os_param->vtoy_img_size=<%llu>", chain->os_param.vtoy_img_size);
debug("os_param->vtoy_img_location_addr=<0x%llx>", chain->os_param.vtoy_img_location_addr);
debug("os_param->vtoy_img_location_len=<%u>", chain->os_param.vtoy_img_location_len);
debug("os_param->vtoy_reserved=<%u %u %u %u>",
debug("os_param->vtoy_reserved=<%u %u %u %u %u>",
g_os_param_reserved[0],
g_os_param_reserved[1],
g_os_param_reserved[2],
g_os_param_reserved[3]
g_os_param_reserved[3],
g_os_param_reserved[4]
);

ventoy_debug_pause();
Expand Down Expand Up @@ -585,6 +588,13 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
g_fixup_iso9660_secover_enable = TRUE;
}

if (g_os_param_reserved[2] == 1 && g_os_param_reserved[4] != 1)
{
g_hook_keyboard = TRUE;
}

debug("internal param: secover:%u keyboard:%u", g_fixup_iso9660_secover_enable, g_hook_keyboard);

for (i = 0; i < sizeof(ventoy_os_param); i++)
{
chksum += *((UINT8 *)(&(g_chain->os_param)) + i);
Expand Down Expand Up @@ -707,16 +717,26 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
if (gDebugPrint)
{
gST->ConIn->Reset(gST->ConIn, FALSE);
//ventoy_wrapper_system();
}

if (g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC)
{
ventoy_wrapper_push_openvolume(pFile->OpenVolume);
pFile->OpenVolume = ventoy_wrapper_open_volume;
}


if (g_hook_keyboard)
{
ventoy_hook_keyboard_start();
}
/* can't add debug print here */
//ventoy_wrapper_system();
Status = gBS->StartImage(Image, NULL, NULL);
if (g_hook_keyboard)
{
ventoy_hook_keyboard_stop();
}

if (EFI_ERROR(Status))
{
debug("Failed to start image %r", Status);
Expand All @@ -743,14 +763,14 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
return EFI_SUCCESS;
}


EFI_STATUS EFIAPI VentoyEfiMain
(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *Protocol;

g_sector_flag_num = 512; /* initial value */

Expand All @@ -760,6 +780,12 @@ EFI_STATUS EFIAPI VentoyEfiMain
return EFI_OUT_OF_RESOURCES;
}

Status = gBS->HandleProtocol(gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **)&Protocol);
if (EFI_SUCCESS == Status)
{
g_con_simple_input_ex = Protocol;
}

gST->ConOut->ClearScreen(gST->ConOut);
ventoy_clear_input();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ typedef struct ventoy_system_wrapper
extern BOOLEAN gDebugPrint;
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...);
EFI_STATUS EFIAPI ventoy_wrapper_system(VOID);
EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File);
EFI_STATUS EFIAPI ventoy_block_io_read
(
IN EFI_BLOCK_IO_PROTOCOL *This,
Expand All @@ -317,6 +316,7 @@ extern BOOLEAN gMemdiskMode;
extern UINTN g_iso_buf_size;
extern ventoy_grub_param_file_replace *g_file_replace_list;
extern BOOLEAN g_fixup_iso9660_secover_enable;
extern EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *g_con_simple_input_ex;

EFI_STATUS EFIAPI ventoy_wrapper_open_volume
(
Expand All @@ -325,6 +325,8 @@ EFI_STATUS EFIAPI ventoy_wrapper_open_volume
);
EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize);
EFI_STATUS EFIAPI ventoy_wrapper_push_openvolume(IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME OpenVolume);
EFI_STATUS ventoy_hook_keyboard_start(VOID);
EFI_STATUS ventoy_hook_keyboard_stop(VOID);

#endif

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include <Protocol/SimpleFileSystem.h>
#include <Ventoy.h>

#define PROCOTOL_SLEEP_SECONDS 0

#define debug_sleep() if (PROCOTOL_SLEEP_SECONDS) sleep(PROCOTOL_SLEEP_SECONDS)

STATIC ventoy_system_wrapper g_system_wrapper;

static struct well_known_guid g_efi_well_known_guids[] =
Expand Down Expand Up @@ -84,183 +88,6 @@ static const char * ventoy_get_guid_name(EFI_GUID *guid)
return gEfiGuidName;
}

EFI_STATUS EFIAPI
ventoy_wrapper_fs_open(EFI_FILE_HANDLE This, EFI_FILE_HANDLE *New, CHAR16 *Name, UINT64 Mode, UINT64 Attributes)
{
(VOID)This;
(VOID)New;
(VOID)Name;
(VOID)Mode;
(VOID)Attributes;
return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
ventoy_wrapper_file_open_ex(EFI_FILE_HANDLE This, EFI_FILE_HANDLE *New, CHAR16 *Name, UINT64 Mode, UINT64 Attributes, EFI_FILE_IO_TOKEN *Token)
{
return ventoy_wrapper_fs_open(This, New, Name, Mode, Attributes);
}

EFI_STATUS EFIAPI
ventoy_wrapper_file_delete(EFI_FILE_HANDLE This)
{
(VOID)This;
return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
ventoy_wrapper_file_set_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN Len, VOID *Data)
{
return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
ventoy_wrapper_file_flush(EFI_FILE_HANDLE This)
{
(VOID)This;
return EFI_SUCCESS;
}

/* Ex version */
EFI_STATUS EFIAPI
ventoy_wrapper_file_flush_ex(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
{
(VOID)This;
(VOID)Token;
return EFI_SUCCESS;
}


EFI_STATUS EFIAPI
ventoy_wrapper_file_write(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
{
(VOID)This;
(VOID)Len;
(VOID)Data;

return EFI_WRITE_PROTECTED;
}

EFI_STATUS EFIAPI
ventoy_wrapper_file_write_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN *Token)
{
return ventoy_wrapper_file_write(This, &(Token->BufferSize), Token->Buffer);
}


static EFI_STATUS EFIAPI
ventoy_wrapper_file_close(EFI_FILE_HANDLE This)
{
(VOID)This;
return EFI_SUCCESS;
}


static EFI_STATUS EFIAPI
ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
{
(VOID)This;

g_efi_file_replace.CurPos = Position;
return EFI_SUCCESS;
}

static EFI_STATUS EFIAPI
ventoy_wrapper_file_get_pos(EFI_FILE_HANDLE This, UINT64 *Position)
{
(VOID)This;

*Position = g_efi_file_replace.CurPos;

return EFI_SUCCESS;
}


static EFI_STATUS EFIAPI
ventoy_wrapper_file_get_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN *Len, VOID *Data)
{
EFI_FILE_INFO *Info = (EFI_FILE_INFO *) Data;

debug("ventoy_wrapper_file_get_info ... %u", *Len);

if (!CompareGuid(Type, &gEfiFileInfoGuid))
{
return EFI_INVALID_PARAMETER;
}

if (*Len == 0)
{
*Len = 384;
return EFI_BUFFER_TOO_SMALL;
}

ZeroMem(Data, sizeof(EFI_FILE_INFO));

Info->Size = sizeof(EFI_FILE_INFO);
Info->FileSize = g_efi_file_replace.FileSizeBytes;
Info->PhysicalSize = g_efi_file_replace.FileSizeBytes;
Info->Attribute = EFI_FILE_READ_ONLY;
//Info->FileName = EFI_FILE_READ_ONLY;

*Len = Info->Size;

return EFI_SUCCESS;
}

static EFI_STATUS EFIAPI
ventoy_wrapper_file_read(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
{
EFI_LBA Lba;
UINTN ReadLen = *Len;

(VOID)This;

debug("ventoy_wrapper_file_read ... %u", *Len);

if (g_efi_file_replace.CurPos + ReadLen > g_efi_file_replace.FileSizeBytes)
{
ReadLen = g_efi_file_replace.FileSizeBytes - g_efi_file_replace.CurPos;
}

Lba = g_efi_file_replace.CurPos / 2048 + g_efi_file_replace.BlockIoSectorStart;

ventoy_block_io_read(NULL, 0, Lba, ReadLen, Data);

*Len = ReadLen;

g_efi_file_replace.CurPos += ReadLen;

return EFI_SUCCESS;
}


EFI_STATUS EFIAPI
ventoy_wrapper_file_read_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN *Token)
{
return ventoy_wrapper_file_read(This, &(Token->BufferSize), Token->Buffer);
}

EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File)
{
File->Revision = EFI_FILE_PROTOCOL_REVISION2;
File->Open = ventoy_wrapper_fs_open;
File->Close = ventoy_wrapper_file_close;
File->Delete = ventoy_wrapper_file_delete;
File->Read = ventoy_wrapper_file_read;
File->Write = ventoy_wrapper_file_write;
File->GetPosition = ventoy_wrapper_file_get_pos;
File->SetPosition = ventoy_wrapper_file_set_pos;
File->GetInfo = ventoy_wrapper_file_get_info;
File->SetInfo = ventoy_wrapper_file_set_info;
File->Flush = ventoy_wrapper_file_flush;
File->OpenEx = ventoy_wrapper_file_open_ex;
File->ReadEx = ventoy_wrapper_file_read_ex;
File->WriteEx = ventoy_wrapper_file_write_ex;
File->FlushEx = ventoy_wrapper_file_flush_ex;

return EFI_SUCCESS;
}

STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
(
IN EFI_HANDLE Handle,
Expand All @@ -270,7 +97,7 @@ STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
{
EFI_STATUS Status = EFI_SUCCESS;

debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol));
debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
Status = g_system_wrapper.OriHandleProtocol(Handle, Protocol, Interface);

if (CompareGuid(Protocol, &gEfiSimpleFileSystemProtocolGuid))
Expand All @@ -280,7 +107,7 @@ STATIC EFI_STATUS EFIAPI ventoy_handle_protocol

pFile->OpenVolume(pFile, &FileProtocol);

debug("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
trace("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
pFile, pFile->OpenVolume, FileProtocol, FileProtocol->Open);

sleep(3);
Expand All @@ -299,7 +126,7 @@ STATIC EFI_STATUS EFIAPI ventoy_open_protocol
IN UINT32 Attributes
)
{
debug("ventoy_open_protocol:%a", ventoy_get_guid_name(Protocol));
debug("ventoy_open_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
return g_system_wrapper.OriOpenProtocol(Handle, Protocol, Interface, AgentHandle, ControllerHandle, Attributes);
}

Expand All @@ -310,15 +137,15 @@ STATIC EFI_STATUS EFIAPI ventoy_locate_protocol
OUT VOID **Interface
)
{
debug("ventoy_locate_protocol:%a", ventoy_get_guid_name(Protocol));
debug("ventoy_locate_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
return g_system_wrapper.OriLocateProtocol(Protocol, Registration, Interface);
}

EFI_STATUS EFIAPI ventoy_wrapper_system(VOID)
{
ventoy_wrapper(gBS, g_system_wrapper, LocateProtocol, ventoy_locate_protocol);
ventoy_wrapper(gBS, g_system_wrapper, HandleProtocol, ventoy_handle_protocol);
ventoy_wrapper(gBS, g_system_wrapper, OpenProtocol, ventoy_open_protocol);
ventoy_wrapper(gBS, g_system_wrapper, OpenProtocol, ventoy_open_protocol);

return EFI_SUCCESS;
}
Expand Down
Loading

0 comments on commit 1cbe4c8

Please sign in to comment.