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
This commit is contained in:
longpanda
2020-08-07 22:23:27 +08:00
parent 433d854aab
commit be50ea69aa
54 changed files with 7366 additions and 257 deletions

View File

@@ -0,0 +1,53 @@
/* 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 */

View File

@@ -0,0 +1,133 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2005,2006,2007,2008,2009 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_KERNEL_HEADER
#define GRUB_KERNEL_HEADER 1
#include <grub/types.h>
#include <grub/symbol.h>
enum
{
OBJ_TYPE_ELF,
OBJ_TYPE_MEMDISK,
OBJ_TYPE_CONFIG,
OBJ_TYPE_PREFIX,
OBJ_TYPE_PUBKEY,
OBJ_TYPE_DTB
};
/* The module header. */
struct grub_module_header
{
/* The type of object. */
grub_uint32_t type;
/* The size of object (including this header). */
grub_uint32_t size;
};
/* "gmim" (GRUB Module Info Magic). */
#define GRUB_MODULE_MAGIC 0x676d696d
struct grub_module_info32
{
/* Magic number so we know we have modules present. */
grub_uint32_t magic;
/* The offset of the modules. */
grub_uint32_t offset;
/* The size of all modules plus this header. */
grub_uint32_t size;
};
struct grub_module_info64
{
/* Magic number so we know we have modules present. */
grub_uint32_t magic;
grub_uint32_t padding;
/* The offset of the modules. */
grub_uint64_t offset;
/* The size of all modules plus this header. */
grub_uint64_t size;
};
#ifndef GRUB_UTIL
/* Space isn't reusable on some platforms. */
/* On Qemu the preload space is readonly. */
/* On emu there is no preload space. */
/* On ieee1275 our code assumes that heap is p=v which isn't guaranteed for module space. */
#if defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_EMU) \
|| defined (GRUB_MACHINE_EFI) \
|| (defined (GRUB_MACHINE_IEEE1275) && !defined (__sparc__))
#define GRUB_KERNEL_PRELOAD_SPACE_REUSABLE 0
#endif
#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) \
|| defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) \
|| defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_ARC) \
|| (defined (__sparc__) && defined (GRUB_MACHINE_IEEE1275)) \
|| defined (GRUB_MACHINE_UBOOT) || defined (GRUB_MACHINE_XEN) \
|| defined(GRUB_MACHINE_XEN_PVH)
/* FIXME: stack is between 2 heap regions. Move it. */
#define GRUB_KERNEL_PRELOAD_SPACE_REUSABLE 1
#endif
#ifndef GRUB_KERNEL_PRELOAD_SPACE_REUSABLE
#error "Please check if preload space is reusable on this platform!"
#endif
#if GRUB_TARGET_SIZEOF_VOID_P == 8
#define grub_module_info grub_module_info64
#else
#define grub_module_info grub_module_info32
#endif
extern grub_addr_t EXPORT_VAR (grub_modbase);
void EXPORT_FUNC(ventoy_env_hook_root)(int hook);
#define FOR_MODULES(var) for (\
var = (grub_modbase && ((((struct grub_module_info *) grub_modbase)->magic) == GRUB_MODULE_MAGIC)) ? (struct grub_module_header *) \
(grub_modbase + (((struct grub_module_info *) grub_modbase)->offset)) : 0;\
var && (grub_addr_t) var \
< (grub_modbase + (((struct grub_module_info *) grub_modbase)->size)); \
var = (struct grub_module_header *) \
(((grub_uint32_t *) var) + ((((struct grub_module_header *) var)->size + sizeof (grub_addr_t) - 1) / sizeof (grub_addr_t)) * (sizeof (grub_addr_t) / sizeof (grub_uint32_t))))
grub_addr_t grub_modules_get_end (void);
#endif
/* The start point of the C code. */
void grub_main (void) __attribute__ ((noreturn));
/* The machine-specific initialization. This must initialize memory. */
void grub_machine_init (void);
/* The machine-specific finalization. */
void EXPORT_FUNC(grub_machine_fini) (int flags);
/* The machine-specific prefix initialization. */
void
grub_machine_get_bootlocation (char **device, char **path);
/* Register all the exported symbols. This is automatically generated. */
void grub_register_exported_symbols (void);
extern void (*EXPORT_VAR(grub_net_poll_cards_idle)) (void);
#endif /* ! GRUB_KERNEL_HEADER */

