]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/ArmJunoPkg: Create two default boot entries on first boot on Juno R1
authorOlivier Martin <olivier.martin@arm.com>
Thu, 26 Feb 2015 11:04:52 +0000 (11:04 +0000)
committeroliviermartin <oliviermartin@Edk2>
Thu, 26 Feb 2015 11:04:52 +0000 (11:04 +0000)
Juno R1 can run in two configurations:
- A57x2
- A57x2-A53x4

The Device Tree tell Linux which configuration has been selected.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16942 6f19259b-4bc3-4df7-8a09-765794883524

ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.inf

index 4b91f1ee06d94c8497608d403f9f2839b934e3f0..e94047ab8b3fbbcaaaaebe2c70c2003baae7c6a0 100644 (file)
 **/\r
 \r
 #include "ArmJunoDxeInternal.h"\r
+\r
+#include <Protocol/DevicePathFromText.h>\r
+\r
+#include <Guid/GlobalVariable.h>\r
+\r
 #include <Library/ArmShellCmdLib.h>\r
 #include <Library/AcpiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
 \r
 // This GUID must match the FILE_GUID in ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf\r
 STATIC CONST EFI_GUID mJunoAcpiTableFile = { 0xa1dd808e, 0x1e95, 0x4399, { 0xab, 0xc0, 0x65, 0x3c, 0x82, 0xe8, 0x53, 0x0c } };\r
 \r
