cbfstool: prefer fmap data over cbfs master header if it exists

Up to now, if both fmap and a master header existed, the master header
was used. Now, use the master header only if no fmap is found.

Change-Id: Iafbf2c9dc325597e23a9780b495549b5d912e9ad
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: http://review.coreboot.org/11629
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 55f8084..24ab0c4 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -343,20 +343,22 @@
 	buffer_clone(&out->buffer, in);
 	out->has_header = false;
 
+	if (cbfs_is_valid_cbfs(out)) {
+		return 0;
+	}
+
 	void *header_loc = cbfs_find_header(in->data, in->size, offset);
 	if (header_loc) {
 		cbfs_get_header(&out->header, header_loc);
 		out->has_header = true;
 		cbfs_fix_legacy_size(out, header_loc);
+		return 0;
 	} else if (offset != ~0u) {
 		ERROR("The -H switch is only valid on legacy images having CBFS master headers.\n");
 		return 1;
-	} else if (!cbfs_is_valid_cbfs(out)) {
-		ERROR("Selected image region is not a valid CBFS.\n");
-		return 1;
 	}
-
-	return 0;
+	ERROR("Selected image region is not a valid CBFS.\n");
+	return 1;
 }
 
 int cbfs_copy_instance(struct cbfs_image *image, size_t copy_offset,