Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Yrk0t-0004Ma-Rr for mharc-grub-devel@gnu.org; Mon, 11 May 2015 05:28:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yrk0r-0004MT-Gd for grub-devel@gnu.org; Mon, 11 May 2015 05:28:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yrk0q-00014N-El for grub-devel@gnu.org; Mon, 11 May 2015 05:28:37 -0400 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::2]:17192) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yrk0q-000146-4n for grub-devel@gnu.org; Mon, 11 May 2015 05:28:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1431336514; l=2683; s=domk; d=aepfle.de; h=Date:Subject:Cc:To:From; bh=xfBNAwSAMJkuQWHxcSnmcnWbKtAjwtfvf7JgAX0srT0=; b=CNuaIQbhCH4u9LRL4NK0RUumlll8tvpp40JV6CMFtLwOUKWS8nulmZrLDoJuzlWaR1t FXhwrT3+DYrAm9JIy399NecFQMGs++6bKoI/jtcRpz1+XmuMMVImzIm9QsUy2K1p8pfus G2HiG3kNSVwZTk1qrq59sndeWfUoT2Ce/zM= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWi/zfN1cLnBYfssVY1SE5ClEYfb5sQvxDNUdfk3GFAM3xrxaZN0YQ== X-RZG-CLASS-ID: mo00 Received: from probook.fritz.box ([2001:a60:10a3:eb01:1ec1:deff:feb9:bb48]) by smtp.strato.de (RZmta 37.5 AUTH) with ESMTPSA id Q01a9fr4B9SYF7b (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve sect571r1 with 571 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 11 May 2015 11:28:34 +0200 (CEST) Received: by probook.fritz.box (Postfix, from userid 1000) id 92168502A7; Mon, 11 May 2015 11:28:33 +0200 (CEST) From: Olaf Hering To: grub-devel@gnu.org Subject: [PATCH] Parse commandline in grub-xen Date: Mon, 11 May 2015 09:28:28 +0000 Message-Id: <1431336508-17290-1-git-send-email-olaf@aepfle.de> X-Mailer: git-send-email 2.3.5 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:238:20a:202:5300::2 Cc: Olaf Hering X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 May 2015 09:28:38 -0000 If grub is used as the kernel in a Xen PV guest there is no way to pass information into grub. This includes info like which disk should be used first when searching for files. Up to now the workaround for the host admin is to rebuild grub-xen every time with grub-mkimage and include a custom script. Such step should be avoided if possible, the distro provided grub-xen binary should be used. With this change the command line (extra= in domU.cfg) will be evaluated by grub. Each 'name=val' pair will be exported as shell variable, other strings will be ignored. This makes it possible to provide a generic grub-xen binary for PV guests. It is now up to the scripts in such binary to interpret the variables as they see fit. It should be noted that some variables may be set by grub itself, overriding anything provided in the cmdline. This depends on the way grub-xen is built, which modules are included. Signed-off-by: Olaf Hering --- grub-core/kern/xen/init.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c index 0559c03..1dbc01f 100644 --- a/grub-core/kern/xen/init.c +++ b/grub-core/kern/xen/init.c @@ -524,6 +524,77 @@ map_all_pages (void) grub_mm_init_region ((void *) heap_start, heap_end - heap_start); } +/* + * Find all name=val pairs in the provided cmd_line and export them + * so that scripts can evaluate the variables for their own purpose. + */ +static void +parse_cmdline (void) +{ + grub_size_t i; + char *p, *name, *val; + int found; + + p = grub_malloc (MAX_GUEST_CMDLINE + 1); + if (!p) + return; + + grub_memcpy (p, grub_xen_start_page_addr->cmd_line, MAX_GUEST_CMDLINE); + p[MAX_GUEST_CMDLINE] = '\0'; + + for (i = 0; i < MAX_GUEST_CMDLINE && p[i]; i++) + { + if (grub_isspace (p[i])) + continue; + + name = &p[i]; + found = 0; + do + { + if (grub_isspace (p[i])) + break; + if (p[i] == '=') + { + p[i] = '\0'; + found = 1; + break; + } + if (!p[i + 1]) + break; + i++; + } + while (i < MAX_GUEST_CMDLINE); + + if (!found) + continue; + + i++; + val = &p[i]; + found = 0; + do + { + if (grub_isspace (p[i])) + { + p[i] = '\0'; + found = 1; + } + if (!p[i + 1]) + found = 1; + if (found) + break; + i++; + } + while (i < MAX_GUEST_CMDLINE); + + if (!found) + continue; + + grub_env_set (name, val); + grub_env_export (name); + } + grub_free (p); +} + extern char _end[]; void @@ -539,6 +610,8 @@ grub_machine_init (void) map_all_pages (); + parse_cmdline (); + grub_console_init (); grub_tsc_init ();