View File

@@ -0,0 +1,119 @@
/* menu.h - Menu model function prototypes and data structures. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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_MENU_HEADER
#define GRUB_MENU_HEADER 1
struct bls_entry
{
struct bls_entry *next;
struct bls_entry *prev;
struct keyval **keyvals;
int nkeyvals;
char *filename;
int visible;
};
struct grub_menu_entry_class
{
char *name;
struct grub_menu_entry_class *next;
};
/* The menu entry. */
struct grub_menu_entry
{
/* The title name. */
const char *title;
/* The identifier. */
const char *id;
/* If set means not everybody is allowed to boot this entry. */
int restricted;
/* Allowed users. */
const char *users;
/* The classes associated with the menu entry:
used to choose an icon or other style attributes.
This is a dummy head node for the linked list, so for an entry E,
E.classes->next is the first class if it is not NULL. */
struct grub_menu_entry_class *classes;
/* The sourcecode of the menu entry, used by the editor. */
const char *sourcecode;
/* Parameters to be passed to menu definition. */
int argc;
char **args;
int hotkey;
int submenu;
/* The next element. */
struct grub_menu_entry *next;
/* BLS used to populate the entry */
struct bls_entry *bls;
};
typedef struct grub_menu_entry *grub_menu_entry_t;
/* The menu. */
struct grub_menu
{
/* The size of a menu. */
int size;
/* The list of menu entries. */
grub_menu_entry_t entry_list;
};
typedef struct grub_menu *grub_menu_t;
/* Callback structure menu viewers can use to provide user feedback when
default entries are executed, possibly including fallback entries. */
typedef struct grub_menu_execute_callback
{
/* Called immediately before ENTRY is booted. */
void (*notify_booting) (grub_menu_entry_t entry, void *userdata);
/* Called when executing one entry has failed, and another entry, ENTRY, will
be executed as a fallback. The implementation of this function should
delay for a period of at least 2 seconds before returning in order to
allow the user time to read the information before it can be lost by
executing ENTRY. */
void (*notify_fallback) (grub_menu_entry_t entry, void *userdata);
/* Called when an entry has failed to execute and there is no remaining
fallback entry to attempt. */
void (*notify_failure) (void *userdata);
}
*grub_menu_execute_callback_t;
grub_menu_entry_t grub_menu_get_entry (grub_menu_t menu, int no);
int grub_menu_get_timeout (void);
void grub_menu_set_timeout (int timeout);
void grub_menu_entry_run (grub_menu_entry_t entry);
int grub_menu_get_default_entry_index (grub_menu_t menu);
void grub_menu_init (void);
void grub_menu_fini (void);
#endif /* GRUB_MENU_HEADER */

View File

