Use finish boot services and switch to new command line interface in linux loader

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-09-01 03:05:36 +02:00
parent b764f436e7
commit afef75b254

View file

@ -327,6 +327,7 @@ grub_linux_boot (void)
grub_efi_uintn_t desc_size; grub_efi_uintn_t desc_size;
grub_efi_uint32_t desc_version; grub_efi_uint32_t desc_version;
grub_efi_memory_descriptor_t *mmap_buf; grub_efi_memory_descriptor_t *mmap_buf;
grub_err_t err;
/* FPSWA. */ /* FPSWA. */
query_fpswa (); query_fpswa ();
@ -349,18 +350,16 @@ grub_linux_boot (void)
mmap_buf = grub_efi_allocate_boot_pages (0, page_align (mmap_size) >> 12); mmap_buf = grub_efi_allocate_boot_pages (0, page_align (mmap_size) >> 12);
if (! mmap_buf) if (! mmap_buf)
grub_fatal ("cannot allocate memory map"); grub_fatal ("cannot allocate memory map");
if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key, err = grub_efi_finish_boot_services (&mmap_size, mmap_buf, &map_key,
&desc_size, &desc_version) <= 0) &desc_size, &desc_version);
grub_fatal ("cannot get memory map"); if (err)
return err;
boot_param->efi_memmap = (grub_uint64_t)mmap_buf; boot_param->efi_memmap = (grub_uint64_t)mmap_buf;
boot_param->efi_memmap_size = mmap_size; boot_param->efi_memmap_size = mmap_size;
boot_param->efi_memdesc_size = desc_size; boot_param->efi_memdesc_size = desc_size;
boot_param->efi_memdesc_version = desc_version; boot_param->efi_memdesc_version = desc_version;
if (! grub_efi_exit_boot_services (map_key))
grub_fatal ("cannot exit boot services");
/* See you next boot. */ /* See you next boot. */
asm volatile ("mov r28=%1; br.sptk.few %0" :: "b"(entry),"r"(boot_param)); asm volatile ("mov r28=%1; br.sptk.few %0" :: "b"(entry),"r"(boot_param));
@ -494,8 +493,9 @@ grub_load_elf64 (grub_file_t file, void *buffer)
return 0; return 0;
} }
void static grub_err_t
grub_rescue_cmd_linux (int argc, char *argv[]) grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{ {
grub_file_t file = 0; grub_file_t file = 0;
char buffer[GRUB_ELF_SEARCH]; char buffer[GRUB_ELF_SEARCH];
@ -574,10 +574,12 @@ grub_rescue_cmd_linux (int argc, char *argv[])
boot_param_pages); boot_param_pages);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
} }
return grub_errno;
} }
void static grub_err_t
grub_rescue_cmd_initrd (int argc, char *argv[]) grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{ {
grub_file_t file = 0; grub_file_t file = 0;
@ -617,10 +619,12 @@ grub_rescue_cmd_initrd (int argc, char *argv[])
fail: fail:
if (file) if (file)
grub_file_close (file); grub_file_close (file);
return grub_errno;
} }
void static grub_err_t
grub_rescue_cmd_payload (int argc, char *argv[]) grub_cmd_payload (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{ {
grub_file_t file = 0; grub_file_t file = 0;
grub_ssize_t size, len = 0; grub_ssize_t size, len = 0;
@ -708,10 +712,12 @@ grub_rescue_cmd_payload (int argc, char *argv[])
grub_free (base); grub_free (base);
grub_free (cmdline); grub_free (cmdline);
} }
return grub_errno;
} }
void static grub_err_t
grub_rescue_cmd_relocate (int argc, char *argv[]) grub_cmd_relocate (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{ {
static const char * const vals[] = { "off", "on", "force"}; static const char * const vals[] = { "off", "on", "force"};
unsigned int i; unsigned int i;
@ -719,6 +725,7 @@ grub_rescue_cmd_relocate (int argc, char *argv[])
if (argc == 0) if (argc == 0)
{ {
grub_printf ("relocate is %s\n", vals[relocate]); grub_printf ("relocate is %s\n", vals[relocate]);
return GRUB_ERR_NONE;
} }
else if (argc == 1) else if (argc == 1)
{ {
@ -728,67 +735,63 @@ grub_rescue_cmd_relocate (int argc, char *argv[])
if (grub_strcmp (argv[0], vals[i]) == 0) if (grub_strcmp (argv[0], vals[i]) == 0)
{ {
relocate = i; relocate = i;
return; return GRUB_ERR_NONE;
} }
grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown relocate value"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown relocate value");
} }
else else
{ {
grub_error (GRUB_ERR_BAD_ARGUMENT, "accept 0 or 1 argument"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "accept 0 or 1 argument");
} }
} }
void static grub_err_t
grub_rescue_cmd_fpswa (int argc, char *argv[] __attribute__((unused))) grub_cmd_fpswa (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[] __attribute__((unused)))
{ {
if (argc != 0) if (argc != 0)
{ {
grub_error (GRUB_ERR_BAD_ARGUMENT, "Arguments not expected"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "Arguments not expected");
return;
} }
query_fpswa (); query_fpswa ();
if (fpswa == NULL) if (fpswa == NULL)
grub_printf ("No FPSWA loaded\n"); grub_printf ("No FPSWA loaded\n");
else else
grub_printf ("FPSWA revision: %x\n", fpswa->revision); grub_printf ("FPSWA revision: %x\n", fpswa->revision);
return GRUB_ERR_NONE;
} }
static grub_command_t cmd_linux, cmd_initrd, cmd_payload, cmd_relocate, cmd_fpswa;
GRUB_MOD_INIT(linux) GRUB_MOD_INIT(linux)
{ {
grub_register_extcmd ("linux", grub_normal_linux_command, cmd_linux = grub_register_command ("linux", grub_cmd_linux,
GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, "FILE [ARGS...]", "Load Linux.");
"linux FILE [ARGS...]",
"Load Linux.", 0);
grub_register_extcmd ("initrd", grub_normal_initrd_command, cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, "FILE", "Load initrd.");
"initrd FILE",
"Load initrd.", 0);
grub_register_extcmd ("payload", grub_normal_cmd_payload, cmd_payload = grub_register_command ("payload", grub_cmd_payload,
GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, "FILE [ARGS...]",
"payload FILE [ARGS...]", "Load an additional file.");
"Load an additional file.", 0);
grub_register_extcmd ("relocate", grub_normal_cmd_relocate, cmd_relocate = grub_register_command ("relocate", grub_cmd_relocate,
GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, "[on|off|force]",
"relocate [on|off|force]", "Set relocate feature.");
"Set relocate feature.", 0);
grub_register_extcmd ("fpswa", grub_normal_cmd_fpswa, cmd_fpswa = grub_register_command ("fpswa", grub_cmd_fpswa,
GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, "", "Display FPSWA version.");
"fpswa",
"Display FPSWA version.", 0);
my_mod = mod; my_mod = mod;
} }
GRUB_MOD_FINI(linux) GRUB_MOD_FINI(linux)
{ {
grub_unregister_command ("linux"); grub_unregister_command (cmd_linux);
grub_unregister_command ("initrd"); grub_unregister_command (cmd_initrd);
grub_unregister_command ("payload"); grub_unregister_command (cmd_payload);
grub_unregister_command ("relocate"); grub_unregister_command (cmd_relocate);
grub_unregister_command ("fpswa"); grub_unregister_command (cmd_fpswa);
} }