tools/kwbimage.c: Correct header size for SPI boot

If defined, the macro CONFIG_SYS_SPI_U_BOOT_OFFS allows a board
to specify the offset of the payload image into the kwb image
file.  This value was being used to locate the image, but was not
used in the "header size" field of the main header.  Move the
use of this macro into the function that returns the header size
so that the same value is used in all places.

Signed-off-by: Kevin Smith <kevin.smith@elecsyscorp.com>
Tested-by: Stefan Roese <sr@denx.de>
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 9540e7e..1ff17ca 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -420,6 +420,18 @@
 			*hasext = 1;
 	}
 
+#if defined(CONFIG_SYS_SPI_U_BOOT_OFFS)
+	if (headersz > CONFIG_SYS_SPI_U_BOOT_OFFS) {
+		fprintf(stderr, "Error: Image header (incl. SPL image) too big!\n");
+		fprintf(stderr, "header=0x%x CONFIG_SYS_SPI_U_BOOT_OFFS=0x%x!\n",
+			(int)headersz, CONFIG_SYS_SPI_U_BOOT_OFFS);
+		fprintf(stderr, "Increase CONFIG_SYS_SPI_U_BOOT_OFFS!\n");
+		return 0;
+	} else {
+		headersz = CONFIG_SYS_SPI_U_BOOT_OFFS;
+	}
+#endif
+
 	/*
 	 * The payload should be aligned on some reasonable
 	 * boundary
@@ -869,16 +881,6 @@
 			sizeof(struct ext_hdr_v0);
 	} else {
 		alloc_len = image_headersz_v1(params, NULL);
-#if defined(CONFIG_SYS_SPI_U_BOOT_OFFS)
-		if (alloc_len > CONFIG_SYS_SPI_U_BOOT_OFFS) {
-			fprintf(stderr, "Error: Image header (incl. SPL image) too big!\n");
-			fprintf(stderr, "header=0x%x CONFIG_SYS_SPI_U_BOOT_OFFS=0x%x!\n",
-				alloc_len, CONFIG_SYS_SPI_U_BOOT_OFFS);
-			fprintf(stderr, "Increase CONFIG_SYS_SPI_U_BOOT_OFFS!\n");
-		} else {
-			alloc_len = CONFIG_SYS_SPI_U_BOOT_OFFS;
-		}
-#endif
 	}
 
 	hdr = malloc(alloc_len);