Commit be50ea69 authored by longpanda's avatar longpanda
Browse files

1. Boot menu over serial supported

2. Optimization for booting Solus
3. Optimization for booting .efi file
4. support deepin-live iso
5. support Endless OS
6. framework for booting .img file
parent 433d854a
...@@ -331,7 +331,7 @@ EFI_STATUS EFIAPI ventoy_save_ramdisk_param(VOID) ...@@ -331,7 +331,7 @@ EFI_STATUS EFIAPI ventoy_save_ramdisk_param(VOID)
Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid, Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(g_ramdisk_param), &(g_ramdisk_param)); sizeof(g_ramdisk_param), &(g_ramdisk_param));
debug("set efi variable %r", Status); debug("set ramdisk variable %r", Status);
return Status; return Status;
} }
...@@ -663,17 +663,22 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle) ...@@ -663,17 +663,22 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
size = StrDecimalToUintn(pPos + 5); size = StrDecimalToUintn(pPos + 5);
debug("memory addr:%p size:%lu", chain, size); debug("memory addr:%p size:%lu", chain, size);
g_chain = AllocatePool(size);
CopyMem(g_chain, chain, size);
if (StrStr(pCmdLine, L"memdisk")) if (StrStr(pCmdLine, L"memdisk"))
{ {
g_iso_buf_size = size; g_iso_data_buf = (UINT8 *)chain + sizeof(ventoy_chain_head);
g_iso_buf_size = size - sizeof(ventoy_chain_head);
debug("memdisk mode iso_buf_size:%u", g_iso_buf_size);
g_chain = chain;
gMemdiskMode = TRUE; gMemdiskMode = TRUE;
} }
else else
{ {
debug("This is normal mode");
g_chain = AllocatePool(size);
CopyMem(g_chain, chain, size);
g_chunk = (ventoy_img_chunk *)((char *)g_chain + g_chain->img_chunk_offset); g_chunk = (ventoy_img_chunk *)((char *)g_chain + g_chain->img_chunk_offset);
g_img_chunk_num = g_chain->img_chunk_num; g_img_chunk_num = g_chain->img_chunk_num;
g_override_chunk = (ventoy_override_chunk *)((char *)g_chain + g_chain->override_chunk_offset); g_override_chunk = (ventoy_override_chunk *)((char *)g_chain + g_chain->override_chunk_offset);
...@@ -725,6 +730,8 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle) ...@@ -725,6 +730,8 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
} }
} }
ventoy_debug_pause();
FreePool(pCmdLine); FreePool(pCmdLine);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
...@@ -942,15 +949,29 @@ EFI_STATUS EFIAPI VentoyEfiMain ...@@ -942,15 +949,29 @@ EFI_STATUS EFIAPI VentoyEfiMain
if (gMemdiskMode) if (gMemdiskMode)
{ {
g_ramdisk_param.PhyAddr = (UINT64)(UINTN)g_chain; g_ramdisk_param.PhyAddr = (UINT64)(UINTN)g_iso_data_buf;
g_ramdisk_param.DiskSize = (UINT64)g_iso_buf_size; g_ramdisk_param.DiskSize = (UINT64)g_iso_buf_size;
ventoy_save_ramdisk_param(); ventoy_save_ramdisk_param();
if (gLoadIsoEfi)
{
ventoy_find_iso_disk(ImageHandle);
ventoy_find_iso_disk_fs(ImageHandle);
ventoy_load_isoefi_driver(ImageHandle);
}
ventoy_install_blockio(ImageHandle, g_iso_buf_size); ventoy_install_blockio(ImageHandle, g_iso_buf_size);
ventoy_debug_pause();
Status = ventoy_boot(ImageHandle); Status = ventoy_boot(ImageHandle);
ventoy_delete_ramdisk_param(); ventoy_delete_ramdisk_param();
if (gLoadIsoEfi && gBlockData.IsoDriverImage)
{
gBS->UnloadImage(gBlockData.IsoDriverImage);
}
} }
else else
{ {
......
...@@ -339,6 +339,7 @@ extern ventoy_sector_flag *g_sector_flag; ...@@ -339,6 +339,7 @@ extern ventoy_sector_flag *g_sector_flag;
extern UINT32 g_sector_flag_num; extern UINT32 g_sector_flag_num;
extern BOOLEAN gMemdiskMode; extern BOOLEAN gMemdiskMode;
extern UINTN g_iso_buf_size; extern UINTN g_iso_buf_size;
extern UINT8 *g_iso_data_buf;
extern ventoy_grub_param_file_replace *g_file_replace_list; extern ventoy_grub_param_file_replace *g_file_replace_list;
extern BOOLEAN g_fixup_iso9660_secover_enable; extern BOOLEAN g_fixup_iso9660_secover_enable;
extern EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *g_con_simple_input_ex; extern EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *g_con_simple_input_ex;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <Protocol/SimpleFileSystem.h> #include <Protocol/SimpleFileSystem.h>
#include <Ventoy.h> #include <Ventoy.h>
UINT8 *g_iso_data_buf = NULL;
UINTN g_iso_buf_size = 0; UINTN g_iso_buf_size = 0;
BOOLEAN gMemdiskMode = FALSE; BOOLEAN gMemdiskMode = FALSE;
...@@ -254,7 +255,7 @@ EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read ...@@ -254,7 +255,7 @@ EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read
(VOID)This; (VOID)This;
(VOID)MediaId; (VOID)MediaId;
CopyMem(Buffer, (char *)g_chain + (Lba * 2048), BufferSize); CopyMem(Buffer, g_iso_data_buf + (Lba * 2048), BufferSize);
if (g_blockio_start_record_bcd && FALSE == g_blockio_bcd_read_done) if (g_blockio_start_record_bcd && FALSE == g_blockio_bcd_read_done)
{ {
......
...@@ -809,6 +809,16 @@ module = { ...@@ -809,6 +809,16 @@ module = {
common = commands/blocklist.c; common = commands/blocklist.c;
}; };
module = {
name = blscfg;
common = commands/blscfg.c;
common = commands/loadenv.h;
enable = powerpc_ieee1275;
enable = efi;
enable = i386_pc;
enable = emu;
};
module = { module = {
name = boot; name = boot;
common = commands/boot.c; common = commands/boot.c;
...@@ -986,6 +996,7 @@ module = { ...@@ -986,6 +996,7 @@ module = {
module = { module = {
name = loadenv; name = loadenv;
common = commands/loadenv.c; common = commands/loadenv.c;
common = commands/loadenv.h;
common = lib/envblk.c; common = lib/envblk.c;
}; };
......
This diff is collapsed.
This diff is collapsed.
/* loadenv.c - command to load/save environment variable. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/mm.h>
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/partition.h>
#include <grub/lib/envblk.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include "loadenv.h"
GRUB_MOD_LICENSE ("GPLv3+");
static const struct grub_arg_option options[] =
{
/* TRANSLATORS: This option is used to override default filename
for loading and storing environment. */
{"file", 'f', 0, N_("Specify filename."), 0, ARG_TYPE_PATHNAME},
{"skip-sig", 's', 0,
N_("Skip signature-checking of the environment file."), 0, ARG_TYPE_NONE},
{0, 0, 0, 0, 0, 0}
};
/* Opens 'filename' with compression filters disabled. Optionally disables the
PUBKEY filter (that insists upon properly signed files) as well. PUBKEY
filter is restored before the function returns. */
static grub_file_t
open_envblk_file (char *filename,
enum grub_file_type type)
{
grub_file_t file;
char *buf = 0;
if (! filename)
{
const char *prefix;
int len;
prefix = grub_env_get ("prefix");
if (! prefix)
{
grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "prefix");
return 0;
}
len = grub_strlen (prefix);
buf = grub_malloc (len + 1 + sizeof (GRUB_ENVBLK_DEFCFG));
if (! buf)
return 0;
filename = buf;
grub_strcpy (filename, prefix);
filename[len] = '/';
grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG);
}
file = grub_file_open (filename, type);
grub_free (buf);
return file;
}
static grub_err_t
grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
grub_file_t file;
grub_envblk_t envblk;
grub_env_whitelist_t whitelist;
whitelist.len = argc;
whitelist.list = args;
/* state[0] is the -f flag; state[1] is the --skip-sig flag */
file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
GRUB_FILE_TYPE_LOADENV
| (state[1].set
? GRUB_FILE_TYPE_SKIP_SIGNATURE : GRUB_FILE_TYPE_NONE));
if (! file)
return grub_errno;
envblk = read_envblk_file (file);
if (! envblk)
goto fail;
/* argc > 0 indicates caller provided a whitelist of variables to read. */
grub_envblk_iterate (envblk, argc > 0 ? &whitelist : 0, set_var);
grub_envblk_close (envblk);
fail:
grub_file_close (file);
return grub_errno;
}
/* Print all variables in current context. */
static int
print_var (const char *name, const char *value,
void *hook_data __attribute__ ((unused)))
{
grub_printf ("%s=%s\n", name, value);
return 0;
}
static grub_err_t
grub_cmd_list_env (grub_extcmd_context_t ctxt,
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
struct grub_arg_list *state = ctxt->state;
grub_file_t file;
grub_envblk_t envblk;
file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
GRUB_FILE_TYPE_LOADENV
| (state[1].set
? GRUB_FILE_TYPE_SKIP_SIGNATURE : GRUB_FILE_TYPE_NONE));
if (! file)
return grub_errno;
envblk = read_envblk_file (file);
if (! envblk)
goto fail;
grub_envblk_iterate (envblk, NULL, print_var);
grub_envblk_close (envblk);
fail:
grub_file_close (file);
return grub_errno;
}
/* Used to maintain a variable length of blocklists internally. */
struct blocklist
{
grub_disk_addr_t sector;
unsigned offset;
unsigned length;
struct blocklist *next;
};
static void
free_blocklists (struct blocklist *p)
{
struct blocklist *q;
for (; p; p = q)
{
q = p->next;
grub_free (p);
}
}
static grub_err_t
check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
grub_file_t file)
{
grub_size_t total_length;
grub_size_t index;
grub_disk_t disk;
grub_disk_addr_t part_start;
struct blocklist *p;
char *buf;
/* Sanity checks. */
total_length = 0;
for (p = blocklists; p; p = p->next)
{
struct blocklist *q;
/* Check if any pair of blocks overlap. */
for (q = p->next; q; q = q->next)
{
grub_disk_addr_t s1, s2;
grub_disk_addr_t e1, e2;
s1 = p->sector;
e1 = s1 + ((p->length + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
s2 = q->sector;
e2 = s2 + ((q->length + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
if (s1 < e2 && s2 < e1)
{
/* This might be actually valid, but it is unbelievable that
any filesystem makes such a silly allocation. */
return grub_error (GRUB_ERR_BAD_FS, "malformed file");
}
}
total_length += p->length;
}
if (total_length != grub_file_size (file))
{
/* Maybe sparse, unallocated sectors. No way in GRUB. */
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "sparse file not allowed");
}
/* One more sanity check. Re-read all sectors by blocklists, and compare
those with the data read via a file. */
disk = file->device->disk;
part_start = grub_partition_get_start (disk->partition);
buf = grub_envblk_buffer (envblk);
char *blockbuf = NULL;
grub_size_t blockbuf_len = 0;
for (p = blocklists, index = 0; p; index += p->length, p = p->next)
{
if (p->length > blockbuf_len)
{
grub_free (blockbuf);
blockbuf_len = 2 * p->length;
blockbuf = grub_malloc (blockbuf_len);
if (!blockbuf)
return grub_errno;
}
if (grub_disk_read (disk, p->sector - part_start,
p->offset, p->length, blockbuf))
return grub_errno;
if (grub_memcmp (buf + index, blockbuf, p->length) != 0)
return grub_error (GRUB_ERR_FILE_READ_ERROR, "invalid blocklist");
}
return GRUB_ERR_NONE;
}
static int
write_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
grub_file_t file)
{
char *buf;
grub_disk_t disk;
grub_disk_addr_t part_start;
struct blocklist *p;
grub_size_t index;
buf = grub_envblk_buffer (envblk);
disk = file->device->disk;
part_start = grub_partition_get_start (disk->partition);
index = 0;
for (p = blocklists; p; index += p->length, p = p->next)
{
if (grub_disk_write (disk, p->sector - part_start,
p->offset, p->length, buf + index))
return 0;
}
return 1;
}
/* Context for grub_cmd_save_env. */
struct grub_cmd_save_env_ctx
{
struct blocklist *head, *tail;
};
/* Store blocklists in a linked list. */
static void
save_env_read_hook (grub_disk_addr_t sector, unsigned offset, unsigned length,
void *data)
{
struct grub_cmd_save_env_ctx *ctx = data;
struct blocklist *block;
block = grub_malloc (sizeof (*block));
if (! block)
return;
block->sector = sector;
block->offset = offset;
block->length = length;
/* Slightly complicated, because the list should be FIFO. */
block->next = 0;
if (ctx->tail)
ctx->tail->next = block;
ctx->tail = block;
if (! ctx->head)
ctx->head = block;
}
static grub_err_t
grub_cmd_save_env (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
grub_file_t file;
grub_envblk_t envblk;
struct grub_cmd_save_env_ctx ctx = {
.head = 0,
.tail = 0
};
if (! argc)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no variable is specified");
file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
GRUB_FILE_TYPE_SAVEENV
| GRUB_FILE_TYPE_SKIP_SIGNATURE);
if (! file)
return grub_errno;
if (! file->device->disk)
{
grub_file_close (file);
return grub_error (GRUB_ERR_BAD_DEVICE, "disk device required");
}
file->read_hook = save_env_read_hook;
file->read_hook_data = &ctx;
envblk = read_envblk_file (file);
file->read_hook = 0;
if (! envblk)
goto fail;
if (check_blocklists (envblk, ctx.head, file))
goto fail;
while (argc)
{
const char *value;
value = grub_env_get (args[0]);
if (value)
{
if (! grub_envblk_set (envblk, args[0], value))
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "environment block too small");
goto fail;
}
}
else
grub_envblk_delete (envblk, args[0]);
argc--;
args++;
}
write_blocklists (envblk, ctx.head, file);
fail:
if (envblk)
grub_envblk_close (envblk);
free_blocklists (ctx.head);
grub_file_close (file);
return grub_errno;
}
static grub_extcmd_t cmd_load, cmd_list, cmd_save;
GRUB_MOD_INIT(loadenv)
{
cmd_load =
grub_register_extcmd ("load_env", grub_cmd_load_env, 0,
N_("[-f FILE] [-s|--skip-sig] [variable_name_to_whitelist] [...]"),
N_("Load variables from environment block file."),
options);
cmd_list =
grub_register_extcmd ("list_env", grub_cmd_list_env, 0, N_("[-f FILE]"),
N_("List variables from environment block file."),
options);
cmd_save =
grub_register_extcmd ("save_env", grub_cmd_save_env, 0,
N_("[-f FILE] variable_name [...]"),
N_("Save variables to environment block file."),
options);
}
GRUB_MOD_FINI(loadenv)
{
grub_unregister_extcmd (cmd_load);
grub_unregister_extcmd (cmd_list);
grub_unregister_extcmd (cmd_save);
}
/* loadenv.c - command to load/save environment variable. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
static grub_envblk_t UNUSED
read_envblk_file (grub_file_t file)
{
grub_off_t offset = 0;
char *buf;
grub_size_t size = grub_file_size (file);
grub_envblk_t envblk;
buf = grub_malloc (size);
if (! buf)
return 0;
while (size > 0)
{
grub_ssize_t ret;
ret = grub_file_read (file, buf + offset, size);
if (ret <= 0)
{
grub_free (buf);
return 0;
}
size -= ret;
offset += ret;
}
envblk = grub_envblk_open (buf, offset);
if (! envblk)
{
grub_free (buf);
grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
return 0;
}
return envblk;
}
struct grub_env_whitelist
{
grub_size_t len;
char **list;
};
typedef struct grub_env_whitelist grub_env_whitelist_t;
static int UNUSED
test_whitelist_membership (const char* name,
const grub_env_whitelist_t* whitelist)
{
grub_size_t i;
for (i = 0; i < whitelist->len; i++)
if (grub_strcmp (name, whitelist->list[i]) == 0)
return 1; /* found it */
return 0; /* not found */
}
/* Helper for grub_cmd_load_env. */
static int UNUSED
set_var (const char *name, const char *value, void *whitelist)
{
if (! whitelist)
{
grub_env_set (name, value);
return 0;
}
if (test_whitelist_membership (name,
(const grub_env_whitelist_t *) whitelist))
grub_env_set (name, value);
return 0;
}
/* menuentry.c - menuentry command */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/normal.h>
static const struct grub_arg_option options[] =
{
{"class", 1, GRUB_ARG_OPTION_REPEATABLE,
N_("Menu entry type."), N_("STRING"), ARG_TYPE_STRING},
{"users", 2, 0,
N_("List of users allowed to boot this entry."), N_("USERNAME[,USERNAME]"),
ARG_TYPE_STRING},
{"hotkey", 3, 0,
N_("Keyboard key to quickly boot this entry."), N_("KEYBOARD_KEY"), ARG_TYPE_STRING},
{"source", 4, 0,
N_("Use STRING as menu entry body."), N_("STRING"), ARG_TYPE_STRING},
{"id", 0, 0, N_("Menu entry identifier."), N_("STRING"), ARG_TYPE_STRING},
/* TRANSLATORS: menu entry can either be bootable by anyone or only by
handful of users. By default when security is active only superusers can
boot a given menu entry. With --unrestricted (this option)
anyone can boot it. */
{"unrestricted", 0, 0, N_("This entry can be booted by any user."),
0, ARG_TYPE_NONE},
{0, 0, 0, 0, 0, 0}
};
static struct
{
const char *name;
int key;
} hotkey_aliases[] =
{
{"backspace", GRUB_TERM_BACKSPACE},
{"tab", GRUB_TERM_TAB},
{"delete", GRUB_TERM_KEY_DC},
{"insert", GRUB_TERM_KEY_INSERT},
{"f1", GRUB_TERM_KEY_F1},
{"f2", GRUB_TERM_KEY_F2},
{"f3", GRUB_TERM_KEY_F3},
{"f4", GRUB_TERM_KEY_F4},
{"f5", GRUB_TERM_KEY_F5},
{"f6", GRUB_TERM_KEY_F6},
{"f7", GRUB_TERM_KEY_F7},
{"f8", GRUB_TERM_KEY_F8},
{"f9", GRUB_TERM_KEY_F9},
{"f10", GRUB_TERM_KEY_F10},
{"f11", GRUB_TERM_KEY_F11},
{"f12", GRUB_TERM_KEY_F12},
};
/* Add a menu entry to the current menu context (as given by the environment
variable data slot `menu'). As the configuration file is read, the script
parser calls this when a menu entry is to be created. */
grub_err_t
grub_normal_add_menu_entry (int argc, const char **args,
char **classes, const char *id,
const char *users, const char *hotkey,
const char *prefix, const char *sourcecode,
int submenu, int *index, struct bls_entry *bls)
{
int menu_hotkey = 0;
char **menu_args = NULL;
char *menu_users = NULL;
char *menu_title = NULL;
char *menu_sourcecode = NULL;
char *menu_id = NULL;
struct grub_menu_entry_class *menu_classes = NULL;
grub_menu_t menu;
grub_menu_entry_t *last;
menu = grub_env_get_menu ();
if (! menu)
return grub_error (GRUB_ERR_MENU, "no menu context");
last = &menu->entry_list;
menu_sourcecode = grub_xasprintf ("%s%s", prefix ?: "", sourcecode);
if (! menu_sourcecode)
return grub_errno;
if (classes && classes[0])
{
int i;
for (i = 0; classes[i]; i++); /* count # of menuentry classes */
menu_classes = grub_zalloc (sizeof (struct grub_menu_entry_class)
* (i + 1));
if (! menu_classes)
goto fail;
for (i = 0; classes[i]; i++)
{
menu_classes[i].name = grub_strdup (classes[i]);
if (! menu_classes[i].name)
goto fail;
menu_classes[i].next = classes[i + 1] ? &menu_classes[i + 1] : NULL;
}
}
if (users)
{
menu_users = grub_strdup (users);
if (! menu_users)
goto fail;
}
if (hotkey)
{
unsigned i;
for (i = 0; i < ARRAY_SIZE (hotkey_aliases); i++)
if (grub_strcmp (hotkey, hotkey_aliases[i].name) == 0)
{
menu_hotkey = hotkey_aliases[i].key;
break;
}
if (i == ARRAY_SIZE (hotkey_aliases))
menu_hotkey = hotkey[0];
}
if (! argc)
{
grub_error (GRUB_ERR_MENU, "menuentry is missing title");
goto fail;
}
menu_title = grub_strdup (args[0]);
if (! menu_title)
goto fail;
grub_dprintf ("menu", "id:\"%s\"\n", id);
grub_dprintf ("menu", "title:\"%s\"\n", menu_title);
menu_id = grub_strdup (id ? : menu_title);
if (! menu_id)
goto fail;
grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id);
/* Save argc, args to pass as parameters to block arg later. */
menu_args = grub_malloc (sizeof (char*) * (argc + 1));
if (! menu_args)
goto fail;
{
int i;
for (i = 0; i < argc; i++)
{
menu_args[i] = grub_strdup (args[i]);
if (! menu_args[i])
goto fail;
}
menu_args[argc] = NULL;
}
/* Add the menu entry at the end of the list. */
int ind=0;
while (*last)
{
ind++;
last = &(*last)->next;
}
*last = grub_zalloc (sizeof (**last));
if (! *last)
goto fail;
(*last)->title = menu_title;
(*last)->id = menu_id;
(*last)->hotkey = menu_hotkey;
(*last)->classes = menu_classes;
if (menu_users)
(*last)->restricted = 1;
(*last)->users = menu_users;
(*last)->argc = argc;
(*last)->args = menu_args;
(*last)->sourcecode = menu_sourcecode;
(*last)->submenu = submenu;
(*last)->bls = bls;
menu->size++;
if (index)
*index = ind;
return GRUB_ERR_NONE;
fail:
grub_free (menu_sourcecode);
{
int i;
for (i = 0; menu_classes && menu_classes[i].name; i++)
grub_free (menu_classes[i].name);
grub_free (menu_classes);
}
{
int i;
for (i = 0; menu_args && menu_args[i]; i++)
grub_free (menu_args[i]);
grub_free (menu_args);
}
grub_free (menu_users);
grub_free (menu_title);
grub_free (menu_id);
return grub_errno;
}
static char *
setparams_prefix (int argc, char **args)
{
int i;
int j;
char *p;
char *result;
grub_size_t len = 10;
/* Count resulting string length */
for (i = 0; i < argc; i++)
{
len += 3; /* 3 = 1 space + 2 quotes */
p = args[i];
while (*p)
len += (*p++ == '\'' ? 3 : 1);
}
result = grub_malloc (len + 2);
if (! result)
return 0;
grub_strcpy (result, "setparams");
p = result + 9;
for (j = 0; j < argc; j++)
{
*p++ = ' ';
*p++ = '\'';
p = grub_strchrsub (p, args[j], '\'', "'\\''");
*p++ = '\'';
}
*p++ = '\n';
*p = '\0';
return result;
}
static grub_err_t
grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args)
{
char ch;
char *src;
char *prefix;
unsigned len;
grub_err_t r;
const char *users;
if (! argc)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing arguments");
if (ctxt->state[3].set && ctxt->script)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "multiple menuentry definitions");
if (! ctxt->state[3].set && ! ctxt->script)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no menuentry definition");
if (ctxt->state[1].set)
users = ctxt->state[1].arg;
else if (ctxt->state[5].set)
users = NULL;
else
users = "";
if (! ctxt->script)
return grub_normal_add_menu_entry (argc, (const char **) args,
(ctxt->state[0].set ? ctxt->state[0].args
: NULL),
ctxt->state[4].arg,
users,
ctxt->state[2].arg, 0,
ctxt->state[3].arg,
ctxt->extcmd->cmd->name[0] == 's',
NULL, NULL);
src = args[argc - 1];
args[argc - 1] = NULL;
len = grub_strlen(src);
ch = src[len - 1];
src[len - 1] = '\0';
prefix = setparams_prefix (argc - 1, args);
if (! prefix)
return grub_errno;
r = grub_normal_add_menu_entry (argc - 1, (const char **) args,
ctxt->state[0].args, ctxt->state[4].arg,
users,
ctxt->state[2].arg, prefix, src + 1,
ctxt->extcmd->cmd->name[0] == 's', NULL,
NULL);
src[len - 1] = ch;
args[argc - 1] = src;
grub_free (prefix);
return r;
}
static grub_extcmd_t cmd, cmd_sub;
void
grub_menu_init (void)
{
cmd = grub_register_extcmd ("menuentry", grub_cmd_menuentry,
GRUB_COMMAND_FLAG_BLOCKS
| GRUB_COMMAND_ACCEPT_DASH
| GRUB_COMMAND_FLAG_EXTRACTOR,
N_("BLOCK"), N_("Define a menu entry."), options);
cmd_sub = grub_register_extcmd ("submenu", grub_cmd_menuentry,
GRUB_COMMAND_FLAG_BLOCKS
| GRUB_COMMAND_ACCEPT_DASH
| GRUB_COMMAND_FLAG_EXTRACTOR,
N_("BLOCK"), N_("Define a submenu."),
options);
}
void
grub_menu_fini (void)
{
grub_unregister_extcmd (cmd);
grub_unregister_extcmd (cmd_sub);
}
...@@ -109,6 +109,52 @@ grub_env_write_root (struct grub_env_var *var __attribute__ ((unused)), ...@@ -109,6 +109,52 @@ grub_env_write_root (struct grub_env_var *var __attribute__ ((unused)),
return grub_strdup (val); return grub_strdup (val);
} }
static int g_ventoy_hook_root = 0;
void ventoy_env_hook_root(int hook)
{
g_ventoy_hook_root = hook;
}
static char *
ventoy_env_write_root (struct grub_env_var *var __attribute__ ((unused)),
const char *val)
{
const char *pos = val;
char buf[256];
if (g_ventoy_hook_root == 0)
{
return grub_env_write_root(var, val);
}
if (pos[0] == '(')
{
pos++;
}
if (grub_strncmp(pos, "vtimghd", 7) == 0)
{
return grub_env_write_root(var, val);
}
pos = grub_strchr(val, ',');
if (!pos)
{
return grub_env_write_root(var, val);
}
if (val[0] == '(')
{
grub_snprintf(buf, sizeof(buf), "(vtimghd%s", pos);
}
else
{
grub_snprintf(buf, sizeof(buf), "vtimghd%s", pos);
}
return grub_env_write_root(var, buf);
}
static void static void
grub_set_prefix_and_root (void) grub_set_prefix_and_root (void)
{ {
...@@ -123,7 +169,7 @@ grub_set_prefix_and_root (void) ...@@ -123,7 +169,7 @@ grub_set_prefix_and_root (void)
if (header->type == OBJ_TYPE_PREFIX) if (header->type == OBJ_TYPE_PREFIX)
prefix = (char *) header + sizeof (struct grub_module_header); prefix = (char *) header + sizeof (struct grub_module_header);
grub_register_variable_hook ("root", 0, grub_env_write_root); grub_register_variable_hook ("root", 0, ventoy_env_write_root);
grub_machine_get_bootlocation (&fwdevice, &fwpath); grub_machine_get_bootlocation (&fwdevice, &fwpath);
......
This diff is collapsed.
This diff is collapsed.
...@@ -803,6 +803,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) ...@@ -803,6 +803,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
goto refresh; goto refresh;
case GRUB_TERM_KEY_F2: case GRUB_TERM_KEY_F2:
case '2':
if (0 == g_ventoy_fn_mutex) { if (0 == g_ventoy_fn_mutex) {
cmdstr = grub_env_get("VTOY_F2_CMD"); cmdstr = grub_env_get("VTOY_F2_CMD");
if (cmdstr) if (cmdstr)
...@@ -816,6 +817,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) ...@@ -816,6 +817,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
} }
break; break;
case GRUB_TERM_KEY_F3: case GRUB_TERM_KEY_F3:
case '3':
if (0 == g_ventoy_fn_mutex) { if (0 == g_ventoy_fn_mutex) {
cmdstr = grub_env_get("VTOY_F3_CMD"); cmdstr = grub_env_get("VTOY_F3_CMD");
if (cmdstr) if (cmdstr)
...@@ -827,6 +829,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) ...@@ -827,6 +829,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
} }
break; break;
case GRUB_TERM_KEY_F4: case GRUB_TERM_KEY_F4:
case '4':
if (0 == g_ventoy_fn_mutex) { if (0 == g_ventoy_fn_mutex) {
cmdstr = grub_env_get("VTOY_F4_CMD"); cmdstr = grub_env_get("VTOY_F4_CMD");
if (cmdstr) if (cmdstr)
...@@ -840,6 +843,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) ...@@ -840,6 +843,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
} }
break; break;
case GRUB_TERM_KEY_F5: case GRUB_TERM_KEY_F5:
case '5':
if (0 == g_ventoy_fn_mutex) { if (0 == g_ventoy_fn_mutex) {
cmdstr = grub_env_get("VTOY_F5_CMD"); cmdstr = grub_env_get("VTOY_F5_CMD");
if (cmdstr) if (cmdstr)
...@@ -853,6 +857,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) ...@@ -853,6 +857,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
} }
break; break;
case GRUB_TERM_KEY_F6: case GRUB_TERM_KEY_F6:
case '6':
if (0 == g_ventoy_fn_mutex) { if (0 == g_ventoy_fn_mutex) {
cmdstr = grub_env_get("VTOY_F6_CMD"); cmdstr = grub_env_get("VTOY_F6_CMD");
if (cmdstr) if (cmdstr)
...@@ -866,6 +871,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) ...@@ -866,6 +871,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
} }
break; break;
case GRUB_TERM_KEY_F7: case GRUB_TERM_KEY_F7:
case '7':
cmdstr = grub_env_get("VTOY_F7_CMD"); cmdstr = grub_env_get("VTOY_F7_CMD");
if (cmdstr) if (cmdstr)
{ {
...@@ -875,6 +881,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) ...@@ -875,6 +881,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
} }
break; break;
case GRUB_TERM_KEY_F1: case GRUB_TERM_KEY_F1:
case '1':
menu_fini (); menu_fini ();
g_ventoy_memdisk_mode = 1 - g_ventoy_memdisk_mode; g_ventoy_memdisk_mode = 1 - g_ventoy_memdisk_mode;
g_ventoy_menu_refresh = 1; g_ventoy_menu_refresh = 1;
......
...@@ -180,11 +180,13 @@ command-line or ESC to discard edits and return to the GRUB menu."), ...@@ -180,11 +180,13 @@ command-line or ESC to discard edits and return to the GRUB menu."),
if (nested) if (nested)
{ {
#if 0
ret += grub_print_message_indented_real ret += grub_print_message_indented_real
(_("Press enter to boot the selected OS, " (_("Press enter to boot the selected OS, "
"`e' to edit the commands before booting " "`e' to edit the commands before booting "
"or `c' for a command-line. ESC to return previous menu."), "or `c' for a command-line. ESC to return previous menu."),
STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
#endif
} }
else else
{ {
...@@ -195,7 +197,7 @@ command-line or ESC to discard edits and return to the GRUB menu."), ...@@ -195,7 +197,7 @@ command-line or ESC to discard edits and return to the GRUB menu."),
ret += grub_print_message_indented_real("\n", STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); ret += grub_print_message_indented_real("\n", STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
ret += grub_print_message_indented_real(grub_env_get("VTOY_HOTKEY_TIP"), ret += grub_print_message_indented_real(grub_env_get("VTOY_HOTKEY_TIP"),
STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); 3, 6, term, dry_run);
} }
} }
return ret; return ret;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <grub/i18n.h> #include <grub/i18n.h>
#include <grub/net.h> #include <grub/net.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/kernel.h>
#ifdef GRUB_MACHINE_EFI #ifdef GRUB_MACHINE_EFI
#include <grub/efi/efi.h> #include <grub/efi/efi.h>
#endif #endif
...@@ -317,6 +318,38 @@ static grub_err_t ventoy_cmd_strstr(grub_extcmd_context_t ctxt, int argc, char * ...@@ -317,6 +318,38 @@ static grub_err_t ventoy_cmd_strstr(grub_extcmd_context_t ctxt, int argc, char *
return (grub_strstr(args[0], args[1])) ? 0 : 1; return (grub_strstr(args[0], args[1])) ? 0 : 1;
} }
static grub_err_t ventoy_cmd_strbegin(grub_extcmd_context_t ctxt, int argc, char **args)
{
char *c0, *c1;
(void)ctxt;
if (argc != 2)
{
return 1;
}
c0 = args[0];
c1 = args[1];
while (*c0 && *c1)
{
if (*c0 != *c1)
{
return 1;
}
c0++;
c1++;
}
if (*c1)
{
return 1;
}
return 0;
}
static grub_err_t ventoy_cmd_incr(grub_extcmd_context_t ctxt, int argc, char **args) static grub_err_t ventoy_cmd_incr(grub_extcmd_context_t ctxt, int argc, char **args)
{ {
long value_long = 0; long value_long = 0;
...@@ -410,7 +443,122 @@ static grub_err_t ventoy_cmd_load_wimboot(grub_extcmd_context_t ctxt, int argc, ...@@ -410,7 +443,122 @@ static grub_err_t ventoy_cmd_load_wimboot(grub_extcmd_context_t ctxt, int argc,
return 0; return 0;
} }
static grub_err_t ventoy_cmd_load_iso_to_mem(grub_extcmd_context_t ctxt, int argc, char **args) static int ventoy_load_efiboot_template(char **buf, int *datalen, int *direntoff)
{
int len;
grub_file_t file;
char exec[128];
char *data = NULL;
grub_uint32_t offset;
file = ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s/ventoy/ventoy_efiboot.img.xz", ventoy_get_env("vtoy_efi_part"));
if (file == NULL)
{
debug("failed to open file <%s>\n", "ventoy_efiboot.img.xz");
return 1;
}
len = (int)file->size;
data = (char *)grub_malloc(file->size);
if (!data)
{
return 1;
}
grub_file_read(file, data, file->size);
grub_file_close(file);
grub_snprintf(exec, sizeof(exec), "loopback efiboot mem:0x%llx:size:%d", (ulonglong)(ulong)data, len);
grub_script_execute_sourcecode(exec);
file = grub_file_open("(efiboot)/EFI/BOOT/BOOTX64.EFI", GRUB_FILE_TYPE_LINUX_INITRD);
offset = (grub_uint32_t)grub_iso9660_get_last_file_dirent_pos(file);
grub_file_close(file);
grub_script_execute_sourcecode("loopback -d efiboot");
*buf = data;
*datalen = len;
*direntoff = offset + 2;
return 0;
}
static grub_err_t ventoy_cmd_concat_efi_iso(grub_extcmd_context_t ctxt, int argc, char **args)
{
int len = 0;
int totlen = 0;
int offset = 0;
grub_file_t file;
char name[32];
char value[32];
char *buf = NULL;
char *data = NULL;
ventoy_iso9660_override *dirent;
(void)ctxt;
if (argc != 2)
{
return 1;
}
totlen = sizeof(ventoy_chain_head);
if (ventoy_load_efiboot_template(&buf, &len, &offset))
{
debug("failed to load efiboot template %d\n", len);
return 1;
}
totlen += len;
debug("efiboot template len:%d offset:%d\n", len, offset);
file = ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s", args[0]);
if (file == NULL)
{
debug("failed to open file <%s>\n", args[0]);
return 1;
}
totlen += ventoy_align_2k(file->size);
dirent = (ventoy_iso9660_override *)(buf + offset);
dirent->first_sector = len / 2048;
dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector);
dirent->size = (grub_uint32_t)file->size;
dirent->size_be = grub_swap_bytes32(dirent->size);
debug("rawiso len:%d efilen:%d total:%d\n", len, (int)file->size, totlen);
#ifdef GRUB_MACHINE_EFI
data = (char *)grub_efi_allocate_iso_buf(totlen);
#else
data = (char *)grub_malloc(totlen);
#endif
ventoy_fill_os_param(file, (ventoy_os_param *)data);
grub_memcpy(data + sizeof(ventoy_chain_head), buf, len);
grub_check_free(buf);
grub_file_read(file, data + sizeof(ventoy_chain_head) + len, file->size);
grub_file_close(file);
grub_snprintf(name, sizeof(name), "%s_addr", args[1]);
grub_snprintf(value, sizeof(value), "0x%llx", (ulonglong)(ulong)data);
grub_env_set(name, value);
grub_snprintf(name, sizeof(name), "%s_size", args[1]);
grub_snprintf(value, sizeof(value), "%d", (int)(totlen));
grub_env_set(name, value);
return 0;
}
static grub_err_t ventoy_cmd_load_file_to_mem(grub_extcmd_context_t ctxt, int argc, char **args)
{ {
int rc = 1; int rc = 1;
char name[32]; char name[32];
...@@ -430,7 +578,7 @@ static grub_err_t ventoy_cmd_load_iso_to_mem(grub_extcmd_context_t ctxt, int arg ...@@ -430,7 +578,7 @@ static grub_err_t ventoy_cmd_load_iso_to_mem(grub_extcmd_context_t ctxt, int arg
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]); file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (file == NULL) if (file == NULL)
{ {
debug("failed to open file <%s> for udf check\n", args[0]); debug("failed to open file <%s>\n", args[0]);
return 1; return 1;
} }
...@@ -456,6 +604,57 @@ static grub_err_t ventoy_cmd_load_iso_to_mem(grub_extcmd_context_t ctxt, int arg ...@@ -456,6 +604,57 @@ static grub_err_t ventoy_cmd_load_iso_to_mem(grub_extcmd_context_t ctxt, int arg
return rc; return rc;
} }
static grub_err_t ventoy_cmd_load_img_memdisk(grub_extcmd_context_t ctxt, int argc, char **args)
{
int rc = 1;
int headlen;
char name[32];
char value[32];
char *buf = NULL;
grub_file_t file;
(void)ctxt;
(void)argc;
(void)args;
if (argc != 2)
{
return rc;
}
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (file == NULL)
{
debug("failed to open file <%s> for udf check\n", args[0]);
return 1;
}
headlen = sizeof(ventoy_chain_head);
#ifdef GRUB_MACHINE_EFI
buf = (char *)grub_efi_allocate_iso_buf(headlen + file->size);
#else
buf = (char *)grub_malloc(headlen + file->size);
#endif
ventoy_fill_os_param(file, (ventoy_os_param *)buf);
grub_file_read(file, buf + headlen, file->size);
grub_snprintf(name, sizeof(name), "%s_addr", args[1]);
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(value, sizeof(value), "%llu", (unsigned long long)file->size);
grub_env_set(name, value);
grub_file_close(file);
rc = 0;
return rc;
}
static grub_err_t ventoy_cmd_iso9660_nojoliet(grub_extcmd_context_t ctxt, int argc, char **args) static grub_err_t ventoy_cmd_iso9660_nojoliet(grub_extcmd_context_t ctxt, int argc, char **args)
{ {
(void)ctxt; (void)ctxt;
...@@ -834,6 +1033,14 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho ...@@ -834,6 +1033,14 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
type = img_type_efi; type = img_type_efi;
} }
#endif #endif
else if (0 == grub_strcasecmp(filename + len - 4, ".img"))
{
if (len == 18 && grub_strncmp(filename, "ventoy_wimboot", 14) == 0)
{
return 0;
}
type = img_type_img;
}
else else
{ {
return 0; return 0;
...@@ -1359,13 +1566,14 @@ static grub_err_t ventoy_cmd_img_name(grub_extcmd_context_t ctxt, int argc, char ...@@ -1359,13 +1566,14 @@ static grub_err_t ventoy_cmd_img_name(grub_extcmd_context_t ctxt, int argc, char
static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int argc, char **args) static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int argc, char **args)
{ {
int img_id = 0; int img_id = 0;
char value[32];
char *pos = NULL; char *pos = NULL;
const char *id = NULL; const char *id = NULL;
img_info *cur = g_ventoy_img_list; img_info *cur = g_ventoy_img_list;
(void)ctxt; (void)ctxt;
if (argc != 1) if (argc < 1 || argc > 2)
{ {
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {var}", cmd_raw_name); return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {var}", cmd_raw_name);
} }
...@@ -1398,6 +1606,12 @@ static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int arg ...@@ -1398,6 +1606,12 @@ static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int arg
grub_env_set(args[0], cur->path); grub_env_set(args[0], cur->path);
if (argc > 1)
{
grub_snprintf(value, sizeof(value), "%llu", (ulonglong)(cur->size));
grub_env_set(args[1], value);
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE); VENTOY_CMD_RETURN(GRUB_ERR_NONE);
} }
...@@ -2366,6 +2580,28 @@ end: ...@@ -2366,6 +2580,28 @@ end:
return 0; return 0;
} }
static grub_err_t ventoy_cmd_img_hook_root(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
ventoy_env_hook_root(1);
return 0;
}
static grub_err_t ventoy_cmd_img_unhook_root(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
ventoy_env_hook_root(0);
return 0;
}
grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...) grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...)
{ {
grub_uint64_t size = 0; grub_uint64_t size = 0;
...@@ -2489,6 +2725,7 @@ static cmd_para ventoy_cmds[] = ...@@ -2489,6 +2725,7 @@ static cmd_para ventoy_cmds[] =
{ {
{ "vt_incr", ventoy_cmd_incr, 0, NULL, "{Var} {INT}", "Increase integer variable", NULL }, { "vt_incr", ventoy_cmd_incr, 0, NULL, "{Var} {INT}", "Increase integer variable", NULL },
{ "vt_strstr", ventoy_cmd_strstr, 0, NULL, "", "", NULL }, { "vt_strstr", ventoy_cmd_strstr, 0, NULL, "", "", NULL },
{ "vt_str_begin", ventoy_cmd_strbegin, 0, NULL, "", "", NULL },
{ "vt_debug", ventoy_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL }, { "vt_debug", ventoy_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL },
{ "vtdebug", ventoy_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL }, { "vtdebug", ventoy_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL },
{ "vtbreak", ventoy_cmd_break, 0, NULL, "{level}", "set debug break", NULL }, { "vtbreak", ventoy_cmd_break, 0, NULL, "{level}", "set debug break", NULL },
...@@ -2502,7 +2739,10 @@ static cmd_para ventoy_cmds[] = ...@@ -2502,7 +2739,10 @@ static cmd_para ventoy_cmds[] =
{ "vt_img_sector", ventoy_cmd_img_sector, 0, NULL, "{imageName}", "", NULL }, { "vt_img_sector", ventoy_cmd_img_sector, 0, NULL, "{imageName}", "", NULL },
{ "vt_dump_img_sector", ventoy_cmd_dump_img_sector, 0, NULL, "", "", NULL }, { "vt_dump_img_sector", ventoy_cmd_dump_img_sector, 0, NULL, "", "", NULL },
{ "vt_load_wimboot", ventoy_cmd_load_wimboot, 0, NULL, "", "", NULL }, { "vt_load_wimboot", ventoy_cmd_load_wimboot, 0, NULL, "", "", NULL },
{ "vt_load_cpio", ventoy_cmd_load_cpio, 0, NULL, "", "", NULL }, { "vt_load_cpio", ventoy_cmd_load_cpio, 0, NULL, "", "", NULL },
{ "vt_trailer_cpio", ventoy_cmd_trailer_cpio, 0, NULL, "", "", NULL },
{ "vt_find_first_bootable_hd", ventoy_cmd_find_bootable_hdd, 0, NULL, "", "", NULL }, { "vt_find_first_bootable_hd", ventoy_cmd_find_bootable_hdd, 0, NULL, "", "", NULL },
{ "vt_dump_menu", ventoy_cmd_dump_menu, 0, NULL, "", "", NULL }, { "vt_dump_menu", ventoy_cmd_dump_menu, 0, NULL, "", "", NULL },
{ "vt_dynamic_menu", ventoy_cmd_dynamic_menu, 0, NULL, "", "", NULL }, { "vt_dynamic_menu", ventoy_cmd_dynamic_menu, 0, NULL, "", "", NULL },
...@@ -2517,7 +2757,9 @@ static cmd_para ventoy_cmds[] = ...@@ -2517,7 +2757,9 @@ static cmd_para ventoy_cmds[] =
{ "vt_iso9660_nojoliet", ventoy_cmd_iso9660_nojoliet, 0, NULL, "", "", NULL }, { "vt_iso9660_nojoliet", ventoy_cmd_iso9660_nojoliet, 0, NULL, "", "", NULL },
{ "vt_is_udf", ventoy_cmd_is_udf, 0, NULL, "", "", NULL }, { "vt_is_udf", ventoy_cmd_is_udf, 0, NULL, "", "", NULL },
{ "vt_file_size", ventoy_cmd_file_size, 0, NULL, "", "", NULL }, { "vt_file_size", ventoy_cmd_file_size, 0, NULL, "", "", NULL },
{ "vt_load_iso_to_mem", ventoy_cmd_load_iso_to_mem, 0, NULL, "", "", NULL }, { "vt_load_file_to_mem", ventoy_cmd_load_file_to_mem, 0, NULL, "", "", NULL },
{ "vt_load_img_memdisk", ventoy_cmd_load_img_memdisk, 0, NULL, "", "", NULL },
{ "vt_concat_efi_iso", ventoy_cmd_concat_efi_iso, 0, NULL, "", "", NULL },
{ "vt_linux_parse_initrd_isolinux", ventoy_cmd_isolinux_initrd_collect, 0, NULL, "{cfgfile}", "", NULL }, { "vt_linux_parse_initrd_isolinux", ventoy_cmd_isolinux_initrd_collect, 0, NULL, "{cfgfile}", "", NULL },
{ "vt_linux_parse_initrd_grub", ventoy_cmd_grub_initrd_collect, 0, NULL, "{cfgfile}", "", NULL }, { "vt_linux_parse_initrd_grub", ventoy_cmd_grub_initrd_collect, 0, NULL, "{cfgfile}", "", NULL },
...@@ -2557,6 +2799,9 @@ static cmd_para ventoy_cmds[] = ...@@ -2557,6 +2799,9 @@ static cmd_para ventoy_cmds[] =
{ "vt_unix_replace_ko", ventoy_cmd_unix_replace_ko, 0, NULL, "", "", NULL }, { "vt_unix_replace_ko", ventoy_cmd_unix_replace_ko, 0, NULL, "", "", NULL },
{ "vt_unix_chain_data", ventoy_cmd_unix_chain_data, 0, NULL, "", "", NULL }, { "vt_unix_chain_data", ventoy_cmd_unix_chain_data, 0, NULL, "", "", NULL },
{ "vt_img_hook_root", ventoy_cmd_img_hook_root, 0, NULL, "", "", NULL },
{ "vt_img_unhook_root", ventoy_cmd_img_unhook_root, 0, NULL, "", "", NULL },
}; };
......
...@@ -467,6 +467,7 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc, ...@@ -467,6 +467,7 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_trailer_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name); int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name);
grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...); grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...);
grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...); grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...);
......
...@@ -151,6 +151,12 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk) ...@@ -151,6 +151,12 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk)
grub_printf("display_mode: %s\n", value); grub_printf("display_mode: %s\n", value);
} }
value = vtoy_json_get_string_ex(json->pstChild, "serial_param");
if (value)
{
grub_printf("serial_param %s\n", value);
}
value = vtoy_json_get_string_ex(json->pstChild, "ventoy_left"); value = vtoy_json_get_string_ex(json->pstChild, "ventoy_left");
if (value) if (value)
{ {
...@@ -236,6 +242,13 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk) ...@@ -236,6 +242,13 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
debug("display_mode %s\n", value); debug("display_mode %s\n", value);
grub_env_set("vtoy_display_mode", value); grub_env_set("vtoy_display_mode", value);
} }
value = vtoy_json_get_string_ex(json->pstChild, "serial_param");
if (value)
{
debug("serial_param %s\n", value);
grub_env_set("vtoy_serial_param", value);
}
value = vtoy_json_get_string_ex(json->pstChild, "ventoy_left"); value = vtoy_json_get_string_ex(json->pstChild, "ventoy_left");
if (value) if (value)
......
This diff is collapsed.
/* compiler.h - macros for various compiler features */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010,2014 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_COMPILER_HEADER
#define GRUB_COMPILER_HEADER 1
/* GCC version checking borrowed from glibc. */
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
# define GNUC_PREREQ(maj,min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define GNUC_PREREQ(maj,min) 0
#endif
/* Does this compiler support compile-time error attributes? */
#if GNUC_PREREQ(4,3)
# define ATTRIBUTE_ERROR(msg) \
__attribute__ ((__error__ (msg)))
#else
# define ATTRIBUTE_ERROR(msg) __attribute__ ((noreturn))
#endif
#if GNUC_PREREQ(4,4)
# define GNU_PRINTF gnu_printf
#else
# define GNU_PRINTF printf
#endif
#if GNUC_PREREQ(3,4)
# define WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
#else
# define WARN_UNUSED_RESULT
#endif
#define UNUSED __attribute__((__unused__))
#endif /* ! GRUB_COMPILER_HEADER */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment