Blame SOURCES/0308-Move-GRUB-out-of-system-area-when-using-xorriso-1.2..patch

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