All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH GRUB] Allow initrd concatenation on ARM64
@ 2015-11-12 13:08 Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 7+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-12 13:08 UTC (permalink / raw)
  To: The development of GRUB 2, Fu Wei, xen-devel


[-- Attachment #1.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.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 #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH GRUB] Allow initrd concatenation on ARM64
  2015-11-12 13:48   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2016-02-22 15:40     ` Fu Wei
  0 siblings, 0 replies; 7+ messages in thread
From: Fu Wei @ 2016-02-22 15:40 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: The development of GRUB 2, Julien Grall, Ian Campbell,
	Leif Lindholm, xen-devel

Hi Vladimir,

Sorry for late response, I turned to work on other tasks and haven't
sent the test resulted to you.

Last weekend I got a email from Julien about a xen boot problem on
arm64, I just noticed that you have simplified the xen_boot.c to drop
xen_linux, xen_initrd and xen_xsm.

By this way, we still can boot xen on arm64 by loading modules in a
specific order, and simplified the xen boot code.  I guess that is also
a good way to make  a patch for updating boot entrance in grub.cfg.

Is this still OK to update grub.cfg by this way:
(1) in xen_boot.c
  grub_env_set ("grub_xen_boot", "y");
  grub_env_export ("grub_xen_boot");

(2)in util/grub.d/20_linux_xen.in

----
diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
index f532fb9..49aa709 100644
--- a/util/grub.d/20_linux_xen.in
+++ b/util/grub.d/20_linux_xen.in
@@ -120,16 +120,16 @@ linux_entry ()
         else
             xen_rm_opts="no-real-mode edd=off"
         fi
- multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args}
\${xen_rm_opts}
+ ${multiboot_cmd} ${rel_xen_dirname}/${xen_basename} placeholder
${xen_args} \${xen_rm_opts}
  echo '$(echo "$lmessage" | grub_quote)'
- module ${rel_dirname}/${basename} placeholder
root=${linux_root_device_thisversion} ro ${args}
+ ${module_linux_cmd} ${rel_dirname}/${basename} placeholder
root=${linux_root_device_thisversion} ro ${args}
 EOF
   if test -n "${initrd}" ; then
     # TRANSLATORS: ramdisk isn't identifier. Should be translated.
     message="$(gettext_printf "Loading initial ramdisk ...")"
     sed "s/^/$submenu_indentation/" << EOF
  echo '$(echo "$message" | grub_quote)'
- module --nounzip   ${rel_dirname}/${initrd}
+ ${module_initrd_cmd}  ${rel_dirname}/${initrd}
 EOF
   fi
   sed "s/^/$submenu_indentation/" << EOF
@@ -185,6 +185,16 @@ case "$machine" in
     *) GENKERNEL_ARCH="$machine" ;;
 esac

+if [ "x$grub_xen_boot" != xy ]; then
+ multiboot_cmd="multiboot"
+ module_linux_cmd="module"
+ module_initrd_cmd="module --nounzip"
+else
+ multiboot_cmd="xen_hypervisor"
+ module_linux_cmd="xen_module"
+ module_initrd_cmd="xen_module"
+fi
+
 # Extra indentation to add to menu entries in a submenu. We're not in a submenu
 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
 submenu_indentation=""
----

(3)add xen_* aliases on x86,
----
diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c
index c4d9689..b88d51b 100644
--- a/grub-core/loader/i386/xen.c
+++ b/grub-core/loader/i386/xen.c
@@ -696,10 +696,14 @@ GRUB_MOD_INIT (xen)
                                   0, N_("Load Linux."));
   cmd_multiboot = grub_register_command ("multiboot", grub_cmd_xen,
                                         0, N_("Load Linux."));
+  cmd_multiboot = grub_register_command ("xen_hypervisor", grub_cmd_xen,
+                                        0, N_("Load Linux."));
   cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
                                      0, N_("Load initrd."));
   cmd_module = grub_register_command ("module", grub_cmd_module,
                                      0, N_("Load module."));
+  cmd_module = grub_register_command ("xen_module", grub_cmd_module,
+                                     0, N_("Load module."));
   my_mod = mod;
 }
----

Please correct me if I misunderstand something, thanks for your help,  :-)
and sorry for delay  :-(



On 12 November 2015 at 21:48, Vladimir 'φ-coder/phcoder' Serbinenko
<phcoder@gmail.com> wrote:
> On 12.11.2015 14:27, Ian Campbell wrote:
>> On Thu, 2015-11-12 at 14:08 +0100, Vladimir 'φ-coder/phcoder' Serbinenko
>> wrote:
>>> While on it also change "xen_linux" to "xen_kernel" to be vendor-neutral
>>> Could someone test please? I only compile-tested it
>>
>> I was expecting this patch to include a change
>> to ./util/grub.d/20_linux_xen.in to update the naming there, but it looks
>> like that aspect of the original series isn't in tree yet?
>>
> We need to figure out what we should do on x86 wrt multiboot vs
> multiboot2 before adapting 20_linux_xen
>> BTW, you have a stray "linux" in the description of the (now) xen_kernel
>> command.
>>
> Fixed locally, thank you
>> Ian.
>>
>> .
>>
>
>



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch
Ph: +86 21 61221326(direct)
Ph: +86 186 2020 4684 (mobile)
Room 1512, Regus One Corporate Avenue,Level 15,
One Corporate Avenue,222 Hubin Road,Huangpu District,
Shanghai,China 200021

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH GRUB] Allow initrd concatenation on ARM64
  2015-11-12 13:27 ` [Xen-devel] " Ian Campbell
  2015-11-12 13:48   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-12 13:48   ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 7+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-12 13:48 UTC (permalink / raw)
  To: Ian Campbell, The development of GRUB 2, Fu Wei, xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 708 bytes --]

