Fix a bug that Windows ISO in local disk can not install when boot through F2 browser mode in Legacy BIOS mode.

This commit is contained in:
longpanda 2022-04-28 22:07:30 +08:00
parent fd0d335eb6
commit 0984f5ba58
7 changed files with 41 additions and 18 deletions

View File

@ -113,6 +113,7 @@ grub_uint8_t *g_conf_replace_new_buf = NULL;
int g_conf_replace_new_len = 0; int g_conf_replace_new_len = 0;
int g_conf_replace_new_len_align = 0; int g_conf_replace_new_len_align = 0;
int g_ventoy_disk_bios_id = 0;
ventoy_gpt_info *g_ventoy_part_info = NULL; ventoy_gpt_info *g_ventoy_part_info = NULL;
grub_uint64_t g_ventoy_disk_size = 0; grub_uint64_t g_ventoy_disk_size = 0;
grub_uint64_t g_ventoy_disk_part_size[2]; grub_uint64_t g_ventoy_disk_part_size[2];
@ -4526,6 +4527,8 @@ int ventoy_load_part_table(const char *diskname)
g_ventoy_disk_size = disk->total_sectors * (1U << disk->log_sector_size); g_ventoy_disk_size = disk->total_sectors * (1U << disk->log_sector_size);
g_ventoy_disk_bios_id = disk->id;
grub_disk_read(disk, 0, 0, sizeof(ventoy_gpt_info), g_ventoy_part_info); grub_disk_read(disk, 0, 0, sizeof(ventoy_gpt_info), g_ventoy_part_info);
grub_disk_close(disk); grub_disk_close(disk);

View File

@ -1034,6 +1034,7 @@ extern conf_replace *g_conf_replace_node;
extern grub_uint8_t *g_conf_replace_new_buf; extern grub_uint8_t *g_conf_replace_new_buf;
extern int g_conf_replace_new_len; extern int g_conf_replace_new_len;
extern int g_conf_replace_new_len_align; extern int g_conf_replace_new_len_align;
extern int g_ventoy_disk_bios_id;
extern grub_uint64_t g_ventoy_disk_size; extern grub_uint64_t g_ventoy_disk_size;
extern grub_uint64_t g_ventoy_disk_part_size[2]; extern grub_uint64_t g_ventoy_disk_part_size[2];
extern grub_uint32_t g_ventoy_plat_data; extern grub_uint32_t g_ventoy_plat_data;

View File

