[grub] Add EFI filesystem stuff for mac booting.

Peter Jones pjones at fedoraproject.org
Thu Feb 9 19:34:08 UTC 2012


commit 6f12388eb360f8cad71d1ccee84fc57a4922c585
Author: Peter Jones <pjones at redhat.com>
Date:   Thu Feb 9 14:33:24 2012 -0500

    Add EFI filesystem stuff for mac booting.

 ...ll-back-to-old-efi-GOP-detection-behavior.patch |   46 ---
 grub-fedora-16.patch => grub-fedora-17.patch       |  399 ++++++++++++++++----
 grub.spec                                          |   10 +-
 3 files changed, 330 insertions(+), 125 deletions(-)
---
diff --git a/grub-fedora-16.patch b/grub-fedora-17.patch
similarity index 99%
rename from grub-fedora-16.patch
rename to grub-fedora-17.patch
index 03d2086..33808ec 100644
--- a/grub-fedora-16.patch
+++ b/grub-fedora-17.patch
@@ -1,19 +1,19 @@
 From: Peter Jones <pjones at redhat.com>
-Date: Mon, 14 Mar, 2011 09:29:00 -0500
-Subject: [PATCH] Changes from grub-0.97 to fedora-16
+Date: Thu 9 Feb 2012 13:50:00 -0500
+Subject: [PATCH] Changes from grub-0.97 to fedora-17
 
-This patch is a bundle of the changes between grub-0.97 and fedora-16.
+This patch is a bundle of the changes between grub-0.97 and fedora-17.
 It can be reginerated from the git repository at:
 
 http://git.kernel.org/?p=boot/grub-fedora/grub-fedora.git;a=summary
 
 Using the command:
 
-git diff grub-0.97 fedora-16
-
+git diff grub-0.97 fedora-17
+ 
  .gitignore                     |    8 
  ChangeLog                      |   48 
- Makefile.am                    |    3 
+ Makefile.am                    |    7 
  Makefile.in                    |  175 
  acinclude.m4                   |    4 
  aclocal.m4                     |  555 +-
@@ -37,15 +37,15 @@ git diff grub-0.97 fedora-16
  efi/efichainloader.c           |  265 +
  efi/eficon.c                   |  306 +
  efi/eficore.c                  |  241 +
- efi/efidisk.c                  |  785 ++++
+ efi/efidisk.c                  |  783 ++++
  efi/efidp.c                    |  999 +++++
- efi/efigraph.c                 | 1498 ++++++++
+ efi/efigraph.c                 | 1501 ++++++++
  efi/efimain.c                  |  129 
  efi/efimisc.c                  |  665 +++
  efi/efimm.c                    |  539 ++
  efi/efiserial.c                |  265 +
  efi/efitftp.c                  |  228 +
- efi/efiuga.c                   |  979 +++++
+ efi/efiuga.c                   |  982 +++++
  efi/font_8x16.c                | 4638 ++++++++++++++++++++++++
  efi/graphics.c                 |  659 +++
  efi/graphics.h                 |   81 
@@ -107,7 +107,7 @@ git diff grub-0.97 fedora-16
  stage1/Makefile.in             |  169 
  stage1/stage1.S                |    4 
  stage2/.gitignore              |    5 
- stage2/Makefile.am             |   73 
+ stage2/Makefile.am             |   77 
  stage2/Makefile.in             | 1729 +++++----
  stage2/asm.S                   |  284 +
  stage2/boot.c                  |  114 
@@ -115,17 +115,18 @@ git diff grub-0.97 fedora-16
  stage2/char_io.c               |  609 ++-
  stage2/cmdline.c               |   19 
  stage2/common.c                |   16 
- stage2/disk_io.c               |  208 -
+ stage2/disk_io.c               |  211 -
  stage2/efistubs.c              |    7 
  stage2/efistubs.h              |    8 
  stage2/fat.h                   |    2 
- stage2/filesys.h               |   17 
+ stage2/filesys.h               |   28 
  stage2/fsys_ext2fs.c           |  394 +-
  stage2/fsys_fat.c              |   41 
  stage2/fsys_iso9660.c          |    6 
  stage2/fsys_jfs.c              |   12 
  stage2/fsys_minix.c            |   10 
  stage2/fsys_reiserfs.c         |   44 
+ stage2/fsys_uefi.c             |  196 +
  stage2/fsys_vstafs.c           |   28 
  stage2/fsys_xfs.c              |   22 
  stage2/gpt.h                   |   69 
@@ -138,7 +139,7 @@ git diff grub-0.97 fedora-16
  stage2/serial.c                |    4 
  stage2/sha256crypt.c           |  723 +++
  stage2/sha512crypt.c           |  795 ++++
- stage2/shared.h                |  124 
+ stage2/shared.h                |  126 
  stage2/smp-imps.h              |    1 
  stage2/stage1_5.c              |    3 
  stage2/stage2.c                |  203 -
@@ -151,7 +152,7 @@ git diff grub-0.97 fedora-16
  util/Makefile.in               |  131 
  util/grub-crypt.in             |   80 
  util/grub-install.in           |  334 +
- 140 files changed, 27836 insertions(+), 10643 deletions(-)
+ 141 files changed, 28056 insertions(+), 10647 deletions(-)
 
 diff --git a/.gitignore b/.gitignore
 new file mode 100644
@@ -234,15 +235,18 @@ index 0f93033..9602fb9 100644
  
  	From Steven Dick <ssd.gnu at mmae.ucf.edu>:
 diff --git a/Makefile.am b/Makefile.am
-index 63a9a4f..a27da9c 100644
+index 63a9a4f..9bde872 100644
 --- a/Makefile.am
 +++ b/Makefile.am
-@@ -1,4 +1,7 @@
+@@ -1,4 +1,9 @@
  # Do not change this order if you don't know what you are doing.
  AUTOMAKE_OPTIONS = 1.7 gnu
- SUBDIRS = netboot stage2 stage1 lib grub util docs
+-SUBDIRS = netboot stage2 stage1 lib grub util docs
++SUBDIRS = netboot stage2 stage1 lib util docs
 +if PLATFORM_EFI
 +SUBDIRS += efi
++else
++SUBDIRS += grub
 +endif
  EXTRA_DIST = BUGS MAINTENANCE
 diff --git a/Makefile.in b/Makefile.in
@@ -11694,10 +11698,10 @@ index 0000000..8abea7d
 +
 diff --git a/efi/efidisk.c b/efi/efidisk.c
 new file mode 100644
-index 0000000..2192021
+index 0000000..3f69798
 --- /dev/null
 +++ b/efi/efidisk.c
-@@ -0,0 +1,785 @@
+@@ -0,0 +1,783 @@
 +/*
 + *  GRUB  --  GRand Unified Bootloader
 + *  Copyright (C) 2006  Free Software Foundation, Inc.
@@ -12165,8 +12169,7 @@ index 0000000..2192021
 +	       == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE)
 +	      && (GRUB_EFI_DEVICE_PATH_SUBTYPE (c->last_device_path)
 +		  == GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE)
-+	      && (part_start == hd.partition_start)
-+	      && (part_length == hd.partition_size))
++	      && (part_start == hd.partition_start))
 +	    {
 +	      handle = c->handle;
 +	      return 1;
@@ -12294,8 +12297,7 @@ index 0000000..2192021
 +			 &gpt_size, buf))
 +    {
 +      if (part_type
-+	  && partition_start == hd.partition_start
-+	  && partition_len == hd.partition_size)
++	  && partition_start == hd.partition_start)
 +	{
 +	  *drive = drv;
 +	  *partition = part;
@@ -13490,10 +13492,10 @@ index 0000000..d8ca03d
 +}
 diff --git a/efi/efigraph.c b/efi/efigraph.c
 new file mode 100644
-index 0000000..c285d39
+index 0000000..fc88123
 --- /dev/null
 +++ b/efi/efigraph.c
-@@ -0,0 +1,1498 @@
+@@ -0,0 +1,1501 @@
 +/* efigraph.c - EFI "graphics output" support for GRUB/EFI */
 +/*
 + *  GRUB  --  GRand Unified Bootloader
@@ -14909,6 +14911,9 @@ index 0000000..c285d39
 +
 +	grub_free(handles);
 +
++	if (!eg->output_intf)
++	    eg->output_intf = grub_efi_locate_protocol(&graphics_output_guid, NULL);
++
 +        if (!eg->output_intf)
 +            goto fail;
 +
@@ -16853,10 +16858,10 @@ index 0000000..ba6918f
 +}
 diff --git a/efi/efiuga.c b/efi/efiuga.c
 new file mode 100644
-index 0000000..e035c55
+index 0000000..b27500b
 --- /dev/null
 +++ b/efi/efiuga.c
-@@ -0,0 +1,979 @@
+@@ -0,0 +1,982 @@
 +/* efiuga.c - "univeral graphics adapter" support for GRUB/EFI */
 +/*
 + *  GRUB  --  GRand Unified Bootloader
@@ -17771,6 +17776,9 @@ index 0000000..e035c55
 +
 +	grub_free(handles);
 +
++	if (!uga->draw_intf)
++	    uga->draw_intf = grub_efi_locate_protocol(&draw_guid, NULL);
++
 +        if (!uga->draw_intf) {
 +            grub_free(uga);
 +            return 0;
@@ -23241,7 +23249,7 @@ index 0000000..40a991e
 +cpu
 diff --git a/efi/grub/efi/api.h b/efi/grub/efi/api.h
 new file mode 100644
-index 0000000..f7f8a3d
+index 0000000..81a0b3f
 --- /dev/null
 +++ b/efi/grub/efi/api.h
 @@ -0,0 +1,1716 @@
@@ -24867,10 +24875,10 @@ index 0000000..f7f8a3d
 +  grub_efi_status_t (*write) (struct grub_efi_file * this,
 +			      grub_efi_uintn_t * buffer_size,
 +			      void * buffer);
-+  grub_efi_status_t (*set_position) (struct grub_efi_file * this,
-+				     grub_efi_uint64_t position);
 +  grub_efi_status_t (*get_position) (struct grub_efi_file * this,
 +				     grub_efi_uint64_t * position);
++  grub_efi_status_t (*set_position) (struct grub_efi_file * this,
++				     grub_efi_uint64_t position);
 +  grub_efi_status_t (*get_info) (struct grub_efi_file * this,
 +				 grub_efi_guid_t * information_type,
 +				 grub_efi_uintn_t * buffer_size,
@@ -33500,7 +33508,7 @@ index 0000000..e0480a0
 +*.a
 +*.o
 diff --git a/stage2/Makefile.am b/stage2/Makefile.am
-index f8e6d42..477d129 100644
+index f8e6d42..04ff165 100644
 --- a/stage2/Makefile.am
 +++ b/stage2/Makefile.am
 @@ -7,19 +7,23 @@ noinst_HEADERS = apic.h defs.h dir.h disk_inode.h disk_inode_ffs.h \
@@ -33512,7 +33520,8 @@ index f8e6d42..477d129 100644
  EXTRA_DIST = setjmp.S apm.S $(noinst_SCRIPTS)
  
  # For <stage1.h>.
- INCLUDES = -I$(top_srcdir)/stage1
+-INCLUDES = -I$(top_srcdir)/stage1
++INCLUDES = -I$(top_srcdir)/stage1 -I$(top_srcdir)/efi
  
  # The library for /sbin/grub.
 +if PLATFORM_EFI
@@ -33522,9 +33531,10 @@ index f8e6d42..477d129 100644
 +endif
  libgrub_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \
  	disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ffs.c fsys_iso9660.c \
- 	fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
+-	fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
 -	fsys_vstafs.c fsys_xfs.c gunzip.c md5.c serial.c stage2.c \
 -	terminfo.c tparm.c
++	fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_uefi.c fsys_ufs2.c \
 +	fsys_vstafs.c fsys_xfs.c gunzip.c md5.c serial.c sha256crypt.c \
 +	sha512crypt.c stage2.c terminfo.c tparm.c graphics.c efistubs.c
  libgrub_a_CFLAGS = $(GRUB_CFLAGS) -I$(top_srcdir)/lib \
@@ -33591,7 +33601,7 @@ index f8e6d42..477d129 100644
 +
 +libstage2_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \
 +	disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ffs.c fsys_iso9660.c \
-+	fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
++	fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_uefi.c fsys_ufs2.c \
 +	fsys_vstafs.c fsys_xfs.c gunzip.c md5.c serial.c sha256crypt.c \
 +	sha512crypt.c stage2.c terminfo.c tparm.c efistubs.c
 +libstage2_a_CFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
@@ -38135,7 +38145,7 @@ index 4185d23..e30daf8 100644
 +#endif
 +
 diff --git a/stage2/builtins.c b/stage2/builtins.c
-index 3e08a86..fe6a622 100644
+index 3e08a86..b95b181 100644
 --- a/stage2/builtins.c
 +++ b/stage2/builtins.c
 @@ -56,6 +56,9 @@ static int bootdev;
@@ -38988,11 +38998,11 @@ index 3e08a86..fe6a622 100644
 +  unsigned long tmp_partition = saved_partition;
 +
 +  /* Hard disks.  */