On 12.11.2015 14:27, Ian Campbell wrote:
> On Thu, 2015-11-12 at 14:08 +0100, Vladimir 'φ-coder/phcoder' Serbinenko
> wrote:
>> While on it also change "xen_linux" to "xen_kernel" to be vendor-neutral
>> Could someone test please? I only compile-tested it
> 
> I was expecting this patch to include a change
> to ./util/grub.d/20_linux_xen.in to update the naming there, but it looks
> like that aspect of the original series isn't in tree yet?
> 
We need to figure out what we should do on x86 wrt multiboot vs
multiboot2 before adapting 20_linux_xen
> BTW, you have a stray "linux" in the description of the (now) xen_kernel
> command.
> 
Fixed locally, thank you
> Ian.
> 
> .
> 



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH GRUB] Allow initrd concatenation on ARM64
  2015-11-12 13:08 Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-12 13:27 ` Ian Campbell
  2015-11-12 13:27 ` [Xen-devel] " Ian Campbell
@ 2015-11-12 13:30 ` Fu Wei
  2015-11-12 13:30 ` Fu Wei
  3 siblings, 0 replies; 7+ messages in thread
From: Fu Wei @ 2015-11-12 13:30 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: The development of GRUB 2, xen-devel

Hi Vladimir,

OK, I will test it.

On 12 November 2015 at 21:08, Vladimir 'φ-coder/phcoder' Serbinenko
<phcoder@gmail.com> wrote:
> While on it also change "xen_linux" to "xen_kernel" to be vendor-neutral
> Could someone test please? I only compile-tested it



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch
Ph: +86 21 61221326(direct)
Ph: +86 186 2020 4684 (mobile)
Room 1512, Regus One Corporate Avenue,Level 15,
One Corporate Avenue,222 Hubin Road,Huangpu District,
Shanghai,China 200021

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH GRUB] Allow initrd concatenation on ARM64
  2015-11-12 13:08 Vladimir 'φ-coder/phcoder' Serbinenko
                   ` (2 preceding siblings ...)
  2015-11-12 13:30 ` Fu Wei
@ 2015-11-12 13:30 ` Fu Wei
  3 siblings, 0 replies; 7+ messages in thread
From: Fu Wei @ 2015-11-12 13:30 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: The development of GRUB 2, xen-devel

Hi Vladimir,

OK, I will test it.

On 12 November 2015 at 21:08, Vladimir 'φ-coder/phcoder' Serbinenko
<phcoder@gmail.com> wrote:
> While on it also change "xen_linux" to "xen_kernel" to be vendor-neutral
> Could someone test please? I only compile-tested it



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch
Ph: +86 21 61221326(direct)
Ph: +86 186 2020 4684 (mobile)
Room 1512, Regus One Corporate Avenue,Level 15,
One Corporate Avenue,222 Hubin Road,Huangpu District,
Shanghai,China 200021


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH GRUB] Allow initrd concatenation on ARM64
  2015-11-12 13:08 Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-12 13:27 ` Ian Campbell
  2015-11-12 13:27 ` [Xen-devel] " Ian Campbell
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Ian Campbell @ 2015-11-12 13:27 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko,
	The development of GRUB 2, Fu Wei, xen-devel

On Thu, 2015-11-12 at 14:08 +0100, Vladimir 'φ-coder/phcoder' Serbinenko
wrote:
> While on it also change "xen_linux" to "xen_kernel" to be vendor-neutral
> Could someone test please? I only compile-tested it

I was expecting this patch to include a change
to ./util/grub.d/20_linux_xen.in to update the naming there, but it looks
like that aspect of the original series isn't in tree yet?

BTW, you have a stray "linux" in the description of the (now) xen_kernel
command.

Ian.


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH GRUB] Allow initrd concatenation on ARM64
@ 2015-11-12 13:08 Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-12 13:27 ` Ian Campbell
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-12 13:08 UTC (permalink / raw)
  To: The development of GRUB 2, Fu Wei, xen-devel


[-- 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 --]

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-02-22 15:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12 13:08 [PATCH GRUB] Allow initrd concatenation on ARM64 Vladimir 'φ-coder/phcoder' Serbinenko
  -- strict thread matches above, loose matches on Subject: below --
2015-11-12 13:08 Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-12 13:27 ` Ian Campbell
2015-11-12 13:27 ` [Xen-devel] " Ian Campbell
2015-11-12 13:48   ` Vladimir 'φ-coder/phcoder' Serbinenko
2016-02-22 15:40     ` Fu Wei
2015-11-12 13:48   ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-12 13:30 ` Fu Wei
2015-11-12 13:30 ` Fu Wei

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.