1. Optimization for WIMBOOT mode.

2. Add WIMBOOT for UEFI mode.
This commit is contained in:
longpanda
2021-05-13 23:05:42 +08:00
parent ca62128f9b
commit 93996cf7e2
120 changed files with 24582 additions and 29 deletions

View File

@@ -964,3 +964,20 @@ void * grub_efi_allocate_iso_buf(grub_uint64_t size)
return (void *)(unsigned long)address;
}
void * grub_efi_allocate_chain_buf(grub_uint64_t size)
{
grub_efi_boot_services_t *b;
grub_efi_status_t status;
grub_efi_physical_address_t address = 0;
grub_efi_uintn_t pages = GRUB_EFI_BYTES_TO_PAGES(size);
b = grub_efi_system_table->boot_services;
status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES, GRUB_EFI_LOADER_DATA, pages, &address);
if (status != GRUB_EFI_SUCCESS)
{
return NULL;
}
return (void *)(unsigned long)address;
}

View File

@@ -127,6 +127,8 @@ static grub_uint64_t g_enumerate_start_time_ms;
static grub_uint64_t g_enumerate_finish_time_ms;
static int g_vtoy_file_flt[VTOY_FILE_FLT_BUTT] = {0};
static const char *g_vtoy_winpeshl_ini = "[LaunchApps]\r\nvtoyjump.exe";
static const char *g_menu_class[] =
{
"vtoyiso", "vtoywim", "vtoyefi", "vtoyimg", "vtoyvhd", "vtoyvtoy"
@@ -1020,7 +1022,7 @@ static grub_err_t ventoy_cmd_concat_efi_iso(grub_extcmd_context_t ctxt, int argc
data = (char *)grub_efi_allocate_iso_buf(totlen);
#else
data = (char *)grub_malloc(totlen);
#endif
#endif
ventoy_fill_os_param(file, (ventoy_os_param *)data);
@@ -1048,36 +1050,52 @@ static grub_err_t ventoy_cmd_load_file_to_mem(grub_extcmd_context_t ctxt, int ar
char value[32];
char *buf = NULL;
grub_file_t file;
enum grub_file_type type;
(void)ctxt;
(void)argc;
(void)args;
if (argc != 2)
if (argc != 3)
{
return rc;
}
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (grub_strcmp(args[0], "nodecompress") == 0)
{
type = VENTOY_FILE_TYPE;
}
else
{
type = GRUB_FILE_TYPE_LINUX_INITRD;
}
file = ventoy_grub_file_open(type, "%s", args[1]);
if (file == NULL)
{
debug("failed to open file <%s>\n", args[0]);
debug("failed to open file <%s>\n", args[1]);
return 1;
}
#ifdef GRUB_MACHINE_EFI
buf = (char *)grub_efi_allocate_iso_buf(file->size);
buf = (char *)grub_efi_allocate_chain_buf(file->size);
#else
buf = (char *)grub_malloc(file->size);
#endif
if (!buf)
{
grub_file_close(file);
return 1;
}
grub_file_read(file, buf, file->size);
grub_snprintf(name, sizeof(name), "%s_addr", args[1]);
grub_snprintf(name, sizeof(name), "%s_addr", args[2]);
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(name, sizeof(name), "%s_size", args[2]);
grub_snprintf(value, sizeof(value), "%llu", (unsigned long long)file->size);
grub_env_set(name, value);
@@ -4349,6 +4367,23 @@ int ventoy_env_init(void)
grub_env_export("ventoy_env_param");
}
grub_snprintf(buf, sizeof(buf), "0x%lx", (ulong)g_vtoy_winpeshl_ini);
grub_env_set("vtoy_winpeshl_ini_addr", buf);
grub_snprintf(buf, sizeof(buf), "%d", (int)grub_strlen(g_vtoy_winpeshl_ini));
grub_env_set("vtoy_winpeshl_ini_size", buf);
grub_env_export("vtoy_winpeshl_ini_addr");
grub_env_export("vtoy_winpeshl_ini_size");
grub_snprintf(buf, sizeof(buf), "0x%lx", (ulong)ventoy_chain_file_size);
grub_env_set("vtoy_chain_file_size", buf);
grub_env_export("vtoy_chain_file_size");
grub_snprintf(buf, sizeof(buf), "0x%lx", (ulong)ventoy_chain_file_read);
grub_env_set("vtoy_chain_file_read", buf);
grub_env_export("vtoy_chain_file_read");
return 0;
}
@@ -4470,6 +4505,8 @@ static cmd_para ventoy_cmds[] =
{ "vt_check_secureboot_var", ventoy_cmd_check_secureboot_var, 0, NULL, "", "", NULL },
{ "vt_clear_key", ventoy_cmd_clear_key, 0, NULL, "", "", NULL },
{ "vt_img_check_range", ventoy_cmd_img_check_range, 0, NULL, "", "", NULL },
{ "vt_is_pe64", ventoy_cmd_is_pe64, 0, NULL, "", "", NULL },
{ "vt_sel_wimboot", ventoy_cmd_sel_wimboot, 0, NULL, "", "", NULL },
};
@@ -4484,6 +4521,7 @@ int ventoy_register_all_cmd(void)
cur->cmd = grub_register_extcmd(cur->name, cur->func, cur->flags,
cur->summary, cur->description, cur->parser);
}
return 0;
}

