]> code.delx.au - refind/commitdiff
Applied old rEFIt commits r467 and r472, which improve Mac legacy
authorsrs5694 <srs5694@users.sourceforge.net>
Fri, 9 Jan 2015 01:09:46 +0000 (20:09 -0500)
committersrs5694 <srs5694@users.sourceforge.net>
Fri, 9 Jan 2015 01:09:46 +0000 (20:09 -0500)
boots from other than the first disk and add support for BMPs with
negative height fields, respectively.

NEWS.txt
libeg/load_bmp.c
refind/main.c

index 0a1dbcf34627c9e736017e7d8f8719627968022b..3d2313716b47193ee0f9ab7d80a586547477e4a1 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,11 +1,19 @@
-0.8.5 (??/??/201?):
+0.8.5 (??/??/2015):
 -------------------
 
 - Improved install.sh to make it smarter about figuring out where to
   install on Macs.
 
 -------------------
 
 - Improved install.sh to make it smarter about figuring out where to
   install on Macs.
 
-- Added missing check of architecture type for MOK and memory test
-  utilities.
+- Added missing check of architecture type for several tools.
+
+- Applied rEFIt commit r472, which adds support for BMP images with negative
+  height fields, indicating that the image is NOT vertically flipped. This
+  commit and r467 were not incorporated in the original rEFInd because I
+  forked it from a Debian rEFIt package that had been patched to build
+  under GNU-EFI, and was apparently based on a slightly earlier version.
+
+- Applied rEFIt commit r467, which improves Mac handling of legacy boots
+  from other than the first hard disk.
 
 
 0.8.4 (12/8/2014):
 
 
 0.8.4 (12/8/2014):
