**/\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
UINT32 Midr;\r
UINT32 CpuType;\r
UINT32 CpuRev;\r
+ BOOLEAN IsJunoR1;\r
\r
Status = PciEmulationEntryPoint ();\r
if (EFI_ERROR (Status)) {\r
// 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
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
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
// 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