Restrict searching to 0xc0000 and 0xf0000 (the expansion ROM area) and search
for a valid ROM header before proceeding to search for the iBFT data.

Has not been tested against a machine with a valid checksum.

Signed-off-by: Brandon Philips <bphilips@suse.de>
---
 utils/fwparam_ibft/fwparam_ibft.c |   33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

Index: open-iscsi-svn/utils/fwparam_ibft/fwparam_ibft.c
===================================================================
--- open-iscsi-svn.orig/utils/fwparam_ibft/fwparam_ibft.c
+++ open-iscsi-svn/utils/fwparam_ibft/fwparam_ibft.c
@@ -39,6 +39,8 @@ char default_file_name[] = "/dev/mem";
 char *filename = default_file_name;
 int boot_selected_only;
 
+char* ID_ROMEXT="UÂª"; /* 0x55aa */
+
 const char nulls[16]; /* defaults to zero */
 
 /*
@@ -435,13 +437,38 @@ search_file(char *filebuf, char *string,
 		return NULL;
 }
 
+static char * search_rom(char * buf, int start_addr, int last)
+{
+	char *a, *ret;
+	char *end = buf + last;
+	unsigned char csize;
+	int size;
+
+	for (a = buf; a < end; a += 512) {
+		if (memcmp(a,ID_ROMEXT,1)==0) {
+			memcpy(&csize, a + 2, 1);
+			size = csize * 512;
+
+			if (debug > 1)
+				fprintf(stderr, "Found a rom section at %x\n",
+					((int)(a - buf)) + start_addr);
+
+			ret = search_file(a, iBFTSTR, strlen(iBFTSTR), size);
+			if (ret != NULL)
+				return ret;
+		}
+	}
+	return NULL;
+}
+
+
 int
 main (int argc, char **argv)
 {
 	int fd, option, ret;
 	char *filebuf, *ibft_loc;
-	int start = 512 * 1024; /* 512k */
-	int end_search = (1024 * 1024) - start; /* 512k */
+	int start = 0xc0000;
+	int end_search = 0xf0000 - start;
 
 	progname = argv[0];
 
@@ -502,7 +529,7 @@ main (int argc, char **argv)
 		exit(1);
 	}
 
-	ibft_loc = search_file(filebuf, iBFTSTR, strlen(iBFTSTR), end_search);
+	ibft_loc = search_rom(filebuf, start, end_search);
 	if (ibft_loc) {
 		if (dump_ibft(ibft_loc))
 			ret = 0;