-+  for (drive = 0x79; drive < 0x88; drive++)
++  for (drive = 0x80; drive < 0x89; drive++)
 +    {
 +      unsigned long part = 0xFFFFFF;
 +
-+      if (drive == 0x79)
++      if (drive == 0x88)
 +	  drive = 0x100;
 +
 +      current_drive = drive;
@@ -41142,7 +41152,7 @@ index 09f9e31..e96bec2 100644
    
    /* Start main routine here.  */
 diff --git a/stage2/disk_io.c b/stage2/disk_io.c
-index b9bc526..ee7300d 100644
+index b9bc526..e5a3b2b 100644
 --- a/stage2/disk_io.c
 +++ b/stage2/disk_io.c
 @@ -21,12 +21,17 @@
@@ -41173,7 +41183,17 @@ index b9bc526..ee7300d 100644
  # ifdef FSYS_TFTP
    {"tftp", tftp_mount, tftp_read, tftp_dir, tftp_close, 0},
  # endif
-@@ -127,8 +135,8 @@ struct geometry buf_geom;
+@@ -75,6 +83,9 @@ struct fsys_entry fsys_table[NUM_FSYS + 1] =
+ # ifdef FSYS_UFS2
+   {"ufs2", ufs2_mount, ufs2_read, ufs2_dir, 0, ufs2_embed},
+ # endif
++# ifdef PLATFORM_EFI
++  {"uefi", uefi_mount, uefi_read, uefi_dir, uefi_close, 0},
++# endif
+ # ifdef FSYS_ISO9660
+   {"iso9660", iso9660_mount, iso9660_read, iso9660_dir, 0, 0},
+ # endif
+@@ -127,8 +138,8 @@ struct geometry buf_geom;
  int filepos;
  int filemax;
  
@@ -41184,7 +41204,7 @@ index b9bc526..ee7300d 100644
  {
    asm volatile ("bsfl %1,%0"
  		: "=r" (word)
-@@ -140,7 +148,7 @@ int
+@@ -140,7 +151,7 @@ int
  rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
  {
    int slen, sectors_per_vtrack;
@@ -41193,7 +41213,7 @@ index b9bc526..ee7300d 100644
  
    if (byte_len <= 0)
      return 1;
-@@ -163,7 +171,7 @@ rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
+@@ -163,7 +174,7 @@ rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
  	    }
  	  buf_drive = drive;
  	  buf_track = -1;
@@ -41202,7 +41222,7 @@ index b9bc526..ee7300d 100644
  	}
  
        /* Make sure that SECTOR is valid.  */
-@@ -297,7 +305,7 @@ devread (int sector, int byte_offset, int byte_len, char *buf)
+@@ -297,7 +308,7 @@ devread (int sector, int byte_offset, int byte_len, char *buf)
     *  Check partition boundaries
     */
    if (sector < 0
@@ -41211,7 +41231,7 @@ index b9bc526..ee7300d 100644
  	  >= part_length))
      {
        errnum = ERR_OUTSIDE_PART;
-@@ -307,8 +315,8 @@ devread (int sector, int byte_offset, int byte_len, char *buf)
+@@ -307,8 +318,8 @@ devread (int sector, int byte_offset, int byte_len, char *buf)
    /*
     *  Get the read to the beginning of a partition.
     */
@@ -41222,7 +41242,7 @@ index b9bc526..ee7300d 100644
  
  #if !defined(STAGE1_5)
    if (disk_read_hook && debug)
-@@ -347,7 +355,7 @@ rawwrite (int drive, int sector, char *buf)
+@@ -347,7 +358,7 @@ rawwrite (int drive, int sector, char *buf)
  	sector = 1;
      }
    
@@ -41231,7 +41251,7 @@ index b9bc526..ee7300d 100644
    if (biosdisk (BIOSDISK_WRITE, drive, &buf_geom,
  		sector, 1, SCRATCHSEG))
      {
-@@ -373,23 +381,23 @@ devwrite (int sector, int sector_count, char *buf)
+@@ -373,23 +384,23 @@ devwrite (int sector, int sector_count, char *buf)
  	 embed a Stage 1.5 into a partition instead of a MBR, use system
  	 calls directly instead of biosdisk, because of the bug in
  	 Linux. *sigh*  */
@@ -41269,7 +41289,7 @@ index b9bc526..ee7300d 100644
  }
  
  static int
-@@ -400,7 +408,7 @@ sane_partition (void)
+@@ -400,7 +411,7 @@ sane_partition (void)
      return 1;
    
    if (!(current_partition & 0xFF000000uL)
@@ -41278,7 +41298,7 @@ index b9bc526..ee7300d 100644
  	  || current_drive == cdrom_drive)
        && (current_partition & 0xFF) == 0xFF
        && ((current_partition & 0xFF00) == 0xFF00
-@@ -458,7 +466,7 @@ make_saved_active (void)
+@@ -458,7 +469,7 @@ make_saved_active (void)
  	}
  
        /* Read the MBR in the scratch space.  */
@@ -41287,7 +41307,7 @@ index b9bc526..ee7300d 100644
  	return 0;
  
        /* If the partition is an extended partition, setting the active
-@@ -502,8 +510,8 @@ int
+@@ -502,8 +513,8 @@ int
  set_partition_hidden_flag (int hidden)
  {
    unsigned long part = 0xFFFFFF;
@@ -41298,7 +41318,7 @@ index b9bc526..ee7300d 100644
    char mbr[512];
    
    /* The drive must be a hard disk.  */
-@@ -524,8 +532,15 @@ set_partition_hidden_flag (int hidden)
+@@ -524,8 +535,15 @@ set_partition_hidden_flag (int hidden)
    /* Look for the partition.  */
    while (next_partition (current_drive, 0xFFFFFF, &part, &type,           
  			 &start, &len, &offset, &entry,
@@ -41316,7 +41336,7 @@ index b9bc526..ee7300d 100644
        if (part == current_partition)
  	{
  	  /* Found.  */
-@@ -577,11 +592,14 @@ next_partition (unsigned long drive, unsigned long dest,
+@@ -577,11 +595,14 @@ next_partition (unsigned long drive, unsigned long dest,
  		unsigned long *partition, int *type,
  		unsigned long *start, unsigned long *len,
  		unsigned long *offset, int *entry,
@@ -41332,7 +41352,7 @@ index b9bc526..ee7300d 100644
  
    /* Get next BSD partition in current PC slice.  */
    int next_bsd_partition (void)
-@@ -601,7 +619,7 @@ next_partition (unsigned long drive, unsigned long dest,
+@@ -601,7 +622,7 @@ next_partition (unsigned long drive, unsigned long dest,
  
  	  /* Read the BSD label.  */
  	  if (! rawread (drive, *start + BSD_LABEL_SECTOR,
@@ -41341,7 +41361,7 @@ index b9bc526..ee7300d 100644
  	    return 0;
  
  	  /* Check if it is valid.  */
-@@ -656,7 +674,7 @@ next_partition (unsigned long drive, unsigned long dest,
+@@ -656,7 +677,7 @@ next_partition (unsigned long drive, unsigned long dest,
  	}
  
        /* Read the MBR or the boot sector of the extended partition.  */
@@ -41350,7 +41370,7 @@ index b9bc526..ee7300d 100644
  	return 0;
  
        /* Check if it is valid.  */
-@@ -666,6 +684,40 @@ next_partition (unsigned long drive, unsigned long dest,
+@@ -666,6 +687,40 @@ next_partition (unsigned long drive, unsigned long dest,
  	  return 0;
  	}
  
@@ -41391,7 +41411,7 @@ index b9bc526..ee7300d 100644
        /* Increase the entry number.  */
        (*entry)++;
  
-@@ -710,6 +762,43 @@ next_partition (unsigned long drive, unsigned long dest,
+@@ -710,6 +765,43 @@ next_partition (unsigned long drive, unsigned long dest,
        return 1;
      }
  
@@ -41435,7 +41455,7 @@ index b9bc526..ee7300d 100644
    /* Start the body of this function.  */
    
  #ifndef STAGE1_5
-@@ -717,6 +806,9 @@ next_partition (unsigned long drive, unsigned long dest,
+@@ -717,6 +809,9 @@ next_partition (unsigned long drive, unsigned long dest,
      return 0;
  #endif
  
@@ -41445,7 +41465,7 @@ index b9bc526..ee7300d 100644
    /* If previous partition is a BSD partition or a PC slice which
       contains BSD partitions...  */
    if ((*partition != 0xFFFFFF && IS_PC_SLICE_TYPE_BSD (*type & 0xff))
-@@ -755,8 +847,11 @@ real_open_partition (int flags)
+@@ -755,8 +850,11 @@ real_open_partition (int flags)
    unsigned long dest_partition = current_partition;
    unsigned long part_offset;
    unsigned long ext_offset;
@@ -41458,7 +41478,7 @@ index b9bc526..ee7300d 100644
    int bsd_part, pc_slice;
  
    /* For simplicity.  */
-@@ -766,7 +861,8 @@ real_open_partition (int flags)
+@@ -766,7 +864,8 @@ real_open_partition (int flags)
        int ret = next_partition (current_drive, dest_partition,
  				&current_partition, &current_slice,
  				&part_start, &part_length,
@@ -41468,7 +41488,7 @@ index b9bc526..ee7300d 100644
        bsd_part = (current_partition >> 8) & 0xFF;
        pc_slice = current_partition >> 16;
        return ret;
-@@ -926,6 +1022,17 @@ open_partition (void)
+@@ -926,6 +1025,17 @@ open_partition (void)
    return real_open_partition (0);
  }
  
@@ -41486,7 +41506,7 @@ index b9bc526..ee7300d 100644
  
  #ifndef STAGE1_5
  /* XX used for device completion in 'set_device' and 'print_completions' */
-@@ -978,7 +1085,7 @@ set_device (char *device)
+@@ -978,7 +1088,7 @@ set_device (char *device)
        if (*device != ',' && *device != ')')
  	{
  	  char ch = *device;
@@ -41495,7 +41515,7 @@ index b9bc526..ee7300d 100644
  	  if (*device == 'f' || *device == 'h'
  	      || (*device == 'n' && network_ready)
  	      || (*device == 'c' && cdrom_drive != GRUB_INVALID_DRIVE))
-@@ -1002,14 +1109,14 @@ set_device (char *device)
+@@ -1002,14 +1112,14 @@ set_device (char *device)
  
  	  if ((*device == 'f'
  	       || *device == 'h'
@@ -41513,7 +41533,7 @@ index b9bc526..ee7300d 100644
  	  if (ch == 'n' && network_ready)
  	    current_drive = NETWORK_DRIVE;
  	  else
-@@ -1131,7 +1238,7 @@ set_bootdev (int hdbias)
+@@ -1131,7 +1241,7 @@ set_bootdev (int hdbias)
    if ((saved_drive & 0x80) && cur_part_addr)
      {
        if (rawread (saved_drive, cur_part_offset,
@@ -41522,7 +41542,7 @@ index b9bc526..ee7300d 100644
  	{
  	  char *dst, *src;
        
-@@ -1243,6 +1350,12 @@ setup_part (char *filename)
+@@ -1243,6 +1353,12 @@ setup_part (char *filename)
  
  
  #ifndef STAGE1_5
@@ -41535,7 +41555,7 @@ index b9bc526..ee7300d 100644
  /*
   *  This prints the filesystem type or gives relevant information.
   */
-@@ -1376,7 +1489,7 @@ print_completions (int is_filename, int is_completion)
+@@ -1376,7 +1492,7 @@ print_completions (int is_filename, int is_completion)
  
  	      if (!ptr
  		  || *(ptr-1) != 'd'
@@ -41544,7 +41564,7 @@ index b9bc526..ee7300d 100644
  		  || *(ptr-2) != 'n'
  #endif /* SUPPORT_NETBOOT */
  		  || *(ptr-2) != 'c')
-@@ -1385,7 +1498,7 @@ print_completions (int is_filename, int is_completion)
+@@ -1385,7 +1501,7 @@ print_completions (int is_filename, int is_completion)
  		       i < (ptr && (*(ptr-1) == 'd' && *(ptr-2) == 'f') ? 1:2);
  		       i++)
  		    {
@@ -41553,7 +41573,7 @@ index b9bc526..ee7300d 100644
  			{
  			  disk_no = (i * 0x80) + j;
  			  if ((disk_choice || disk_no == current_drive)
-@@ -1407,7 +1520,7 @@ print_completions (int is_filename, int is_completion)
+@@ -1407,7 +1523,7 @@ print_completions (int is_filename, int is_completion)
  		      || (*(ptr-1) == 'd' && *(ptr-2) == 'c')))
  		print_a_completion ("cd");
  
@@ -41562,7 +41582,7 @@ index b9bc526..ee7300d 100644
  	      if (network_ready
  		  && (disk_choice || NETWORK_DRIVE == current_drive)
  		  && (!ptr
-@@ -1596,7 +1709,7 @@ grub_open (char *filename)
+@@ -1596,7 +1712,7 @@ grub_open (char *filename)
  
  	  BLK_BLKLENGTH (list_addr) = tmp;
  
@@ -41571,7 +41591,7 @@ index b9bc526..ee7300d 100644
  	  list_addr += BLK_BLKLIST_INC_VAL;
  
  	  if (*ptr != ',')
-@@ -1673,6 +1786,7 @@ grub_read (char *buf, int len)
+@@ -1673,6 +1789,7 @@ grub_read (char *buf, int len)
    if (block_file)
      {
        int size, off, ret = 0;
@@ -41579,7 +41599,7 @@ index b9bc526..ee7300d 100644
  
        while (len && !errnum)
  	{
-@@ -1687,10 +1801,10 @@ grub_read (char *buf, int len)
+@@ -1687,10 +1804,10 @@ grub_read (char *buf, int len)
  	  /* run BLK_CUR_FILEPOS up to filepos */
  	  while (filepos > BLK_CUR_FILEPOS)
  	    {
@@ -41593,7 +41613,7 @@ index b9bc526..ee7300d 100644
  		  BLK_CUR_BLKNUM++;
  
  		  if (BLK_CUR_BLKNUM >= BLK_BLKLENGTH (BLK_CUR_BLKLIST))
-@@ -1703,9 +1817,9 @@ grub_read (char *buf, int len)
+@@ -1703,9 +1820,9 @@ grub_read (char *buf, int len)
  		BLK_CUR_FILEPOS = filepos;
  	    }
  
@@ -41646,10 +41666,27 @@ index 7fed6ba..f154eed 100644
  #define FAT_LONGDIR_ID(entry) \
    (*((unsigned char *) (entry)))
 diff --git a/stage2/filesys.h b/stage2/filesys.h
-index bbad8b9..4295e45 100644
+index bbad8b9..79e5f1f 100644
 --- a/stage2/filesys.h
 +++ b/stage2/filesys.h
-@@ -115,6 +115,17 @@ void tftp_close (void);
+@@ -40,6 +40,16 @@ int ufs2_embed (int *start_sector, int needed_sectors);
+ #define FSYS_UFS2_NUM 0
+ #endif
+ 
++#ifdef PLATFORM_EFI
++#define FSYS_UEFI_NUM 1
++int uefi_mount (void);
++int uefi_read (char *buf, int len);
++int uefi_dir (char *dirname);
++void uefi_close (void);
++#else
++#define FSYS_UEFI_NUM 0
++#endif
++
+ #ifdef FSYS_FAT
+ #define FSYS_FAT_NUM 1
+ int fat_mount (void);
+@@ -115,6 +125,17 @@ void tftp_close (void);
  #define FSYS_TFTP_NUM 0
  #endif
  
@@ -41667,16 +41704,17 @@ index bbad8b9..4295e45 100644
  #ifdef FSYS_ISO9660
  #define FSYS_ISO9660_NUM 1
  int iso9660_mount (void);
-@@ -128,7 +139,7 @@ int iso9660_dir (char *dirname);
+@@ -128,7 +149,8 @@ int iso9660_dir (char *dirname);
  #define NUM_FSYS	\
    (FSYS_FFS_NUM + FSYS_FAT_NUM + FSYS_EXT2FS_NUM + FSYS_MINIX_NUM	\
     + FSYS_REISERFS_NUM + FSYS_VSTAFS_NUM + FSYS_JFS_NUM + FSYS_XFS_NUM	\
 -   + FSYS_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM)
-+   + FSYS_TFTP_NUM + FSYS_EFI_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM)
++   + FSYS_TFTP_NUM + FSYS_EFI_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM \
++   + FSYS_UEFI_NUM)
  #endif
  
  /* defines for the block filesystem info area */
-@@ -137,8 +148,8 @@ int iso9660_dir (char *dirname);
+@@ -137,8 +159,8 @@ int iso9660_dir (char *dirname);
  #define BLK_CUR_BLKLIST      (*((int*)(FSYS_BUF+4)))
  #define BLK_CUR_BLKNUM       (*((int*)(FSYS_BUF+8)))
  #define BLK_MAX_ADDR         (FSYS_BUF+0x7FF9)
@@ -42678,6 +42716,208 @@ index 93ec5f8..f46fcb2 100644
    
    return (needed_sectors <= num_sectors);
  }
+diff --git a/stage2/fsys_uefi.c b/stage2/fsys_uefi.c
+new file mode 100644
+index 0000000..38ee614
+--- /dev/null
++++ b/stage2/fsys_uefi.c
+@@ -0,0 +1,196 @@
++/*
++ *  GRUB  --  GRand Unified Bootloader
++ *  Copyright (C) 2001   Free Software Foundation, Inc.
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
++ */
++
++#include "shared.h"
++#include "filesys.h"
++
++#ifdef PLATFORM_EFI
++#undef GRUB_UTIL
++
++#include <grub/types.h>
++#include <grub/misc.h>
++#include <grub/efi/efi.h>
++#include <grub/efi/misc.h>
++#include <grub/efi/api.h>
++
++static grub_efi_simple_file_system_t *file_system;
++static grub_efi_guid_t fsinfo_guid = GRUB_EFI_DEVICE_PATH_GUID;
++grub_efi_file_t *root = NULL;
++grub_efi_file_t *file = NULL;
++
++typedef struct {
++  grub_efi_uint64_t size;
++  grub_efi_uint64_t filesize;
++  grub_efi_uint64_t physicalsize;
++  grub_efi_time_t createtime;
++  grub_efi_time_t accesstime;
++  grub_efi_time_t modifytime;
++  grub_efi_uint64_t attribute;
++  grub_efi_char16_t filename[];
++} grub_efi_file_info_t;
++
++int 
++uefi_mount (void)
++{
++  grub_efi_handle_t dev_handle = grub_efidisk_get_current_bdev_handle();
++  grub_efi_status_t status;
++
++  if (!dev_handle)
++    return 0;
++  
++  file_system = grub_efi_open_protocol (dev_handle, &simple_file_system_guid,
++					GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
++
++  if (!file_system)
++    return 0;
++
++  status = Call_Service_2 (file_system->open_volume, file_system, &root);
++
++  if (status != GRUB_EFI_SUCCESS)
++    return 0;
++
++  return 1;
++}
++
++int 
++uefi_dir (char *dirname)
++{
++  grub_efi_status_t status;
++  grub_efi_char16_t *file_name_w = NULL;
++  grub_efi_char16_t *dir_name_w = NULL;
++  grub_efi_file_info_t *fileinfo = NULL;
++  grub_efi_uintn_t buffersize = 0;  
++  grub_efi_file_t *directory = NULL;
++  int i, dirlen = 0, ret = 0;
++
++  file_name_w = grub_malloc (2 * strlen(dirname) + 2);
++  if (!file_name_w)
++    goto done;
++
++  for (i=0; i<strlen(dirname); i++) {
++    file_name_w[i] = dirname[i];
++    if (file_name_w[i] == '/') {
++      file_name_w[i] = '\\';
++      dirlen = i;
++    }
++  }
++
++  file_name_w[i] = '\0';
++
++  dir_name_w = grub_malloc (2 * dirlen + 2);
++  if (!dir_name_w)
++    goto done;
++
++  for (i=0; i<dirlen; i++)
++    dir_name_w[i] = file_name_w[i];
++
++  dir_name_w[i] = '\0';
++
++  status = Call_Service_5 (root->open, root, &file, file_name_w,
++			   GRUB_EFI_FILE_MODE_READ, 0);
++
++  if (status != GRUB_EFI_SUCCESS)
++    goto done;
++
++  status = Call_Service_5 (root->open, root, &directory, dir_name_w,
++			   GRUB_EFI_FILE_MODE_READ, 0);
++
++  while (1) {
++    int filenamelen;
++    int invalid = 0;
++
++    status = Call_Service_3 (directory->read, directory, &buffersize, fileinfo);
++
++    if (status == GRUB_EFI_BUFFER_TOO_SMALL) {
++      fileinfo = grub_malloc(buffersize);
++      continue;
++    } else if (status) {
++      goto done;
++    }
++    if (buffersize == 0) {
++      goto done;
++    }
++
++    filenamelen = fileinfo->size - sizeof(*fileinfo);
++
++    if (filenamelen != ((strlen(dirname) - dirlen) * 2))
++      continue;
++
++    for (i=0; i<filenamelen/2; i++)
++      if (fileinfo->filename[i] != file_name_w[i + dirlen + 1])
++	invalid = 1;
++
++    if (!invalid)
++      break;
++  }
++
++  ret = 1;
++  filemax = fileinfo->filesize;
++  filepos = 0;
++
++ done:
++  if (fileinfo)
++    grub_free (fileinfo);
++  if (dir_name_w)
++    grub_free (dir_name_w);
++  if (file_name_w)
++    grub_free (file_name_w);
++
++  return ret;
++}
++
++void
++uefi_close (void)
++{
++  grub_efi_status_t status = 0;
++
++  if (file)
++    status = Call_Service_1 (file->close, file);
++
++  file = NULL;
++}
++
++int 
++uefi_read (char *addr, int len)
++{
++  grub_efi_status_t status;
++  grub_efi_uintn_t length = len;
++
++  errnum = 0;
++
++  status = Call_Service_2 (file->set_position, file, filepos);
++
++  if (status != GRUB_EFI_SUCCESS)
++    goto out;
++
++  status = Call_Service_3 (file->read, file, &length, addr);
++  
++  len = length;
++
++  if (status == GRUB_EFI_SUCCESS) {
++    filepos += len;
++    return len;
++  }
++
++ out:
++  errnum = ERR_FILE_NOT_FOUND;
++
++  return 0;
++}
++#endif
 diff --git a/stage2/fsys_vstafs.c b/stage2/fsys_vstafs.c
 index a116717..652e784 100644
 --- a/stage2/fsys_vstafs.c
@@ -45308,7 +45548,7 @@ index 0000000..ff6cd26
 +}
 +#endif
 diff --git a/stage2/shared.h b/stage2/shared.h
-index 77eef11..a82067b 100644
+index 77eef11..b56b44b 100644
 --- a/stage2/shared.h
 +++ b/stage2/shared.h
 @@ -35,9 +35,10 @@
@@ -45393,6 +45633,15 @@ index 77eef11..a82067b 100644
  /* Stage 2 identifiers */
  #define STAGE2_ID_STAGE2		0
  #define STAGE2_ID_FFS_STAGE1_5		1
+@@ -360,7 +367,7 @@ extern char *grub_scratch_mem;
+ #define memcpy grub_memmove	/* we don't need a separate memcpy */
+ #define memset grub_memset
+ #define isspace grub_isspace
+-#define printf grub_printf
++#define printf(format...) grub_printf(format)
+ #define sprintf grub_sprintf
+ #undef putchar
+ #define putchar grub_putchar
 @@ -371,14 +378,24 @@ extern char *grub_scratch_mem;
  #define tolower grub_tolower
  #define strlen grub_strlen
diff --git a/grub.spec b/grub.spec
index edea7ea..c50a61c 100644
--- a/grub.spec
+++ b/grub.spec
@@ -1,6 +1,6 @@
 Name: grub
 Version: 0.97
-Release: 85%{?dist}
+Release: 86%{?dist}
 Epoch: 1
 Summary: Grand Unified Boot Loader.
 Group: System Environment/Base
@@ -24,9 +24,8 @@ Source0: ftp://alpha.gnu.org/gnu/%{name}/%{name}-%{version}.tar.gz
 
 # This is from
 # http://git.kernel.org/?p=boot/grub-fedora/grub-fedora.git;a=summary
-Patch0: grub-fedora-16.patch
-Patch1: 0001-Fall-back-to-old-efi-GOP-detection-behavior.patch
-Patch2: 0001-Fix-strange-compilation-problem.patch
+Patch0: grub-fedora-17.patch
+Patch1: 0001-Fix-strange-compilation-problem.patch
 
 %description
 GRUB (Grand Unified Boot Loader) is an experimental boot loader
@@ -121,6 +120,9 @@ fi
 /sbin/grub-crypt
 
 %changelog
+* Thu Feb 09 2012 Peter Jones <pjones at redhat.com> - 0.97-86
+- Add EFI filesystem stuff for mac booting.
+
 * Fri Jan 13 2012 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1:0.97-85
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild
 


More information about the scm-commits mailing list