+/**\r
+ * Build and Set UEFI Variable Boot####\r
+ *\r
+ * @param BootVariableName       Name of the UEFI Variable\r
+ * @param Attributes             'Attributes' for the Boot#### variable as per UEFI spec\r
+ * @param BootDescription        Description of the Boot#### variable\r
+ * @param DevicePath             EFI Device Path of the EFI Application to boot\r
+ * @param OptionalData           Parameters to pass to the EFI application\r
+ * @param OptionalDataSize       Size of the parameters to pass to the EFI application\r
+ *\r
+ * @return EFI_OUT_OF_RESOURCES  A memory allocation failed\r
+ * @return                       Return value of RT.SetVariable\r
+ */\r
+STATIC\r
+EFI_STATUS\r
+BootOptionCreate (\r
+  IN  CHAR16                    BootVariableName[9],\r
+  IN  UINT32                    Attributes,\r
+  IN  CHAR16*                   BootDescription,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,\r
+  IN  UINT8*                    OptionalData,\r
+  IN  UINTN                     OptionalDataSize\r
+  )\r
+{\r
+  UINTN                         VariableSize;\r
+  UINT8                         *Variable;\r
+  UINT8                         *VariablePtr;\r
+  UINTN                         FilePathListLength;\r
+  UINTN                         BootDescriptionSize;\r
+\r
+  FilePathListLength  = GetDevicePathSize (DevicePath);\r
+  BootDescriptionSize = StrSize (BootDescription);\r
+\r
+  // Each Boot#### variable is built as follow:\r
+  //   UINT32                   Attributes\r
+  //   UINT16                   FilePathListLength\r
+  //   CHAR16*                  Description\r
+  //   EFI_DEVICE_PATH_PROTOCOL FilePathList[]\r
+  //   UINT8                    OptionalData[]\r
+  VariableSize = sizeof (UINT32) + sizeof (UINT16) +\r
+      BootDescriptionSize + FilePathListLength + OptionalDataSize;\r
+  Variable = AllocateZeroPool (VariableSize);\r
+  if (Variable == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  // 'Attributes' field\r
+  *(UINT32*)Variable = Attributes;\r
+  // 'FilePathListLength' field\r
+  VariablePtr = Variable + sizeof (UINT32);\r
+  *(UINT16*)VariablePtr = FilePathListLength;\r
+  // 'Description' field\r
+  VariablePtr += sizeof (UINT16);\r
+  CopyMem (VariablePtr, BootDescription, BootDescriptionSize);\r
+  // 'FilePathList' field\r
+  VariablePtr += BootDescriptionSize;\r
+  CopyMem (VariablePtr, DevicePath, FilePathListLength);\r
+  // 'OptionalData' field\r
+  VariablePtr += FilePathListLength;\r
+  CopyMem (VariablePtr, OptionalData, OptionalDataSize);\r
+\r
+  return gRT->SetVariable (\r
+      BootVariableName,\r
+      &gEfiGlobalVariableGuid,\r
+      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+      VariableSize, Variable\r
+      );\r
+}\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 ArmJunoEntryPoint (\r
@@ -34,6 +112,7 @@ ArmJunoEntryPoint (
   UINT32                Midr;\r
   UINT32                CpuType;\r
   UINT32                CpuRev;\r
+  BOOLEAN               IsJunoR1;\r
 \r
   Status = PciEmulationEntryPoint ();\r
   if (EFI_ERROR (Status)) {\r
@@ -89,10 +168,11 @@ ArmJunoEntryPoint (
   // runtime by checking the value of the MIDR register.\r
   //\r
 \r
-  Midr    = ArmReadMidr ();\r
-  CpuType = (Midr >> ARM_CPU_TYPE_SHIFT) & ARM_CPU_TYPE_MASK;\r
-  CpuRev  = Midr & ARM_CPU_REV_MASK;\r
+  Midr           = ArmReadMidr ();\r
+  CpuType        = (Midr >> ARM_CPU_TYPE_SHIFT) & ARM_CPU_TYPE_MASK;\r
+  CpuRev         = Midr & ARM_CPU_REV_MASK;\r
   TextDevicePath = NULL;\r
+  IsJunoR1       = FALSE;\r
 \r
   switch (CpuType) {\r
   case ARM_CPU_TYPE_A53:\r
@@ -100,6 +180,7 @@ ArmJunoEntryPoint (
       TextDevicePath = (CHAR16*)FixedPcdGetPtr (PcdJunoR0FdtDevicePath);\r
     } else if (CpuRev == ARM_CPU_REV (0, 3)) {\r
       TextDevicePath = (CHAR16*)FixedPcdGetPtr (PcdJunoR1A57x2FdtDevicePath);\r
+      IsJunoR1       = TRUE;\r
     }\r
     break;\r
 \r
@@ -108,6 +189,7 @@ ArmJunoEntryPoint (
       TextDevicePath = (CHAR16*)FixedPcdGetPtr (PcdJunoR0FdtDevicePath);\r
     } else if (CpuRev == ARM_CPU_REV (1, 1)) {\r
       TextDevicePath = (CHAR16*)FixedPcdGetPtr (PcdJunoR1A57x2FdtDevicePath);\r
+      IsJunoR1       = TRUE;\r
     }\r
   }\r
 \r
@@ -130,5 +212,78 @@ ArmJunoEntryPoint (
   // Try to install the ACPI Tables\r
   Status = LocateAndInstallAcpiFromFv (&mJunoAcpiTableFile);\r
 \r
+  //\r
+  // If Juno R1 and it is the first boot then default boot entries will be created\r
+  //\r
+  if (IsJunoR1) {\r
+    CONST CHAR16*                       ExtraBootArgument = L" dtb=juno-r1-ca57x2_ca53x4.dtb";\r
+    UINTN                               Size;\r
+    EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL* EfiDevicePathFromTextProtocol;\r
+    EFI_DEVICE_PATH*                    BootDevicePath;\r
+    CHAR16*                             DefaultBootArgument;\r
+    UINTN                               DefaultBootArgumentSize;\r
+    CHAR16*                             DefaultBootArgument2;\r
+    UINTN                               DefaultBootArgument2Size;\r
+    UINT16                              BootOrder[2];\r
+\r
+    // Because the driver has a dependency on gEfiVariable(Write)ArchProtocolGuid (see [Depex]\r
+    // section of the INF file), we know we can safely access the UEFI Variable at that stage.\r
+    Size = 0;\r
+    Status = gRT->GetVariable (L"BootOrder", &gEfiGlobalVariableGuid, NULL, &Size, NULL);\r
+    if (Status == EFI_NOT_FOUND) {\r
+      Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);\r
+      if (EFI_ERROR (Status)) {\r
+        // You must provide an implementation of DevicePathFromTextProtocol in your firmware (eg: DevicePathDxe)\r
+        DEBUG ((EFI_D_ERROR, "Error: Require DevicePathFromTextProtocol\n"));\r
+        return Status;\r
+      }\r
+      // We use the same default kernel\r
+      BootDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr (PcdDefaultBootDevicePath));\r
+\r
+      // Create the entry if the Default values are correct\r
+      if (BootDevicePath != NULL) {\r
+        DefaultBootArgument = (CHAR16*)PcdGetPtr (PcdDefaultBootArgument);\r
+        DefaultBootArgumentSize = StrSize (DefaultBootArgument);\r
+        DefaultBootArgument2Size = DefaultBootArgumentSize + StrSize (ExtraBootArgument);\r
+\r
+        DefaultBootArgument2 = AllocatePool (DefaultBootArgument2Size);\r
+        if (DefaultBootArgument2 == NULL) {\r
+          FreePool (BootDevicePath);\r
+          return EFI_OUT_OF_RESOURCES;\r
+        }\r
+        CopyMem (DefaultBootArgument2, DefaultBootArgument, DefaultBootArgumentSize);\r
+        CopyMem ((UINT8*)DefaultBootArgument2 + (StrLen (DefaultBootArgument2) * sizeof (CHAR16)), ExtraBootArgument, StrSize (ExtraBootArgument));\r
+\r
+        // Create Boot0001 environment variable\r
+        Status = BootOptionCreate (L"Boot0001", LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT,\r
+            L"Linux with A57x2", BootDevicePath,\r
+            (UINT8*)DefaultBootArgument, DefaultBootArgumentSize);\r
+        ASSERT_EFI_ERROR (Status);\r
+\r
+        // Create Boot0002 environment variable\r
+        Status = BootOptionCreate (L"Boot0002", LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT,\r
+            L"Linux with A57x2_A53x4", BootDevicePath,\r
+            (UINT8*)DefaultBootArgument2, DefaultBootArgument2Size);\r
+        ASSERT_EFI_ERROR (Status);\r
+\r
+        // Add the new Boot Index to the list\r
+        BootOrder[0] = 1; // Boot0001\r
+        BootOrder[1] = 2; // Boot0002\r
+        Status = gRT->SetVariable (\r
+            L"BootOrder",\r
+            &gEfiGlobalVariableGuid,\r
+            EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+            sizeof (BootOrder),\r
+            BootOrder\r
+            );\r
+\r
+        FreePool (BootDevicePath);\r
+        FreePool (DefaultBootArgument2);\r
+      } else {\r
+        Status = EFI_UNSUPPORTED;\r
+      }\r
+    }\r
+  }\r
+\r
   return Status;\r
 }\r
index 370edcb7c857748baba30ec75548d00b90f25d9a..ea1738ba7593571723a719c8690b94116f21ed72 100644 (file)
   gArmJunoTokenSpaceGuid.PcdJunoR1A57x2FdtDevicePath\r
   gArmJunoTokenSpaceGuid.PcdJunoR1A57x2A53x4FdtDevicePath\r
 \r
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath\r
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument\r
+\r
 [Pcd]\r
   gEmbeddedTokenSpaceGuid.PcdFdtDevicePaths\r
 \r
 [Depex]\r
-  TRUE\r
+  # We depend on these protocols to create the default boot entries\r
+  gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid\r