[syslinux:elflink] load_linux: additional cleanups and corner case fixing

syslinux-bot for H. Peter Anvin hpa at linux.intel.com
Mon Feb 4 11:39:02 PST 2013


Commit-ID:  c3b4e4408688d150da5da74b15b5dba773ff3f28
Gitweb:     http://www.syslinux.org/commit/c3b4e4408688d150da5da74b15b5dba773ff3f28
Author:     H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Mon, 4 Feb 2013 11:35:39 -0800
Committer:  H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Mon, 4 Feb 2013 11:35:39 -0800

load_linux: additional cleanups and corner case fixing

Handle the case with a zero-length passed in initramfs for ancient
protocols, since we bothered handling it correctly for newer
protocols.

Move the setting of the command line pointer to the place where the
command line is actually placed, for clarity.

Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>

---
 com32/lib/syslinux/load_linux.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/com32/lib/syslinux/load_linux.c b/com32/lib/syslinux/load_linux.c
index f70682f..f67c2e4 100644
--- a/com32/lib/syslinux/load_linux.c
+++ b/com32/lib/syslinux/load_linux.c
@@ -290,7 +290,10 @@ int syslinux_boot_linux(void *kernel_buf, size_t kernel_size,
     if (!(hdr.loadflags & LOAD_HIGH) && prot_mode_size > 512 * 1024)
 	goto bail;		/* Kernel cannot be loaded low */
 
-    if (initramfs && hdr.version < 0x0200)
+    /* Get the size of the initramfs, if there is one */
+    irf_size = initramfs_size(initramfs);
+
+    if (irf_size && hdr.version < 0x0200)
 	goto bail;		/* initrd/initramfs not supported */
 
     if (hdr.version >= 0x0200) {
@@ -389,18 +392,6 @@ int syslinux_boot_linux(void *kernel_buf, size_t kernel_size,
 	}
     }
 
-    /* Set up the command line information in the header */
-    if (hdr.version >= 0x0202) {
-	whdr->cmd_line_ptr = real_mode_base + cmdline_offset;
-    } else {
-	whdr->old_cmd_line_magic = OLD_CMDLINE_MAGIC;
-	whdr->old_cmd_line_offset = cmdline_offset;
-	if (hdr.version >= 0x0200) {
-	    /* Be paranoid and round up to a multiple of 16 */
-	    whdr->setup_move_size = (cmdline_offset + cmdline_size + 15) & ~15;
-	}
-    }
-
     if (syslinux_add_movelist(&fraglist, real_mode_base, (addr_t) kernel_buf,
 			      real_mode_size))
 	goto bail;
@@ -417,6 +408,16 @@ int syslinux_boot_linux(void *kernel_buf, size_t kernel_size,
     if (syslinux_add_movelist(&fraglist, real_mode_base + cmdline_offset,
 			      (addr_t) cmdline, cmdline_size))
 	goto bail;
+    if (hdr.version >= 0x0202) {
+	whdr->cmd_line_ptr = real_mode_base + cmdline_offset;
+    } else {
+	whdr->old_cmd_line_magic = OLD_CMDLINE_MAGIC;
+	whdr->old_cmd_line_offset = cmdline_offset;
+	if (hdr.version >= 0x0200) {
+	    /* Be paranoid and round up to a multiple of 16 */
+	    whdr->setup_move_size = (cmdline_offset + cmdline_size + 15) & ~15;
+	}
+    }
 
     /* Protected-mode code */
     if (syslinux_add_movelist(&fraglist, prot_mode_base,
@@ -430,8 +431,6 @@ int syslinux_boot_linux(void *kernel_buf, size_t kernel_size,
        We should put it at the highest possible address which is
        <= hdr.initrd_addr_max, which fits the entire initramfs. */
 
-    irf_size = initramfs_size(initramfs);	/* Handles initramfs == NULL */
-
     if (irf_size) {
 	addr_t best_addr = 0;
 	struct syslinux_memmap *ml;


More information about the Syslinux-commits mailing list