From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>,
Fu Wei <fu.wei@linaro.org>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: [PATCH GRUB] Allow initrd concatenation on ARM64
Date: Thu, 12 Nov 2015 14:08:26 +0100 [thread overview]
Message-ID: <56448F4A.2090609@gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 127 bytes --]
While on it also change "xen_linux" to "xen_kernel" to be vendor-neutral
Could someone test please? I only compile-tested it
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: initrd.diff --]
[-- Type: text/x-diff; name="initrd.diff", Size: 9568 bytes --]
diff --git a/docs/grub.texi b/docs/grub.texi
index 1df3db2..112b42b 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -3859,7 +3859,7 @@ you forget a command, you can run the command @command{help}
* videoinfo:: List available video modes
@comment * xen_*:: Xen boot commands
* xen_hypervisor:: Load xen hypervisor binary
-* xen_linux:: Load dom0 kernel for xen hypervisor
+* xen_kernel:: Load dom0 kernel for xen hypervisor
* xen_initrd:: Load dom0 initrd for dom0 kernel
* xen_xsm:: Load xen security module for xen hypervisor
@end menu
@@ -5134,10 +5134,10 @@ verbatim as the @dfn{kernel command-line}. Any other binaries must be
reloaded after using this command.
@end deffn
-@node xen_linux
-@subsection xen_linux
+@node xen_kernel
+@subsection xen_kernel
-@deffn Command xen_linux file [arguments]
+@deffn Command xen_kernel file [arguments]
Load a dom0 kernel image for xen hypervisor at the booting process of xen.
The rest of the line is passed verbatim as the module command line.
@end deffn
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index d9fa0e3..34f7b61 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1641,6 +1642,7 @@ module = {
module = {
name = xen_boot;
common = lib/cmdline.c;
+ common = loader/linux.c;
arm64 = loader/arm64/xen_boot.c;
enable = arm64;
};
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
index d1a2189..e4a12bc 100644
--- a/grub-core/loader/arm64/xen_boot.c
+++ b/grub-core/loader/arm64/xen_boot.c
@@ -33,6 +33,7 @@
#include <grub/efi/pe32.h> /* required by struct xen_hypervisor_header */
#include <grub/i18n.h>
#include <grub/lib/cmdline.h>
+#include <grub/linux.h>
GRUB_MOD_LICENSE ("GPLv3+");
@@ -137,17 +138,53 @@ xen_boot_address_align (grub_addr_t start, grub_size_t align)
}
/* set module type according to command name. */
-static grub_err_t
-set_module_type (grub_command_t cmd, struct xen_boot_binary *module)
+static struct xen_boot_binary *
+allocate_module (module_type_t type)
{
- if (!grub_strcmp (cmd->name, "xen_linux"))
- module->node_info.type = MODULE_IMAGE;
- else if (!grub_strcmp (cmd->name, "xen_initrd"))
- module->node_info.type = MODULE_INITRD;
- else if (!grub_strcmp (cmd->name, "xen_xsm"))
- module->node_info.type = MODULE_XSM;
+ struct xen_boot_binary *module;
- return GRUB_ERR_NONE;
+ if (!loaded)
+ {
+ grub_error (GRUB_ERR_BAD_ARGUMENT,
+ N_("you need to load the Xen Hypervisor first"));
+ return NULL;
+ }
+
+ module =
+ (struct xen_boot_binary *) grub_zalloc (sizeof (struct xen_boot_binary));
+ if (!module)
+ return NULL;
+
+ module->node_info.type = type;
+
+ switch (module->node_info.type)
+ {
+ case MODULE_IMAGE:
+ case MODULE_INITRD:
+ case MODULE_XSM:
+ module->node_info.compat_string =
+ default_compat_string[module->node_info.type].compat_string;
+ module->node_info.compat_string_size =
+ default_compat_string[module->node_info.type].size;
+ break;
+
+ case MODULE_CUSTOM:
+ /* we have set the node_info in set_module_type */
+ break;
+
+ default:
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid argument"));
+ return NULL;
+ }
+ module->name = module->node_info.compat_string;
+ module->align = module_default_align[module->node_info.type];
+
+ grub_dprintf ("xen_loader", "Init %s module and node info:\n"
+ "compatible %s\ncompat_string_size 0x%lx\n",
+ module->name, module->node_info.compat_string,
+ module->node_info.compat_string_size);
+
+ return module;
}
static grub_err_t
@@ -372,11 +409,11 @@ xen_unload (void)
return GRUB_ERR_NONE;
}
-static void
-xen_boot_binary_load (struct xen_boot_binary *binary, grub_file_t file,
- int argc, char *argv[])
+static grub_err_t
+xen_boot_binary_allocate (struct xen_boot_binary *binary,
+ grub_size_t size)
{
- binary->size = grub_file_size (file);
+ binary->size = size;
grub_dprintf ("xen_loader", "Xen_boot %s file size: 0x%lx\n",
binary->name, binary->size);
@@ -386,13 +423,21 @@ xen_boot_binary_load (struct xen_boot_binary *binary, grub_file_t file,
(binary->size +
binary->align));
if (!binary->start)
- {
- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
- return;
- }
+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
grub_dprintf ("xen_loader", "Xen_boot %s numpages: 0x%lx\n",
binary->name, GRUB_EFI_BYTES_TO_PAGES (binary->size + binary->align));
+ return GRUB_ERR_NONE;
+}
+
+static void
+xen_boot_binary_load (struct xen_boot_binary *binary, grub_file_t file,
+ int argc, char *argv[])
+{
+ if (xen_boot_binary_allocate(binary, grub_file_size(file)))
+ {
+ return;
+ }
if (grub_file_read (file, (void *) xen_boot_address_align (binary->start,
binary->align),
@@ -432,9 +477,9 @@ xen_boot_binary_load (struct xen_boot_binary *binary, grub_file_t file,
static grub_err_t
grub_cmd_xen_module (grub_command_t cmd, int argc, char *argv[])
{
-
struct xen_boot_binary *module = NULL;
grub_file_t file = 0;
+ module_type_t type = MODULE_IMAGE;
if (!argc)
{
@@ -442,46 +487,15 @@ grub_cmd_xen_module (grub_command_t cmd, int argc, char *argv[])
goto fail;
}
- if (!loaded)
- {
- grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("you need to load the Xen Hypervisor first"));
- goto fail;
- }
-
- module =
- (struct xen_boot_binary *) grub_zalloc (sizeof (struct xen_boot_binary));
- if (!module)
- return grub_errno;
+ if (grub_strcmp (cmd->name, "xen_kernel") == 0)
+ type = MODULE_IMAGE;
+ else if (grub_strcmp (cmd->name, "xen_xsm") == 0)
+ type = MODULE_XSM;
+ module = allocate_module (type);
/* process all the options and get module type */
- if (set_module_type (cmd, module) != GRUB_ERR_NONE)
+ if (!module)
goto fail;
- switch (module->node_info.type)
- {
- case MODULE_IMAGE:
- case MODULE_INITRD:
- case MODULE_XSM:
- module->node_info.compat_string =
- default_compat_string[module->node_info.type].compat_string;
- module->node_info.compat_string_size =
- default_compat_string[module->node_info.type].size;
- break;
-
- case MODULE_CUSTOM:
- /* we have set the node_info in set_module_type */
- break;
-
- default:
- return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid argument"));
- }
- module->name = module->node_info.compat_string;
- module->align = module_default_align[module->node_info.type];
-
- grub_dprintf ("xen_loader", "Init %s module and node info:\n"
- "compatible %s\ncompat_string_size 0x%lx\n",
- module->name, module->node_info.compat_string,
- module->node_info.compat_string_size);
file = grub_file_open (argv[0]);
if (!file)
@@ -501,6 +515,44 @@ fail:
}
static grub_err_t
+grub_cmd_xen_initrd (grub_command_t cmd __attribute__ ((unused)),
+ int argc, char *argv[])
+{
+ struct xen_boot_binary *module = NULL;
+ struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 };
+ void *initrd_mem;
+
+ if (!argc)
+ {
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
+ goto fail;
+ }
+
+ module = allocate_module (MODULE_INITRD);
+ /* process all the options and get module type */
+ if (!module)
+ goto fail;
+
+ if (xen_boot_binary_allocate (module, grub_get_initrd_size (&initrd_ctx)))
+ goto fail;
+
+ initrd_mem = (void *) xen_boot_address_align (module->start,
+ module->align);
+
+ if (grub_initrd_load (&initrd_ctx, argv, initrd_mem))
+ goto fail;
+
+ grub_list_push (GRUB_AS_LIST_P (&module_head), GRUB_AS_LIST (module));
+
+fail:
+ grub_initrd_close (&initrd_ctx);
+ if (grub_errno != GRUB_ERR_NONE)
+ single_binary_unload (module);
+
+ return grub_errno;
+}
+
+static grub_err_t
grub_cmd_xen_hypervisor (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
@@ -559,18 +611,18 @@ fail:
}
static grub_command_t cmd_xen_hypervisor;
-static grub_command_t cmd_xen_linux, cmd_xen_initrd, cmd_xen_xsm;
+static grub_command_t cmd_xen_kernel, cmd_xen_initrd, cmd_xen_xsm;
GRUB_MOD_INIT (xen_boot)
{
cmd_xen_hypervisor =
grub_register_command ("xen_hypervisor", grub_cmd_xen_hypervisor, 0,
N_("Load a xen hypervisor."));
- cmd_xen_linux =
- grub_register_command ("xen_linux", grub_cmd_xen_module, 0,
+ cmd_xen_kernel =
+ grub_register_command ("xen_kernel", grub_cmd_xen_module, 0,
N_("Load a xen linux kernel for dom0."));
cmd_xen_initrd =
- grub_register_command ("xen_initrd", grub_cmd_xen_module, 0,
+ grub_register_command ("xen_initrd", grub_cmd_xen_initrd, 0,
N_("Load a xen initrd for dom0."));
cmd_xen_xsm =
grub_register_command ("xen_xsm", grub_cmd_xen_module, 0,
@@ -581,7 +633,7 @@ GRUB_MOD_INIT (xen_boot)
GRUB_MOD_FINI (xen_boot)
{
grub_unregister_command (cmd_xen_hypervisor);
- grub_unregister_command (cmd_xen_linux);
+ grub_unregister_command (cmd_xen_kernel);
grub_unregister_command (cmd_xen_initrd);
grub_unregister_command (cmd_xen_xsm);
}
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]
next reply other threads:[~2015-11-12 13:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-12 13:08 Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2015-11-12 13:27 ` [Xen-devel] [PATCH GRUB] Allow initrd concatenation on ARM64 Ian Campbell
2015-11-12 13:48 ` Vladimir 'φ-coder/phcoder' Serbinenko
2016-02-22 15:40 ` Fu Wei
2015-11-12 13:30 ` Fu Wei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56448F4A.2090609@gmail.com \
--to=phcoder@gmail.com \
--cc=fu.wei@linaro.org \
--cc=grub-devel@gnu.org \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).