Skip to content

Commit

Permalink
vhd boot
Browse files Browse the repository at this point in the history
live cd
fix bug
  • Loading branch information
ventoy committed Sep 11, 2020
1 parent a29bdfb commit a287bf8
Show file tree
Hide file tree
Showing 21 changed files with 870 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,36 @@ EFI_STATUS EFIAPI ventoy_delete_variable(VOID)
return Status;
}

#if (VENTOY_DEVICE_WARN != 0)
STATIC VOID ventoy_warn_invalid_device(VOID)
{
STATIC BOOLEAN flag = FALSE;

if (flag)
{
return;
}

flag = TRUE;
gST->ConOut->ClearScreen(gST->ConOut);
gST->ConOut->OutputString(gST->ConOut, VTOY_WARNING L"\r\n");
gST->ConOut->OutputString(gST->ConOut, VTOY_WARNING L"\r\n");
gST->ConOut->OutputString(gST->ConOut, VTOY_WARNING L"\r\n\r\n\r\n");

gST->ConOut->OutputString(gST->ConOut, L"This is NOT a standard Ventoy device and is NOT officially supported.\r\n\r\n");
gST->ConOut->OutputString(gST->ConOut, L"You should follow the official instructions in https://www.ventoy.net\r\n");

gST->ConOut->OutputString(gST->ConOut, L"\r\n\r\nWill continue to boot after 15 seconds ...... ");

sleep(15);
}
#else
STATIC VOID ventoy_warn_invalid_device(VOID)
{

}
#endif

STATIC EFI_STATUS EFIAPI ventoy_load_image
(
IN EFI_HANDLE ImageHandle,
Expand Down Expand Up @@ -420,6 +450,7 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk(IN EFI_HANDLE ImageHandle)
UINTN i = 0;
UINTN Count = 0;
UINT64 DiskSize = 0;
MBR_HEAD *pMBR = NULL;
UINT8 *pBuffer = NULL;
EFI_HANDLE *Handles;
EFI_STATUS Status = EFI_SUCCESS;
Expand Down Expand Up @@ -463,6 +494,18 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk(IN EFI_HANDLE ImageHandle)

if (CompareMem(g_chain->os_param.vtoy_disk_guid, pBuffer + 0x180, 16) == 0)
{
pMBR = (MBR_HEAD *)pBuffer;
if (pMBR->PartTbl[0].FsFlag != 0xEE)
{
if (pMBR->PartTbl[0].StartSectorId != 2048 ||
pMBR->PartTbl[1].SectorCount != 65536 ||
pMBR->PartTbl[1].StartSectorId != pMBR->PartTbl[0].StartSectorId + pMBR->PartTbl[0].SectorCount)
{
debug("Failed to check disk part table");
ventoy_warn_invalid_device();
}
}

gBlockData.RawBlockIoHandle = Handles[i];
gBlockData.pRawBlockIo = pBlockIo;
gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
Expand Down Expand Up @@ -582,6 +625,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
UINT32 old_cnt = 0;
UINTN size = 0;
UINT8 chksum = 0;
const char *pEnv = NULL;
CHAR16 *pPos = NULL;
CHAR16 *pCmdLine = NULL;
EFI_STATUS Status = EFI_SUCCESS;
Expand Down Expand Up @@ -649,9 +693,19 @@ 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;
grub_env_get = pGrubParam->grub_env_get;
pEnv = grub_env_get("VTOY_CHKDEV_RESULT_STRING");
if (!pEnv)
{
return EFI_INVALID_PARAMETER;
}

if (pEnv[0] != '0' || pEnv[1] != 0)
{
ventoy_warn_invalid_device();
}

g_file_replace_list = &pGrubParam->file_replace;
old_cnt = g_file_replace_list->old_file_cnt;
debug("file replace: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>",
Expand Down Expand Up @@ -963,7 +1017,11 @@ EFI_STATUS EFIAPI VentoyEfiMain
gST->ConOut->ClearScreen(gST->ConOut);
ventoy_clear_input();

ventoy_parse_cmdline(ImageHandle);
Status = ventoy_parse_cmdline(ImageHandle);
if (EFI_ERROR(Status))
{
return Status;
}

if (gMemdiskMode)
{
Expand Down Expand Up @@ -1000,22 +1058,24 @@ EFI_STATUS EFIAPI VentoyEfiMain
else
{
ventoy_save_variable();
ventoy_find_iso_disk(ImageHandle);

if (gLoadIsoEfi)
Status = ventoy_find_iso_disk(ImageHandle);
if (!EFI_ERROR(Status))
{
ventoy_find_iso_disk_fs(ImageHandle);
ventoy_load_isoefi_driver(ImageHandle);
}

ventoy_debug_pause();

ventoy_install_blockio(ImageHandle, g_chain->virt_img_size_in_bytes);
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);
ventoy_debug_pause();

Status = ventoy_boot(ImageHandle);
}

ventoy_clean_env();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ typedef struct ventoy_virt_chunk
#error Unknown Processor Type
#endif

#define VENTOY_DEVICE_WARN 0
#define VTOY_WARNING L"!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"

typedef struct ventoy_sector_flag
{
UINT8 flag; // 0:init 1:mem 2:remap
Expand Down Expand Up @@ -275,6 +278,32 @@ typedef struct ventoy_iso9660_override
UINT32 size_be;
}ventoy_iso9660_override;

typedef struct PART_TABLE
{
UINT8 Active; // 0x00 0x80

UINT8 StartHead;
UINT16 StartSector : 6;
UINT16 StartCylinder : 10;

UINT8 FsFlag;

UINT8 EndHead;
UINT16 EndSector : 6;
UINT16 EndCylinder : 10;

UINT32 StartSectorId;
UINT32 SectorCount;
}PART_TABLE;

typedef struct MBR_HEAD
{
UINT8 BootCode[446];
PART_TABLE PartTbl[4];
UINT8 Byte55;
UINT8 ByteAA;
}MBR_HEAD;

#pragma pack()


Expand Down
1 change: 1 addition & 0 deletions GRUB2/MOD_SRC/grub-2.04/grub-core/Makefile.core.def
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,7 @@ module = {
common = ventoy/ventoy_linux.c;
common = ventoy/ventoy_unix.c;
common = ventoy/ventoy_windows.c;
common = ventoy/ventoy_vhd.c;
common = ventoy/ventoy_plugin.c;
common = ventoy/ventoy_json.c;
common = ventoy/lzx.c;
Expand Down
Loading

0 comments on commit a287bf8

Please sign in to comment.