1 From 82540f3a4b280133f2d1a58cb8baba01c1f09690 Mon Sep 17 00:00:00 2001
2 From: Olivier Martin <olivier.martin@arm.com>
3 Date: Thu, 16 Feb 2012 15:56:40 +0000
4 Subject: [PATCH 3/3] ArmPlatformPkg/EblCmdLib: Add 'dumpfdt' EBL command
6 This command dumps the FDT blob pointed by the Device Path defined in the
7 command argument or used the Platform specifc FDT defined by its Device Path
8 in the UEFI Variable 'Fdt' or the PcdFdtDevicePath PCD.
10 ArmPlatformPkg/Library/EblCmdLib/EblCmdFdt.c | 206 ++++++++++++++++++++++++
11 ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c | 12 ++
12 ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf | 6 +
13 3 files changed, 224 insertions(+), 0 deletions(-)
14 create mode 100755 ArmPlatformPkg/Library/EblCmdLib/EblCmdFdt.c
15 mode change 100644 => 100755 ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c
16 mode change 100644 => 100755 ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
18 diff --git a/ArmPlatformPkg/Library/EblCmdLib/EblCmdFdt.c b/ArmPlatformPkg/Library/EblCmdLib/EblCmdFdt.c
20 index 0000000..3c5eb8e
22 +++ b/ArmPlatformPkg/Library/EblCmdLib/EblCmdFdt.c
26 +#include <Library/MemoryAllocationLib.h>
27 +#include <Library/BdsLib.h>
28 +#include <Library/DebugLib.h>
29 +#include <Library/PcdLib.h>
30 +#include <Library/PrintLib.h>
31 +#include <Library/UefiLib.h>
32 +#include <Library/UefiApplicationEntryPoint.h>
33 +#include <Library/UefiBootServicesTableLib.h>
34 +#include <Library/UefiRuntimeServicesTableLib.h>
36 +#include <Protocol/DevicePathFromText.h>
38 +#include <Guid/GlobalVariable.h>
42 +#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
43 +#define PALIGN(p, a) ((void *)(ALIGN((unsigned long)(p), (a))))
44 +#define GET_CELL(p) (p += 4, *((const uint32_t *)(p-4)))
49 + IN CONST VOID* data,
53 + CONST CHAR8 *s = data;
56 + /* zero length is not */
61 + /* must terminate with zero */
62 + if (s[len - 1] != '\0') {
67 + while (*s/* && isprint(*s)*/) {
71 + /* not zero, or not done yet */
72 + if (*s != '\0' || (s + 1 - ss) < len) {
82 + IN CONST CHAR8* data,
87 + CONST CHAR8 *p = data;
89 + /* no data, don't print */
93 + if (IsPrintableString (data, len)) {
94 + Print(L" = \"%a\"", (const char *)data);
95 + } else if ((len % 4) == 0) {
97 + for (i = 0; i < len; i += 4) {
98 + Print(L"0x%08x%a", fdt32_to_cpu(GET_CELL(p)),i < (len - 4) ? " " : "");
103 + for (i = 0; i < len; i++)
104 + Print(L"%02x%a", *p++, i < len - 1 ? " " : "");
114 + struct fdt_header *bph;
117 + CONST CHAR8* p_struct;
118 + CONST CHAR8* p_strings;
132 + off_dt = fdt32_to_cpu(bph->off_dt_struct);
133 + off_str = fdt32_to_cpu(bph->off_dt_strings);
134 + p_struct = (CONST CHAR8*)FdtBlob + off_dt;
135 + p_strings = (CONST CHAR8*)FdtBlob + off_str;
136 + version = fdt32_to_cpu(bph->version);
139 + while ((tag = fdt32_to_cpu(GET_CELL(p))) != FDT_END) {
141 + /* printf("tag: 0x%08x (%d)\n", tag, p - p_struct); */
143 + if (tag == FDT_BEGIN_NODE) {
145 + p = PALIGN(p + strlen(s) + 1, 4);
150 + Print(L"%*s%a {\n", depth * shift, L" ", s);
156 + if (tag == FDT_END_NODE) {
159 + Print(L"%*s};\n", depth * shift, L" ");
163 + if (tag == FDT_NOP) {
164 + Print(L"%*s// [NOP]\n", depth * shift, L" ");
168 + if (tag != FDT_PROP) {
169 + Print(L"%*s ** Unknown tag 0x%08x\n", depth * shift, L" ", tag);
172 + sz = fdt32_to_cpu(GET_CELL(p));
173 + s = p_strings + fdt32_to_cpu(GET_CELL(p));
174 + if (version < 16 && sz >= 8)
178 + p = PALIGN(p + sz, 4);
180 + Print(L"%*s%a", depth * shift, L" ", s);
193 + EFI_DEVICE_PATH* FdtDevicePath;
197 + EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;
199 + // If no FDT file is passed to the argument then get the one from the platform
201 + Status = GetEnvironmentVariable (L"Fdt",NULL,NULL,(VOID**)&FdtDevicePath);
202 + if (Status == EFI_NOT_FOUND) {
203 + // No set yet, get the Default Device Path
204 + Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
205 + ASSERT_EFI_ERROR(Status);
206 + FdtDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdFdtDevicePath));
209 + return EFI_NOT_FOUND;
212 + Status = BdsLoadImage (FdtDevicePath, AllocateAnyPages, (EFI_PHYSICAL_ADDRESS*)&FdtBlob, &FdtBlobSize);
213 + if (EFI_ERROR(Status)) {
214 + Print (L"ERROR: Did not find the Fdt Blob.\n");
218 + Ret = fdt_check_header(FdtBlob);
220 + Print (L"ERROR: Device Tree header not valid (err:%d)\n",Ret);
226 + FreePool (FdtDevicePath);
228 + return EFI_SUCCESS;
230 diff --git a/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c b/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c
233 index b75dbfb..327a794
234 --- a/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c
235 +++ b/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c
236 @@ -42,6 +42,12 @@ EblDumpMmu (
248 Simple arm disassembler via a library
249 @@ -416,6 +422,12 @@ GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mLibCmdTemplate[] =
250 " list all the Device Paths",
256 + " dump the current fdt or the one defined in the arguments",
262 diff --git a/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf b/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
265 index 0eb71a0..9f84c07
266 --- a/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
267 +++ b/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
276 MdeModulePkg/MdeModulePkg.dec
277 EmbeddedPkg/EmbeddedPkg.dec
279 + ArmPlatformPkg/ArmPlatformPkg.dec
290 gEfiDebugSupportProtocolGuid
294 gEfiDebugImageInfoTableGuid
297 + gArmPlatformTokenSpaceGuid.PcdFdtDevicePath