]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/EblCmdLib/EblCmdFdt.c
3 * Copyright (c) 2011-2013, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/MemoryAllocationLib.h>
18 #include <Library/BdsLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/PrintLib.h>
22 #include <Library/UefiLib.h>
23 #include <Library/UefiApplicationEntryPoint.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/UefiRuntimeServicesTableLib.h>
27 #include <Protocol/DevicePathFromText.h>
29 #include <Guid/ArmGlobalVariableHob.h>
34 #define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
35 #define PALIGN(p, a) ((void *)(ALIGN((unsigned long)(p), (a))))
36 #define GET_CELL(p) (p += 4, *((const uint32_t *)(p-4)))
45 CONST CHAR8
*s
= data
;
53 // Must terminate with zero
54 if (s
[len
- 1] != '\0') {
59 while (*s
/* && isprint(*s)*/) {
63 // Not zero, or not done yet
64 if (*s
!= '\0' || (s
+ 1 - ss
) < len
) {
79 CONST CHAR8
*p
= data
;
81 // No data, don't print
85 if (IsPrintableString (data
, len
)) {
86 Print(L
" = \"%a\"", (const char *)data
);
87 } else if ((len
% 4) == 0) {
89 for (i
= 0; i
< len
; i
+= 4) {
90 Print(L
"0x%08x%a", fdt32_to_cpu(GET_CELL(p
)),i
< (len
- 4) ? " " : "");
95 for (i
= 0; i
< len
; i
++)
96 Print(L
"%02x%a", *p
++, i
< len
- 1 ? " " : "");
106 struct fdt_header
*bph
;
109 CONST CHAR8
* p_struct
;
110 CONST CHAR8
* p_strings
;
124 off_dt
= fdt32_to_cpu(bph
->off_dt_struct
);
125 off_str
= fdt32_to_cpu(bph
->off_dt_strings
);
126 p_struct
= (CONST CHAR8
*)FdtBlob
+ off_dt
;
127 p_strings
= (CONST CHAR8
*)FdtBlob
+ off_str
;
128 version
= fdt32_to_cpu(bph
->version
);
131 while ((tag
= fdt32_to_cpu(GET_CELL(p
))) != FDT_END
) {
133 if (tag
== FDT_BEGIN_NODE
) {
135 p
= PALIGN(p
+ strlen(s
) + 1, 4);
140 Print(L
"%*s%a {\n", depth
* shift
, L
" ", s
);
146 if (tag
== FDT_END_NODE
) {
149 Print(L
"%*s};\n", depth
* shift
, L
" ");
153 if (tag
== FDT_NOP
) {
154 Print(L
"%*s// [NOP]\n", depth
* shift
, L
" ");
158 if (tag
!= FDT_PROP
) {
159 Print(L
"%*s ** Unknown tag 0x%08x\n", depth
* shift
, L
" ", tag
);
162 sz
= fdt32_to_cpu(GET_CELL(p
));
163 s
= p_strings
+ fdt32_to_cpu(GET_CELL(p
));
164 if (version
< 16 && sz
>= 8)
168 p
= PALIGN(p
+ sz
, 4);
170 Print(L
"%*s%a", depth
* shift
, L
" ", s
);
186 // If no FDT file is passed to the argument then get the one from the platform
188 Status
= EfiGetSystemConfigurationTable (&gFdtTableGuid
, &FdtBlob
);
189 if (EFI_ERROR (Status
)) {
190 Print (L
"ERROR: Did not find the Fdt Blob.\n");
194 return EFI_NOT_FOUND
;
197 Ret
= fdt_check_header (FdtBlob
);
199 Print (L
"ERROR: Device Tree header not valid (err:%d)\n", Ret
);
200 return EFI_INVALID_PARAMETER
;