Skip to content

Commit

Permalink
Fix up and boot with legacy Linux command for SL
Browse files Browse the repository at this point in the history
Signed-off-by: Ross Philipson <[email protected]>
  • Loading branch information
rossphilipson committed Sep 13, 2022
1 parent bdf2f79 commit d84e48c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion grub-core/Makefile.core.def
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ module = {
module = {
name = linux;
i386_pc = loader/i386/pc/linux.c;
x86_64_efi = loader/i386/efi/linux.c;
x86_64_efi = loader/i386/linux.c;
i386_efi = loader/i386/efi/linux.c;
i386_xen_pvh = loader/i386/linux.c;
xen = loader/i386/xen.c;
Expand Down
30 changes: 28 additions & 2 deletions grub-core/loader/i386/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static grub_size_t maximal_cmdline_size;
static struct linux_kernel_info *linux_info;
static struct linux_kernel_params linux_params;
static char *linux_cmdline;
static void *linux_params_ptr;
#ifdef GRUB_MACHINE_EFI
static grub_efi_uintn_t efi_mmap_size;
#else
Expand Down Expand Up @@ -472,6 +473,7 @@ grub_linux_boot_mmap_fill (grub_uint64_t addr, grub_uint64_t size,
* Please keep the logic in sync with the Linux kernel,
* drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
*/
#if 0
static grub_uint8_t
grub_efi_get_secureboot (void)
{
Expand Down Expand Up @@ -545,6 +547,7 @@ grub_efi_get_secureboot (void)
return secureboot;
}
#endif
#endif

static grub_err_t
grub_linux_boot (void)
Expand Down Expand Up @@ -835,11 +838,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
struct linux_i386_kernel_header lh;
grub_uint8_t setup_sects;
grub_size_t real_size, prot_size;
grub_size_t kernel_offset = 0;
grub_ssize_t len;
int i;
grub_size_t align, min_align;
int relocatable;
grub_uint64_t preferred_address = GRUB_LINUX_BZIMAGE_ADDR;
grub_uint8_t *kernel = NULL;

grub_dl_ref (my_mod);

Expand All @@ -853,14 +858,25 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (! file)
goto fail;

if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
len = grub_file_size (file);
kernel = grub_malloc (len);
if (!kernel)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
goto fail;
}

if (grub_file_read (file, kernel, len) != len)
{
if (!grub_errno)
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
argv[0]);
goto fail;
}

grub_memcpy (&lh, kernel, sizeof (lh));
kernel_offset = sizeof (lh);

if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
{
grub_error (GRUB_ERR_BAD_OS, "invalid magic number");
Expand Down Expand Up @@ -1309,6 +1325,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),

fail:

grub_free (kernel);

if (file)
grub_file_close (file);

Expand Down Expand Up @@ -1412,7 +1430,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
return grub_errno;
}

static grub_command_t cmd_linux, cmd_initrd;
static grub_command_t cmd_linux, cmd_initrd, cmd_linuxefi, cmd_initrdefi;

GRUB_MOD_INIT(linux)
{
Expand All @@ -1421,8 +1439,14 @@ GRUB_MOD_INIT(linux)

cmd_linux = grub_register_command ("linux", grub_cmd_linux,
0, N_("Load Linux."));
cmd_linuxefi =
grub_register_command ("linuxefi", grub_cmd_linux,
0, N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
0, N_("Load initrd."));
cmd_initrdefi =
grub_register_command ("initrdefi", grub_cmd_initrd,
0, N_("Load initrd."));
my_mod = mod;
}

Expand All @@ -1432,5 +1456,7 @@ GRUB_MOD_FINI(linux)
return;

grub_unregister_command (cmd_linux);
grub_unregister_command (cmd_linuxefi);
grub_unregister_command (cmd_initrd);
grub_unregister_command (cmd_initrdefi);
}

0 comments on commit d84e48c

Please sign in to comment.