summaryrefslogtreecommitdiff
path: root/auto_boot.patch
blob: 017bb8f6f474db0a305c10fca8208b0c22d03e9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--- a/ArmPlatformPkg/Bds/BootOption.c
+++ b/ArmPlatformPkg/Bds/BootOption.c
@@ -14,6 +14,13 @@
 
 #include "BdsInternal.h"
 
+//CHANGE -- START
+#include <Library/DxeServicesTableLib.h>
+#include <Protocol/BlockIo.h>
+#include <Guid/DebugImageInfoTable.h>
+#include <Protocol/DevicePathToText.h>
+//CHANGE -- END
+
 extern EFI_HANDLE mImageHandle;
 
 EFI_STATUS
@@ -34,6 +41,17 @@
   EFI_DEVICE_PATH*                      Initrd;
   UINT16                                LoadOptionIndexSize;
 
+//CHANGE -- START
+  UINTN                     HandleCount;
+  EFI_HANDLE                *HandleBuffer;
+  UINTN                     Index;
+  //CHAR16*                   String;
+  //EFI_DEVICE_PATH_PROTOCOL* DevicePathProtocol;
+  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL*  DevicePathToTextProtocol;
+  EFI_DEVICE_PATH_PROTOCOL  *LoadImageDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL  *FileSystemDevicePath;
+//CHANGE -- END
+
   if (IS_ARM_BDS_BOOTENTRY (BootOption)) {
     Status = EFI_UNSUPPORTED;
     OptionalData = BootOption->OptionalData;
@@ -55,9 +73,72 @@
         Initrd = NULL;
       }
 
+//CHANGE CODE -- START
+    do {
+    // Locate all the driver handles
+    Status = gBS->LocateHandleBuffer (
+                AllHandles,
+                NULL,
+                NULL,
+                &HandleCount,
+                &HandleBuffer
+                );
+    if (EFI_ERROR (Status)) {
+      break;
+    }
+
+    // Connect every handles
+    for (Index = 0; Index < HandleCount; Index++) {
+      gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
+    }
+
+    if (HandleBuffer != NULL) {
+      FreePool (HandleBuffer);
+    }
+
+    // Check if new handles have been created after the start of the previous handles
+    Status = gDS->Dispatch ();
+  } while (!EFI_ERROR(Status));
+
+
+  Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
+  if (EFI_ERROR (Status)) {
+    AsciiPrint ("Did not find the DevicePathToTextProtocol.\n");
+    return Status;
+  }
+
+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &HandleCount, &HandleBuffer);
+  if (EFI_ERROR (Status)) {
+    AsciiPrint ("No device path found\n");
+    return Status;
+  }
+
+  /*for (Index = 0; Index < HandleCount; Index++) {
+    Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);
+    String = DevicePathToTextProtocol->ConvertDevicePathToText(DevicePathProtocol,TRUE,TRUE);
+    Print (L"[0x%X] %s\n",(UINT32)HandleBuffer[Index], String);
+  }*/
+
+  for (Index = 0; Index < HandleCount; Index++) {
+    //Get the device path
+    FileSystemDevicePath = DevicePathFromHandle(HandleBuffer[Index]);
+    if (FileSystemDevicePath == NULL) {
+      continue;
+    }
+
+    //Check if zImage file on SD-MMC.
+    LoadImageDevicePath = FileDevicePath(HandleBuffer[Index], L"uImage");
+    Status = BdsBootLinuxAtag (LoadImageDevicePath, Initrd, (CHAR8*)(LinuxArguments + 1));
+    if (EFI_ERROR(Status)) {
+      continue;
+    }
+  }
+//CHANGE CODE -- END
+#if 0 //remove while removing CHANGE CODE
       Status = BdsBootLinuxAtag (BootOption->FilePathList,
                                  Initrd, // Initrd
                                  (CHAR8*)(LinuxArguments + 1)); // CmdLine
+#endif
     } else if (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT) {
       LinuxArguments = &(OptionalData->Arguments.LinuxArguments);
       CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);