a5bd9f6
From 46aa8934bbcbc427f7424e77bead7c0c8356a138 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Sun, 14 Apr 2013 18:53:14 +0200
a5bd9f6
Subject: [PATCH 307/364] 	Move GRUB out of system area when using
a5bd9f6
 xorriso 1.2.9 or later.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog                       |   4 +
a5bd9f6
 grub-core/Makefile.core.def     |  13 +++
a5bd9f6
 grub-core/boot/i386/pc/boot.S   | 194 +++++++++++++++++++++++++---------------
a5bd9f6
 grub-core/boot/i386/pc/cdboot.S |   5 +-
a5bd9f6
 util/grub-mkrescue.in           |  23 +++--
a5bd9f6
 5 files changed, 159 insertions(+), 80 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 60effd3..fc3dd51 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,5 +1,9 @@
a5bd9f6
 2013-04-14  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
 
a5bd9f6
+	Move GRUB out of system area when using xorriso 1.2.9 or later.
a5bd9f6
+
a5bd9f6
+2013-04-14  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
 	* tests/grub_cmd_date.in: Add missing exit 1.
a5bd9f6
 
a5bd9f6
 2013-04-14  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
a5bd9f6
index f1f1012..459e566 100644
a5bd9f6
--- a/grub-core/Makefile.core.def
a5bd9f6
+++ b/grub-core/Makefile.core.def
a5bd9f6
@@ -282,6 +282,19 @@ image = {
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
 image = {
a5bd9f6
+  name = boot_hybrid;
a5bd9f6
+  i386_pc = boot/i386/pc/boot.S;
a5bd9f6
+
a5bd9f6
+  cppflags = '-DHYBRID_BOOT=1';
a5bd9f6
+  
a5bd9f6
+  i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
a5bd9f6
+  i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
a5bd9f6
+
a5bd9f6
+  objcopyflags = '-O binary';
a5bd9f6
+  enable = i386_pc;
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
+image = {
a5bd9f6
   name = cdboot;
a5bd9f6
 
a5bd9f6
   i386_pc = boot/i386/pc/cdboot.S;
a5bd9f6
diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S
a5bd9f6
index 314f140..c0880c6 100644
a5bd9f6
--- a/grub-core/boot/i386/pc/boot.S
a5bd9f6
+++ b/grub-core/boot/i386/pc/boot.S
a5bd9f6
@@ -28,6 +28,81 @@
a5bd9f6
 #define MSG(x)	movw $x, %si; call LOCAL(message)
a5bd9f6
 #define ERR(x)	movw $x, %si; jmp LOCAL(error_message)
a5bd9f6
 
a5bd9f6
+	.macro floppy
a5bd9f6
+part_start:
a5bd9f6
+
a5bd9f6
+probe_values:
a5bd9f6
+	.byte	36, 18, 15, 9, 0
a5bd9f6
+
a5bd9f6
+LOCAL(floppy_probe):
a5bd9f6
+/*
a5bd9f6
+ *  Perform floppy probe.
a5bd9f6
+ */
a5bd9f6
+
a5bd9f6
+	movw	$probe_values - 1, %si
a5bd9f6
+
a5bd9f6
+LOCAL(probe_loop):
a5bd9f6
+	/* reset floppy controller INT 13h AH=0 */
a5bd9f6
+	xorw	%ax, %ax
a5bd9f6
+	int	$0x13
a5bd9f6
+
a5bd9f6
+	incw	%si
a5bd9f6
+	movb	(%si), %cl
a5bd9f6
+
a5bd9f6
+	/* if number of sectors is 0, display error and die */
a5bd9f6
+	cmpb	$0, %cl
a5bd9f6
+	jne	1f
a5bd9f6
+
a5bd9f6
+/*
a5bd9f6
+ * Floppy disk probe failure.
a5bd9f6
+ */
a5bd9f6
+	MSG(fd_probe_error_string)
a5bd9f6
+	jmp	LOCAL(general_error)
a5bd9f6
+
a5bd9f6
+/* "Floppy" */
a5bd9f6
+fd_probe_error_string:	.asciz "Floppy"
a5bd9f6
+
a5bd9f6
+1:
a5bd9f6
+	/* perform read */
a5bd9f6
+	movw	$GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
a5bd9f6
+	movw	%bx, %es
a5bd9f6
+	xorw	%bx, %bx
a5bd9f6
+	movw	$0x201, %ax
a5bd9f6
+	movb	$0, %ch
a5bd9f6
+	movb	$0, %dh
a5bd9f6
+	int	$0x13
a5bd9f6
+
a5bd9f6
+	/* if error, jump to "LOCAL(probe_loop)" */
a5bd9f6
+	jc	LOCAL(probe_loop)
a5bd9f6
+
a5bd9f6
+	/* %cl is already the correct value! */
a5bd9f6
+	movb	$1, %dh
a5bd9f6
+	movb	$79, %ch
a5bd9f6
+
a5bd9f6
+	jmp	LOCAL(final_init)
a5bd9f6
+	.endm
a5bd9f6
+
a5bd9f6
+	.macro scratch
a5bd9f6
+
a5bd9f6
+	/* scratch space */
a5bd9f6
+mode:
a5bd9f6
+	.byte	0
a5bd9f6
+disk_address_packet:
a5bd9f6
+sectors:
a5bd9f6
+	.long	0
a5bd9f6
+heads:
a5bd9f6
+	.long	0
a5bd9f6
+cylinders:
a5bd9f6
+	.word	0
a5bd9f6
+sector_start:
a5bd9f6
+	.byte	0
a5bd9f6
+head_start:
a5bd9f6
+	.byte	0
a5bd9f6
+cylinder_start:
a5bd9f6
+	.word	0
a5bd9f6
+	/* more space... */
a5bd9f6
+	.endm
a5bd9f6
+
a5bd9f6
 	.file	"boot.S"
a5bd9f6
 
a5bd9f6
 	.text
a5bd9f6
@@ -51,6 +126,34 @@ start:
a5bd9f6
 	jmp	LOCAL(after_BPB)
a5bd9f6
 	nop	/* do I care about this ??? */
a5bd9f6
 
a5bd9f6
+#ifdef HYBRID_BOOT
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+
a5bd9f6
+	nop
a5bd9f6
+	nop
a5bd9f6
+	jmp	LOCAL(after_BPB)
a5bd9f6
+#else
a5bd9f6
 	/*
a5bd9f6
 	 * This space is for the BIOS parameter block!!!!  Don't change
a5bd9f6
 	 * the first jump, nor start the code anywhere but right after
a5bd9f6
@@ -59,27 +162,14 @@ start:
a5bd9f6
 
a5bd9f6
 	. = _start + GRUB_BOOT_MACHINE_BPB_START
a5bd9f6
 	. = _start + 4
a5bd9f6
-
a5bd9f6
-	/* scratch space */
a5bd9f6
-mode:
a5bd9f6
-	.byte	0
a5bd9f6
-disk_address_packet:
a5bd9f6
-sectors:
a5bd9f6
-	.long	0
a5bd9f6
-heads:
a5bd9f6
-	.long	0
a5bd9f6
-cylinders:
a5bd9f6
-	.word	0
a5bd9f6
-sector_start:
a5bd9f6
-	.byte	0
a5bd9f6
-head_start:
a5bd9f6
-	.byte	0
a5bd9f6
-cylinder_start:
a5bd9f6
-	.word	0
a5bd9f6
-	/* more space... */
a5bd9f6
+#endif
a5bd9f6
+#ifdef HYBRID_BOOT
a5bd9f6
+	floppy
a5bd9f6
+#else
a5bd9f6
+	scratch
a5bd9f6
+#endif
a5bd9f6
 
a5bd9f6
 	. = _start + GRUB_BOOT_MACHINE_BPB_END
a5bd9f6
-
a5bd9f6
 	/*
a5bd9f6
 	 * End of BIOS parameter block.
a5bd9f6
 	 */
a5bd9f6
@@ -87,9 +177,11 @@ cylinder_start:
a5bd9f6
 kernel_address:
a5bd9f6
 	.word	GRUB_BOOT_MACHINE_KERNEL_ADDR
a5bd9f6
 
a5bd9f6
+#ifndef HYBRID_BOOT
a5bd9f6
 	. = _start + GRUB_BOOT_MACHINE_KERNEL_SECTOR
a5bd9f6
 kernel_sector:
a5bd9f6
 	.long	1, 0
a5bd9f6
+#endif
a5bd9f6
 
a5bd9f6
 	. = _start + GRUB_BOOT_MACHINE_BOOT_DRIVE
a5bd9f6
 boot_drive:
a5bd9f6
@@ -410,6 +502,11 @@ LOCAL(message):
a5bd9f6
 	 *  number here.
a5bd9f6
 	 */
a5bd9f6
 
a5bd9f6
+#ifdef HYBRID_BOOT
a5bd9f6
+	. = _start + 0x1b0
a5bd9f6
+kernel_sector:
a5bd9f6
+	.long	1, 0
a5bd9f6
+#endif
a5bd9f6
 	. = _start + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC
a5bd9f6
 nt_magic:
a5bd9f6
 	.long 0
a5bd9f6
@@ -419,62 +516,17 @@ nt_magic:
a5bd9f6
 	 *  This is where an MBR would go if on a hard disk.  The code
a5bd9f6
 	 *  here isn't even referenced unless we're on a floppy.  Kinda
a5bd9f6
 	 *  sneaky, huh?
a5bd9f6
-	 */
a5bd9f6
+	*/
a5bd9f6
 
a5bd9f6
 	. = _start + GRUB_BOOT_MACHINE_PART_START
a5bd9f6
-part_start:
a5bd9f6
-
a5bd9f6
-probe_values:
a5bd9f6
-	.byte	36, 18, 15, 9, 0
a5bd9f6
-
a5bd9f6
-LOCAL(floppy_probe):
a5bd9f6
-/*
a5bd9f6
- *  Perform floppy probe.
a5bd9f6
- */
a5bd9f6
-
a5bd9f6
-	movw	$probe_values - 1, %si
a5bd9f6
-
a5bd9f6
-LOCAL(probe_loop):
a5bd9f6
-	/* reset floppy controller INT 13h AH=0 */
a5bd9f6
-	xorw	%ax, %ax
a5bd9f6
-	int	$0x13
a5bd9f6
-
a5bd9f6
-	incw	%si
a5bd9f6
-	movb	(%si), %cl
a5bd9f6
-
a5bd9f6
-	/* if number of sectors is 0, display error and die */
a5bd9f6
-	cmpb	$0, %cl
a5bd9f6
-	jne	1f
a5bd9f6
-
a5bd9f6
-/*
a5bd9f6
- * Floppy disk probe failure.
a5bd9f6
- */
a5bd9f6
-	MSG(fd_probe_error_string)
a5bd9f6
-	jmp	LOCAL(general_error)
a5bd9f6
-
a5bd9f6
-/* "Floppy" */
a5bd9f6
-fd_probe_error_string:	.asciz "Floppy"
a5bd9f6
-
a5bd9f6
-1:
a5bd9f6
-	/* perform read */
a5bd9f6
-	movw	$GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
a5bd9f6
-	movw	%bx, %es
a5bd9f6
-	xorw	%bx, %bx
a5bd9f6
-	movw	$0x201, %ax
a5bd9f6
-	movb	$0, %ch
a5bd9f6
-	movb	$0, %dh
a5bd9f6
-	int	$0x13
a5bd9f6
 
a5bd9f6
-	/* if error, jump to "LOCAL(probe_loop)" */
a5bd9f6
-	jc	LOCAL(probe_loop)
a5bd9f6
-
a5bd9f6
-	/* %cl is already the correct value! */
a5bd9f6
-	movb	$1, %dh
a5bd9f6
-	movb	$79, %ch
a5bd9f6
-
a5bd9f6
-	jmp	LOCAL(final_init)
a5bd9f6
+#ifndef HYBRID_BOOT
a5bd9f6
+	floppy
a5bd9f6
+#else
a5bd9f6
+	scratch
a5bd9f6
+#endif
a5bd9f6
 
a5bd9f6
 	. = _start + GRUB_BOOT_MACHINE_PART_END
a5bd9f6
-
a5bd9f6
+	
a5bd9f6
 /* the last 2 bytes in the sector 0 contain the signature */
a5bd9f6
 	.word	GRUB_BOOT_MACHINE_SIGNATURE
a5bd9f6
diff --git a/grub-core/boot/i386/pc/cdboot.S b/grub-core/boot/i386/pc/cdboot.S
a5bd9f6
index d939835..92df7c7 100644
a5bd9f6
--- a/grub-core/boot/i386/pc/cdboot.S
a5bd9f6
+++ b/grub-core/boot/i386/pc/cdboot.S
a5bd9f6
@@ -93,11 +93,12 @@ LOCAL(read_cdrom):
a5bd9f6
 	pushw	$CDBLK_LENG
a5bd9f6
 
a5bd9f6
 	/* Block number.  */
a5bd9f6
+	incl    %esi
a5bd9f6
 	pushl	%eax
a5bd9f6
 	pushl	%esi
a5bd9f6
 
a5bd9f6
 	/* Buffer address.  */
a5bd9f6
-	pushw	$((DATA_ADDR - 0x400)>> 4)
a5bd9f6
+	pushw	$((DATA_ADDR - 0x200)>> 4)
a5bd9f6
 	pushl	%eax
a5bd9f6
 	pushw	$0x10
a5bd9f6
 
a5bd9f6
@@ -167,6 +168,6 @@ err_noboot_msg:
a5bd9f6
 err_cdfail_msg:
a5bd9f6
 	.ascii	"cdrom read fails\0"
a5bd9f6
 
a5bd9f6
-	. = start + 0x1FF
a5bd9f6
+	. = start + 0x7FF
a5bd9f6
 
a5bd9f6
 	.byte	0
a5bd9f6
diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in
a5bd9f6
index c74c8ca..b97d674 100644
a5bd9f6
--- a/util/grub-mkrescue.in
a5bd9f6
+++ b/util/grub-mkrescue.in
a5bd9f6
@@ -365,15 +365,25 @@ if test -e "${pc_dir}" ; then
a5bd9f6
         iso9660 biosdisk
a5bd9f6
     cat "${pc_dir}/cdboot.img" "${core_img}" > "${iso9660_dir}/boot/grub/i386-pc/eltorito.img"
a5bd9f6
 
a5bd9f6
-    embed_img="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
a5bd9f6
-    cat "${pc_dir}/boot.img" "${core_img}" > "${embed_img}"
a5bd9f6
-
a5bd9f6
-    rm -f "${core_img}"
a5bd9f6
-
a5bd9f6
     grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-load-size 4 -boot-info-table"
a5bd9f6
     if [ "$system_area" = common ]; then
a5bd9f6
-	grub_mkisofs_arguments="--embedded-boot ${embed_img}"
a5bd9f6
+	if "${xorriso}" -as mkisofs -help 2>&1 | fgrep "grub2-boot-info" >/dev/null; then
a5bd9f6
+	    grub_mkisofs_arguments="${grub_mkisofs_arguments} --grub2-boot-info --grub2-mbr ${pc_dir}/boot_hybrid.img"
a5bd9f6
+	else
a5bd9f6
+	    gettext "Your xorriso doesn't support \`--grub2-boot-info'. Some features are disabled. Please use xorriso 1.2.9 or later."
a5bd9f6
+	    echo
a5bd9f6
+	    sysarea_img="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
a5bd9f6
+	    cat "${pc_dir}/boot.img" "${core_img}" > "${sysarea_img}"
a5bd9f6
+	    if [ "$(wc -c "${sysarea_img}" | awk '{ print $1; }')" -gt 32768 ]; then
a5bd9f6
+		gettext "Your xorriso doesn't support \`--grub2-boot-info'. Your core image is too big. Boot as disk is disabled. Please use xorriso 1.2.9 or later."
a5bd9f6
+		echo
a5bd9f6
+	    else
a5bd9f6
+		grub_mkisofs_arguments="${grub_mkisofs_arguments} -G ${sysarea_img}"
a5bd9f6
+	    fi
a5bd9f6
+	fi
a5bd9f6
     fi
a5bd9f6
+
a5bd9f6
+    rm -f "${core_img}"
a5bd9f6
 fi
a5bd9f6
 
a5bd9f6
 # build multiboot core.img
a5bd9f6
@@ -495,6 +505,5 @@ fi
a5bd9f6
 rm -rf "${iso9660_dir}"
a5bd9f6
 
a5bd9f6
 rm -f "${sysarea_img}"
a5bd9f6
-rm -f "${embed_img}"
a5bd9f6
 
a5bd9f6
 exit 0
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6