If you have

  option CONFIG_COMPRESSED_PAYLOAD_LZMA=1
  option CONFIG_PRECOMPRESSED_PAYLOAD=1

set in Config.lb but accidentally use an uncompressed payload coreboot-v2 bombs
out like this:

  elfboot: Attempting to load payload.
  rom_stream: 0xfffc0000 - 0xfffdefff
  Uncompressing to RAM 0x01000000 Decoder scratchpad too small!
  Decoding error = 1
  Unexpected Exception: 6 @ 10:04000408 - Halting
  Code: 0 eflags: 00010057
  eax: 00000101 ebx: 04000400 ecx: 000003d4 edx: fffc0000
  edi: 04000400 esi: 04000401 ebp: 04000400 esp: 0013dfb4

The attached patch modifies v2's lzma code so that it assumes an uncompressed
payload if it fails to find a properly compressed payload.

Compare with the fatal error above:

  elfboot: Attempting to load payload.
  rom_stream: 0xfffc0000 - 0xfffdefff
  Uncompressing to RAM 0x01000000 Decoder scratchpad too small!
   olen = 0x00000000 done.
  Decompression failed. Assuming payload is uncompressed...
  Found ELF candidate at offset 0
  header_offset is 0
  Try to load at offset 0x0

And if you don't have CONFIG_COMPRESSED_PAYLOAD_LZMA and
CONFIG_PRECOMPRESSED_PAYLOAD set and use an uncompressed payload, things are as
before:

  elfboot: Attempting to load payload.
  rom_stream: 0xfffc0000 - 0xfffdefff
  Found ELF candidate at offset 0
  header_offset is 0
  Try to load at offset 0x0

One can argue that this is a case of 'builder beware', but my counter argument
is that anything that causes unexpected runtime breakage is really, really,
really bad, and should be avoided where possible.

This patch also fixes one erroneous comment.

Signed-off-by: Ward Vandewege <ward@gnu.org>

Index: src/stream/rom_stream.c
===================================================================
--- src/stream/rom_stream.c	(revision 3540)
+++ src/stream/rom_stream.c	(working copy)
@@ -26,7 +26,7 @@
 #error "You're defining more than one compression type, which is not allowed (of course)"
 #endif
 #define HAVE_UNCOMPRESSER 1
-// include generic nrv2b
+// include generic lzma
 #include "../lib/lzma.c"
 #endif
 
@@ -97,8 +97,14 @@
         printk_debug("Uncompressing to RAM 0x%08lx ", dest);
         olen = uncompress((uint8_t *) rom_start, (uint8_t *)dest );
 	printk_debug(" olen = 0x%08lx done.\n", olen);
-	rom_end = dest + olen - 1;
-	rom = dest;
+	if (olen != 0) {
+		rom_end = dest + olen - 1;
+		rom = dest;
+	} else {
+		/* Decompression failed, assume payload is uncompressed */
+		printk_debug("Decompression failed. Assuming payload is uncompressed...\n");
+		rom = rom_start;
+	}
 #else
         rom = rom_start;
 #endif
Index: src/lib/lzma.c
===================================================================
--- src/lib/lzma.c	(revision 3540)
+++ src/lib/lzma.c	(working copy)
@@ -28,16 +28,19 @@
 	outSize = *(UInt32 *)(src + LZMA_PROPERTIES_SIZE);
 	if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) {
 		printk_warning("Incorrect stream properties\n");
+		return 0;
 	}
 	mallocneeds = (LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
 	if (mallocneeds > 15980) {
 		printk_warning("Decoder scratchpad too small!\n");
+		return 0;
 	}
 	state.Probs = (CProb *)scratchpad;
 	res = LzmaDecode(&state, src + LZMA_PROPERTIES_SIZE + 8, (SizeT)0xffffffff, &inProcessed,
 		dst, outSize, &outProcessed);
 	if (res != 0) {
 		printk_warning("Decoding error = %d\n", res);
+		return 0;
 	}
 	return outSize;
 }