View File

@@ -554,11 +554,13 @@ int ventoy_is_dir_exist(const char *fmt, ...);
int ventoy_fill_data(grub_uint32_t buflen, char *buffer);
grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_is_pe64(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wim_check_bootable(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_dump_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_sel_wimboot(grub_extcmd_context_t ctxt, int argc, char **args);
VTOY_JSON *vtoy_json_find_item
(
@@ -1011,6 +1013,8 @@ int ventoy_load_part_table(const char *diskname);
int ventoy_env_init(void);
int ventoy_register_all_cmd(void);
int ventoy_unregister_all_cmd(void);
int ventoy_chain_file_size(const char *path);
int ventoy_chain_file_read(const char *path, int offset, int len, void *buf);
#define VTOY_CMD_CHECK(a) if (33554432 != g_ventoy_disk_part_size[a]) ventoy_syscall0(exit)

View File

@@ -314,6 +314,90 @@ static int ventoy_is_pe64(grub_uint8_t *buffer)
return 0;
}
grub_err_t ventoy_cmd_is_pe64(grub_extcmd_context_t ctxt, int argc, char **args)
{
int ret = 1;
grub_file_t file;
grub_uint8_t buf[512];
(void)ctxt;
(void)argc;
file = grub_file_open(args[0], VENTOY_FILE_TYPE);
if (!file)
{
return 1;
}
grub_memset(buf, 0, 512);
grub_file_read(file, buf, 512);
if (ventoy_is_pe64(buf))
{
debug("%s is PE64\n", args[0]);
ret = 0;
}
else
{
debug("%s is PE32\n", args[0]);
}
grub_file_close(file);
return ret;
}
grub_err_t ventoy_cmd_sel_wimboot(grub_extcmd_context_t ctxt, int argc, char **args)
{
int size;
char *buf = NULL;
char configfile[128];
(void)ctxt;
(void)argc;
(void)args;
debug("select wimboot argc:%d\n", argc);
buf = (char *)grub_malloc(8192);
if (!buf)
{
return 0;
}
size = (int)grub_snprintf(buf, 8192,
"menuentry \"Windows Setup (32-bit)\" {\n"
" set vtoy_wimboot_sel=32\n"
"}\n"
"menuentry \"Windows Setup (64-bit)\" {\n"
" set vtoy_wimboot_sel=64\n"
"}\n"
);
buf[size] = 0;
g_ventoy_menu_esc = 1;
g_ventoy_suppress_esc = 1;
grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, size);
grub_script_execute_sourcecode(configfile);
g_ventoy_menu_esc = 0;
g_ventoy_suppress_esc = 0;
grub_free(buf);
if (g_ventoy_last_entry == 0)
{
debug("last entry=%d %s=32\n", g_ventoy_last_entry, args[0]);
grub_env_set(args[0], "32");
}
else
{
debug("last entry=%d %s=64\n", g_ventoy_last_entry, args[0]);
grub_env_set(args[0], "64");
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args)
{
wim_patch *next = NULL;
@@ -1810,3 +1894,29 @@ grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
int ventoy_chain_file_size(const char *path)
{
int size;
grub_file_t file;
file = grub_file_open(path, VENTOY_FILE_TYPE);
size = (int)(file->size);
grub_file_close(file);
return size;
}
int ventoy_chain_file_read(const char *path, int offset, int len, void *buf)
{
int size;
grub_file_t file;
file = grub_file_open(path, VENTOY_FILE_TYPE);
grub_file_seek(file, offset);
size = grub_file_read(file, buf, len);
grub_file_close(file);
return size;
}

View File

@@ -87,6 +87,7 @@ EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
const grub_efi_device_path_t *dp2);
void * EXPORT_FUNC (grub_efi_allocate_iso_buf) (grub_uint64_t size);
void * EXPORT_FUNC (grub_efi_allocate_chain_buf) (grub_uint64_t size);
extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd,