summaryrefslogtreecommitdiff
path: root/utils/fwparam_ibft
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2007-07-25 19:04:16 -0500
committerMike Christie <michaelc@cs.wisc.edu>2007-07-25 19:04:16 -0500
commit2899caf02bbfd76cd56103e696e5aebed6af9276 (patch)
tree0f2369652a43f3dce39a626160890c3e63b039e0 /utils/fwparam_ibft
parent75a052f1bedab2ca504156e2c6fa5b72c371c75b (diff)
downloadopen-iscsi-2899caf02bbfd76cd56103e696e5aebed6af9276.tar.gz
hook fw programs into iscsi tools
This patch hooks ibft into iscsiadm and iscsistart. Why do this? It seems easier to be able to just run the same tool we use for normal login. For example in the installer or initramfs we can do this: // This will check for fw crap and if found // log into targets that are found // returns 0 on success and non zero if // there was no fw crap or we could not log // in or some other error. // This will _not_ store any record (text files // with data in it) in /var/lib/iscsi. // It is completely dynamic in that regard. ret = iscsiadm -m discovery -t fwboot -l (fwboot - is a new discovery type I added which is for this fw crap). // For normal iscsi install we can then do: ret = iscsiadm -m discovery -t st -p ip:port -l // This will do discovery to the portal at // ip:port, and now the code supports the -l on discovery, // so it will also log into all the targets found // automagically for the caller. // This will store records (text files with target data in it) // like usual to /var/lib/iscsi. To setup the initramfs then, we just need some variable that tells us if we are doing the fw boot or the pxe net iscsi boot. This could be done by checking iscsiadm or iscsistart like so: ret = iscsiadm -m discovery -t fwboot // no login/-l command this time if ret indicates success, then setup initramfs for dynamic fwboot else do the normal pxe static iscsi root stuff we did. In the initrams fs if using iscsistart we would just do (if this got setup for fw dynamic boot) or it would end up as And if using iscsiadm in the initramfs you can just do iscsiadm -m discovery -t fwboot -l The patch was made using Prasana and Doug's code. I have not tested it. I do not have the hardware handy (no intel card and I got stuck looking for a ppc box with it).
Diffstat (limited to 'utils/fwparam_ibft')
-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
3 files changed, 124 insertions, 82 deletions
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_ */