Skip to content

Commit

Permalink
Compatibility for EFI Device Paths
Browse files Browse the repository at this point in the history
Some EFI device paths have an ending node with type 0xFF instead of the usual 0x7F. Since 0xFF is not a valid type for UEFI, gfxutil should assume that it is an end type.
gfxutil.xscheme has an example device path.
  • Loading branch information
joevt authored and vit9696 committed Jun 5, 2021
1 parent 7bd92cc commit 0b636b9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
23 changes: 23 additions & 0 deletions edk2misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ typedef struct {
} PATCHED_SASEX_DEVICE_PATH;


BOOLEAN
EFIAPI
OldIsDevicePathEndType (
IN CONST VOID *Node
);

BOOLEAN
EFIAPI
IsDevicePathEndType (
IN CONST VOID *Node
)
{
ASSERT (Node != NULL);
return (BOOLEAN) ((DevicePathType (Node) & EFI_DP_TYPE_MASK) == END_DEVICE_PATH_TYPE);
}

VOID
OldDevPathToTextSasEx (
IN OUT POOL_PRINT *Str,
Expand Down Expand Up @@ -327,6 +343,10 @@ const DEVICE_NODE_TO_SIZE NodeSize[] = {
{BBS_DEVICE_PATH , BBS_BBS_DP , psize(Bbs) , 0, 0 },
{END_DEVICE_PATH_TYPE , END_INSTANCE_DEVICE_PATH_SUBTYPE , psize(DevPath) , 0, 0 },
{END_DEVICE_PATH_TYPE , END_ENTIRE_DEVICE_PATH_SUBTYPE , psize(DevPath) , 0, 0 },
{EFI_DP_TYPE_UNPACKED +
END_DEVICE_PATH_TYPE , END_INSTANCE_DEVICE_PATH_SUBTYPE , psize(DevPath) , 0, 0 },
{EFI_DP_TYPE_UNPACKED +
END_DEVICE_PATH_TYPE , END_ENTIRE_DEVICE_PATH_SUBTYPE , psize(DevPath) , 0, 0 },
{0 , 0 , psize(DevPath) , 1, 1 },
};

Expand Down Expand Up @@ -377,6 +397,9 @@ void VerifyDevicePathNodeSizes(VOID * DevicePath) {
}

if (IsDevicePathEnd (Node)) {
if (!OldIsDevicePathEndType (Node)) {
fprintf(stderr, "End node at offset %ld has type 0xFF which is valid for EFI but not UEFI.\n", (void*)Node-(void*)DevicePath);
}
break;
}
Node = NextDevicePathNode (Node);
Expand Down
4 changes: 4 additions & 0 deletions edk2misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#include "UefiDevicePathLib.h"

#define EFI_DP_TYPE_MASK 0x7F
#define EFI_DP_TYPE_UNPACKED 0x80


EFI_STATUS
EFIAPI
UefiBootServicesTableLibConstructor (void);
Expand Down
2 changes: 1 addition & 1 deletion efidevp.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int OutputDevicePathUtilFromText(void* asciitextpath, unsigned long asciitextpat
{
int nodelen = node->Length[0] | node->Length[1] << 8;
bytepathlen += nodelen;
if (node->Type == END_DEVICE_PATH_TYPE && node->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE) break;
if ((node->Type & EFI_DP_TYPE_MASK) == END_DEVICE_PATH_TYPE && node->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE) break;
node = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8*)node + nodelen);
}
PrintMem (bytepath, bytepathlen);
Expand Down
4 changes: 4 additions & 0 deletions gfxutil.xcodeproj/xcshareddata/xcschemes/gfxutil.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
argument = "02010c00d041030a0000000001010600001b0101060000000316100001000000000000000000000004012a0002000000062c0100000000004d7d000100000000e7f9c0ca664da545b0bd10a52e34ec5d020204032400f7fc74be7c0bf349914701f4042e68426c5c2fe7555cc34aaabf0209eb2185077fff0400"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "04061400CA98B835A9B6CE498C72904735CC49B7FFFF04007074616C380000000000000000000000000000000000000000000000000000000000000000000000"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-vsn -o xml -i bin deviceproperties.bin deviceproperties.plist"
isEnabled = "NO">
Expand Down

0 comments on commit 0b636b9

Please sign in to comment.