index a836e6e2d9b5107ed1f94cda118857bbf8565788..24fec9f5483cccfc0e2f43b12733255453f9e82b 100644 (file)
@@ -51,20 +51,20 @@ typedef struct {
 typedef struct {
     CHAR8         CharB;
     CHAR8         CharM;
 typedef struct {
     CHAR8         CharB;
     CHAR8         CharM;
-    UINT32        Size;
-    UINT16        Reserved[2];
-    UINT32        ImageOffset;
-    UINT32        HeaderSize;
-    UINT32        PixelWidth;
-    UINT32        PixelHeight;
-    UINT16        Planes;       // Must be 1
-    UINT16        BitPerPixel;  // 1, 4, 8, or 24
-    UINT32        CompressionType;
-    UINT32        ImageSize;    // Compressed image size in bytes
-    UINT32        XPixelsPerMeter;
-    UINT32        YPixelsPerMeter;
-    UINT32        NumberOfColors;
-    UINT32        ImportantColors;
+    INT32         Size;
+    INT16         Reserved[2];
+    INT32         ImageOffset;
+    INT32         HeaderSize;
+    INT32         PixelWidth;
+    INT32         PixelHeight;
+    INT16         Planes;       // Must be 1
+    INT16         BitPerPixel;  // 1, 4, 8, or 24
+    INT32         CompressionType;
+    INT32         ImageSize;    // Compressed image size in bytes
+    INT32         XPixelsPerMeter;
+    INT32         YPixelsPerMeter;
+    INT32         NumberOfColors;
+    INT32         ImportantColors;
 } BMP_IMAGE_HEADER;
 
 #pragma pack()
 } BMP_IMAGE_HEADER;
 
 #pragma pack()
@@ -82,8 +82,9 @@ EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
     UINTN               x, y;
     UINT8               *ImagePtr;
     UINT8               *ImagePtrBase;
     UINTN               x, y;
     UINT8               *ImagePtr;
     UINT8               *ImagePtrBase;
-    UINTN               ImageLineOffset;
+    UINTN               PixelWidth, PixelHeight, ImageLineOffset;
     UINT8               ImageValue = 0, AlphaValue;
     UINT8               ImageValue = 0, AlphaValue;
+    BOOLEAN             UpsideDown;
     EG_PIXEL            *PixelPtr;
     UINTN               Index, BitIndex;
 
     EG_PIXEL            *PixelPtr;
     UINTN               Index, BitIndex;
 
@@ -98,9 +99,19 @@ EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
     if (BmpHeader->BitPerPixel != 1 && BmpHeader->BitPerPixel != 4 &&
         BmpHeader->BitPerPixel != 8 && BmpHeader->BitPerPixel != 24)
         return NULL;
     if (BmpHeader->BitPerPixel != 1 && BmpHeader->BitPerPixel != 4 &&
         BmpHeader->BitPerPixel != 8 && BmpHeader->BitPerPixel != 24)
         return NULL;
+    if (BmpHeader->PixelWidth < 1 || BmpHeader->PixelWidth > 4096 ||
+        BmpHeader->PixelHeight < -4096 || BmpHeader->PixelHeight == 0 ||
+        BmpHeader->PixelHeight > 4096)
+        return NULL;
 
     // calculate parameters
 
     // calculate parameters
-    ImageLineOffset = BmpHeader->PixelWidth;
+    PixelWidth = BmpHeader->PixelWidth;
+    UpsideDown = BmpHeader->PixelHeight >= 0;
+    if (BmpHeader->PixelHeight < 0)
+        PixelHeight = -BmpHeader->PixelHeight;
+    else
+        PixelHeight = BmpHeader->PixelHeight;
+    ImageLineOffset = PixelWidth;
     if (BmpHeader->BitPerPixel == 24)
         ImageLineOffset *= 3;
     else if (BmpHeader->BitPerPixel == 1)
     if (BmpHeader->BitPerPixel == 24)
         ImageLineOffset *= 3;
     else if (BmpHeader->BitPerPixel == 1)
@@ -110,11 +121,11 @@ EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
     if ((ImageLineOffset % 4) != 0)
         ImageLineOffset = ImageLineOffset + (4 - (ImageLineOffset % 4));
     // check bounds
     if ((ImageLineOffset % 4) != 0)
         ImageLineOffset = ImageLineOffset + (4 - (ImageLineOffset % 4));
     // check bounds
-    if (BmpHeader->ImageOffset + ImageLineOffset * BmpHeader->PixelHeight > FileDataLength)
+    if (BmpHeader->ImageOffset + ImageLineOffset * PixelHeight > FileDataLength)
         return NULL;
 
     // allocate image structure and buffer
         return NULL;
 
     // allocate image structure and buffer
-    NewImage = egCreateImage(BmpHeader->PixelWidth, BmpHeader->PixelHeight, WantAlpha);
+    NewImage = egCreateImage(PixelWidth, PixelHeight, WantAlpha);
     if (NewImage == NULL)
         return NULL;
     AlphaValue = WantAlpha ? 255 : 0;
     if (NewImage == NULL)
         return NULL;
     AlphaValue = WantAlpha ? 255 : 0;
@@ -122,15 +133,18 @@ EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
     // convert image
     BmpColorMap = (BMP_COLOR_MAP *)(FileData + sizeof(BMP_IMAGE_HEADER));
     ImagePtrBase = FileData + BmpHeader->ImageOffset;
     // convert image
     BmpColorMap = (BMP_COLOR_MAP *)(FileData + sizeof(BMP_IMAGE_HEADER));
     ImagePtrBase = FileData + BmpHeader->ImageOffset;
-    for (y = 0; y < BmpHeader->PixelHeight; y++) {
+    for (y = 0; y < PixelHeight; y++) {
         ImagePtr = ImagePtrBase;
         ImagePtrBase += ImageLineOffset;
         ImagePtr = ImagePtrBase;
         ImagePtrBase += ImageLineOffset;
-        PixelPtr = NewImage->PixelData + (BmpHeader->PixelHeight - 1 - y) * BmpHeader->PixelWidth;
+        if (UpsideDown)
+            PixelPtr = NewImage->PixelData + (PixelHeight - 1 - y) * PixelWidth;
+        else
+            PixelPtr = NewImage->PixelData + y * PixelWidth;
         
         switch (BmpHeader->BitPerPixel) {
             
             case 1:
         
         switch (BmpHeader->BitPerPixel) {
             
             case 1:
-                for (x = 0; x < BmpHeader->PixelWidth; x++) {
+                for (x = 0; x < PixelWidth; x++) {
                     BitIndex = x & 0x07;
                     if (BitIndex == 0)
                         ImageValue = *ImagePtr++;
                     BitIndex = x & 0x07;
                     if (BitIndex == 0)
                         ImageValue = *ImagePtr++;
@@ -145,7 +159,7 @@ EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
                 break;
             
             case 4:
                 break;
             
             case 4:
-                for (x = 0; x <= BmpHeader->PixelWidth - 2; x += 2) {
+                for (x = 0; x <= PixelWidth - 2; x += 2) {
                     ImageValue = *ImagePtr++;
                     
                     Index = ImageValue >> 4;
                     ImageValue = *ImagePtr++;
                     
                     Index = ImageValue >> 4;
@@ -162,7 +176,7 @@ EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
                     PixelPtr->a = AlphaValue;
                     PixelPtr++;
                 }
                     PixelPtr->a = AlphaValue;
                     PixelPtr++;
                 }
-                if (x < BmpHeader->PixelWidth) {
+                if (x < PixelWidth) {
                     ImageValue = *ImagePtr++;
                     
                     Index = ImageValue >> 4;
                     ImageValue = *ImagePtr++;
                     
                     Index = ImageValue >> 4;
@@ -175,7 +189,7 @@ EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
                 break;
             
             case 8:
                 break;
             
             case 8:
-                for (x = 0; x < BmpHeader->PixelWidth; x++) {
+                for (x = 0; x < PixelWidth; x++) {
                     Index = *ImagePtr++;
                     PixelPtr->b = BmpColorMap[Index].Blue;
                     PixelPtr->g = BmpColorMap[Index].Green;
                     Index = *ImagePtr++;
                     PixelPtr->b = BmpColorMap[Index].Blue;
                     PixelPtr->g = BmpColorMap[Index].Green;
@@ -186,7 +200,7 @@ EG_IMAGE * egDecodeBMP(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
                 break;
             
             case 24:
                 break;
             
             case 24:
-                for (x = 0; x < BmpHeader->PixelWidth; x++) {
+                for (x = 0; x < PixelWidth; x++) {
                     PixelPtr->b = *ImagePtr++;
                     PixelPtr->g = *ImagePtr++;
                     PixelPtr->r = *ImagePtr++;
                     PixelPtr->b = *ImagePtr++;
                     PixelPtr->g = *ImagePtr++;
                     PixelPtr->r = *ImagePtr++;
@@ -234,11 +248,11 @@ VOID egEncodeBMP(IN EG_IMAGE *Image, OUT UINT8 **FileDataReturn, OUT UINTN *File
     BmpHeader = (BMP_IMAGE_HEADER *)FileData;
     BmpHeader->CharB = 'B';
     BmpHeader->CharM = 'M';
     BmpHeader = (BMP_IMAGE_HEADER *)FileData;
     BmpHeader->CharB = 'B';
     BmpHeader->CharM = 'M';
-    BmpHeader->Size = FileDataLength;
+    BmpHeader->Size = (INT32)FileDataLength;
     BmpHeader->ImageOffset = sizeof(BMP_IMAGE_HEADER);
     BmpHeader->HeaderSize = 40;
     BmpHeader->ImageOffset = sizeof(BMP_IMAGE_HEADER);
     BmpHeader->HeaderSize = 40;
-    BmpHeader->PixelWidth = Image->Width;
-    BmpHeader->PixelHeight = Image->Height;
+    BmpHeader->PixelWidth = (INT32)Image->Width;
+    BmpHeader->PixelHeight = (INT32)Image->Height;
     BmpHeader->Planes = 1;
     BmpHeader->BitPerPixel = 24;
     BmpHeader->CompressionType = 0;
     BmpHeader->Planes = 1;
     BmpHeader->BitPerPixel = 24;
     BmpHeader->CompressionType = 0;
index 1598463af2929fb9599186174f689c6b203e5483..76241e52d8df3279104d3b49c3316e4c45ed89eb 100644 (file)
@@ -176,7 +176,7 @@ static VOID AboutrEFInd(VOID)
 
     if (AboutMenu.EntryCount == 0) {
         AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
 
     if (AboutMenu.EntryCount == 0) {
         AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
-        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.8.4.1");
+        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.8.4.2");
         AddMenuInfoLine(&AboutMenu, L"");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012-2014 Roderick W. Smith");
         AddMenuInfoLine(&AboutMenu, L"");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012-2014 Roderick W. Smith");
@@ -1646,6 +1646,21 @@ static EFI_STATUS ActivateMbrPartition(IN EFI_BLOCK_IO *BlockIO, IN UINTN Partit
     return EFI_SUCCESS;
 } /* static EFI_STATUS ActivateMbrPartition() */
 
     return EFI_SUCCESS;
 } /* static EFI_STATUS ActivateMbrPartition() */
 
+static EFI_GUID AppleVariableVendorID = { 0x7C436110, 0xAB2A, 0x4BBB, 0xA8, 0x80, 0xFE, 0x41, 0x99, 0x5C, 0x9F, 0x82 };
+
+static EFI_STATUS WriteBootDiskHint(IN EFI_DEVICE_PATH *WholeDiskDevicePath)
+{
+   EFI_STATUS          Status;
+
+   Status = refit_call5_wrapper(RT->SetVariable, L"BootCampHD", &AppleVariableVendorID,
+                                EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+                                GetDevicePathSize(WholeDiskDevicePath), WholeDiskDevicePath);
+   if (EFI_ERROR(Status))
+      return Status;
+
+   return EFI_SUCCESS;
+}
+
 // early 2006 Core Duo / Core Solo models
 static UINT8 LegacyLoaderDevicePath1Data[] = {
     0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
 // early 2006 Core Duo / Core Solo models
 static UINT8 LegacyLoaderDevicePath1Data[] = {
     0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
@@ -1719,9 +1734,11 @@ static VOID StartLegacy(IN LEGACY_ENTRY *Entry, IN CHAR16 *SelectionName)
                       (UGAHeight - BootLogoImage->Height) >> 1,
                       &StdBackgroundPixel);
 
                       (UGAHeight - BootLogoImage->Height) >> 1,
                       &StdBackgroundPixel);
 
-    if (Entry->Volume->IsMbrPartition) {
+    if (Entry->Volume->IsMbrPartition)
         ActivateMbrPartition(Entry->Volume->WholeDiskBlockIO, Entry->Volume->MbrPartitionIndex);
         ActivateMbrPartition(Entry->Volume->WholeDiskBlockIO, Entry->Volume->MbrPartitionIndex);
-    }
+
+    if (Entry->Volume->DiskKind != DISK_KIND_OPTICAL && Entry->Volume->WholeDiskDevicePath != NULL)
+       WriteBootDiskHint(Entry->Volume->WholeDiskDevicePath);
 
     ExtractLegacyLoaderPaths(DiscoveredPathList, MAX_DISCOVERED_PATHS, LegacyLoaderList);
 
 
     ExtractLegacyLoaderPaths(DiscoveredPathList, MAX_DISCOVERED_PATHS, LegacyLoaderList);
 
@@ -2419,7 +2436,7 @@ static VOID ScanForTools(VOID) {
          case TAG_SHELL:
             j = 0;
             while ((FileName = FindCommaDelimited(SHELL_NAMES, j++)) != NULL) {
          case TAG_SHELL:
             j = 0;
             while ((FileName = FindCommaDelimited(SHELL_NAMES, j++)) != NULL) {
-               if (FileExists(SelfRootDir, FileName)) {
+               if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
                   AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"EFI Shell", BuiltinIcon(BUILTIN_ICON_TOOL_SHELL),
                                'S', FALSE);
                }
                   AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"EFI Shell", BuiltinIcon(BUILTIN_ICON_TOOL_SHELL),
                                'S', FALSE);
                }
@@ -2430,7 +2447,7 @@ static VOID ScanForTools(VOID) {
          case TAG_GPTSYNC:
             j = 0;
             while ((FileName = FindCommaDelimited(GPTSYNC_NAMES, j++)) != NULL) {
          case TAG_GPTSYNC:
             j = 0;
             while ((FileName = FindCommaDelimited(GPTSYNC_NAMES, j++)) != NULL) {
-               if (FileExists(SelfRootDir, FileName)) {
+               if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
                   AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"Hybrid MBR tool", BuiltinIcon(BUILTIN_ICON_TOOL_PART),
                                'P', FALSE);
                } // if
                   AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"Hybrid MBR tool", BuiltinIcon(BUILTIN_ICON_TOOL_PART),
                                'P', FALSE);
                } // if
@@ -2442,7 +2459,7 @@ static VOID ScanForTools(VOID) {
          case TAG_GDISK:
             j = 0;
             while ((FileName = FindCommaDelimited(GDISK_NAMES, j++)) != NULL) {
          case TAG_GDISK:
             j = 0;
             while ((FileName = FindCommaDelimited(GDISK_NAMES, j++)) != NULL) {
-               if (FileExists(SelfRootDir, FileName)) {
+               if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
                   AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"disk partitioning tool",
                                BuiltinIcon(BUILTIN_ICON_TOOL_PART), 'G', FALSE);
                } // if
                   AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"disk partitioning tool",
                                BuiltinIcon(BUILTIN_ICON_TOOL_PART), 'G', FALSE);
                } // if
@@ -2454,7 +2471,7 @@ static VOID ScanForTools(VOID) {
          case TAG_NETBOOT:
             j = 0;
             while ((FileName = FindCommaDelimited(NETBOOT_NAMES, j++)) != NULL) {
          case TAG_NETBOOT:
             j = 0;
             while ((FileName = FindCommaDelimited(NETBOOT_NAMES, j++)) != NULL) {
-               if (FileExists(SelfRootDir, FileName)) {
+               if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
                   AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"Netboot",
                                BuiltinIcon(BUILTIN_ICON_TOOL_NETBOOT), 'N', FALSE);
                } // if
                   AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"Netboot",
                                BuiltinIcon(BUILTIN_ICON_TOOL_NETBOOT), 'N', FALSE);
                } // if
@@ -2466,7 +2483,8 @@ static VOID ScanForTools(VOID) {
          case TAG_APPLE_RECOVERY:
             FileName = StrDuplicate(L"\\com.apple.recovery.boot\\boot.efi");
             for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
          case TAG_APPLE_RECOVERY:
             FileName = StrDuplicate(L"\\com.apple.recovery.boot\\boot.efi");
             for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
-               if ((Volumes[VolumeIndex]->RootDir != NULL) && (FileExists(Volumes[VolumeIndex]->RootDir, FileName))) {
+               if ((Volumes[VolumeIndex]->RootDir != NULL) && (FileExists(Volumes[VolumeIndex]->RootDir, FileName)) &&
+                   IsValidLoader(Volumes[VolumeIndex]->RootDir, FileName)) {
                   SPrint(Description, 255, L"Apple Recovery on %s", Volumes[VolumeIndex]->VolName);
                   AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, FileName, Description,
                                BuiltinIcon(BUILTIN_ICON_TOOL_APPLE_RESCUE), 'R', TRUE);
                   SPrint(Description, 255, L"Apple Recovery on %s", Volumes[VolumeIndex]->VolName);
                   AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, FileName, Description,
                                BuiltinIcon(BUILTIN_ICON_TOOL_APPLE_RESCUE), 'R', TRUE);
@@ -2482,6 +2500,7 @@ static VOID ScanForTools(VOID) {
                SplitVolumeAndFilename(&FileName, &VolName);
                for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
                   if ((Volumes[VolumeIndex]->RootDir != NULL) && (FileExists(Volumes[VolumeIndex]->RootDir, FileName)) &&
                SplitVolumeAndFilename(&FileName, &VolName);
                for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
                   if ((Volumes[VolumeIndex]->RootDir != NULL) && (FileExists(Volumes[VolumeIndex]->RootDir, FileName)) &&
+                      IsValidLoader(Volumes[VolumeIndex]->RootDir, FileName) &&
                       ((VolName == NULL) || (StriCmp(VolName, Volumes[VolumeIndex]->VolName) == 0))) {
                      SPrint(Description, 255, L"Microsoft Recovery on %s", Volumes[VolumeIndex]->VolName);
                      AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, FileName, Description,
                       ((VolName == NULL) || (StriCmp(VolName, Volumes[VolumeIndex]->VolName) == 0))) {
                      SPrint(Description, 255, L"Microsoft Recovery on %s", Volumes[VolumeIndex]->VolName);
                      AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, FileName, Description,