b .Lreloc_loop\r
.Lreloc_done:\r
\r
- // Do early platform specific actions\r
- bl ASM_PFX(ArmPlatformPeiBootAction)\r
+ bl ASM_PFX(DiscoverDramFromDt)\r
\r
// Get ID of this CPU in Multicore system\r
bl ASM_PFX(ArmReadMpidr)\r
\r
_NeverReturn:\r
b _NeverReturn\r
+\r
+// VOID\r
+// DiscoverDramFromDt (\r
+// VOID *DeviceTreeBaseAddress, // passed by loader in x0\r
+// VOID *ImageBase // passed by FDF trampoline in x1\r
+// );\r
+ASM_PFX(DiscoverDramFromDt):\r
+ //\r
+ // If we are booting from RAM using the Linux kernel boot protocol, x0 will\r
+ // point to the DTB image in memory. Otherwise, use the default value defined\r
+ // by the platform.\r
+ //\r
+ cbnz x0, 0f\r
+ ldr x0, PcdGet64 (PcdDeviceTreeInitialBaseAddress)\r
+\r
+0:mov x29, x30 // preserve LR\r
+ mov x28, x0 // preserve DTB pointer\r
+ mov x27, x1 // preserve base of image pointer\r
+\r
+ //\r
+ // The base of the runtime image has been preserved in x1. Check whether\r
+ // the expected magic number can be found in the header.\r
+ //\r
+ ldr w8, .LArm64LinuxMagic\r
+ ldr w9, [x1, #0x38]\r
+ cmp w8, w9\r
+ bne .Lout\r
+\r
+ //\r
+ //\r
+ // OK, so far so good. We have confirmed that we likely have a DTB and are\r
+ // booting via the arm64 Linux boot protocol. Update the base-of-image PCD\r
+ // to the actual relocated value, and add the shift of PcdFdBaseAddress to\r
+ // PcdFvBaseAddress as well\r
+ //\r
+ adr x8, PcdGet64 (PcdFdBaseAddress)\r
+ adr x9, PcdGet64 (PcdFvBaseAddress)\r
+ ldr x6, [x8]\r
+ ldr x7, [x9]\r
+ sub x7, x7, x6\r
+ add x7, x7, x1\r
+ str x1, [x8]\r
+ str x7, [x9]\r
+\r
+ //\r
+ // Discover the memory size and offset from the DTB, and record in the\r
+ // respective PCDs. This will also return false if a corrupt DTB is\r
+ // encountered. Since we are calling a C function, use the window at the\r
+ // beginning of the FD image as a temp stack.\r
+ //\r
+ adr x1, PcdGet64 (PcdSystemMemoryBase)\r
+ adr x2, PcdGet64 (PcdSystemMemorySize)\r
+ mov sp, x7\r
+ bl FindMemnode\r
+ cbz x0, .Lout\r
+\r
+ //\r
+ // Copy the DTB to the slack space right after the 64 byte arm64/Linux style\r
+ // image header at the base of this image (defined in the FDF), and record the\r
+ // pointer in PcdDeviceTreeInitialBaseAddress.\r
+ //\r
+ adr x8, PcdGet64 (PcdDeviceTreeInitialBaseAddress)\r
+ add x27, x27, #0x40\r
+ str x27, [x8]\r
+\r
+ mov x0, x27\r
+ mov x1, x28\r
+ bl CopyFdt\r
+\r
+.Lout:\r
+ ret x29\r
+\r
+.LArm64LinuxMagic:\r
+ .byte 0x41, 0x52, 0x4d, 0x64\r
\r
_NeverReturn:\r
b _NeverReturn\r
+\r
+ASM_PFX(ArmPlatformPeiBootAction):\r
+ //\r
+ // If we are booting from RAM using the Linux kernel boot protocol, r0 will\r
+ // point to the DTB image in memory. Otherwise, use the default value defined\r
+ // by the platform.\r
+ //\r
+ teq r0, #0\r
+ bne 0f\r
+ LDRL (r0, PcdGet64 (PcdDeviceTreeInitialBaseAddress))\r
+\r
+0:mov r11, r14 // preserve LR\r
+ mov r10, r0 // preserve DTB pointer\r
+ mov r9, r1 // preserve base of image pointer\r
+\r
+ //\r
+ // The base of the runtime image has been preserved in r1. Check whether\r
+ // the expected magic number can be found in the header.\r
+ //\r
+ ldr r8, .LArm32LinuxMagic\r
+ ldr r7, [r1, #0x24]\r
+ cmp r7, r8\r
+ bne .Lout\r
+\r
+ //\r
+ //\r
+ // OK, so far so good. We have confirmed that we likely have a DTB and are\r
+ // booting via the ARM Linux boot protocol. Update the base-of-image PCD\r
+ // to the actual relocated value, and add the shift of PcdFdBaseAddress to\r
+ // PcdFvBaseAddress as well\r
+ //\r
+ ADRL (r8, PcdGet64 (PcdFdBaseAddress))\r
+ ADRL (r7, PcdGet64 (PcdFvBaseAddress))\r
+ ldr r6, [r8]\r
+ ldr r5, [r7]\r
+ sub r5, r5, r6\r
+ add r5, r5, r1\r
+ str r1, [r8]\r
+ str r5, [r7]\r
+\r
+ //\r
+ // Discover the memory size and offset from the DTB, and record in the\r
+ // respective PCDs. This will also return false if a corrupt DTB is\r
+ // encountered. Since we are calling a C function, use the window at the\r
+ // beginning of the FD image as a temp stack.\r
+ //\r
+ ADRL (r1, PcdGet64 (PcdSystemMemoryBase))\r
+ ADRL (r2, PcdGet64 (PcdSystemMemorySize))\r
+ mov sp, r5\r
+ bl FindMemnode\r
+ teq r0, #0\r
+ beq .Lout\r
+\r
+ //\r
+ // Copy the DTB to the slack space right after the 64 byte arm64/Linux style\r
+ // image header at the base of this image (defined in the FDF), and record the\r
+ // pointer in PcdDeviceTreeInitialBaseAddress.\r
+ //\r
+ ADRL (r8, PcdGet64 (PcdDeviceTreeInitialBaseAddress))\r
+ add r9, r9, #0x40\r
+ str r9, [r8]\r
+\r
+ mov r0, r9\r
+ mov r1, r10\r
+ bl CopyFdt\r
+\r
+.Lout:\r
+ bx r11\r
+\r
+.LArm32LinuxMagic:\r
+ .byte 0x18, 0x28, 0x6f, 0x01\r
\r
[Sources]\r
PrePi.c\r
+ FdtParser.c\r
\r
[Sources.AArch64]\r
AArch64/ArchPrePi.c\r
[LibraryClasses]\r
BaseLib\r
DebugLib\r
+ FdtLib\r
ArmLib\r
IoLib\r
TimerLib\r
--- /dev/null
+/*\r
+ * Copyright (c) 2015, Linaro Ltd. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials\r
+ * are licensed and made available under the terms and conditions of the BSD License\r
+ * which accompanies this distribution. The full text of the license may be found at\r
+ * http://opensource.org/licenses/bsd-license.php\r
+ *\r
+ * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ */\r
+\r
+#include <Uefi.h>\r
+#include <Include/libfdt.h>\r
+\r
+BOOLEAN\r
+FindMemnode (\r
+ IN VOID *DeviceTreeBlob,\r
+ OUT UINT64 *SystemMemoryBase,\r
+ OUT UINT64 *SystemMemorySize\r
+ )\r
+{\r
+ INT32 MemoryNode;\r
+ INT32 AddressCells;\r
+ INT32 SizeCells;\r
+ INT32 Length;\r
+ CONST INT32 *Prop;\r
+\r
+ if (fdt_check_header (DeviceTreeBlob) != 0) {\r
+ return FALSE;\r
+ }\r
+\r
+ //\r
+ // Look for a node called "memory" at the lowest level of the tree\r
+ //\r
+ MemoryNode = fdt_path_offset (DeviceTreeBlob, "/memory");\r
+ if (MemoryNode <= 0) {\r
+ return FALSE;\r
+ }\r
+\r
+ //\r
+ // Retrieve the #address-cells and #size-cells properties\r
+ // from the root node, or use the default if not provided.\r
+ //\r
+ AddressCells = 1;\r
+ SizeCells = 1;\r
+\r
+ Prop = fdt_getprop (DeviceTreeBlob, 0, "#address-cells", &Length);\r
+ if (Length == 4) {\r
+ AddressCells = fdt32_to_cpu (*Prop);\r
+ }\r
+\r
+ Prop = fdt_getprop (DeviceTreeBlob, 0, "#size-cells", &Length);\r
+ if (Length == 4) {\r
+ SizeCells = fdt32_to_cpu (*Prop);\r
+ }\r
+\r
+ //\r
+ // Now find the 'reg' property of the /memory node, and read the first\r
+ // range listed.\r
+ //\r
+ Prop = fdt_getprop (DeviceTreeBlob, MemoryNode, "reg", &Length);\r
+\r
+ if (Length < (AddressCells + SizeCells) * sizeof (INT32)) {\r
+ return FALSE;\r
+ }\r
+\r
+ *SystemMemoryBase = fdt32_to_cpu (Prop[0]);\r
+ if (AddressCells > 1) {\r
+ *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);\r
+ }\r
+ Prop += AddressCells;\r
+\r
+ *SystemMemorySize = fdt32_to_cpu (Prop[0]);\r
+ if (SizeCells > 1) {\r
+ *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+VOID\r
+CopyFdt (\r
+ IN VOID *FdtDest,\r
+ IN VOID *FdtSource\r
+ )\r
+{\r
+ fdt_pack(FdtSource);\r
+ CopyMem (FdtDest, FdtSource, fdt_totalsize (FdtSource));\r
+}\r