diff options
author | Lee Duncan <lduncan@suse.com> | 2022-04-01 10:15:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-01 10:15:01 -0700 |
commit | 465d051402ce0d0a2998f5c204b8bb10e5541b05 (patch) | |
tree | dd1b6a61e16cca30ffc540b4c8d2847df613cdd3 | |
parent | 4cc94655720a5c1fe3baf1cb903ed35880d505fe (diff) | |
parent | d35fd49d536c47090d6e14b66f002a6c37297d07 (diff) | |
download | open-iscsi-465d051402ce0d0a2998f5c204b8bb10e5541b05.tar.gz |
Merge pull request #328 from gonzoleeman/more-makefile-cleanup
More makefile cleanup
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | usr/.gitignore | 1 | ||||
-rw-r--r-- | usr/Makefile | 42 | ||||
-rw-r--r-- | usr/fwparam_ibft/Makefile (renamed from utils/fwparam_ibft/Makefile) | 11 | ||||
-rw-r--r-- | usr/fwparam_ibft/README | 23 | ||||
-rw-r--r-- | usr/fwparam_ibft/fw_entry.c (renamed from utils/fwparam_ibft/fw_entry.c) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/fwparam.h (renamed from utils/fwparam_ibft/fwparam.h) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/fwparam_ppc.c (renamed from utils/fwparam_ibft/fwparam_ppc.c) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/fwparam_sysfs.c (renamed from utils/fwparam_ibft/fwparam_sysfs.c) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/iscsi_obp.h (renamed from utils/fwparam_ibft/iscsi_obp.h) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/prom_lex.c (renamed from utils/fwparam_ibft/prom_lex.c) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/prom_lex.l (renamed from utils/fwparam_ibft/prom_lex.l) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/prom_parse.h (renamed from utils/fwparam_ibft/prom_parse.h) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/prom_parse.tab.c (renamed from utils/fwparam_ibft/prom_parse.tab.c) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/prom_parse.tab.h (renamed from utils/fwparam_ibft/prom_parse.tab.h) | 0 | ||||
-rw-r--r-- | usr/fwparam_ibft/prom_parse.y (renamed from utils/fwparam_ibft/prom_parse.y) | 0 | ||||
-rw-r--r-- | utils/Makefile | 4 | ||||
-rw-r--r-- | utils/fwparam_ibft/fwparam_ibft.c | 499 | ||||
-rw-r--r-- | utils/fwparam_ibft/fwparam_ibft.h | 149 |
19 files changed, 62 insertions, 671 deletions
@@ -51,7 +51,6 @@ make_utils: user: iscsiuio/Makefile $(MAKE) $(MFLAGS) -C libopeniscsiusr $(MAKE) $(MFLAGS) -C utils/sysdeps - $(MAKE) $(MFLAGS) -C utils/fwparam_ibft $(MAKE) $(MFLAGS) -C usr $(MAKE) $(MFLAGS) -C utils $(MAKE) $(MFLAGS) -C etc @@ -78,7 +77,6 @@ force: ; clean: $(MAKE) $(MFLAGS) -C utils/sysdeps clean - $(MAKE) $(MFLAGS) -C utils/fwparam_ibft clean $(MAKE) $(MFLAGS) -C utils clean $(MAKE) $(MFLAGS) -C usr clean $(MAKE) $(MFLAGS) -C etc clean @@ -125,7 +123,7 @@ install_libopeniscsiusr: $(MAKE) $(MFLAGS) -C libopeniscsiusr install depend: - for dir in usr utils utils/fwparam_ibft; do \ + for dir in usr utils utils/fwparam_ibft utils/sysdeps; do \ $(MAKE) $(MFLAGS) -C $$dir $@; \ done diff --git a/usr/.gitignore b/usr/.gitignore index 32000e2..a672448 100644 --- a/usr/.gitignore +++ b/usr/.gitignore @@ -1,3 +1,4 @@ iscsiadm iscsid iscsistart +.depend diff --git a/usr/Makefile b/usr/Makefile index 04e0bbb..41afa63 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -61,34 +61,42 @@ CFLAGS += -DISCSI_CONFIG_ROOT=\"$(HOMEDIR)\" PROGRAMS = iscsid iscsiadm iscsistart PROGRAMS_DEST = $(addprefix $(DESTDIR)$(SBINDIR)/,$(PROGRAMS)) +ISCSID_OBJS = iscsid.o session_mgmt.o discoveryd.o mntcheck.o +ISCSIADM_OBJS = iscsiadm.o session_mgmt.o mntcheck.o +ISCSISTART_OBJS = iscsistart.o statics.o + # libc compat files -SYSDEPS_SRCS = $(sort $(wildcard ../utils/sysdeps/*.o)) +SYSDEPS_DIR = $(TOPDIR)/utils/sysdeps +SYSDEPS_OBJS = $(SYSDEPS_DIR)/sysdeps.o # sources shared between iscsid, iscsiadm and iscsistart -ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o iscsi_timer.o login.o log.o \ +ISCSI_LIB_OBJS = iscsi_util.o io.o auth.o iscsi_timer.o login.o log.o \ iface.o idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o \ iscsi_net_util.o iscsid_req.o transport.o iser.o cxgbi.o be2iscsi.o \ initiator_common.o iscsi_err.o flashnode.o uip_mgmt_ipc.o \ - netlink.o $(SYSDEPS_SRCS) + netlink.o # core initiator files -INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o kern_err_table.o +INITIATOR_OBJS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o kern_err_table.o # fw boot files -FW_BOOT_SRCS = $(sort $(wildcard ../utils/fwparam_ibft/*.o)) +FW_BOOT_DIR = fwparam_ibft +FW_BOOT_OBJ_FILES = fw_entry.o fwparam_sysfs.o prom_lex.o prom_parse.tab.o fwparam_ppc.o +FW_BOOT_OBJS = $(addprefix $(FW_BOOT_DIR)/,$(FW_BOOT_OBJ_FILES)) # core discovery files -DISCOVERY_SRCS = $(FW_BOOT_SRCS) local_strings.o discovery.o +DISCOVERY_OBJS = local_strings.o discovery.o all: $(PROGRAMS) -iscsid: $(ISCSI_LIB_SRCS) $(INITIATOR_SRCS) $(DISCOVERY_SRCS) \ - iscsid.o session_mgmt.o discoveryd.o mntcheck.o +iscsid: $(ISCSI_LIB_OBJS) $(SYSDEPS_OBJS) $(INITIATOR_OBJS) $(DISCOVERY_OBJS) $(FW_BOOT_OBJS) \ + $(ISCSID_OBJS) $(CC) $(CFLAGS) $^ -o $@ -lisns -lcrypto -lrt -lmount $(LDFLAGS) $(ISCSI_LIB) -iscsiadm: $(ISCSI_LIB_SRCS) $(DISCOVERY_SRCS) iscsiadm.o session_mgmt.o mntcheck.o +iscsiadm: $(ISCSI_LIB_OBJS) $(SYSDEPS_OBJS) $(DISCOVERY_OBJS) $(FW_BOOT_OBJS) \ + $(ISCSIADM_OBJS) $(CC) $(CFLAGS) $^ -o $@ -lisns -lcrypto -lmount $(LDFLAGS) $(ISCSI_LIB) -iscsistart: $(ISCSI_LIB_SRCS) $(INITIATOR_SRCS) $(FW_BOOT_SRCS) \ - iscsistart.o statics.o +iscsistart: $(ISCSI_LIB_OBJS) $(SYSDEPS_OBJS) $(INITIATOR_OBJS) $(FW_BOOT_OBJS) \ + $(ISCSISTART_OBJS) $(CC) $(CFLAGS) $^ -o $@ -lcrypto -lrt $(LDFLAGS) $(ISCSI_LIB) install: $(DESTDIR)$(SBINDIR) $(PROGRAMS_DEST) @@ -99,10 +107,20 @@ $(DESTDIR)$(SBINDIR): $(PROGRAMS_DEST): $(DESTDIR)$(SBINDIR)/%: % $(INSTALL) -m 755 $? $@ +$(SYSDEPS_OBJS): + $(MAKE) $(MFLAGS) -C $(SYSDEPS_DIR) + +$(FW_BOOT_OBJS): + $(MAKE) $(MFLAGS) -C $(FW_BOOT_DIR) + clean: - rm -f *.o $(PROGRAMS) .depend $(LIBSYS) + $(RM) $(ISCSI_LIB_OBJS) $(INITIATOR_OBJS) $(DISCOVERY_OBJS) \ + $(ISCSISTART_OBJS) $(ISCSID_OBJS) $(ISCSIADM_OBJS) \ + $(PROGRAMS) .depend + $(MAKE) $(MFLAGS) -C $(FW_BOOT_DIR) clean depend: gcc $(CFLAGS) -M `ls *.c` > .depend + $(MAKE) $(MFLAGS) -C $(FW_BOOT_DIR) depend -include .depend diff --git a/utils/fwparam_ibft/Makefile b/usr/fwparam_ibft/Makefile index c27ba40..6739f41 100644 --- a/utils/fwparam_ibft/Makefile +++ b/usr/fwparam_ibft/Makefile @@ -27,10 +27,9 @@ endif SBINDIR ?= $(DESTDIR)/sbin SYSDEPS_OBJS = $(sort $(wildcard ../sysdeps/*.o)) -OBJS := fw_entry.o fwparam_sysfs.o $(SYSDEPS_OBJS) \ - $(TOPDIR)/usr/iscsi_net_util.o -OBJS += prom_lex.o prom_parse.tab.o fwparam_ppc.o -CLEANFILES = $(OBJS) *.output *~ +OBJS := fw_entry.o fwparam_sysfs.o \ + prom_lex.o prom_parse.tab.o fwparam_ppc.o +CLEANFILES = $(OBJS) *.output CFLAGS ?= -O2 -g WARNFLAGS ?= -Wall -Wstrict-prototypes -Wno-format-truncation @@ -43,9 +42,9 @@ LDFLAGS += -L$(TOPDIR)/libopeniscsiusr -liscsiusr all: $(OBJS) clean: - rm -f *.o $(CLEANFILES) .depend + rm -f $(CLEANFILES) .depend -$(OBJS): prom_parse.tab.h prom_parse.h fwparam_ibft.h +$(OBJS): prom_parse.tab.h prom_parse.h depend: gcc $(CFLAGS) -M `ls *.c` > .depend diff --git a/usr/fwparam_ibft/README b/usr/fwparam_ibft/README new file mode 100644 index 0000000..f040493 --- /dev/null +++ b/usr/fwparam_ibft/README @@ -0,0 +1,23 @@ +The files in this directory are used by +iscsi programs in "usr" to access and parse +the iBFT data. + +This code uses bison/lex to parse the data, +but at some point it was decided to check in +the output files from bison and flex, so that +the average source-code user would not have +to run those tools to compile the code. + +Now it is likely that most folks can get those +tools, but the system of having static +parsing and lexical analysis has worked for +so long (and isn't broken), it would be a +shame to change and break it. So the static +files remain, for now. + +Note: if you wish to use these object files, +they have two external requirements: they +need the compatability routines in sysdeps.o, +and they need the file iscsi_net_util.o. + +Lee Duncan Mar, 2022 diff --git a/utils/fwparam_ibft/fw_entry.c b/usr/fwparam_ibft/fw_entry.c index 96af145..96af145 100644 --- a/utils/fwparam_ibft/fw_entry.c +++ b/usr/fwparam_ibft/fw_entry.c diff --git a/utils/fwparam_ibft/fwparam.h b/usr/fwparam_ibft/fwparam.h index 141def7..141def7 100644 --- a/utils/fwparam_ibft/fwparam.h +++ b/usr/fwparam_ibft/fwparam.h diff --git a/utils/fwparam_ibft/fwparam_ppc.c b/usr/fwparam_ibft/fwparam_ppc.c index da9d76e..da9d76e 100644 --- a/utils/fwparam_ibft/fwparam_ppc.c +++ b/usr/fwparam_ibft/fwparam_ppc.c diff --git a/utils/fwparam_ibft/fwparam_sysfs.c b/usr/fwparam_ibft/fwparam_sysfs.c index 87fd6d4..87fd6d4 100644 --- a/utils/fwparam_ibft/fwparam_sysfs.c +++ b/usr/fwparam_ibft/fwparam_sysfs.c diff --git a/utils/fwparam_ibft/iscsi_obp.h b/usr/fwparam_ibft/iscsi_obp.h index 8580052..8580052 100644 --- a/utils/fwparam_ibft/iscsi_obp.h +++ b/usr/fwparam_ibft/iscsi_obp.h diff --git a/utils/fwparam_ibft/prom_lex.c b/usr/fwparam_ibft/prom_lex.c index c8ed9cb..c8ed9cb 100644 --- a/utils/fwparam_ibft/prom_lex.c +++ b/usr/fwparam_ibft/prom_lex.c diff --git a/utils/fwparam_ibft/prom_lex.l b/usr/fwparam_ibft/prom_lex.l index e70c790..e70c790 100644 --- a/utils/fwparam_ibft/prom_lex.l +++ b/usr/fwparam_ibft/prom_lex.l diff --git a/utils/fwparam_ibft/prom_parse.h b/usr/fwparam_ibft/prom_parse.h index 00cffff..00cffff 100644 --- a/utils/fwparam_ibft/prom_parse.h +++ b/usr/fwparam_ibft/prom_parse.h diff --git a/utils/fwparam_ibft/prom_parse.tab.c b/usr/fwparam_ibft/prom_parse.tab.c index 6275961..6275961 100644 --- a/utils/fwparam_ibft/prom_parse.tab.c +++ b/usr/fwparam_ibft/prom_parse.tab.c diff --git a/utils/fwparam_ibft/prom_parse.tab.h b/usr/fwparam_ibft/prom_parse.tab.h index 4897b23..4897b23 100644 --- a/utils/fwparam_ibft/prom_parse.tab.h +++ b/usr/fwparam_ibft/prom_parse.tab.h diff --git a/utils/fwparam_ibft/prom_parse.y b/usr/fwparam_ibft/prom_parse.y index efe1578..efe1578 100644 --- a/utils/fwparam_ibft/prom_parse.y +++ b/usr/fwparam_ibft/prom_parse.y diff --git a/utils/Makefile b/utils/Makefile index 250b77e..01f7e0b 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -2,8 +2,8 @@ # # Make file for the util sub-directory # -# This make file does not control the fwparam_ibft -# or sysdeps subdirectories. Those are still controlled +# This make file does not control the sysdeps +# subdirectory, which is controlled # from the top-level make file. # diff --git a/utils/fwparam_ibft/fwparam_ibft.c b/utils/fwparam_ibft/fwparam_ibft.c deleted file mode 100644 index e68e503..0000000 --- a/utils/fwparam_ibft/fwparam_ibft.c +++ /dev/null @@ -1,499 +0,0 @@ -/* - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * Copyright (C) IBM Corporation, 2006 - * - * Authors: Patrick Mansfield <patmans@us.ibm.com> - * Mike Anderson <andmike@us.ibm.com> - * - */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include "fwparam_ibft.h" -#include "fw_context.h" - -char *progname = "fwparam_ibft"; -int debug; -int dev_count; -char filename[FILENAMESZ]; - -const char nulls[16]; /* defaults to zero */ - -int -verify_hdr(char *name, struct ibft_hdr *hdr, int id, int version, int length) -{ -#define VERIFY_HDR_FIELD(val) \ - if (hdr->val != val) { \ - fprintf(stderr, \ - "%s: error, %s structure expected %s %d but" \ - " got %d\n", \ - progname, name, #val, hdr->val, val); \ - return -1; \ - } - - if (debug > 1) - fprintf(stderr, "%s: verifying %s header\n", __FUNCTION__, - name); - - VERIFY_HDR_FIELD(id); - VERIFY_HDR_FIELD(version); - VERIFY_HDR_FIELD(length); - -#undef VERIFY_HDR_FIELD - return 0; -} - -#define CHECK_HDR(ident, name) \ - verify_hdr(#name, &ident->hdr, id_##name, version_##name, \ - sizeof(*ident)) - -/* - * Format 8 byte scsi LUN. Just format 8 bytes of hex, we could also - * format in the format as specified in rfc4173 (1-2-3-4, or 1-2), that is - * a nice format for humans :) - */ -void -format_lun(char *buf, size_t size, uint8_t *lun) -{ - int i; - - for (i = 0; i < 8; i++) - snprintf(buf++, size--, "%x", lun[i]); -} - -void -dump_lun(char *prefix, char *id, uint8_t *lun) -{ - char buf[32]; - - format_lun(buf, sizeof(buf), lun); - - if (prefix) - printf("%s%s=%s\n", prefix, id, buf); - else - printf("%s=%s\n", id, buf); - -} - -void -dump_word(char *prefix, char *id, unsigned short value) -{ - if (prefix) - printf("%s%s=%d\n", prefix, id, value); - else - printf("%s=%d\n", id, value); -} - -void -dump_string(char *prefix, char *id, char *value, int len) -{ - if (len == 0) - return; - /* - * Not checking if the offset is non-zero, it is not even passed - * in, else we need to pass a start and offset rather than value. - */ - - /* - * prints the string in "value" that has "len" characters (the - * printf "*" * means use the next argument as the length). - */ - if (prefix) - printf("%s%s=%.*s\n", prefix, id, len, value); - else - printf("%s=%.*s\n", id, len, value); -} - -void -format_ipaddr(char *buf, size_t size, uint8_t *ip) -{ - if (ip[0] == 0 && ip[1] == 0 && ip[2] == 0 && ip[3] == 0 && - ip[4] == 0 && ip[5] == 0 && ip[6] == 0 && ip[7] == 0 && - ip[8] == 0 && ip[9] == 0 && ip[10] == 0xff && ip[11] == 0xff) { - /* - * IPV4 - */ - snprintf(buf, size, "%d.%d.%d.%d", ip[12], ip[13], ip[14], ip[15]); - } else { - /* XXX ... */ - fprintf(stderr, "%s: warning no IPV6 support.\n", progname); - buf[0] = '\0'; - return; - } - -} - -/* - * Dump the 16 byte ipaddr, as IPV6 or IPV4. - */ -void -dump_ipaddr(char *prefix, char *id, uint8_t *ip) -{ - char buf[32]; - - /* - * Assumes all zero means no IP address. - */ - if (!memcmp(ip, nulls, sizeof(nulls))) - return; - - format_ipaddr(buf, sizeof(buf), ip); - - if (prefix) - printf("%s%s=%s\n", prefix, id, buf); - else - printf("%s=%s\n", id, buf); - -} - -/* - * Dump the 8 byte mac address - */ -void -dump_mac(char *prefix, char *id, uint8_t *mac) -{ - int i; - - if (prefix) - printf("%s%s=", prefix, id); - else - printf("%s=", id); - - for (i = 0; i < 5; i++) - printf("%02x:", mac[i]); - printf("%02x\n", mac[i]); -} - - -void -dump_initiator_prefix(void *ibft_loc, struct ibft_initiator *initiator, char *prefix) -{ - if (!initiator) - return; - /* - * Not all fields are (or were) supported by open-iscsi. Plus, - * some of these are for discovery. - */ - dump_ipaddr(prefix, "ISNS", initiator->isns_server); - dump_ipaddr(prefix, "SLP", initiator->slp_server); - dump_ipaddr(prefix, "PRIMARY_RADIUS_SERVER", initiator->pri_radius_server); - dump_ipaddr(prefix, "SECONDARY_RADIUS_SERVER", initiator->sec_radius_server); - dump_string(prefix, "NAME", ibft_loc + - initiator->initiator_name_off, initiator->initiator_name_len); -} - -void -dump_nic_prefix(void *ibft_loc, struct ibft_nic *nic, char *prefix) -{ - - if (!nic) - return; - - dump_mac(prefix, "HWADDR", nic->mac); - /* - * Assume dhcp if any non-zero portions of its address are set - * (again, undocumented). - */ - if (memcmp(nic->dhcp, nulls, sizeof(nic->dhcp))) { - dump_ipaddr(prefix, "DHCP", nic->dhcp); - } else { - dump_ipaddr(prefix, "IPADDR", nic->ip_addr); - /* - * XXX: Not sure how a mask "prefix" will be used in network - * bringup, this sounds less flexible than the normal - * masks used. - */ - printf("%s%s=%d\n", prefix, "MASK", nic->subnet_mask_prefix); - dump_ipaddr(prefix, "GATEWAY", nic->gateway); - dump_ipaddr(prefix, "DNSADDR1", nic->primary_dns); - dump_ipaddr(prefix, "DNSADDR2", nic->secondary_dns); - } - - dump_string(prefix, "HOSTNAME", ibft_loc + nic->hostname_off, - nic->hostname_len); - /* - * XXX unknown vlan: - */ - dump_word(prefix, "VLAN", nic->vlan); - /* - * XXX sort of unknown pci_bdf: 8 bits bus, 5 bits device, 3 bits - * function. - */ - if (prefix ) - printf("%s%s=%d:%d:%d\n", prefix, "PCI_BDF", - /* bus */ (nic->pci_bdf & 0xff00) >> 8, - /* device */ (nic->pci_bdf & 0xf8) >> 3, - /* function */ (nic->pci_bdf & 0x07)); - else - printf("%s=%d:%d:%d\n", "PCI_BDF", - /* bus */ (nic->pci_bdf & 0xff00) >> 8, - /* device */ (nic->pci_bdf & 0xf8) >> 3, - /* function */ (nic->pci_bdf & 0x07)); -} - -void -dump_tgt_prefix(void *ibft_loc, struct ibft_tgt *tgt, char *prefix) -{ - - if (!tgt) - return; - - dump_ipaddr(prefix, "IPADDR", tgt->ip_addr); - dump_word(prefix, "PORT", tgt->port); - /* - * XXX there should at least be a "no LUN specified field", or - * have different location objects, so the setup can search for - * the appropriate LU (like mount by label, or use of the - * /dev/disk/by-id names, or .... - * - * Like: - * uint8_t lu_type; 0: nothing specified, 1: LUN, 2: misc - * name - OS can use any way it wants, would have embedded a - * "NAME=string", like "LABEL=myrootvolume", or - * "DEV_NAME=/dev/disk/by-id/scsi-198279562093043094003030903". - * union lu_value { - * uint8_t lun[8]; - * uint8_t misc_name[64]; - * }; - * - * Maybe just add an extension header, and let the admin/user put - * strings like: "area:VALUE=string" into it? - */ - dump_lun(prefix, "LUN", tgt->lun); - dump_string(prefix, "NAME", ibft_loc + tgt->tgt_name_off, - tgt->tgt_name_len); - /* - * Note: don't dump the nic association, just let the IP address take - * care of the routing. - */ - /* - * Note: don't dump the chap "type", just the chap names and secrets - * if any are specified - they imply CHAP and reversed CHAP. - */ - dump_string(prefix, "CHAP_NAME", ibft_loc + tgt->chap_name_off, - tgt->chap_name_len); - dump_string(prefix, "CHAP_PASSWORD", ibft_loc + tgt->chap_secret_off, - tgt->chap_secret_len); - dump_string(prefix, "CHAP_NAME_IN", ibft_loc + tgt->rev_chap_name_off, - tgt->rev_chap_name_len); - dump_string(prefix, "CHAP_PASSWORD_IN", - ibft_loc + tgt->rev_chap_secret_off, - tgt->rev_chap_secret_len); -} - -/* - * Read in and dump ASCII output for ibft starting at ibft_loc. - */ -int -dump_ibft(void *ibft_loc, struct boot_context *context) -{ - struct ibft_table_hdr *ibft_hdr = ibft_loc; - struct ibft_control *control; - struct ibft_initiator *initiator = NULL; - struct ibft_nic *nic0 = NULL, *nic1 = NULL; - struct ibft_tgt *tgt0 = NULL, *tgt1 = NULL; - char ipbuf[32]; - - control = ibft_loc + sizeof(*ibft_hdr); - CHECK_HDR(control, control); - - /* - * The ibft is setup to return multiple pieces for each - * object (like multiple nic's or multiple targets), but it only - * maps 1 initiator, two targets, and two nics, follow that layout - * here (i.e. don't search for others). - * - * Also, unknown what to do for extensions piece, it is not - * documented. - */ - - if (control->initiator_off) { - initiator = ibft_loc + control->initiator_off; - CHECK_HDR(initiator, initiator); - } - - if (control->nic0_off) { - nic0 = ibft_loc + control->nic0_off; - CHECK_HDR(nic0, nic); - } - - if (control->nic1_off) { - nic1 = ibft_loc + control->nic1_off; - CHECK_HDR(nic1, nic); - } - - if (control->tgt0_off) { - tgt0 = ibft_loc + control->tgt0_off; - CHECK_HDR(tgt0, target); - } - - if (control->tgt1_off) { - tgt1 = ibft_loc + control->tgt1_off; - CHECK_HDR(tgt1, target); - } - - strlcpy(context->initiatorname, - (char *)ibft_loc+initiator->initiator_name_off, - initiator->initiator_name_len + 1); - - if (tgt0 && (tgt0->hdr.flags & INIT_FLAG_FW_SEL_BOOT)) { - strlcpy((char *)context->targetname, - (char *)(ibft_loc+tgt0->tgt_name_off), - tgt0->tgt_name_len); - format_ipaddr(ipbuf, sizeof(ipbuf), - tgt0->ip_addr); - strlcpy((char *)context->target_ipaddr, ipbuf, - sizeof(ipbuf)); - context->target_port = tgt0->port; - strlcpy(context->chap_name, - (char *)(ibft_loc + tgt0->chap_name_off), - tgt0->chap_name_len); - strlcpy(context->chap_password, - (char*)(ibft_loc + tgt0->chap_secret_off), - tgt0->chap_secret_len); - strlcpy(context->chap_name_in, - (char *)(ibft_loc + tgt0->rev_chap_name_off), - tgt0->rev_chap_name_len); - strlcpy(context->chap_password_in, - (char *)(ibft_loc + tgt0->rev_chap_secret_off), - tgt0->rev_chap_secret_len); - } else if (tgt1 && - (tgt1->hdr.flags & INIT_FLAG_FW_SEL_BOOT)) { - strlcpy((char *)context->targetname, - (char *)(ibft_loc+tgt1->tgt_name_off), - tgt1->tgt_name_len); - format_ipaddr(ipbuf, sizeof(ipbuf), - tgt1->ip_addr); - strlcpy((char *)context->target_ipaddr,ipbuf, - sizeof(ipbuf)); - context->target_port = tgt1->port; - strlcpy(context->chap_name, - (char *)(ibft_loc + tgt1->chap_name_off), - tgt1->chap_name_len); - strlcpy(context->chap_password, - (char*)(ibft_loc + tgt1->chap_secret_off), - tgt1->chap_secret_len); - strlcpy(context->chap_name_in, - (char *)(ibft_loc + tgt1->rev_chap_name_off), - tgt1->rev_chap_name_len); - strlcpy(context->chap_password_in, - (char *)(ibft_loc + tgt1->rev_chap_secret_off), - tgt1->rev_chap_secret_len); - } - - return 0; -} - -char *search_ibft(unsigned char *start, int length) -{ - unsigned char *cur_ptr; - struct ibft_table_hdr *ibft_hdr; - unsigned char check_sum; - uint32_t i; - - cur_ptr = (unsigned char *)start; - for (cur_ptr = (unsigned char *)start; - cur_ptr < (start + length); - cur_ptr++) { - if (memcmp(cur_ptr, iBFTSTR,strlen(iBFTSTR))) - continue; - - ibft_hdr = (struct ibft_table_hdr *)cur_ptr; - /* Make sure it's correct version. */ - if (ibft_hdr->revision != iBFT_REV) - continue; - - /* Make sure that length is valid. */ - if ((cur_ptr + ibft_hdr->length) <= (start + length)) { - /* Let verify the checksum */ - for (i = 0, check_sum = 0; i < ibft_hdr->length; i++) - check_sum += cur_ptr[i]; - - if (check_sum == 0) - return (char *)cur_ptr; - } - } - return NULL; -} - -int -fwparam_ibft(struct boot_context *context, const char *filepath) -{ - int fd, ret; - char *filebuf, *ibft_loc; - int start = 512 * 1024; /* 512k */ - int end_search = (1024 * 1024) - start; /* 512k */ - struct stat buf; - - if (filepath) - strlcpy(filename, filepath, FILENAMESZ); - else - strlcpy(filename, X86_DEFAULT_FILENAME, FILENAMESZ); - - fd = open(filename, O_RDONLY); - if (fd < 0) { - fprintf(stderr, "Could not open %s: %s (%d)\n", - filename, strerror(errno), errno); - return -1; - } - - /* Find the size. */ - if (stat(filename, &buf)!=0) { - fprintf(stderr, "Could not stat file %s: %s (%d)\n", - filename, strerror(errno), errno); - close(fd); - return -1; - } - /* And if not zero use that size */ - if (buf.st_size > 0) { - start = 0; - end_search=buf.st_size; - } - /* - * XXX Possibly warn and exit if start > filesize(fd), or if start + - * end_search > filesize(fd). Else, we will get a bus error for - * small files (with memmap, and for testing at least, it would - * be hard to find a system with less than 1024k). - */ - filebuf = mmap(NULL, end_search, PROT_READ, MAP_PRIVATE, fd, start); - if (filebuf == MAP_FAILED) { - fprintf(stderr, "Could not mmap %s: %s (%d)\n", - filename, strerror(errno), errno); - ret = -1; - goto done; - } - - ibft_loc = search_ibft((unsigned char *)filebuf, end_search); - if (ibft_loc) - ret = dump_ibft(ibft_loc, context); - else { - printf("Could not find iBFT.\n"); - ret = -1; - } - munmap(filebuf, end_search); -done: - close(fd); - return ret; -} diff --git a/utils/fwparam_ibft/fwparam_ibft.h b/utils/fwparam_ibft/fwparam_ibft.h deleted file mode 100644 index 92968b3..0000000 --- a/utils/fwparam_ibft/fwparam_ibft.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * Copyright (C) IBM Corporation, 2006,2007 - * - * Authors: Doug Maxey <dwm@austin.ibm.com> - * Patrick Mansfield <patmans@us.ibm.com> - * - */ - -#ifndef FWPARAM_IBFT_H_ -#define FWPARAM_IBFT_H_ - -/* #include <sys/types.h> */ -#include <stdint.h> -#include "fw_context.h" - -/* - * Structures here are is based on Doug's original code, and Patrick's - * interpretation of the IBM internal design document title the "iSCSI - * Boot Firmware Table (iBFT)". - */ -#define iBFTSTR "iBFT" -#define iBFT_SIG { 'i','B','F','T' } - -#define iBFT_REV 1 - -/* - * These macros are lower case to make the verify_hdr macro easier. - */ -#define version_control 1 -#define version_initiator 1 -#define version_nic 1 -#define version_target 1 -#define version_extensions 1 - -enum ibft_id { - id_control = 1, - id_initiator, - id_nic, - id_target, - id_extensions, -}; - -struct ibft_hdr { - uint8_t id; - uint8_t version; - uint16_t length; - uint8_t ind; - uint8_t flags; -}; - -struct ibft_table_hdr { - uint8_t signature[4]; - uint32_t length; - uint8_t revision; - uint8_t checksum; - uint8_t oemid[6]; - uint8_t oem_table_id[8]; - uint8_t rsvd1[24]; -} __attribute__((__packed__)); - -struct ibft_control { - struct ibft_hdr hdr; - uint16_t extensions; - uint16_t initiator_off; - uint16_t nic0_off; - uint16_t tgt0_off; - uint16_t nic1_off; - uint16_t tgt1_off; -} __attribute__((__packed__)); - -struct ibft_initiator { -#define INIT_FLAG_VALID 1 -#define INIT_FLAG_FW_SEL_BOOT 2 - struct ibft_hdr hdr; - uint8_t isns_server[16]; - uint8_t slp_server[16]; - uint8_t pri_radius_server[16]; - uint8_t sec_radius_server[16]; - uint16_t initiator_name_len; - uint16_t initiator_name_off; -} __attribute__((__packed__)); - -struct ibft_nic { -#define NIC_FLAG_VALID 1 -#define NIC_FLAG_FW_SEL_BOOT 2 - struct ibft_hdr hdr; - uint8_t ip_addr[16]; - uint8_t subnet_mask_prefix; - uint8_t origin; - uint8_t gateway[16]; - uint8_t primary_dns[16]; - uint8_t secondary_dns[16]; - uint8_t dhcp[16]; - uint16_t vlan; - uint8_t mac[6]; - uint16_t pci_bdf; - uint16_t hostname_len; - uint16_t hostname_off; -} __attribute__((__packed__)); - -struct ibft_tgt { -#define TGT_FLAG_VALID 1 -#define TGT_FLAG_FW_SEL_BOOT 2 -#define TGT_FLAG_USE_RADIUS_CHAT 4 -#define TGT_FLAG_USE_RADIUS_RCHAT 8 - struct ibft_hdr hdr; - uint8_t ip_addr[16]; - uint16_t port; - uint8_t lun[8]; -#define TGT_CHAP 1 -#define TGT_MUTUAL_CHAP 2 - uint8_t chap_type; - uint8_t nic_assoc; - uint16_t tgt_name_len; - uint16_t tgt_name_off; - uint16_t chap_name_len; - uint16_t chap_name_off; - uint16_t chap_secret_len; - uint16_t chap_secret_off; - uint16_t rev_chap_name_len; - uint16_t rev_chap_name_off; - uint16_t rev_chap_secret_len; - uint16_t rev_chap_secret_off; -} __attribute__((__packed__)); - -/* Common variables */ -#define FILENAMESZ (1024) -extern char filename[FILENAMESZ]; -#define X86_DEFAULT_FILENAME "/dev/mem" -extern int debug; -extern int dev_count; - -extern int fwparam_ibft(struct boot_context *context, const char *filepath); -#endif /* FWPARAM_IBFT_H_ */ |