Fix NBI flags in the presence of segment merging
authorMichael Brown <mbrown@fensystems.co.uk>
Mon, 9 Jun 2008 23:11:25 +0000 (00:11 +0100)
committerH. Peter Anvin <hpa@zytor.com>
Mon, 9 Jun 2008 23:22:45 +0000 (16:22 -0700)
output_nbi() was calculating ihdr.flags before merging in subsequent
segments; this meant that if the last segment got merged,
NBI_IFLAG_LAST was never set.  This breaks mknbi's disnbi.pl and
causes gPXE to reject the NBI file as invalid.

Move the calculation of ihdr.flags until after segment merging has
taken place.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
nbi.c

diff --git a/nbi.c b/nbi.c
index c26a010..d50f90e 100644 (file)
--- a/nbi.c
+++ b/nbi.c
@@ -78,7 +78,6 @@ int output_nbi(struct segment *segs, addr_t entry, FILE *out)
                        ihdr.lengths = sizeof ihdr >> 2;
                        ihdr.tags = 0;
                        ihdr.resv = 0;
-                       ihdr.flags = s->next ? 0 : NBI_IFLAG_LAST;
                        /* The semantics of NBI memsz > filesz is
                           unclear.  It might be desirable to actually
                           allow generation of NOBITS segments. */
@@ -99,6 +98,7 @@ int output_nbi(struct segment *segs, addr_t entry, FILE *out)
                        ihdr.load_addr = address;
                        ihdr.filesz    = length;
                        ihdr.memsz     = length;
+                       ihdr.flags     = s->next ? 0 : NBI_IFLAG_LAST;
 
                        offset += c_fwrite(&ihdr, sizeof ihdr, out);
                }