From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1UXYVa-0002lZ-MP for mharc-grub-devel@gnu.org; Wed, 01 May 2013 10:59:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXYVX-0002hZ-M4 for grub-devel@gnu.org; Wed, 01 May 2013 10:59:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UXYVV-0003aM-Uw for grub-devel@gnu.org; Wed, 01 May 2013 10:59:47 -0400 Received: from mail-lb0-f169.google.com ([209.85.217.169]:37442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXYVR-0003Yh-1t; Wed, 01 May 2013 10:59:41 -0400 Received: by mail-lb0-f169.google.com with SMTP id z5so1524101lbh.28 for ; Wed, 01 May 2013 07:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:cc:subject:message-id:in-reply-to :references:x-mailer:mime-version:content-type :content-transfer-encoding; bh=DQtU9p8a5BWF7lGgIB7tzI4Gjy/MctKYxkIDehRV/Hs=; b=sPk53NeeT16uXJQObV2JWmGTuK+FzYuHNN7psYqiK8j0p9K+Ov8UlBTxFpvpCWjM0Y alLx8JkePggN4x2XDAbtt4NjgdZtwpx8e+vTpwzjirEz1qeL7hwGq94wHdtBa3l3he8N dBOb7l/SaBntJIFX4BXVNzjVSSFa4k506mlY2Ye3bGjF3rsToW7CbztRFhksSfQYyj7b xYn3YW9Kh0k+XkLY1Ll8/4To6IR0kCYgIZ92oFwbBlgPvhJn1CEaQpLIEsnQrH5ZN1tM phWr/NJbhtZIuzNMro9SEa0IFDxqsCKgUtNLTLM13YaYT4UV6fCg/4J76k7BcV2kjkqB 2Oyw== X-Received: by 10.112.201.196 with SMTP id kc4mr1315878lbc.24.1367420379291; Wed, 01 May 2013 07:59:39 -0700 (PDT) Received: from opensuse.site ([94.29.72.160]) by mx.google.com with ESMTPSA id dn9sm1348021lbc.14.2013.05.01.07.59.38 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Wed, 01 May 2013 07:59:38 -0700 (PDT) Date: Wed, 1 May 2013 18:59:34 +0400 From: Andrey Borzenkov To: Rigoberto Corujo Subject: Re: Obtaining the MAC address of the boot NIC for a PXE boot Message-ID: <20130501185934.3f2b9c28@opensuse.site> In-Reply-To: <1367240132.58582.YahooMailNeo@web120204.mail.ne1.yahoo.com> References: <1367240132.58582.YahooMailNeo@web120204.mail.ne1.yahoo.com> X-Mailer: Claws Mail 3.9.0 (GTK+ 2.24.14; x86_64-suse-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.217.169 Cc: "help-grub@gnu.org" , grub-devel@gnu.org 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: Wed, 01 May 2013 14:59:49 -0000 ÷ Mon, 29 Apr 2013 05:55:32 -0700 (PDT) Rigoberto Corujo ÐÉÛÅÔ: > Hello everyone, > > With pxelinux, you can specify "IPAPPEND 2" in your boot loader configuration file and the MAC address of the boot NIC automatically gets appended to your kernel parameters as "BOOTIF=XX:XX:XX:XX:XX:XX".š > > I am now trying to become familiar with Grub 2, because if its EFI support. š I noticed that with Grub 2, some of the documentation, which may be outdated, says that there is a "net_pxe_mac" variable which, as I understand it, should contain the MAC address of the boot NIC. šHowever, I've built the latest Grub 2 sources and, when I PXE boot and drop into a grub shell prompt, if type "set", I don't see "net_pxe_mac" listed as one of the variables. šI know there is a "net_ls_addr" command which prints out something like "efinet8 3c:4a:92:b2:6a:e8 10.1.1.114", but I don't know how to use Grub scripting to parse out the MAC address. šI also don't know if there will ever be a case where "net_ls_addr" will print out multiple entries on a PXE boot, making it difficult to determine which one corresponds to the boot NIC. > > > Basically, I'm using the "ksdevice=bootif" kernel parameter when PXE booting my Red Hat kernel. šWith PXE Linux, "bootif" provides the MAC address of the boot NIC. šI was hoping to do something like "ksdevice=${net_pxe_mac}", but since "net_pxe_mac" does not appear to be getting set, I need to find some other method. > As it stands currently, net_pxe_* variables are defined on PC BIOS platform only. For UEFI (which you apparently have) GRUB2 defines net_efinetNN_* variables where efinetNN is symbolic name for interface that was used to boot GRUB2. May be GRUB2 should also define net_pxe_* namespace for the case of UEFI. There is no real way to find out which interface was used for booting and even if there were, grub does not support nested variables substitution or eval'ing (like ${net_${boot_if}_mac). Probably, adding "eval" support is really the most simple. Could you test the patch below. What it does, is - it adds "eval" command (same as known from UNIX shells) which executes its argument - it exports boot interface as "efi_boot_interface" variable This should allow you to do if $grub_platform = efi ; then eval "set net_pxe_mac=\$net_${efi_boot_interface}_mac" fi and then use $net_pxe_mac on both platforms. If it works for you, I will clean it up; for consistency this is probably needed for ieee1275 as well. --- grub-core/Makefile.core.def | 5 ++++ grub-core/commands/eval.c | 51 ++++++++++++++++++++++++++++++++++++++ grub-core/net/drivers/efi/efinet.c | 2 ++ 3 files changed, 58 insertions(+) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 7e19acb..8844f2f 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -699,6 +699,11 @@ module = { }; module = { + name = eval; + common = commands/eval.c; +}; + +module = { name = extcmd; common = commands/extcmd.c; common = lib/arg.c; diff --git a/grub-core/commands/eval.c b/grub-core/commands/eval.c new file mode 100644 index 0000000..a21ff89 --- /dev/null +++ b/grub-core/commands/eval.c @@ -0,0 +1,51 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +static grub_err_t +grub_cmd_eval (grub_extcmd_context_t ctxt __attribute__((__unused__)), + int argc, char *argv[]) +{ + char *dummy[1] = { NULL }; + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); + return grub_script_execute_sourcecode (argv[0], 0, dummy); +} + +static grub_extcmd_t cmd; + +GRUB_MOD_INIT(eval) +{ + cmd = grub_register_extcmd ("eval", grub_cmd_eval, 0, + N_("[STRING]"), N_("Evaluate commands"), + NULL); +} + +GRUB_MOD_FINI(eval) +{ + grub_unregister_extcmd (cmd); +} + diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c index 2b344d6..f7d8fd5 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -23,6 +23,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -250,6 +251,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, &pxe_mode->dhcp_ack, sizeof (pxe_mode->dhcp_ack), 1, device, path); + grub_env_set ("efi_boot_interface", card->name); return; } } -- tg: (93daf86..) e/uefi_pxe_vars (depends on: master)