Shao Miller
2012-Nov-23 01:59 UTC
[syslinux] [PATCH] nictype.c32: PXELINUX module to display UNDI NIC bus type...
Applies to Syslinux 4.06. Attached, below, and available at: Repository: git://git.zytor.com/users/sha0/syslinux.git Branch: nictype - Shao Miller ----- From 2764e260e12d9769e3b699e4213b9a164e64924a Mon Sep 17 00:00:00 2001 From: Shao Miller <sha0.miller at gmail.com> Date: Thu, 22 Nov 2012 20:43:25 -0500 Subject: [PATCH] nictype.c32: PXELINUX module to display UNDI NIC bus type... ...and optionally load a config-file based on the PCI VENdor and DEVice IDs. Usage: nictype.c32 [--config] --config will try to load a config-file with the name VVVVDDDD, where VVVV is the PCI VENdor code and DDDD is the PCI DEVice code, both for the NIC Signed-off-by: Shao Miller <sha0.miller at gmail.com> --- com32/modules/Makefile | 3 +- com32/modules/nictype.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 com32/modules/nictype.c diff --git a/com32/modules/Makefile b/com32/modules/Makefile index f110e58..10c6688 100644 --- a/com32/modules/Makefile +++ b/com32/modules/Makefile @@ -24,7 +24,8 @@ MODULES = config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \ meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \ kbdmap.c32 cmd.c32 vpdtest.c32 host.c32 ls.c32 gpxecmd.c32 \ ifcpu.c32 cpuid.c32 cat.c32 pwd.c32 ifplop.c32 zzjson.c32 \ - whichsys.c32 prdhcp.c32 pxechn.c32 kontron_wdt.c32 ifmemdsk.c32 + whichsys.c32 prdhcp.c32 pxechn.c32 kontron_wdt.c32 ifmemdsk.c32 \ + nictype.c32 TESTFILES diff --git a/com32/modules/nictype.c b/com32/modules/nictype.c new file mode 100644 index 0000000..b2a1c2a --- /dev/null +++ b/com32/modules/nictype.c @@ -0,0 +1,115 @@ +/* ------------------------------------------------------------------------- *\ + * + * Copyright 2012 Shao Miller <sha0.miller at gmail.com> - All Rights Reserved + * + * This program 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, Inc., 51 Franklin St, Fifth Floor, + * Boston MA 02110-1301, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * +\* ------------------------------------------------------------------------- */ + +/* + * nictype.c32 + * + * PXELINUX module that displays UNDI NIC bus type and optionally loads + * a config-file based on the PCI VENdor and DEVice IDs + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <console.h> +#include <syslinux/pxe.h> +#include <syslinux/boot.h> + +#undef Countof +#define Countof(array) (sizeof (array) / sizeof *(array)) + +static const char *nic_type_names[] = { + "Unknown", + "Unknown", + "PCI", + "PnP", + "CardBus", +}; + +static int usage(const char *prog); + +static const char prog_name[] = "nictype.c32"; + +int main(int argc, char **argv) +{ + int status; + t_PXENV_UNDI_GET_NIC_TYPE nic_type_info; + char filename[] = "VVVVDDDD"; + + openconsole(&dev_stdcon_r, &dev_stdcon_w); + + status = pxe_get_nic_type(&nic_type_info); + if (status == -1 || status != PXENV_STATUS_SUCCESS) { + fprintf(stderr, "pxe_get_nic_type failure\n"); + goto err_nic_type_info; + } + + /* Unknown NIC type? */ + if (nic_type_info.NicType >= Countof(nic_type_names)) + nic_type_info.NicType = 0; + + printf("NIC type: %s\n", nic_type_names[nic_type_info.NicType]); + + if (argc < 1 || argc > 2 || (argc == 2 && argv[1] && + strncmp(argv[1], "--config", + sizeof "--config"))) { + status = usage(argv[0]); + goto err_usage; + } + + if (argc == 1) { + status = EXIT_SUCCESS; + goto out; + } + + if (nic_type_info.NicType != PCI_NIC) { + fprintf(stderr, "NIC type not supported for --config\n"); + goto err_config_nic_type; + } + + status = sprintf(filename, "%04X%04X", nic_type_info.info.pci.Vendor_ID, + nic_type_info.info.pci.Dev_ID); + if (status != Countof(filename) - 1) { + fprintf(stderr, "Error constructing --config filename\n"); + status = EXIT_FAILURE; + goto err_filename; + } + + printf("Loading config-file '%s'...\n", filename); + syslinux_run_kernel_image(filename, "", 0, IMAGE_TYPE_CONFIG); + fprintf(stderr, "Failed to load config-file\n"); + status = EXIT_FAILURE; + + err_filename: + + err_config_nic_type: + + out: + + err_usage: + + err_nic_type_info: + + return status; +} + +static int usage(const char *prog) +{ + const char text[] +"Usage: %s [--config]\n" +"\n" +"--config will try to load a config-file with the name VVVVDDDD, where VVVV\n" +"is the PCI VENdor code and DDDD is the PCI DEVice code, both for the NIC\n"; + + fprintf(stderr, text, prog ? prog : prog_name); + return EXIT_FAILURE; +} -- 1.7.11.7 -------------- next part -------------->From 2764e260e12d9769e3b699e4213b9a164e64924a Mon Sep 17 00:00:00 2001From: Shao Miller <sha0.miller at gmail.com> Date: Thu, 22 Nov 2012 20:43:25 -0500 Subject: [PATCH] nictype.c32: PXELINUX module to display UNDI NIC bus type... ...and optionally load a config-file based on the PCI VENdor and DEVice IDs. Usage: nictype.c32 [--config] --config will try to load a config-file with the name VVVVDDDD, where VVVV is the PCI VENdor code and DDDD is the PCI DEVice code, both for the NIC Signed-off-by: Shao Miller <sha0.miller at gmail.com> --- com32/modules/Makefile | 3 +- com32/modules/nictype.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 com32/modules/nictype.c diff --git a/com32/modules/Makefile b/com32/modules/Makefile index f110e58..10c6688 100644 --- a/com32/modules/Makefile +++ b/com32/modules/Makefile @@ -24,7 +24,8 @@ MODULES = config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \ meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \ kbdmap.c32 cmd.c32 vpdtest.c32 host.c32 ls.c32 gpxecmd.c32 \ ifcpu.c32 cpuid.c32 cat.c32 pwd.c32 ifplop.c32 zzjson.c32 \ - whichsys.c32 prdhcp.c32 pxechn.c32 kontron_wdt.c32 ifmemdsk.c32 + whichsys.c32 prdhcp.c32 pxechn.c32 kontron_wdt.c32 ifmemdsk.c32 \ + nictype.c32 TESTFILES diff --git a/com32/modules/nictype.c b/com32/modules/nictype.c new file mode 100644 index 0000000..b2a1c2a --- /dev/null +++ b/com32/modules/nictype.c @@ -0,0 +1,115 @@ +/* ------------------------------------------------------------------------- *\ + * + * Copyright 2012 Shao Miller <sha0.miller at gmail.com> - All Rights Reserved + * + * This program 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, Inc., 51 Franklin St, Fifth Floor, + * Boston MA 02110-1301, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * +\* ------------------------------------------------------------------------- */ + +/* + * nictype.c32 + * + * PXELINUX module that displays UNDI NIC bus type and optionally loads + * a config-file based on the PCI VENdor and DEVice IDs + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <console.h> +#include <syslinux/pxe.h> +#include <syslinux/boot.h> + +#undef Countof +#define Countof(array) (sizeof (array) / sizeof *(array)) + +static const char *nic_type_names[] = { + "Unknown", + "Unknown", + "PCI", + "PnP", + "CardBus", +}; + +static int usage(const char *prog); + +static const char prog_name[] = "nictype.c32"; + +int main(int argc, char **argv) +{ + int status; + t_PXENV_UNDI_GET_NIC_TYPE nic_type_info; + char filename[] = "VVVVDDDD"; + + openconsole(&dev_stdcon_r, &dev_stdcon_w); + + status = pxe_get_nic_type(&nic_type_info); + if (status == -1 || status != PXENV_STATUS_SUCCESS) { + fprintf(stderr, "pxe_get_nic_type failure\n"); + goto err_nic_type_info; + } + + /* Unknown NIC type? */ + if (nic_type_info.NicType >= Countof(nic_type_names)) + nic_type_info.NicType = 0; + + printf("NIC type: %s\n", nic_type_names[nic_type_info.NicType]); + + if (argc < 1 || argc > 2 || (argc == 2 && argv[1] && + strncmp(argv[1], "--config", + sizeof "--config"))) { + status = usage(argv[0]); + goto err_usage; + } + + if (argc == 1) { + status = EXIT_SUCCESS; + goto out; + } + + if (nic_type_info.NicType != PCI_NIC) { + fprintf(stderr, "NIC type not supported for --config\n"); + goto err_config_nic_type; + } + + status = sprintf(filename, "%04X%04X", nic_type_info.info.pci.Vendor_ID, + nic_type_info.info.pci.Dev_ID); + if (status != Countof(filename) - 1) { + fprintf(stderr, "Error constructing --config filename\n"); + status = EXIT_FAILURE; + goto err_filename; + } + + printf("Loading config-file '%s'...\n", filename); + syslinux_run_kernel_image(filename, "", 0, IMAGE_TYPE_CONFIG); + fprintf(stderr, "Failed to load config-file\n"); + status = EXIT_FAILURE; + + err_filename: + + err_config_nic_type: + + out: + + err_usage: + + err_nic_type_info: + + return status; +} + +static int usage(const char *prog) +{ + const char text[] +"Usage: %s [--config]\n" +"\n" +"--config will try to load a config-file with the name VVVVDDDD, where VVVV\n" +"is the PCI VENdor code and DDDD is the PCI DEVice code, both for the NIC\n"; + + fprintf(stderr, text, prog ? prog : prog_name); + return EXIT_FAILURE; +} -- 1.7.11.7
Shao Miller
2012-Nov-23 20:52 UTC
[syslinux] [PATCH] nictype.c32: PXELINUX module to display UNDI NIC bus type...
On 11/22/2012 20:59, Shao Miller wrote:> Applies to Syslinux 4.06. Attached, below, and available at: > > Repository: git://git.zytor.com/users/sha0/syslinux.git > Branch: nictype >Please carbon-copy Torgeir for future discussion in this particular thread. I have updated the branch mentioned above to include a new '--fallback' feature for the '--config' option, as well as a new '--label' option. Unfortunately, the '--fallback' option cannot be used with the '--label' option at this time because trying to call a label, whether it exists or not, does not return to the caller; it terminates the COMBOOT32 module before attempting to jump to the label. Thus the fall-back will be whatever Syslinux has been given with the most recently loaded config-file's DEFAULT directive. If someone has an idea for a work-around, I'd be interested. :) Here is the new usage statement: Usage: nictype.c32 [--config | --label] [--fallback <command>] --config will try to load a config-file with the name VVVVDDDD --label will try to jump to a label with name VVVVDDDD --fallback specifies a label or command to run if --config fails VVVV is the VENdor code and DDDD is the DEVice code, for PCI and CardBus NICs. - Shao Miller