@ -1651,24 +1651,39 @@ static void ventoy_windows_fill_virt_data( grub_uint64_t isosize, ventoy_chai
return; return;
} }
static int ventoy_windows_drive_map(ventoy_chain_head *chain) static int ventoy_windows_drive_map(ventoy_chain_head *chain, int vlnk)
{ {
int hd1 = 0;
grub_disk_t disk; grub_disk_t disk;
debug("drive map begin <%p> ...\n", chain); debug("drive map begin <%p> <%d> ...\n", chain, vlnk);
if (chain->disk_drive == 0x80) disk = grub_disk_open("hd1");
if (disk)
{ {
disk = grub_disk_open("hd1"); grub_disk_close(disk);
if (disk) hd1 = 1;
debug("BIOS hd1 exist\n");
}
else
{
debug("failed to open disk %s\n", "hd1");
}
if (vlnk)
{
if (g_ventoy_disk_bios_id == 0x80 && hd1)
{ {
grub_disk_close(disk); debug("drive map needed vlnk %p\n", disk);
debug("drive map needed %p\n", disk);
chain->drive_map = 0x81; chain->drive_map = 0x81;
} }
else }
else if (chain->disk_drive == 0x80)
{
if (hd1)
{ {
debug("failed to open disk %s\n", "hd1"); debug("drive map needed normal %p\n", disk);
chain->drive_map = 0x81;
} }
} }
else else
@ -1961,7 +1976,7 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
if (ventoy_is_efi_os() == 0) if (ventoy_is_efi_os() == 0)
{ {
ventoy_windows_drive_map(chain); ventoy_windows_drive_map(chain, file->vlnk);
} }
VENTOY_CMD_RETURN(GRUB_ERR_NONE); VENTOY_CMD_RETURN(GRUB_ERR_NONE);
@ -2203,7 +2218,7 @@ static grub_err_t ventoy_vlnk_wim_chain_data(grub_file_t wimfile)
if (ventoy_is_efi_os() == 0) if (ventoy_is_efi_os() == 0)
{ {
ventoy_windows_drive_map(chain); ventoy_windows_drive_map(chain, 0);
} }
grub_file_close(file); grub_file_close(file);
@ -2357,7 +2372,7 @@ static grub_err_t ventoy_normal_wim_chain_data(grub_file_t wimfile)
if (ventoy_is_efi_os() == 0) if (ventoy_is_efi_os() == 0)
{ {
ventoy_windows_drive_map(chain); ventoy_windows_drive_map(chain, 0);
} }
grub_file_close(file); grub_file_close(file);

Binary file not shown.

View File

@ -616,10 +616,9 @@ static void ventoy_dump_chain(ventoy_chain_head *chain)
printf("os_param->vtoy_disk_part_type=%u\n", chain->os_param.vtoy_disk_part_type); printf("os_param->vtoy_disk_part_type=%u\n", chain->os_param.vtoy_disk_part_type);
printf("os_param->vtoy_img_path=<%s>\n", chain->os_param.vtoy_img_path); printf("os_param->vtoy_img_path=<%s>\n", chain->os_param.vtoy_img_path);
printf("os_param->vtoy_img_size=<%llu>\n", chain->os_param.vtoy_img_size); printf("os_param->vtoy_img_size=<%llu>\n", chain->os_param.vtoy_img_size);
printf("os_param->vtoy_reserve[0]=<%u>\n", vtoy_reserve[0]); printf("os_param->vtoy_reserve[ ]=<%u %u %u %u %u %u %u>\n",
printf("os_param->vtoy_reserve[1]=<%u>\n", vtoy_reserve[1]); vtoy_reserve[0], vtoy_reserve[1], vtoy_reserve[2], vtoy_reserve[3],
printf("os_param->vtoy_reserve[2]=<%u>\n", vtoy_reserve[2]); vtoy_reserve[4], vtoy_reserve[5], vtoy_reserve[6]);
printf("os_param->vtoy_reserve[3]=<%u>\n", vtoy_reserve[3]);
printf("os_param->vtoy_img_location_addr=<0x%llx>\n", chain->os_param.vtoy_img_location_addr); printf("os_param->vtoy_img_location_addr=<0x%llx>\n", chain->os_param.vtoy_img_location_addr);
printf("os_param->vtoy_img_location_len=<%u>\n", chain->os_param.vtoy_img_location_len); printf("os_param->vtoy_img_location_len=<%u>\n", chain->os_param.vtoy_img_location_len);
ventoy_debug_pause(); ventoy_debug_pause();

View File

@ -1441,7 +1441,12 @@ unsigned int ventoy_int13_hook (ventoy_chain_head *chain)
natural_drive = 0xE0; /* just set a cdrom drive number 224 */ natural_drive = 0xE0; /* just set a cdrom drive number 224 */
} }
if (chain->disk_drive >= 0x80 && chain->drive_map >= 0x80) if (chain->os_param.vtoy_reserved[6])
{
g_drive_map1 = 0x80;
g_drive_map2 = 0x81;
}
else if (chain->disk_drive >= 0x80 && chain->drive_map >= 0x80)
{ {
g_drive_map1 = chain->disk_drive; g_drive_map1 = chain->disk_drive;
g_drive_map2 = chain->drive_map; g_drive_map2 = chain->drive_map;

View File

@ -86,7 +86,7 @@ typedef struct ventoy_os_param
grub_uint64_t vtoy_img_location_addr; grub_uint64_t vtoy_img_location_addr;
grub_uint32_t vtoy_img_location_len; grub_uint32_t vtoy_img_location_len;
grub_uint64_t vtoy_reserved[4]; // Internal use by ventoy grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy
grub_uint8_t vtoy_disk_signature[4]; grub_uint8_t vtoy_disk_signature[4];