/** @file\r
*\r
-* Copyright (c) 2011-2012, ARM Limited. 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
+* Copyright (c) 2011-2013, ARM Limited. All rights reserved.\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
+* 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
\r
UINTN Pages;\r
BOOLEAN PsciSmcSupported;\r
UINTN Rx;\r
+ UINTN OriginalFdtSize;\r
\r
//\r
// Ensure the Power State Coordination Interface (PSCI) SMCs are there if supported\r
}\r
}\r
\r
+ //\r
+ // Sanity checks on the original FDT blob.\r
+ //\r
err = fdt_check_header ((VOID*)(UINTN)(*FdtBlobBase));\r
if (err != 0) {\r
Print (L"ERROR: Device Tree header not valid (err:%d)\n", err);\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ // The original FDT blob might have been loaded partially.\r
+ // Check that it is not the case.\r
+ OriginalFdtSize = (UINTN)fdt_totalsize ((VOID*)(UINTN)(*FdtBlobBase));\r
+ if (OriginalFdtSize > *FdtBlobSize) {\r
+ Print (L"ERROR: Incomplete FDT. Only %d/%d bytes have been loaded.\n",\r
+ *FdtBlobSize, OriginalFdtSize);\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
//\r
// Allocate memory for the new FDT\r
//\r
- NewFdtBlobSize = fdt_totalsize((VOID*)(UINTN)(*FdtBlobBase)) + FDT_ADDITIONAL_ENTRIES_SIZE;\r
+ NewFdtBlobSize = OriginalFdtSize + FDT_ADDITIONAL_ENTRIES_SIZE;\r
\r
// Try below a watermark address\r
Status = EFI_NOT_FOUND;\r
if (node >= 0) {\r
fdt_setprop_string(fdt, node, "name", "memory");\r
fdt_setprop_string(fdt, node, "device_type", "memory");\r
- \r
+\r
GetSystemMemoryResources (&ResourceList);\r
Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)ResourceList.ForwardLink;\r
- \r
+\r
if (sizeof(UINTN) == sizeof(UINT32)) {\r
Region.Base = cpu_to_fdt32((UINTN)Resource->PhysicalStart);\r
Region.Size = cpu_to_fdt32((UINTN)Resource->ResourceLength);\r
return EFI_SUCCESS;\r
\r
FAIL_NEW_FDT:\r
- *FdtBlobSize = (UINTN)fdt_totalsize ((VOID*)(UINTN)(*FdtBlobBase));\r
+ *FdtBlobSize = OriginalFdtSize;\r
// Return success even if we failed to update the FDT blob. The original one is still valid.\r
return EFI_SUCCESS;\r
}\r