@@ -0,0 +1,177 @@
/* normal.h - prototypes for the normal mode */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2005,2006,2007,2008,2009 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_NORMAL_HEADER
#define GRUB_NORMAL_HEADER 1
#include <grub/term.h>
#include <grub/symbol.h>
#include <grub/err.h>
#include <grub/env.h>
#include <grub/menu.h>
#include <grub/command.h>
#include <grub/file.h>
/* The standard left and right margin for some messages. */
#define STANDARD_MARGIN 6
/* The type of a completion item. */
enum grub_completion_type
{
GRUB_COMPLETION_TYPE_COMMAND,
GRUB_COMPLETION_TYPE_DEVICE,
GRUB_COMPLETION_TYPE_PARTITION,
GRUB_COMPLETION_TYPE_FILE,
GRUB_COMPLETION_TYPE_ARGUMENT
};
typedef enum grub_completion_type grub_completion_type_t;
extern struct grub_menu_viewer grub_normal_text_menu_viewer;
extern int grub_normal_exit_level;
/* Defined in `main.c'. */
void grub_enter_normal_mode (const char *config);
void grub_normal_execute (const char *config, int nested, int batch);
struct grub_term_screen_geometry
{
/* The number of entries shown at a time. */
int num_entries;
int first_entry_y;
int first_entry_x;
int entry_width;
int timeout_y;
int timeout_lines;
int border;
int right_margin;
};
void grub_menu_init_page (int nested, int edit,
struct grub_term_screen_geometry *geo,
struct grub_term_output *term);
void grub_normal_init_page (struct grub_term_output *term, int y);
char *grub_file_getline (grub_file_t file);
void grub_cmdline_run (int nested, int force_auth);
/* Defined in `cmdline.c'. */
char *grub_cmdline_get (const char *prompt);
grub_err_t grub_set_history (int newsize);
/* Defined in `completion.c'. */
char *grub_normal_do_completion (char *buf, int *restore,
void (*hook) (const char *item, grub_completion_type_t type, int count));
/* Defined in `misc.c'. */
grub_err_t grub_normal_print_device_info (const char *name);
/* Defined in `color.c'. */
char *grub_env_write_color_normal (struct grub_env_var *var, const char *val);
char *grub_env_write_color_highlight (struct grub_env_var *var, const char *val);
int grub_parse_color_name_pair (grub_uint8_t *ret, const char *name);
/* Defined in `menu_text.c'. */
void grub_wait_after_message (void);
void
grub_print_ucs4 (const grub_uint32_t * str,
const grub_uint32_t * last_position,
int margin_left, int margin_right,
struct grub_term_output *term);
void
grub_print_ucs4_menu (const grub_uint32_t * str,
const grub_uint32_t * last_position,
int margin_left, int margin_right,
struct grub_term_output *term,
int skip_lines, int max_lines, grub_uint32_t contchar,
struct grub_term_pos *pos);
int
grub_ucs4_count_lines (const grub_uint32_t * str,
const grub_uint32_t * last_position,
int margin_left, int margin_right,
struct grub_term_output *term);
grub_size_t grub_getstringwidth (grub_uint32_t * str,
const grub_uint32_t * last_position,
struct grub_term_output *term);
void grub_print_message_indented (const char *msg, int margin_left,
int margin_right,
struct grub_term_output *term);
void
grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested);
grub_err_t
grub_show_menu (grub_menu_t menu, int nested, int autobooted);
/* Defined in `handler.c'. */
void read_handler_list (void);
void free_handler_list (void);
/* Defined in `dyncmd.c'. */
void read_command_list (const char *prefix);
/* Defined in `autofs.c'. */
void read_fs_list (const char *prefix);
void grub_context_init (void);
void grub_context_fini (void);
void read_crypto_list (const char *prefix);
void read_terminal_list (const char *prefix);
void grub_set_more (int onoff);
void grub_normal_reset_more (void);
void grub_xputs_normal (const char *str);
extern int grub_extractor_level;
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);
grub_err_t
grub_normal_set_password (const char *user, const char *password);
void grub_normal_free_menu (grub_menu_t menu);
void grub_normal_auth_init (void);
void grub_normal_auth_fini (void);
void
grub_xnputs (const char *str, grub_size_t msg_len);
grub_command_t
grub_dyncmd_get_cmd (grub_command_t cmd);
void
grub_gettext_reread_prefix (const char *val);
enum grub_human_size_type
{
GRUB_HUMAN_SIZE_NORMAL,
GRUB_HUMAN_SIZE_SHORT,
GRUB_HUMAN_SIZE_SPEED,
};
const char *
grub_get_human_size (grub_uint64_t size, enum grub_human_size_type type);
#endif /* ! GRUB_NORMAL_HEADER */