summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--include/fw_context.h46
-rw-r--r--usr/Makefile10
-rw-r--r--usr/config.h1
-rw-r--r--usr/idbm.c21
-rw-r--r--usr/iscsiadm.c97
-rw-r--r--usr/iscsistart.c46
-rw-r--r--utils/fwparam_ibft/fw_entry.c36
-rw-r--r--utils/fwparam_ibft/fwparam_ibft.c152
-rw-r--r--utils/fwparam_ibft/fwparam_ibft.h18
10 files changed, 329 insertions, 101 deletions
diff --git a/Makefile b/Makefile
index 16ef1df..70986b1 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,6 @@ all:
$(MAKE) -C usr
$(MAKE) -C kernel
$(MAKE) -C utils
- $(MAKE) -C utils/fwparam_ibft
@echo
@echo "Compilation complete Output file"
@echo "----------------------------------- ----------------"
@@ -38,7 +37,6 @@ all:
@echo "Built iSCSI over TCP kernel module: kernel/iscsi_tcp.ko"
@echo "Built iSCSI daemon: usr/iscsid"
@echo "Built management application: usr/iscsiadm"
- @echo "Built utility: utils/fwparam_ibft/fwparam_ibft"
@echo
@echo Read README file for detailed information.
@@ -46,7 +44,6 @@ clean:
$(MAKE) -C utils clean
$(MAKE) -C usr clean
$(MAKE) -C kernel clean
- $(MAKE) -C utils/fwparam_ibft clean
# this is for safety
# now -jXXX will still be safe
diff --git a/include/fw_context.h b/include/fw_context.h
new file mode 100644
index 0000000..4307509
--- /dev/null
+++ b/include/fw_context.h
@@ -0,0 +1,46 @@
+/*
+ * 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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * Copyright (C) IBM Corporation. 2007
+ * Author: Doug Maxey <dwm@austin.ibm.com>
+ * "Prasanna Mumbai" <mumbai.prasanna@gmail.com>
+ *
+ */
+#ifndef FWPARAM_CONTEXT_H_
+#define FWPARAM_CONTEXT_H_
+
+struct boot_context {
+#define IQNSZ (223)
+ int target_port;
+ char initiatorname[IQNSZ];
+ char targetname[IQNSZ];
+ char target_ipaddr[32];
+ char chap_name[127];
+ char chap_password[16];
+ char chap_name_in[127];
+ char chap_password_in[16];
+ char mac[16];
+ char iface[42];
+ char lun[17];
+ char vlan[15];
+ char isid[10];
+};
+
+int fw_entry_init(struct boot_context *context, int option);
+
+#define FW_CONNECT 0
+#define FW_PRINT 1
+
+#endif /* FWPARAM_CONTEXT_H_ */
diff --git a/usr/Makefile b/usr/Makefile
index eed5c77..821d7fc 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -39,21 +39,23 @@ ISCSI_LIB_SRCS = util.o io.o auth.o login.o log.o md5.o sha1.o iscsi_sysfs.o idb
COMMON_SRCS = $(ISCSI_LIB_SRCS)
# core initiator files
INITIATOR_SRCS = initiator.o scsi.o actor.o mgmt_ipc.o isns.o transport.o
+# fw boot files
+FW_BOOT_SRCS = $(addprefix ../utils/fwparam_ibft/, fw_entry.o fwparam_ibft.o)
all: $(PROGRAMS)
iscsid: $(COMMON_SRCS) $(IPC_OBJ) $(INITIATOR_SRCS) iscsid.o
$(CC) $(CFLAGS) $^ -o $@
-iscsiadm: $(COMMON_SRCS) strings.o discovery.o iscsiadm.o
+iscsiadm: $(COMMON_SRCS) $(FW_BOOT_SRCS) strings.o discovery.o iscsiadm.o
$(CC) $(CFLAGS) $^ -o $@
-iscsistart: $(IPC_OBJ) $(ISCSI_LIB_SRCS) $(INITIATOR_SRCS) iscsistart.o \
- statics.o
+iscsistart: $(IPC_OBJ) $(ISCSI_LIB_SRCS) $(INITIATOR_SRCS) $(FW_BOOT_SRCS) \
+ iscsistart.o statics.o
$(CC) $(CFLAGS) -static $^ -o $@
clean:
- rm -f *.o $(PROGRAMS) .depend
+ rm -f *.o $(PROGRAMS) ../utils/fwparam_ibft/*.o .depend
depend:
gcc $(CFLAGS) -M `ls *.c` > .depend
diff --git a/usr/config.h b/usr/config.h
index 493be42..8c36735 100644
--- a/usr/config.h
+++ b/usr/config.h
@@ -158,6 +158,7 @@ typedef enum discovery_type {
DISCOVERY_TYPE_SLP,
DISCOVERY_TYPE_ISNS,
DISCOVERY_TYPE_STATIC,
+ DISCOVERY_TYPE_FWBOOT,
} discovery_type_e;
typedef struct conn_rec {
diff --git a/usr/idbm.c b/usr/idbm.c
index f63e5b4..697b172 100644
--- a/usr/idbm.c
+++ b/usr/idbm.c
@@ -100,6 +100,17 @@
_n++; \
} while(0)
+#define __recinfo_int_o6(_key,_info,_rec,_name,_show,_op0,_op1,_op2,\
+ _op3,_op4,_op5,_n)\
+do{\
+ __recinfo_int_o5(_key,_info,_rec,_name,_show,_op0,_op1,_op2,_op3,\
+ _op4,_n); _n--; \
+ if (_rec->_name == 5) strncpy(_info[_n].value, _op5, VALUE_MAXVAL); \
+ _info[_n].opts[5] = _op5; \
+ _info[_n].numopts = 6; \
+ _n++; \
+} while(0)
+
/*
* from linux kernel
*/
@@ -126,7 +137,7 @@ static char *strstrip(char *s)
static char *get_global_string_param(char *pathname, const char *key)
{
FILE *f = NULL;
- int c, len;
+ int len;
char *line, buffer[1024];
char *name = NULL;
@@ -184,9 +195,9 @@ idbm_recinfo_discovery(discovery_rec_t *r, recinfo_t *ri)
__recinfo_int_o2("discovery.startup", ri, r, startup, IDBM_SHOW,
"manual", "automatic", num);
- __recinfo_int_o5("discovery.type", ri, r, type, IDBM_SHOW,
+ __recinfo_int_o6("discovery.type", ri, r, type, IDBM_SHOW,
"sendtargets", "offload_send_targets", "slp", "isns",
- "static", num);
+ "static", "fwboot", num);
if (r->type == DISCOVERY_TYPE_SENDTARGETS) {
__recinfo_str("discovery.sendtargets.address", ri, r,
address, IDBM_SHOW, num);
@@ -256,9 +267,9 @@ idbm_recinfo_node(node_rec_t *r, recinfo_t *ri)
__recinfo_str("node.discovery_address", ri, r, disc_address, IDBM_SHOW,
num);
__recinfo_int("node.discovery_port", ri, r, disc_port, IDBM_SHOW, num);
- __recinfo_int_o5("node.discovery_type", ri, r, disc_type,
+ __recinfo_int_o6("node.discovery_type", ri, r, disc_type,
IDBM_SHOW, "send_targets", "offload_send_targets",
- "slp", "isns", "static", num);
+ "slp", "isns", "static", "fwboot", num);
__recinfo_int("node.session.initial_cmdsn", ri, r,
session.initial_cmdsn, IDBM_SHOW, num);
__recinfo_int("node.session.initial_login_retry_max", ri, r,
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
index 911edf8..a40c730 100644
--- a/usr/iscsiadm.c
+++ b/usr/iscsiadm.c
@@ -39,6 +39,7 @@
#include "iscsi_sysfs.h"
#include "list.h"
#include "iscsi_settings.h"
+#include "fw_context.h"
struct iscsi_ipc *ipc = NULL; /* dummy */
static char program_name[] = "iscsiadm";
@@ -155,6 +156,8 @@ str_to_type(char *str)
type = DISCOVERY_TYPE_SLP;
else if (!strcmp("isns", str))
type = DISCOVERY_TYPE_ISNS;
+ else if (!strcmp("fwboot", str))
+ type = DISCOVERY_TYPE_FWBOOT;
else
type = -1;
@@ -1215,17 +1218,40 @@ do_offload_sendtargets(idbm_t *db, discovery_rec_t *drec,
return discovery_offload_sendtargets(db, host_no, do_login, drec);
}
+static int login_discovered_portals(idbm_t *db, void *data, node_rec_t *rec)
+{
+ discovery_rec_t *drec = data;
+
+ if (rec->disc_type != drec->type ||
+ rec->disc_port != drec->port ||
+ strcmp(rec->disc_address, drec->address))
+ return -1;
+
+ login_portal(db, NULL, rec);
+ /*
+ * This is used during the initial setup, so we want to see
+ * what portals we can or cannot log into and we will just continue
+ */
+ return 0;
+}
+
static int
do_sofware_sendtargets(idbm_t *db, discovery_rec_t *drec,
struct list_head *ifaces, int info_level, int do_login)
{
- int rc;
+ int rc, nr_found = 0;
drec->type = DISCOVERY_TYPE_SENDTARGETS;
rc = discovery_sendtargets(db, drec, ifaces);
- if (!rc)
- idbm_print_discovered(db, drec, info_level);
- return rc;
+ if (rc)
+ return rc;
+
+ idbm_print_discovered(db, drec, info_level);
+
+ if (!do_login)
+ return 0;
+
+ return idbm_for_each_rec(db, &nr_found, drec, login_discovered_portals);
}
static int
@@ -1293,6 +1319,64 @@ sw_st:
return do_sofware_sendtargets(db, drec, ifaces, info_level, do_login);
}
+static int do_fwboot(idbm_t *db, discovery_rec_t *drec, int do_login)
+{
+ struct boot_context context;
+ struct node_rec *rec;
+ int ret;
+
+ memset(&context, 0, sizeof(struct boot_context));
+ /*
+ * Should we print this iscsiadm style or the ibft tool style
+ */
+ ret = fw_entry_init(&context, FW_PRINT);
+ if (ret) {
+ log_error("Could not print fw values.");
+ return ret;
+ }
+
+ if (!do_login)
+ return 0;
+
+ memset(&context, 0, sizeof(struct boot_context));
+ ret = fw_entry_init(&context, FW_CONNECT);
+ if (ret) {
+ log_error("Could not read fw values.");
+ return ret;
+ }
+
+ /* tpgt hard coded to 1 */
+ rec = create_node_record(db, context.targetname, 1,
+ context.target_ipaddr, context.target_port,
+ NULL, 1);
+ if (!rec) {
+ log_error("Could not setup rec for fwboot login.");
+ return ENOMEM;
+ }
+
+ /*
+ * For now initiator name is the default value. When Erez
+ * does his iname virtualization we can set that on a per iface
+ * basis.
+ */
+ strncpy(rec->session.auth.username, context.chap_name,
+ sizeof(context.chap_name));
+ strncpy((char *)rec->session.auth.password, context.chap_password,
+ sizeof(context.chap_password));
+ strncpy(rec->session.auth.username_in, context.chap_name_in,
+ sizeof(context.chap_name_in));
+ strncpy((char *)rec->session.auth.password_in, context.chap_password_in,
+ sizeof(context.chap_password_in));
+ rec->session.auth.password_length =
+ strlen((char *)context.chap_password);
+ rec->session.auth.password_in_length =
+ strlen((char *)context.chap_password_in);
+ ret = login_portal(db, NULL, rec);
+ free(rec);
+ return ret;
+}
+
+
static int isns_dev_attr_query(idbm_t *db, discovery_rec_t *drec,
int info_level)
{
@@ -1852,6 +1936,11 @@ main(int argc, char **argv)
if (isns_dev_attr_query(db, &drec, info_level))
rc = -1;
break;
+ case DISCOVERY_TYPE_FWBOOT:
+ drec.type = DISCOVERY_TYPE_FWBOOT;
+ if (do_fwboot(db, &drec, do_login))
+ rc = -1;
+ break;
default:
if (ip) {
if (idbm_discovery_read(db, &drec, ip, port)) {
diff --git a/usr/iscsistart.c b/usr/iscsistart.c
index 5d9dc1b..133d50a 100644
--- a/usr/iscsistart.c
+++ b/usr/iscsistart.c
@@ -42,6 +42,7 @@
#include "version.h"
#include "iscsi_sysfs.h"
#include "iscsi_settings.h"
+#include "fw_context.h"
/* global config info */
/* initiator needs initiator name/alias */
@@ -68,6 +69,8 @@ static struct option const long_options[] = {
{"username_in", required_argument, NULL, 'U'},
{"password_in", required_argument, NULL, 'W'},
{"debug", required_argument, NULL, 'd'},
+ {"fwparam_connect", no_argument, NULL, 'b'},
+ {"fwparam_print", no_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0},
@@ -92,6 +95,8 @@ Open-iSCSI initiator.\n\
-U, --username_in=N set incoming username to N (optional)\n\
-W, --password_in=N set incoming password to N (optional\n\
-d, --debug debuglevel print debugging information \n\
+ -b, --fwparam_connect create a session to the target\n\
+ -f, --fwparam_print print the iBFT to STDOUT \n\
-h, --help display this help and exit\n\
-v, --version display version and exit\n\
");
@@ -175,15 +180,15 @@ do { \
} \
} while (0);
-/* TODO fix leaks */
int main(int argc, char *argv[])
{
struct utsname host_info; /* will use to compound initiator alias */
struct iscsi_auth_config *auth;
char *initiatorname = NULL;
- int ch, longindex;
+ int ch, longindex, ret;
struct sigaction sa_old;
struct sigaction sa_new;
+ struct boot_context context;
pid_t pid;
idbm_node_setup_defaults(&config_rec);
@@ -197,7 +202,7 @@ int main(int argc, char *argv[])
sa_new.sa_flags = 0;
sigaction(SIGINT, &sa_new, &sa_old );
- while ((ch = getopt_long(argc, argv, "i:t:g:a:p:d:u:w:U:W:vh",
+ while ((ch = getopt_long(argc, argv, "i:t:g:a:p:d:u:w:U:W:bfvh",
long_options, &longindex)) >= 0) {
switch (ch) {
case 'i':
@@ -246,6 +251,41 @@ int main(int argc, char *argv[])
case 'd':
log_level = atoi(optarg);
break;
+ case 'b':
+ ret = fw_entry_init(&context, FW_CONNECT);
+ if (ret) {
+ printf("Could not setup fw entries.");
+ exit(0);
+ }
+
+ initiatorname = context.initiatorname;
+ strncpy(config_rec.name, context.targetname,
+ sizeof(context.targetname));
+ strncpy(config_rec.conn[0].address,
+ context.target_ipaddr,
+ sizeof(context.target_ipaddr));
+ config_rec.conn[0].port = context.target_port;
+ /* this seems broken ??? */
+ config_rec.tpgt = 1;
+ strncpy(auth->username, context.chap_name,
+ sizeof(context.chap_name));
+ strncpy((char *)auth->password, context.chap_password,
+ sizeof(context.chap_password));
+ auth->password_length = strlen((char *)auth->password);
+ strncpy(auth->username_in, context.chap_name_in,
+ sizeof(context.chap_name_in));
+ strncpy((char *)auth->password_in,
+ context.chap_password_in,
+ sizeof(context.chap_password_in));
+ auth->password_in_length =
+ strlen((char *)auth->password_in);
+ break;
+ case 'f':
+ if (fw_entry_init(&context, FW_PRINT)) {
+ printf("Could not print fw values.");
+ exit(1);
+ } else
+ exit(0);
case 'v':
printf("%s version %s\n", program_name,
ISCSI_VERSION_STR);
diff --git a/utils/fwparam_ibft/fw_entry.c b/utils/fwparam_ibft/fw_entry.c
new file mode 100644
index 0000000..a498d4f
--- /dev/null
+++ b/utils/fwparam_ibft/fw_entry.c
@@ -0,0 +1,36 @@
+/*
+ * 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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * Copyright (C) IBM Corporation. 2007
+ * Author: Doug Maxey <dwm@austin.ibm.com>
+ * based on code written by "Prasanna Mumbai" <mumbai.prasanna@gmail.com>
+ *
+ */
+#include "fw_context.h"
+#include "fwparam_ibft.h"
+
+int
+fw_entry_init(struct boot_context *context, int option)
+{
+ int ret = 0 ;
+/*
+ ppc should uncomment
+
+ ret = fwparam_ppc(context, option);
+ if (ret)
+*/
+ ret = fwparam_ibft(context, option);
+ return ret;
+}
diff --git a/utils/fwparam_ibft/fwparam_ibft.c b/utils/fwparam_ibft/fwparam_ibft.c
index 1b33a98..1613ae6 100644
--- a/utils/fwparam_ibft/fwparam_ibft.c
+++ b/utils/fwparam_ibft/fwparam_ibft.c
@@ -32,24 +32,15 @@
#include <errno.h>
#include "fwparam_ibft.h"
+#include "fw_context.h"
-char *progname;
+char *progname = "fwparam_ibft";
int debug;
-char default_file_name[] = "/dev/mem";
-char *filename = default_file_name;
-int boot_selected_only;
+char filename[FILENAMESZ];
const char nulls[16]; /* defaults to zero */
-/*
- * Prefix strings, for the "prefixN:NAME=value".
- */
-#define NETWORK "network"
-#define INITIATOR "iscsi-initiator"
-#define TGT "target"
-
-
-void
+int
verify_hdr(char *name, struct ibft_hdr *hdr, int id, int version, int length)
{
#define VERIFY_HDR_FIELD(val) \
@@ -58,7 +49,7 @@ verify_hdr(char *name, struct ibft_hdr *hdr, int id, int version, int length)
"%s: error, %s structure expected %s %d but" \
" got %d\n", \
progname, name, #val, hdr->val, val); \
- exit(1); \
+ return -1; \
}
if (debug > 1)
@@ -70,6 +61,7 @@ verify_hdr(char *name, struct ibft_hdr *hdr, int id, int version, int length)
VERIFY_HDR_FIELD(length);
#undef VERIFY_HDR_FIELD
+ return 0;
}
#define CHECK_HDR(ident, name) \
@@ -314,7 +306,7 @@ dump_tgt_prefix(void *ibft_loc, struct ibft_tgt *tgt, char *prefix)
* Read in and dump ASCII output for ibft starting at ibft_loc.
*/
int
-dump_ibft(void *ibft_loc)
+dump_ibft(void *ibft_loc, struct boot_context *context, int option)
{
struct ibft_table_hdr *ibft_hdr = ibft_loc;
struct ibft_control *control;
@@ -322,6 +314,7 @@ dump_ibft(void *ibft_loc)
struct ibft_nic *nic0 = NULL, *nic1 = NULL;
struct ibft_tgt *tgt0 = NULL, *tgt1 = NULL;
char sum = 0, *buf = ibft_loc;
+ char ipbuf[32];
char prefix[32];
for (; buf <= (char *) (ibft_loc + ibft_hdr->length);)
@@ -367,8 +360,7 @@ dump_ibft(void *ibft_loc)
CHECK_HDR(tgt1, target);
}
- if (boot_selected_only) {
-
+ if (option == FW_PRINT) {
snprintf(prefix, sizeof(prefix), "iSCSI_INITIATOR_");
if (initiator && (initiator->hdr.flags &
@@ -386,20 +378,55 @@ dump_ibft(void *ibft_loc)
else if (tgt1 && (tgt1->hdr.flags & INIT_FLAG_FW_SEL_BOOT))
dump_tgt_prefix(ibft_loc, tgt1, prefix);
- } else {
-
- snprintf(prefix, sizeof(prefix), "%s%d:", INITIATOR, 0);
- dump_initiator_prefix(ibft_loc, initiator, prefix);
-
- snprintf(prefix, sizeof(prefix), "%s%d:", NETWORK, 0);
- dump_nic_prefix(ibft_loc, nic0, prefix);
- snprintf(prefix, sizeof(prefix), "%s%d:", TGT, 0);
- dump_tgt_prefix(ibft_loc, tgt0, prefix);
-
- snprintf(prefix, sizeof(prefix), "%s%d:", NETWORK, 1);
- dump_nic_prefix(ibft_loc, nic1, prefix);
- snprintf(prefix, sizeof(prefix), "%s%d:", TGT, 1);
- dump_tgt_prefix(ibft_loc, tgt1, prefix);
+ } else if (option == FW_CONNECT) {
+ strncpy(context->initiatorname,
+ (char *)ibft_loc+initiator->initiator_name_off,
+ initiator->initiator_name_len + 1);
+
+ if (tgt0 && (tgt0->hdr.flags & INIT_FLAG_FW_SEL_BOOT)) {
+ strncpy((char *)context->targetname,
+ (char *)(ibft_loc+tgt0->tgt_name_off),
+ tgt0->tgt_name_len);
+ format_ipaddr(ipbuf, sizeof(ipbuf),
+ tgt0->ip_addr);
+ strncpy((char *)context->target_ipaddr, ipbuf,
+ sizeof(ipbuf));
+ context->target_port = tgt0->port;
+ strncpy(context->chap_name,
+ (char *)(ibft_loc + tgt0->chap_name_off),
+ tgt0->chap_name_len);
+ strncpy(context->chap_password,
+ (char*)(ibft_loc + tgt0->chap_secret_off),
+ tgt0->chap_secret_len);
+ strncpy(context->chap_name_in,
+ (char *)(ibft_loc + tgt0->rev_chap_name_off),
+ tgt0->rev_chap_name_len);
+ strncpy(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)) {
+ strncpy((char *)context->targetname,
+ (char *)(ibft_loc+tgt1->tgt_name_off),
+ tgt1->tgt_name_len);
+ format_ipaddr(ipbuf, sizeof(ipbuf),
+ tgt1->ip_addr);
+ strncpy((char *)context->target_ipaddr,ipbuf,
+ sizeof(ipbuf));
+ context->target_port = tgt1->port;
+ strncpy(context->chap_name,
+ (char *)(ibft_loc + tgt1->chap_name_off),
+ tgt1->chap_name_len);
+ strncpy(context->chap_password,
+ (char*)(ibft_loc + tgt1->chap_secret_off),
+ tgt1->chap_secret_len);
+ strncpy(context->chap_name_in,
+ (char *)(ibft_loc + tgt1->rev_chap_name_off),
+ tgt1->rev_chap_name_len);
+ strncpy(context->chap_password_in,
+ (char *)(ibft_loc + tgt1->rev_chap_secret_off),
+ tgt1->rev_chap_secret_len);
+ }
}
return 0;
@@ -436,57 +463,19 @@ search_file(char *filebuf, char *string, int len, int max)
}
int
-main (int argc, char **argv)
+fwparam_ibft(struct boot_context *context, int option)
{
- int fd, option, ret;
+ int fd, ret;
char *filebuf, *ibft_loc;
int start = 512 * 1024; /* 512k */
int end_search = (1024 * 1024) - start; /* 512k */
- progname = argv[0];
-
- while (1) {
- option = getopt(argc, argv, "f:m:s:e:vhb");
- if (option == -1)
- break;
- switch (option) {
- case 'b':
- boot_selected_only = 1;
- break;
- case 'e':
- end_search = strtoul(optarg, NULL, 0);
- break;
- case 'f':
- filename = optarg;
- break;
- case 's':
- start = strtoul(optarg, NULL, 0);
- break;
- case 'v':
- debug++;
- break;
- default:
- fprintf(stderr, "Unknown or bad option '%c'\n", option);
- case 'h':
- printf("Usage: %s OPTIONS\n"
- "-b print only fw boot selected sections\n"
- "-f file_to_search (default /dev/mem)\n"
- "-s offset to start search\n"
- "-e length of search\n"
- "-v verbose\n",
- progname);
- exit(1);
- }
- }
-
- if (debug)
- fprintf(stderr, "file: %s; start %d, end_search %d, debug %d\n",
- filename, start, end_search, debug);
+ strncpy(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);
- exit(1);
+ return -1;
}
/*
@@ -499,18 +488,17 @@ main (int argc, char **argv)
if (filebuf == MAP_FAILED) {
fprintf(stderr, "Could not mmap %s: %s (%d)\n",
filename, strerror(errno), errno);
- exit(1);
+ ret = -1;
+ goto done;
}
ibft_loc = search_file(filebuf, iBFTSTR, strlen(iBFTSTR), end_search);
- if (ibft_loc) {
- if (dump_ibft(ibft_loc))
- ret = 0;
- else
- ret = 1;
- } else
- ret = 1;
+ if (ibft_loc)
+ ret = dump_ibft(ibft_loc, context, option);
+ else
+ ret = -1;
munmap(filebuf, end_search);
+done:
close(fd);
- exit(ret);
+ return ret;
}
diff --git a/utils/fwparam_ibft/fwparam_ibft.h b/utils/fwparam_ibft/fwparam_ibft.h
index 67b7084..773d7c4 100644
--- a/utils/fwparam_ibft/fwparam_ibft.h
+++ b/utils/fwparam_ibft/fwparam_ibft.h
@@ -26,6 +26,7 @@
/* #include <sys/types.h> */
#include <stdint.h>
+#include "fw_context.h"
/*
* Structures here are is based on Doug's original code, and Patrick's
@@ -136,4 +137,21 @@ struct ibft_tgt {
uint16_t rev_chap_secret_off;
} __attribute__((__packed__));
+/* Common variables */
+#define FILENAMESZ (42)
+extern char filename[FILENAMESZ];
+#define X86_DEFAULT_FILENAME "/dev/mem"
+
+/*
+ * Prefix strings, for the "prefixN:NAME=value".
+ */
+#define NETWORK "network"
+#define INITIATOR "iscsi-initiator"
+#define TARGET "target"
+
+
+/* func decls */
+extern int fwparam_ibft(struct boot_context *context, int option);
+extern int fwparam_ppc(struct boot_context *context, int option);
+
#endif /* FWPARAM_IBFT_H_ */