zbyszek / rpms / grub2

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