public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 0/3] Support FDT library.
@ 2023-04-17  5:35 Benny Lin
  2023-04-17  5:35 ` [PATCH v3 1/3] Tianocore: " Benny Lin
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Benny Lin @ 2023-04-17  5:35 UTC (permalink / raw)
  To: devel
  Cc: Benny Lin, Michael D Kinney, Liming Gao, Zhiguang Liu,
	Sean Brogan, Michael Kubacki, Pedro Falcato

From: Benny Lin <benny.lin@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
Add FDT support in EDK2 by submodule 3rd party libfdt
(https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
and refer to LibcLib implementation by Pedro.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Benny Lin <benny.lin@intel.com>

Benny Lin (3):
  Tianocore: Support FDT library.
  MdePkg: Support FDT library.
  .pytool: Support FDT library.

 .gitmodules                               |   3 +
 .pytool/CISettings.py                     |   2 +
 MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
 MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
 MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
 MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
 MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
 MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
 MdePkg/Library/BaseFdtLib/libfdt          |   1 +
 MdePkg/Library/BaseFdtLib/limits.h        |  10 +
 MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
 MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
 MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
 MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
 MdePkg/Library/BaseFdtLib/string.h        |  10 +
 MdePkg/MdePkg.ci.yaml                     |  17 +-
 MdePkg/MdePkg.dec                         |   4 +
 MdePkg/MdePkg.dsc                         |   1 +
 ReadMe.rst                                |   1 +
 19 files changed, 1050 insertions(+), 2 deletions(-)
 create mode 100644 MdePkg/Include/Library/FdtLib.h
 create mode 100644 MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
 create mode 100644 MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
 create mode 100644 MdePkg/Library/BaseFdtLib/FdtLib.c
 create mode 100644 MdePkg/Library/BaseFdtLib/LibFdtSupport.h
 create mode 100644 MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
 create mode 160000 MdePkg/Library/BaseFdtLib/libfdt
 create mode 100644 MdePkg/Library/BaseFdtLib/limits.h
 create mode 100644 MdePkg/Library/BaseFdtLib/stdbool.h
 create mode 100644 MdePkg/Library/BaseFdtLib/stddef.h
 create mode 100644 MdePkg/Library/BaseFdtLib/stdint.h
 create mode 100644 MdePkg/Library/BaseFdtLib/stdlib.h
 create mode 100644 MdePkg/Library/BaseFdtLib/string.h

-- 
2.39.1.windows.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 1/3] Tianocore: Support FDT library.
  2023-04-17  5:35 [PATCH v3 0/3] Support FDT library Benny Lin
@ 2023-04-17  5:35 ` Benny Lin
  2023-04-19 15:58   ` Michael D Kinney
  2023-04-17  5:35 ` [PATCH v3 2/3] MdePkg: " Benny Lin
  2023-04-17  5:35 ` [PATCH v3 3/3] .pytool: " Benny Lin
  2 siblings, 1 reply; 20+ messages in thread
From: Benny Lin @ 2023-04-17  5:35 UTC (permalink / raw)
  To: devel; +Cc: Benny Lin, Andrew Fish, Leif Lindholm, Michael D Kinney

From: Benny Lin <benny.lin@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
Add FDT support in EDK2 by submodule 3rd party libfdt
(https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)

Add submodule libfdt and update ReadMe for the licence.

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Benny Lin <benny.lin@intel.com>
---
 .gitmodules                      | 3 +++
 MdePkg/Library/BaseFdtLib/libfdt | 1 +
 ReadMe.rst                       | 1 +
 3 files changed, 5 insertions(+)

diff --git a/.gitmodules b/.gitmodules
index fe8a43be93..b1888c3488 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -26,3 +26,6 @@
 [submodule "UnitTestFrameworkPkg/Library/SubhookLib/subhook"]
 	path = UnitTestFrameworkPkg/Library/SubhookLib/subhook
 	url = https://github.com/Zeex/subhook.git
+[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
+	path = MdePkg/Library/BaseFdtLib/libfdt
+	url = https://github.com/devicetree-org/pylibfdt.git
diff --git a/MdePkg/Library/BaseFdtLib/libfdt b/MdePkg/Library/BaseFdtLib/libfdt
new file mode 160000
index 0000000000..cfff805481
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/libfdt
@@ -0,0 +1 @@
+Subproject commit cfff805481bdea27f900c32698171286542b8d3c
diff --git a/ReadMe.rst b/ReadMe.rst
index 91b9cf3c5e..d46c534229 100644
--- a/ReadMe.rst
+++ b/ReadMe.rst
@@ -96,6 +96,7 @@ that are covered by additional licenses.
 -  `UnitTestFrameworkPkg/Library/GoogleTestLib/googletest <https://github.com/google/googletest/blob/86add13493e5c881d7e4ba77fb91c1f57752b3a4/LICENSE>`__
 -  `UnitTestFrameworkPkg/Library/SubhookLib/subhook <https://github.com/Zeex/subhook/blob/83d4e1ebef3588fae48b69a7352cc21801cb70bc/LICENSE.txt>`__
 -  `RedfishPkg/Library/JsonLib/jansson <https://github.com/akheron/jansson/blob/2882ead5bb90cf12a01b07b2c2361e24960fae02/LICENSE>`__
+-  `MdePkg/Library/BaseFdtLib/libfdt <https://github.com/devicetree-org/pylibfdt/blob/f39368a217496d32c4091a2dba4045b60649e3a5/BSD-2-Clause>`__
 
 The EDK II Project is composed of packages. The maintainers for each package
 are listed in `Maintainers.txt <Maintainers.txt>`__.
-- 
2.39.1.windows.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-17  5:35 [PATCH v3 0/3] Support FDT library Benny Lin
  2023-04-17  5:35 ` [PATCH v3 1/3] Tianocore: " Benny Lin
@ 2023-04-17  5:35 ` Benny Lin
  2023-04-19 15:54   ` Michael D Kinney
  2023-04-17  5:35 ` [PATCH v3 3/3] .pytool: " Benny Lin
  2 siblings, 1 reply; 20+ messages in thread
From: Benny Lin @ 2023-04-17  5:35 UTC (permalink / raw)
  To: devel; +Cc: Benny Lin, Michael D Kinney, Liming Gao, Zhiguang Liu,
	Pedro Falcato

From: Benny Lin <benny.lin@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
Add FDT support in EDK2 by submodule 3rd party libfdt
(https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
and refer to LibcLib implementation by Pedro.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Benny Lin <benny.lin@intel.com>
---
 MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
 MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
 MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
 MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
 MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
 MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
 MdePkg/Library/BaseFdtLib/limits.h        |  10 +
 MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
 MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
 MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
 MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
 MdePkg/Library/BaseFdtLib/string.h        |  10 +
 MdePkg/MdePkg.ci.yaml                     |  17 +-
 MdePkg/MdePkg.dec                         |   4 +
 MdePkg/MdePkg.dsc                         |   1 +
 15 files changed, 1043 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Include/Library/FdtLib.h b/MdePkg/Include/Library/FdtLib.h
new file mode 100644
index 0000000000..d59b749c25
--- /dev/null
+++ b/MdePkg/Include/Library/FdtLib.h
@@ -0,0 +1,314 @@
+/** @file
+  Flattened Device Tree Library.
+
+  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef FDT_LIB_H_
+#define FDT_LIB_H_
+
+///
+/// Flattened Device Tree definition
+///
+typedef struct {
+  UINT32    Magic;               /* magic word FDT_MAGIC */
+  UINT32    TotalSize;           /* total size of DT block */
+  UINT32    OffsetDtStruct;      /* offset to structure */
+  UINT32    OffsetDtStrings;     /* offset to strings */
+  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map */
+  UINT32    Version;             /* format version */
+  UINT32    LastCompVersion;     /* last compatible version */
+
+  /* version 2 fields below */
+  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
+                                    booting on */
+  /* version 3 fields below */
+  UINT32    SizeDtStrings;       /* size of the strings block */
+
+  /* version 17 fields below */
+  UINT32    SizeDtStruct;        /* size of the structure block */
+} FDT_HEADER;
+
+typedef struct {
+  UINT64    Address;
+  UINT64    Size;
+} FDT_RESERVE_ENTRY;
+
+typedef struct {
+  UINT32    Tag;
+  CHAR8     Name[];
+} FDT_NODE_HEADER;
+
+typedef struct {
+  UINT32    Tag;
+  UINT32    Length;
+  UINT32    NameOffset;
+  CHAR8     Data[];
+} FDT_PROPERTY;
+
+#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST FDT_HEADER *)(Fdt))->Field)
+
+#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
+#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt, TotalSize))
+#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt, OffsetDtStruct))
+#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt, OffsetDtStrings))
+#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt, OffsetMemRsvmap))
+#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
+#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt, LastCompVersion))
+#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt, BootCpuidPhys))
+#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt, SizeDtStrings))
+#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt, SizeDtStruct))
+
+/**
+  Verify the header of the Flattened Device Tree
+
+  @param[in] Fdt            The pointer to FDT blob.
+
+  @return Zero for successfully, otherwise failed.
+
+**/
+INT32
+EFIAPI
+FdtCheckHeader (
+  IN CONST VOID  *Fdt
+  );
+
+/**
+  Create a empty Flattened Device Tree.
+
+  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
+  @param[in] BufferSize     The BufferSize to the pool size.
+
+  @return Zero for successfully, otherwise failed.
+
+**/
+RETURN_STATUS
+EFIAPI
+FdtCreateEmptyTree (
+  IN VOID   *Buffer,
+  IN UINTN  BufferSize
+  );
+
+/**
+  Returns a offset of next node from the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to previous node.
+  @param[in] Depth          The depth to the level of tree hierarchy.
+
+  @return The offset to next node offset.
+
+**/
+INT32
+EFIAPI
+FdtNextNode (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset,
+  IN INT32       *Depth
+  );
+
+/**
+  Returns a offset of first node under the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to previous node.
+
+  @return The offset to next node offset.
+
+**/
+INT32
+EFIAPI
+FdtFirstSubnode (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset
+  );
+
+/**
+  Returns a offset of next node from the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to previous node.
+
+  @return The offset to next node offset.
+
+**/
+INT32
+EFIAPI
+FdtNextSubnode (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset
+  );
+
+/**
+  Returns a offset of first node which includes the given name.
+
+  @param[in] Fdt             The pointer to FDT blob.
+  @param[in] ParentOffset    The offset to the node which start find under.
+  @param[in] Name            The name to search the node with the name.
+  @param[in] NameLength      The length of the name to check only.
+
+  @return The offset to node offset with given node name.
+
+**/
+INT32
+EFIAPI
+FdtSubnodeOffsetNameLen (
+  IN CONST VOID   *Fdt,
+  IN INT32        ParentOffset,
+  IN CONST CHAR8  *Name,
+  IN INT32        NameLength
+  );
+
+/**
+  Returns a offset of first node which includes the given property name and value.
+
+  @param[in] Fdt             The pointer to FDT blob.
+  @param[in] StartOffset     The offset to the starting node to find.
+  @param[in] PropertyName    The property name to search the node including the named property.
+  @param[in] PropertyValue   The property value to check the same property value.
+  @param[in] PropertyLength  The length of the value in PropertValue.
+
+  @return The offset to node offset with given property.
+
+**/
+INT32
+EFIAPI
+FdtNodeOffsetByPropValue (
+  IN CONST VOID   *Fdt,
+  IN INT32        StartOffset,
+  IN CONST CHAR8  *PropertyName,
+  IN CONST VOID   *PropertyValue,
+  IN INT32        PropertyLength
+  );
+
+/**
+  Returns a property with the given name from the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] NodeOffset     The offset to the given node.
+  @param[in] Name           The name to the property which need be searched
+  @param[in] Length         The length to the size of the property found.
+
+  @return The property to the structure of the found property.
+
+**/
+CONST FDT_PROPERTY *
+EFIAPI
+FdtGetProperty (
+  IN CONST VOID   *Fdt,
+  IN INT32        NodeOffset,
+  IN CONST CHAR8  *Name,
+  IN INT32        *Length
+  );
+
+/**
+  Returns a offset of first property in the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to the node which need be searched.
+
+  @return The offset to first property offset in the given node.
+
+**/
+INT32
+EFIAPI
+FdtFirstPropertyOffset (
+  IN CONST VOID  *Fdt,
+  IN INT32       NodeOffset
+  );
+
+/**
+  Returns a offset of next property from the given property.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to previous property.
+
+  @return The offset to next property offset.
+
+**/
+INT32
+EFIAPI
+FdtNextPropertyOffset (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset
+  );
+
+/**
+  Returns a property from the given offset of the property.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to the given offset of the property.
+  @param[in] Length         The length to the size of the property found.
+
+  @return The property to the structure of the given property offset.
+
+**/
+CONST FDT_PROPERTY *
+EFIAPI
+FdtGetPropertyByOffset (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset,
+  IN INT32       *Length
+  );
+
+/**
+  Returns a string by the given string offset.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] StrOffset      The offset to the location in the strings block of FDT.
+  @param[in] Length         The length to the size of string which need be retrieved.
+
+  @return The string to the given string offset.
+
+**/
+CONST CHAR8 *
+EFIAPI
+FdtGetString (
+  IN CONST VOID  *Fdt,
+  IN INT32       StrOffset,
+  IN INT32       *Length        OPTIONAL
+  );
+
+/**
+  Add a new node to the FDT.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] ParentOffset   The offset to the node offset which want to add in.
+  @param[in] Name           The name to name the node.
+
+  @return  The offset to the new node.
+
+**/
+INT32
+EFIAPI
+FdtAddSubnode (
+  IN VOID         *Fdt,
+  IN INT32        ParentOffset,
+  IN CONST CHAR8  *Name
+  );
+
+/**
+  Add or modify a property in the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] NodeOffset     The offset to the node offset which want to add in.
+  @param[in] Name           The name to name the property.
+  @param[in] Value          The value to the property value.
+  @param[in] Length         The length to the size of the property.
+
+  @return  Zero for successfully, otherwise failed.
+
+**/
+INT32
+EFIAPI
+FdtSetProp (
+  IN VOID         *Fdt,
+  IN INT32        NodeOffset,
+  IN CONST CHAR8  *Name,
+  IN CONST VOID   *Value,
+  IN UINT32       Length
+  );
+
+#endif /* FDT_LIB_H_ */
diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
new file mode 100644
index 0000000000..730e568ff6
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
@@ -0,0 +1,62 @@
+## @file
+# Flattened Device Tree Library.
+#
+# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001B
+  BASE_NAME                      = BaseFdtLib
+  MODULE_UNI_FILE                = BaseFdtLib.uni
+  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-E8CEC206DE04
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = FdtLib
+
+  DEFINE FDT_LIB_PATH            = libfdt/libfdt
+
+#
+#  VALID_ARCHITECTURES           = IA32 X64
+#
+
+[Sources]
+  FdtLib.c
+  LibFdtWrapper.c
+  # header Wrapper files
+  limits.h
+  stdbool.h
+  stddef.h
+  stdint.h
+  stdlib.h
+  string.h
+
+  $(FDT_LIB_PATH)/fdt.c
+  $(FDT_LIB_PATH)/fdt.h
+  $(FDT_LIB_PATH)/fdt_addresses.c
+  $(FDT_LIB_PATH)/fdt_check.c
+  $(FDT_LIB_PATH)/fdt_empty_tree.c
+  $(FDT_LIB_PATH)/fdt_overlay.c
+  $(FDT_LIB_PATH)/fdt_ro.c
+  $(FDT_LIB_PATH)/fdt_rw.c
+  $(FDT_LIB_PATH)/fdt_strerror.c
+  $(FDT_LIB_PATH)/fdt_sw.c
+  $(FDT_LIB_PATH)/fdt_wip.c
+  $(FDT_LIB_PATH)/libfdt.h
+  $(FDT_LIB_PATH)/libfdt_env.h
+  $(FDT_LIB_PATH)/libfdt_internal.h
+
+[Packages]
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+
+[BuildOptions]
+  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
+  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
+
diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
new file mode 100644
index 0000000000..3f7e45ea6f
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
@@ -0,0 +1,14 @@
+// /** @file
+// Flattened Device Tree Library.
+//
+// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT             #language en-US "Instance of FDT Library"
+
+#string STR_MODULE_DESCRIPTION          #language en-US "This module provides FDT Library implementation."
+
diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c b/MdePkg/Library/BaseFdtLib/FdtLib.c
new file mode 100644
index 0000000000..200a496c7e
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
@@ -0,0 +1,301 @@
+/** @file
+  Flattened Device Tree Library.
+
+  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <libfdt/libfdt/libfdt.h>
+
+/**
+  Verify the header of the Flattened Device Tree
+
+  @param[in] Fdt            The pointer to FDT blob.
+
+  @return Zero for successfully, otherwise failed.
+
+**/
+INT32
+EFIAPI
+FdtCheckHeader (
+  IN CONST VOID  *Fdt
+  )
+{
+  return fdt_check_header(Fdt);
+}
+
+/**
+  Create a empty Flattened Device Tree.
+
+  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
+  @param[in] BufferSize     The BufferSize to the pool size.
+
+  @return Zero for successfully, otherwise failed.
+
+**/
+INT32
+EFIAPI
+FdtCreateEmptyTree (
+  IN VOID    *Buffer,
+  IN UINT32  BufferSize
+  )
+{
+  return fdt_create_empty_tree (Buffer, (int)BufferSize);
+}
+
+/**
+  Returns a offset of next node from the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to previous node.
+  @param[in] Depth          The depth to the level of tree hierarchy.
+
+  @return The offset to next node offset.
+
+**/
+INT32
+EFIAPI
+FdtNextNode (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset,
+  IN INT32       *Depth
+  )
+{
+  return fdt_next_node (Fdt, Offset, Depth);
+}
+
+/**
+  Returns a offset of first node under the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to previous node.
+
+  @return The offset to next node offset.
+
+**/
+INT32
+EFIAPI
+FdtFirstSubnode (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset
+  )
+{
+  return fdt_first_subnode (Fdt, Offset);
+}
+
+/**
+  Returns a offset of next node from the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to previous node.
+
+  @return The offset to next node offset.
+
+**/
+INT32
+EFIAPI
+FdtNextSubnode (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset
+  )
+{
+  return fdt_next_subnode (Fdt, Offset);
+}
+
+/**
+  Returns a offset of first node which includes the given name.
+
+  @param[in] Fdt             The pointer to FDT blob.
+  @param[in] ParentOffset    The offset to the node which start find under.
+  @param[in] Name            The name to search the node with the name.
+  @param[in] NameLength      The length of the name to check only.
+
+  @return The offset to node offset with given node name.
+
+**/
+INT32
+EFIAPI
+FdtSubnodeOffsetNameLen (
+  IN CONST VOID   *Fdt,
+  IN INT32        ParentOffset,
+  IN CONST CHAR8  *Name,
+  IN INT32        NameLength
+  )
+{
+  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name, NameLength);
+}
+
+/**
+  Returns a offset of first node which includes the given property name and value.
+
+  @param[in] Fdt             The pointer to FDT blob.
+  @param[in] StartOffset     The offset to the starting node to find.
+  @param[in] PropertyName    The property name to search the node including the named property.
+  @param[in] PropertyValue   The property value to check the same property value.
+  @param[in] PropertyLength  The length of the value in PropertValue.
+
+  @return The offset to node offset with given property.
+
+**/
+INT32
+EFIAPI
+FdtNodeOffsetByPropValue (
+  IN CONST VOID   *Fdt,
+  IN INT32        StartOffset,
+  IN CONST CHAR8  *PropertyName,
+  IN CONST VOID   *PropertyValue,
+  IN INT32        PropertyLength
+  )
+{
+  return fdt_node_offset_by_prop_value (Fdt, StartOffset, PropertyName, PropertyValue, PropertyLength);
+}
+
+/**
+  Returns a property with the given name from the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] NodeOffset     The offset to the given node.
+  @param[in] Name           The name to the property which need be searched
+  @param[in] Length         The length to the size of the property found.
+
+  @return The property to the structure of the found property.
+
+**/
+CONST struct fdt_property *
+EFIAPI
+FdtGetProperty (
+  IN CONST VOID   *Fdt,
+  IN INT32        NodeOffset,
+  IN CONST CHAR8  *Name,
+  IN INT32        *Length
+  )
+{
+  return fdt_get_property (Fdt, NodeOffset, Name, Length);
+}
+
+/**
+  Returns a offset of first property in the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] NodeOffset     The offset to the node which need be searched.
+
+  @return The offset to first property offset in the given node.
+
+**/
+INT32
+EFIAPI
+FdtFirstPropertyOffset (
+  IN CONST VOID  *Fdt,
+  IN INT32       NodeOffset
+  )
+{
+  return fdt_first_property_offset (Fdt, NodeOffset);
+}
+
+/**
+  Returns a offset of next property from the given property.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to previous property.
+
+  @return The offset to next property offset.
+
+**/
+INT32
+EFIAPI
+FdtNextPropertyOffset (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset
+  )
+{
+  return fdt_next_property_offset (Fdt, Offset);
+}
+
+/**
+  Returns a property from the given offset of the property.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] Offset         The offset to the given offset of the property.
+  @param[in] Length         The length to the size of the property found.
+
+  @return The property to the structure of the given property offset.
+
+**/
+CONST struct fdt_property *
+EFIAPI
+FdtGetPropertyByOffset (
+  IN CONST VOID  *Fdt,
+  IN INT32       Offset,
+  IN INT32       *Length
+  )
+{
+  return fdt_get_property_by_offset (Fdt, Offset, Length);
+}
+
+/**
+  Returns a string by the given string offset.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] StrOffset      The offset to the location in the strings block of FDT.
+  @param[in] Length         The length to the size of string which need be retrieved.
+
+  @return The string to the given string offset.
+
+**/
+CONST CHAR8 *
+EFIAPI
+FdtGetString (
+  IN CONST VOID  *Fdt,
+  IN INT32       StrOffset,
+  IN INT32       *Length        OPTIONAL
+  )
+{
+  return fdt_get_string (Fdt, StrOffset, Length);
+}
+
+/**
+  Add a new node to the FDT.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] ParentOffset   The offset to the node offset which want to add in.
+  @param[in] Name           The name to name the node.
+
+  @return  The offset to the new node.
+
+**/
+INT32
+EFIAPI
+FdtAddSubnode (
+  IN VOID         *Fdt,
+  IN INT32        ParentOffset,
+  IN CONST CHAR8  *Name
+  )
+{
+  return fdt_add_subnode (Fdt, ParentOffset, Name);
+}
+
+/**
+  Add or modify a property in the given node.
+
+  @param[in] Fdt            The pointer to FDT blob.
+  @param[in] NodeOffset     The offset to the node offset which want to add in.
+  @param[in] Name           The name to name the property.
+  @param[in] Value          The value to the property value.
+  @param[in] Length         The length to the size of the property.
+
+  @return  Zero for successfully, otherwise failed.
+
+**/
+INT32
+EFIAPI
+FdtSetProp (
+  IN VOID         *Fdt,
+  IN INT32        NodeOffset,
+  IN CONST CHAR8  *Name,
+  IN CONST VOID   *Value,
+  IN UINT32       Length
+  )
+{
+  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
+}
diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
new file mode 100644
index 0000000000..e738f4ded4
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
@@ -0,0 +1,99 @@
+/** @file
+  Root include file of C runtime library to support building the third-party
+  libfdt library.
+
+  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef FDT_LIB_SUPPORT_H_
+#define FDT_LIB_SUPPORT_H_
+
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+typedef UINT8    uint8_t;
+typedef UINT16   uint16_t;
+typedef INT32    int32_t;
+typedef UINT32   uint32_t;
+typedef UINT64   uint64_t;
+typedef UINTN    uintptr_t;
+typedef UINTN    size_t;
+typedef BOOLEAN  bool;
+
+#define true   (1 == 1)
+#define false  (1 == 0)
+
+//
+// Definitions for global constants used by libfdt library routines
+//
+#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value */
+#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32 value */
+#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32 value */
+
+//
+// Function prototypes of libfdt Library routines
+//
+void *
+memset     (
+  void *,
+  int,
+  size_t
+  );
+
+int
+memcmp      (
+  const void *,
+  const void *,
+  size_t
+  );
+
+int
+strcmp      (
+  const char *,
+  const char *
+  );
+
+char *
+strchr     (
+  const char *,
+  int
+  );
+
+char *
+strrchr    (
+  const char *,
+  int
+  );
+
+unsigned long
+strtoul     (
+  const char *,
+  char **,
+  int
+  );
+
+char *
+strcpy (
+  char        *strDest,
+  const char  *strSource
+  );
+
+//
+// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
+//
+#define memcpy(dest, source, count)         CopyMem(dest,source, (UINTN)(count))
+#define memset(dest, ch, count)             SetMem(dest, (UINTN)(count),(UINT8)(ch))
+#define memchr(buf, ch, count)              ScanMem8(buf, (UINTN)(count),(UINT8)ch)
+#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1, buf2, (UINTN)(count)))
+#define memmove(dest, source, count)        CopyMem(dest, source, (UINTN)(count))
+#define strlen(str)                         (size_t)(AsciiStrLen(str))
+#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
+#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest, MAX_STRING_SIZE, strSource, (UINTN)count)
+#define strcat(strDest, strSource)          AsciiStrCatS(strDest, MAX_STRING_SIZE, strSource)
+#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1, string2))
+#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1, string2, (UINTN)(count)))
+
+#endif /* FDT_LIB_SUPPORT_H_ */
diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
new file mode 100644
index 0000000000..772bba4839
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
@@ -0,0 +1,173 @@
+/** @file
+  ISO C implementations of strchr, strrchr and strtoul.
+
+  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2023 Pedro Falcato All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+
+#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long value */
+
+// Very quick notes:
+// We only go through the string once for both functions
+// They are minimal implementations (not speed optimized) of ISO C semantics
+// strchr and strrchr also include the null terminator as part of the string
+// so the code gets a bit clunky to handle that case specifically.
+
+char *
+strchr (
+  const char  *Str,
+  int         Char
+  )
+{
+  char  *S;
+
+  S = (char *)Str;
+
+  for ( ; ; S++) {
+    if (*S == Char) {
+      return S;
+    }
+
+    if (*S == '\0') {
+      return NULL;
+    }
+  }
+}
+
+char *
+strrchr (
+  const char  *Str,
+  int         Char
+  )
+{
+  char  *S, *last;
+
+  S    = (char *)Str;
+  last = NULL;
+
+  for ( ; ; S++) {
+    if (*S == Char) {
+      last = S;
+    }
+
+    if (*S == '\0') {
+      return last;
+    }
+  }
+}
+
+STATIC
+int
+__isspace (
+  int  ch
+  )
+{
+  // basic ASCII ctype.h:isspace(). Not efficient
+  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f';
+}
+
+unsigned long
+strtoul (
+  const char  *Nptr,
+  char        **EndPtr,
+  int         Base
+  )
+{
+  BOOLEAN        Negate;
+  BOOLEAN        Overflow;
+  unsigned long  Val;
+
+  Negate   = FALSE;
+  Overflow = FALSE;
+  Val      = 0;
+
+  // Reject bad numeric bases
+  if ((Base < 0) || (Base == 1) || (Base > 36)) {
+    return 0;
+  }
+
+  // Skip whitespace
+  while (__isspace (*Nptr)) {
+    Nptr++;
+  }
+
+  // Check for + or - prefixes
+  if (*Nptr == '-') {
+    Negate = TRUE;
+    Nptr++;
+  } else if (*Nptr == '+') {
+    Nptr++;
+  }
+
+  // Consume the start, autodetecting base if needed
+  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X')) && ((Base == 0) || (Base == 16))) {
+    // Hex
+    Nptr += 2;
+    Base  = 16;
+  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] == 'B')) && ((Base == 0) || (Base == 2))) {
+    // Binary (standard pending C23)
+    Nptr += 2;
+    Base  = 2;
+  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
+    // Octal
+    Nptr++;
+    Base = 8;
+  } else {
+    if (Base == 0) {
+      // Assume decimal
+      Base = 10;
+    }
+  }
+
+  while (TRUE) {
+    int            Digit;
+    char           C;
+    unsigned long  NewVal;
+
+    C     = *Nptr;
+    Digit = -1;
+
+    if ((C >= '0') && (C <= '9')) {
+      Digit = C - '0';
+    } else if ((C >= 'a') && (C <= 'z')) {
+      Digit = C - 'a' + 10;
+    } else if ((C >= 'A') && (C <= 'Z')) {
+      Digit = C - 'A' + 10;
+    }
+
+    if ((Digit == -1) || (Digit >= Base)) {
+      // Note that this case also handles the \0
+      if (EndPtr) {
+        *EndPtr = (char *)Nptr;
+      }
+
+      break;
+    }
+
+    NewVal = Val * Base + Digit;
+
+    if (NewVal < Val) {
+      // Overflow
+      Overflow = TRUE;
+    }
+
+    Val = NewVal;
+
+    Nptr++;
+  }
+
+  if (Negate) {
+    Val = -Val;
+  }
+
+  if (Overflow) {
+    Val = ULONG_MAX;
+  }
+
+  // TODO: We're lacking errno here.
+  return Val;
+}
diff --git a/MdePkg/Library/BaseFdtLib/limits.h b/MdePkg/Library/BaseFdtLib/limits.h
new file mode 100644
index 0000000000..f6cf8d5702
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/limits.h
@@ -0,0 +1,10 @@
+/** @file
+  Include file to support building the third-party libfdt library.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <LibFdtSupport.h>
+
diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h b/MdePkg/Library/BaseFdtLib/stdbool.h
new file mode 100644
index 0000000000..f6cf8d5702
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/stdbool.h
@@ -0,0 +1,10 @@
+/** @file
+  Include file to support building the third-party libfdt library.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <LibFdtSupport.h>
+
diff --git a/MdePkg/Library/BaseFdtLib/stddef.h b/MdePkg/Library/BaseFdtLib/stddef.h
new file mode 100644
index 0000000000..f6cf8d5702
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/stddef.h
@@ -0,0 +1,10 @@
+/** @file
+  Include file to support building the third-party libfdt library.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <LibFdtSupport.h>
+
diff --git a/MdePkg/Library/BaseFdtLib/stdint.h b/MdePkg/Library/BaseFdtLib/stdint.h
new file mode 100644
index 0000000000..f6cf8d5702
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/stdint.h
@@ -0,0 +1,10 @@
+/** @file
+  Include file to support building the third-party libfdt library.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <LibFdtSupport.h>
+
diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h b/MdePkg/Library/BaseFdtLib/stdlib.h
new file mode 100644
index 0000000000..f6cf8d5702
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/stdlib.h
@@ -0,0 +1,10 @@
+/** @file
+  Include file to support building the third-party libfdt library.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <LibFdtSupport.h>
+
diff --git a/MdePkg/Library/BaseFdtLib/string.h b/MdePkg/Library/BaseFdtLib/string.h
new file mode 100644
index 0000000000..f6cf8d5702
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/string.h
@@ -0,0 +1,10 @@
+/** @file
+  Include file to support building the third-party libfdt library.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <LibFdtSupport.h>
+
diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
index 6ba85ebe61..f039daccdb 100644
--- a/MdePkg/MdePkg.ci.yaml
+++ b/MdePkg/MdePkg.ci.yaml
@@ -2,7 +2,7 @@
 # CI configuration for MdePkg
 #
 # Copyright (c) Microsoft Corporation
-# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
 # Copyright (c) 2023, Loongson Technology Corporation Limited. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -67,7 +67,8 @@
             "Include/Library/PcdLib.h",
             "Include/Library/SafeIntLib.h",
             "Include/Protocol/DebugSupport.h",
-            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
+            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
+            "Library/BaseFdtLib"
         ]
     },
     ## options defined ci/Plugin/CompilerPlugin
@@ -164,5 +165,17 @@
         "ExtendWords": [],           # words to extend to the dictionary for this package
         "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
         "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported)
+    },
+    # options defined in .pytool/Plugin/UncrustifyCheck
+    "UncrustifyCheck": {
+        "IgnoreFiles": [
+            "Library/BaseFdtLib/libfdt",
+            "Library/BaseFdtLib/limits.h",
+            "Library/BaseFdtLib/stdbool.h",
+            "Library/BaseFdtLib/stddef.h",
+            "Library/BaseFdtLib/stdint.h",
+            "Library/BaseFdtLib/stdlib.h",
+            "Library/BaseFdtLib/string.h"
+        ]
     }
 }
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index e70182bf7f..9804a7a6bd 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -289,6 +289,10 @@
   #
   ArmTrngLib|Include/Library/ArmTrngLib.h
 
+  ##  @libraryclass  Provides APIs for third-party library libfdt.
+  #
+  FdtLib|Include/Library/FdtLib.h
+
 [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
   ##  @libraryclass  Provides services to generate random number.
   #
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 152c02991a..b38c863812 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -137,6 +137,7 @@
   MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
 
   MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
+  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
 
 [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
   #
-- 
2.39.1.windows.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v3 3/3] .pytool: Support FDT library.
  2023-04-17  5:35 [PATCH v3 0/3] Support FDT library Benny Lin
  2023-04-17  5:35 ` [PATCH v3 1/3] Tianocore: " Benny Lin
  2023-04-17  5:35 ` [PATCH v3 2/3] MdePkg: " Benny Lin
@ 2023-04-17  5:35 ` Benny Lin
  2023-04-19 15:58   ` Michael D Kinney
  2 siblings, 1 reply; 20+ messages in thread
From: Benny Lin @ 2023-04-17  5:35 UTC (permalink / raw)
  To: devel; +Cc: Benny Lin, Sean Brogan, Michael Kubacki, Michael D Kinney,
	Liming Gao

From: Benny Lin <benny.lin@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
Add FDT support in EDK2 by submodule 3rd party libfdt
(https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)

Add RequiredSubmodule object for CI setting.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Benny Lin <benny.lin@intel.com>
---
 .pytool/CISettings.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.pytool/CISettings.py b/.pytool/CISettings.py
index e3f44add58..2fb99f2a17 100644
--- a/.pytool/CISettings.py
+++ b/.pytool/CISettings.py
@@ -195,6 +195,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
             "RedfishPkg/Library/JsonLib/jansson", False))
         rs.append(RequiredSubmodule(
             "UnitTestFrameworkPkg/Library/SubhookLib/subhook", False))
+        rs.append(RequiredSubmodule(
+            "MdePkg/Library/BaseFdtLib/libfdt", False))
         return rs
 
     def GetName(self):
-- 
2.39.1.windows.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-17  5:35 ` [PATCH v3 2/3] MdePkg: " Benny Lin
@ 2023-04-19 15:54   ` Michael D Kinney
  2023-04-19 17:11     ` Benny Lin
  0 siblings, 1 reply; 20+ messages in thread
From: Michael D Kinney @ 2023-04-19 15:54 UTC (permalink / raw)
  To: Lin, Benny, devel@edk2.groups.io
  Cc: Gao, Liming, Liu, Zhiguang, Pedro Falcato, Kinney, Michael D

A few comments below.

Mike

> -----Original Message-----
> From: Lin, Benny <benny.lin@intel.com>
> Sent: Sunday, April 16, 2023 10:35 PM
> To: devel@edk2.groups.io
> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> From: Benny Lin <benny.lin@intel.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> Add FDT support in EDK2 by submodule 3rd party libfdt
> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> and refer to LibcLib implementation by Pedro.
> 
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> Signed-off-by: Benny Lin <benny.lin@intel.com>
> ---
>  MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
>  MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
>  MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
>  MdePkg/MdePkg.ci.yaml                     |  17 +-
>  MdePkg/MdePkg.dec                         |   4 +
>  MdePkg/MdePkg.dsc                         |   1 +
>  15 files changed, 1043 insertions(+), 2 deletions(-)
> 
> diff --git a/MdePkg/Include/Library/FdtLib.h b/MdePkg/Include/Library/FdtLib.h
> new file mode 100644
> index 0000000000..d59b749c25
> --- /dev/null
> +++ b/MdePkg/Include/Library/FdtLib.h
> @@ -0,0 +1,314 @@
> +/** @file
> 
> +  Flattened Device Tree Library.
> 
> +
> 
> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#ifndef FDT_LIB_H_
> 
> +#define FDT_LIB_H_
> 
> +
> 
> +///
> 
> +/// Flattened Device Tree definition
> 
> +///
> 
> +typedef struct {
> 
> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> 
> +  UINT32    TotalSize;           /* total size of DT block */
> 
> +  UINT32    OffsetDtStruct;      /* offset to structure */
> 
> +  UINT32    OffsetDtStrings;     /* offset to strings */
> 
> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map */
> 
> +  UINT32    Version;             /* format version */
> 
> +  UINT32    LastCompVersion;     /* last compatible version */
> 
> +
> 
> +  /* version 2 fields below */
> 
> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
> 
> +                                    booting on */
> 
> +  /* version 3 fields below */
> 
> +  UINT32    SizeDtStrings;       /* size of the strings block */
> 
> +
> 
> +  /* version 17 fields below */
> 
> +  UINT32    SizeDtStruct;        /* size of the structure block */
> 
> +} FDT_HEADER;

I see the macros below use SwapBytes32() on all the fields from this
structure.  Does this mean this structure is big endian?  If that is
the case, then the description of this structure and all individual 
fields must make that very clear so any consumer of the structure knows
it does not follow the default endianness of UEFI/PI and that consumers
must either use the macros or consumers must use SwapBytes32() on
their own when using this structure directly.

> 
> +
> 
> +typedef struct {
> 
> +  UINT64    Address;
> 
> +  UINT64    Size;
> 
> +} FDT_RESERVE_ENTRY;


I do not see this type used anywhere in the lib class or the lib instance.
Can it be removed?

> 
> +
> 
> +typedef struct {
> 
> +  UINT32    Tag;
> 
> +  CHAR8     Name[];
> 
> +} FDT_NODE_HEADER;


I do not see this type used anywhere in the lib class or the lib instance.
Can it be removed?

> 
> +
> 
> +typedef struct {
> 
> +  UINT32    Tag;
> 
> +  UINT32    Length;
> 
> +  UINT32    NameOffset;
> 
> +  CHAR8     Data[];
> 
> +} FDT_PROPERTY;
> 
> +
> 
> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST FDT_HEADER *)(Fdt))->Field)
> 
> +
> 
> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
> 
> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt, TotalSize))
> 
> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt, OffsetDtStruct))
> 
> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt, OffsetDtStrings))
> 
> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt, OffsetMemRsvmap))
> 
> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
> 
> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt, LastCompVersion))
> 
> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt, BootCpuidPhys))
> 
> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt, SizeDtStrings))
> 
> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt, SizeDtStruct))
> 
> +
> 
> +/**
> 
> +  Verify the header of the Flattened Device Tree
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +
> 
> +  @return Zero for successfully, otherwise failed.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtCheckHeader (
> 
> +  IN CONST VOID  *Fdt
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Create a empty Flattened Device Tree.
> 
> +
> 
> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> 
> +  @param[in] BufferSize     The BufferSize to the pool size.
> 
> +
> 
> +  @return Zero for successfully, otherwise failed.
> 
> +
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +FdtCreateEmptyTree (
> 
> +  IN VOID   *Buffer,
> 
> +  IN UINTN  BufferSize
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a offset of next node from the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to previous node.
> 
> +  @param[in] Depth          The depth to the level of tree hierarchy.
> 
> +
> 
> +  @return The offset to next node offset.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtNextNode (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset,
> 
> +  IN INT32       *Depth
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a offset of first node under the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to previous node.
> 
> +
> 
> +  @return The offset to next node offset.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtFirstSubnode (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a offset of next node from the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to previous node.
> 
> +
> 
> +  @return The offset to next node offset.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtNextSubnode (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a offset of first node which includes the given name.
> 
> +
> 
> +  @param[in] Fdt             The pointer to FDT blob.
> 
> +  @param[in] ParentOffset    The offset to the node which start find under.
> 
> +  @param[in] Name            The name to search the node with the name.
> 
> +  @param[in] NameLength      The length of the name to check only.
> 
> +
> 
> +  @return The offset to node offset with given node name.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtSubnodeOffsetNameLen (
> 
> +  IN CONST VOID   *Fdt,
> 
> +  IN INT32        ParentOffset,
> 
> +  IN CONST CHAR8  *Name,
> 
> +  IN INT32        NameLength
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a offset of first node which includes the given property name and value.
> 
> +
> 
> +  @param[in] Fdt             The pointer to FDT blob.
> 
> +  @param[in] StartOffset     The offset to the starting node to find.
> 
> +  @param[in] PropertyName    The property name to search the node including the named property.
> 
> +  @param[in] PropertyValue   The property value to check the same property value.
> 
> +  @param[in] PropertyLength  The length of the value in PropertValue.
> 
> +
> 
> +  @return The offset to node offset with given property.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtNodeOffsetByPropValue (
> 
> +  IN CONST VOID   *Fdt,
> 
> +  IN INT32        StartOffset,
> 
> +  IN CONST CHAR8  *PropertyName,
> 
> +  IN CONST VOID   *PropertyValue,
> 
> +  IN INT32        PropertyLength
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a property with the given name from the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] NodeOffset     The offset to the given node.
> 
> +  @param[in] Name           The name to the property which need be searched
> 
> +  @param[in] Length         The length to the size of the property found.
> 
> +
> 
> +  @return The property to the structure of the found property.
> 
> +
> 
> +**/
> 
> +CONST FDT_PROPERTY *
> 
> +EFIAPI
> 
> +FdtGetProperty (
> 
> +  IN CONST VOID   *Fdt,
> 
> +  IN INT32        NodeOffset,
> 
> +  IN CONST CHAR8  *Name,
> 
> +  IN INT32        *Length
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a offset of first property in the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to the node which need be searched.
> 
> +
> 
> +  @return The offset to first property offset in the given node.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtFirstPropertyOffset (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       NodeOffset
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a offset of next property from the given property.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to previous property.
> 
> +
> 
> +  @return The offset to next property offset.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtNextPropertyOffset (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a property from the given offset of the property.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to the given offset of the property.
> 
> +  @param[in] Length         The length to the size of the property found.
> 
> +
> 
> +  @return The property to the structure of the given property offset.
> 
> +
> 
> +**/
> 
> +CONST FDT_PROPERTY *
> 
> +EFIAPI
> 
> +FdtGetPropertyByOffset (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset,
> 
> +  IN INT32       *Length
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Returns a string by the given string offset.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> 
> +  @param[in] Length         The length to the size of string which need be retrieved.
> 
> +
> 
> +  @return The string to the given string offset.
> 
> +
> 
> +**/
> 
> +CONST CHAR8 *
> 
> +EFIAPI
> 
> +FdtGetString (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       StrOffset,
> 
> +  IN INT32       *Length        OPTIONAL
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Add a new node to the FDT.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> 
> +  @param[in] Name           The name to name the node.
> 
> +
> 
> +  @return  The offset to the new node.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtAddSubnode (
> 
> +  IN VOID         *Fdt,
> 
> +  IN INT32        ParentOffset,
> 
> +  IN CONST CHAR8  *Name
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Add or modify a property in the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> 
> +  @param[in] Name           The name to name the property.
> 
> +  @param[in] Value          The value to the property value.
> 
> +  @param[in] Length         The length to the size of the property.
> 
> +
> 
> +  @return  Zero for successfully, otherwise failed.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtSetProp (
> 
> +  IN VOID         *Fdt,
> 
> +  IN INT32        NodeOffset,
> 
> +  IN CONST CHAR8  *Name,
> 
> +  IN CONST VOID   *Value,
> 
> +  IN UINT32       Length
> 
> +  );
> 
> +
> 
> +#endif /* FDT_LIB_H_ */
> 
> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> new file mode 100644
> index 0000000000..730e568ff6
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> @@ -0,0 +1,62 @@
> +## @file
> 
> +# Flattened Device Tree Library.
> 
> +#
> 
> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +#
> 
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +#
> 
> +#
> 
> +##
> 
> +
> 
> +[Defines]
> 
> +  INF_VERSION                    = 0x0001001B
> 
> +  BASE_NAME                      = BaseFdtLib
> 
> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> 
> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-E8CEC206DE04
> 
> +  MODULE_TYPE                    = BASE
> 
> +  VERSION_STRING                 = 1.0
> 
> +  LIBRARY_CLASS                  = FdtLib
> 
> +
> 
> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> 
> +
> 
> +#
> 
> +#  VALID_ARCHITECTURES           = IA32 X64
> 
> +#
> 
> +
> 
> +[Sources]
> 
> +  FdtLib.c
> 
> +  LibFdtWrapper.c
> 
> +  # header Wrapper files
> 
> +  limits.h
> 
> +  stdbool.h
> 
> +  stddef.h
> 
> +  stdint.h
> 
> +  stdlib.h
> 
> +  string.h
> 
> +
> 
> +  $(FDT_LIB_PATH)/fdt.c
> 
> +  $(FDT_LIB_PATH)/fdt.h
> 
> +  $(FDT_LIB_PATH)/fdt_addresses.c
> 
> +  $(FDT_LIB_PATH)/fdt_check.c
> 
> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> 
> +  $(FDT_LIB_PATH)/fdt_overlay.c
> 
> +  $(FDT_LIB_PATH)/fdt_ro.c
> 
> +  $(FDT_LIB_PATH)/fdt_rw.c
> 
> +  $(FDT_LIB_PATH)/fdt_strerror.c
> 
> +  $(FDT_LIB_PATH)/fdt_sw.c
> 
> +  $(FDT_LIB_PATH)/fdt_wip.c
> 
> +  $(FDT_LIB_PATH)/libfdt.h
> 
> +  $(FDT_LIB_PATH)/libfdt_env.h
> 
> +  $(FDT_LIB_PATH)/libfdt_internal.h
> 
> +
> 
> +[Packages]
> 
> +  MdePkg/MdePkg.dec
> 
> +
> 
> +[LibraryClasses]
> 
> +  BaseLib
> 
> +  BaseMemoryLib
> 
> +
> 
> +[BuildOptions]
> 
> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> 
> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
> 
> +
> 
> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> new file mode 100644
> index 0000000000..3f7e45ea6f
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> @@ -0,0 +1,14 @@
> +// /** @file
> 
> +// Flattened Device Tree Library.
> 
> +//
> 
> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +//
> 
> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +//
> 
> +// **/
> 
> +
> 
> +
> 
> +#string STR_MODULE_ABSTRACT             #language en-US "Instance of FDT Library"
> 
> +
> 
> +#string STR_MODULE_DESCRIPTION          #language en-US "This module provides FDT Library implementation."
> 
> +
> 
> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c b/MdePkg/Library/BaseFdtLib/FdtLib.c
> new file mode 100644
> index 0000000000..200a496c7e
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> @@ -0,0 +1,301 @@
> +/** @file
> 
> +  Flattened Device Tree Library.
> 
> +
> 
> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <libfdt/libfdt/libfdt.h>
> 
> +
> 
> +/**
> 
> +  Verify the header of the Flattened Device Tree
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +
> 
> +  @return Zero for successfully, otherwise failed.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtCheckHeader (
> 
> +  IN CONST VOID  *Fdt
> 
> +  )
> 
> +{
> 
> +  return fdt_check_header(Fdt);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Create a empty Flattened Device Tree.
> 
> +
> 
> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> 
> +  @param[in] BufferSize     The BufferSize to the pool size.
> 
> +
> 
> +  @return Zero for successfully, otherwise failed.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtCreateEmptyTree (
> 
> +  IN VOID    *Buffer,
> 
> +  IN UINT32  BufferSize
> 
> +  )
> 
> +{
> 
> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a offset of next node from the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to previous node.
> 
> +  @param[in] Depth          The depth to the level of tree hierarchy.
> 
> +
> 
> +  @return The offset to next node offset.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtNextNode (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset,
> 
> +  IN INT32       *Depth
> 
> +  )
> 
> +{
> 
> +  return fdt_next_node (Fdt, Offset, Depth);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a offset of first node under the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to previous node.
> 
> +
> 
> +  @return The offset to next node offset.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtFirstSubnode (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset
> 
> +  )
> 
> +{
> 
> +  return fdt_first_subnode (Fdt, Offset);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a offset of next node from the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to previous node.
> 
> +
> 
> +  @return The offset to next node offset.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtNextSubnode (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset
> 
> +  )
> 
> +{
> 
> +  return fdt_next_subnode (Fdt, Offset);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a offset of first node which includes the given name.
> 
> +
> 
> +  @param[in] Fdt             The pointer to FDT blob.
> 
> +  @param[in] ParentOffset    The offset to the node which start find under.
> 
> +  @param[in] Name            The name to search the node with the name.
> 
> +  @param[in] NameLength      The length of the name to check only.
> 
> +
> 
> +  @return The offset to node offset with given node name.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtSubnodeOffsetNameLen (
> 
> +  IN CONST VOID   *Fdt,
> 
> +  IN INT32        ParentOffset,
> 
> +  IN CONST CHAR8  *Name,
> 
> +  IN INT32        NameLength
> 
> +  )
> 
> +{
> 
> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name, NameLength);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a offset of first node which includes the given property name and value.
> 
> +
> 
> +  @param[in] Fdt             The pointer to FDT blob.
> 
> +  @param[in] StartOffset     The offset to the starting node to find.
> 
> +  @param[in] PropertyName    The property name to search the node including the named property.
> 
> +  @param[in] PropertyValue   The property value to check the same property value.
> 
> +  @param[in] PropertyLength  The length of the value in PropertValue.
> 
> +
> 
> +  @return The offset to node offset with given property.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtNodeOffsetByPropValue (
> 
> +  IN CONST VOID   *Fdt,
> 
> +  IN INT32        StartOffset,
> 
> +  IN CONST CHAR8  *PropertyName,
> 
> +  IN CONST VOID   *PropertyValue,
> 
> +  IN INT32        PropertyLength
> 
> +  )
> 
> +{
> 
> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset, PropertyName, PropertyValue, PropertyLength);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a property with the given name from the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] NodeOffset     The offset to the given node.
> 
> +  @param[in] Name           The name to the property which need be searched
> 
> +  @param[in] Length         The length to the size of the property found.
> 
> +
> 
> +  @return The property to the structure of the found property.
> 
> +
> 
> +**/
> 
> +CONST struct fdt_property *
> 
> +EFIAPI
> 
> +FdtGetProperty (
> 
> +  IN CONST VOID   *Fdt,
> 
> +  IN INT32        NodeOffset,
> 
> +  IN CONST CHAR8  *Name,
> 
> +  IN INT32        *Length
> 
> +  )
> 
> +{
> 
> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a offset of first property in the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] NodeOffset     The offset to the node which need be searched.
> 
> +
> 
> +  @return The offset to first property offset in the given node.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtFirstPropertyOffset (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       NodeOffset
> 
> +  )
> 
> +{
> 
> +  return fdt_first_property_offset (Fdt, NodeOffset);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a offset of next property from the given property.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to previous property.
> 
> +
> 
> +  @return The offset to next property offset.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtNextPropertyOffset (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset
> 
> +  )
> 
> +{
> 
> +  return fdt_next_property_offset (Fdt, Offset);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a property from the given offset of the property.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] Offset         The offset to the given offset of the property.
> 
> +  @param[in] Length         The length to the size of the property found.
> 
> +
> 
> +  @return The property to the structure of the given property offset.
> 
> +
> 
> +**/
> 
> +CONST struct fdt_property *
> 
> +EFIAPI
> 
> +FdtGetPropertyByOffset (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       Offset,
> 
> +  IN INT32       *Length
> 
> +  )
> 
> +{
> 
> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Returns a string by the given string offset.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> 
> +  @param[in] Length         The length to the size of string which need be retrieved.
> 
> +
> 
> +  @return The string to the given string offset.
> 
> +
> 
> +**/
> 
> +CONST CHAR8 *
> 
> +EFIAPI
> 
> +FdtGetString (
> 
> +  IN CONST VOID  *Fdt,
> 
> +  IN INT32       StrOffset,
> 
> +  IN INT32       *Length        OPTIONAL
> 
> +  )
> 
> +{
> 
> +  return fdt_get_string (Fdt, StrOffset, Length);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Add a new node to the FDT.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> 
> +  @param[in] Name           The name to name the node.
> 
> +
> 
> +  @return  The offset to the new node.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtAddSubnode (
> 
> +  IN VOID         *Fdt,
> 
> +  IN INT32        ParentOffset,
> 
> +  IN CONST CHAR8  *Name
> 
> +  )
> 
> +{
> 
> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> 
> +}
> 
> +
> 
> +/**
> 
> +  Add or modify a property in the given node.
> 
> +
> 
> +  @param[in] Fdt            The pointer to FDT blob.
> 
> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> 
> +  @param[in] Name           The name to name the property.
> 
> +  @param[in] Value          The value to the property value.
> 
> +  @param[in] Length         The length to the size of the property.
> 
> +
> 
> +  @return  Zero for successfully, otherwise failed.
> 
> +
> 
> +**/
> 
> +INT32
> 
> +EFIAPI
> 
> +FdtSetProp (
> 
> +  IN VOID         *Fdt,
> 
> +  IN INT32        NodeOffset,
> 
> +  IN CONST CHAR8  *Name,
> 
> +  IN CONST VOID   *Value,
> 
> +  IN UINT32       Length
> 
> +  )
> 
> +{
> 
> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> 
> +}
> 
> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> new file mode 100644
> index 0000000000..e738f4ded4
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> @@ -0,0 +1,99 @@
> +/** @file
> 
> +  Root include file of C runtime library to support building the third-party
> 
> +  libfdt library.
> 
> +
> 
> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#ifndef FDT_LIB_SUPPORT_H_
> 
> +#define FDT_LIB_SUPPORT_H_
> 
> +
> 
> +#include <Base.h>
> 
> +#include <Library/BaseLib.h>
> 
> +#include <Library/BaseMemoryLib.h>
> 
> +
> 
> +typedef UINT8    uint8_t;
> 
> +typedef UINT16   uint16_t;
> 
> +typedef INT32    int32_t;
> 
> +typedef UINT32   uint32_t;
> 
> +typedef UINT64   uint64_t;
> 
> +typedef UINTN    uintptr_t;
> 
> +typedef UINTN    size_t;
> 
> +typedef BOOLEAN  bool;
> 
> +
> 
> +#define true   (1 == 1)
> 
> +#define false  (1 == 0)
> 
> +
> 
> +//
> 
> +// Definitions for global constants used by libfdt library routines
> 
> +//
> 
> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value */
> 
> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32 value */
> 
> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32 value */
> 
> +
> 
> +//
> 
> +// Function prototypes of libfdt Library routines
> 
> +//
> 
> +void *
> 
> +memset     (
> 
> +  void *,
> 
> +  int,
> 
> +  size_t
> 
> +  );
> 
> +
> 
> +int
> 
> +memcmp      (
> 
> +  const void *,
> 
> +  const void *,
> 
> +  size_t
> 
> +  );
> 
> +
> 
> +int
> 
> +strcmp      (
> 
> +  const char *,
> 
> +  const char *
> 
> +  );
> 
> +
> 
> +char *
> 
> +strchr     (
> 
> +  const char *,
> 
> +  int
> 
> +  );
> 
> +
> 
> +char *
> 
> +strrchr    (
> 
> +  const char *,
> 
> +  int
> 
> +  );
> 
> +
> 
> +unsigned long
> 
> +strtoul     (
> 
> +  const char *,
> 
> +  char **,
> 
> +  int
> 
> +  );
> 
> +
> 
> +char *
> 
> +strcpy (
> 
> +  char        *strDest,
> 
> +  const char  *strSource
> 
> +  );
> 
> +
> 
> +//
> 
> +// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
> 
> +//
> 
> +#define memcpy(dest, source, count)         CopyMem(dest,source, (UINTN)(count))
> 
> +#define memset(dest, ch, count)             SetMem(dest, (UINTN)(count),(UINT8)(ch))
> 
> +#define memchr(buf, ch, count)              ScanMem8(buf, (UINTN)(count),(UINT8)ch)
> 
> +#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1, buf2, (UINTN)(count)))
> 
> +#define memmove(dest, source, count)        CopyMem(dest, source, (UINTN)(count))
> 
> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> 
> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
> 
> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest, MAX_STRING_SIZE, strSource, (UINTN)count)
> 
> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest, MAX_STRING_SIZE, strSource)
> 
> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1, string2))
> 
> +#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1, string2, (UINTN)(count)))
> 
> +
> 
> +#endif /* FDT_LIB_SUPPORT_H_ */
> 
> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> new file mode 100644
> index 0000000000..772bba4839
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> @@ -0,0 +1,173 @@
> +/** @file
> 
> +  ISO C implementations of strchr, strrchr and strtoul.
> 
> +
> 
> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> 
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <Base.h>
> 
> +
> 
> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long value */
> 
> +
> 
> +// Very quick notes:
> 
> +// We only go through the string once for both functions
> 
> +// They are minimal implementations (not speed optimized) of ISO C semantics
> 
> +// strchr and strrchr also include the null terminator as part of the string
> 
> +// so the code gets a bit clunky to handle that case specifically.
> 
> +
> 
> +char *
> 
> +strchr (
> 
> +  const char  *Str,
> 
> +  int         Char
> 
> +  )
> 
> +{
> 
> +  char  *S;
> 
> +
> 
> +  S = (char *)Str;
> 
> +
> 
> +  for ( ; ; S++) {
> 
> +    if (*S == Char) {
> 
> +      return S;
> 
> +    }
> 
> +
> 
> +    if (*S == '\0') {
> 
> +      return NULL;
> 
> +    }
> 
> +  }
> 
> +}
> 
> +
> 
> +char *
> 
> +strrchr (
> 
> +  const char  *Str,
> 
> +  int         Char
> 
> +  )
> 
> +{
> 
> +  char  *S, *last;
> 
> +
> 
> +  S    = (char *)Str;
> 
> +  last = NULL;
> 
> +
> 
> +  for ( ; ; S++) {
> 
> +    if (*S == Char) {
> 
> +      last = S;
> 
> +    }
> 
> +
> 
> +    if (*S == '\0') {
> 
> +      return last;
> 
> +    }
> 
> +  }
> 
> +}
> 
> +
> 
> +STATIC
> 
> +int
> 
> +__isspace (
> 
> +  int  ch
> 
> +  )
> 
> +{
> 
> +  // basic ASCII ctype.h:isspace(). Not efficient
> 
> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f';
> 
> +}
> 
> +
> 
> +unsigned long
> 
> +strtoul (
> 
> +  const char  *Nptr,
> 
> +  char        **EndPtr,
> 
> +  int         Base
> 
> +  )
> 
> +{
> 
> +  BOOLEAN        Negate;
> 
> +  BOOLEAN        Overflow;
> 
> +  unsigned long  Val;
> 
> +
> 
> +  Negate   = FALSE;
> 
> +  Overflow = FALSE;
> 
> +  Val      = 0;
> 
> +
> 
> +  // Reject bad numeric bases
> 
> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> 
> +    return 0;
> 
> +  }
> 
> +
> 
> +  // Skip whitespace
> 
> +  while (__isspace (*Nptr)) {
> 
> +    Nptr++;
> 
> +  }
> 
> +
> 
> +  // Check for + or - prefixes
> 
> +  if (*Nptr == '-') {
> 
> +    Negate = TRUE;
> 
> +    Nptr++;
> 
> +  } else if (*Nptr == '+') {
> 
> +    Nptr++;
> 
> +  }
> 
> +
> 
> +  // Consume the start, autodetecting base if needed
> 
> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X')) && ((Base == 0) || (Base == 16))) {
> 
> +    // Hex
> 
> +    Nptr += 2;
> 
> +    Base  = 16;
> 
> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] == 'B')) && ((Base == 0) || (Base == 2))) {
> 
> +    // Binary (standard pending C23)
> 
> +    Nptr += 2;
> 
> +    Base  = 2;
> 
> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> 
> +    // Octal
> 
> +    Nptr++;
> 
> +    Base = 8;
> 
> +  } else {
> 
> +    if (Base == 0) {
> 
> +      // Assume decimal
> 
> +      Base = 10;
> 
> +    }
> 
> +  }
> 
> +
> 
> +  while (TRUE) {
> 
> +    int            Digit;
> 
> +    char           C;
> 
> +    unsigned long  NewVal;
> 
> +
> 
> +    C     = *Nptr;
> 
> +    Digit = -1;
> 
> +
> 
> +    if ((C >= '0') && (C <= '9')) {
> 
> +      Digit = C - '0';
> 
> +    } else if ((C >= 'a') && (C <= 'z')) {
> 
> +      Digit = C - 'a' + 10;
> 
> +    } else if ((C >= 'A') && (C <= 'Z')) {
> 
> +      Digit = C - 'A' + 10;
> 
> +    }
> 
> +
> 
> +    if ((Digit == -1) || (Digit >= Base)) {
> 
> +      // Note that this case also handles the \0
> 
> +      if (EndPtr) {
> 
> +        *EndPtr = (char *)Nptr;
> 
> +      }
> 
> +
> 
> +      break;
> 
> +    }
> 
> +
> 
> +    NewVal = Val * Base + Digit;
> 
> +
> 
> +    if (NewVal < Val) {
> 
> +      // Overflow
> 
> +      Overflow = TRUE;
> 
> +    }
> 
> +
> 
> +    Val = NewVal;
> 
> +
> 
> +    Nptr++;
> 
> +  }
> 
> +
> 
> +  if (Negate) {
> 
> +    Val = -Val;
> 
> +  }
> 
> +
> 
> +  if (Overflow) {
> 
> +    Val = ULONG_MAX;
> 
> +  }
> 
> +
> 
> +  // TODO: We're lacking errno here.
> 
> +  return Val;
> 
> +}
> 
> diff --git a/MdePkg/Library/BaseFdtLib/limits.h b/MdePkg/Library/BaseFdtLib/limits.h
> new file mode 100644
> index 0000000000..f6cf8d5702
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> @@ -0,0 +1,10 @@
> +/** @file
> 
> +  Include file to support building the third-party libfdt library.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <LibFdtSupport.h>
> 
> +
> 
> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h b/MdePkg/Library/BaseFdtLib/stdbool.h
> new file mode 100644
> index 0000000000..f6cf8d5702
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> @@ -0,0 +1,10 @@
> +/** @file
> 
> +  Include file to support building the third-party libfdt library.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <LibFdtSupport.h>
> 
> +
> 
> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h b/MdePkg/Library/BaseFdtLib/stddef.h
> new file mode 100644
> index 0000000000..f6cf8d5702
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> @@ -0,0 +1,10 @@
> +/** @file
> 
> +  Include file to support building the third-party libfdt library.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <LibFdtSupport.h>
> 
> +
> 
> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h b/MdePkg/Library/BaseFdtLib/stdint.h
> new file mode 100644
> index 0000000000..f6cf8d5702
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> @@ -0,0 +1,10 @@
> +/** @file
> 
> +  Include file to support building the third-party libfdt library.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <LibFdtSupport.h>
> 
> +
> 
> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h b/MdePkg/Library/BaseFdtLib/stdlib.h
> new file mode 100644
> index 0000000000..f6cf8d5702
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> @@ -0,0 +1,10 @@
> +/** @file
> 
> +  Include file to support building the third-party libfdt library.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <LibFdtSupport.h>
> 
> +
> 
> diff --git a/MdePkg/Library/BaseFdtLib/string.h b/MdePkg/Library/BaseFdtLib/string.h
> new file mode 100644
> index 0000000000..f6cf8d5702
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/string.h
> @@ -0,0 +1,10 @@
> +/** @file
> 
> +  Include file to support building the third-party libfdt library.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <LibFdtSupport.h>
> 
> +
> 
> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
> index 6ba85ebe61..f039daccdb 100644
> --- a/MdePkg/MdePkg.ci.yaml
> +++ b/MdePkg/MdePkg.ci.yaml
> @@ -2,7 +2,7 @@
>  # CI configuration for MdePkg
> 
>  #
> 
>  # Copyright (c) Microsoft Corporation
> 
> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
> 
> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> 
>  # Copyright (c) 2023, Loongson Technology Corporation Limited. All rights reserved.<BR>
> 
>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -67,7 +67,8 @@
>              "Include/Library/PcdLib.h",
> 
>              "Include/Library/SafeIntLib.h",
> 
>              "Include/Protocol/DebugSupport.h",
> 
> -            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> 
> +            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> 
> +            "Library/BaseFdtLib"
> 
>          ]
> 
>      },
> 
>      ## options defined ci/Plugin/CompilerPlugin
> 
> @@ -164,5 +165,17 @@
>          "ExtendWords": [],           # words to extend to the dictionary for this package
> 
>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
> 
>          "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported)
> 
> +    },
> 
> +    # options defined in .pytool/Plugin/UncrustifyCheck
> 
> +    "UncrustifyCheck": {
> 
> +        "IgnoreFiles": [
> 
> +            "Library/BaseFdtLib/libfdt",
> 
> +            "Library/BaseFdtLib/limits.h",
> 
> +            "Library/BaseFdtLib/stdbool.h",
> 
> +            "Library/BaseFdtLib/stddef.h",
> 
> +            "Library/BaseFdtLib/stdint.h",
> 
> +            "Library/BaseFdtLib/stdlib.h",
> 
> +            "Library/BaseFdtLib/string.h"
> 
> +        ]
> 
>      }
> 
>  }
> 
> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
> index e70182bf7f..9804a7a6bd 100644
> --- a/MdePkg/MdePkg.dec
> +++ b/MdePkg/MdePkg.dec
> @@ -289,6 +289,10 @@
>    #
> 
>    ArmTrngLib|Include/Library/ArmTrngLib.h
> 
> 
> 
> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> 
> +  #
> 
> +  FdtLib|Include/Library/FdtLib.h
> 
> +
> 
>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> 
>    ##  @libraryclass  Provides services to generate random number.
> 
>    #
> 
> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
> index 152c02991a..b38c863812 100644
> --- a/MdePkg/MdePkg.dsc
> +++ b/MdePkg/MdePkg.dsc
> @@ -137,6 +137,7 @@
>    MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> 
> 
> 
>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> 
> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> 
> 
> 
>  [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
> 
>    #
> 
> --
> 2.39.1.windows.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 1/3] Tianocore: Support FDT library.
  2023-04-17  5:35 ` [PATCH v3 1/3] Tianocore: " Benny Lin
@ 2023-04-19 15:58   ` Michael D Kinney
  0 siblings, 0 replies; 20+ messages in thread
From: Michael D Kinney @ 2023-04-19 15:58 UTC (permalink / raw)
  To: Lin, Benny, devel@edk2.groups.io
  Cc: Andrew Fish, Leif Lindholm, Kinney, Michael D

Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>

> -----Original Message-----
> From: Lin, Benny <benny.lin@intel.com>
> Sent: Sunday, April 16, 2023 10:35 PM
> To: devel@edk2.groups.io
> Cc: Lin, Benny <benny.lin@intel.com>; Andrew Fish <afish@apple.com>; Leif Lindholm <quic_llindhol@quicinc.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>
> Subject: [PATCH v3 1/3] Tianocore: Support FDT library.
> 
> From: Benny Lin <benny.lin@intel.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> Add FDT support in EDK2 by submodule 3rd party libfdt
> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> 
> Add submodule libfdt and update ReadMe for the licence.
> 
> Cc: Andrew Fish <afish@apple.com>
> Cc: Leif Lindholm <quic_llindhol@quicinc.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Signed-off-by: Benny Lin <benny.lin@intel.com>
> ---
>  .gitmodules                      | 3 +++
>  MdePkg/Library/BaseFdtLib/libfdt | 1 +
>  ReadMe.rst                       | 1 +
>  3 files changed, 5 insertions(+)
> 
> diff --git a/.gitmodules b/.gitmodules
> index fe8a43be93..b1888c3488 100644
> --- a/.gitmodules
> +++ b/.gitmodules
> @@ -26,3 +26,6 @@
>  [submodule "UnitTestFrameworkPkg/Library/SubhookLib/subhook"]
>  	path = UnitTestFrameworkPkg/Library/SubhookLib/subhook
>  	url = https://github.com/Zeex/subhook.git
> +[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
> +	path = MdePkg/Library/BaseFdtLib/libfdt
> +	url = https://github.com/devicetree-org/pylibfdt.git
> diff --git a/MdePkg/Library/BaseFdtLib/libfdt b/MdePkg/Library/BaseFdtLib/libfdt
> new file mode 160000
> index 0000000000..cfff805481
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/libfdt
> @@ -0,0 +1 @@
> +Subproject commit cfff805481bdea27f900c32698171286542b8d3c
> diff --git a/ReadMe.rst b/ReadMe.rst
> index 91b9cf3c5e..d46c534229 100644
> --- a/ReadMe.rst
> +++ b/ReadMe.rst
> @@ -96,6 +96,7 @@ that are covered by additional licenses.
>  -  `UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
> <https://github.com/google/googletest/blob/86add13493e5c881d7e4ba77fb91c1f57752b3a4/LICENSE>`__
> 
>  -  `UnitTestFrameworkPkg/Library/SubhookLib/subhook
> <https://github.com/Zeex/subhook/blob/83d4e1ebef3588fae48b69a7352cc21801cb70bc/LICENSE.txt>`__
> 
>  -  `RedfishPkg/Library/JsonLib/jansson
> <https://github.com/akheron/jansson/blob/2882ead5bb90cf12a01b07b2c2361e24960fae02/LICENSE>`__
> 
> +-  `MdePkg/Library/BaseFdtLib/libfdt <https://github.com/devicetree-
> org/pylibfdt/blob/f39368a217496d32c4091a2dba4045b60649e3a5/BSD-2-Clause>`__
> 
> 
> 
>  The EDK II Project is composed of packages. The maintainers for each package
> 
>  are listed in `Maintainers.txt <Maintainers.txt>`__.
> 
> --
> 2.39.1.windows.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 3/3] .pytool: Support FDT library.
  2023-04-17  5:35 ` [PATCH v3 3/3] .pytool: " Benny Lin
@ 2023-04-19 15:58   ` Michael D Kinney
  0 siblings, 0 replies; 20+ messages in thread
From: Michael D Kinney @ 2023-04-19 15:58 UTC (permalink / raw)
  To: Lin, Benny, devel@edk2.groups.io
  Cc: Sean Brogan, Michael Kubacki, Gao, Liming, Kinney, Michael D

Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>

> -----Original Message-----
> From: Lin, Benny <benny.lin@intel.com>
> Sent: Sunday, April 16, 2023 10:35 PM
> To: devel@edk2.groups.io
> Cc: Lin, Benny <benny.lin@intel.com>; Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki
> <mikuback@linux.microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>
> Subject: [PATCH v3 3/3] .pytool: Support FDT library.
> 
> From: Benny Lin <benny.lin@intel.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> Add FDT support in EDK2 by submodule 3rd party libfdt
> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> 
> Add RequiredSubmodule object for CI setting.
> 
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Kubacki <mikuback@linux.microsoft.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Signed-off-by: Benny Lin <benny.lin@intel.com>
> ---
>  .pytool/CISettings.py | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/.pytool/CISettings.py b/.pytool/CISettings.py
> index e3f44add58..2fb99f2a17 100644
> --- a/.pytool/CISettings.py
> +++ b/.pytool/CISettings.py
> @@ -195,6 +195,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
>              "RedfishPkg/Library/JsonLib/jansson", False))
> 
>          rs.append(RequiredSubmodule(
> 
>              "UnitTestFrameworkPkg/Library/SubhookLib/subhook", False))
> 
> +        rs.append(RequiredSubmodule(
> 
> +            "MdePkg/Library/BaseFdtLib/libfdt", False))
> 
>          return rs
> 
> 
> 
>      def GetName(self):
> 
> --
> 2.39.1.windows.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-19 15:54   ` Michael D Kinney
@ 2023-04-19 17:11     ` Benny Lin
  2023-04-19 21:04       ` Michael D Kinney
  0 siblings, 1 reply; 20+ messages in thread
From: Benny Lin @ 2023-04-19 17:11 UTC (permalink / raw)
  To: Kinney, Michael D, devel@edk2.groups.io
  Cc: Gao, Liming, Liu, Zhiguang, Pedro Falcato

Please find my feedback below.
We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER, what do you think?

QQQ
Benny

>-----Original Message-----
>From: Kinney, Michael D <michael.d.kinney@intel.com> 
>Sent: Wednesday, April 19, 2023 11:54 PM
>To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
>Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>; Kinney, Michael D <michael.d.kinney@intel.com>
>Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
>
>A few comments below.
>
>Mike
>
>> -----Original Message-----
>> From: Lin, Benny <benny.lin@intel.com>
>> Sent: Sunday, April 16, 2023 10:35 PM
>> To: devel@edk2.groups.io
>> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D 
>> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; 
>> Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato 
>> <pedro.falcato@gmail.com>
>> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
>> 
>> From: Benny Lin <benny.lin@intel.com>
>> 
>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
>> Add FDT support in EDK2 by submodule 3rd party libfdt
>> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
>> and refer to LibcLib implementation by Pedro.
>> 
>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
>> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
>> Signed-off-by: Benny Lin <benny.lin@intel.com>
>> ---
>>  MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
>>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++  
>> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
>>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
>>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++  
>> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
>>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
>>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
>>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
>>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
>>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
>>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
>>  MdePkg/MdePkg.ci.yaml                     |  17 +-
>>  MdePkg/MdePkg.dec                         |   4 +
>>  MdePkg/MdePkg.dsc                         |   1 +
>>  15 files changed, 1043 insertions(+), 2 deletions(-)
>> 
>> diff --git a/MdePkg/Include/Library/FdtLib.h 
>> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index 
>> 0000000000..d59b749c25
>> --- /dev/null
>> +++ b/MdePkg/Include/Library/FdtLib.h
>> @@ -0,0 +1,314 @@
>> +/** @file
>> 
>> +  Flattened Device Tree Library.
>> 
>> +
>> 
>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#ifndef FDT_LIB_H_
>> 
>> +#define FDT_LIB_H_
>> 
>> +
>> 
>> +///
>> 
>> +/// Flattened Device Tree definition
>> 
>> +///
>> 
>> +typedef struct {
>> 
>> +  UINT32    Magic;               /* magic word FDT_MAGIC */
>> 
>> +  UINT32    TotalSize;           /* total size of DT block */
>> 
>> +  UINT32    OffsetDtStruct;      /* offset to structure */
>> 
>> +  UINT32    OffsetDtStrings;     /* offset to strings */
>> 
>> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map */
>> 
>> +  UINT32    Version;             /* format version */
>> 
>> +  UINT32    LastCompVersion;     /* last compatible version */
>> 
>> +
>> 
>> +  /* version 2 fields below */
>> 
>> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
>> 
>> +                                    booting on */
>> 
>> +  /* version 3 fields below */
>> 
>> +  UINT32    SizeDtStrings;       /* size of the strings block */
>> 
>> +
>> 
>> +  /* version 17 fields below */
>> 
>> +  UINT32    SizeDtStruct;        /* size of the structure block */
>> 
>> +} FDT_HEADER;
>
>I see the macros below use SwapBytes32() on all the fields from this structure.  Does this mean this structure is big >endian?  If that is the case, then the description of this structure and all individual fields must make that very clear >so any consumer of the structure knows it does not follow the default endianness of UEFI/PI and that consumers >must either use the macros or consumers must use SwapBytes32() on their own when using this structure directly.

Yes, it's big endian. I will complete more descriptions in patch v4.

>> 
>> +
>> 
>> +typedef struct {
>> 
>> +  UINT64    Address;
>> 
>> +  UINT64    Size;
>> 
>> +} FDT_RESERVE_ENTRY;
>
>
>I do not see this type used anywhere in the lib class or the lib instance.
>Can it be removed?

I think we can remove it because it might be not used for further usage of FDT support.

>
>> 
>> +
>> 
>> +typedef struct {
>> 
>> +  UINT32    Tag;
>> 
>> +  CHAR8     Name[];
>> 
>> +} FDT_NODE_HEADER;
>
>
>I do not see this type used anywhere in the lib class or the lib instance.
>Can it be removed?

When we need retrieve a node from a FDT blob, we will get a node offset then we could use the struct to map the node content. It's very useful.

>
>> 
>> +
>> 
>> +typedef struct {
>> 
>> +  UINT32    Tag;
>> 
>> +  UINT32    Length;
>> 
>> +  UINT32    NameOffset;
>> 
>> +  CHAR8     Data[];
>> 
>> +} FDT_PROPERTY;
>> 
>> +
>> 
>> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST FDT_HEADER 
>> +*)(Fdt))->Field)
>> 
>> +
>> 
>> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
>> 
>> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt, TotalSize))
>> 
>> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt, OffsetDtStruct))
>> 
>> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt, 
>> +OffsetDtStrings))
>> 
>> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt, 
>> +OffsetMemRsvmap))
>> 
>> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
>> 
>> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt, 
>> +LastCompVersion))
>> 
>> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt, BootCpuidPhys))
>> 
>> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt, SizeDtStrings))
>> 
>> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt, SizeDtStruct))
>> 
>> +
>> 
>> +/**
>> 
>> +  Verify the header of the Flattened Device Tree
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +
>> 
>> +  @return Zero for successfully, otherwise failed.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtCheckHeader (
>> 
>> +  IN CONST VOID  *Fdt
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Create a empty Flattened Device Tree.
>> 
>> +
>> 
>> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
>> 
>> +  @param[in] BufferSize     The BufferSize to the pool size.
>> 
>> +
>> 
>> +  @return Zero for successfully, otherwise failed.
>> 
>> +
>> 
>> +**/
>> 
>> +RETURN_STATUS
>> 
>> +EFIAPI
>> 
>> +FdtCreateEmptyTree (
>> 
>> +  IN VOID   *Buffer,
>> 
>> +  IN UINTN  BufferSize
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of next node from the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to previous node.
>> 
>> +  @param[in] Depth          The depth to the level of tree hierarchy.
>> 
>> +
>> 
>> +  @return The offset to next node offset.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtNextNode (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset,
>> 
>> +  IN INT32       *Depth
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of first node under the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to previous node.
>> 
>> +
>> 
>> +  @return The offset to next node offset.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtFirstSubnode (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of next node from the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to previous node.
>> 
>> +
>> 
>> +  @return The offset to next node offset.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtNextSubnode (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of first node which includes the given name.
>> 
>> +
>> 
>> +  @param[in] Fdt             The pointer to FDT blob.
>> 
>> +  @param[in] ParentOffset    The offset to the node which start find under.
>> 
>> +  @param[in] Name            The name to search the node with the name.
>> 
>> +  @param[in] NameLength      The length of the name to check only.
>> 
>> +
>> 
>> +  @return The offset to node offset with given node name.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtSubnodeOffsetNameLen (
>> 
>> +  IN CONST VOID   *Fdt,
>> 
>> +  IN INT32        ParentOffset,
>> 
>> +  IN CONST CHAR8  *Name,
>> 
>> +  IN INT32        NameLength
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of first node which includes the given property name and value.
>> 
>> +
>> 
>> +  @param[in] Fdt             The pointer to FDT blob.
>> 
>> +  @param[in] StartOffset     The offset to the starting node to find.
>> 
>> +  @param[in] PropertyName    The property name to search the node including the named property.
>> 
>> +  @param[in] PropertyValue   The property value to check the same property value.
>> 
>> +  @param[in] PropertyLength  The length of the value in PropertValue.
>> 
>> +
>> 
>> +  @return The offset to node offset with given property.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtNodeOffsetByPropValue (
>> 
>> +  IN CONST VOID   *Fdt,
>> 
>> +  IN INT32        StartOffset,
>> 
>> +  IN CONST CHAR8  *PropertyName,
>> 
>> +  IN CONST VOID   *PropertyValue,
>> 
>> +  IN INT32        PropertyLength
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a property with the given name from the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] NodeOffset     The offset to the given node.
>> 
>> +  @param[in] Name           The name to the property which need be searched
>> 
>> +  @param[in] Length         The length to the size of the property found.
>> 
>> +
>> 
>> +  @return The property to the structure of the found property.
>> 
>> +
>> 
>> +**/
>> 
>> +CONST FDT_PROPERTY *
>> 
>> +EFIAPI
>> 
>> +FdtGetProperty (
>> 
>> +  IN CONST VOID   *Fdt,
>> 
>> +  IN INT32        NodeOffset,
>> 
>> +  IN CONST CHAR8  *Name,
>> 
>> +  IN INT32        *Length
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of first property in the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to the node which need be searched.
>> 
>> +
>> 
>> +  @return The offset to first property offset in the given node.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtFirstPropertyOffset (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       NodeOffset
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of next property from the given property.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to previous property.
>> 
>> +
>> 
>> +  @return The offset to next property offset.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtNextPropertyOffset (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a property from the given offset of the property.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to the given offset of the property.
>> 
>> +  @param[in] Length         The length to the size of the property found.
>> 
>> +
>> 
>> +  @return The property to the structure of the given property offset.
>> 
>> +
>> 
>> +**/
>> 
>> +CONST FDT_PROPERTY *
>> 
>> +EFIAPI
>> 
>> +FdtGetPropertyByOffset (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset,
>> 
>> +  IN INT32       *Length
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a string by the given string offset.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
>> 
>> +  @param[in] Length         The length to the size of string which need be retrieved.
>> 
>> +
>> 
>> +  @return The string to the given string offset.
>> 
>> +
>> 
>> +**/
>> 
>> +CONST CHAR8 *
>> 
>> +EFIAPI
>> 
>> +FdtGetString (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       StrOffset,
>> 
>> +  IN INT32       *Length        OPTIONAL
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Add a new node to the FDT.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
>> 
>> +  @param[in] Name           The name to name the node.
>> 
>> +
>> 
>> +  @return  The offset to the new node.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtAddSubnode (
>> 
>> +  IN VOID         *Fdt,
>> 
>> +  IN INT32        ParentOffset,
>> 
>> +  IN CONST CHAR8  *Name
>> 
>> +  );
>> 
>> +
>> 
>> +/**
>> 
>> +  Add or modify a property in the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
>> 
>> +  @param[in] Name           The name to name the property.
>> 
>> +  @param[in] Value          The value to the property value.
>> 
>> +  @param[in] Length         The length to the size of the property.
>> 
>> +
>> 
>> +  @return  Zero for successfully, otherwise failed.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtSetProp (
>> 
>> +  IN VOID         *Fdt,
>> 
>> +  IN INT32        NodeOffset,
>> 
>> +  IN CONST CHAR8  *Name,
>> 
>> +  IN CONST VOID   *Value,
>> 
>> +  IN UINT32       Length
>> 
>> +  );
>> 
>> +
>> 
>> +#endif /* FDT_LIB_H_ */
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf 
>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>> new file mode 100644
>> index 0000000000..730e568ff6
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>> @@ -0,0 +1,62 @@
>> +## @file
>> 
>> +# Flattened Device Tree Library.
>> 
>> +#
>> 
>> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +#
>> 
>> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +#
>> 
>> +#
>> 
>> +##
>> 
>> +
>> 
>> +[Defines]
>> 
>> +  INF_VERSION                    = 0x0001001B
>> 
>> +  BASE_NAME                      = BaseFdtLib
>> 
>> +  MODULE_UNI_FILE                = BaseFdtLib.uni
>> 
>> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-E8CEC206DE04
>> 
>> +  MODULE_TYPE                    = BASE
>> 
>> +  VERSION_STRING                 = 1.0
>> 
>> +  LIBRARY_CLASS                  = FdtLib
>> 
>> +
>> 
>> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
>> 
>> +
>> 
>> +#
>> 
>> +#  VALID_ARCHITECTURES           = IA32 X64
>> 
>> +#
>> 
>> +
>> 
>> +[Sources]
>> 
>> +  FdtLib.c
>> 
>> +  LibFdtWrapper.c
>> 
>> +  # header Wrapper files
>> 
>> +  limits.h
>> 
>> +  stdbool.h
>> 
>> +  stddef.h
>> 
>> +  stdint.h
>> 
>> +  stdlib.h
>> 
>> +  string.h
>> 
>> +
>> 
>> +  $(FDT_LIB_PATH)/fdt.c
>> 
>> +  $(FDT_LIB_PATH)/fdt.h
>> 
>> +  $(FDT_LIB_PATH)/fdt_addresses.c
>> 
>> +  $(FDT_LIB_PATH)/fdt_check.c
>> 
>> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
>> 
>> +  $(FDT_LIB_PATH)/fdt_overlay.c
>> 
>> +  $(FDT_LIB_PATH)/fdt_ro.c
>> 
>> +  $(FDT_LIB_PATH)/fdt_rw.c
>> 
>> +  $(FDT_LIB_PATH)/fdt_strerror.c
>> 
>> +  $(FDT_LIB_PATH)/fdt_sw.c
>> 
>> +  $(FDT_LIB_PATH)/fdt_wip.c
>> 
>> +  $(FDT_LIB_PATH)/libfdt.h
>> 
>> +  $(FDT_LIB_PATH)/libfdt_env.h
>> 
>> +  $(FDT_LIB_PATH)/libfdt_internal.h
>> 
>> +
>> 
>> +[Packages]
>> 
>> +  MdePkg/MdePkg.dec
>> 
>> +
>> 
>> +[LibraryClasses]
>> 
>> +  BaseLib
>> 
>> +  BaseMemoryLib
>> 
>> +
>> 
>> +[BuildOptions]
>> 
>> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
>> 
>> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
>> 
>> +
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni 
>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
>> new file mode 100644
>> index 0000000000..3f7e45ea6f
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
>> @@ -0,0 +1,14 @@
>> +// /** @file
>> 
>> +// Flattened Device Tree Library.
>> 
>> +//
>> 
>> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +//
>> 
>> +// SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +//
>> 
>> +// **/
>> 
>> +
>> 
>> +
>> 
>> +#string STR_MODULE_ABSTRACT             #language en-US "Instance of FDT Library"
>> 
>> +
>> 
>> +#string STR_MODULE_DESCRIPTION          #language en-US "This module provides FDT Library implementation."
>> 
>> +
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c 
>> b/MdePkg/Library/BaseFdtLib/FdtLib.c
>> new file mode 100644
>> index 0000000000..200a496c7e
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
>> @@ -0,0 +1,301 @@
>> +/** @file
>> 
>> +  Flattened Device Tree Library.
>> 
>> +
>> 
>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#include <libfdt/libfdt/libfdt.h>
>> 
>> +
>> 
>> +/**
>> 
>> +  Verify the header of the Flattened Device Tree
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +
>> 
>> +  @return Zero for successfully, otherwise failed.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtCheckHeader (
>> 
>> +  IN CONST VOID  *Fdt
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_check_header(Fdt);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Create a empty Flattened Device Tree.
>> 
>> +
>> 
>> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
>> 
>> +  @param[in] BufferSize     The BufferSize to the pool size.
>> 
>> +
>> 
>> +  @return Zero for successfully, otherwise failed.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtCreateEmptyTree (
>> 
>> +  IN VOID    *Buffer,
>> 
>> +  IN UINT32  BufferSize
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of next node from the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to previous node.
>> 
>> +  @param[in] Depth          The depth to the level of tree hierarchy.
>> 
>> +
>> 
>> +  @return The offset to next node offset.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtNextNode (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset,
>> 
>> +  IN INT32       *Depth
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_next_node (Fdt, Offset, Depth);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of first node under the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to previous node.
>> 
>> +
>> 
>> +  @return The offset to next node offset.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtFirstSubnode (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_first_subnode (Fdt, Offset);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of next node from the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to previous node.
>> 
>> +
>> 
>> +  @return The offset to next node offset.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtNextSubnode (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_next_subnode (Fdt, Offset);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of first node which includes the given name.
>> 
>> +
>> 
>> +  @param[in] Fdt             The pointer to FDT blob.
>> 
>> +  @param[in] ParentOffset    The offset to the node which start find under.
>> 
>> +  @param[in] Name            The name to search the node with the name.
>> 
>> +  @param[in] NameLength      The length of the name to check only.
>> 
>> +
>> 
>> +  @return The offset to node offset with given node name.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtSubnodeOffsetNameLen (
>> 
>> +  IN CONST VOID   *Fdt,
>> 
>> +  IN INT32        ParentOffset,
>> 
>> +  IN CONST CHAR8  *Name,
>> 
>> +  IN INT32        NameLength
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name, 
>> + NameLength);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of first node which includes the given property name and value.
>> 
>> +
>> 
>> +  @param[in] Fdt             The pointer to FDT blob.
>> 
>> +  @param[in] StartOffset     The offset to the starting node to find.
>> 
>> +  @param[in] PropertyName    The property name to search the node including the named property.
>> 
>> +  @param[in] PropertyValue   The property value to check the same property value.
>> 
>> +  @param[in] PropertyLength  The length of the value in PropertValue.
>> 
>> +
>> 
>> +  @return The offset to node offset with given property.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtNodeOffsetByPropValue (
>> 
>> +  IN CONST VOID   *Fdt,
>> 
>> +  IN INT32        StartOffset,
>> 
>> +  IN CONST CHAR8  *PropertyName,
>> 
>> +  IN CONST VOID   *PropertyValue,
>> 
>> +  IN INT32        PropertyLength
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset, 
>> + PropertyName, PropertyValue, PropertyLength);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a property with the given name from the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] NodeOffset     The offset to the given node.
>> 
>> +  @param[in] Name           The name to the property which need be searched
>> 
>> +  @param[in] Length         The length to the size of the property found.
>> 
>> +
>> 
>> +  @return The property to the structure of the found property.
>> 
>> +
>> 
>> +**/
>> 
>> +CONST struct fdt_property *
>> 
>> +EFIAPI
>> 
>> +FdtGetProperty (
>> 
>> +  IN CONST VOID   *Fdt,
>> 
>> +  IN INT32        NodeOffset,
>> 
>> +  IN CONST CHAR8  *Name,
>> 
>> +  IN INT32        *Length
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of first property in the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] NodeOffset     The offset to the node which need be searched.
>> 
>> +
>> 
>> +  @return The offset to first property offset in the given node.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtFirstPropertyOffset (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       NodeOffset
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_first_property_offset (Fdt, NodeOffset);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a offset of next property from the given property.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to previous property.
>> 
>> +
>> 
>> +  @return The offset to next property offset.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtNextPropertyOffset (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_next_property_offset (Fdt, Offset);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a property from the given offset of the property.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] Offset         The offset to the given offset of the property.
>> 
>> +  @param[in] Length         The length to the size of the property found.
>> 
>> +
>> 
>> +  @return The property to the structure of the given property offset.
>> 
>> +
>> 
>> +**/
>> 
>> +CONST struct fdt_property *
>> 
>> +EFIAPI
>> 
>> +FdtGetPropertyByOffset (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       Offset,
>> 
>> +  IN INT32       *Length
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Returns a string by the given string offset.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
>> 
>> +  @param[in] Length         The length to the size of string which need be retrieved.
>> 
>> +
>> 
>> +  @return The string to the given string offset.
>> 
>> +
>> 
>> +**/
>> 
>> +CONST CHAR8 *
>> 
>> +EFIAPI
>> 
>> +FdtGetString (
>> 
>> +  IN CONST VOID  *Fdt,
>> 
>> +  IN INT32       StrOffset,
>> 
>> +  IN INT32       *Length        OPTIONAL
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_get_string (Fdt, StrOffset, Length);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Add a new node to the FDT.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
>> 
>> +  @param[in] Name           The name to name the node.
>> 
>> +
>> 
>> +  @return  The offset to the new node.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtAddSubnode (
>> 
>> +  IN VOID         *Fdt,
>> 
>> +  IN INT32        ParentOffset,
>> 
>> +  IN CONST CHAR8  *Name
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
>> 
>> +}
>> 
>> +
>> 
>> +/**
>> 
>> +  Add or modify a property in the given node.
>> 
>> +
>> 
>> +  @param[in] Fdt            The pointer to FDT blob.
>> 
>> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
>> 
>> +  @param[in] Name           The name to name the property.
>> 
>> +  @param[in] Value          The value to the property value.
>> 
>> +  @param[in] Length         The length to the size of the property.
>> 
>> +
>> 
>> +  @return  Zero for successfully, otherwise failed.
>> 
>> +
>> 
>> +**/
>> 
>> +INT32
>> 
>> +EFIAPI
>> 
>> +FdtSetProp (
>> 
>> +  IN VOID         *Fdt,
>> 
>> +  IN INT32        NodeOffset,
>> 
>> +  IN CONST CHAR8  *Name,
>> 
>> +  IN CONST VOID   *Value,
>> 
>> +  IN UINT32       Length
>> 
>> +  )
>> 
>> +{
>> 
>> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
>> 
>> +}
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h 
>> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
>> new file mode 100644
>> index 0000000000..e738f4ded4
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
>> @@ -0,0 +1,99 @@
>> +/** @file
>> 
>> +  Root include file of C runtime library to support building the 
>> + third-party
>> 
>> +  libfdt library.
>> 
>> +
>> 
>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#ifndef FDT_LIB_SUPPORT_H_
>> 
>> +#define FDT_LIB_SUPPORT_H_
>> 
>> +
>> 
>> +#include <Base.h>
>> 
>> +#include <Library/BaseLib.h>
>> 
>> +#include <Library/BaseMemoryLib.h>
>> 
>> +
>> 
>> +typedef UINT8    uint8_t;
>> 
>> +typedef UINT16   uint16_t;
>> 
>> +typedef INT32    int32_t;
>> 
>> +typedef UINT32   uint32_t;
>> 
>> +typedef UINT64   uint64_t;
>> 
>> +typedef UINTN    uintptr_t;
>> 
>> +typedef UINTN    size_t;
>> 
>> +typedef BOOLEAN  bool;
>> 
>> +
>> 
>> +#define true   (1 == 1)
>> 
>> +#define false  (1 == 0)
>> 
>> +
>> 
>> +//
>> 
>> +// Definitions for global constants used by libfdt library routines
>> 
>> +//
>> 
>> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value */
>> 
>> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32 value */
>> 
>> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32 value */
>> 
>> +
>> 
>> +//
>> 
>> +// Function prototypes of libfdt Library routines
>> 
>> +//
>> 
>> +void *
>> 
>> +memset     (
>> 
>> +  void *,
>> 
>> +  int,
>> 
>> +  size_t
>> 
>> +  );
>> 
>> +
>> 
>> +int
>> 
>> +memcmp      (
>> 
>> +  const void *,
>> 
>> +  const void *,
>> 
>> +  size_t
>> 
>> +  );
>> 
>> +
>> 
>> +int
>> 
>> +strcmp      (
>> 
>> +  const char *,
>> 
>> +  const char *
>> 
>> +  );
>> 
>> +
>> 
>> +char *
>> 
>> +strchr     (
>> 
>> +  const char *,
>> 
>> +  int
>> 
>> +  );
>> 
>> +
>> 
>> +char *
>> 
>> +strrchr    (
>> 
>> +  const char *,
>> 
>> +  int
>> 
>> +  );
>> 
>> +
>> 
>> +unsigned long
>> 
>> +strtoul     (
>> 
>> +  const char *,
>> 
>> +  char **,
>> 
>> +  int
>> 
>> +  );
>> 
>> +
>> 
>> +char *
>> 
>> +strcpy (
>> 
>> +  char        *strDest,
>> 
>> +  const char  *strSource
>> 
>> +  );
>> 
>> +
>> 
>> +//
>> 
>> +// Macros that directly map functions to BaseLib, BaseMemoryLib, and 
>> +DebugLib functions
>> 
>> +//
>> 
>> +#define memcpy(dest, source, count)         CopyMem(dest,source, (UINTN)(count))
>> 
>> +#define memset(dest, ch, count)             SetMem(dest, (UINTN)(count),(UINT8)(ch))
>> 
>> +#define memchr(buf, ch, count)              ScanMem8(buf, (UINTN)(count),(UINT8)ch)
>> 
>> +#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1, buf2, (UINTN)(count)))
>> 
>> +#define memmove(dest, source, count)        CopyMem(dest, source, (UINTN)(count))
>> 
>> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
>> 
>> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
>> 
>> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest, 
>> +MAX_STRING_SIZE, strSource, (UINTN)count)
>> 
>> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest, MAX_STRING_SIZE, strSource)
>> 
>> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1, string2))
>> 
>> +#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1, string2, (UINTN)(count)))
>> 
>> +
>> 
>> +#endif /* FDT_LIB_SUPPORT_H_ */
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c 
>> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
>> new file mode 100644
>> index 0000000000..772bba4839
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
>> @@ -0,0 +1,173 @@
>> +/** @file
>> 
>> +  ISO C implementations of strchr, strrchr and strtoul.
>> 
>> +
>> 
>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
>> 
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#include <Base.h>
>> 
>> +
>> 
>> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long value */
>> 
>> +
>> 
>> +// Very quick notes:
>> 
>> +// We only go through the string once for both functions
>> 
>> +// They are minimal implementations (not speed optimized) of ISO C 
>> +semantics
>> 
>> +// strchr and strrchr also include the null terminator as part of the 
>> +string
>> 
>> +// so the code gets a bit clunky to handle that case specifically.
>> 
>> +
>> 
>> +char *
>> 
>> +strchr (
>> 
>> +  const char  *Str,
>> 
>> +  int         Char
>> 
>> +  )
>> 
>> +{
>> 
>> +  char  *S;
>> 
>> +
>> 
>> +  S = (char *)Str;
>> 
>> +
>> 
>> +  for ( ; ; S++) {
>> 
>> +    if (*S == Char) {
>> 
>> +      return S;
>> 
>> +    }
>> 
>> +
>> 
>> +    if (*S == '\0') {
>> 
>> +      return NULL;
>> 
>> +    }
>> 
>> +  }
>> 
>> +}
>> 
>> +
>> 
>> +char *
>> 
>> +strrchr (
>> 
>> +  const char  *Str,
>> 
>> +  int         Char
>> 
>> +  )
>> 
>> +{
>> 
>> +  char  *S, *last;
>> 
>> +
>> 
>> +  S    = (char *)Str;
>> 
>> +  last = NULL;
>> 
>> +
>> 
>> +  for ( ; ; S++) {
>> 
>> +    if (*S == Char) {
>> 
>> +      last = S;
>> 
>> +    }
>> 
>> +
>> 
>> +    if (*S == '\0') {
>> 
>> +      return last;
>> 
>> +    }
>> 
>> +  }
>> 
>> +}
>> 
>> +
>> 
>> +STATIC
>> 
>> +int
>> 
>> +__isspace (
>> 
>> +  int  ch
>> 
>> +  )
>> 
>> +{
>> 
>> +  // basic ASCII ctype.h:isspace(). Not efficient
>> 
>> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch == 
>> + '\v' || ch == '\f';
>> 
>> +}
>> 
>> +
>> 
>> +unsigned long
>> 
>> +strtoul (
>> 
>> +  const char  *Nptr,
>> 
>> +  char        **EndPtr,
>> 
>> +  int         Base
>> 
>> +  )
>> 
>> +{
>> 
>> +  BOOLEAN        Negate;
>> 
>> +  BOOLEAN        Overflow;
>> 
>> +  unsigned long  Val;
>> 
>> +
>> 
>> +  Negate   = FALSE;
>> 
>> +  Overflow = FALSE;
>> 
>> +  Val      = 0;
>> 
>> +
>> 
>> +  // Reject bad numeric bases
>> 
>> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
>> 
>> +    return 0;
>> 
>> +  }
>> 
>> +
>> 
>> +  // Skip whitespace
>> 
>> +  while (__isspace (*Nptr)) {
>> 
>> +    Nptr++;
>> 
>> +  }
>> 
>> +
>> 
>> +  // Check for + or - prefixes
>> 
>> +  if (*Nptr == '-') {
>> 
>> +    Negate = TRUE;
>> 
>> +    Nptr++;
>> 
>> +  } else if (*Nptr == '+') {
>> 
>> +    Nptr++;
>> 
>> +  }
>> 
>> +
>> 
>> +  // Consume the start, autodetecting base if needed
>> 
>> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X')) && 
>> + ((Base == 0) || (Base == 16))) {
>> 
>> +    // Hex
>> 
>> +    Nptr += 2;
>> 
>> +    Base  = 16;
>> 
>> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] == 
>> + 'B')) && ((Base == 0) || (Base == 2))) {
>> 
>> +    // Binary (standard pending C23)
>> 
>> +    Nptr += 2;
>> 
>> +    Base  = 2;
>> 
>> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
>> 
>> +    // Octal
>> 
>> +    Nptr++;
>> 
>> +    Base = 8;
>> 
>> +  } else {
>> 
>> +    if (Base == 0) {
>> 
>> +      // Assume decimal
>> 
>> +      Base = 10;
>> 
>> +    }
>> 
>> +  }
>> 
>> +
>> 
>> +  while (TRUE) {
>> 
>> +    int            Digit;
>> 
>> +    char           C;
>> 
>> +    unsigned long  NewVal;
>> 
>> +
>> 
>> +    C     = *Nptr;
>> 
>> +    Digit = -1;
>> 
>> +
>> 
>> +    if ((C >= '0') && (C <= '9')) {
>> 
>> +      Digit = C - '0';
>> 
>> +    } else if ((C >= 'a') && (C <= 'z')) {
>> 
>> +      Digit = C - 'a' + 10;
>> 
>> +    } else if ((C >= 'A') && (C <= 'Z')) {
>> 
>> +      Digit = C - 'A' + 10;
>> 
>> +    }
>> 
>> +
>> 
>> +    if ((Digit == -1) || (Digit >= Base)) {
>> 
>> +      // Note that this case also handles the \0
>> 
>> +      if (EndPtr) {
>> 
>> +        *EndPtr = (char *)Nptr;
>> 
>> +      }
>> 
>> +
>> 
>> +      break;
>> 
>> +    }
>> 
>> +
>> 
>> +    NewVal = Val * Base + Digit;
>> 
>> +
>> 
>> +    if (NewVal < Val) {
>> 
>> +      // Overflow
>> 
>> +      Overflow = TRUE;
>> 
>> +    }
>> 
>> +
>> 
>> +    Val = NewVal;
>> 
>> +
>> 
>> +    Nptr++;
>> 
>> +  }
>> 
>> +
>> 
>> +  if (Negate) {
>> 
>> +    Val = -Val;
>> 
>> +  }
>> 
>> +
>> 
>> +  if (Overflow) {
>> 
>> +    Val = ULONG_MAX;
>> 
>> +  }
>> 
>> +
>> 
>> +  // TODO: We're lacking errno here.
>> 
>> +  return Val;
>> 
>> +}
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/limits.h 
>> b/MdePkg/Library/BaseFdtLib/limits.h
>> new file mode 100644
>> index 0000000000..f6cf8d5702
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/limits.h
>> @@ -0,0 +1,10 @@
>> +/** @file
>> 
>> +  Include file to support building the third-party libfdt library.
>> 
>> +
>> 
>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#include <LibFdtSupport.h>
>> 
>> +
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h 
>> b/MdePkg/Library/BaseFdtLib/stdbool.h
>> new file mode 100644
>> index 0000000000..f6cf8d5702
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
>> @@ -0,0 +1,10 @@
>> +/** @file
>> 
>> +  Include file to support building the third-party libfdt library.
>> 
>> +
>> 
>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#include <LibFdtSupport.h>
>> 
>> +
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h 
>> b/MdePkg/Library/BaseFdtLib/stddef.h
>> new file mode 100644
>> index 0000000000..f6cf8d5702
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
>> @@ -0,0 +1,10 @@
>> +/** @file
>> 
>> +  Include file to support building the third-party libfdt library.
>> 
>> +
>> 
>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#include <LibFdtSupport.h>
>> 
>> +
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h 
>> b/MdePkg/Library/BaseFdtLib/stdint.h
>> new file mode 100644
>> index 0000000000..f6cf8d5702
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
>> @@ -0,0 +1,10 @@
>> +/** @file
>> 
>> +  Include file to support building the third-party libfdt library.
>> 
>> +
>> 
>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#include <LibFdtSupport.h>
>> 
>> +
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h 
>> b/MdePkg/Library/BaseFdtLib/stdlib.h
>> new file mode 100644
>> index 0000000000..f6cf8d5702
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
>> @@ -0,0 +1,10 @@
>> +/** @file
>> 
>> +  Include file to support building the third-party libfdt library.
>> 
>> +
>> 
>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#include <LibFdtSupport.h>
>> 
>> +
>> 
>> diff --git a/MdePkg/Library/BaseFdtLib/string.h 
>> b/MdePkg/Library/BaseFdtLib/string.h
>> new file mode 100644
>> index 0000000000..f6cf8d5702
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/string.h
>> @@ -0,0 +1,10 @@
>> +/** @file
>> 
>> +  Include file to support building the third-party libfdt library.
>> 
>> +
>> 
>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> +
>> 
>> +**/
>> 
>> +
>> 
>> +#include <LibFdtSupport.h>
>> 
>> +
>> 
>> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index 
>> 6ba85ebe61..f039daccdb 100644
>> --- a/MdePkg/MdePkg.ci.yaml
>> +++ b/MdePkg/MdePkg.ci.yaml
>> @@ -2,7 +2,7 @@
>>  # CI configuration for MdePkg
>> 
>>  #
>> 
>>  # Copyright (c) Microsoft Corporation
>> 
>> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
>> 
>> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> 
>>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
>> 
>>  # Copyright (c) 2023, Loongson Technology Corporation Limited. All 
>> rights reserved.<BR>
>> 
>>  # SPDX-License-Identifier: BSD-2-Clause-Patent
>> 
>> @@ -67,7 +67,8 @@
>>              "Include/Library/PcdLib.h",
>> 
>>              "Include/Library/SafeIntLib.h",
>> 
>>              "Include/Protocol/DebugSupport.h",
>> 
>> -            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
>> 
>> +            
>> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
>> 
>> +            "Library/BaseFdtLib"
>> 
>>          ]
>> 
>>      },
>> 
>>      ## options defined ci/Plugin/CompilerPlugin
>> 
>> @@ -164,5 +165,17 @@
>>          "ExtendWords": [],           # words to extend to the dictionary for this package
>> 
>>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
>> 
>>          "AdditionalIncludePaths": [] # Additional paths to spell 
>> check (wildcards supported)
>> 
>> +    },
>> 
>> +    # options defined in .pytool/Plugin/UncrustifyCheck
>> 
>> +    "UncrustifyCheck": {
>> 
>> +        "IgnoreFiles": [
>> 
>> +            "Library/BaseFdtLib/libfdt",
>> 
>> +            "Library/BaseFdtLib/limits.h",
>> 
>> +            "Library/BaseFdtLib/stdbool.h",
>> 
>> +            "Library/BaseFdtLib/stddef.h",
>> 
>> +            "Library/BaseFdtLib/stdint.h",
>> 
>> +            "Library/BaseFdtLib/stdlib.h",
>> 
>> +            "Library/BaseFdtLib/string.h"
>> 
>> +        ]
>> 
>>      }
>> 
>>  }
>> 
>> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 
>> e70182bf7f..9804a7a6bd 100644
>> --- a/MdePkg/MdePkg.dec
>> +++ b/MdePkg/MdePkg.dec
>> @@ -289,6 +289,10 @@
>>    #
>> 
>>    ArmTrngLib|Include/Library/ArmTrngLib.h
>> 
>> 
>> 
>> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
>> 
>> +  #
>> 
>> +  FdtLib|Include/Library/FdtLib.h
>> 
>> +
>> 
>>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
>> 
>>    ##  @libraryclass  Provides services to generate random number.
>> 
>>    #
>> 
>> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 
>> 152c02991a..b38c863812 100644
>> --- a/MdePkg/MdePkg.dsc
>> +++ b/MdePkg/MdePkg.dsc
>> @@ -137,6 +137,7 @@
>>    MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
>> 
>> 
>> 
>>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
>> 
>> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>> 
>> 
>> 
>>  [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
>> 
>>    #
>> 
>> --
>> 2.39.1.windows.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-19 17:11     ` Benny Lin
@ 2023-04-19 21:04       ` Michael D Kinney
  2023-04-20  4:25         ` Benny Lin
  0 siblings, 1 reply; 20+ messages in thread
From: Michael D Kinney @ 2023-04-19 21:04 UTC (permalink / raw)
  To: Lin, Benny, devel@edk2.groups.io
  Cc: Gao, Liming, Liu, Zhiguang, Pedro Falcato, Kinney, Michael D

Responses below

Mike

> -----Original Message-----
> From: Lin, Benny <benny.lin@intel.com>
> Sent: Wednesday, April 19, 2023 10:12 AM
> To: Kinney, Michael D <michael.d.kinney@intel.com>; devel@edk2.groups.io
> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> Please find my feedback below.
> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER, what do you think?
> 
> QQQ
> Benny
> 
> >-----Original Message-----
> >From: Kinney, Michael D <michael.d.kinney@intel.com>
> >Sent: Wednesday, April 19, 2023 11:54 PM
> >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>
> >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> >
> >A few comments below.
> >
> >Mike
> >
> >> -----Original Message-----
> >> From: Lin, Benny <benny.lin@intel.com>
> >> Sent: Sunday, April 16, 2023 10:35 PM
> >> To: devel@edk2.groups.io
> >> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> >> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
> >> Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> >> <pedro.falcato@gmail.com>
> >> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> >>
> >> From: Benny Lin <benny.lin@intel.com>
> >>
> >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> >> Add FDT support in EDK2 by submodule 3rd party libfdt
> >> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> >> and refer to LibcLib implementation by Pedro.
> >>
> >> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> >> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> >> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> >> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> >> Signed-off-by: Benny Lin <benny.lin@intel.com>
> >> ---
> >>  MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
> >>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> >> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> >>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
> >>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> >> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
> >>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> >>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> >>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> >>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> >>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> >>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
> >>  MdePkg/MdePkg.ci.yaml                     |  17 +-
> >>  MdePkg/MdePkg.dec                         |   4 +
> >>  MdePkg/MdePkg.dsc                         |   1 +
> >>  15 files changed, 1043 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/MdePkg/Include/Library/FdtLib.h
> >> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
> >> 0000000000..d59b749c25
> >> --- /dev/null
> >> +++ b/MdePkg/Include/Library/FdtLib.h
> >> @@ -0,0 +1,314 @@
> >> +/** @file
> >>
> >> +  Flattened Device Tree Library.
> >>
> >> +
> >>
> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#ifndef FDT_LIB_H_
> >>
> >> +#define FDT_LIB_H_
> >>
> >> +
> >>
> >> +///
> >>
> >> +/// Flattened Device Tree definition
> >>
> >> +///
> >>
> >> +typedef struct {
> >>
> >> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> >>
> >> +  UINT32    TotalSize;           /* total size of DT block */
> >>
> >> +  UINT32    OffsetDtStruct;      /* offset to structure */
> >>
> >> +  UINT32    OffsetDtStrings;     /* offset to strings */
> >>
> >> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map */
> >>
> >> +  UINT32    Version;             /* format version */
> >>
> >> +  UINT32    LastCompVersion;     /* last compatible version */
> >>
> >> +
> >>
> >> +  /* version 2 fields below */
> >>
> >> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
> >>
> >> +                                    booting on */
> >>
> >> +  /* version 3 fields below */
> >>
> >> +  UINT32    SizeDtStrings;       /* size of the strings block */
> >>
> >> +
> >>
> >> +  /* version 17 fields below */
> >>
> >> +  UINT32    SizeDtStruct;        /* size of the structure block */
> >>
> >> +} FDT_HEADER;
> >
> >I see the macros below use SwapBytes32() on all the fields from this structure.  Does this mean this structure is big >endian?  If
> that is the case, then the description of this structure and all individual fields must make that very clear >so any consumer of the
> structure knows it does not follow the default endianness of UEFI/PI and that consumers >must either use the macros or consumers must
> use SwapBytes32() on their own when using this structure directly.
> 
> Yes, it's big endian. I will complete more descriptions in patch v4.

Would it be simpler if we have a lib service that converts the entire header from big endian to little endian.
That way, the consumer can use the FDT_HEADER directly without any of the macros?

Also, is the rest of the FDT blob also big endian?

> 
> >>
> >> +
> >>
> >> +typedef struct {
> >>
> >> +  UINT64    Address;
> >>
> >> +  UINT64    Size;
> >>
> >> +} FDT_RESERVE_ENTRY;
> >
> >
> >I do not see this type used anywhere in the lib class or the lib instance.
> >Can it be removed?
> 
> I think we can remove it because it might be not used for further usage of FDT support.
> 
> >
> >>
> >> +
> >>
> >> +typedef struct {
> >>
> >> +  UINT32    Tag;
> >>
> >> +  CHAR8     Name[];
> >>
> >> +} FDT_NODE_HEADER;
> >
> >
> >I do not see this type used anywhere in the lib class or the lib instance.
> >Can it be removed?
> 
> When we need retrieve a node from a FDT blob, we will get a node offset then we could use the struct to map the node content. It's
> very useful.

Please add a comment header for this structure and describe the usage as it related to the rest of the FdtLib services.

> 
> >
> >>
> >> +
> >>
> >> +typedef struct {
> >>
> >> +  UINT32    Tag;
> >>
> >> +  UINT32    Length;
> >>
> >> +  UINT32    NameOffset;
> >>
> >> +  CHAR8     Data[];
> >>
> >> +} FDT_PROPERTY;
> >>
> >> +
> >>
> >> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST FDT_HEADER
> >> +*)(Fdt))->Field)
> >>
> >> +
> >>
> >> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
> >>
> >> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt, TotalSize))
> >>
> >> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt, OffsetDtStruct))
> >>
> >> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
> >> +OffsetDtStrings))
> >>
> >> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
> >> +OffsetMemRsvmap))
> >>
> >> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
> >>
> >> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
> >> +LastCompVersion))
> >>
> >> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt, BootCpuidPhys))
> >>
> >> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt, SizeDtStrings))
> >>
> >> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt, SizeDtStruct))
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Verify the header of the Flattened Device Tree
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +
> >>
> >> +  @return Zero for successfully, otherwise failed.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtCheckHeader (
> >>
> >> +  IN CONST VOID  *Fdt
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Create a empty Flattened Device Tree.
> >>
> >> +
> >>
> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> >>
> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> >>
> >> +
> >>
> >> +  @return Zero for successfully, otherwise failed.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +RETURN_STATUS
> >>
> >> +EFIAPI
> >>
> >> +FdtCreateEmptyTree (
> >>
> >> +  IN VOID   *Buffer,
> >>
> >> +  IN UINTN  BufferSize
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of next node from the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to previous node.
> >>
> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> >>
> >> +
> >>
> >> +  @return The offset to next node offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtNextNode (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset,
> >>
> >> +  IN INT32       *Depth
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of first node under the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to previous node.
> >>
> >> +
> >>
> >> +  @return The offset to next node offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtFirstSubnode (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of next node from the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to previous node.
> >>
> >> +
> >>
> >> +  @return The offset to next node offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtNextSubnode (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of first node which includes the given name.
> >>
> >> +
> >>
> >> +  @param[in] Fdt             The pointer to FDT blob.
> >>
> >> +  @param[in] ParentOffset    The offset to the node which start find under.
> >>
> >> +  @param[in] Name            The name to search the node with the name.
> >>
> >> +  @param[in] NameLength      The length of the name to check only.
> >>
> >> +
> >>
> >> +  @return The offset to node offset with given node name.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtSubnodeOffsetNameLen (
> >>
> >> +  IN CONST VOID   *Fdt,
> >>
> >> +  IN INT32        ParentOffset,
> >>
> >> +  IN CONST CHAR8  *Name,
> >>
> >> +  IN INT32        NameLength
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of first node which includes the given property name and value.
> >>
> >> +
> >>
> >> +  @param[in] Fdt             The pointer to FDT blob.
> >>
> >> +  @param[in] StartOffset     The offset to the starting node to find.
> >>
> >> +  @param[in] PropertyName    The property name to search the node including the named property.
> >>
> >> +  @param[in] PropertyValue   The property value to check the same property value.
> >>
> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> >>
> >> +
> >>
> >> +  @return The offset to node offset with given property.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtNodeOffsetByPropValue (
> >>
> >> +  IN CONST VOID   *Fdt,
> >>
> >> +  IN INT32        StartOffset,
> >>
> >> +  IN CONST CHAR8  *PropertyName,
> >>
> >> +  IN CONST VOID   *PropertyValue,
> >>
> >> +  IN INT32        PropertyLength
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a property with the given name from the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] NodeOffset     The offset to the given node.
> >>
> >> +  @param[in] Name           The name to the property which need be searched
> >>
> >> +  @param[in] Length         The length to the size of the property found.
> >>
> >> +
> >>
> >> +  @return The property to the structure of the found property.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +CONST FDT_PROPERTY *
> >>
> >> +EFIAPI
> >>
> >> +FdtGetProperty (
> >>
> >> +  IN CONST VOID   *Fdt,
> >>
> >> +  IN INT32        NodeOffset,
> >>
> >> +  IN CONST CHAR8  *Name,
> >>
> >> +  IN INT32        *Length
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of first property in the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to the node which need be searched.
> >>
> >> +
> >>
> >> +  @return The offset to first property offset in the given node.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtFirstPropertyOffset (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       NodeOffset
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of next property from the given property.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to previous property.
> >>
> >> +
> >>
> >> +  @return The offset to next property offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtNextPropertyOffset (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a property from the given offset of the property.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to the given offset of the property.
> >>
> >> +  @param[in] Length         The length to the size of the property found.
> >>
> >> +
> >>
> >> +  @return The property to the structure of the given property offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +CONST FDT_PROPERTY *
> >>
> >> +EFIAPI
> >>
> >> +FdtGetPropertyByOffset (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset,
> >>
> >> +  IN INT32       *Length
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a string by the given string offset.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> >>
> >> +  @param[in] Length         The length to the size of string which need be retrieved.
> >>
> >> +
> >>
> >> +  @return The string to the given string offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +CONST CHAR8 *
> >>
> >> +EFIAPI
> >>
> >> +FdtGetString (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       StrOffset,
> >>
> >> +  IN INT32       *Length        OPTIONAL
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Add a new node to the FDT.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> >>
> >> +  @param[in] Name           The name to name the node.
> >>
> >> +
> >>
> >> +  @return  The offset to the new node.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtAddSubnode (
> >>
> >> +  IN VOID         *Fdt,
> >>
> >> +  IN INT32        ParentOffset,
> >>
> >> +  IN CONST CHAR8  *Name
> >>
> >> +  );
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Add or modify a property in the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> >>
> >> +  @param[in] Name           The name to name the property.
> >>
> >> +  @param[in] Value          The value to the property value.
> >>
> >> +  @param[in] Length         The length to the size of the property.
> >>
> >> +
> >>
> >> +  @return  Zero for successfully, otherwise failed.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtSetProp (
> >>
> >> +  IN VOID         *Fdt,
> >>
> >> +  IN INT32        NodeOffset,
> >>
> >> +  IN CONST CHAR8  *Name,
> >>
> >> +  IN CONST VOID   *Value,
> >>
> >> +  IN UINT32       Length
> >>
> >> +  );
> >>
> >> +
> >>
> >> +#endif /* FDT_LIB_H_ */
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >> new file mode 100644
> >> index 0000000000..730e568ff6
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >> @@ -0,0 +1,62 @@
> >> +## @file
> >>
> >> +# Flattened Device Tree Library.
> >>
> >> +#
> >>
> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +#
> >>
> >> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +#
> >>
> >> +#
> >>
> >> +##
> >>
> >> +
> >>
> >> +[Defines]
> >>
> >> +  INF_VERSION                    = 0x0001001B
> >>
> >> +  BASE_NAME                      = BaseFdtLib
> >>
> >> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> >>
> >> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-E8CEC206DE04
> >>
> >> +  MODULE_TYPE                    = BASE
> >>
> >> +  VERSION_STRING                 = 1.0
> >>
> >> +  LIBRARY_CLASS                  = FdtLib
> >>
> >> +
> >>
> >> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> >>
> >> +
> >>
> >> +#
> >>
> >> +#  VALID_ARCHITECTURES           = IA32 X64
> >>
> >> +#
> >>
> >> +
> >>
> >> +[Sources]
> >>
> >> +  FdtLib.c
> >>
> >> +  LibFdtWrapper.c
> >>
> >> +  # header Wrapper files
> >>
> >> +  limits.h
> >>
> >> +  stdbool.h
> >>
> >> +  stddef.h
> >>
> >> +  stdint.h
> >>
> >> +  stdlib.h
> >>
> >> +  string.h
> >>
> >> +
> >>
> >> +  $(FDT_LIB_PATH)/fdt.c
> >>
> >> +  $(FDT_LIB_PATH)/fdt.h
> >>
> >> +  $(FDT_LIB_PATH)/fdt_addresses.c
> >>
> >> +  $(FDT_LIB_PATH)/fdt_check.c
> >>
> >> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> >>
> >> +  $(FDT_LIB_PATH)/fdt_overlay.c
> >>
> >> +  $(FDT_LIB_PATH)/fdt_ro.c
> >>
> >> +  $(FDT_LIB_PATH)/fdt_rw.c
> >>
> >> +  $(FDT_LIB_PATH)/fdt_strerror.c
> >>
> >> +  $(FDT_LIB_PATH)/fdt_sw.c
> >>
> >> +  $(FDT_LIB_PATH)/fdt_wip.c
> >>
> >> +  $(FDT_LIB_PATH)/libfdt.h
> >>
> >> +  $(FDT_LIB_PATH)/libfdt_env.h
> >>
> >> +  $(FDT_LIB_PATH)/libfdt_internal.h
> >>
> >> +
> >>
> >> +[Packages]
> >>
> >> +  MdePkg/MdePkg.dec
> >>
> >> +
> >>
> >> +[LibraryClasses]
> >>
> >> +  BaseLib
> >>
> >> +  BaseMemoryLib
> >>
> >> +
> >>
> >> +[BuildOptions]
> >>
> >> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> >>
> >> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
> >>
> >> +
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> >> new file mode 100644
> >> index 0000000000..3f7e45ea6f
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> >> @@ -0,0 +1,14 @@
> >> +// /** @file
> >>
> >> +// Flattened Device Tree Library.
> >>
> >> +//
> >>
> >> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +//
> >>
> >> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +//
> >>
> >> +// **/
> >>
> >> +
> >>
> >> +
> >>
> >> +#string STR_MODULE_ABSTRACT             #language en-US "Instance of FDT Library"
> >>
> >> +
> >>
> >> +#string STR_MODULE_DESCRIPTION          #language en-US "This module provides FDT Library implementation."
> >>
> >> +
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> >> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> >> new file mode 100644
> >> index 0000000000..200a496c7e
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> >> @@ -0,0 +1,301 @@
> >> +/** @file
> >>
> >> +  Flattened Device Tree Library.
> >>
> >> +
> >>
> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#include <libfdt/libfdt/libfdt.h>
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Verify the header of the Flattened Device Tree
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +
> >>
> >> +  @return Zero for successfully, otherwise failed.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtCheckHeader (
> >>
> >> +  IN CONST VOID  *Fdt
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_check_header(Fdt);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Create a empty Flattened Device Tree.
> >>
> >> +
> >>
> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> >>
> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> >>
> >> +
> >>
> >> +  @return Zero for successfully, otherwise failed.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtCreateEmptyTree (
> >>
> >> +  IN VOID    *Buffer,
> >>
> >> +  IN UINT32  BufferSize
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of next node from the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to previous node.
> >>
> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> >>
> >> +
> >>
> >> +  @return The offset to next node offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtNextNode (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset,
> >>
> >> +  IN INT32       *Depth
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_next_node (Fdt, Offset, Depth);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of first node under the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to previous node.
> >>
> >> +
> >>
> >> +  @return The offset to next node offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtFirstSubnode (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_first_subnode (Fdt, Offset);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of next node from the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to previous node.
> >>
> >> +
> >>
> >> +  @return The offset to next node offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtNextSubnode (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_next_subnode (Fdt, Offset);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of first node which includes the given name.
> >>
> >> +
> >>
> >> +  @param[in] Fdt             The pointer to FDT blob.
> >>
> >> +  @param[in] ParentOffset    The offset to the node which start find under.
> >>
> >> +  @param[in] Name            The name to search the node with the name.
> >>
> >> +  @param[in] NameLength      The length of the name to check only.
> >>
> >> +
> >>
> >> +  @return The offset to node offset with given node name.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtSubnodeOffsetNameLen (
> >>
> >> +  IN CONST VOID   *Fdt,
> >>
> >> +  IN INT32        ParentOffset,
> >>
> >> +  IN CONST CHAR8  *Name,
> >>
> >> +  IN INT32        NameLength
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name,
> >> + NameLength);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of first node which includes the given property name and value.
> >>
> >> +
> >>
> >> +  @param[in] Fdt             The pointer to FDT blob.
> >>
> >> +  @param[in] StartOffset     The offset to the starting node to find.
> >>
> >> +  @param[in] PropertyName    The property name to search the node including the named property.
> >>
> >> +  @param[in] PropertyValue   The property value to check the same property value.
> >>
> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> >>
> >> +
> >>
> >> +  @return The offset to node offset with given property.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtNodeOffsetByPropValue (
> >>
> >> +  IN CONST VOID   *Fdt,
> >>
> >> +  IN INT32        StartOffset,
> >>
> >> +  IN CONST CHAR8  *PropertyName,
> >>
> >> +  IN CONST VOID   *PropertyValue,
> >>
> >> +  IN INT32        PropertyLength
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> >> + PropertyName, PropertyValue, PropertyLength);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a property with the given name from the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] NodeOffset     The offset to the given node.
> >>
> >> +  @param[in] Name           The name to the property which need be searched
> >>
> >> +  @param[in] Length         The length to the size of the property found.
> >>
> >> +
> >>
> >> +  @return The property to the structure of the found property.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +CONST struct fdt_property *
> >>
> >> +EFIAPI
> >>
> >> +FdtGetProperty (
> >>
> >> +  IN CONST VOID   *Fdt,
> >>
> >> +  IN INT32        NodeOffset,
> >>
> >> +  IN CONST CHAR8  *Name,
> >>
> >> +  IN INT32        *Length
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of first property in the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] NodeOffset     The offset to the node which need be searched.
> >>
> >> +
> >>
> >> +  @return The offset to first property offset in the given node.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtFirstPropertyOffset (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       NodeOffset
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_first_property_offset (Fdt, NodeOffset);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a offset of next property from the given property.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to previous property.
> >>
> >> +
> >>
> >> +  @return The offset to next property offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtNextPropertyOffset (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_next_property_offset (Fdt, Offset);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a property from the given offset of the property.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] Offset         The offset to the given offset of the property.
> >>
> >> +  @param[in] Length         The length to the size of the property found.
> >>
> >> +
> >>
> >> +  @return The property to the structure of the given property offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +CONST struct fdt_property *
> >>
> >> +EFIAPI
> >>
> >> +FdtGetPropertyByOffset (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       Offset,
> >>
> >> +  IN INT32       *Length
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Returns a string by the given string offset.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> >>
> >> +  @param[in] Length         The length to the size of string which need be retrieved.
> >>
> >> +
> >>
> >> +  @return The string to the given string offset.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +CONST CHAR8 *
> >>
> >> +EFIAPI
> >>
> >> +FdtGetString (
> >>
> >> +  IN CONST VOID  *Fdt,
> >>
> >> +  IN INT32       StrOffset,
> >>
> >> +  IN INT32       *Length        OPTIONAL
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_get_string (Fdt, StrOffset, Length);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Add a new node to the FDT.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> >>
> >> +  @param[in] Name           The name to name the node.
> >>
> >> +
> >>
> >> +  @return  The offset to the new node.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtAddSubnode (
> >>
> >> +  IN VOID         *Fdt,
> >>
> >> +  IN INT32        ParentOffset,
> >>
> >> +  IN CONST CHAR8  *Name
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> +  Add or modify a property in the given node.
> >>
> >> +
> >>
> >> +  @param[in] Fdt            The pointer to FDT blob.
> >>
> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> >>
> >> +  @param[in] Name           The name to name the property.
> >>
> >> +  @param[in] Value          The value to the property value.
> >>
> >> +  @param[in] Length         The length to the size of the property.
> >>
> >> +
> >>
> >> +  @return  Zero for successfully, otherwise failed.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +INT32
> >>
> >> +EFIAPI
> >>
> >> +FdtSetProp (
> >>
> >> +  IN VOID         *Fdt,
> >>
> >> +  IN INT32        NodeOffset,
> >>
> >> +  IN CONST CHAR8  *Name,
> >>
> >> +  IN CONST VOID   *Value,
> >>
> >> +  IN UINT32       Length
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> >>
> >> +}
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> >> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> >> new file mode 100644
> >> index 0000000000..e738f4ded4
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> >> @@ -0,0 +1,99 @@
> >> +/** @file
> >>
> >> +  Root include file of C runtime library to support building the
> >> + third-party
> >>
> >> +  libfdt library.
> >>
> >> +
> >>
> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#ifndef FDT_LIB_SUPPORT_H_
> >>
> >> +#define FDT_LIB_SUPPORT_H_
> >>
> >> +
> >>
> >> +#include <Base.h>
> >>
> >> +#include <Library/BaseLib.h>
> >>
> >> +#include <Library/BaseMemoryLib.h>
> >>
> >> +
> >>
> >> +typedef UINT8    uint8_t;
> >>
> >> +typedef UINT16   uint16_t;
> >>
> >> +typedef INT32    int32_t;
> >>
> >> +typedef UINT32   uint32_t;
> >>
> >> +typedef UINT64   uint64_t;
> >>
> >> +typedef UINTN    uintptr_t;
> >>
> >> +typedef UINTN    size_t;
> >>
> >> +typedef BOOLEAN  bool;
> >>
> >> +
> >>
> >> +#define true   (1 == 1)
> >>
> >> +#define false  (1 == 0)
> >>
> >> +
> >>
> >> +//
> >>
> >> +// Definitions for global constants used by libfdt library routines
> >>
> >> +//
> >>
> >> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value */
> >>
> >> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32 value */
> >>
> >> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32 value */
> >>
> >> +
> >>
> >> +//
> >>
> >> +// Function prototypes of libfdt Library routines
> >>
> >> +//
> >>
> >> +void *
> >>
> >> +memset     (
> >>
> >> +  void *,
> >>
> >> +  int,
> >>
> >> +  size_t
> >>
> >> +  );
> >>
> >> +
> >>
> >> +int
> >>
> >> +memcmp      (
> >>
> >> +  const void *,
> >>
> >> +  const void *,
> >>
> >> +  size_t
> >>
> >> +  );
> >>
> >> +
> >>
> >> +int
> >>
> >> +strcmp      (
> >>
> >> +  const char *,
> >>
> >> +  const char *
> >>
> >> +  );
> >>
> >> +
> >>
> >> +char *
> >>
> >> +strchr     (
> >>
> >> +  const char *,
> >>
> >> +  int
> >>
> >> +  );
> >>
> >> +
> >>
> >> +char *
> >>
> >> +strrchr    (
> >>
> >> +  const char *,
> >>
> >> +  int
> >>
> >> +  );
> >>
> >> +
> >>
> >> +unsigned long
> >>
> >> +strtoul     (
> >>
> >> +  const char *,
> >>
> >> +  char **,
> >>
> >> +  int
> >>
> >> +  );
> >>
> >> +
> >>
> >> +char *
> >>
> >> +strcpy (
> >>
> >> +  char        *strDest,
> >>
> >> +  const char  *strSource
> >>
> >> +  );
> >>
> >> +
> >>
> >> +//
> >>
> >> +// Macros that directly map functions to BaseLib, BaseMemoryLib, and
> >> +DebugLib functions
> >>
> >> +//
> >>
> >> +#define memcpy(dest, source, count)         CopyMem(dest,source, (UINTN)(count))
> >>
> >> +#define memset(dest, ch, count)             SetMem(dest, (UINTN)(count),(UINT8)(ch))
> >>
> >> +#define memchr(buf, ch, count)              ScanMem8(buf, (UINTN)(count),(UINT8)ch)
> >>
> >> +#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1, buf2, (UINTN)(count)))
> >>
> >> +#define memmove(dest, source, count)        CopyMem(dest, source, (UINTN)(count))
> >>
> >> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> >>
> >> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
> >>
> >> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest,
> >> +MAX_STRING_SIZE, strSource, (UINTN)count)
> >>
> >> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest, MAX_STRING_SIZE, strSource)
> >>
> >> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1, string2))
> >>
> >> +#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1, string2, (UINTN)(count)))
> >>
> >> +
> >>
> >> +#endif /* FDT_LIB_SUPPORT_H_ */
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> >> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> >> new file mode 100644
> >> index 0000000000..772bba4839
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> >> @@ -0,0 +1,173 @@
> >> +/** @file
> >>
> >> +  ISO C implementations of strchr, strrchr and strtoul.
> >>
> >> +
> >>
> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> >>
> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#include <Base.h>
> >>
> >> +
> >>
> >> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long value */
> >>
> >> +
> >>
> >> +// Very quick notes:
> >>
> >> +// We only go through the string once for both functions
> >>
> >> +// They are minimal implementations (not speed optimized) of ISO C
> >> +semantics
> >>
> >> +// strchr and strrchr also include the null terminator as part of the
> >> +string
> >>
> >> +// so the code gets a bit clunky to handle that case specifically.
> >>
> >> +
> >>
> >> +char *
> >>
> >> +strchr (
> >>
> >> +  const char  *Str,
> >>
> >> +  int         Char
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  char  *S;
> >>
> >> +
> >>
> >> +  S = (char *)Str;
> >>
> >> +
> >>
> >> +  for ( ; ; S++) {
> >>
> >> +    if (*S == Char) {
> >>
> >> +      return S;
> >>
> >> +    }
> >>
> >> +
> >>
> >> +    if (*S == '\0') {
> >>
> >> +      return NULL;
> >>
> >> +    }
> >>
> >> +  }
> >>
> >> +}
> >>
> >> +
> >>
> >> +char *
> >>
> >> +strrchr (
> >>
> >> +  const char  *Str,
> >>
> >> +  int         Char
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  char  *S, *last;
> >>
> >> +
> >>
> >> +  S    = (char *)Str;
> >>
> >> +  last = NULL;
> >>
> >> +
> >>
> >> +  for ( ; ; S++) {
> >>
> >> +    if (*S == Char) {
> >>
> >> +      last = S;
> >>
> >> +    }
> >>
> >> +
> >>
> >> +    if (*S == '\0') {
> >>
> >> +      return last;
> >>
> >> +    }
> >>
> >> +  }
> >>
> >> +}
> >>
> >> +
> >>
> >> +STATIC
> >>
> >> +int
> >>
> >> +__isspace (
> >>
> >> +  int  ch
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  // basic ASCII ctype.h:isspace(). Not efficient
> >>
> >> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch ==
> >> + '\v' || ch == '\f';
> >>
> >> +}
> >>
> >> +
> >>
> >> +unsigned long
> >>
> >> +strtoul (
> >>
> >> +  const char  *Nptr,
> >>
> >> +  char        **EndPtr,
> >>
> >> +  int         Base
> >>
> >> +  )
> >>
> >> +{
> >>
> >> +  BOOLEAN        Negate;
> >>
> >> +  BOOLEAN        Overflow;
> >>
> >> +  unsigned long  Val;
> >>
> >> +
> >>
> >> +  Negate   = FALSE;
> >>
> >> +  Overflow = FALSE;
> >>
> >> +  Val      = 0;
> >>
> >> +
> >>
> >> +  // Reject bad numeric bases
> >>
> >> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> >>
> >> +    return 0;
> >>
> >> +  }
> >>
> >> +
> >>
> >> +  // Skip whitespace
> >>
> >> +  while (__isspace (*Nptr)) {
> >>
> >> +    Nptr++;
> >>
> >> +  }
> >>
> >> +
> >>
> >> +  // Check for + or - prefixes
> >>
> >> +  if (*Nptr == '-') {
> >>
> >> +    Negate = TRUE;
> >>
> >> +    Nptr++;
> >>
> >> +  } else if (*Nptr == '+') {
> >>
> >> +    Nptr++;
> >>
> >> +  }
> >>
> >> +
> >>
> >> +  // Consume the start, autodetecting base if needed
> >>
> >> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X')) &&
> >> + ((Base == 0) || (Base == 16))) {
> >>
> >> +    // Hex
> >>
> >> +    Nptr += 2;
> >>
> >> +    Base  = 16;
> >>
> >> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> >> + 'B')) && ((Base == 0) || (Base == 2))) {
> >>
> >> +    // Binary (standard pending C23)
> >>
> >> +    Nptr += 2;
> >>
> >> +    Base  = 2;
> >>
> >> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> >>
> >> +    // Octal
> >>
> >> +    Nptr++;
> >>
> >> +    Base = 8;
> >>
> >> +  } else {
> >>
> >> +    if (Base == 0) {
> >>
> >> +      // Assume decimal
> >>
> >> +      Base = 10;
> >>
> >> +    }
> >>
> >> +  }
> >>
> >> +
> >>
> >> +  while (TRUE) {
> >>
> >> +    int            Digit;
> >>
> >> +    char           C;
> >>
> >> +    unsigned long  NewVal;
> >>
> >> +
> >>
> >> +    C     = *Nptr;
> >>
> >> +    Digit = -1;
> >>
> >> +
> >>
> >> +    if ((C >= '0') && (C <= '9')) {
> >>
> >> +      Digit = C - '0';
> >>
> >> +    } else if ((C >= 'a') && (C <= 'z')) {
> >>
> >> +      Digit = C - 'a' + 10;
> >>
> >> +    } else if ((C >= 'A') && (C <= 'Z')) {
> >>
> >> +      Digit = C - 'A' + 10;
> >>
> >> +    }
> >>
> >> +
> >>
> >> +    if ((Digit == -1) || (Digit >= Base)) {
> >>
> >> +      // Note that this case also handles the \0
> >>
> >> +      if (EndPtr) {
> >>
> >> +        *EndPtr = (char *)Nptr;
> >>
> >> +      }
> >>
> >> +
> >>
> >> +      break;
> >>
> >> +    }
> >>
> >> +
> >>
> >> +    NewVal = Val * Base + Digit;
> >>
> >> +
> >>
> >> +    if (NewVal < Val) {
> >>
> >> +      // Overflow
> >>
> >> +      Overflow = TRUE;
> >>
> >> +    }
> >>
> >> +
> >>
> >> +    Val = NewVal;
> >>
> >> +
> >>
> >> +    Nptr++;
> >>
> >> +  }
> >>
> >> +
> >>
> >> +  if (Negate) {
> >>
> >> +    Val = -Val;
> >>
> >> +  }
> >>
> >> +
> >>
> >> +  if (Overflow) {
> >>
> >> +    Val = ULONG_MAX;
> >>
> >> +  }
> >>
> >> +
> >>
> >> +  // TODO: We're lacking errno here.
> >>
> >> +  return Val;
> >>
> >> +}
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> >> b/MdePkg/Library/BaseFdtLib/limits.h
> >> new file mode 100644
> >> index 0000000000..f6cf8d5702
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> >> @@ -0,0 +1,10 @@
> >> +/** @file
> >>
> >> +  Include file to support building the third-party libfdt library.
> >>
> >> +
> >>
> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#include <LibFdtSupport.h>
> >>
> >> +
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> >> b/MdePkg/Library/BaseFdtLib/stdbool.h
> >> new file mode 100644
> >> index 0000000000..f6cf8d5702
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> >> @@ -0,0 +1,10 @@
> >> +/** @file
> >>
> >> +  Include file to support building the third-party libfdt library.
> >>
> >> +
> >>
> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#include <LibFdtSupport.h>
> >>
> >> +
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> >> b/MdePkg/Library/BaseFdtLib/stddef.h
> >> new file mode 100644
> >> index 0000000000..f6cf8d5702
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> >> @@ -0,0 +1,10 @@
> >> +/** @file
> >>
> >> +  Include file to support building the third-party libfdt library.
> >>
> >> +
> >>
> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#include <LibFdtSupport.h>
> >>
> >> +
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> >> b/MdePkg/Library/BaseFdtLib/stdint.h
> >> new file mode 100644
> >> index 0000000000..f6cf8d5702
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> >> @@ -0,0 +1,10 @@
> >> +/** @file
> >>
> >> +  Include file to support building the third-party libfdt library.
> >>
> >> +
> >>
> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#include <LibFdtSupport.h>
> >>
> >> +
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> >> b/MdePkg/Library/BaseFdtLib/stdlib.h
> >> new file mode 100644
> >> index 0000000000..f6cf8d5702
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> >> @@ -0,0 +1,10 @@
> >> +/** @file
> >>
> >> +  Include file to support building the third-party libfdt library.
> >>
> >> +
> >>
> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#include <LibFdtSupport.h>
> >>
> >> +
> >>
> >> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> >> b/MdePkg/Library/BaseFdtLib/string.h
> >> new file mode 100644
> >> index 0000000000..f6cf8d5702
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseFdtLib/string.h
> >> @@ -0,0 +1,10 @@
> >> +/** @file
> >>
> >> +  Include file to support building the third-party libfdt library.
> >>
> >> +
> >>
> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#include <LibFdtSupport.h>
> >>
> >> +
> >>
> >> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index
> >> 6ba85ebe61..f039daccdb 100644
> >> --- a/MdePkg/MdePkg.ci.yaml
> >> +++ b/MdePkg/MdePkg.ci.yaml
> >> @@ -2,7 +2,7 @@
> >>  # CI configuration for MdePkg
> >>
> >>  #
> >>
> >>  # Copyright (c) Microsoft Corporation
> >>
> >> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
> >>
> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>
> >>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> >>
> >>  # Copyright (c) 2023, Loongson Technology Corporation Limited. All
> >> rights reserved.<BR>
> >>
> >>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> @@ -67,7 +67,8 @@
> >>              "Include/Library/PcdLib.h",
> >>
> >>              "Include/Library/SafeIntLib.h",
> >>
> >>              "Include/Protocol/DebugSupport.h",
> >>
> >> -            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> >>
> >> +
> >> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> >>
> >> +            "Library/BaseFdtLib"
> >>
> >>          ]
> >>
> >>      },
> >>
> >>      ## options defined ci/Plugin/CompilerPlugin
> >>
> >> @@ -164,5 +165,17 @@
> >>          "ExtendWords": [],           # words to extend to the dictionary for this package
> >>
> >>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
> >>
> >>          "AdditionalIncludePaths": [] # Additional paths to spell
> >> check (wildcards supported)
> >>
> >> +    },
> >>
> >> +    # options defined in .pytool/Plugin/UncrustifyCheck
> >>
> >> +    "UncrustifyCheck": {
> >>
> >> +        "IgnoreFiles": [
> >>
> >> +            "Library/BaseFdtLib/libfdt",
> >>
> >> +            "Library/BaseFdtLib/limits.h",
> >>
> >> +            "Library/BaseFdtLib/stdbool.h",
> >>
> >> +            "Library/BaseFdtLib/stddef.h",
> >>
> >> +            "Library/BaseFdtLib/stdint.h",
> >>
> >> +            "Library/BaseFdtLib/stdlib.h",
> >>
> >> +            "Library/BaseFdtLib/string.h"
> >>
> >> +        ]
> >>
> >>      }
> >>
> >>  }
> >>
> >> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> >> e70182bf7f..9804a7a6bd 100644
> >> --- a/MdePkg/MdePkg.dec
> >> +++ b/MdePkg/MdePkg.dec
> >> @@ -289,6 +289,10 @@
> >>    #
> >>
> >>    ArmTrngLib|Include/Library/ArmTrngLib.h
> >>
> >>
> >>
> >> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> >>
> >> +  #
> >>
> >> +  FdtLib|Include/Library/FdtLib.h
> >>
> >> +
> >>
> >>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> >>
> >>    ##  @libraryclass  Provides services to generate random number.
> >>
> >>    #
> >>
> >> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> >> 152c02991a..b38c863812 100644
> >> --- a/MdePkg/MdePkg.dsc
> >> +++ b/MdePkg/MdePkg.dsc
> >> @@ -137,6 +137,7 @@
> >>    MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> >>
> >>
> >>
> >>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> >>
> >> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >>
> >>
> >>
> >>  [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
> >>
> >>    #
> >>
> >> --
> >> 2.39.1.windows.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-19 21:04       ` Michael D Kinney
@ 2023-04-20  4:25         ` Benny Lin
  2023-04-20 16:44           ` Michael D Kinney
  0 siblings, 1 reply; 20+ messages in thread
From: Benny Lin @ 2023-04-20  4:25 UTC (permalink / raw)
  To: Kinney, Michael D, devel@edk2.groups.io
  Cc: Gao, Liming, Liu, Zhiguang, Pedro Falcato



>-----Original Message-----
>From: Kinney, Michael D <michael.d.kinney@intel.com> 
>Sent: Thursday, April 20, 2023 5:04 AM
>To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
>Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>; Kinney, Michael D <michael.d.kinney@intel.com>
>Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
>
>Responses below
>
>Mike
>
>> -----Original Message-----
>> From: Lin, Benny <benny.lin@intel.com>
>> Sent: Wednesday, April 19, 2023 10:12 AM
>> To: Kinney, Michael D <michael.d.kinney@intel.com>; 
>> devel@edk2.groups.io
>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang 
>> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
>> 
>> Please find my feedback below.
>> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER, what do you think?
>> 
>> QQQ
>> Benny
>> 
>> >-----Original Message-----
>> >From: Kinney, Michael D <michael.d.kinney@intel.com>
>> >Sent: Wednesday, April 19, 2023 11:54 PM
>> >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
>> >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang 
>> ><zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>; 
>> >Kinney,
>> Michael D <michael.d.kinney@intel.com>
>> >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
>> >
>> >A few comments below.
>> >
>> >Mike
>> >
>> >> -----Original Message-----
>> >> From: Lin, Benny <benny.lin@intel.com>
>> >> Sent: Sunday, April 16, 2023 10:35 PM
>> >> To: devel@edk2.groups.io
>> >> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D 
>> >> <michael.d.kinney@intel.com>; Gao, Liming 
>> >> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; 
>> >> Pedro Falcato <pedro.falcato@gmail.com>
>> >> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
>> >>
>> >> From: Benny Lin <benny.lin@intel.com>
>> >>
>> >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
>> >> Add FDT support in EDK2 by submodule 3rd party libfdt
>> >> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
>> >> and refer to LibcLib implementation by Pedro.
>> >>
>> >> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>> >> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>> >> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
>> >> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
>> >> Signed-off-by: Benny Lin <benny.lin@intel.com>
>> >> ---
>> >>  MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
>> >>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++ 
>> >> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
>> >>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
>> >>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++ 
>> >> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
>> >>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
>> >>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
>> >>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
>> >>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
>> >>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
>> >>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
>> >>  MdePkg/MdePkg.ci.yaml                     |  17 +-
>> >>  MdePkg/MdePkg.dec                         |   4 +
>> >>  MdePkg/MdePkg.dsc                         |   1 +
>> >>  15 files changed, 1043 insertions(+), 2 deletions(-)
>> >>
>> >> diff --git a/MdePkg/Include/Library/FdtLib.h 
>> >> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
>> >> 0000000000..d59b749c25
>> >> --- /dev/null
>> >> +++ b/MdePkg/Include/Library/FdtLib.h
>> >> @@ -0,0 +1,314 @@
>> >> +/** @file
>> >>
>> >> +  Flattened Device Tree Library.
>> >>
>> >> +
>> >>
>> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#ifndef FDT_LIB_H_
>> >>
>> >> +#define FDT_LIB_H_
>> >>
>> >> +
>> >>
>> >> +///
>> >>
>> >> +/// Flattened Device Tree definition
>> >>
>> >> +///
>> >>
>> >> +typedef struct {
>> >>
>> >> +  UINT32    Magic;               /* magic word FDT_MAGIC */
>> >>
>> >> +  UINT32    TotalSize;           /* total size of DT block */
>> >>
>> >> +  UINT32    OffsetDtStruct;      /* offset to structure */
>> >>
>> >> +  UINT32    OffsetDtStrings;     /* offset to strings */
>> >>
>> >> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map */
>> >>
>> >> +  UINT32    Version;             /* format version */
>> >>
>> >> +  UINT32    LastCompVersion;     /* last compatible version */
>> >>
>> >> +
>> >>
>> >> +  /* version 2 fields below */
>> >>
>> >> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
>> >>
>> >> +                                    booting on */
>> >>
>> >> +  /* version 3 fields below */
>> >>
>> >> +  UINT32    SizeDtStrings;       /* size of the strings block */
>> >>
>> >> +
>> >>
>> >> +  /* version 17 fields below */
>> >>
>> >> +  UINT32    SizeDtStruct;        /* size of the structure block */
>> >>
>> >> +} FDT_HEADER;
>> >
>> >I see the macros below use SwapBytes32() on all the fields from this 
>> >structure.  Does this mean this structure is big >endian?  If
>> that is the case, then the description of this structure and all 
>> individual fields must make that very clear >so any consumer of the 
>> structure knows it does not follow the default endianness of UEFI/PI and that consumers >must either use the macros or consumers must use SwapBytes32() on their own when using this structure directly.
>> 
>> Yes, it's big endian. I will complete more descriptions in patch v4.
>
>Would it be simpler if we have a lib service that converts the entire header from big endian to little endian.
>That way, the consumer can use the FDT_HEADER directly without any of the macros?
>
>Also, is the rest of the FDT blob also big endian?

FDT blob format is binary encoding of FDT data with big endian. In addition, the consumer will set or get FDT data with FDT blob. We can complete more descriptions to warn consumers to be careful if just use header struct for mapping and get/set FDT data with FDT blob. 

For provide lib services that converts between big endian and little endian, we can provide a get header function to convert between big endian and little endian. However, we also need to consider the property value for setting and getting then we can convert in wrapper functions.

For example,

INT32
EFIAPI
FdtSetProp (
  IN VOID         *Fdt,
  IN INT32        NodeOffset,
  IN CONST CHAR8  *Name,
  IN CONST VOID   *Value,
  IN UINT32       Length
  )
{
  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
}

More functions for various byte width.
INT32
EFIAPI
FdtSetProp16 (
  IN VOID         *Fdt,
  IN INT32        NodeOffset,
  IN CONST CHAR8  *Name,
  IN CONST UINT16   *Value,
  IN UINT32       Length
  )
{
  return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value), (int)Length);
}

INT32
EFIAPI
FdtSetProp32 (
  IN VOID         *Fdt,
  IN INT32        NodeOffset,
  IN CONST CHAR8  *Name,
  IN CONST UINT32   *Value,
  IN UINT32       Length
  )
{
  return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value), (int)Length);
}

>> 
>> >>
>> >> +
>> >>
>> >> +typedef struct {
>> >>
>> >> +  UINT64    Address;
>> >>
>> >> +  UINT64    Size;
>> >>
>> >> +} FDT_RESERVE_ENTRY;
>> >
>> >
>> >I do not see this type used anywhere in the lib class or the lib instance.
>> >Can it be removed?
>> 
>> I think we can remove it because it might be not used for further usage of FDT support.
>> 
>> >
>> >>
>> >> +
>> >>
>> >> +typedef struct {
>> >>
>> >> +  UINT32    Tag;
>> >>
>> >> +  CHAR8     Name[];
>> >>
>> >> +} FDT_NODE_HEADER;
>> >
>> >
>> >I do not see this type used anywhere in the lib class or the lib instance.
>> >Can it be removed?
>> 
>> When we need retrieve a node from a FDT blob, we will get a node 
>> offset then we could use the struct to map the node content. It's very useful.
>
>Please add a comment header for this structure and describe the usage as it related to the rest of the FdtLib >services.

I will add descriptions for the usage and remove FDT_RESERVE_ENTRY in patch v4.

>
>> 
>> >
>> >>
>> >> +
>> >>
>> >> +typedef struct {
>> >>
>> >> +  UINT32    Tag;
>> >>
>> >> +  UINT32    Length;
>> >>
>> >> +  UINT32    NameOffset;
>> >>
>> >> +  CHAR8     Data[];
>> >>
>> >> +} FDT_PROPERTY;
>> >>
>> >> +
>> >>
>> >> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST FDT_HEADER
>> >> +*)(Fdt))->Field)
>> >>
>> >> +
>> >>
>> >> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
>> >>
>> >> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt, TotalSize))
>> >>
>> >> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt, OffsetDtStruct))
>> >>
>> >> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
>> >> +OffsetDtStrings))
>> >>
>> >> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
>> >> +OffsetMemRsvmap))
>> >>
>> >> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
>> >>
>> >> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
>> >> +LastCompVersion))
>> >>
>> >> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt, BootCpuidPhys))
>> >>
>> >> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt, SizeDtStrings))
>> >>
>> >> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt, SizeDtStruct))
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Verify the header of the Flattened Device Tree
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +
>> >>
>> >> +  @return Zero for successfully, otherwise failed.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtCheckHeader (
>> >>
>> >> +  IN CONST VOID  *Fdt
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Create a empty Flattened Device Tree.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
>> >>
>> >> +  @param[in] BufferSize     The BufferSize to the pool size.
>> >>
>> >> +
>> >>
>> >> +  @return Zero for successfully, otherwise failed.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +RETURN_STATUS
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtCreateEmptyTree (
>> >>
>> >> +  IN VOID   *Buffer,
>> >>
>> >> +  IN UINTN  BufferSize
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of next node from the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to previous node.
>> >>
>> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to next node offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtNextNode (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset,
>> >>
>> >> +  IN INT32       *Depth
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of first node under the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to previous node.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to next node offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtFirstSubnode (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of next node from the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to previous node.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to next node offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtNextSubnode (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of first node which includes the given name.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt             The pointer to FDT blob.
>> >>
>> >> +  @param[in] ParentOffset    The offset to the node which start find under.
>> >>
>> >> +  @param[in] Name            The name to search the node with the name.
>> >>
>> >> +  @param[in] NameLength      The length of the name to check only.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to node offset with given node name.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtSubnodeOffsetNameLen (
>> >>
>> >> +  IN CONST VOID   *Fdt,
>> >>
>> >> +  IN INT32        ParentOffset,
>> >>
>> >> +  IN CONST CHAR8  *Name,
>> >>
>> >> +  IN INT32        NameLength
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of first node which includes the given property name and value.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt             The pointer to FDT blob.
>> >>
>> >> +  @param[in] StartOffset     The offset to the starting node to find.
>> >>
>> >> +  @param[in] PropertyName    The property name to search the node including the named property.
>> >>
>> >> +  @param[in] PropertyValue   The property value to check the same property value.
>> >>
>> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to node offset with given property.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtNodeOffsetByPropValue (
>> >>
>> >> +  IN CONST VOID   *Fdt,
>> >>
>> >> +  IN INT32        StartOffset,
>> >>
>> >> +  IN CONST CHAR8  *PropertyName,
>> >>
>> >> +  IN CONST VOID   *PropertyValue,
>> >>
>> >> +  IN INT32        PropertyLength
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a property with the given name from the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] NodeOffset     The offset to the given node.
>> >>
>> >> +  @param[in] Name           The name to the property which need be searched
>> >>
>> >> +  @param[in] Length         The length to the size of the property found.
>> >>
>> >> +
>> >>
>> >> +  @return The property to the structure of the found property.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +CONST FDT_PROPERTY *
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtGetProperty (
>> >>
>> >> +  IN CONST VOID   *Fdt,
>> >>
>> >> +  IN INT32        NodeOffset,
>> >>
>> >> +  IN CONST CHAR8  *Name,
>> >>
>> >> +  IN INT32        *Length
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of first property in the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to the node which need be searched.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to first property offset in the given node.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtFirstPropertyOffset (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       NodeOffset
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of next property from the given property.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to previous property.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to next property offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtNextPropertyOffset (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a property from the given offset of the property.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to the given offset of the property.
>> >>
>> >> +  @param[in] Length         The length to the size of the property found.
>> >>
>> >> +
>> >>
>> >> +  @return The property to the structure of the given property offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +CONST FDT_PROPERTY *
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtGetPropertyByOffset (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset,
>> >>
>> >> +  IN INT32       *Length
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a string by the given string offset.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
>> >>
>> >> +  @param[in] Length         The length to the size of string which need be retrieved.
>> >>
>> >> +
>> >>
>> >> +  @return The string to the given string offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +CONST CHAR8 *
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtGetString (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       StrOffset,
>> >>
>> >> +  IN INT32       *Length        OPTIONAL
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Add a new node to the FDT.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
>> >>
>> >> +  @param[in] Name           The name to name the node.
>> >>
>> >> +
>> >>
>> >> +  @return  The offset to the new node.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtAddSubnode (
>> >>
>> >> +  IN VOID         *Fdt,
>> >>
>> >> +  IN INT32        ParentOffset,
>> >>
>> >> +  IN CONST CHAR8  *Name
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Add or modify a property in the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
>> >>
>> >> +  @param[in] Name           The name to name the property.
>> >>
>> >> +  @param[in] Value          The value to the property value.
>> >>
>> >> +  @param[in] Length         The length to the size of the property.
>> >>
>> >> +
>> >>
>> >> +  @return  Zero for successfully, otherwise failed.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtSetProp (
>> >>
>> >> +  IN VOID         *Fdt,
>> >>
>> >> +  IN INT32        NodeOffset,
>> >>
>> >> +  IN CONST CHAR8  *Name,
>> >>
>> >> +  IN CONST VOID   *Value,
>> >>
>> >> +  IN UINT32       Length
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +#endif /* FDT_LIB_H_ */
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>> >> new file mode 100644
>> >> index 0000000000..730e568ff6
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>> >> @@ -0,0 +1,62 @@
>> >> +## @file
>> >>
>> >> +# Flattened Device Tree Library.
>> >>
>> >> +#
>> >>
>> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +#
>> >>
>> >> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +#
>> >>
>> >> +#
>> >>
>> >> +##
>> >>
>> >> +
>> >>
>> >> +[Defines]
>> >>
>> >> +  INF_VERSION                    = 0x0001001B
>> >>
>> >> +  BASE_NAME                      = BaseFdtLib
>> >>
>> >> +  MODULE_UNI_FILE                = BaseFdtLib.uni
>> >>
>> >> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-E8CEC206DE04
>> >>
>> >> +  MODULE_TYPE                    = BASE
>> >>
>> >> +  VERSION_STRING                 = 1.0
>> >>
>> >> +  LIBRARY_CLASS                  = FdtLib
>> >>
>> >> +
>> >>
>> >> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
>> >>
>> >> +
>> >>
>> >> +#
>> >>
>> >> +#  VALID_ARCHITECTURES           = IA32 X64
>> >>
>> >> +#
>> >>
>> >> +
>> >>
>> >> +[Sources]
>> >>
>> >> +  FdtLib.c
>> >>
>> >> +  LibFdtWrapper.c
>> >>
>> >> +  # header Wrapper files
>> >>
>> >> +  limits.h
>> >>
>> >> +  stdbool.h
>> >>
>> >> +  stddef.h
>> >>
>> >> +  stdint.h
>> >>
>> >> +  stdlib.h
>> >>
>> >> +  string.h
>> >>
>> >> +
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt.c
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt.h
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt_addresses.c
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt_check.c
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt_overlay.c
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt_ro.c
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt_rw.c
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt_strerror.c
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt_sw.c
>> >>
>> >> +  $(FDT_LIB_PATH)/fdt_wip.c
>> >>
>> >> +  $(FDT_LIB_PATH)/libfdt.h
>> >>
>> >> +  $(FDT_LIB_PATH)/libfdt_env.h
>> >>
>> >> +  $(FDT_LIB_PATH)/libfdt_internal.h
>> >>
>> >> +
>> >>
>> >> +[Packages]
>> >>
>> >> +  MdePkg/MdePkg.dec
>> >>
>> >> +
>> >>
>> >> +[LibraryClasses]
>> >>
>> >> +  BaseLib
>> >>
>> >> +  BaseMemoryLib
>> >>
>> >> +
>> >>
>> >> +[BuildOptions]
>> >>
>> >> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
>> >>
>> >> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
>> >>
>> >> +
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
>> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
>> >> new file mode 100644
>> >> index 0000000000..3f7e45ea6f
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
>> >> @@ -0,0 +1,14 @@
>> >> +// /** @file
>> >>
>> >> +// Flattened Device Tree Library.
>> >>
>> >> +//
>> >>
>> >> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +//
>> >>
>> >> +// SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +//
>> >>
>> >> +// **/
>> >>
>> >> +
>> >>
>> >> +
>> >>
>> >> +#string STR_MODULE_ABSTRACT             #language en-US "Instance of FDT Library"
>> >>
>> >> +
>> >>
>> >> +#string STR_MODULE_DESCRIPTION          #language en-US "This module provides FDT Library implementation."
>> >>
>> >> +
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
>> >> b/MdePkg/Library/BaseFdtLib/FdtLib.c
>> >> new file mode 100644
>> >> index 0000000000..200a496c7e
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
>> >> @@ -0,0 +1,301 @@
>> >> +/** @file
>> >>
>> >> +  Flattened Device Tree Library.
>> >>
>> >> +
>> >>
>> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#include <libfdt/libfdt/libfdt.h>
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Verify the header of the Flattened Device Tree
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +
>> >>
>> >> +  @return Zero for successfully, otherwise failed.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtCheckHeader (
>> >>
>> >> +  IN CONST VOID  *Fdt
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_check_header(Fdt);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Create a empty Flattened Device Tree.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
>> >>
>> >> +  @param[in] BufferSize     The BufferSize to the pool size.
>> >>
>> >> +
>> >>
>> >> +  @return Zero for successfully, otherwise failed.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtCreateEmptyTree (
>> >>
>> >> +  IN VOID    *Buffer,
>> >>
>> >> +  IN UINT32  BufferSize
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of next node from the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to previous node.
>> >>
>> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to next node offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtNextNode (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset,
>> >>
>> >> +  IN INT32       *Depth
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_next_node (Fdt, Offset, Depth);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of first node under the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to previous node.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to next node offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtFirstSubnode (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_first_subnode (Fdt, Offset);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of next node from the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to previous node.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to next node offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtNextSubnode (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_next_subnode (Fdt, Offset);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of first node which includes the given name.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt             The pointer to FDT blob.
>> >>
>> >> +  @param[in] ParentOffset    The offset to the node which start find under.
>> >>
>> >> +  @param[in] Name            The name to search the node with the name.
>> >>
>> >> +  @param[in] NameLength      The length of the name to check only.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to node offset with given node name.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtSubnodeOffsetNameLen (
>> >>
>> >> +  IN CONST VOID   *Fdt,
>> >>
>> >> +  IN INT32        ParentOffset,
>> >>
>> >> +  IN CONST CHAR8  *Name,
>> >>
>> >> +  IN INT32        NameLength
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name, 
>> >> + NameLength);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of first node which includes the given property name and value.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt             The pointer to FDT blob.
>> >>
>> >> +  @param[in] StartOffset     The offset to the starting node to find.
>> >>
>> >> +  @param[in] PropertyName    The property name to search the node including the named property.
>> >>
>> >> +  @param[in] PropertyValue   The property value to check the same property value.
>> >>
>> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to node offset with given property.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtNodeOffsetByPropValue (
>> >>
>> >> +  IN CONST VOID   *Fdt,
>> >>
>> >> +  IN INT32        StartOffset,
>> >>
>> >> +  IN CONST CHAR8  *PropertyName,
>> >>
>> >> +  IN CONST VOID   *PropertyValue,
>> >>
>> >> +  IN INT32        PropertyLength
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset, 
>> >> + PropertyName, PropertyValue, PropertyLength);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a property with the given name from the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] NodeOffset     The offset to the given node.
>> >>
>> >> +  @param[in] Name           The name to the property which need be searched
>> >>
>> >> +  @param[in] Length         The length to the size of the property found.
>> >>
>> >> +
>> >>
>> >> +  @return The property to the structure of the found property.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +CONST struct fdt_property *
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtGetProperty (
>> >>
>> >> +  IN CONST VOID   *Fdt,
>> >>
>> >> +  IN INT32        NodeOffset,
>> >>
>> >> +  IN CONST CHAR8  *Name,
>> >>
>> >> +  IN INT32        *Length
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of first property in the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] NodeOffset     The offset to the node which need be searched.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to first property offset in the given node.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtFirstPropertyOffset (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       NodeOffset
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_first_property_offset (Fdt, NodeOffset);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a offset of next property from the given property.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to previous property.
>> >>
>> >> +
>> >>
>> >> +  @return The offset to next property offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtNextPropertyOffset (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_next_property_offset (Fdt, Offset);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a property from the given offset of the property.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] Offset         The offset to the given offset of the property.
>> >>
>> >> +  @param[in] Length         The length to the size of the property found.
>> >>
>> >> +
>> >>
>> >> +  @return The property to the structure of the given property offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +CONST struct fdt_property *
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtGetPropertyByOffset (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       Offset,
>> >>
>> >> +  IN INT32       *Length
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Returns a string by the given string offset.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
>> >>
>> >> +  @param[in] Length         The length to the size of string which need be retrieved.
>> >>
>> >> +
>> >>
>> >> +  @return The string to the given string offset.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +CONST CHAR8 *
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtGetString (
>> >>
>> >> +  IN CONST VOID  *Fdt,
>> >>
>> >> +  IN INT32       StrOffset,
>> >>
>> >> +  IN INT32       *Length        OPTIONAL
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_get_string (Fdt, StrOffset, Length);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Add a new node to the FDT.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
>> >>
>> >> +  @param[in] Name           The name to name the node.
>> >>
>> >> +
>> >>
>> >> +  @return  The offset to the new node.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtAddSubnode (
>> >>
>> >> +  IN VOID         *Fdt,
>> >>
>> >> +  IN INT32        ParentOffset,
>> >>
>> >> +  IN CONST CHAR8  *Name
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +/**
>> >>
>> >> +  Add or modify a property in the given node.
>> >>
>> >> +
>> >>
>> >> +  @param[in] Fdt            The pointer to FDT blob.
>> >>
>> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
>> >>
>> >> +  @param[in] Name           The name to name the property.
>> >>
>> >> +  @param[in] Value          The value to the property value.
>> >>
>> >> +  @param[in] Length         The length to the size of the property.
>> >>
>> >> +
>> >>
>> >> +  @return  Zero for successfully, otherwise failed.
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +INT32
>> >>
>> >> +EFIAPI
>> >>
>> >> +FdtSetProp (
>> >>
>> >> +  IN VOID         *Fdt,
>> >>
>> >> +  IN INT32        NodeOffset,
>> >>
>> >> +  IN CONST CHAR8  *Name,
>> >>
>> >> +  IN CONST VOID   *Value,
>> >>
>> >> +  IN UINT32       Length
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
>> >>
>> >> +}
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
>> >> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
>> >> new file mode 100644
>> >> index 0000000000..e738f4ded4
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
>> >> @@ -0,0 +1,99 @@
>> >> +/** @file
>> >>
>> >> +  Root include file of C runtime library to support building the 
>> >> + third-party
>> >>
>> >> +  libfdt library.
>> >>
>> >> +
>> >>
>> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#ifndef FDT_LIB_SUPPORT_H_
>> >>
>> >> +#define FDT_LIB_SUPPORT_H_
>> >>
>> >> +
>> >>
>> >> +#include <Base.h>
>> >>
>> >> +#include <Library/BaseLib.h>
>> >>
>> >> +#include <Library/BaseMemoryLib.h>
>> >>
>> >> +
>> >>
>> >> +typedef UINT8    uint8_t;
>> >>
>> >> +typedef UINT16   uint16_t;
>> >>
>> >> +typedef INT32    int32_t;
>> >>
>> >> +typedef UINT32   uint32_t;
>> >>
>> >> +typedef UINT64   uint64_t;
>> >>
>> >> +typedef UINTN    uintptr_t;
>> >>
>> >> +typedef UINTN    size_t;
>> >>
>> >> +typedef BOOLEAN  bool;
>> >>
>> >> +
>> >>
>> >> +#define true   (1 == 1)
>> >>
>> >> +#define false  (1 == 0)
>> >>
>> >> +
>> >>
>> >> +//
>> >>
>> >> +// Definitions for global constants used by libfdt library 
>> >> +routines
>> >>
>> >> +//
>> >>
>> >> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value */
>> >>
>> >> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32 value */
>> >>
>> >> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32 value */
>> >>
>> >> +
>> >>
>> >> +//
>> >>
>> >> +// Function prototypes of libfdt Library routines
>> >>
>> >> +//
>> >>
>> >> +void *
>> >>
>> >> +memset     (
>> >>
>> >> +  void *,
>> >>
>> >> +  int,
>> >>
>> >> +  size_t
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +int
>> >>
>> >> +memcmp      (
>> >>
>> >> +  const void *,
>> >>
>> >> +  const void *,
>> >>
>> >> +  size_t
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +int
>> >>
>> >> +strcmp      (
>> >>
>> >> +  const char *,
>> >>
>> >> +  const char *
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +char *
>> >>
>> >> +strchr     (
>> >>
>> >> +  const char *,
>> >>
>> >> +  int
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +char *
>> >>
>> >> +strrchr    (
>> >>
>> >> +  const char *,
>> >>
>> >> +  int
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +unsigned long
>> >>
>> >> +strtoul     (
>> >>
>> >> +  const char *,
>> >>
>> >> +  char **,
>> >>
>> >> +  int
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +char *
>> >>
>> >> +strcpy (
>> >>
>> >> +  char        *strDest,
>> >>
>> >> +  const char  *strSource
>> >>
>> >> +  );
>> >>
>> >> +
>> >>
>> >> +//
>> >>
>> >> +// Macros that directly map functions to BaseLib, BaseMemoryLib, 
>> >> +and DebugLib functions
>> >>
>> >> +//
>> >>
>> >> +#define memcpy(dest, source, count)         CopyMem(dest,source, (UINTN)(count))
>> >>
>> >> +#define memset(dest, ch, count)             SetMem(dest, (UINTN)(count),(UINT8)(ch))
>> >>
>> >> +#define memchr(buf, ch, count)              ScanMem8(buf, (UINTN)(count),(UINT8)ch)
>> >>
>> >> +#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1, buf2, (UINTN)(count)))
>> >>
>> >> +#define memmove(dest, source, count)        CopyMem(dest, source, (UINTN)(count))
>> >>
>> >> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
>> >>
>> >> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
>> >>
>> >> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest, 
>> >> +MAX_STRING_SIZE, strSource, (UINTN)count)
>> >>
>> >> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest, MAX_STRING_SIZE, strSource)
>> >>
>> >> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1, string2))
>> >>
>> >> +#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1, string2, (UINTN)(count)))
>> >>
>> >> +
>> >>
>> >> +#endif /* FDT_LIB_SUPPORT_H_ */
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
>> >> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
>> >> new file mode 100644
>> >> index 0000000000..772bba4839
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
>> >> @@ -0,0 +1,173 @@
>> >> +/** @file
>> >>
>> >> +  ISO C implementations of strchr, strrchr and strtoul.
>> >>
>> >> +
>> >>
>> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
>> >>
>> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#include <Base.h>
>> >>
>> >> +
>> >>
>> >> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long value */
>> >>
>> >> +
>> >>
>> >> +// Very quick notes:
>> >>
>> >> +// We only go through the string once for both functions
>> >>
>> >> +// They are minimal implementations (not speed optimized) of ISO C 
>> >> +semantics
>> >>
>> >> +// strchr and strrchr also include the null terminator as part of 
>> >> +the string
>> >>
>> >> +// so the code gets a bit clunky to handle that case specifically.
>> >>
>> >> +
>> >>
>> >> +char *
>> >>
>> >> +strchr (
>> >>
>> >> +  const char  *Str,
>> >>
>> >> +  int         Char
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  char  *S;
>> >>
>> >> +
>> >>
>> >> +  S = (char *)Str;
>> >>
>> >> +
>> >>
>> >> +  for ( ; ; S++) {
>> >>
>> >> +    if (*S == Char) {
>> >>
>> >> +      return S;
>> >>
>> >> +    }
>> >>
>> >> +
>> >>
>> >> +    if (*S == '\0') {
>> >>
>> >> +      return NULL;
>> >>
>> >> +    }
>> >>
>> >> +  }
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +char *
>> >>
>> >> +strrchr (
>> >>
>> >> +  const char  *Str,
>> >>
>> >> +  int         Char
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  char  *S, *last;
>> >>
>> >> +
>> >>
>> >> +  S    = (char *)Str;
>> >>
>> >> +  last = NULL;
>> >>
>> >> +
>> >>
>> >> +  for ( ; ; S++) {
>> >>
>> >> +    if (*S == Char) {
>> >>
>> >> +      last = S;
>> >>
>> >> +    }
>> >>
>> >> +
>> >>
>> >> +    if (*S == '\0') {
>> >>
>> >> +      return last;
>> >>
>> >> +    }
>> >>
>> >> +  }
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +STATIC
>> >>
>> >> +int
>> >>
>> >> +__isspace (
>> >>
>> >> +  int  ch
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  // basic ASCII ctype.h:isspace(). Not efficient
>> >>
>> >> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch 
>> >> + == '\v' || ch == '\f';
>> >>
>> >> +}
>> >>
>> >> +
>> >>
>> >> +unsigned long
>> >>
>> >> +strtoul (
>> >>
>> >> +  const char  *Nptr,
>> >>
>> >> +  char        **EndPtr,
>> >>
>> >> +  int         Base
>> >>
>> >> +  )
>> >>
>> >> +{
>> >>
>> >> +  BOOLEAN        Negate;
>> >>
>> >> +  BOOLEAN        Overflow;
>> >>
>> >> +  unsigned long  Val;
>> >>
>> >> +
>> >>
>> >> +  Negate   = FALSE;
>> >>
>> >> +  Overflow = FALSE;
>> >>
>> >> +  Val      = 0;
>> >>
>> >> +
>> >>
>> >> +  // Reject bad numeric bases
>> >>
>> >> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
>> >>
>> >> +    return 0;
>> >>
>> >> +  }
>> >>
>> >> +
>> >>
>> >> +  // Skip whitespace
>> >>
>> >> +  while (__isspace (*Nptr)) {
>> >>
>> >> +    Nptr++;
>> >>
>> >> +  }
>> >>
>> >> +
>> >>
>> >> +  // Check for + or - prefixes
>> >>
>> >> +  if (*Nptr == '-') {
>> >>
>> >> +    Negate = TRUE;
>> >>
>> >> +    Nptr++;
>> >>
>> >> +  } else if (*Nptr == '+') {
>> >>
>> >> +    Nptr++;
>> >>
>> >> +  }
>> >>
>> >> +
>> >>
>> >> +  // Consume the start, autodetecting base if needed
>> >>
>> >> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X')) 
>> >> + && ((Base == 0) || (Base == 16))) {
>> >>
>> >> +    // Hex
>> >>
>> >> +    Nptr += 2;
>> >>
>> >> +    Base  = 16;
>> >>
>> >> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
>> >> + 'B')) && ((Base == 0) || (Base == 2))) {
>> >>
>> >> +    // Binary (standard pending C23)
>> >>
>> >> +    Nptr += 2;
>> >>
>> >> +    Base  = 2;
>> >>
>> >> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
>> >>
>> >> +    // Octal
>> >>
>> >> +    Nptr++;
>> >>
>> >> +    Base = 8;
>> >>
>> >> +  } else {
>> >>
>> >> +    if (Base == 0) {
>> >>
>> >> +      // Assume decimal
>> >>
>> >> +      Base = 10;
>> >>
>> >> +    }
>> >>
>> >> +  }
>> >>
>> >> +
>> >>
>> >> +  while (TRUE) {
>> >>
>> >> +    int            Digit;
>> >>
>> >> +    char           C;
>> >>
>> >> +    unsigned long  NewVal;
>> >>
>> >> +
>> >>
>> >> +    C     = *Nptr;
>> >>
>> >> +    Digit = -1;
>> >>
>> >> +
>> >>
>> >> +    if ((C >= '0') && (C <= '9')) {
>> >>
>> >> +      Digit = C - '0';
>> >>
>> >> +    } else if ((C >= 'a') && (C <= 'z')) {
>> >>
>> >> +      Digit = C - 'a' + 10;
>> >>
>> >> +    } else if ((C >= 'A') && (C <= 'Z')) {
>> >>
>> >> +      Digit = C - 'A' + 10;
>> >>
>> >> +    }
>> >>
>> >> +
>> >>
>> >> +    if ((Digit == -1) || (Digit >= Base)) {
>> >>
>> >> +      // Note that this case also handles the \0
>> >>
>> >> +      if (EndPtr) {
>> >>
>> >> +        *EndPtr = (char *)Nptr;
>> >>
>> >> +      }
>> >>
>> >> +
>> >>
>> >> +      break;
>> >>
>> >> +    }
>> >>
>> >> +
>> >>
>> >> +    NewVal = Val * Base + Digit;
>> >>
>> >> +
>> >>
>> >> +    if (NewVal < Val) {
>> >>
>> >> +      // Overflow
>> >>
>> >> +      Overflow = TRUE;
>> >>
>> >> +    }
>> >>
>> >> +
>> >>
>> >> +    Val = NewVal;
>> >>
>> >> +
>> >>
>> >> +    Nptr++;
>> >>
>> >> +  }
>> >>
>> >> +
>> >>
>> >> +  if (Negate) {
>> >>
>> >> +    Val = -Val;
>> >>
>> >> +  }
>> >>
>> >> +
>> >>
>> >> +  if (Overflow) {
>> >>
>> >> +    Val = ULONG_MAX;
>> >>
>> >> +  }
>> >>
>> >> +
>> >>
>> >> +  // TODO: We're lacking errno here.
>> >>
>> >> +  return Val;
>> >>
>> >> +}
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
>> >> b/MdePkg/Library/BaseFdtLib/limits.h
>> >> new file mode 100644
>> >> index 0000000000..f6cf8d5702
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/limits.h
>> >> @@ -0,0 +1,10 @@
>> >> +/** @file
>> >>
>> >> +  Include file to support building the third-party libfdt library.
>> >>
>> >> +
>> >>
>> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#include <LibFdtSupport.h>
>> >>
>> >> +
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
>> >> b/MdePkg/Library/BaseFdtLib/stdbool.h
>> >> new file mode 100644
>> >> index 0000000000..f6cf8d5702
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
>> >> @@ -0,0 +1,10 @@
>> >> +/** @file
>> >>
>> >> +  Include file to support building the third-party libfdt library.
>> >>
>> >> +
>> >>
>> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#include <LibFdtSupport.h>
>> >>
>> >> +
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
>> >> b/MdePkg/Library/BaseFdtLib/stddef.h
>> >> new file mode 100644
>> >> index 0000000000..f6cf8d5702
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
>> >> @@ -0,0 +1,10 @@
>> >> +/** @file
>> >>
>> >> +  Include file to support building the third-party libfdt library.
>> >>
>> >> +
>> >>
>> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#include <LibFdtSupport.h>
>> >>
>> >> +
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
>> >> b/MdePkg/Library/BaseFdtLib/stdint.h
>> >> new file mode 100644
>> >> index 0000000000..f6cf8d5702
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
>> >> @@ -0,0 +1,10 @@
>> >> +/** @file
>> >>
>> >> +  Include file to support building the third-party libfdt library.
>> >>
>> >> +
>> >>
>> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#include <LibFdtSupport.h>
>> >>
>> >> +
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
>> >> b/MdePkg/Library/BaseFdtLib/stdlib.h
>> >> new file mode 100644
>> >> index 0000000000..f6cf8d5702
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
>> >> @@ -0,0 +1,10 @@
>> >> +/** @file
>> >>
>> >> +  Include file to support building the third-party libfdt library.
>> >>
>> >> +
>> >>
>> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#include <LibFdtSupport.h>
>> >>
>> >> +
>> >>
>> >> diff --git a/MdePkg/Library/BaseFdtLib/string.h
>> >> b/MdePkg/Library/BaseFdtLib/string.h
>> >> new file mode 100644
>> >> index 0000000000..f6cf8d5702
>> >> --- /dev/null
>> >> +++ b/MdePkg/Library/BaseFdtLib/string.h
>> >> @@ -0,0 +1,10 @@
>> >> +/** @file
>> >>
>> >> +  Include file to support building the third-party libfdt library.
>> >>
>> >> +
>> >>
>> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> +
>> >>
>> >> +**/
>> >>
>> >> +
>> >>
>> >> +#include <LibFdtSupport.h>
>> >>
>> >> +
>> >>
>> >> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index 
>> >> 6ba85ebe61..f039daccdb 100644
>> >> --- a/MdePkg/MdePkg.ci.yaml
>> >> +++ b/MdePkg/MdePkg.ci.yaml
>> >> @@ -2,7 +2,7 @@
>> >>  # CI configuration for MdePkg
>> >>
>> >>  #
>> >>
>> >>  # Copyright (c) Microsoft Corporation
>> >>
>> >> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
>> >>
>> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>> >>
>> >>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
>> >>
>> >>  # Copyright (c) 2023, Loongson Technology Corporation Limited. All 
>> >> rights reserved.<BR>
>> >>
>> >>  # SPDX-License-Identifier: BSD-2-Clause-Patent
>> >>
>> >> @@ -67,7 +67,8 @@
>> >>              "Include/Library/PcdLib.h",
>> >>
>> >>              "Include/Library/SafeIntLib.h",
>> >>
>> >>              "Include/Protocol/DebugSupport.h",
>> >>
>> >> -            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
>> >>
>> >> +
>> >> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
>> >>
>> >> +            "Library/BaseFdtLib"
>> >>
>> >>          ]
>> >>
>> >>      },
>> >>
>> >>      ## options defined ci/Plugin/CompilerPlugin
>> >>
>> >> @@ -164,5 +165,17 @@
>> >>          "ExtendWords": [],           # words to extend to the dictionary for this package
>> >>
>> >>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
>> >>
>> >>          "AdditionalIncludePaths": [] # Additional paths to spell 
>> >> check (wildcards supported)
>> >>
>> >> +    },
>> >>
>> >> +    # options defined in .pytool/Plugin/UncrustifyCheck
>> >>
>> >> +    "UncrustifyCheck": {
>> >>
>> >> +        "IgnoreFiles": [
>> >>
>> >> +            "Library/BaseFdtLib/libfdt",
>> >>
>> >> +            "Library/BaseFdtLib/limits.h",
>> >>
>> >> +            "Library/BaseFdtLib/stdbool.h",
>> >>
>> >> +            "Library/BaseFdtLib/stddef.h",
>> >>
>> >> +            "Library/BaseFdtLib/stdint.h",
>> >>
>> >> +            "Library/BaseFdtLib/stdlib.h",
>> >>
>> >> +            "Library/BaseFdtLib/string.h"
>> >>
>> >> +        ]
>> >>
>> >>      }
>> >>
>> >>  }
>> >>
>> >> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 
>> >> e70182bf7f..9804a7a6bd 100644
>> >> --- a/MdePkg/MdePkg.dec
>> >> +++ b/MdePkg/MdePkg.dec
>> >> @@ -289,6 +289,10 @@
>> >>    #
>> >>
>> >>    ArmTrngLib|Include/Library/ArmTrngLib.h
>> >>
>> >>
>> >>
>> >> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
>> >>
>> >> +  #
>> >>
>> >> +  FdtLib|Include/Library/FdtLib.h
>> >>
>> >> +
>> >>
>> >>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
>> >>
>> >>    ##  @libraryclass  Provides services to generate random number.
>> >>
>> >>    #
>> >>
>> >> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
>> >> 152c02991a..b38c863812 100644
>> >> --- a/MdePkg/MdePkg.dsc
>> >> +++ b/MdePkg/MdePkg.dsc
>> >> @@ -137,6 +137,7 @@
>> >>    
>> >> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
>> >>
>> >>
>> >>
>> >>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
>> >>
>> >> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>> >>
>> >>
>> >>
>> >>  [Components.IA32, Components.X64, Components.ARM, 
>> >> Components.AARCH64]
>> >>
>> >>    #
>> >>
>> >> --
>> >> 2.39.1.windows.1
>
>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-20  4:25         ` Benny Lin
@ 2023-04-20 16:44           ` Michael D Kinney
  2023-04-21  2:33             ` [edk2-devel] " Chiu, Chasel
  2023-04-24 17:28             ` Leif Lindholm
  0 siblings, 2 replies; 20+ messages in thread
From: Michael D Kinney @ 2023-04-20 16:44 UTC (permalink / raw)
  To: Lin, Benny, devel@edk2.groups.io, Leif Lindholm
  Cc: Gao, Liming, Liu, Zhiguang, Pedro Falcato, Kinney, Michael D

Hi Leif,

What is your opinion on FDT being big endian.

Do we want the lib to help with that aspect, or leave it up to the consumer of the lib to 
convert as needed?  Seems like an area that could be very error prone if we are not
careful.

Mike

> -----Original Message-----
> From: Lin, Benny <benny.lin@intel.com>
> Sent: Wednesday, April 19, 2023 9:25 PM
> To: Kinney, Michael D <michael.d.kinney@intel.com>; devel@edk2.groups.io
> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> 
> 
> >-----Original Message-----
> >From: Kinney, Michael D <michael.d.kinney@intel.com>
> >Sent: Thursday, April 20, 2023 5:04 AM
> >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>
> >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> >
> >Responses below
> >
> >Mike
> >
> >> -----Original Message-----
> >> From: Lin, Benny <benny.lin@intel.com>
> >> Sent: Wednesday, April 19, 2023 10:12 AM
> >> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> >> devel@edk2.groups.io
> >> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> >> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> >> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> >>
> >> Please find my feedback below.
> >> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER, what do you think?
> >>
> >> QQQ
> >> Benny
> >>
> >> >-----Original Message-----
> >> >From: Kinney, Michael D <michael.d.kinney@intel.com>
> >> >Sent: Wednesday, April 19, 2023 11:54 PM
> >> >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> >> >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> >> ><zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>;
> >> >Kinney,
> >> Michael D <michael.d.kinney@intel.com>
> >> >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> >> >
> >> >A few comments below.
> >> >
> >> >Mike
> >> >
> >> >> -----Original Message-----
> >> >> From: Lin, Benny <benny.lin@intel.com>
> >> >> Sent: Sunday, April 16, 2023 10:35 PM
> >> >> To: devel@edk2.groups.io
> >> >> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> >> >> <michael.d.kinney@intel.com>; Gao, Liming
> >> >> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> >> >> Pedro Falcato <pedro.falcato@gmail.com>
> >> >> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> >> >>
> >> >> From: Benny Lin <benny.lin@intel.com>
> >> >>
> >> >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> >> >> Add FDT support in EDK2 by submodule 3rd party libfdt
> >> >> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> >> >> and refer to LibcLib implementation by Pedro.
> >> >>
> >> >> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> >> >> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> >> >> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> >> >> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> >> >> Signed-off-by: Benny Lin <benny.lin@intel.com>
> >> >> ---
> >> >>  MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
> >> >>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> >> >> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> >> >>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
> >> >>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> >> >> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
> >> >>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> >> >>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> >> >>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> >> >>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> >> >>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> >> >>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
> >> >>  MdePkg/MdePkg.ci.yaml                     |  17 +-
> >> >>  MdePkg/MdePkg.dec                         |   4 +
> >> >>  MdePkg/MdePkg.dsc                         |   1 +
> >> >>  15 files changed, 1043 insertions(+), 2 deletions(-)
> >> >>
> >> >> diff --git a/MdePkg/Include/Library/FdtLib.h
> >> >> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
> >> >> 0000000000..d59b749c25
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Include/Library/FdtLib.h
> >> >> @@ -0,0 +1,314 @@
> >> >> +/** @file
> >> >>
> >> >> +  Flattened Device Tree Library.
> >> >>
> >> >> +
> >> >>
> >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#ifndef FDT_LIB_H_
> >> >>
> >> >> +#define FDT_LIB_H_
> >> >>
> >> >> +
> >> >>
> >> >> +///
> >> >>
> >> >> +/// Flattened Device Tree definition
> >> >>
> >> >> +///
> >> >>
> >> >> +typedef struct {
> >> >>
> >> >> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> >> >>
> >> >> +  UINT32    TotalSize;           /* total size of DT block */
> >> >>
> >> >> +  UINT32    OffsetDtStruct;      /* offset to structure */
> >> >>
> >> >> +  UINT32    OffsetDtStrings;     /* offset to strings */
> >> >>
> >> >> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map */
> >> >>
> >> >> +  UINT32    Version;             /* format version */
> >> >>
> >> >> +  UINT32    LastCompVersion;     /* last compatible version */
> >> >>
> >> >> +
> >> >>
> >> >> +  /* version 2 fields below */
> >> >>
> >> >> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
> >> >>
> >> >> +                                    booting on */
> >> >>
> >> >> +  /* version 3 fields below */
> >> >>
> >> >> +  UINT32    SizeDtStrings;       /* size of the strings block */
> >> >>
> >> >> +
> >> >>
> >> >> +  /* version 17 fields below */
> >> >>
> >> >> +  UINT32    SizeDtStruct;        /* size of the structure block */
> >> >>
> >> >> +} FDT_HEADER;
> >> >
> >> >I see the macros below use SwapBytes32() on all the fields from this
> >> >structure.  Does this mean this structure is big >endian?  If
> >> that is the case, then the description of this structure and all
> >> individual fields must make that very clear >so any consumer of the
> >> structure knows it does not follow the default endianness of UEFI/PI and that consumers >must either use the macros or consumers
> must use SwapBytes32() on their own when using this structure directly.
> >>
> >> Yes, it's big endian. I will complete more descriptions in patch v4.
> >
> >Would it be simpler if we have a lib service that converts the entire header from big endian to little endian.
> >That way, the consumer can use the FDT_HEADER directly without any of the macros?
> >
> >Also, is the rest of the FDT blob also big endian?
> 
> FDT blob format is binary encoding of FDT data with big endian. In addition, the consumer will set or get FDT data with FDT blob. We
> can complete more descriptions to warn consumers to be careful if just use header struct for mapping and get/set FDT data with FDT
> blob.
> 
> For provide lib services that converts between big endian and little endian, we can provide a get header function to convert between
> big endian and little endian. However, we also need to consider the property value for setting and getting then we can convert in
> wrapper functions.
> 
> For example,
> 
> INT32
> EFIAPI
> FdtSetProp (
>   IN VOID         *Fdt,
>   IN INT32        NodeOffset,
>   IN CONST CHAR8  *Name,
>   IN CONST VOID   *Value,
>   IN UINT32       Length
>   )
> {
>   return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> }
> 
> More functions for various byte width.
> INT32
> EFIAPI
> FdtSetProp16 (
>   IN VOID         *Fdt,
>   IN INT32        NodeOffset,
>   IN CONST CHAR8  *Name,
>   IN CONST UINT16   *Value,
>   IN UINT32       Length
>   )
> {
>   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value), (int)Length);
> }
> 
> INT32
> EFIAPI
> FdtSetProp32 (
>   IN VOID         *Fdt,
>   IN INT32        NodeOffset,
>   IN CONST CHAR8  *Name,
>   IN CONST UINT32   *Value,
>   IN UINT32       Length
>   )
> {
>   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value), (int)Length);
> }
> 
> >>
> >> >>
> >> >> +
> >> >>
> >> >> +typedef struct {
> >> >>
> >> >> +  UINT64    Address;
> >> >>
> >> >> +  UINT64    Size;
> >> >>
> >> >> +} FDT_RESERVE_ENTRY;
> >> >
> >> >
> >> >I do not see this type used anywhere in the lib class or the lib instance.
> >> >Can it be removed?
> >>
> >> I think we can remove it because it might be not used for further usage of FDT support.
> >>
> >> >
> >> >>
> >> >> +
> >> >>
> >> >> +typedef struct {
> >> >>
> >> >> +  UINT32    Tag;
> >> >>
> >> >> +  CHAR8     Name[];
> >> >>
> >> >> +} FDT_NODE_HEADER;
> >> >
> >> >
> >> >I do not see this type used anywhere in the lib class or the lib instance.
> >> >Can it be removed?
> >>
> >> When we need retrieve a node from a FDT blob, we will get a node
> >> offset then we could use the struct to map the node content. It's very useful.
> >
> >Please add a comment header for this structure and describe the usage as it related to the rest of the FdtLib >services.
> 
> I will add descriptions for the usage and remove FDT_RESERVE_ENTRY in patch v4.
> 
> >
> >>
> >> >
> >> >>
> >> >> +
> >> >>
> >> >> +typedef struct {
> >> >>
> >> >> +  UINT32    Tag;
> >> >>
> >> >> +  UINT32    Length;
> >> >>
> >> >> +  UINT32    NameOffset;
> >> >>
> >> >> +  CHAR8     Data[];
> >> >>
> >> >> +} FDT_PROPERTY;
> >> >>
> >> >> +
> >> >>
> >> >> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST FDT_HEADER
> >> >> +*)(Fdt))->Field)
> >> >>
> >> >> +
> >> >>
> >> >> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
> >> >>
> >> >> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt, TotalSize))
> >> >>
> >> >> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt, OffsetDtStruct))
> >> >>
> >> >> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
> >> >> +OffsetDtStrings))
> >> >>
> >> >> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
> >> >> +OffsetMemRsvmap))
> >> >>
> >> >> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
> >> >>
> >> >> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
> >> >> +LastCompVersion))
> >> >>
> >> >> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt, BootCpuidPhys))
> >> >>
> >> >> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt, SizeDtStrings))
> >> >>
> >> >> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt, SizeDtStruct))
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Verify the header of the Flattened Device Tree
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return Zero for successfully, otherwise failed.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtCheckHeader (
> >> >>
> >> >> +  IN CONST VOID  *Fdt
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Create a empty Flattened Device Tree.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> >> >>
> >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return Zero for successfully, otherwise failed.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +RETURN_STATUS
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtCreateEmptyTree (
> >> >>
> >> >> +  IN VOID   *Buffer,
> >> >>
> >> >> +  IN UINTN  BufferSize
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of next node from the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to previous node.
> >> >>
> >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to next node offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtNextNode (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset,
> >> >>
> >> >> +  IN INT32       *Depth
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of first node under the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to previous node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to next node offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtFirstSubnode (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of next node from the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to previous node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to next node offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtNextSubnode (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of first node which includes the given name.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt             The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] ParentOffset    The offset to the node which start find under.
> >> >>
> >> >> +  @param[in] Name            The name to search the node with the name.
> >> >>
> >> >> +  @param[in] NameLength      The length of the name to check only.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to node offset with given node name.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtSubnodeOffsetNameLen (
> >> >>
> >> >> +  IN CONST VOID   *Fdt,
> >> >>
> >> >> +  IN INT32        ParentOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *Name,
> >> >>
> >> >> +  IN INT32        NameLength
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of first node which includes the given property name and value.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt             The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> >> >>
> >> >> +  @param[in] PropertyName    The property name to search the node including the named property.
> >> >>
> >> >> +  @param[in] PropertyValue   The property value to check the same property value.
> >> >>
> >> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to node offset with given property.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtNodeOffsetByPropValue (
> >> >>
> >> >> +  IN CONST VOID   *Fdt,
> >> >>
> >> >> +  IN INT32        StartOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *PropertyName,
> >> >>
> >> >> +  IN CONST VOID   *PropertyValue,
> >> >>
> >> >> +  IN INT32        PropertyLength
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a property with the given name from the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] NodeOffset     The offset to the given node.
> >> >>
> >> >> +  @param[in] Name           The name to the property which need be searched
> >> >>
> >> >> +  @param[in] Length         The length to the size of the property found.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The property to the structure of the found property.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +CONST FDT_PROPERTY *
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtGetProperty (
> >> >>
> >> >> +  IN CONST VOID   *Fdt,
> >> >>
> >> >> +  IN INT32        NodeOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *Name,
> >> >>
> >> >> +  IN INT32        *Length
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of first property in the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to the node which need be searched.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to first property offset in the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtFirstPropertyOffset (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       NodeOffset
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of next property from the given property.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to previous property.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to next property offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtNextPropertyOffset (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a property from the given offset of the property.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to the given offset of the property.
> >> >>
> >> >> +  @param[in] Length         The length to the size of the property found.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The property to the structure of the given property offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +CONST FDT_PROPERTY *
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtGetPropertyByOffset (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset,
> >> >>
> >> >> +  IN INT32       *Length
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a string by the given string offset.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> >> >>
> >> >> +  @param[in] Length         The length to the size of string which need be retrieved.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The string to the given string offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +CONST CHAR8 *
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtGetString (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       StrOffset,
> >> >>
> >> >> +  IN INT32       *Length        OPTIONAL
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Add a new node to the FDT.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> >> >>
> >> >> +  @param[in] Name           The name to name the node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return  The offset to the new node.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtAddSubnode (
> >> >>
> >> >> +  IN VOID         *Fdt,
> >> >>
> >> >> +  IN INT32        ParentOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *Name
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Add or modify a property in the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> >> >>
> >> >> +  @param[in] Name           The name to name the property.
> >> >>
> >> >> +  @param[in] Value          The value to the property value.
> >> >>
> >> >> +  @param[in] Length         The length to the size of the property.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return  Zero for successfully, otherwise failed.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtSetProp (
> >> >>
> >> >> +  IN VOID         *Fdt,
> >> >>
> >> >> +  IN INT32        NodeOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *Name,
> >> >>
> >> >> +  IN CONST VOID   *Value,
> >> >>
> >> >> +  IN UINT32       Length
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +#endif /* FDT_LIB_H_ */
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >> >> new file mode 100644
> >> >> index 0000000000..730e568ff6
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >> >> @@ -0,0 +1,62 @@
> >> >> +## @file
> >> >>
> >> >> +# Flattened Device Tree Library.
> >> >>
> >> >> +#
> >> >>
> >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +#
> >> >>
> >> >> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +#
> >> >>
> >> >> +#
> >> >>
> >> >> +##
> >> >>
> >> >> +
> >> >>
> >> >> +[Defines]
> >> >>
> >> >> +  INF_VERSION                    = 0x0001001B
> >> >>
> >> >> +  BASE_NAME                      = BaseFdtLib
> >> >>
> >> >> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> >> >>
> >> >> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-E8CEC206DE04
> >> >>
> >> >> +  MODULE_TYPE                    = BASE
> >> >>
> >> >> +  VERSION_STRING                 = 1.0
> >> >>
> >> >> +  LIBRARY_CLASS                  = FdtLib
> >> >>
> >> >> +
> >> >>
> >> >> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> >> >>
> >> >> +
> >> >>
> >> >> +#
> >> >>
> >> >> +#  VALID_ARCHITECTURES           = IA32 X64
> >> >>
> >> >> +#
> >> >>
> >> >> +
> >> >>
> >> >> +[Sources]
> >> >>
> >> >> +  FdtLib.c
> >> >>
> >> >> +  LibFdtWrapper.c
> >> >>
> >> >> +  # header Wrapper files
> >> >>
> >> >> +  limits.h
> >> >>
> >> >> +  stdbool.h
> >> >>
> >> >> +  stddef.h
> >> >>
> >> >> +  stdint.h
> >> >>
> >> >> +  stdlib.h
> >> >>
> >> >> +  string.h
> >> >>
> >> >> +
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt.h
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt_addresses.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt_check.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt_overlay.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt_ro.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt_rw.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt_strerror.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt_sw.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/fdt_wip.c
> >> >>
> >> >> +  $(FDT_LIB_PATH)/libfdt.h
> >> >>
> >> >> +  $(FDT_LIB_PATH)/libfdt_env.h
> >> >>
> >> >> +  $(FDT_LIB_PATH)/libfdt_internal.h
> >> >>
> >> >> +
> >> >>
> >> >> +[Packages]
> >> >>
> >> >> +  MdePkg/MdePkg.dec
> >> >>
> >> >> +
> >> >>
> >> >> +[LibraryClasses]
> >> >>
> >> >> +  BaseLib
> >> >>
> >> >> +  BaseMemoryLib
> >> >>
> >> >> +
> >> >>
> >> >> +[BuildOptions]
> >> >>
> >> >> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> >> >>
> >> >> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
> >> >>
> >> >> +
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> >> >> new file mode 100644
> >> >> index 0000000000..3f7e45ea6f
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> >> >> @@ -0,0 +1,14 @@
> >> >> +// /** @file
> >> >>
> >> >> +// Flattened Device Tree Library.
> >> >>
> >> >> +//
> >> >>
> >> >> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +//
> >> >>
> >> >> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +//
> >> >>
> >> >> +// **/
> >> >>
> >> >> +
> >> >>
> >> >> +
> >> >>
> >> >> +#string STR_MODULE_ABSTRACT             #language en-US "Instance of FDT Library"
> >> >>
> >> >> +
> >> >>
> >> >> +#string STR_MODULE_DESCRIPTION          #language en-US "This module provides FDT Library implementation."
> >> >>
> >> >> +
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> >> >> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> >> >> new file mode 100644
> >> >> index 0000000000..200a496c7e
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> >> >> @@ -0,0 +1,301 @@
> >> >> +/** @file
> >> >>
> >> >> +  Flattened Device Tree Library.
> >> >>
> >> >> +
> >> >>
> >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#include <libfdt/libfdt/libfdt.h>
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Verify the header of the Flattened Device Tree
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return Zero for successfully, otherwise failed.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtCheckHeader (
> >> >>
> >> >> +  IN CONST VOID  *Fdt
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_check_header(Fdt);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Create a empty Flattened Device Tree.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> >> >>
> >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return Zero for successfully, otherwise failed.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtCreateEmptyTree (
> >> >>
> >> >> +  IN VOID    *Buffer,
> >> >>
> >> >> +  IN UINT32  BufferSize
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of next node from the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to previous node.
> >> >>
> >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to next node offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtNextNode (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset,
> >> >>
> >> >> +  IN INT32       *Depth
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_next_node (Fdt, Offset, Depth);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of first node under the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to previous node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to next node offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtFirstSubnode (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_first_subnode (Fdt, Offset);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of next node from the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to previous node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to next node offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtNextSubnode (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_next_subnode (Fdt, Offset);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of first node which includes the given name.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt             The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] ParentOffset    The offset to the node which start find under.
> >> >>
> >> >> +  @param[in] Name            The name to search the node with the name.
> >> >>
> >> >> +  @param[in] NameLength      The length of the name to check only.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to node offset with given node name.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtSubnodeOffsetNameLen (
> >> >>
> >> >> +  IN CONST VOID   *Fdt,
> >> >>
> >> >> +  IN INT32        ParentOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *Name,
> >> >>
> >> >> +  IN INT32        NameLength
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name,
> >> >> + NameLength);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of first node which includes the given property name and value.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt             The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> >> >>
> >> >> +  @param[in] PropertyName    The property name to search the node including the named property.
> >> >>
> >> >> +  @param[in] PropertyValue   The property value to check the same property value.
> >> >>
> >> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to node offset with given property.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtNodeOffsetByPropValue (
> >> >>
> >> >> +  IN CONST VOID   *Fdt,
> >> >>
> >> >> +  IN INT32        StartOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *PropertyName,
> >> >>
> >> >> +  IN CONST VOID   *PropertyValue,
> >> >>
> >> >> +  IN INT32        PropertyLength
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> >> >> + PropertyName, PropertyValue, PropertyLength);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a property with the given name from the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] NodeOffset     The offset to the given node.
> >> >>
> >> >> +  @param[in] Name           The name to the property which need be searched
> >> >>
> >> >> +  @param[in] Length         The length to the size of the property found.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The property to the structure of the found property.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +CONST struct fdt_property *
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtGetProperty (
> >> >>
> >> >> +  IN CONST VOID   *Fdt,
> >> >>
> >> >> +  IN INT32        NodeOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *Name,
> >> >>
> >> >> +  IN INT32        *Length
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of first property in the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] NodeOffset     The offset to the node which need be searched.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to first property offset in the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtFirstPropertyOffset (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       NodeOffset
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_first_property_offset (Fdt, NodeOffset);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a offset of next property from the given property.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to previous property.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The offset to next property offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtNextPropertyOffset (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_next_property_offset (Fdt, Offset);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a property from the given offset of the property.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] Offset         The offset to the given offset of the property.
> >> >>
> >> >> +  @param[in] Length         The length to the size of the property found.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The property to the structure of the given property offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +CONST struct fdt_property *
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtGetPropertyByOffset (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       Offset,
> >> >>
> >> >> +  IN INT32       *Length
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Returns a string by the given string offset.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> >> >>
> >> >> +  @param[in] Length         The length to the size of string which need be retrieved.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return The string to the given string offset.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +CONST CHAR8 *
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtGetString (
> >> >>
> >> >> +  IN CONST VOID  *Fdt,
> >> >>
> >> >> +  IN INT32       StrOffset,
> >> >>
> >> >> +  IN INT32       *Length        OPTIONAL
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_get_string (Fdt, StrOffset, Length);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Add a new node to the FDT.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> >> >>
> >> >> +  @param[in] Name           The name to name the node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return  The offset to the new node.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtAddSubnode (
> >> >>
> >> >> +  IN VOID         *Fdt,
> >> >>
> >> >> +  IN INT32        ParentOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *Name
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +/**
> >> >>
> >> >> +  Add or modify a property in the given node.
> >> >>
> >> >> +
> >> >>
> >> >> +  @param[in] Fdt            The pointer to FDT blob.
> >> >>
> >> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> >> >>
> >> >> +  @param[in] Name           The name to name the property.
> >> >>
> >> >> +  @param[in] Value          The value to the property value.
> >> >>
> >> >> +  @param[in] Length         The length to the size of the property.
> >> >>
> >> >> +
> >> >>
> >> >> +  @return  Zero for successfully, otherwise failed.
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +INT32
> >> >>
> >> >> +EFIAPI
> >> >>
> >> >> +FdtSetProp (
> >> >>
> >> >> +  IN VOID         *Fdt,
> >> >>
> >> >> +  IN INT32        NodeOffset,
> >> >>
> >> >> +  IN CONST CHAR8  *Name,
> >> >>
> >> >> +  IN CONST VOID   *Value,
> >> >>
> >> >> +  IN UINT32       Length
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> >> >>
> >> >> +}
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> >> >> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> >> >> new file mode 100644
> >> >> index 0000000000..e738f4ded4
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> >> >> @@ -0,0 +1,99 @@
> >> >> +/** @file
> >> >>
> >> >> +  Root include file of C runtime library to support building the
> >> >> + third-party
> >> >>
> >> >> +  libfdt library.
> >> >>
> >> >> +
> >> >>
> >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#ifndef FDT_LIB_SUPPORT_H_
> >> >>
> >> >> +#define FDT_LIB_SUPPORT_H_
> >> >>
> >> >> +
> >> >>
> >> >> +#include <Base.h>
> >> >>
> >> >> +#include <Library/BaseLib.h>
> >> >>
> >> >> +#include <Library/BaseMemoryLib.h>
> >> >>
> >> >> +
> >> >>
> >> >> +typedef UINT8    uint8_t;
> >> >>
> >> >> +typedef UINT16   uint16_t;
> >> >>
> >> >> +typedef INT32    int32_t;
> >> >>
> >> >> +typedef UINT32   uint32_t;
> >> >>
> >> >> +typedef UINT64   uint64_t;
> >> >>
> >> >> +typedef UINTN    uintptr_t;
> >> >>
> >> >> +typedef UINTN    size_t;
> >> >>
> >> >> +typedef BOOLEAN  bool;
> >> >>
> >> >> +
> >> >>
> >> >> +#define true   (1 == 1)
> >> >>
> >> >> +#define false  (1 == 0)
> >> >>
> >> >> +
> >> >>
> >> >> +//
> >> >>
> >> >> +// Definitions for global constants used by libfdt library
> >> >> +routines
> >> >>
> >> >> +//
> >> >>
> >> >> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value */
> >> >>
> >> >> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32 value */
> >> >>
> >> >> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32 value */
> >> >>
> >> >> +
> >> >>
> >> >> +//
> >> >>
> >> >> +// Function prototypes of libfdt Library routines
> >> >>
> >> >> +//
> >> >>
> >> >> +void *
> >> >>
> >> >> +memset     (
> >> >>
> >> >> +  void *,
> >> >>
> >> >> +  int,
> >> >>
> >> >> +  size_t
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +int
> >> >>
> >> >> +memcmp      (
> >> >>
> >> >> +  const void *,
> >> >>
> >> >> +  const void *,
> >> >>
> >> >> +  size_t
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +int
> >> >>
> >> >> +strcmp      (
> >> >>
> >> >> +  const char *,
> >> >>
> >> >> +  const char *
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +char *
> >> >>
> >> >> +strchr     (
> >> >>
> >> >> +  const char *,
> >> >>
> >> >> +  int
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +char *
> >> >>
> >> >> +strrchr    (
> >> >>
> >> >> +  const char *,
> >> >>
> >> >> +  int
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +unsigned long
> >> >>
> >> >> +strtoul     (
> >> >>
> >> >> +  const char *,
> >> >>
> >> >> +  char **,
> >> >>
> >> >> +  int
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +char *
> >> >>
> >> >> +strcpy (
> >> >>
> >> >> +  char        *strDest,
> >> >>
> >> >> +  const char  *strSource
> >> >>
> >> >> +  );
> >> >>
> >> >> +
> >> >>
> >> >> +//
> >> >>
> >> >> +// Macros that directly map functions to BaseLib, BaseMemoryLib,
> >> >> +and DebugLib functions
> >> >>
> >> >> +//
> >> >>
> >> >> +#define memcpy(dest, source, count)         CopyMem(dest,source, (UINTN)(count))
> >> >>
> >> >> +#define memset(dest, ch, count)             SetMem(dest, (UINTN)(count),(UINT8)(ch))
> >> >>
> >> >> +#define memchr(buf, ch, count)              ScanMem8(buf, (UINTN)(count),(UINT8)ch)
> >> >>
> >> >> +#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1, buf2, (UINTN)(count)))
> >> >>
> >> >> +#define memmove(dest, source, count)        CopyMem(dest, source, (UINTN)(count))
> >> >>
> >> >> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> >> >>
> >> >> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
> >> >>
> >> >> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest,
> >> >> +MAX_STRING_SIZE, strSource, (UINTN)count)
> >> >>
> >> >> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest, MAX_STRING_SIZE, strSource)
> >> >>
> >> >> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1, string2))
> >> >>
> >> >> +#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1, string2, (UINTN)(count)))
> >> >>
> >> >> +
> >> >>
> >> >> +#endif /* FDT_LIB_SUPPORT_H_ */
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> >> >> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> >> >> new file mode 100644
> >> >> index 0000000000..772bba4839
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> >> >> @@ -0,0 +1,173 @@
> >> >> +/** @file
> >> >>
> >> >> +  ISO C implementations of strchr, strrchr and strtoul.
> >> >>
> >> >> +
> >> >>
> >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> >> >>
> >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#include <Base.h>
> >> >>
> >> >> +
> >> >>
> >> >> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long value */
> >> >>
> >> >> +
> >> >>
> >> >> +// Very quick notes:
> >> >>
> >> >> +// We only go through the string once for both functions
> >> >>
> >> >> +// They are minimal implementations (not speed optimized) of ISO C
> >> >> +semantics
> >> >>
> >> >> +// strchr and strrchr also include the null terminator as part of
> >> >> +the string
> >> >>
> >> >> +// so the code gets a bit clunky to handle that case specifically.
> >> >>
> >> >> +
> >> >>
> >> >> +char *
> >> >>
> >> >> +strchr (
> >> >>
> >> >> +  const char  *Str,
> >> >>
> >> >> +  int         Char
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  char  *S;
> >> >>
> >> >> +
> >> >>
> >> >> +  S = (char *)Str;
> >> >>
> >> >> +
> >> >>
> >> >> +  for ( ; ; S++) {
> >> >>
> >> >> +    if (*S == Char) {
> >> >>
> >> >> +      return S;
> >> >>
> >> >> +    }
> >> >>
> >> >> +
> >> >>
> >> >> +    if (*S == '\0') {
> >> >>
> >> >> +      return NULL;
> >> >>
> >> >> +    }
> >> >>
> >> >> +  }
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +char *
> >> >>
> >> >> +strrchr (
> >> >>
> >> >> +  const char  *Str,
> >> >>
> >> >> +  int         Char
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  char  *S, *last;
> >> >>
> >> >> +
> >> >>
> >> >> +  S    = (char *)Str;
> >> >>
> >> >> +  last = NULL;
> >> >>
> >> >> +
> >> >>
> >> >> +  for ( ; ; S++) {
> >> >>
> >> >> +    if (*S == Char) {
> >> >>
> >> >> +      last = S;
> >> >>
> >> >> +    }
> >> >>
> >> >> +
> >> >>
> >> >> +    if (*S == '\0') {
> >> >>
> >> >> +      return last;
> >> >>
> >> >> +    }
> >> >>
> >> >> +  }
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +STATIC
> >> >>
> >> >> +int
> >> >>
> >> >> +__isspace (
> >> >>
> >> >> +  int  ch
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  // basic ASCII ctype.h:isspace(). Not efficient
> >> >>
> >> >> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
> >> >> + == '\v' || ch == '\f';
> >> >>
> >> >> +}
> >> >>
> >> >> +
> >> >>
> >> >> +unsigned long
> >> >>
> >> >> +strtoul (
> >> >>
> >> >> +  const char  *Nptr,
> >> >>
> >> >> +  char        **EndPtr,
> >> >>
> >> >> +  int         Base
> >> >>
> >> >> +  )
> >> >>
> >> >> +{
> >> >>
> >> >> +  BOOLEAN        Negate;
> >> >>
> >> >> +  BOOLEAN        Overflow;
> >> >>
> >> >> +  unsigned long  Val;
> >> >>
> >> >> +
> >> >>
> >> >> +  Negate   = FALSE;
> >> >>
> >> >> +  Overflow = FALSE;
> >> >>
> >> >> +  Val      = 0;
> >> >>
> >> >> +
> >> >>
> >> >> +  // Reject bad numeric bases
> >> >>
> >> >> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> >> >>
> >> >> +    return 0;
> >> >>
> >> >> +  }
> >> >>
> >> >> +
> >> >>
> >> >> +  // Skip whitespace
> >> >>
> >> >> +  while (__isspace (*Nptr)) {
> >> >>
> >> >> +    Nptr++;
> >> >>
> >> >> +  }
> >> >>
> >> >> +
> >> >>
> >> >> +  // Check for + or - prefixes
> >> >>
> >> >> +  if (*Nptr == '-') {
> >> >>
> >> >> +    Negate = TRUE;
> >> >>
> >> >> +    Nptr++;
> >> >>
> >> >> +  } else if (*Nptr == '+') {
> >> >>
> >> >> +    Nptr++;
> >> >>
> >> >> +  }
> >> >>
> >> >> +
> >> >>
> >> >> +  // Consume the start, autodetecting base if needed
> >> >>
> >> >> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
> >> >> + && ((Base == 0) || (Base == 16))) {
> >> >>
> >> >> +    // Hex
> >> >>
> >> >> +    Nptr += 2;
> >> >>
> >> >> +    Base  = 16;
> >> >>
> >> >> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> >> >> + 'B')) && ((Base == 0) || (Base == 2))) {
> >> >>
> >> >> +    // Binary (standard pending C23)
> >> >>
> >> >> +    Nptr += 2;
> >> >>
> >> >> +    Base  = 2;
> >> >>
> >> >> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> >> >>
> >> >> +    // Octal
> >> >>
> >> >> +    Nptr++;
> >> >>
> >> >> +    Base = 8;
> >> >>
> >> >> +  } else {
> >> >>
> >> >> +    if (Base == 0) {
> >> >>
> >> >> +      // Assume decimal
> >> >>
> >> >> +      Base = 10;
> >> >>
> >> >> +    }
> >> >>
> >> >> +  }
> >> >>
> >> >> +
> >> >>
> >> >> +  while (TRUE) {
> >> >>
> >> >> +    int            Digit;
> >> >>
> >> >> +    char           C;
> >> >>
> >> >> +    unsigned long  NewVal;
> >> >>
> >> >> +
> >> >>
> >> >> +    C     = *Nptr;
> >> >>
> >> >> +    Digit = -1;
> >> >>
> >> >> +
> >> >>
> >> >> +    if ((C >= '0') && (C <= '9')) {
> >> >>
> >> >> +      Digit = C - '0';
> >> >>
> >> >> +    } else if ((C >= 'a') && (C <= 'z')) {
> >> >>
> >> >> +      Digit = C - 'a' + 10;
> >> >>
> >> >> +    } else if ((C >= 'A') && (C <= 'Z')) {
> >> >>
> >> >> +      Digit = C - 'A' + 10;
> >> >>
> >> >> +    }
> >> >>
> >> >> +
> >> >>
> >> >> +    if ((Digit == -1) || (Digit >= Base)) {
> >> >>
> >> >> +      // Note that this case also handles the \0
> >> >>
> >> >> +      if (EndPtr) {
> >> >>
> >> >> +        *EndPtr = (char *)Nptr;
> >> >>
> >> >> +      }
> >> >>
> >> >> +
> >> >>
> >> >> +      break;
> >> >>
> >> >> +    }
> >> >>
> >> >> +
> >> >>
> >> >> +    NewVal = Val * Base + Digit;
> >> >>
> >> >> +
> >> >>
> >> >> +    if (NewVal < Val) {
> >> >>
> >> >> +      // Overflow
> >> >>
> >> >> +      Overflow = TRUE;
> >> >>
> >> >> +    }
> >> >>
> >> >> +
> >> >>
> >> >> +    Val = NewVal;
> >> >>
> >> >> +
> >> >>
> >> >> +    Nptr++;
> >> >>
> >> >> +  }
> >> >>
> >> >> +
> >> >>
> >> >> +  if (Negate) {
> >> >>
> >> >> +    Val = -Val;
> >> >>
> >> >> +  }
> >> >>
> >> >> +
> >> >>
> >> >> +  if (Overflow) {
> >> >>
> >> >> +    Val = ULONG_MAX;
> >> >>
> >> >> +  }
> >> >>
> >> >> +
> >> >>
> >> >> +  // TODO: We're lacking errno here.
> >> >>
> >> >> +  return Val;
> >> >>
> >> >> +}
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> >> >> b/MdePkg/Library/BaseFdtLib/limits.h
> >> >> new file mode 100644
> >> >> index 0000000000..f6cf8d5702
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> >> >> @@ -0,0 +1,10 @@
> >> >> +/** @file
> >> >>
> >> >> +  Include file to support building the third-party libfdt library.
> >> >>
> >> >> +
> >> >>
> >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#include <LibFdtSupport.h>
> >> >>
> >> >> +
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> >> >> b/MdePkg/Library/BaseFdtLib/stdbool.h
> >> >> new file mode 100644
> >> >> index 0000000000..f6cf8d5702
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> >> >> @@ -0,0 +1,10 @@
> >> >> +/** @file
> >> >>
> >> >> +  Include file to support building the third-party libfdt library.
> >> >>
> >> >> +
> >> >>
> >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#include <LibFdtSupport.h>
> >> >>
> >> >> +
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> >> >> b/MdePkg/Library/BaseFdtLib/stddef.h
> >> >> new file mode 100644
> >> >> index 0000000000..f6cf8d5702
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> >> >> @@ -0,0 +1,10 @@
> >> >> +/** @file
> >> >>
> >> >> +  Include file to support building the third-party libfdt library.
> >> >>
> >> >> +
> >> >>
> >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#include <LibFdtSupport.h>
> >> >>
> >> >> +
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> >> >> b/MdePkg/Library/BaseFdtLib/stdint.h
> >> >> new file mode 100644
> >> >> index 0000000000..f6cf8d5702
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> >> >> @@ -0,0 +1,10 @@
> >> >> +/** @file
> >> >>
> >> >> +  Include file to support building the third-party libfdt library.
> >> >>
> >> >> +
> >> >>
> >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#include <LibFdtSupport.h>
> >> >>
> >> >> +
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> >> >> b/MdePkg/Library/BaseFdtLib/stdlib.h
> >> >> new file mode 100644
> >> >> index 0000000000..f6cf8d5702
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> >> >> @@ -0,0 +1,10 @@
> >> >> +/** @file
> >> >>
> >> >> +  Include file to support building the third-party libfdt library.
> >> >>
> >> >> +
> >> >>
> >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#include <LibFdtSupport.h>
> >> >>
> >> >> +
> >> >>
> >> >> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> >> >> b/MdePkg/Library/BaseFdtLib/string.h
> >> >> new file mode 100644
> >> >> index 0000000000..f6cf8d5702
> >> >> --- /dev/null
> >> >> +++ b/MdePkg/Library/BaseFdtLib/string.h
> >> >> @@ -0,0 +1,10 @@
> >> >> +/** @file
> >> >>
> >> >> +  Include file to support building the third-party libfdt library.
> >> >>
> >> >> +
> >> >>
> >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> +
> >> >>
> >> >> +**/
> >> >>
> >> >> +
> >> >>
> >> >> +#include <LibFdtSupport.h>
> >> >>
> >> >> +
> >> >>
> >> >> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index
> >> >> 6ba85ebe61..f039daccdb 100644
> >> >> --- a/MdePkg/MdePkg.ci.yaml
> >> >> +++ b/MdePkg/MdePkg.ci.yaml
> >> >> @@ -2,7 +2,7 @@
> >> >>  # CI configuration for MdePkg
> >> >>
> >> >>  #
> >> >>
> >> >>  # Copyright (c) Microsoft Corporation
> >> >>
> >> >> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >> >>
> >> >>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> >> >>
> >> >>  # Copyright (c) 2023, Loongson Technology Corporation Limited. All
> >> >> rights reserved.<BR>
> >> >>
> >> >>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> >> >>
> >> >> @@ -67,7 +67,8 @@
> >> >>              "Include/Library/PcdLib.h",
> >> >>
> >> >>              "Include/Library/SafeIntLib.h",
> >> >>
> >> >>              "Include/Protocol/DebugSupport.h",
> >> >>
> >> >> -            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> >> >>
> >> >> +
> >> >> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> >> >>
> >> >> +            "Library/BaseFdtLib"
> >> >>
> >> >>          ]
> >> >>
> >> >>      },
> >> >>
> >> >>      ## options defined ci/Plugin/CompilerPlugin
> >> >>
> >> >> @@ -164,5 +165,17 @@
> >> >>          "ExtendWords": [],           # words to extend to the dictionary for this package
> >> >>
> >> >>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
> >> >>
> >> >>          "AdditionalIncludePaths": [] # Additional paths to spell
> >> >> check (wildcards supported)
> >> >>
> >> >> +    },
> >> >>
> >> >> +    # options defined in .pytool/Plugin/UncrustifyCheck
> >> >>
> >> >> +    "UncrustifyCheck": {
> >> >>
> >> >> +        "IgnoreFiles": [
> >> >>
> >> >> +            "Library/BaseFdtLib/libfdt",
> >> >>
> >> >> +            "Library/BaseFdtLib/limits.h",
> >> >>
> >> >> +            "Library/BaseFdtLib/stdbool.h",
> >> >>
> >> >> +            "Library/BaseFdtLib/stddef.h",
> >> >>
> >> >> +            "Library/BaseFdtLib/stdint.h",
> >> >>
> >> >> +            "Library/BaseFdtLib/stdlib.h",
> >> >>
> >> >> +            "Library/BaseFdtLib/string.h"
> >> >>
> >> >> +        ]
> >> >>
> >> >>      }
> >> >>
> >> >>  }
> >> >>
> >> >> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> >> >> e70182bf7f..9804a7a6bd 100644
> >> >> --- a/MdePkg/MdePkg.dec
> >> >> +++ b/MdePkg/MdePkg.dec
> >> >> @@ -289,6 +289,10 @@
> >> >>    #
> >> >>
> >> >>    ArmTrngLib|Include/Library/ArmTrngLib.h
> >> >>
> >> >>
> >> >>
> >> >> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> >> >>
> >> >> +  #
> >> >>
> >> >> +  FdtLib|Include/Library/FdtLib.h
> >> >>
> >> >> +
> >> >>
> >> >>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> >> >>
> >> >>    ##  @libraryclass  Provides services to generate random number.
> >> >>
> >> >>    #
> >> >>
> >> >> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> >> >> 152c02991a..b38c863812 100644
> >> >> --- a/MdePkg/MdePkg.dsc
> >> >> +++ b/MdePkg/MdePkg.dsc
> >> >> @@ -137,6 +137,7 @@
> >> >>
> >> >> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> >> >>
> >> >>
> >> >>
> >> >>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> >> >>
> >> >> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >> >>
> >> >>
> >> >>
> >> >>  [Components.IA32, Components.X64, Components.ARM,
> >> >> Components.AARCH64]
> >> >>
> >> >>    #
> >> >>
> >> >> --
> >> >> 2.39.1.windows.1
> >
> >

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-20 16:44           ` Michael D Kinney
@ 2023-04-21  2:33             ` Chiu, Chasel
  2023-04-24 17:28             ` Leif Lindholm
  1 sibling, 0 replies; 20+ messages in thread
From: Chiu, Chasel @ 2023-04-21  2:33 UTC (permalink / raw)
  To: devel@edk2.groups.io, Kinney, Michael D, Lin, Benny,
	Leif Lindholm
  Cc: Gao, Liming, Liu, Zhiguang, Pedro Falcato


Hi Mike,

Thanks for bringing this good point!
We would like to document that all FDT structure data are in *big endian* format and remove those SwapBytes MACROs from FdtLib.h
It makes sense to handle this from library consumer side (consumer can define their own MACROs) because we cannot assume consumer usage always requires SwapBytes.

We will send V4 patch to update this.

Thanks,
Chasel



> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Michael D
> Kinney
> Sent: Thursday, April 20, 2023 9:44 AM
> To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io; Leif Lindholm
> <llindhol@qti.qualcomm.com>
> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>
> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> Hi Leif,
> 
> What is your opinion on FDT being big endian.
> 
> Do we want the lib to help with that aspect, or leave it up to the consumer of
> the lib to
> convert as needed?  Seems like an area that could be very error prone if we are
> not
> careful.
> 
> Mike
> 
> > -----Original Message-----
> > From: Lin, Benny <benny.lin@intel.com>
> > Sent: Wednesday, April 19, 2023 9:25 PM
> > To: Kinney, Michael D <michael.d.kinney@intel.com>; devel@edk2.groups.io
> > Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> >
> >
> >
> > >-----Original Message-----
> > >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > >Sent: Thursday, April 20, 2023 5:04 AM
> > >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>; Kinney,
> > Michael D <michael.d.kinney@intel.com>
> > >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >
> > >Responses below
> > >
> > >Mike
> > >
> > >> -----Original Message-----
> > >> From: Lin, Benny <benny.lin@intel.com>
> > >> Sent: Wednesday, April 19, 2023 10:12 AM
> > >> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > >> devel@edk2.groups.io
> > >> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > >> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > >> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >>
> > >> Please find my feedback below.
> > >> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER, what
> do you think?
> > >>
> > >> QQQ
> > >> Benny
> > >>
> > >> >-----Original Message-----
> > >> >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > >> >Sent: Wednesday, April 19, 2023 11:54 PM
> > >> >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > >> >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > >> ><zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>;
> > >> >Kinney,
> > >> Michael D <michael.d.kinney@intel.com>
> > >> >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >> >
> > >> >A few comments below.
> > >> >
> > >> >Mike
> > >> >
> > >> >> -----Original Message-----
> > >> >> From: Lin, Benny <benny.lin@intel.com>
> > >> >> Sent: Sunday, April 16, 2023 10:35 PM
> > >> >> To: devel@edk2.groups.io
> > >> >> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> > >> >> <michael.d.kinney@intel.com>; Gao, Liming
> > >> >> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> > >> >> Pedro Falcato <pedro.falcato@gmail.com>
> > >> >> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >> >>
> > >> >> From: Benny Lin <benny.lin@intel.com>
> > >> >>
> > >> >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> > >> >> Add FDT support in EDK2 by submodule 3rd party libfdt
> > >> >> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> > >> >> and refer to LibcLib implementation by Pedro.
> > >> >>
> > >> >> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > >> >> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > >> >> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > >> >> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> > >> >> Signed-off-by: Benny Lin <benny.lin@intel.com>
> > >> >> ---
> > >> >>  MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
> > >> >>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> > >> >> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> > >> >>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
> > >> >>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> > >> >> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
> > >> >>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
> > >> >>  MdePkg/MdePkg.ci.yaml                     |  17 +-
> > >> >>  MdePkg/MdePkg.dec                         |   4 +
> > >> >>  MdePkg/MdePkg.dsc                         |   1 +
> > >> >>  15 files changed, 1043 insertions(+), 2 deletions(-)
> > >> >>
> > >> >> diff --git a/MdePkg/Include/Library/FdtLib.h
> > >> >> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
> > >> >> 0000000000..d59b749c25
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Include/Library/FdtLib.h
> > >> >> @@ -0,0 +1,314 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Flattened Device Tree Library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#ifndef FDT_LIB_H_
> > >> >>
> > >> >> +#define FDT_LIB_H_
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +///
> > >> >>
> > >> >> +/// Flattened Device Tree definition
> > >> >>
> > >> >> +///
> > >> >>
> > >> >> +typedef struct {
> > >> >>
> > >> >> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> > >> >>
> > >> >> +  UINT32    TotalSize;           /* total size of DT block */
> > >> >>
> > >> >> +  UINT32    OffsetDtStruct;      /* offset to structure */
> > >> >>
> > >> >> +  UINT32    OffsetDtStrings;     /* offset to strings */
> > >> >>
> > >> >> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map */
> > >> >>
> > >> >> +  UINT32    Version;             /* format version */
> > >> >>
> > >> >> +  UINT32    LastCompVersion;     /* last compatible version */
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  /* version 2 fields below */
> > >> >>
> > >> >> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
> > >> >>
> > >> >> +                                    booting on */
> > >> >>
> > >> >> +  /* version 3 fields below */
> > >> >>
> > >> >> +  UINT32    SizeDtStrings;       /* size of the strings block */
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  /* version 17 fields below */
> > >> >>
> > >> >> +  UINT32    SizeDtStruct;        /* size of the structure block */
> > >> >>
> > >> >> +} FDT_HEADER;
> > >> >
> > >> >I see the macros below use SwapBytes32() on all the fields from this
> > >> >structure.  Does this mean this structure is big >endian?  If
> > >> that is the case, then the description of this structure and all
> > >> individual fields must make that very clear >so any consumer of the
> > >> structure knows it does not follow the default endianness of UEFI/PI and
> that consumers >must either use the macros or consumers
> > must use SwapBytes32() on their own when using this structure directly.
> > >>
> > >> Yes, it's big endian. I will complete more descriptions in patch v4.
> > >
> > >Would it be simpler if we have a lib service that converts the entire header
> from big endian to little endian.
> > >That way, the consumer can use the FDT_HEADER directly without any of the
> macros?
> > >
> > >Also, is the rest of the FDT blob also big endian?
> >
> > FDT blob format is binary encoding of FDT data with big endian. In addition,
> the consumer will set or get FDT data with FDT blob. We
> > can complete more descriptions to warn consumers to be careful if just use
> header struct for mapping and get/set FDT data with FDT
> > blob.
> >
> > For provide lib services that converts between big endian and little endian, we
> can provide a get header function to convert between
> > big endian and little endian. However, we also need to consider the property
> value for setting and getting then we can convert in
> > wrapper functions.
> >
> > For example,
> >
> > INT32
> > EFIAPI
> > FdtSetProp (
> >   IN VOID         *Fdt,
> >   IN INT32        NodeOffset,
> >   IN CONST CHAR8  *Name,
> >   IN CONST VOID   *Value,
> >   IN UINT32       Length
> >   )
> > {
> >   return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > }
> >
> > More functions for various byte width.
> > INT32
> > EFIAPI
> > FdtSetProp16 (
> >   IN VOID         *Fdt,
> >   IN INT32        NodeOffset,
> >   IN CONST CHAR8  *Name,
> >   IN CONST UINT16   *Value,
> >   IN UINT32       Length
> >   )
> > {
> >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value), (int)Length);
> > }
> >
> > INT32
> > EFIAPI
> > FdtSetProp32 (
> >   IN VOID         *Fdt,
> >   IN INT32        NodeOffset,
> >   IN CONST CHAR8  *Name,
> >   IN CONST UINT32   *Value,
> >   IN UINT32       Length
> >   )
> > {
> >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value), (int)Length);
> > }
> >
> > >>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +typedef struct {
> > >> >>
> > >> >> +  UINT64    Address;
> > >> >>
> > >> >> +  UINT64    Size;
> > >> >>
> > >> >> +} FDT_RESERVE_ENTRY;
> > >> >
> > >> >
> > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > >> >Can it be removed?
> > >>
> > >> I think we can remove it because it might be not used for further usage of
> FDT support.
> > >>
> > >> >
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +typedef struct {
> > >> >>
> > >> >> +  UINT32    Tag;
> > >> >>
> > >> >> +  CHAR8     Name[];
> > >> >>
> > >> >> +} FDT_NODE_HEADER;
> > >> >
> > >> >
> > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > >> >Can it be removed?
> > >>
> > >> When we need retrieve a node from a FDT blob, we will get a node
> > >> offset then we could use the struct to map the node content. It's very
> useful.
> > >
> > >Please add a comment header for this structure and describe the usage as it
> related to the rest of the FdtLib >services.
> >
> > I will add descriptions for the usage and remove FDT_RESERVE_ENTRY in patch
> v4.
> >
> > >
> > >>
> > >> >
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +typedef struct {
> > >> >>
> > >> >> +  UINT32    Tag;
> > >> >>
> > >> >> +  UINT32    Length;
> > >> >>
> > >> >> +  UINT32    NameOffset;
> > >> >>
> > >> >> +  CHAR8     Data[];
> > >> >>
> > >> >> +} FDT_PROPERTY;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST
> FDT_HEADER
> > >> >> +*)(Fdt))->Field)
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
> > >> >>
> > >> >> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt, TotalSize))
> > >> >>
> > >> >> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt,
> OffsetDtStruct))
> > >> >>
> > >> >> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
> > >> >> +OffsetDtStrings))
> > >> >>
> > >> >> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
> > >> >> +OffsetMemRsvmap))
> > >> >>
> > >> >> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
> > >> >>
> > >> >> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
> > >> >> +LastCompVersion))
> > >> >>
> > >> >> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt,
> BootCpuidPhys))
> > >> >>
> > >> >> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt,
> SizeDtStrings))
> > >> >>
> > >> >> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt,
> SizeDtStruct))
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Verify the header of the Flattened Device Tree
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtCheckHeader (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Create a empty Flattened Device Tree.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> > >> >>
> > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +RETURN_STATUS
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtCreateEmptyTree (
> > >> >>
> > >> >> +  IN VOID   *Buffer,
> > >> >>
> > >> >> +  IN UINTN  BufferSize
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next node from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextNode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset,
> > >> >>
> > >> >> +  IN INT32       *Depth
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node under the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtFirstSubnode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next node from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextSubnode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node which includes the given name.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] ParentOffset    The offset to the node which start find
> under.
> > >> >>
> > >> >> +  @param[in] Name            The name to search the node with the name.
> > >> >>
> > >> >> +  @param[in] NameLength      The length of the name to check only.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to node offset with given node name.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtSubnodeOffsetNameLen (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        ParentOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN INT32        NameLength
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node which includes the given property name
> and value.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > >> >>
> > >> >> +  @param[in] PropertyName    The property name to search the node
> including the named property.
> > >> >>
> > >> >> +  @param[in] PropertyValue   The property value to check the same
> property value.
> > >> >>
> > >> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to node offset with given property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNodeOffsetByPropValue (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        StartOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *PropertyName,
> > >> >>
> > >> >> +  IN CONST VOID   *PropertyValue,
> > >> >>
> > >> >> +  IN INT32        PropertyLength
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a property with the given name from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > >> >>
> > >> >> +  @param[in] Name           The name to the property which need be
> searched
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property found.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The property to the structure of the found property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST FDT_PROPERTY *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetProperty (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        NodeOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN INT32        *Length
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first property in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to the node which need be
> searched.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to first property offset in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtFirstPropertyOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       NodeOffset
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next property from the given property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next property offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextPropertyOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a property from the given offset of the property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to the given offset of the property.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property found.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The property to the structure of the given property offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST FDT_PROPERTY *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetPropertyByOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset,
> > >> >>
> > >> >> +  IN INT32       *Length
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a string by the given string offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] StrOffset      The offset to the location in the strings block
> of FDT.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of string which need be
> retrieved.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The string to the given string offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST CHAR8 *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetString (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       StrOffset,
> > >> >>
> > >> >> +  IN INT32       *Length        OPTIONAL
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Add a new node to the FDT.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] ParentOffset   The offset to the node offset which want
> to add in.
> > >> >>
> > >> >> +  @param[in] Name           The name to name the node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return  The offset to the new node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtAddSubnode (
> > >> >>
> > >> >> +  IN VOID         *Fdt,
> > >> >>
> > >> >> +  IN INT32        ParentOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Add or modify a property in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the node offset which want
> to add in.
> > >> >>
> > >> >> +  @param[in] Name           The name to name the property.
> > >> >>
> > >> >> +  @param[in] Value          The value to the property value.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return  Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtSetProp (
> > >> >>
> > >> >> +  IN VOID         *Fdt,
> > >> >>
> > >> >> +  IN INT32        NodeOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN CONST VOID   *Value,
> > >> >>
> > >> >> +  IN UINT32       Length
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#endif /* FDT_LIB_H_ */
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >> >> new file mode 100644
> > >> >> index 0000000000..730e568ff6
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >> >> @@ -0,0 +1,62 @@
> > >> >> +## @file
> > >> >>
> > >> >> +# Flattened Device Tree Library.
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +##
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[Defines]
> > >> >>
> > >> >> +  INF_VERSION                    = 0x0001001B
> > >> >>
> > >> >> +  BASE_NAME                      = BaseFdtLib
> > >> >>
> > >> >> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> > >> >>
> > >> >> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-E8CEC206DE04
> > >> >>
> > >> >> +  MODULE_TYPE                    = BASE
> > >> >>
> > >> >> +  VERSION_STRING                 = 1.0
> > >> >>
> > >> >> +  LIBRARY_CLASS                  = FdtLib
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +#  VALID_ARCHITECTURES           = IA32 X64
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[Sources]
> > >> >>
> > >> >> +  FdtLib.c
> > >> >>
> > >> >> +  LibFdtWrapper.c
> > >> >>
> > >> >> +  # header Wrapper files
> > >> >>
> > >> >> +  limits.h
> > >> >>
> > >> >> +  stdbool.h
> > >> >>
> > >> >> +  stddef.h
> > >> >>
> > >> >> +  stdint.h
> > >> >>
> > >> >> +  stdlib.h
> > >> >>
> > >> >> +  string.h
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt.h
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_addresses.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_check.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_overlay.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_ro.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_rw.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_strerror.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_sw.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_wip.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/libfdt.h
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/libfdt_env.h
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/libfdt_internal.h
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[Packages]
> > >> >>
> > >> >> +  MdePkg/MdePkg.dec
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[LibraryClasses]
> > >> >>
> > >> >> +  BaseLib
> > >> >>
> > >> >> +  BaseMemoryLib
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[BuildOptions]
> > >> >>
> > >> >> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> > >> >>
> > >> >> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > >> >> new file mode 100644
> > >> >> index 0000000000..3f7e45ea6f
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > >> >> @@ -0,0 +1,14 @@
> > >> >> +// /** @file
> > >> >>
> > >> >> +// Flattened Device Tree Library.
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// **/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#string STR_MODULE_ABSTRACT             #language en-US "Instance of
> FDT Library"
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#string STR_MODULE_DESCRIPTION          #language en-US "This
> module provides FDT Library implementation."
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> > >> >> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > >> >> new file mode 100644
> > >> >> index 0000000000..200a496c7e
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > >> >> @@ -0,0 +1,301 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Flattened Device Tree Library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <libfdt/libfdt/libfdt.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Verify the header of the Flattened Device Tree
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtCheckHeader (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_check_header(Fdt);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Create a empty Flattened Device Tree.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> > >> >>
> > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtCreateEmptyTree (
> > >> >>
> > >> >> +  IN VOID    *Buffer,
> > >> >>
> > >> >> +  IN UINT32  BufferSize
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next node from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextNode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset,
> > >> >>
> > >> >> +  IN INT32       *Depth
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_next_node (Fdt, Offset, Depth);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node under the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtFirstSubnode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_first_subnode (Fdt, Offset);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next node from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextSubnode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_next_subnode (Fdt, Offset);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node which includes the given name.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] ParentOffset    The offset to the node which start find
> under.
> > >> >>
> > >> >> +  @param[in] Name            The name to search the node with the name.
> > >> >>
> > >> >> +  @param[in] NameLength      The length of the name to check only.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to node offset with given node name.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtSubnodeOffsetNameLen (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        ParentOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN INT32        NameLength
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name,
> > >> >> + NameLength);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node which includes the given property name
> and value.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > >> >>
> > >> >> +  @param[in] PropertyName    The property name to search the node
> including the named property.
> > >> >>
> > >> >> +  @param[in] PropertyValue   The property value to check the same
> property value.
> > >> >>
> > >> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to node offset with given property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNodeOffsetByPropValue (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        StartOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *PropertyName,
> > >> >>
> > >> >> +  IN CONST VOID   *PropertyValue,
> > >> >>
> > >> >> +  IN INT32        PropertyLength
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> > >> >> + PropertyName, PropertyValue, PropertyLength);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a property with the given name from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > >> >>
> > >> >> +  @param[in] Name           The name to the property which need be
> searched
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property found.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The property to the structure of the found property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST struct fdt_property *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetProperty (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        NodeOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN INT32        *Length
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first property in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the node which need be
> searched.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to first property offset in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtFirstPropertyOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       NodeOffset
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_first_property_offset (Fdt, NodeOffset);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next property from the given property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next property offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextPropertyOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_next_property_offset (Fdt, Offset);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a property from the given offset of the property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to the given offset of the property.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property found.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The property to the structure of the given property offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST struct fdt_property *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetPropertyByOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset,
> > >> >>
> > >> >> +  IN INT32       *Length
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a string by the given string offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] StrOffset      The offset to the location in the strings block
> of FDT.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of string which need be
> retrieved.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The string to the given string offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST CHAR8 *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetString (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       StrOffset,
> > >> >>
> > >> >> +  IN INT32       *Length        OPTIONAL
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_get_string (Fdt, StrOffset, Length);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Add a new node to the FDT.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] ParentOffset   The offset to the node offset which want
> to add in.
> > >> >>
> > >> >> +  @param[in] Name           The name to name the node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return  The offset to the new node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtAddSubnode (
> > >> >>
> > >> >> +  IN VOID         *Fdt,
> > >> >>
> > >> >> +  IN INT32        ParentOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Add or modify a property in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the node offset which want
> to add in.
> > >> >>
> > >> >> +  @param[in] Name           The name to name the property.
> > >> >>
> > >> >> +  @param[in] Value          The value to the property value.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return  Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtSetProp (
> > >> >>
> > >> >> +  IN VOID         *Fdt,
> > >> >>
> > >> >> +  IN INT32        NodeOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN CONST VOID   *Value,
> > >> >>
> > >> >> +  IN UINT32       Length
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..e738f4ded4
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > >> >> @@ -0,0 +1,99 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Root include file of C runtime library to support building the
> > >> >> + third-party
> > >> >>
> > >> >> +  libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#ifndef FDT_LIB_SUPPORT_H_
> > >> >>
> > >> >> +#define FDT_LIB_SUPPORT_H_
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <Base.h>
> > >> >>
> > >> >> +#include <Library/BaseLib.h>
> > >> >>
> > >> >> +#include <Library/BaseMemoryLib.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +typedef UINT8    uint8_t;
> > >> >>
> > >> >> +typedef UINT16   uint16_t;
> > >> >>
> > >> >> +typedef INT32    int32_t;
> > >> >>
> > >> >> +typedef UINT32   uint32_t;
> > >> >>
> > >> >> +typedef UINT64   uint64_t;
> > >> >>
> > >> >> +typedef UINTN    uintptr_t;
> > >> >>
> > >> >> +typedef UINTN    size_t;
> > >> >>
> > >> >> +typedef BOOLEAN  bool;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#define true   (1 == 1)
> > >> >>
> > >> >> +#define false  (1 == 0)
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// Definitions for global constants used by libfdt library
> > >> >> +routines
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value */
> > >> >>
> > >> >> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32 value
> */
> > >> >>
> > >> >> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32
> value */
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// Function prototypes of libfdt Library routines
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +void *
> > >> >>
> > >> >> +memset     (
> > >> >>
> > >> >> +  void *,
> > >> >>
> > >> >> +  int,
> > >> >>
> > >> >> +  size_t
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +int
> > >> >>
> > >> >> +memcmp      (
> > >> >>
> > >> >> +  const void *,
> > >> >>
> > >> >> +  const void *,
> > >> >>
> > >> >> +  size_t
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +int
> > >> >>
> > >> >> +strcmp      (
> > >> >>
> > >> >> +  const char *,
> > >> >>
> > >> >> +  const char *
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strchr     (
> > >> >>
> > >> >> +  const char *,
> > >> >>
> > >> >> +  int
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strrchr    (
> > >> >>
> > >> >> +  const char *,
> > >> >>
> > >> >> +  int
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +unsigned long
> > >> >>
> > >> >> +strtoul     (
> > >> >>
> > >> >> +  const char *,
> > >> >>
> > >> >> +  char **,
> > >> >>
> > >> >> +  int
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strcpy (
> > >> >>
> > >> >> +  char        *strDest,
> > >> >>
> > >> >> +  const char  *strSource
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// Macros that directly map functions to BaseLib, BaseMemoryLib,
> > >> >> +and DebugLib functions
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +#define memcpy(dest, source, count)         CopyMem(dest,source,
> (UINTN)(count))
> > >> >>
> > >> >> +#define memset(dest, ch, count)             SetMem(dest,
> (UINTN)(count),(UINT8)(ch))
> > >> >>
> > >> >> +#define memchr(buf, ch, count)              ScanMem8(buf,
> (UINTN)(count),(UINT8)ch)
> > >> >>
> > >> >> +#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1,
> buf2, (UINTN)(count)))
> > >> >>
> > >> >> +#define memmove(dest, source, count)        CopyMem(dest, source,
> (UINTN)(count))
> > >> >>
> > >> >> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> > >> >>
> > >> >> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
> > >> >>
> > >> >> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest,
> > >> >> +MAX_STRING_SIZE, strSource, (UINTN)count)
> > >> >>
> > >> >> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest,
> MAX_STRING_SIZE, strSource)
> > >> >>
> > >> >> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1,
> string2))
> > >> >>
> > >> >> +#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1,
> string2, (UINTN)(count)))
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#endif /* FDT_LIB_SUPPORT_H_ */
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > >> >> new file mode 100644
> > >> >> index 0000000000..772bba4839
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > >> >> @@ -0,0 +1,173 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  ISO C implementations of strchr, strrchr and strtoul.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> > >> >>
> > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <Base.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long
> value */
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +// Very quick notes:
> > >> >>
> > >> >> +// We only go through the string once for both functions
> > >> >>
> > >> >> +// They are minimal implementations (not speed optimized) of ISO C
> > >> >> +semantics
> > >> >>
> > >> >> +// strchr and strrchr also include the null terminator as part of
> > >> >> +the string
> > >> >>
> > >> >> +// so the code gets a bit clunky to handle that case specifically.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strchr (
> > >> >>
> > >> >> +  const char  *Str,
> > >> >>
> > >> >> +  int         Char
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  char  *S;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  S = (char *)Str;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  for ( ; ; S++) {
> > >> >>
> > >> >> +    if (*S == Char) {
> > >> >>
> > >> >> +      return S;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if (*S == '\0') {
> > >> >>
> > >> >> +      return NULL;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strrchr (
> > >> >>
> > >> >> +  const char  *Str,
> > >> >>
> > >> >> +  int         Char
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  char  *S, *last;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  S    = (char *)Str;
> > >> >>
> > >> >> +  last = NULL;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  for ( ; ; S++) {
> > >> >>
> > >> >> +    if (*S == Char) {
> > >> >>
> > >> >> +      last = S;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if (*S == '\0') {
> > >> >>
> > >> >> +      return last;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +STATIC
> > >> >>
> > >> >> +int
> > >> >>
> > >> >> +__isspace (
> > >> >>
> > >> >> +  int  ch
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  // basic ASCII ctype.h:isspace(). Not efficient
> > >> >>
> > >> >> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
> > >> >> + == '\v' || ch == '\f';
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +unsigned long
> > >> >>
> > >> >> +strtoul (
> > >> >>
> > >> >> +  const char  *Nptr,
> > >> >>
> > >> >> +  char        **EndPtr,
> > >> >>
> > >> >> +  int         Base
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  BOOLEAN        Negate;
> > >> >>
> > >> >> +  BOOLEAN        Overflow;
> > >> >>
> > >> >> +  unsigned long  Val;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Negate   = FALSE;
> > >> >>
> > >> >> +  Overflow = FALSE;
> > >> >>
> > >> >> +  Val      = 0;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // Reject bad numeric bases
> > >> >>
> > >> >> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> > >> >>
> > >> >> +    return 0;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // Skip whitespace
> > >> >>
> > >> >> +  while (__isspace (*Nptr)) {
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // Check for + or - prefixes
> > >> >>
> > >> >> +  if (*Nptr == '-') {
> > >> >>
> > >> >> +    Negate = TRUE;
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +  } else if (*Nptr == '+') {
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // Consume the start, autodetecting base if needed
> > >> >>
> > >> >> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
> > >> >> + && ((Base == 0) || (Base == 16))) {
> > >> >>
> > >> >> +    // Hex
> > >> >>
> > >> >> +    Nptr += 2;
> > >> >>
> > >> >> +    Base  = 16;
> > >> >>
> > >> >> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> > >> >> + 'B')) && ((Base == 0) || (Base == 2))) {
> > >> >>
> > >> >> +    // Binary (standard pending C23)
> > >> >>
> > >> >> +    Nptr += 2;
> > >> >>
> > >> >> +    Base  = 2;
> > >> >>
> > >> >> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> > >> >>
> > >> >> +    // Octal
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +    Base = 8;
> > >> >>
> > >> >> +  } else {
> > >> >>
> > >> >> +    if (Base == 0) {
> > >> >>
> > >> >> +      // Assume decimal
> > >> >>
> > >> >> +      Base = 10;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  while (TRUE) {
> > >> >>
> > >> >> +    int            Digit;
> > >> >>
> > >> >> +    char           C;
> > >> >>
> > >> >> +    unsigned long  NewVal;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    C     = *Nptr;
> > >> >>
> > >> >> +    Digit = -1;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if ((C >= '0') && (C <= '9')) {
> > >> >>
> > >> >> +      Digit = C - '0';
> > >> >>
> > >> >> +    } else if ((C >= 'a') && (C <= 'z')) {
> > >> >>
> > >> >> +      Digit = C - 'a' + 10;
> > >> >>
> > >> >> +    } else if ((C >= 'A') && (C <= 'Z')) {
> > >> >>
> > >> >> +      Digit = C - 'A' + 10;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if ((Digit == -1) || (Digit >= Base)) {
> > >> >>
> > >> >> +      // Note that this case also handles the \0
> > >> >>
> > >> >> +      if (EndPtr) {
> > >> >>
> > >> >> +        *EndPtr = (char *)Nptr;
> > >> >>
> > >> >> +      }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +      break;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    NewVal = Val * Base + Digit;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if (NewVal < Val) {
> > >> >>
> > >> >> +      // Overflow
> > >> >>
> > >> >> +      Overflow = TRUE;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    Val = NewVal;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  if (Negate) {
> > >> >>
> > >> >> +    Val = -Val;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  if (Overflow) {
> > >> >>
> > >> >> +    Val = ULONG_MAX;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // TODO: We're lacking errno here.
> > >> >>
> > >> >> +  return Val;
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> > >> >> b/MdePkg/Library/BaseFdtLib/limits.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> > >> >> b/MdePkg/Library/BaseFdtLib/stdbool.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> > >> >> b/MdePkg/Library/BaseFdtLib/stddef.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> > >> >> b/MdePkg/Library/BaseFdtLib/stdint.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> > >> >> b/MdePkg/Library/BaseFdtLib/stdlib.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> > >> >> b/MdePkg/Library/BaseFdtLib/string.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/string.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index
> > >> >> 6ba85ebe61..f039daccdb 100644
> > >> >> --- a/MdePkg/MdePkg.ci.yaml
> > >> >> +++ b/MdePkg/MdePkg.ci.yaml
> > >> >> @@ -2,7 +2,7 @@
> > >> >>  # CI configuration for MdePkg
> > >> >>
> > >> >>  #
> > >> >>
> > >> >>  # Copyright (c) Microsoft Corporation
> > >> >>
> > >> >> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> > >> >>
> > >> >>  # Copyright (c) 2023, Loongson Technology Corporation Limited. All
> > >> >> rights reserved.<BR>
> > >> >>
> > >> >>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> @@ -67,7 +67,8 @@
> > >> >>              "Include/Library/PcdLib.h",
> > >> >>
> > >> >>              "Include/Library/SafeIntLib.h",
> > >> >>
> > >> >>              "Include/Protocol/DebugSupport.h",
> > >> >>
> > >> >> -            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> > >> >>
> > >> >> +
> > >> >> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> > >> >>
> > >> >> +            "Library/BaseFdtLib"
> > >> >>
> > >> >>          ]
> > >> >>
> > >> >>      },
> > >> >>
> > >> >>      ## options defined ci/Plugin/CompilerPlugin
> > >> >>
> > >> >> @@ -164,5 +165,17 @@
> > >> >>          "ExtendWords": [],           # words to extend to the dictionary for this
> package
> > >> >>
> > >> >>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that
> should be ignore
> > >> >>
> > >> >>          "AdditionalIncludePaths": [] # Additional paths to spell
> > >> >> check (wildcards supported)
> > >> >>
> > >> >> +    },
> > >> >>
> > >> >> +    # options defined in .pytool/Plugin/UncrustifyCheck
> > >> >>
> > >> >> +    "UncrustifyCheck": {
> > >> >>
> > >> >> +        "IgnoreFiles": [
> > >> >>
> > >> >> +            "Library/BaseFdtLib/libfdt",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/limits.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/stdbool.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/stddef.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/stdint.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/stdlib.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/string.h"
> > >> >>
> > >> >> +        ]
> > >> >>
> > >> >>      }
> > >> >>
> > >> >>  }
> > >> >>
> > >> >> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> > >> >> e70182bf7f..9804a7a6bd 100644
> > >> >> --- a/MdePkg/MdePkg.dec
> > >> >> +++ b/MdePkg/MdePkg.dec
> > >> >> @@ -289,6 +289,10 @@
> > >> >>    #
> > >> >>
> > >> >>    ArmTrngLib|Include/Library/ArmTrngLib.h
> > >> >>
> > >> >>
> > >> >>
> > >> >> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> > >> >>
> > >> >> +  #
> > >> >>
> > >> >> +  FdtLib|Include/Library/FdtLib.h
> > >> >>
> > >> >> +
> > >> >>
> > >> >>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> > >> >>
> > >> >>    ##  @libraryclass  Provides services to generate random number.
> > >> >>
> > >> >>    #
> > >> >>
> > >> >> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> > >> >> 152c02991a..b38c863812 100644
> > >> >> --- a/MdePkg/MdePkg.dsc
> > >> >> +++ b/MdePkg/MdePkg.dsc
> > >> >> @@ -137,6 +137,7 @@
> > >> >>
> > >> >>
> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> > >> >>
> > >> >>
> > >> >>
> > >> >>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> > >> >>
> > >> >> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >> >>
> > >> >>
> > >> >>
> > >> >>  [Components.IA32, Components.X64, Components.ARM,
> > >> >> Components.AARCH64]
> > >> >>
> > >> >>    #
> > >> >>
> > >> >> --
> > >> >> 2.39.1.windows.1
> > >
> > >
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-20 16:44           ` Michael D Kinney
  2023-04-21  2:33             ` [edk2-devel] " Chiu, Chasel
@ 2023-04-24 17:28             ` Leif Lindholm
  2023-04-24 17:41               ` Michael D Kinney
  1 sibling, 1 reply; 20+ messages in thread
From: Leif Lindholm @ 2023-04-24 17:28 UTC (permalink / raw)
  To: devel, michael.d.kinney
  Cc: Lin, Benny, Leif Lindholm, Gao, Liming, Liu, Zhiguang,
	Pedro Falcato

Apologies, I was refactoring a git tree and switched off the world :)

Well, being a bit late to the party ... my view is it would be
preferable if we put the byteswapping in the library.

The DT format is *defined* to be big-endian, 32-bit cells. So frankly,
I have no problems with pushing responsibility onto individual
platforms if they have decided to be "clever" by ignoring that -
if that gets rid of a bunch of boilerplate for sensibly behaving platforms.

Maybe another excuse for getting
https://github.com/tianocore/edk2-platforms/blob/master/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
into MdePkg?

/
    Leif

On Thu, Apr 20, 2023 at 16:44:03 +0000, Michael D Kinney wrote:
> Hi Leif,
> 
> What is your opinion on FDT being big endian.
> 
> Do we want the lib to help with that aspect, or leave it up to the consumer of the lib to 
> convert as needed?  Seems like an area that could be very error prone if we are not
> careful.
> 
> Mike
> 
> > -----Original Message-----
> > From: Lin, Benny <benny.lin@intel.com>
> > Sent: Wednesday, April 19, 2023 9:25 PM
> > To: Kinney, Michael D <michael.d.kinney@intel.com>; devel@edk2.groups.io
> > Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > 
> > 
> > 
> > >-----Original Message-----
> > >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > >Sent: Thursday, April 20, 2023 5:04 AM
> > >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>; Kinney,
> > Michael D <michael.d.kinney@intel.com>
> > >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >
> > >Responses below
> > >
> > >Mike
> > >
> > >> -----Original Message-----
> > >> From: Lin, Benny <benny.lin@intel.com>
> > >> Sent: Wednesday, April 19, 2023 10:12 AM
> > >> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > >> devel@edk2.groups.io
> > >> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > >> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > >> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >>
> > >> Please find my feedback below.
> > >> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER, what do you think?
> > >>
> > >> QQQ
> > >> Benny
> > >>
> > >> >-----Original Message-----
> > >> >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > >> >Sent: Wednesday, April 19, 2023 11:54 PM
> > >> >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > >> >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > >> ><zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>;
> > >> >Kinney,
> > >> Michael D <michael.d.kinney@intel.com>
> > >> >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >> >
> > >> >A few comments below.
> > >> >
> > >> >Mike
> > >> >
> > >> >> -----Original Message-----
> > >> >> From: Lin, Benny <benny.lin@intel.com>
> > >> >> Sent: Sunday, April 16, 2023 10:35 PM
> > >> >> To: devel@edk2.groups.io
> > >> >> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> > >> >> <michael.d.kinney@intel.com>; Gao, Liming
> > >> >> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> > >> >> Pedro Falcato <pedro.falcato@gmail.com>
> > >> >> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >> >>
> > >> >> From: Benny Lin <benny.lin@intel.com>
> > >> >>
> > >> >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> > >> >> Add FDT support in EDK2 by submodule 3rd party libfdt
> > >> >> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> > >> >> and refer to LibcLib implementation by Pedro.
> > >> >>
> > >> >> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > >> >> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > >> >> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > >> >> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> > >> >> Signed-off-by: Benny Lin <benny.lin@intel.com>
> > >> >> ---
> > >> >>  MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
> > >> >>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> > >> >> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> > >> >>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
> > >> >>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> > >> >> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
> > >> >>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> > >> >>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
> > >> >>  MdePkg/MdePkg.ci.yaml                     |  17 +-
> > >> >>  MdePkg/MdePkg.dec                         |   4 +
> > >> >>  MdePkg/MdePkg.dsc                         |   1 +
> > >> >>  15 files changed, 1043 insertions(+), 2 deletions(-)
> > >> >>
> > >> >> diff --git a/MdePkg/Include/Library/FdtLib.h
> > >> >> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
> > >> >> 0000000000..d59b749c25
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Include/Library/FdtLib.h
> > >> >> @@ -0,0 +1,314 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Flattened Device Tree Library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#ifndef FDT_LIB_H_
> > >> >>
> > >> >> +#define FDT_LIB_H_
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +///
> > >> >>
> > >> >> +/// Flattened Device Tree definition
> > >> >>
> > >> >> +///
> > >> >>
> > >> >> +typedef struct {
> > >> >>
> > >> >> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> > >> >>
> > >> >> +  UINT32    TotalSize;           /* total size of DT block */
> > >> >>
> > >> >> +  UINT32    OffsetDtStruct;      /* offset to structure */
> > >> >>
> > >> >> +  UINT32    OffsetDtStrings;     /* offset to strings */
> > >> >>
> > >> >> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map */
> > >> >>
> > >> >> +  UINT32    Version;             /* format version */
> > >> >>
> > >> >> +  UINT32    LastCompVersion;     /* last compatible version */
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  /* version 2 fields below */
> > >> >>
> > >> >> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
> > >> >>
> > >> >> +                                    booting on */
> > >> >>
> > >> >> +  /* version 3 fields below */
> > >> >>
> > >> >> +  UINT32    SizeDtStrings;       /* size of the strings block */
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  /* version 17 fields below */
> > >> >>
> > >> >> +  UINT32    SizeDtStruct;        /* size of the structure block */
> > >> >>
> > >> >> +} FDT_HEADER;
> > >> >
> > >> >I see the macros below use SwapBytes32() on all the fields from this
> > >> >structure.  Does this mean this structure is big >endian?  If
> > >> that is the case, then the description of this structure and all
> > >> individual fields must make that very clear >so any consumer of the
> > >> structure knows it does not follow the default endianness of UEFI/PI and that consumers >must either use the macros or consumers
> > must use SwapBytes32() on their own when using this structure directly.
> > >>
> > >> Yes, it's big endian. I will complete more descriptions in patch v4.
> > >
> > >Would it be simpler if we have a lib service that converts the entire header from big endian to little endian.
> > >That way, the consumer can use the FDT_HEADER directly without any of the macros?
> > >
> > >Also, is the rest of the FDT blob also big endian?
> > 
> > FDT blob format is binary encoding of FDT data with big endian. In addition, the consumer will set or get FDT data with FDT blob. We
> > can complete more descriptions to warn consumers to be careful if just use header struct for mapping and get/set FDT data with FDT
> > blob.
> > 
> > For provide lib services that converts between big endian and little endian, we can provide a get header function to convert between
> > big endian and little endian. However, we also need to consider the property value for setting and getting then we can convert in
> > wrapper functions.
> > 
> > For example,
> > 
> > INT32
> > EFIAPI
> > FdtSetProp (
> >   IN VOID         *Fdt,
> >   IN INT32        NodeOffset,
> >   IN CONST CHAR8  *Name,
> >   IN CONST VOID   *Value,
> >   IN UINT32       Length
> >   )
> > {
> >   return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > }
> > 
> > More functions for various byte width.
> > INT32
> > EFIAPI
> > FdtSetProp16 (
> >   IN VOID         *Fdt,
> >   IN INT32        NodeOffset,
> >   IN CONST CHAR8  *Name,
> >   IN CONST UINT16   *Value,
> >   IN UINT32       Length
> >   )
> > {
> >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value), (int)Length);
> > }
> > 
> > INT32
> > EFIAPI
> > FdtSetProp32 (
> >   IN VOID         *Fdt,
> >   IN INT32        NodeOffset,
> >   IN CONST CHAR8  *Name,
> >   IN CONST UINT32   *Value,
> >   IN UINT32       Length
> >   )
> > {
> >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value), (int)Length);
> > }
> > 
> > >>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +typedef struct {
> > >> >>
> > >> >> +  UINT64    Address;
> > >> >>
> > >> >> +  UINT64    Size;
> > >> >>
> > >> >> +} FDT_RESERVE_ENTRY;
> > >> >
> > >> >
> > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > >> >Can it be removed?
> > >>
> > >> I think we can remove it because it might be not used for further usage of FDT support.
> > >>
> > >> >
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +typedef struct {
> > >> >>
> > >> >> +  UINT32    Tag;
> > >> >>
> > >> >> +  CHAR8     Name[];
> > >> >>
> > >> >> +} FDT_NODE_HEADER;
> > >> >
> > >> >
> > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > >> >Can it be removed?
> > >>
> > >> When we need retrieve a node from a FDT blob, we will get a node
> > >> offset then we could use the struct to map the node content. It's very useful.
> > >
> > >Please add a comment header for this structure and describe the usage as it related to the rest of the FdtLib >services.
> > 
> > I will add descriptions for the usage and remove FDT_RESERVE_ENTRY in patch v4.
> > 
> > >
> > >>
> > >> >
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +typedef struct {
> > >> >>
> > >> >> +  UINT32    Tag;
> > >> >>
> > >> >> +  UINT32    Length;
> > >> >>
> > >> >> +  UINT32    NameOffset;
> > >> >>
> > >> >> +  CHAR8     Data[];
> > >> >>
> > >> >> +} FDT_PROPERTY;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST FDT_HEADER
> > >> >> +*)(Fdt))->Field)
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
> > >> >>
> > >> >> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt, TotalSize))
> > >> >>
> > >> >> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt, OffsetDtStruct))
> > >> >>
> > >> >> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
> > >> >> +OffsetDtStrings))
> > >> >>
> > >> >> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
> > >> >> +OffsetMemRsvmap))
> > >> >>
> > >> >> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
> > >> >>
> > >> >> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
> > >> >> +LastCompVersion))
> > >> >>
> > >> >> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt, BootCpuidPhys))
> > >> >>
> > >> >> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt, SizeDtStrings))
> > >> >>
> > >> >> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt, SizeDtStruct))
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Verify the header of the Flattened Device Tree
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtCheckHeader (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Create a empty Flattened Device Tree.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> > >> >>
> > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +RETURN_STATUS
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtCreateEmptyTree (
> > >> >>
> > >> >> +  IN VOID   *Buffer,
> > >> >>
> > >> >> +  IN UINTN  BufferSize
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next node from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextNode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset,
> > >> >>
> > >> >> +  IN INT32       *Depth
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node under the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtFirstSubnode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next node from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextSubnode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node which includes the given name.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] ParentOffset    The offset to the node which start find under.
> > >> >>
> > >> >> +  @param[in] Name            The name to search the node with the name.
> > >> >>
> > >> >> +  @param[in] NameLength      The length of the name to check only.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to node offset with given node name.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtSubnodeOffsetNameLen (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        ParentOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN INT32        NameLength
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node which includes the given property name and value.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > >> >>
> > >> >> +  @param[in] PropertyName    The property name to search the node including the named property.
> > >> >>
> > >> >> +  @param[in] PropertyValue   The property value to check the same property value.
> > >> >>
> > >> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to node offset with given property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNodeOffsetByPropValue (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        StartOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *PropertyName,
> > >> >>
> > >> >> +  IN CONST VOID   *PropertyValue,
> > >> >>
> > >> >> +  IN INT32        PropertyLength
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a property with the given name from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > >> >>
> > >> >> +  @param[in] Name           The name to the property which need be searched
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property found.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The property to the structure of the found property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST FDT_PROPERTY *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetProperty (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        NodeOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN INT32        *Length
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first property in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to the node which need be searched.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to first property offset in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtFirstPropertyOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       NodeOffset
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next property from the given property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next property offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextPropertyOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a property from the given offset of the property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to the given offset of the property.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property found.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The property to the structure of the given property offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST FDT_PROPERTY *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetPropertyByOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset,
> > >> >>
> > >> >> +  IN INT32       *Length
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a string by the given string offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of string which need be retrieved.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The string to the given string offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST CHAR8 *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetString (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       StrOffset,
> > >> >>
> > >> >> +  IN INT32       *Length        OPTIONAL
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Add a new node to the FDT.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> > >> >>
> > >> >> +  @param[in] Name           The name to name the node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return  The offset to the new node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtAddSubnode (
> > >> >>
> > >> >> +  IN VOID         *Fdt,
> > >> >>
> > >> >> +  IN INT32        ParentOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Add or modify a property in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> > >> >>
> > >> >> +  @param[in] Name           The name to name the property.
> > >> >>
> > >> >> +  @param[in] Value          The value to the property value.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return  Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtSetProp (
> > >> >>
> > >> >> +  IN VOID         *Fdt,
> > >> >>
> > >> >> +  IN INT32        NodeOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN CONST VOID   *Value,
> > >> >>
> > >> >> +  IN UINT32       Length
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#endif /* FDT_LIB_H_ */
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >> >> new file mode 100644
> > >> >> index 0000000000..730e568ff6
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >> >> @@ -0,0 +1,62 @@
> > >> >> +## @file
> > >> >>
> > >> >> +# Flattened Device Tree Library.
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +##
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[Defines]
> > >> >>
> > >> >> +  INF_VERSION                    = 0x0001001B
> > >> >>
> > >> >> +  BASE_NAME                      = BaseFdtLib
> > >> >>
> > >> >> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> > >> >>
> > >> >> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-E8CEC206DE04
> > >> >>
> > >> >> +  MODULE_TYPE                    = BASE
> > >> >>
> > >> >> +  VERSION_STRING                 = 1.0
> > >> >>
> > >> >> +  LIBRARY_CLASS                  = FdtLib
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +#  VALID_ARCHITECTURES           = IA32 X64
> > >> >>
> > >> >> +#
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[Sources]
> > >> >>
> > >> >> +  FdtLib.c
> > >> >>
> > >> >> +  LibFdtWrapper.c
> > >> >>
> > >> >> +  # header Wrapper files
> > >> >>
> > >> >> +  limits.h
> > >> >>
> > >> >> +  stdbool.h
> > >> >>
> > >> >> +  stddef.h
> > >> >>
> > >> >> +  stdint.h
> > >> >>
> > >> >> +  stdlib.h
> > >> >>
> > >> >> +  string.h
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt.h
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_addresses.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_check.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_overlay.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_ro.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_rw.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_strerror.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_sw.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/fdt_wip.c
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/libfdt.h
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/libfdt_env.h
> > >> >>
> > >> >> +  $(FDT_LIB_PATH)/libfdt_internal.h
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[Packages]
> > >> >>
> > >> >> +  MdePkg/MdePkg.dec
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[LibraryClasses]
> > >> >>
> > >> >> +  BaseLib
> > >> >>
> > >> >> +  BaseMemoryLib
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +[BuildOptions]
> > >> >>
> > >> >> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> > >> >>
> > >> >> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > >> >> new file mode 100644
> > >> >> index 0000000000..3f7e45ea6f
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > >> >> @@ -0,0 +1,14 @@
> > >> >> +// /** @file
> > >> >>
> > >> >> +// Flattened Device Tree Library.
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// **/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#string STR_MODULE_ABSTRACT             #language en-US "Instance of FDT Library"
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#string STR_MODULE_DESCRIPTION          #language en-US "This module provides FDT Library implementation."
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> > >> >> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > >> >> new file mode 100644
> > >> >> index 0000000000..200a496c7e
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > >> >> @@ -0,0 +1,301 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Flattened Device Tree Library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <libfdt/libfdt/libfdt.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Verify the header of the Flattened Device Tree
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtCheckHeader (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_check_header(Fdt);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Create a empty Flattened Device Tree.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> > >> >>
> > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtCreateEmptyTree (
> > >> >>
> > >> >> +  IN VOID    *Buffer,
> > >> >>
> > >> >> +  IN UINT32  BufferSize
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next node from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextNode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset,
> > >> >>
> > >> >> +  IN INT32       *Depth
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_next_node (Fdt, Offset, Depth);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node under the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtFirstSubnode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_first_subnode (Fdt, Offset);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next node from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next node offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextSubnode (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_next_subnode (Fdt, Offset);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node which includes the given name.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] ParentOffset    The offset to the node which start find under.
> > >> >>
> > >> >> +  @param[in] Name            The name to search the node with the name.
> > >> >>
> > >> >> +  @param[in] NameLength      The length of the name to check only.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to node offset with given node name.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtSubnodeOffsetNameLen (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        ParentOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN INT32        NameLength
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name,
> > >> >> + NameLength);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first node which includes the given property name and value.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > >> >>
> > >> >> +  @param[in] PropertyName    The property name to search the node including the named property.
> > >> >>
> > >> >> +  @param[in] PropertyValue   The property value to check the same property value.
> > >> >>
> > >> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to node offset with given property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNodeOffsetByPropValue (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        StartOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *PropertyName,
> > >> >>
> > >> >> +  IN CONST VOID   *PropertyValue,
> > >> >>
> > >> >> +  IN INT32        PropertyLength
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> > >> >> + PropertyName, PropertyValue, PropertyLength);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a property with the given name from the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > >> >>
> > >> >> +  @param[in] Name           The name to the property which need be searched
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property found.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The property to the structure of the found property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST struct fdt_property *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetProperty (
> > >> >>
> > >> >> +  IN CONST VOID   *Fdt,
> > >> >>
> > >> >> +  IN INT32        NodeOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN INT32        *Length
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of first property in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the node which need be searched.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to first property offset in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtFirstPropertyOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       NodeOffset
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_first_property_offset (Fdt, NodeOffset);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a offset of next property from the given property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to previous property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The offset to next property offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtNextPropertyOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_next_property_offset (Fdt, Offset);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a property from the given offset of the property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] Offset         The offset to the given offset of the property.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property found.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The property to the structure of the given property offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST struct fdt_property *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetPropertyByOffset (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       Offset,
> > >> >>
> > >> >> +  IN INT32       *Length
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Returns a string by the given string offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of string which need be retrieved.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return The string to the given string offset.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +CONST CHAR8 *
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtGetString (
> > >> >>
> > >> >> +  IN CONST VOID  *Fdt,
> > >> >>
> > >> >> +  IN INT32       StrOffset,
> > >> >>
> > >> >> +  IN INT32       *Length        OPTIONAL
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_get_string (Fdt, StrOffset, Length);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Add a new node to the FDT.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> > >> >>
> > >> >> +  @param[in] Name           The name to name the node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return  The offset to the new node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtAddSubnode (
> > >> >>
> > >> >> +  IN VOID         *Fdt,
> > >> >>
> > >> >> +  IN INT32        ParentOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +/**
> > >> >>
> > >> >> +  Add or modify a property in the given node.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > >> >>
> > >> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> > >> >>
> > >> >> +  @param[in] Name           The name to name the property.
> > >> >>
> > >> >> +  @param[in] Value          The value to the property value.
> > >> >>
> > >> >> +  @param[in] Length         The length to the size of the property.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  @return  Zero for successfully, otherwise failed.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +INT32
> > >> >>
> > >> >> +EFIAPI
> > >> >>
> > >> >> +FdtSetProp (
> > >> >>
> > >> >> +  IN VOID         *Fdt,
> > >> >>
> > >> >> +  IN INT32        NodeOffset,
> > >> >>
> > >> >> +  IN CONST CHAR8  *Name,
> > >> >>
> > >> >> +  IN CONST VOID   *Value,
> > >> >>
> > >> >> +  IN UINT32       Length
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..e738f4ded4
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > >> >> @@ -0,0 +1,99 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Root include file of C runtime library to support building the
> > >> >> + third-party
> > >> >>
> > >> >> +  libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#ifndef FDT_LIB_SUPPORT_H_
> > >> >>
> > >> >> +#define FDT_LIB_SUPPORT_H_
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <Base.h>
> > >> >>
> > >> >> +#include <Library/BaseLib.h>
> > >> >>
> > >> >> +#include <Library/BaseMemoryLib.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +typedef UINT8    uint8_t;
> > >> >>
> > >> >> +typedef UINT16   uint16_t;
> > >> >>
> > >> >> +typedef INT32    int32_t;
> > >> >>
> > >> >> +typedef UINT32   uint32_t;
> > >> >>
> > >> >> +typedef UINT64   uint64_t;
> > >> >>
> > >> >> +typedef UINTN    uintptr_t;
> > >> >>
> > >> >> +typedef UINTN    size_t;
> > >> >>
> > >> >> +typedef BOOLEAN  bool;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#define true   (1 == 1)
> > >> >>
> > >> >> +#define false  (1 == 0)
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// Definitions for global constants used by libfdt library
> > >> >> +routines
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value */
> > >> >>
> > >> >> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32 value */
> > >> >>
> > >> >> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32 value */
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// Function prototypes of libfdt Library routines
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +void *
> > >> >>
> > >> >> +memset     (
> > >> >>
> > >> >> +  void *,
> > >> >>
> > >> >> +  int,
> > >> >>
> > >> >> +  size_t
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +int
> > >> >>
> > >> >> +memcmp      (
> > >> >>
> > >> >> +  const void *,
> > >> >>
> > >> >> +  const void *,
> > >> >>
> > >> >> +  size_t
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +int
> > >> >>
> > >> >> +strcmp      (
> > >> >>
> > >> >> +  const char *,
> > >> >>
> > >> >> +  const char *
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strchr     (
> > >> >>
> > >> >> +  const char *,
> > >> >>
> > >> >> +  int
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strrchr    (
> > >> >>
> > >> >> +  const char *,
> > >> >>
> > >> >> +  int
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +unsigned long
> > >> >>
> > >> >> +strtoul     (
> > >> >>
> > >> >> +  const char *,
> > >> >>
> > >> >> +  char **,
> > >> >>
> > >> >> +  int
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strcpy (
> > >> >>
> > >> >> +  char        *strDest,
> > >> >>
> > >> >> +  const char  *strSource
> > >> >>
> > >> >> +  );
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +// Macros that directly map functions to BaseLib, BaseMemoryLib,
> > >> >> +and DebugLib functions
> > >> >>
> > >> >> +//
> > >> >>
> > >> >> +#define memcpy(dest, source, count)         CopyMem(dest,source, (UINTN)(count))
> > >> >>
> > >> >> +#define memset(dest, ch, count)             SetMem(dest, (UINTN)(count),(UINT8)(ch))
> > >> >>
> > >> >> +#define memchr(buf, ch, count)              ScanMem8(buf, (UINTN)(count),(UINT8)ch)
> > >> >>
> > >> >> +#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1, buf2, (UINTN)(count)))
> > >> >>
> > >> >> +#define memmove(dest, source, count)        CopyMem(dest, source, (UINTN)(count))
> > >> >>
> > >> >> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> > >> >>
> > >> >> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
> > >> >>
> > >> >> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest,
> > >> >> +MAX_STRING_SIZE, strSource, (UINTN)count)
> > >> >>
> > >> >> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest, MAX_STRING_SIZE, strSource)
> > >> >>
> > >> >> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1, string2))
> > >> >>
> > >> >> +#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1, string2, (UINTN)(count)))
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#endif /* FDT_LIB_SUPPORT_H_ */
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > >> >> new file mode 100644
> > >> >> index 0000000000..772bba4839
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > >> >> @@ -0,0 +1,173 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  ISO C implementations of strchr, strrchr and strtoul.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> > >> >>
> > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <Base.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long value */
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +// Very quick notes:
> > >> >>
> > >> >> +// We only go through the string once for both functions
> > >> >>
> > >> >> +// They are minimal implementations (not speed optimized) of ISO C
> > >> >> +semantics
> > >> >>
> > >> >> +// strchr and strrchr also include the null terminator as part of
> > >> >> +the string
> > >> >>
> > >> >> +// so the code gets a bit clunky to handle that case specifically.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strchr (
> > >> >>
> > >> >> +  const char  *Str,
> > >> >>
> > >> >> +  int         Char
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  char  *S;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  S = (char *)Str;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  for ( ; ; S++) {
> > >> >>
> > >> >> +    if (*S == Char) {
> > >> >>
> > >> >> +      return S;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if (*S == '\0') {
> > >> >>
> > >> >> +      return NULL;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +char *
> > >> >>
> > >> >> +strrchr (
> > >> >>
> > >> >> +  const char  *Str,
> > >> >>
> > >> >> +  int         Char
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  char  *S, *last;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  S    = (char *)Str;
> > >> >>
> > >> >> +  last = NULL;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  for ( ; ; S++) {
> > >> >>
> > >> >> +    if (*S == Char) {
> > >> >>
> > >> >> +      last = S;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if (*S == '\0') {
> > >> >>
> > >> >> +      return last;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +STATIC
> > >> >>
> > >> >> +int
> > >> >>
> > >> >> +__isspace (
> > >> >>
> > >> >> +  int  ch
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  // basic ASCII ctype.h:isspace(). Not efficient
> > >> >>
> > >> >> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
> > >> >> + == '\v' || ch == '\f';
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +unsigned long
> > >> >>
> > >> >> +strtoul (
> > >> >>
> > >> >> +  const char  *Nptr,
> > >> >>
> > >> >> +  char        **EndPtr,
> > >> >>
> > >> >> +  int         Base
> > >> >>
> > >> >> +  )
> > >> >>
> > >> >> +{
> > >> >>
> > >> >> +  BOOLEAN        Negate;
> > >> >>
> > >> >> +  BOOLEAN        Overflow;
> > >> >>
> > >> >> +  unsigned long  Val;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  Negate   = FALSE;
> > >> >>
> > >> >> +  Overflow = FALSE;
> > >> >>
> > >> >> +  Val      = 0;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // Reject bad numeric bases
> > >> >>
> > >> >> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> > >> >>
> > >> >> +    return 0;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // Skip whitespace
> > >> >>
> > >> >> +  while (__isspace (*Nptr)) {
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // Check for + or - prefixes
> > >> >>
> > >> >> +  if (*Nptr == '-') {
> > >> >>
> > >> >> +    Negate = TRUE;
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +  } else if (*Nptr == '+') {
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // Consume the start, autodetecting base if needed
> > >> >>
> > >> >> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
> > >> >> + && ((Base == 0) || (Base == 16))) {
> > >> >>
> > >> >> +    // Hex
> > >> >>
> > >> >> +    Nptr += 2;
> > >> >>
> > >> >> +    Base  = 16;
> > >> >>
> > >> >> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> > >> >> + 'B')) && ((Base == 0) || (Base == 2))) {
> > >> >>
> > >> >> +    // Binary (standard pending C23)
> > >> >>
> > >> >> +    Nptr += 2;
> > >> >>
> > >> >> +    Base  = 2;
> > >> >>
> > >> >> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> > >> >>
> > >> >> +    // Octal
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +    Base = 8;
> > >> >>
> > >> >> +  } else {
> > >> >>
> > >> >> +    if (Base == 0) {
> > >> >>
> > >> >> +      // Assume decimal
> > >> >>
> > >> >> +      Base = 10;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  while (TRUE) {
> > >> >>
> > >> >> +    int            Digit;
> > >> >>
> > >> >> +    char           C;
> > >> >>
> > >> >> +    unsigned long  NewVal;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    C     = *Nptr;
> > >> >>
> > >> >> +    Digit = -1;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if ((C >= '0') && (C <= '9')) {
> > >> >>
> > >> >> +      Digit = C - '0';
> > >> >>
> > >> >> +    } else if ((C >= 'a') && (C <= 'z')) {
> > >> >>
> > >> >> +      Digit = C - 'a' + 10;
> > >> >>
> > >> >> +    } else if ((C >= 'A') && (C <= 'Z')) {
> > >> >>
> > >> >> +      Digit = C - 'A' + 10;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if ((Digit == -1) || (Digit >= Base)) {
> > >> >>
> > >> >> +      // Note that this case also handles the \0
> > >> >>
> > >> >> +      if (EndPtr) {
> > >> >>
> > >> >> +        *EndPtr = (char *)Nptr;
> > >> >>
> > >> >> +      }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +      break;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    NewVal = Val * Base + Digit;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    if (NewVal < Val) {
> > >> >>
> > >> >> +      // Overflow
> > >> >>
> > >> >> +      Overflow = TRUE;
> > >> >>
> > >> >> +    }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    Val = NewVal;
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +    Nptr++;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  if (Negate) {
> > >> >>
> > >> >> +    Val = -Val;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  if (Overflow) {
> > >> >>
> > >> >> +    Val = ULONG_MAX;
> > >> >>
> > >> >> +  }
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +  // TODO: We're lacking errno here.
> > >> >>
> > >> >> +  return Val;
> > >> >>
> > >> >> +}
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> > >> >> b/MdePkg/Library/BaseFdtLib/limits.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> > >> >> b/MdePkg/Library/BaseFdtLib/stdbool.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> > >> >> b/MdePkg/Library/BaseFdtLib/stddef.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> > >> >> b/MdePkg/Library/BaseFdtLib/stdint.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> > >> >> b/MdePkg/Library/BaseFdtLib/stdlib.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> > >> >> b/MdePkg/Library/BaseFdtLib/string.h
> > >> >> new file mode 100644
> > >> >> index 0000000000..f6cf8d5702
> > >> >> --- /dev/null
> > >> >> +++ b/MdePkg/Library/BaseFdtLib/string.h
> > >> >> @@ -0,0 +1,10 @@
> > >> >> +/** @file
> > >> >>
> > >> >> +  Include file to support building the third-party libfdt library.
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +**/
> > >> >>
> > >> >> +
> > >> >>
> > >> >> +#include <LibFdtSupport.h>
> > >> >>
> > >> >> +
> > >> >>
> > >> >> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index
> > >> >> 6ba85ebe61..f039daccdb 100644
> > >> >> --- a/MdePkg/MdePkg.ci.yaml
> > >> >> +++ b/MdePkg/MdePkg.ci.yaml
> > >> >> @@ -2,7 +2,7 @@
> > >> >>  # CI configuration for MdePkg
> > >> >>
> > >> >>  #
> > >> >>
> > >> >>  # Copyright (c) Microsoft Corporation
> > >> >>
> > >> >> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > >> >>
> > >> >>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> > >> >>
> > >> >>  # Copyright (c) 2023, Loongson Technology Corporation Limited. All
> > >> >> rights reserved.<BR>
> > >> >>
> > >> >>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> > >> >>
> > >> >> @@ -67,7 +67,8 @@
> > >> >>              "Include/Library/PcdLib.h",
> > >> >>
> > >> >>              "Include/Library/SafeIntLib.h",
> > >> >>
> > >> >>              "Include/Protocol/DebugSupport.h",
> > >> >>
> > >> >> -            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> > >> >>
> > >> >> +
> > >> >> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> > >> >>
> > >> >> +            "Library/BaseFdtLib"
> > >> >>
> > >> >>          ]
> > >> >>
> > >> >>      },
> > >> >>
> > >> >>      ## options defined ci/Plugin/CompilerPlugin
> > >> >>
> > >> >> @@ -164,5 +165,17 @@
> > >> >>          "ExtendWords": [],           # words to extend to the dictionary for this package
> > >> >>
> > >> >>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
> > >> >>
> > >> >>          "AdditionalIncludePaths": [] # Additional paths to spell
> > >> >> check (wildcards supported)
> > >> >>
> > >> >> +    },
> > >> >>
> > >> >> +    # options defined in .pytool/Plugin/UncrustifyCheck
> > >> >>
> > >> >> +    "UncrustifyCheck": {
> > >> >>
> > >> >> +        "IgnoreFiles": [
> > >> >>
> > >> >> +            "Library/BaseFdtLib/libfdt",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/limits.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/stdbool.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/stddef.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/stdint.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/stdlib.h",
> > >> >>
> > >> >> +            "Library/BaseFdtLib/string.h"
> > >> >>
> > >> >> +        ]
> > >> >>
> > >> >>      }
> > >> >>
> > >> >>  }
> > >> >>
> > >> >> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> > >> >> e70182bf7f..9804a7a6bd 100644
> > >> >> --- a/MdePkg/MdePkg.dec
> > >> >> +++ b/MdePkg/MdePkg.dec
> > >> >> @@ -289,6 +289,10 @@
> > >> >>    #
> > >> >>
> > >> >>    ArmTrngLib|Include/Library/ArmTrngLib.h
> > >> >>
> > >> >>
> > >> >>
> > >> >> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> > >> >>
> > >> >> +  #
> > >> >>
> > >> >> +  FdtLib|Include/Library/FdtLib.h
> > >> >>
> > >> >> +
> > >> >>
> > >> >>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> > >> >>
> > >> >>    ##  @libraryclass  Provides services to generate random number.
> > >> >>
> > >> >>    #
> > >> >>
> > >> >> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> > >> >> 152c02991a..b38c863812 100644
> > >> >> --- a/MdePkg/MdePkg.dsc
> > >> >> +++ b/MdePkg/MdePkg.dsc
> > >> >> @@ -137,6 +137,7 @@
> > >> >>
> > >> >> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> > >> >>
> > >> >>
> > >> >>
> > >> >>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> > >> >>
> > >> >> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >> >>
> > >> >>
> > >> >>
> > >> >>  [Components.IA32, Components.X64, Components.ARM,
> > >> >> Components.AARCH64]
> > >> >>
> > >> >>    #
> > >> >>
> > >> >> --
> > >> >> 2.39.1.windows.1
> > >
> > >
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-24 17:28             ` Leif Lindholm
@ 2023-04-24 17:41               ` Michael D Kinney
  2023-04-26  5:21                 ` Chiu, Chasel
       [not found]                 ` <17596494A9010E70.30288@groups.io>
  0 siblings, 2 replies; 20+ messages in thread
From: Michael D Kinney @ 2023-04-24 17:41 UTC (permalink / raw)
  To: Leif Lindholm, devel@edk2.groups.io
  Cc: Lin, Benny, Leif Lindholm, Gao, Liming, Liu, Zhiguang,
	Pedro Falcato, Kinney, Michael D

Hi Leif,

Do you have a proposal or small example on what you want to see
in the library?

Mike

> -----Original Message-----
> From: Leif Lindholm <quic_llindhol@quicinc.com>
> Sent: Monday, April 24, 2023 10:29 AM
> To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>
> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu,
> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> Apologies, I was refactoring a git tree and switched off the world :)
> 
> Well, being a bit late to the party ... my view is it would be
> preferable if we put the byteswapping in the library.
> 
> The DT format is *defined* to be big-endian, 32-bit cells. So frankly,
> I have no problems with pushing responsibility onto individual
> platforms if they have decided to be "clever" by ignoring that -
> if that gets rid of a bunch of boilerplate for sensibly behaving platforms.
> 
> Maybe another excuse for getting
> https://github.com/tianocore/edk2-platforms/blob/master/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
> into MdePkg?
> 
> /
>     Leif
> 
> On Thu, Apr 20, 2023 at 16:44:03 +0000, Michael D Kinney wrote:
> > Hi Leif,
> >
> > What is your opinion on FDT being big endian.
> >
> > Do we want the lib to help with that aspect, or leave it up to the consumer of the lib to
> > convert as needed?  Seems like an area that could be very error prone if we are not
> > careful.
> >
> > Mike
> >
> > > -----Original Message-----
> > > From: Lin, Benny <benny.lin@intel.com>
> > > Sent: Wednesday, April 19, 2023 9:25 PM
> > > To: Kinney, Michael D <michael.d.kinney@intel.com>; devel@edk2.groups.io
> > > Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > > Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >
> > >
> > >
> > > >-----Original Message-----
> > > >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > > >Sent: Thursday, April 20, 2023 5:04 AM
> > > >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > > >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> <pedro.falcato@gmail.com>; Kinney,
> > > Michael D <michael.d.kinney@intel.com>
> > > >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >
> > > >Responses below
> > > >
> > > >Mike
> > > >
> > > >> -----Original Message-----
> > > >> From: Lin, Benny <benny.lin@intel.com>
> > > >> Sent: Wednesday, April 19, 2023 10:12 AM
> > > >> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > >> devel@edk2.groups.io
> > > >> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > >> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > > >> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >>
> > > >> Please find my feedback below.
> > > >> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER, what do you think?
> > > >>
> > > >> QQQ
> > > >> Benny
> > > >>
> > > >> >-----Original Message-----
> > > >> >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > > >> >Sent: Wednesday, April 19, 2023 11:54 PM
> > > >> >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > > >> >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > >> ><zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>;
> > > >> >Kinney,
> > > >> Michael D <michael.d.kinney@intel.com>
> > > >> >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >> >
> > > >> >A few comments below.
> > > >> >
> > > >> >Mike
> > > >> >
> > > >> >> -----Original Message-----
> > > >> >> From: Lin, Benny <benny.lin@intel.com>
> > > >> >> Sent: Sunday, April 16, 2023 10:35 PM
> > > >> >> To: devel@edk2.groups.io
> > > >> >> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> > > >> >> <michael.d.kinney@intel.com>; Gao, Liming
> > > >> >> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> > > >> >> Pedro Falcato <pedro.falcato@gmail.com>
> > > >> >> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >> >>
> > > >> >> From: Benny Lin <benny.lin@intel.com>
> > > >> >>
> > > >> >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> > > >> >> Add FDT support in EDK2 by submodule 3rd party libfdt
> > > >> >> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> > > >> >> and refer to LibcLib implementation by Pedro.
> > > >> >>
> > > >> >> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > > >> >> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > > >> >> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > > >> >> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> > > >> >> Signed-off-by: Benny Lin <benny.lin@intel.com>
> > > >> >> ---
> > > >> >>  MdePkg/Include/Library/FdtLib.h           | 314 ++++++++++++++++++++
> > > >> >>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> > > >> >> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> > > >> >>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301 +++++++++++++++++++
> > > >> >>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> > > >> >> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
> > > >> >>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> > > >> >>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> > > >> >>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> > > >> >>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> > > >> >>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> > > >> >>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
> > > >> >>  MdePkg/MdePkg.ci.yaml                     |  17 +-
> > > >> >>  MdePkg/MdePkg.dec                         |   4 +
> > > >> >>  MdePkg/MdePkg.dsc                         |   1 +
> > > >> >>  15 files changed, 1043 insertions(+), 2 deletions(-)
> > > >> >>
> > > >> >> diff --git a/MdePkg/Include/Library/FdtLib.h
> > > >> >> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
> > > >> >> 0000000000..d59b749c25
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Include/Library/FdtLib.h
> > > >> >> @@ -0,0 +1,314 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  Flattened Device Tree Library.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#ifndef FDT_LIB_H_
> > > >> >>
> > > >> >> +#define FDT_LIB_H_
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +///
> > > >> >>
> > > >> >> +/// Flattened Device Tree definition
> > > >> >>
> > > >> >> +///
> > > >> >>
> > > >> >> +typedef struct {
> > > >> >>
> > > >> >> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> > > >> >>
> > > >> >> +  UINT32    TotalSize;           /* total size of DT block */
> > > >> >>
> > > >> >> +  UINT32    OffsetDtStruct;      /* offset to structure */
> > > >> >>
> > > >> >> +  UINT32    OffsetDtStrings;     /* offset to strings */
> > > >> >>
> > > >> >> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map */
> > > >> >>
> > > >> >> +  UINT32    Version;             /* format version */
> > > >> >>
> > > >> >> +  UINT32    LastCompVersion;     /* last compatible version */
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  /* version 2 fields below */
> > > >> >>
> > > >> >> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
> > > >> >>
> > > >> >> +                                    booting on */
> > > >> >>
> > > >> >> +  /* version 3 fields below */
> > > >> >>
> > > >> >> +  UINT32    SizeDtStrings;       /* size of the strings block */
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  /* version 17 fields below */
> > > >> >>
> > > >> >> +  UINT32    SizeDtStruct;        /* size of the structure block */
> > > >> >>
> > > >> >> +} FDT_HEADER;
> > > >> >
> > > >> >I see the macros below use SwapBytes32() on all the fields from this
> > > >> >structure.  Does this mean this structure is big >endian?  If
> > > >> that is the case, then the description of this structure and all
> > > >> individual fields must make that very clear >so any consumer of the
> > > >> structure knows it does not follow the default endianness of UEFI/PI and that consumers >must either use the macros or
> consumers
> > > must use SwapBytes32() on their own when using this structure directly.
> > > >>
> > > >> Yes, it's big endian. I will complete more descriptions in patch v4.
> > > >
> > > >Would it be simpler if we have a lib service that converts the entire header from big endian to little endian.
> > > >That way, the consumer can use the FDT_HEADER directly without any of the macros?
> > > >
> > > >Also, is the rest of the FDT blob also big endian?
> > >
> > > FDT blob format is binary encoding of FDT data with big endian. In addition, the consumer will set or get FDT data with FDT
> blob. We
> > > can complete more descriptions to warn consumers to be careful if just use header struct for mapping and get/set FDT data
> with FDT
> > > blob.
> > >
> > > For provide lib services that converts between big endian and little endian, we can provide a get header function to convert
> between
> > > big endian and little endian. However, we also need to consider the property value for setting and getting then we can
> convert in
> > > wrapper functions.
> > >
> > > For example,
> > >
> > > INT32
> > > EFIAPI
> > > FdtSetProp (
> > >   IN VOID         *Fdt,
> > >   IN INT32        NodeOffset,
> > >   IN CONST CHAR8  *Name,
> > >   IN CONST VOID   *Value,
> > >   IN UINT32       Length
> > >   )
> > > {
> > >   return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > > }
> > >
> > > More functions for various byte width.
> > > INT32
> > > EFIAPI
> > > FdtSetProp16 (
> > >   IN VOID         *Fdt,
> > >   IN INT32        NodeOffset,
> > >   IN CONST CHAR8  *Name,
> > >   IN CONST UINT16   *Value,
> > >   IN UINT32       Length
> > >   )
> > > {
> > >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value), (int)Length);
> > > }
> > >
> > > INT32
> > > EFIAPI
> > > FdtSetProp32 (
> > >   IN VOID         *Fdt,
> > >   IN INT32        NodeOffset,
> > >   IN CONST CHAR8  *Name,
> > >   IN CONST UINT32   *Value,
> > >   IN UINT32       Length
> > >   )
> > > {
> > >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value), (int)Length);
> > > }
> > >
> > > >>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +typedef struct {
> > > >> >>
> > > >> >> +  UINT64    Address;
> > > >> >>
> > > >> >> +  UINT64    Size;
> > > >> >>
> > > >> >> +} FDT_RESERVE_ENTRY;
> > > >> >
> > > >> >
> > > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > > >> >Can it be removed?
> > > >>
> > > >> I think we can remove it because it might be not used for further usage of FDT support.
> > > >>
> > > >> >
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +typedef struct {
> > > >> >>
> > > >> >> +  UINT32    Tag;
> > > >> >>
> > > >> >> +  CHAR8     Name[];
> > > >> >>
> > > >> >> +} FDT_NODE_HEADER;
> > > >> >
> > > >> >
> > > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > > >> >Can it be removed?
> > > >>
> > > >> When we need retrieve a node from a FDT blob, we will get a node
> > > >> offset then we could use the struct to map the node content. It's very useful.
> > > >
> > > >Please add a comment header for this structure and describe the usage as it related to the rest of the FdtLib >services.
> > >
> > > I will add descriptions for the usage and remove FDT_RESERVE_ENTRY in patch v4.
> > >
> > > >
> > > >>
> > > >> >
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +typedef struct {
> > > >> >>
> > > >> >> +  UINT32    Tag;
> > > >> >>
> > > >> >> +  UINT32    Length;
> > > >> >>
> > > >> >> +  UINT32    NameOffset;
> > > >> >>
> > > >> >> +  CHAR8     Data[];
> > > >> >>
> > > >> >> +} FDT_PROPERTY;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST FDT_HEADER
> > > >> >> +*)(Fdt))->Field)
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
> > > >> >>
> > > >> >> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt, TotalSize))
> > > >> >>
> > > >> >> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt, OffsetDtStruct))
> > > >> >>
> > > >> >> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
> > > >> >> +OffsetDtStrings))
> > > >> >>
> > > >> >> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
> > > >> >> +OffsetMemRsvmap))
> > > >> >>
> > > >> >> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
> > > >> >>
> > > >> >> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
> > > >> >> +LastCompVersion))
> > > >> >>
> > > >> >> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt, BootCpuidPhys))
> > > >> >>
> > > >> >> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt, SizeDtStrings))
> > > >> >>
> > > >> >> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt, SizeDtStruct))
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Verify the header of the Flattened Device Tree
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return Zero for successfully, otherwise failed.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtCheckHeader (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Create a empty Flattened Device Tree.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> > > >> >>
> > > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return Zero for successfully, otherwise failed.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +RETURN_STATUS
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtCreateEmptyTree (
> > > >> >>
> > > >> >> +  IN VOID   *Buffer,
> > > >> >>
> > > >> >> +  IN UINTN  BufferSize
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of next node from the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to previous node.
> > > >> >>
> > > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to next node offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtNextNode (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset,
> > > >> >>
> > > >> >> +  IN INT32       *Depth
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of first node under the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to previous node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to next node offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtFirstSubnode (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of next node from the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to previous node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to next node offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtNextSubnode (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of first node which includes the given name.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] ParentOffset    The offset to the node which start find under.
> > > >> >>
> > > >> >> +  @param[in] Name            The name to search the node with the name.
> > > >> >>
> > > >> >> +  @param[in] NameLength      The length of the name to check only.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to node offset with given node name.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtSubnodeOffsetNameLen (
> > > >> >>
> > > >> >> +  IN CONST VOID   *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        ParentOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *Name,
> > > >> >>
> > > >> >> +  IN INT32        NameLength
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of first node which includes the given property name and value.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > > >> >>
> > > >> >> +  @param[in] PropertyName    The property name to search the node including the named property.
> > > >> >>
> > > >> >> +  @param[in] PropertyValue   The property value to check the same property value.
> > > >> >>
> > > >> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to node offset with given property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtNodeOffsetByPropValue (
> > > >> >>
> > > >> >> +  IN CONST VOID   *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        StartOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *PropertyName,
> > > >> >>
> > > >> >> +  IN CONST VOID   *PropertyValue,
> > > >> >>
> > > >> >> +  IN INT32        PropertyLength
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a property with the given name from the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > > >> >>
> > > >> >> +  @param[in] Name           The name to the property which need be searched
> > > >> >>
> > > >> >> +  @param[in] Length         The length to the size of the property found.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The property to the structure of the found property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +CONST FDT_PROPERTY *
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtGetProperty (
> > > >> >>
> > > >> >> +  IN CONST VOID   *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        NodeOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *Name,
> > > >> >>
> > > >> >> +  IN INT32        *Length
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of first property in the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to the node which need be searched.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to first property offset in the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtFirstPropertyOffset (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       NodeOffset
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of next property from the given property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to previous property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to next property offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtNextPropertyOffset (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a property from the given offset of the property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to the given offset of the property.
> > > >> >>
> > > >> >> +  @param[in] Length         The length to the size of the property found.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The property to the structure of the given property offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +CONST FDT_PROPERTY *
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtGetPropertyByOffset (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset,
> > > >> >>
> > > >> >> +  IN INT32       *Length
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a string by the given string offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> > > >> >>
> > > >> >> +  @param[in] Length         The length to the size of string which need be retrieved.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The string to the given string offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +CONST CHAR8 *
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtGetString (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       StrOffset,
> > > >> >>
> > > >> >> +  IN INT32       *Length        OPTIONAL
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Add a new node to the FDT.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> > > >> >>
> > > >> >> +  @param[in] Name           The name to name the node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return  The offset to the new node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtAddSubnode (
> > > >> >>
> > > >> >> +  IN VOID         *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        ParentOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *Name
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Add or modify a property in the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> > > >> >>
> > > >> >> +  @param[in] Name           The name to name the property.
> > > >> >>
> > > >> >> +  @param[in] Value          The value to the property value.
> > > >> >>
> > > >> >> +  @param[in] Length         The length to the size of the property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return  Zero for successfully, otherwise failed.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtSetProp (
> > > >> >>
> > > >> >> +  IN VOID         *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        NodeOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *Name,
> > > >> >>
> > > >> >> +  IN CONST VOID   *Value,
> > > >> >>
> > > >> >> +  IN UINT32       Length
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#endif /* FDT_LIB_H_ */
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..730e568ff6
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > >> >> @@ -0,0 +1,62 @@
> > > >> >> +## @file
> > > >> >>
> > > >> >> +# Flattened Device Tree Library.
> > > >> >>
> > > >> >> +#
> > > >> >>
> > > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +#
> > > >> >>
> > > >> >> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +#
> > > >> >>
> > > >> >> +#
> > > >> >>
> > > >> >> +##
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +[Defines]
> > > >> >>
> > > >> >> +  INF_VERSION                    = 0x0001001B
> > > >> >>
> > > >> >> +  BASE_NAME                      = BaseFdtLib
> > > >> >>
> > > >> >> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> > > >> >>
> > > >> >> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-E8CEC206DE04
> > > >> >>
> > > >> >> +  MODULE_TYPE                    = BASE
> > > >> >>
> > > >> >> +  VERSION_STRING                 = 1.0
> > > >> >>
> > > >> >> +  LIBRARY_CLASS                  = FdtLib
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#
> > > >> >>
> > > >> >> +#  VALID_ARCHITECTURES           = IA32 X64
> > > >> >>
> > > >> >> +#
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +[Sources]
> > > >> >>
> > > >> >> +  FdtLib.c
> > > >> >>
> > > >> >> +  LibFdtWrapper.c
> > > >> >>
> > > >> >> +  # header Wrapper files
> > > >> >>
> > > >> >> +  limits.h
> > > >> >>
> > > >> >> +  stdbool.h
> > > >> >>
> > > >> >> +  stddef.h
> > > >> >>
> > > >> >> +  stdint.h
> > > >> >>
> > > >> >> +  stdlib.h
> > > >> >>
> > > >> >> +  string.h
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt.h
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt_addresses.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt_check.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt_overlay.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt_ro.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt_rw.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt_strerror.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt_sw.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/fdt_wip.c
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/libfdt.h
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/libfdt_env.h
> > > >> >>
> > > >> >> +  $(FDT_LIB_PATH)/libfdt_internal.h
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +[Packages]
> > > >> >>
> > > >> >> +  MdePkg/MdePkg.dec
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +[LibraryClasses]
> > > >> >>
> > > >> >> +  BaseLib
> > > >> >>
> > > >> >> +  BaseMemoryLib
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +[BuildOptions]
> > > >> >>
> > > >> >> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> > > >> >>
> > > >> >> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..3f7e45ea6f
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > >> >> @@ -0,0 +1,14 @@
> > > >> >> +// /** @file
> > > >> >>
> > > >> >> +// Flattened Device Tree Library.
> > > >> >>
> > > >> >> +//
> > > >> >>
> > > >> >> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +//
> > > >> >>
> > > >> >> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +//
> > > >> >>
> > > >> >> +// **/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#string STR_MODULE_ABSTRACT             #language en-US "Instance of FDT Library"
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#string STR_MODULE_DESCRIPTION          #language en-US "This module provides FDT Library implementation."
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > >> >> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..200a496c7e
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > >> >> @@ -0,0 +1,301 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  Flattened Device Tree Library.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#include <libfdt/libfdt/libfdt.h>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Verify the header of the Flattened Device Tree
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return Zero for successfully, otherwise failed.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtCheckHeader (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_check_header(Fdt);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Create a empty Flattened Device Tree.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> > > >> >>
> > > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return Zero for successfully, otherwise failed.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtCreateEmptyTree (
> > > >> >>
> > > >> >> +  IN VOID    *Buffer,
> > > >> >>
> > > >> >> +  IN UINT32  BufferSize
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of next node from the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to previous node.
> > > >> >>
> > > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to next node offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtNextNode (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset,
> > > >> >>
> > > >> >> +  IN INT32       *Depth
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_next_node (Fdt, Offset, Depth);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of first node under the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to previous node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to next node offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtFirstSubnode (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_first_subnode (Fdt, Offset);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of next node from the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to previous node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to next node offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtNextSubnode (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_next_subnode (Fdt, Offset);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of first node which includes the given name.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] ParentOffset    The offset to the node which start find under.
> > > >> >>
> > > >> >> +  @param[in] Name            The name to search the node with the name.
> > > >> >>
> > > >> >> +  @param[in] NameLength      The length of the name to check only.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to node offset with given node name.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtSubnodeOffsetNameLen (
> > > >> >>
> > > >> >> +  IN CONST VOID   *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        ParentOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *Name,
> > > >> >>
> > > >> >> +  IN INT32        NameLength
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name,
> > > >> >> + NameLength);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of first node which includes the given property name and value.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > > >> >>
> > > >> >> +  @param[in] PropertyName    The property name to search the node including the named property.
> > > >> >>
> > > >> >> +  @param[in] PropertyValue   The property value to check the same property value.
> > > >> >>
> > > >> >> +  @param[in] PropertyLength  The length of the value in PropertValue.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to node offset with given property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtNodeOffsetByPropValue (
> > > >> >>
> > > >> >> +  IN CONST VOID   *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        StartOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *PropertyName,
> > > >> >>
> > > >> >> +  IN CONST VOID   *PropertyValue,
> > > >> >>
> > > >> >> +  IN INT32        PropertyLength
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> > > >> >> + PropertyName, PropertyValue, PropertyLength);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a property with the given name from the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > > >> >>
> > > >> >> +  @param[in] Name           The name to the property which need be searched
> > > >> >>
> > > >> >> +  @param[in] Length         The length to the size of the property found.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The property to the structure of the found property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +CONST struct fdt_property *
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtGetProperty (
> > > >> >>
> > > >> >> +  IN CONST VOID   *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        NodeOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *Name,
> > > >> >>
> > > >> >> +  IN INT32        *Length
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of first property in the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] NodeOffset     The offset to the node which need be searched.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to first property offset in the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtFirstPropertyOffset (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       NodeOffset
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_first_property_offset (Fdt, NodeOffset);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a offset of next property from the given property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to previous property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The offset to next property offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtNextPropertyOffset (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_next_property_offset (Fdt, Offset);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a property from the given offset of the property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] Offset         The offset to the given offset of the property.
> > > >> >>
> > > >> >> +  @param[in] Length         The length to the size of the property found.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The property to the structure of the given property offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +CONST struct fdt_property *
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtGetPropertyByOffset (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       Offset,
> > > >> >>
> > > >> >> +  IN INT32       *Length
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Returns a string by the given string offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] StrOffset      The offset to the location in the strings block of FDT.
> > > >> >>
> > > >> >> +  @param[in] Length         The length to the size of string which need be retrieved.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return The string to the given string offset.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +CONST CHAR8 *
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtGetString (
> > > >> >>
> > > >> >> +  IN CONST VOID  *Fdt,
> > > >> >>
> > > >> >> +  IN INT32       StrOffset,
> > > >> >>
> > > >> >> +  IN INT32       *Length        OPTIONAL
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_get_string (Fdt, StrOffset, Length);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Add a new node to the FDT.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] ParentOffset   The offset to the node offset which want to add in.
> > > >> >>
> > > >> >> +  @param[in] Name           The name to name the node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return  The offset to the new node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtAddSubnode (
> > > >> >>
> > > >> >> +  IN VOID         *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        ParentOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *Name
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +/**
> > > >> >>
> > > >> >> +  Add or modify a property in the given node.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > >> >>
> > > >> >> +  @param[in] NodeOffset     The offset to the node offset which want to add in.
> > > >> >>
> > > >> >> +  @param[in] Name           The name to name the property.
> > > >> >>
> > > >> >> +  @param[in] Value          The value to the property value.
> > > >> >>
> > > >> >> +  @param[in] Length         The length to the size of the property.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  @return  Zero for successfully, otherwise failed.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +INT32
> > > >> >>
> > > >> >> +EFIAPI
> > > >> >>
> > > >> >> +FdtSetProp (
> > > >> >>
> > > >> >> +  IN VOID         *Fdt,
> > > >> >>
> > > >> >> +  IN INT32        NodeOffset,
> > > >> >>
> > > >> >> +  IN CONST CHAR8  *Name,
> > > >> >>
> > > >> >> +  IN CONST VOID   *Value,
> > > >> >>
> > > >> >> +  IN UINT32       Length
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..e738f4ded4
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > >> >> @@ -0,0 +1,99 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  Root include file of C runtime library to support building the
> > > >> >> + third-party
> > > >> >>
> > > >> >> +  libfdt library.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#ifndef FDT_LIB_SUPPORT_H_
> > > >> >>
> > > >> >> +#define FDT_LIB_SUPPORT_H_
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#include <Base.h>
> > > >> >>
> > > >> >> +#include <Library/BaseLib.h>
> > > >> >>
> > > >> >> +#include <Library/BaseMemoryLib.h>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +typedef UINT8    uint8_t;
> > > >> >>
> > > >> >> +typedef UINT16   uint16_t;
> > > >> >>
> > > >> >> +typedef INT32    int32_t;
> > > >> >>
> > > >> >> +typedef UINT32   uint32_t;
> > > >> >>
> > > >> >> +typedef UINT64   uint64_t;
> > > >> >>
> > > >> >> +typedef UINTN    uintptr_t;
> > > >> >>
> > > >> >> +typedef UINTN    size_t;
> > > >> >>
> > > >> >> +typedef BOOLEAN  bool;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#define true   (1 == 1)
> > > >> >>
> > > >> >> +#define false  (1 == 0)
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +//
> > > >> >>
> > > >> >> +// Definitions for global constants used by libfdt library
> > > >> >> +routines
> > > >> >>
> > > >> >> +//
> > > >> >>
> > > >> >> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value */
> > > >> >>
> > > >> >> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32 value */
> > > >> >>
> > > >> >> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32 value */
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +//
> > > >> >>
> > > >> >> +// Function prototypes of libfdt Library routines
> > > >> >>
> > > >> >> +//
> > > >> >>
> > > >> >> +void *
> > > >> >>
> > > >> >> +memset     (
> > > >> >>
> > > >> >> +  void *,
> > > >> >>
> > > >> >> +  int,
> > > >> >>
> > > >> >> +  size_t
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +int
> > > >> >>
> > > >> >> +memcmp      (
> > > >> >>
> > > >> >> +  const void *,
> > > >> >>
> > > >> >> +  const void *,
> > > >> >>
> > > >> >> +  size_t
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +int
> > > >> >>
> > > >> >> +strcmp      (
> > > >> >>
> > > >> >> +  const char *,
> > > >> >>
> > > >> >> +  const char *
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +char *
> > > >> >>
> > > >> >> +strchr     (
> > > >> >>
> > > >> >> +  const char *,
> > > >> >>
> > > >> >> +  int
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +char *
> > > >> >>
> > > >> >> +strrchr    (
> > > >> >>
> > > >> >> +  const char *,
> > > >> >>
> > > >> >> +  int
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +unsigned long
> > > >> >>
> > > >> >> +strtoul     (
> > > >> >>
> > > >> >> +  const char *,
> > > >> >>
> > > >> >> +  char **,
> > > >> >>
> > > >> >> +  int
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +char *
> > > >> >>
> > > >> >> +strcpy (
> > > >> >>
> > > >> >> +  char        *strDest,
> > > >> >>
> > > >> >> +  const char  *strSource
> > > >> >>
> > > >> >> +  );
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +//
> > > >> >>
> > > >> >> +// Macros that directly map functions to BaseLib, BaseMemoryLib,
> > > >> >> +and DebugLib functions
> > > >> >>
> > > >> >> +//
> > > >> >>
> > > >> >> +#define memcpy(dest, source, count)         CopyMem(dest,source, (UINTN)(count))
> > > >> >>
> > > >> >> +#define memset(dest, ch, count)             SetMem(dest, (UINTN)(count),(UINT8)(ch))
> > > >> >>
> > > >> >> +#define memchr(buf, ch, count)              ScanMem8(buf, (UINTN)(count),(UINT8)ch)
> > > >> >>
> > > >> >> +#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1, buf2, (UINTN)(count)))
> > > >> >>
> > > >> >> +#define memmove(dest, source, count)        CopyMem(dest, source, (UINTN)(count))
> > > >> >>
> > > >> >> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> > > >> >>
> > > >> >> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
> > > >> >>
> > > >> >> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest,
> > > >> >> +MAX_STRING_SIZE, strSource, (UINTN)count)
> > > >> >>
> > > >> >> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest, MAX_STRING_SIZE, strSource)
> > > >> >>
> > > >> >> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1, string2))
> > > >> >>
> > > >> >> +#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1, string2, (UINTN)(count)))
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#endif /* FDT_LIB_SUPPORT_H_ */
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..772bba4839
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > >> >> @@ -0,0 +1,173 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  ISO C implementations of strchr, strrchr and strtoul.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> > > >> >>
> > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#include <Base.h>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long value */
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +// Very quick notes:
> > > >> >>
> > > >> >> +// We only go through the string once for both functions
> > > >> >>
> > > >> >> +// They are minimal implementations (not speed optimized) of ISO C
> > > >> >> +semantics
> > > >> >>
> > > >> >> +// strchr and strrchr also include the null terminator as part of
> > > >> >> +the string
> > > >> >>
> > > >> >> +// so the code gets a bit clunky to handle that case specifically.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +char *
> > > >> >>
> > > >> >> +strchr (
> > > >> >>
> > > >> >> +  const char  *Str,
> > > >> >>
> > > >> >> +  int         Char
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  char  *S;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  S = (char *)Str;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  for ( ; ; S++) {
> > > >> >>
> > > >> >> +    if (*S == Char) {
> > > >> >>
> > > >> >> +      return S;
> > > >> >>
> > > >> >> +    }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +    if (*S == '\0') {
> > > >> >>
> > > >> >> +      return NULL;
> > > >> >>
> > > >> >> +    }
> > > >> >>
> > > >> >> +  }
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +char *
> > > >> >>
> > > >> >> +strrchr (
> > > >> >>
> > > >> >> +  const char  *Str,
> > > >> >>
> > > >> >> +  int         Char
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  char  *S, *last;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  S    = (char *)Str;
> > > >> >>
> > > >> >> +  last = NULL;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  for ( ; ; S++) {
> > > >> >>
> > > >> >> +    if (*S == Char) {
> > > >> >>
> > > >> >> +      last = S;
> > > >> >>
> > > >> >> +    }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +    if (*S == '\0') {
> > > >> >>
> > > >> >> +      return last;
> > > >> >>
> > > >> >> +    }
> > > >> >>
> > > >> >> +  }
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +STATIC
> > > >> >>
> > > >> >> +int
> > > >> >>
> > > >> >> +__isspace (
> > > >> >>
> > > >> >> +  int  ch
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  // basic ASCII ctype.h:isspace(). Not efficient
> > > >> >>
> > > >> >> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
> > > >> >> + == '\v' || ch == '\f';
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +unsigned long
> > > >> >>
> > > >> >> +strtoul (
> > > >> >>
> > > >> >> +  const char  *Nptr,
> > > >> >>
> > > >> >> +  char        **EndPtr,
> > > >> >>
> > > >> >> +  int         Base
> > > >> >>
> > > >> >> +  )
> > > >> >>
> > > >> >> +{
> > > >> >>
> > > >> >> +  BOOLEAN        Negate;
> > > >> >>
> > > >> >> +  BOOLEAN        Overflow;
> > > >> >>
> > > >> >> +  unsigned long  Val;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  Negate   = FALSE;
> > > >> >>
> > > >> >> +  Overflow = FALSE;
> > > >> >>
> > > >> >> +  Val      = 0;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  // Reject bad numeric bases
> > > >> >>
> > > >> >> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> > > >> >>
> > > >> >> +    return 0;
> > > >> >>
> > > >> >> +  }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  // Skip whitespace
> > > >> >>
> > > >> >> +  while (__isspace (*Nptr)) {
> > > >> >>
> > > >> >> +    Nptr++;
> > > >> >>
> > > >> >> +  }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  // Check for + or - prefixes
> > > >> >>
> > > >> >> +  if (*Nptr == '-') {
> > > >> >>
> > > >> >> +    Negate = TRUE;
> > > >> >>
> > > >> >> +    Nptr++;
> > > >> >>
> > > >> >> +  } else if (*Nptr == '+') {
> > > >> >>
> > > >> >> +    Nptr++;
> > > >> >>
> > > >> >> +  }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  // Consume the start, autodetecting base if needed
> > > >> >>
> > > >> >> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
> > > >> >> + && ((Base == 0) || (Base == 16))) {
> > > >> >>
> > > >> >> +    // Hex
> > > >> >>
> > > >> >> +    Nptr += 2;
> > > >> >>
> > > >> >> +    Base  = 16;
> > > >> >>
> > > >> >> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> > > >> >> + 'B')) && ((Base == 0) || (Base == 2))) {
> > > >> >>
> > > >> >> +    // Binary (standard pending C23)
> > > >> >>
> > > >> >> +    Nptr += 2;
> > > >> >>
> > > >> >> +    Base  = 2;
> > > >> >>
> > > >> >> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> > > >> >>
> > > >> >> +    // Octal
> > > >> >>
> > > >> >> +    Nptr++;
> > > >> >>
> > > >> >> +    Base = 8;
> > > >> >>
> > > >> >> +  } else {
> > > >> >>
> > > >> >> +    if (Base == 0) {
> > > >> >>
> > > >> >> +      // Assume decimal
> > > >> >>
> > > >> >> +      Base = 10;
> > > >> >>
> > > >> >> +    }
> > > >> >>
> > > >> >> +  }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  while (TRUE) {
> > > >> >>
> > > >> >> +    int            Digit;
> > > >> >>
> > > >> >> +    char           C;
> > > >> >>
> > > >> >> +    unsigned long  NewVal;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +    C     = *Nptr;
> > > >> >>
> > > >> >> +    Digit = -1;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +    if ((C >= '0') && (C <= '9')) {
> > > >> >>
> > > >> >> +      Digit = C - '0';
> > > >> >>
> > > >> >> +    } else if ((C >= 'a') && (C <= 'z')) {
> > > >> >>
> > > >> >> +      Digit = C - 'a' + 10;
> > > >> >>
> > > >> >> +    } else if ((C >= 'A') && (C <= 'Z')) {
> > > >> >>
> > > >> >> +      Digit = C - 'A' + 10;
> > > >> >>
> > > >> >> +    }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +    if ((Digit == -1) || (Digit >= Base)) {
> > > >> >>
> > > >> >> +      // Note that this case also handles the \0
> > > >> >>
> > > >> >> +      if (EndPtr) {
> > > >> >>
> > > >> >> +        *EndPtr = (char *)Nptr;
> > > >> >>
> > > >> >> +      }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +      break;
> > > >> >>
> > > >> >> +    }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +    NewVal = Val * Base + Digit;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +    if (NewVal < Val) {
> > > >> >>
> > > >> >> +      // Overflow
> > > >> >>
> > > >> >> +      Overflow = TRUE;
> > > >> >>
> > > >> >> +    }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +    Val = NewVal;
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +    Nptr++;
> > > >> >>
> > > >> >> +  }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  if (Negate) {
> > > >> >>
> > > >> >> +    Val = -Val;
> > > >> >>
> > > >> >> +  }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  if (Overflow) {
> > > >> >>
> > > >> >> +    Val = ULONG_MAX;
> > > >> >>
> > > >> >> +  }
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +  // TODO: We're lacking errno here.
> > > >> >>
> > > >> >> +  return Val;
> > > >> >>
> > > >> >> +}
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> > > >> >> b/MdePkg/Library/BaseFdtLib/limits.h
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..f6cf8d5702
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> > > >> >> @@ -0,0 +1,10 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  Include file to support building the third-party libfdt library.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#include <LibFdtSupport.h>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> > > >> >> b/MdePkg/Library/BaseFdtLib/stdbool.h
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..f6cf8d5702
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> > > >> >> @@ -0,0 +1,10 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  Include file to support building the third-party libfdt library.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#include <LibFdtSupport.h>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> > > >> >> b/MdePkg/Library/BaseFdtLib/stddef.h
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..f6cf8d5702
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> > > >> >> @@ -0,0 +1,10 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  Include file to support building the third-party libfdt library.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#include <LibFdtSupport.h>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> > > >> >> b/MdePkg/Library/BaseFdtLib/stdint.h
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..f6cf8d5702
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> > > >> >> @@ -0,0 +1,10 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  Include file to support building the third-party libfdt library.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#include <LibFdtSupport.h>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> > > >> >> b/MdePkg/Library/BaseFdtLib/stdlib.h
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..f6cf8d5702
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> > > >> >> @@ -0,0 +1,10 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  Include file to support building the third-party libfdt library.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#include <LibFdtSupport.h>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> > > >> >> b/MdePkg/Library/BaseFdtLib/string.h
> > > >> >> new file mode 100644
> > > >> >> index 0000000000..f6cf8d5702
> > > >> >> --- /dev/null
> > > >> >> +++ b/MdePkg/Library/BaseFdtLib/string.h
> > > >> >> @@ -0,0 +1,10 @@
> > > >> >> +/** @file
> > > >> >>
> > > >> >> +  Include file to support building the third-party libfdt library.
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +**/
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> +#include <LibFdtSupport.h>
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index
> > > >> >> 6ba85ebe61..f039daccdb 100644
> > > >> >> --- a/MdePkg/MdePkg.ci.yaml
> > > >> >> +++ b/MdePkg/MdePkg.ci.yaml
> > > >> >> @@ -2,7 +2,7 @@
> > > >> >>  # CI configuration for MdePkg
> > > >> >>
> > > >> >>  #
> > > >> >>
> > > >> >>  # Copyright (c) Microsoft Corporation
> > > >> >>
> > > >> >> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > >> >>
> > > >> >>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> > > >> >>
> > > >> >>  # Copyright (c) 2023, Loongson Technology Corporation Limited. All
> > > >> >> rights reserved.<BR>
> > > >> >>
> > > >> >>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >> >>
> > > >> >> @@ -67,7 +67,8 @@
> > > >> >>              "Include/Library/PcdLib.h",
> > > >> >>
> > > >> >>              "Include/Library/SafeIntLib.h",
> > > >> >>
> > > >> >>              "Include/Protocol/DebugSupport.h",
> > > >> >>
> > > >> >> -            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> > > >> >>
> > > >> >> +
> > > >> >> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> > > >> >>
> > > >> >> +            "Library/BaseFdtLib"
> > > >> >>
> > > >> >>          ]
> > > >> >>
> > > >> >>      },
> > > >> >>
> > > >> >>      ## options defined ci/Plugin/CompilerPlugin
> > > >> >>
> > > >> >> @@ -164,5 +165,17 @@
> > > >> >>          "ExtendWords": [],           # words to extend to the dictionary for this package
> > > >> >>
> > > >> >>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
> > > >> >>
> > > >> >>          "AdditionalIncludePaths": [] # Additional paths to spell
> > > >> >> check (wildcards supported)
> > > >> >>
> > > >> >> +    },
> > > >> >>
> > > >> >> +    # options defined in .pytool/Plugin/UncrustifyCheck
> > > >> >>
> > > >> >> +    "UncrustifyCheck": {
> > > >> >>
> > > >> >> +        "IgnoreFiles": [
> > > >> >>
> > > >> >> +            "Library/BaseFdtLib/libfdt",
> > > >> >>
> > > >> >> +            "Library/BaseFdtLib/limits.h",
> > > >> >>
> > > >> >> +            "Library/BaseFdtLib/stdbool.h",
> > > >> >>
> > > >> >> +            "Library/BaseFdtLib/stddef.h",
> > > >> >>
> > > >> >> +            "Library/BaseFdtLib/stdint.h",
> > > >> >>
> > > >> >> +            "Library/BaseFdtLib/stdlib.h",
> > > >> >>
> > > >> >> +            "Library/BaseFdtLib/string.h"
> > > >> >>
> > > >> >> +        ]
> > > >> >>
> > > >> >>      }
> > > >> >>
> > > >> >>  }
> > > >> >>
> > > >> >> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> > > >> >> e70182bf7f..9804a7a6bd 100644
> > > >> >> --- a/MdePkg/MdePkg.dec
> > > >> >> +++ b/MdePkg/MdePkg.dec
> > > >> >> @@ -289,6 +289,10 @@
> > > >> >>    #
> > > >> >>
> > > >> >>    ArmTrngLib|Include/Library/ArmTrngLib.h
> > > >> >>
> > > >> >>
> > > >> >>
> > > >> >> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> > > >> >>
> > > >> >> +  #
> > > >> >>
> > > >> >> +  FdtLib|Include/Library/FdtLib.h
> > > >> >>
> > > >> >> +
> > > >> >>
> > > >> >>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> > > >> >>
> > > >> >>    ##  @libraryclass  Provides services to generate random number.
> > > >> >>
> > > >> >>    #
> > > >> >>
> > > >> >> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> > > >> >> 152c02991a..b38c863812 100644
> > > >> >> --- a/MdePkg/MdePkg.dsc
> > > >> >> +++ b/MdePkg/MdePkg.dsc
> > > >> >> @@ -137,6 +137,7 @@
> > > >> >>
> > > >> >> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> > > >> >>
> > > >> >>
> > > >> >>
> > > >> >>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> > > >> >>
> > > >> >> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > >> >>
> > > >> >>
> > > >> >>
> > > >> >>  [Components.IA32, Components.X64, Components.ARM,
> > > >> >> Components.AARCH64]
> > > >> >>
> > > >> >>    #
> > > >> >>
> > > >> >> --
> > > >> >> 2.39.1.windows.1
> > > >
> > > >
> >
> >
> > 
> >
> >

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-04-24 17:41               ` Michael D Kinney
@ 2023-04-26  5:21                 ` Chiu, Chasel
       [not found]                 ` <17596494A9010E70.30288@groups.io>
  1 sibling, 0 replies; 20+ messages in thread
From: Chiu, Chasel @ 2023-04-26  5:21 UTC (permalink / raw)
  To: devel@edk2.groups.io, Kinney, Michael D, Leif Lindholm
  Cc: Lin, Benny, Leif Lindholm, Gao, Liming, Liu, Zhiguang,
	Pedro Falcato


Hello,

Since platform may also define other FDT structures, this EDK2 library may not be able to convert all the FDT structures to little endian.
We might define a generic MACRO in library like CONVERT_FDT_DATA_TO_LITTLE_ENDIAN which can be used for all structure data, but it will be almost like calling SwapBytes** directly.
Any other suggestion?

Thanks,
Chasel


> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Michael D
> Kinney
> Sent: Monday, April 24, 2023 10:41 AM
> To: Leif Lindholm <quic_llindhol@quicinc.com>; devel@edk2.groups.io
> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu,
> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>;
> Kinney, Michael D <michael.d.kinney@intel.com>
> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> Hi Leif,
> 
> Do you have a proposal or small example on what you want to see
> in the library?
> 
> Mike
> 
> > -----Original Message-----
> > From: Leif Lindholm <quic_llindhol@quicinc.com>
> > Sent: Monday, April 24, 2023 10:29 AM
> > To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>
> > Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu,
> > Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> <pedro.falcato@gmail.com>
> > Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> >
> > Apologies, I was refactoring a git tree and switched off the world :)
> >
> > Well, being a bit late to the party ... my view is it would be
> > preferable if we put the byteswapping in the library.
> >
> > The DT format is *defined* to be big-endian, 32-bit cells. So frankly,
> > I have no problems with pushing responsibility onto individual
> > platforms if they have decided to be "clever" by ignoring that -
> > if that gets rid of a bunch of boilerplate for sensibly behaving platforms.
> >
> > Maybe another excuse for getting
> > https://github.com/tianocore/edk2-
> platforms/blob/master/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
> > into MdePkg?
> >
> > /
> >     Leif
> >
> > On Thu, Apr 20, 2023 at 16:44:03 +0000, Michael D Kinney wrote:
> > > Hi Leif,
> > >
> > > What is your opinion on FDT being big endian.
> > >
> > > Do we want the lib to help with that aspect, or leave it up to the consumer of
> the lib to
> > > convert as needed?  Seems like an area that could be very error prone if we
> are not
> > > careful.
> > >
> > > Mike
> > >
> > > > -----Original Message-----
> > > > From: Lin, Benny <benny.lin@intel.com>
> > > > Sent: Wednesday, April 19, 2023 9:25 PM
> > > > To: Kinney, Michael D <michael.d.kinney@intel.com>;
> devel@edk2.groups.io
> > > > Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > > > Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >
> > > >
> > > >
> > > > >-----Original Message-----
> > > > >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > > > >Sent: Thursday, April 20, 2023 5:04 AM
> > > > >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > > > >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu@intel.com>; Pedro Falcato
> > <pedro.falcato@gmail.com>; Kinney,
> > > > Michael D <michael.d.kinney@intel.com>
> > > > >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > > >
> > > > >Responses below
> > > > >
> > > > >Mike
> > > > >
> > > > >> -----Original Message-----
> > > > >> From: Lin, Benny <benny.lin@intel.com>
> > > > >> Sent: Wednesday, April 19, 2023 10:12 AM
> > > > >> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > > >> devel@edk2.groups.io
> > > > >> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > > >> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > > > >> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > > >>
> > > > >> Please find my feedback below.
> > > > >> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER,
> what do you think?
> > > > >>
> > > > >> QQQ
> > > > >> Benny
> > > > >>
> > > > >> >-----Original Message-----
> > > > >> >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > > > >> >Sent: Wednesday, April 19, 2023 11:54 PM
> > > > >> >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > > > >> >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > > >> ><zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>;
> > > > >> >Kinney,
> > > > >> Michael D <michael.d.kinney@intel.com>
> > > > >> >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > > >> >
> > > > >> >A few comments below.
> > > > >> >
> > > > >> >Mike
> > > > >> >
> > > > >> >> -----Original Message-----
> > > > >> >> From: Lin, Benny <benny.lin@intel.com>
> > > > >> >> Sent: Sunday, April 16, 2023 10:35 PM
> > > > >> >> To: devel@edk2.groups.io
> > > > >> >> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> > > > >> >> <michael.d.kinney@intel.com>; Gao, Liming
> > > > >> >> <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu@intel.com>;
> > > > >> >> Pedro Falcato <pedro.falcato@gmail.com>
> > > > >> >> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > > >> >>
> > > > >> >> From: Benny Lin <benny.lin@intel.com>
> > > > >> >>
> > > > >> >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> > > > >> >> Add FDT support in EDK2 by submodule 3rd party libfdt
> > > > >> >> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> > > > >> >> and refer to LibcLib implementation by Pedro.
> > > > >> >>
> > > > >> >> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > > > >> >> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > > > >> >> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > > > >> >> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> > > > >> >> Signed-off-by: Benny Lin <benny.lin@intel.com>
> > > > >> >> ---
> > > > >> >>  MdePkg/Include/Library/FdtLib.h           | 314
> ++++++++++++++++++++
> > > > >> >>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> > > > >> >> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> > > > >> >>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301
> +++++++++++++++++++
> > > > >> >>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> > > > >> >> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
> > > > >> >>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> > > > >> >>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> > > > >> >>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> > > > >> >>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> > > > >> >>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> > > > >> >>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
> > > > >> >>  MdePkg/MdePkg.ci.yaml                     |  17 +-
> > > > >> >>  MdePkg/MdePkg.dec                         |   4 +
> > > > >> >>  MdePkg/MdePkg.dsc                         |   1 +
> > > > >> >>  15 files changed, 1043 insertions(+), 2 deletions(-)
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Include/Library/FdtLib.h
> > > > >> >> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
> > > > >> >> 0000000000..d59b749c25
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Include/Library/FdtLib.h
> > > > >> >> @@ -0,0 +1,314 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  Flattened Device Tree Library.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#ifndef FDT_LIB_H_
> > > > >> >>
> > > > >> >> +#define FDT_LIB_H_
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +///
> > > > >> >>
> > > > >> >> +/// Flattened Device Tree definition
> > > > >> >>
> > > > >> >> +///
> > > > >> >>
> > > > >> >> +typedef struct {
> > > > >> >>
> > > > >> >> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> > > > >> >>
> > > > >> >> +  UINT32    TotalSize;           /* total size of DT block */
> > > > >> >>
> > > > >> >> +  UINT32    OffsetDtStruct;      /* offset to structure */
> > > > >> >>
> > > > >> >> +  UINT32    OffsetDtStrings;     /* offset to strings */
> > > > >> >>
> > > > >> >> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve map
> */
> > > > >> >>
> > > > >> >> +  UINT32    Version;             /* format version */
> > > > >> >>
> > > > >> >> +  UINT32    LastCompVersion;     /* last compatible version */
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  /* version 2 fields below */
> > > > >> >>
> > > > >> >> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
> > > > >> >>
> > > > >> >> +                                    booting on */
> > > > >> >>
> > > > >> >> +  /* version 3 fields below */
> > > > >> >>
> > > > >> >> +  UINT32    SizeDtStrings;       /* size of the strings block */
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  /* version 17 fields below */
> > > > >> >>
> > > > >> >> +  UINT32    SizeDtStruct;        /* size of the structure block */
> > > > >> >>
> > > > >> >> +} FDT_HEADER;
> > > > >> >
> > > > >> >I see the macros below use SwapBytes32() on all the fields from this
> > > > >> >structure.  Does this mean this structure is big >endian?  If
> > > > >> that is the case, then the description of this structure and all
> > > > >> individual fields must make that very clear >so any consumer of the
> > > > >> structure knows it does not follow the default endianness of UEFI/PI
> and that consumers >must either use the macros or
> > consumers
> > > > must use SwapBytes32() on their own when using this structure directly.
> > > > >>
> > > > >> Yes, it's big endian. I will complete more descriptions in patch v4.
> > > > >
> > > > >Would it be simpler if we have a lib service that converts the entire header
> from big endian to little endian.
> > > > >That way, the consumer can use the FDT_HEADER directly without any of
> the macros?
> > > > >
> > > > >Also, is the rest of the FDT blob also big endian?
> > > >
> > > > FDT blob format is binary encoding of FDT data with big endian. In addition,
> the consumer will set or get FDT data with FDT
> > blob. We
> > > > can complete more descriptions to warn consumers to be careful if just use
> header struct for mapping and get/set FDT data
> > with FDT
> > > > blob.
> > > >
> > > > For provide lib services that converts between big endian and little endian,
> we can provide a get header function to convert
> > between
> > > > big endian and little endian. However, we also need to consider the
> property value for setting and getting then we can
> > convert in
> > > > wrapper functions.
> > > >
> > > > For example,
> > > >
> > > > INT32
> > > > EFIAPI
> > > > FdtSetProp (
> > > >   IN VOID         *Fdt,
> > > >   IN INT32        NodeOffset,
> > > >   IN CONST CHAR8  *Name,
> > > >   IN CONST VOID   *Value,
> > > >   IN UINT32       Length
> > > >   )
> > > > {
> > > >   return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > > > }
> > > >
> > > > More functions for various byte width.
> > > > INT32
> > > > EFIAPI
> > > > FdtSetProp16 (
> > > >   IN VOID         *Fdt,
> > > >   IN INT32        NodeOffset,
> > > >   IN CONST CHAR8  *Name,
> > > >   IN CONST UINT16   *Value,
> > > >   IN UINT32       Length
> > > >   )
> > > > {
> > > >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value),
> (int)Length);
> > > > }
> > > >
> > > > INT32
> > > > EFIAPI
> > > > FdtSetProp32 (
> > > >   IN VOID         *Fdt,
> > > >   IN INT32        NodeOffset,
> > > >   IN CONST CHAR8  *Name,
> > > >   IN CONST UINT32   *Value,
> > > >   IN UINT32       Length
> > > >   )
> > > > {
> > > >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value),
> (int)Length);
> > > > }
> > > >
> > > > >>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +typedef struct {
> > > > >> >>
> > > > >> >> +  UINT64    Address;
> > > > >> >>
> > > > >> >> +  UINT64    Size;
> > > > >> >>
> > > > >> >> +} FDT_RESERVE_ENTRY;
> > > > >> >
> > > > >> >
> > > > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > > > >> >Can it be removed?
> > > > >>
> > > > >> I think we can remove it because it might be not used for further usage
> of FDT support.
> > > > >>
> > > > >> >
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +typedef struct {
> > > > >> >>
> > > > >> >> +  UINT32    Tag;
> > > > >> >>
> > > > >> >> +  CHAR8     Name[];
> > > > >> >>
> > > > >> >> +} FDT_NODE_HEADER;
> > > > >> >
> > > > >> >
> > > > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > > > >> >Can it be removed?
> > > > >>
> > > > >> When we need retrieve a node from a FDT blob, we will get a node
> > > > >> offset then we could use the struct to map the node content. It's very
> useful.
> > > > >
> > > > >Please add a comment header for this structure and describe the usage as
> it related to the rest of the FdtLib >services.
> > > >
> > > > I will add descriptions for the usage and remove FDT_RESERVE_ENTRY in
> patch v4.
> > > >
> > > > >
> > > > >>
> > > > >> >
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +typedef struct {
> > > > >> >>
> > > > >> >> +  UINT32    Tag;
> > > > >> >>
> > > > >> >> +  UINT32    Length;
> > > > >> >>
> > > > >> >> +  UINT32    NameOffset;
> > > > >> >>
> > > > >> >> +  CHAR8     Data[];
> > > > >> >>
> > > > >> >> +} FDT_PROPERTY;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST
> FDT_HEADER
> > > > >> >> +*)(Fdt))->Field)
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
> > > > >> >>
> > > > >> >> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt,
> TotalSize))
> > > > >> >>
> > > > >> >> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt,
> OffsetDtStruct))
> > > > >> >>
> > > > >> >> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
> > > > >> >> +OffsetDtStrings))
> > > > >> >>
> > > > >> >> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
> > > > >> >> +OffsetMemRsvmap))
> > > > >> >>
> > > > >> >> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
> > > > >> >>
> > > > >> >> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
> > > > >> >> +LastCompVersion))
> > > > >> >>
> > > > >> >> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt,
> BootCpuidPhys))
> > > > >> >>
> > > > >> >> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt,
> SizeDtStrings))
> > > > >> >>
> > > > >> >> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt,
> SizeDtStruct))
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Verify the header of the Flattened Device Tree
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return Zero for successfully, otherwise failed.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtCheckHeader (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Create a empty Flattened Device Tree.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return Zero for successfully, otherwise failed.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +RETURN_STATUS
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtCreateEmptyTree (
> > > > >> >>
> > > > >> >> +  IN VOID   *Buffer,
> > > > >> >>
> > > > >> >> +  IN UINTN  BufferSize
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of next node from the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > >> >>
> > > > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to next node offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtNextNode (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset,
> > > > >> >>
> > > > >> >> +  IN INT32       *Depth
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of first node under the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to next node offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtFirstSubnode (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of next node from the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to next node offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtNextSubnode (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of first node which includes the given name.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] ParentOffset    The offset to the node which start find
> under.
> > > > >> >>
> > > > >> >> +  @param[in] Name            The name to search the node with the
> name.
> > > > >> >>
> > > > >> >> +  @param[in] NameLength      The length of the name to check only.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to node offset with given node name.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtSubnodeOffsetNameLen (
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        ParentOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *Name,
> > > > >> >>
> > > > >> >> +  IN INT32        NameLength
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of first node which includes the given property
> name and value.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > > > >> >>
> > > > >> >> +  @param[in] PropertyName    The property name to search the
> node including the named property.
> > > > >> >>
> > > > >> >> +  @param[in] PropertyValue   The property value to check the same
> property value.
> > > > >> >>
> > > > >> >> +  @param[in] PropertyLength  The length of the value in
> PropertValue.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to node offset with given property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtNodeOffsetByPropValue (
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        StartOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *PropertyName,
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *PropertyValue,
> > > > >> >>
> > > > >> >> +  IN INT32        PropertyLength
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a property with the given name from the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > > > >> >>
> > > > >> >> +  @param[in] Name           The name to the property which need be
> searched
> > > > >> >>
> > > > >> >> +  @param[in] Length         The length to the size of the property
> found.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The property to the structure of the found property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +CONST FDT_PROPERTY *
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtGetProperty (
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        NodeOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *Name,
> > > > >> >>
> > > > >> >> +  IN INT32        *Length
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of first property in the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to the node which need be
> searched.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to first property offset in the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtFirstPropertyOffset (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       NodeOffset
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of next property from the given property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to previous property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to next property offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtNextPropertyOffset (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a property from the given offset of the property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to the given offset of the
> property.
> > > > >> >>
> > > > >> >> +  @param[in] Length         The length to the size of the property
> found.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The property to the structure of the given property offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +CONST FDT_PROPERTY *
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtGetPropertyByOffset (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset,
> > > > >> >>
> > > > >> >> +  IN INT32       *Length
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a string by the given string offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] StrOffset      The offset to the location in the strings
> block of FDT.
> > > > >> >>
> > > > >> >> +  @param[in] Length         The length to the size of string which need
> be retrieved.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The string to the given string offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +CONST CHAR8 *
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtGetString (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       StrOffset,
> > > > >> >>
> > > > >> >> +  IN INT32       *Length        OPTIONAL
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Add a new node to the FDT.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] ParentOffset   The offset to the node offset which
> want to add in.
> > > > >> >>
> > > > >> >> +  @param[in] Name           The name to name the node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return  The offset to the new node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtAddSubnode (
> > > > >> >>
> > > > >> >> +  IN VOID         *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        ParentOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *Name
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Add or modify a property in the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] NodeOffset     The offset to the node offset which
> want to add in.
> > > > >> >>
> > > > >> >> +  @param[in] Name           The name to name the property.
> > > > >> >>
> > > > >> >> +  @param[in] Value          The value to the property value.
> > > > >> >>
> > > > >> >> +  @param[in] Length         The length to the size of the property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return  Zero for successfully, otherwise failed.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtSetProp (
> > > > >> >>
> > > > >> >> +  IN VOID         *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        NodeOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *Name,
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *Value,
> > > > >> >>
> > > > >> >> +  IN UINT32       Length
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#endif /* FDT_LIB_H_ */
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..730e568ff6
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > > >> >> @@ -0,0 +1,62 @@
> > > > >> >> +## @file
> > > > >> >>
> > > > >> >> +# Flattened Device Tree Library.
> > > > >> >>
> > > > >> >> +#
> > > > >> >>
> > > > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +#
> > > > >> >>
> > > > >> >> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +#
> > > > >> >>
> > > > >> >> +#
> > > > >> >>
> > > > >> >> +##
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +[Defines]
> > > > >> >>
> > > > >> >> +  INF_VERSION                    = 0x0001001B
> > > > >> >>
> > > > >> >> +  BASE_NAME                      = BaseFdtLib
> > > > >> >>
> > > > >> >> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> > > > >> >>
> > > > >> >> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-
> E8CEC206DE04
> > > > >> >>
> > > > >> >> +  MODULE_TYPE                    = BASE
> > > > >> >>
> > > > >> >> +  VERSION_STRING                 = 1.0
> > > > >> >>
> > > > >> >> +  LIBRARY_CLASS                  = FdtLib
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#
> > > > >> >>
> > > > >> >> +#  VALID_ARCHITECTURES           = IA32 X64
> > > > >> >>
> > > > >> >> +#
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +[Sources]
> > > > >> >>
> > > > >> >> +  FdtLib.c
> > > > >> >>
> > > > >> >> +  LibFdtWrapper.c
> > > > >> >>
> > > > >> >> +  # header Wrapper files
> > > > >> >>
> > > > >> >> +  limits.h
> > > > >> >>
> > > > >> >> +  stdbool.h
> > > > >> >>
> > > > >> >> +  stddef.h
> > > > >> >>
> > > > >> >> +  stdint.h
> > > > >> >>
> > > > >> >> +  stdlib.h
> > > > >> >>
> > > > >> >> +  string.h
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt.h
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt_addresses.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt_check.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt_overlay.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt_ro.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt_rw.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt_strerror.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt_sw.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/fdt_wip.c
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/libfdt.h
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/libfdt_env.h
> > > > >> >>
> > > > >> >> +  $(FDT_LIB_PATH)/libfdt_internal.h
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +[Packages]
> > > > >> >>
> > > > >> >> +  MdePkg/MdePkg.dec
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +[LibraryClasses]
> > > > >> >>
> > > > >> >> +  BaseLib
> > > > >> >>
> > > > >> >> +  BaseMemoryLib
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +[BuildOptions]
> > > > >> >>
> > > > >> >> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> > > > >> >>
> > > > >> >> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..3f7e45ea6f
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > > >> >> @@ -0,0 +1,14 @@
> > > > >> >> +// /** @file
> > > > >> >>
> > > > >> >> +// Flattened Device Tree Library.
> > > > >> >>
> > > > >> >> +//
> > > > >> >>
> > > > >> >> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +//
> > > > >> >>
> > > > >> >> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +//
> > > > >> >>
> > > > >> >> +// **/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#string STR_MODULE_ABSTRACT             #language en-US "Instance
> of FDT Library"
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#string STR_MODULE_DESCRIPTION          #language en-US "This
> module provides FDT Library implementation."
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > > >> >> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..200a496c7e
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > > >> >> @@ -0,0 +1,301 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  Flattened Device Tree Library.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#include <libfdt/libfdt/libfdt.h>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Verify the header of the Flattened Device Tree
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return Zero for successfully, otherwise failed.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtCheckHeader (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_check_header(Fdt);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Create a empty Flattened Device Tree.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return Zero for successfully, otherwise failed.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtCreateEmptyTree (
> > > > >> >>
> > > > >> >> +  IN VOID    *Buffer,
> > > > >> >>
> > > > >> >> +  IN UINT32  BufferSize
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of next node from the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > >> >>
> > > > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to next node offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtNextNode (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset,
> > > > >> >>
> > > > >> >> +  IN INT32       *Depth
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_next_node (Fdt, Offset, Depth);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of first node under the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to next node offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtFirstSubnode (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_first_subnode (Fdt, Offset);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of next node from the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to next node offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtNextSubnode (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_next_subnode (Fdt, Offset);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of first node which includes the given name.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] ParentOffset    The offset to the node which start find
> under.
> > > > >> >>
> > > > >> >> +  @param[in] Name            The name to search the node with the
> name.
> > > > >> >>
> > > > >> >> +  @param[in] NameLength      The length of the name to check only.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to node offset with given node name.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtSubnodeOffsetNameLen (
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        ParentOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *Name,
> > > > >> >>
> > > > >> >> +  IN INT32        NameLength
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name,
> > > > >> >> + NameLength);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of first node which includes the given property
> name and value.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > > > >> >>
> > > > >> >> +  @param[in] PropertyName    The property name to search the
> node including the named property.
> > > > >> >>
> > > > >> >> +  @param[in] PropertyValue   The property value to check the same
> property value.
> > > > >> >>
> > > > >> >> +  @param[in] PropertyLength  The length of the value in
> PropertValue.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to node offset with given property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtNodeOffsetByPropValue (
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        StartOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *PropertyName,
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *PropertyValue,
> > > > >> >>
> > > > >> >> +  IN INT32        PropertyLength
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> > > > >> >> + PropertyName, PropertyValue, PropertyLength);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a property with the given name from the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > > > >> >>
> > > > >> >> +  @param[in] Name           The name to the property which need be
> searched
> > > > >> >>
> > > > >> >> +  @param[in] Length         The length to the size of the property
> found.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The property to the structure of the found property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +CONST struct fdt_property *
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtGetProperty (
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        NodeOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *Name,
> > > > >> >>
> > > > >> >> +  IN INT32        *Length
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of first property in the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] NodeOffset     The offset to the node which need be
> searched.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to first property offset in the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtFirstPropertyOffset (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       NodeOffset
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_first_property_offset (Fdt, NodeOffset);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a offset of next property from the given property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to previous property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The offset to next property offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtNextPropertyOffset (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_next_property_offset (Fdt, Offset);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a property from the given offset of the property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] Offset         The offset to the given offset of the
> property.
> > > > >> >>
> > > > >> >> +  @param[in] Length         The length to the size of the property
> found.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The property to the structure of the given property offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +CONST struct fdt_property *
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtGetPropertyByOffset (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       Offset,
> > > > >> >>
> > > > >> >> +  IN INT32       *Length
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Returns a string by the given string offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] StrOffset      The offset to the location in the strings
> block of FDT.
> > > > >> >>
> > > > >> >> +  @param[in] Length         The length to the size of string which need
> be retrieved.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return The string to the given string offset.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +CONST CHAR8 *
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtGetString (
> > > > >> >>
> > > > >> >> +  IN CONST VOID  *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32       StrOffset,
> > > > >> >>
> > > > >> >> +  IN INT32       *Length        OPTIONAL
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_get_string (Fdt, StrOffset, Length);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Add a new node to the FDT.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] ParentOffset   The offset to the node offset which
> want to add in.
> > > > >> >>
> > > > >> >> +  @param[in] Name           The name to name the node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return  The offset to the new node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtAddSubnode (
> > > > >> >>
> > > > >> >> +  IN VOID         *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        ParentOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *Name
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +/**
> > > > >> >>
> > > > >> >> +  Add or modify a property in the given node.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > >> >>
> > > > >> >> +  @param[in] NodeOffset     The offset to the node offset which
> want to add in.
> > > > >> >>
> > > > >> >> +  @param[in] Name           The name to name the property.
> > > > >> >>
> > > > >> >> +  @param[in] Value          The value to the property value.
> > > > >> >>
> > > > >> >> +  @param[in] Length         The length to the size of the property.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  @return  Zero for successfully, otherwise failed.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +INT32
> > > > >> >>
> > > > >> >> +EFIAPI
> > > > >> >>
> > > > >> >> +FdtSetProp (
> > > > >> >>
> > > > >> >> +  IN VOID         *Fdt,
> > > > >> >>
> > > > >> >> +  IN INT32        NodeOffset,
> > > > >> >>
> > > > >> >> +  IN CONST CHAR8  *Name,
> > > > >> >>
> > > > >> >> +  IN CONST VOID   *Value,
> > > > >> >>
> > > > >> >> +  IN UINT32       Length
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..e738f4ded4
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > > >> >> @@ -0,0 +1,99 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  Root include file of C runtime library to support building the
> > > > >> >> + third-party
> > > > >> >>
> > > > >> >> +  libfdt library.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#ifndef FDT_LIB_SUPPORT_H_
> > > > >> >>
> > > > >> >> +#define FDT_LIB_SUPPORT_H_
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#include <Base.h>
> > > > >> >>
> > > > >> >> +#include <Library/BaseLib.h>
> > > > >> >>
> > > > >> >> +#include <Library/BaseMemoryLib.h>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +typedef UINT8    uint8_t;
> > > > >> >>
> > > > >> >> +typedef UINT16   uint16_t;
> > > > >> >>
> > > > >> >> +typedef INT32    int32_t;
> > > > >> >>
> > > > >> >> +typedef UINT32   uint32_t;
> > > > >> >>
> > > > >> >> +typedef UINT64   uint64_t;
> > > > >> >>
> > > > >> >> +typedef UINTN    uintptr_t;
> > > > >> >>
> > > > >> >> +typedef UINTN    size_t;
> > > > >> >>
> > > > >> >> +typedef BOOLEAN  bool;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#define true   (1 == 1)
> > > > >> >>
> > > > >> >> +#define false  (1 == 0)
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +//
> > > > >> >>
> > > > >> >> +// Definitions for global constants used by libfdt library
> > > > >> >> +routines
> > > > >> >>
> > > > >> >> +//
> > > > >> >>
> > > > >> >> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int value
> */
> > > > >> >>
> > > > >> >> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32
> value */
> > > > >> >>
> > > > >> >> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned int32
> value */
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +//
> > > > >> >>
> > > > >> >> +// Function prototypes of libfdt Library routines
> > > > >> >>
> > > > >> >> +//
> > > > >> >>
> > > > >> >> +void *
> > > > >> >>
> > > > >> >> +memset     (
> > > > >> >>
> > > > >> >> +  void *,
> > > > >> >>
> > > > >> >> +  int,
> > > > >> >>
> > > > >> >> +  size_t
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +int
> > > > >> >>
> > > > >> >> +memcmp      (
> > > > >> >>
> > > > >> >> +  const void *,
> > > > >> >>
> > > > >> >> +  const void *,
> > > > >> >>
> > > > >> >> +  size_t
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +int
> > > > >> >>
> > > > >> >> +strcmp      (
> > > > >> >>
> > > > >> >> +  const char *,
> > > > >> >>
> > > > >> >> +  const char *
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +char *
> > > > >> >>
> > > > >> >> +strchr     (
> > > > >> >>
> > > > >> >> +  const char *,
> > > > >> >>
> > > > >> >> +  int
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +char *
> > > > >> >>
> > > > >> >> +strrchr    (
> > > > >> >>
> > > > >> >> +  const char *,
> > > > >> >>
> > > > >> >> +  int
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +unsigned long
> > > > >> >>
> > > > >> >> +strtoul     (
> > > > >> >>
> > > > >> >> +  const char *,
> > > > >> >>
> > > > >> >> +  char **,
> > > > >> >>
> > > > >> >> +  int
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +char *
> > > > >> >>
> > > > >> >> +strcpy (
> > > > >> >>
> > > > >> >> +  char        *strDest,
> > > > >> >>
> > > > >> >> +  const char  *strSource
> > > > >> >>
> > > > >> >> +  );
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +//
> > > > >> >>
> > > > >> >> +// Macros that directly map functions to BaseLib, BaseMemoryLib,
> > > > >> >> +and DebugLib functions
> > > > >> >>
> > > > >> >> +//
> > > > >> >>
> > > > >> >> +#define memcpy(dest, source, count)         CopyMem(dest,source,
> (UINTN)(count))
> > > > >> >>
> > > > >> >> +#define memset(dest, ch, count)             SetMem(dest,
> (UINTN)(count),(UINT8)(ch))
> > > > >> >>
> > > > >> >> +#define memchr(buf, ch, count)              ScanMem8(buf,
> (UINTN)(count),(UINT8)ch)
> > > > >> >>
> > > > >> >> +#define memcmp(buf1, buf2, count)           (int)(CompareMem(buf1,
> buf2, (UINTN)(count)))
> > > > >> >>
> > > > >> >> +#define memmove(dest, source, count)        CopyMem(dest, source,
> (UINTN)(count))
> > > > >> >>
> > > > >> >> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> > > > >> >>
> > > > >> >> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str, count))
> > > > >> >>
> > > > >> >> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest,
> > > > >> >> +MAX_STRING_SIZE, strSource, (UINTN)count)
> > > > >> >>
> > > > >> >> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest,
> MAX_STRING_SIZE, strSource)
> > > > >> >>
> > > > >> >> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1,
> string2))
> > > > >> >>
> > > > >> >> +#define strncmp(string1, string2, count)    (int)(AsciiStrnCmp(string1,
> string2, (UINTN)(count)))
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#endif /* FDT_LIB_SUPPORT_H_ */
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..772bba4839
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > > >> >> @@ -0,0 +1,173 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  ISO C implementations of strchr, strrchr and strtoul.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> > > > >> >>
> > > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#include <Base.h>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned long
> value */
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +// Very quick notes:
> > > > >> >>
> > > > >> >> +// We only go through the string once for both functions
> > > > >> >>
> > > > >> >> +// They are minimal implementations (not speed optimized) of ISO C
> > > > >> >> +semantics
> > > > >> >>
> > > > >> >> +// strchr and strrchr also include the null terminator as part of
> > > > >> >> +the string
> > > > >> >>
> > > > >> >> +// so the code gets a bit clunky to handle that case specifically.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +char *
> > > > >> >>
> > > > >> >> +strchr (
> > > > >> >>
> > > > >> >> +  const char  *Str,
> > > > >> >>
> > > > >> >> +  int         Char
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  char  *S;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  S = (char *)Str;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  for ( ; ; S++) {
> > > > >> >>
> > > > >> >> +    if (*S == Char) {
> > > > >> >>
> > > > >> >> +      return S;
> > > > >> >>
> > > > >> >> +    }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +    if (*S == '\0') {
> > > > >> >>
> > > > >> >> +      return NULL;
> > > > >> >>
> > > > >> >> +    }
> > > > >> >>
> > > > >> >> +  }
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +char *
> > > > >> >>
> > > > >> >> +strrchr (
> > > > >> >>
> > > > >> >> +  const char  *Str,
> > > > >> >>
> > > > >> >> +  int         Char
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  char  *S, *last;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  S    = (char *)Str;
> > > > >> >>
> > > > >> >> +  last = NULL;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  for ( ; ; S++) {
> > > > >> >>
> > > > >> >> +    if (*S == Char) {
> > > > >> >>
> > > > >> >> +      last = S;
> > > > >> >>
> > > > >> >> +    }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +    if (*S == '\0') {
> > > > >> >>
> > > > >> >> +      return last;
> > > > >> >>
> > > > >> >> +    }
> > > > >> >>
> > > > >> >> +  }
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +STATIC
> > > > >> >>
> > > > >> >> +int
> > > > >> >>
> > > > >> >> +__isspace (
> > > > >> >>
> > > > >> >> +  int  ch
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  // basic ASCII ctype.h:isspace(). Not efficient
> > > > >> >>
> > > > >> >> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
> > > > >> >> + == '\v' || ch == '\f';
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +unsigned long
> > > > >> >>
> > > > >> >> +strtoul (
> > > > >> >>
> > > > >> >> +  const char  *Nptr,
> > > > >> >>
> > > > >> >> +  char        **EndPtr,
> > > > >> >>
> > > > >> >> +  int         Base
> > > > >> >>
> > > > >> >> +  )
> > > > >> >>
> > > > >> >> +{
> > > > >> >>
> > > > >> >> +  BOOLEAN        Negate;
> > > > >> >>
> > > > >> >> +  BOOLEAN        Overflow;
> > > > >> >>
> > > > >> >> +  unsigned long  Val;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  Negate   = FALSE;
> > > > >> >>
> > > > >> >> +  Overflow = FALSE;
> > > > >> >>
> > > > >> >> +  Val      = 0;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  // Reject bad numeric bases
> > > > >> >>
> > > > >> >> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> > > > >> >>
> > > > >> >> +    return 0;
> > > > >> >>
> > > > >> >> +  }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  // Skip whitespace
> > > > >> >>
> > > > >> >> +  while (__isspace (*Nptr)) {
> > > > >> >>
> > > > >> >> +    Nptr++;
> > > > >> >>
> > > > >> >> +  }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  // Check for + or - prefixes
> > > > >> >>
> > > > >> >> +  if (*Nptr == '-') {
> > > > >> >>
> > > > >> >> +    Negate = TRUE;
> > > > >> >>
> > > > >> >> +    Nptr++;
> > > > >> >>
> > > > >> >> +  } else if (*Nptr == '+') {
> > > > >> >>
> > > > >> >> +    Nptr++;
> > > > >> >>
> > > > >> >> +  }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  // Consume the start, autodetecting base if needed
> > > > >> >>
> > > > >> >> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
> > > > >> >> + && ((Base == 0) || (Base == 16))) {
> > > > >> >>
> > > > >> >> +    // Hex
> > > > >> >>
> > > > >> >> +    Nptr += 2;
> > > > >> >>
> > > > >> >> +    Base  = 16;
> > > > >> >>
> > > > >> >> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> > > > >> >> + 'B')) && ((Base == 0) || (Base == 2))) {
> > > > >> >>
> > > > >> >> +    // Binary (standard pending C23)
> > > > >> >>
> > > > >> >> +    Nptr += 2;
> > > > >> >>
> > > > >> >> +    Base  = 2;
> > > > >> >>
> > > > >> >> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> > > > >> >>
> > > > >> >> +    // Octal
> > > > >> >>
> > > > >> >> +    Nptr++;
> > > > >> >>
> > > > >> >> +    Base = 8;
> > > > >> >>
> > > > >> >> +  } else {
> > > > >> >>
> > > > >> >> +    if (Base == 0) {
> > > > >> >>
> > > > >> >> +      // Assume decimal
> > > > >> >>
> > > > >> >> +      Base = 10;
> > > > >> >>
> > > > >> >> +    }
> > > > >> >>
> > > > >> >> +  }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  while (TRUE) {
> > > > >> >>
> > > > >> >> +    int            Digit;
> > > > >> >>
> > > > >> >> +    char           C;
> > > > >> >>
> > > > >> >> +    unsigned long  NewVal;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +    C     = *Nptr;
> > > > >> >>
> > > > >> >> +    Digit = -1;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +    if ((C >= '0') && (C <= '9')) {
> > > > >> >>
> > > > >> >> +      Digit = C - '0';
> > > > >> >>
> > > > >> >> +    } else if ((C >= 'a') && (C <= 'z')) {
> > > > >> >>
> > > > >> >> +      Digit = C - 'a' + 10;
> > > > >> >>
> > > > >> >> +    } else if ((C >= 'A') && (C <= 'Z')) {
> > > > >> >>
> > > > >> >> +      Digit = C - 'A' + 10;
> > > > >> >>
> > > > >> >> +    }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +    if ((Digit == -1) || (Digit >= Base)) {
> > > > >> >>
> > > > >> >> +      // Note that this case also handles the \0
> > > > >> >>
> > > > >> >> +      if (EndPtr) {
> > > > >> >>
> > > > >> >> +        *EndPtr = (char *)Nptr;
> > > > >> >>
> > > > >> >> +      }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +      break;
> > > > >> >>
> > > > >> >> +    }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +    NewVal = Val * Base + Digit;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +    if (NewVal < Val) {
> > > > >> >>
> > > > >> >> +      // Overflow
> > > > >> >>
> > > > >> >> +      Overflow = TRUE;
> > > > >> >>
> > > > >> >> +    }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +    Val = NewVal;
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +    Nptr++;
> > > > >> >>
> > > > >> >> +  }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  if (Negate) {
> > > > >> >>
> > > > >> >> +    Val = -Val;
> > > > >> >>
> > > > >> >> +  }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  if (Overflow) {
> > > > >> >>
> > > > >> >> +    Val = ULONG_MAX;
> > > > >> >>
> > > > >> >> +  }
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +  // TODO: We're lacking errno here.
> > > > >> >>
> > > > >> >> +  return Val;
> > > > >> >>
> > > > >> >> +}
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> > > > >> >> b/MdePkg/Library/BaseFdtLib/limits.h
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..f6cf8d5702
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> > > > >> >> @@ -0,0 +1,10 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#include <LibFdtSupport.h>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> > > > >> >> b/MdePkg/Library/BaseFdtLib/stdbool.h
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..f6cf8d5702
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> > > > >> >> @@ -0,0 +1,10 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#include <LibFdtSupport.h>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> > > > >> >> b/MdePkg/Library/BaseFdtLib/stddef.h
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..f6cf8d5702
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> > > > >> >> @@ -0,0 +1,10 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#include <LibFdtSupport.h>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> > > > >> >> b/MdePkg/Library/BaseFdtLib/stdint.h
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..f6cf8d5702
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> > > > >> >> @@ -0,0 +1,10 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#include <LibFdtSupport.h>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> > > > >> >> b/MdePkg/Library/BaseFdtLib/stdlib.h
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..f6cf8d5702
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> > > > >> >> @@ -0,0 +1,10 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#include <LibFdtSupport.h>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> > > > >> >> b/MdePkg/Library/BaseFdtLib/string.h
> > > > >> >> new file mode 100644
> > > > >> >> index 0000000000..f6cf8d5702
> > > > >> >> --- /dev/null
> > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/string.h
> > > > >> >> @@ -0,0 +1,10 @@
> > > > >> >> +/** @file
> > > > >> >>
> > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +**/
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> +#include <LibFdtSupport.h>
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
> index
> > > > >> >> 6ba85ebe61..f039daccdb 100644
> > > > >> >> --- a/MdePkg/MdePkg.ci.yaml
> > > > >> >> +++ b/MdePkg/MdePkg.ci.yaml
> > > > >> >> @@ -2,7 +2,7 @@
> > > > >> >>  # CI configuration for MdePkg
> > > > >> >>
> > > > >> >>  #
> > > > >> >>
> > > > >> >>  # Copyright (c) Microsoft Corporation
> > > > >> >>
> > > > >> >> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > >> >>
> > > > >> >>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> > > > >> >>
> > > > >> >>  # Copyright (c) 2023, Loongson Technology Corporation Limited. All
> > > > >> >> rights reserved.<BR>
> > > > >> >>
> > > > >> >>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >> >>
> > > > >> >> @@ -67,7 +67,8 @@
> > > > >> >>              "Include/Library/PcdLib.h",
> > > > >> >>
> > > > >> >>              "Include/Library/SafeIntLib.h",
> > > > >> >>
> > > > >> >>              "Include/Protocol/DebugSupport.h",
> > > > >> >>
> > > > >> >> -            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> > > > >> >>
> > > > >> >> +
> > > > >> >> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> > > > >> >>
> > > > >> >> +            "Library/BaseFdtLib"
> > > > >> >>
> > > > >> >>          ]
> > > > >> >>
> > > > >> >>      },
> > > > >> >>
> > > > >> >>      ## options defined ci/Plugin/CompilerPlugin
> > > > >> >>
> > > > >> >> @@ -164,5 +165,17 @@
> > > > >> >>          "ExtendWords": [],           # words to extend to the dictionary for
> this package
> > > > >> >>
> > > > >> >>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that
> should be ignore
> > > > >> >>
> > > > >> >>          "AdditionalIncludePaths": [] # Additional paths to spell
> > > > >> >> check (wildcards supported)
> > > > >> >>
> > > > >> >> +    },
> > > > >> >>
> > > > >> >> +    # options defined in .pytool/Plugin/UncrustifyCheck
> > > > >> >>
> > > > >> >> +    "UncrustifyCheck": {
> > > > >> >>
> > > > >> >> +        "IgnoreFiles": [
> > > > >> >>
> > > > >> >> +            "Library/BaseFdtLib/libfdt",
> > > > >> >>
> > > > >> >> +            "Library/BaseFdtLib/limits.h",
> > > > >> >>
> > > > >> >> +            "Library/BaseFdtLib/stdbool.h",
> > > > >> >>
> > > > >> >> +            "Library/BaseFdtLib/stddef.h",
> > > > >> >>
> > > > >> >> +            "Library/BaseFdtLib/stdint.h",
> > > > >> >>
> > > > >> >> +            "Library/BaseFdtLib/stdlib.h",
> > > > >> >>
> > > > >> >> +            "Library/BaseFdtLib/string.h"
> > > > >> >>
> > > > >> >> +        ]
> > > > >> >>
> > > > >> >>      }
> > > > >> >>
> > > > >> >>  }
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> > > > >> >> e70182bf7f..9804a7a6bd 100644
> > > > >> >> --- a/MdePkg/MdePkg.dec
> > > > >> >> +++ b/MdePkg/MdePkg.dec
> > > > >> >> @@ -289,6 +289,10 @@
> > > > >> >>    #
> > > > >> >>
> > > > >> >>    ArmTrngLib|Include/Library/ArmTrngLib.h
> > > > >> >>
> > > > >> >>
> > > > >> >>
> > > > >> >> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> > > > >> >>
> > > > >> >> +  #
> > > > >> >>
> > > > >> >> +  FdtLib|Include/Library/FdtLib.h
> > > > >> >>
> > > > >> >> +
> > > > >> >>
> > > > >> >>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> > > > >> >>
> > > > >> >>    ##  @libraryclass  Provides services to generate random number.
> > > > >> >>
> > > > >> >>    #
> > > > >> >>
> > > > >> >> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> > > > >> >> 152c02991a..b38c863812 100644
> > > > >> >> --- a/MdePkg/MdePkg.dsc
> > > > >> >> +++ b/MdePkg/MdePkg.dsc
> > > > >> >> @@ -137,6 +137,7 @@
> > > > >> >>
> > > > >> >>
> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> > > > >> >>
> > > > >> >>
> > > > >> >>
> > > > >> >>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> > > > >> >>
> > > > >> >> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > > >> >>
> > > > >> >>
> > > > >> >>
> > > > >> >>  [Components.IA32, Components.X64, Components.ARM,
> > > > >> >> Components.AARCH64]
> > > > >> >>
> > > > >> >>    #
> > > > >> >>
> > > > >> >> --
> > > > >> >> 2.39.1.windows.1
> > > > >
> > > > >
> > >
> > >
> > >
> > >
> > >
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
       [not found]                 ` <17596494A9010E70.30288@groups.io>
@ 2023-05-01 16:31                   ` Chiu, Chasel
  2023-05-02 11:41                     ` Leif Lindholm
  0 siblings, 1 reply; 20+ messages in thread
From: Chiu, Chasel @ 2023-05-01 16:31 UTC (permalink / raw)
  To: devel@edk2.groups.io, Chiu, Chasel, Kinney, Michael D,
	Leif Lindholm
  Cc: Lin, Benny, Leif Lindholm, Gao, Liming, Liu, Zhiguang,
	Pedro Falcato


Hi Leif,

Would you please share your ideas and respond Mike's question too?

Thanks,
Chasel



> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chiu, Chasel
> Sent: Tuesday, April 25, 2023 10:22 PM
> To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>;
> Leif Lindholm <quic_llindhol@quicinc.com>
> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu,
> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> 
> Hello,
> 
> Since platform may also define other FDT structures, this EDK2 library may not
> be able to convert all the FDT structures to little endian.
> We might define a generic MACRO in library like
> CONVERT_FDT_DATA_TO_LITTLE_ENDIAN which can be used for all structure
> data, but it will be almost like calling SwapBytes** directly.
> Any other suggestion?
> 
> Thanks,
> Chasel
> 
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Michael D
> > Kinney
> > Sent: Monday, April 24, 2023 10:41 AM
> > To: Leif Lindholm <quic_llindhol@quicinc.com>; devel@edk2.groups.io
> > Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> > <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
> Liu,
> > Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> <pedro.falcato@gmail.com>;
> > Kinney, Michael D <michael.d.kinney@intel.com>
> > Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> >
> > Hi Leif,
> >
> > Do you have a proposal or small example on what you want to see
> > in the library?
> >
> > Mike
> >
> > > -----Original Message-----
> > > From: Leif Lindholm <quic_llindhol@quicinc.com>
> > > Sent: Monday, April 24, 2023 10:29 AM
> > > To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>
> > > Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> > <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
> Liu,
> > > Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> > <pedro.falcato@gmail.com>
> > > Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> > >
> > > Apologies, I was refactoring a git tree and switched off the world :)
> > >
> > > Well, being a bit late to the party ... my view is it would be
> > > preferable if we put the byteswapping in the library.
> > >
> > > The DT format is *defined* to be big-endian, 32-bit cells. So frankly,
> > > I have no problems with pushing responsibility onto individual
> > > platforms if they have decided to be "clever" by ignoring that -
> > > if that gets rid of a bunch of boilerplate for sensibly behaving platforms.
> > >
> > > Maybe another excuse for getting
> > > https://github.com/tianocore/edk2-
> > platforms/blob/master/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
> > > into MdePkg?
> > >
> > > /
> > >     Leif
> > >
> > > On Thu, Apr 20, 2023 at 16:44:03 +0000, Michael D Kinney wrote:
> > > > Hi Leif,
> > > >
> > > > What is your opinion on FDT being big endian.
> > > >
> > > > Do we want the lib to help with that aspect, or leave it up to the consumer
> of
> > the lib to
> > > > convert as needed?  Seems like an area that could be very error prone if we
> > are not
> > > > careful.
> > > >
> > > > Mike
> > > >
> > > > > -----Original Message-----
> > > > > From: Lin, Benny <benny.lin@intel.com>
> > > > > Sent: Wednesday, April 19, 2023 9:25 PM
> > > > > To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > devel@edk2.groups.io
> > > > > Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > > > > Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > > >
> > > > >
> > > > >
> > > > > >-----Original Message-----
> > > > > >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > > > > >Sent: Thursday, April 20, 2023 5:04 AM
> > > > > >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > > > > >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > <zhiguang.liu@intel.com>; Pedro Falcato
> > > <pedro.falcato@gmail.com>; Kinney,
> > > > > Michael D <michael.d.kinney@intel.com>
> > > > > >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > > > >
> > > > > >Responses below
> > > > > >
> > > > > >Mike
> > > > > >
> > > > > >> -----Original Message-----
> > > > > >> From: Lin, Benny <benny.lin@intel.com>
> > > > > >> Sent: Wednesday, April 19, 2023 10:12 AM
> > > > > >> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > > > >> devel@edk2.groups.io
> > > > > >> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > > > >> <zhiguang.liu@intel.com>; Pedro Falcato
> <pedro.falcato@gmail.com>
> > > > > >> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > > > >>
> > > > > >> Please find my feedback below.
> > > > > >> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER,
> > what do you think?
> > > > > >>
> > > > > >> QQQ
> > > > > >> Benny
> > > > > >>
> > > > > >> >-----Original Message-----
> > > > > >> >From: Kinney, Michael D <michael.d.kinney@intel.com>
> > > > > >> >Sent: Wednesday, April 19, 2023 11:54 PM
> > > > > >> >To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > > > > >> >Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > > > >> ><zhiguang.liu@intel.com>; Pedro Falcato
> <pedro.falcato@gmail.com>;
> > > > > >> >Kinney,
> > > > > >> Michael D <michael.d.kinney@intel.com>
> > > > > >> >Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > > > >> >
> > > > > >> >A few comments below.
> > > > > >> >
> > > > > >> >Mike
> > > > > >> >
> > > > > >> >> -----Original Message-----
> > > > > >> >> From: Lin, Benny <benny.lin@intel.com>
> > > > > >> >> Sent: Sunday, April 16, 2023 10:35 PM
> > > > > >> >> To: devel@edk2.groups.io
> > > > > >> >> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> > > > > >> >> <michael.d.kinney@intel.com>; Gao, Liming
> > > > > >> >> <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > <zhiguang.liu@intel.com>;
> > > > > >> >> Pedro Falcato <pedro.falcato@gmail.com>
> > > > > >> >> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > > > >> >>
> > > > > >> >> From: Benny Lin <benny.lin@intel.com>
> > > > > >> >>
> > > > > >> >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> > > > > >> >> Add FDT support in EDK2 by submodule 3rd party libfdt
> > > > > >> >> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> > > > > >> >> and refer to LibcLib implementation by Pedro.
> > > > > >> >>
> > > > > >> >> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > > > > >> >> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > > > > >> >> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > > > > >> >> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> > > > > >> >> Signed-off-by: Benny Lin <benny.lin@intel.com>
> > > > > >> >> ---
> > > > > >> >>  MdePkg/Include/Library/FdtLib.h           | 314
> > ++++++++++++++++++++
> > > > > >> >>  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> > > > > >> >> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> > > > > >> >>  MdePkg/Library/BaseFdtLib/FdtLib.c        | 301
> > +++++++++++++++++++
> > > > > >> >>  MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> > > > > >> >> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
> > > > > >> >>  MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> > > > > >> >>  MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> > > > > >> >>  MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> > > > > >> >>  MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> > > > > >> >>  MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> > > > > >> >>  MdePkg/Library/BaseFdtLib/string.h        |  10 +
> > > > > >> >>  MdePkg/MdePkg.ci.yaml                     |  17 +-
> > > > > >> >>  MdePkg/MdePkg.dec                         |   4 +
> > > > > >> >>  MdePkg/MdePkg.dsc                         |   1 +
> > > > > >> >>  15 files changed, 1043 insertions(+), 2 deletions(-)
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Include/Library/FdtLib.h
> > > > > >> >> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
> > > > > >> >> 0000000000..d59b749c25
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Include/Library/FdtLib.h
> > > > > >> >> @@ -0,0 +1,314 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  Flattened Device Tree Library.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#ifndef FDT_LIB_H_
> > > > > >> >>
> > > > > >> >> +#define FDT_LIB_H_
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +///
> > > > > >> >>
> > > > > >> >> +/// Flattened Device Tree definition
> > > > > >> >>
> > > > > >> >> +///
> > > > > >> >>
> > > > > >> >> +typedef struct {
> > > > > >> >>
> > > > > >> >> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> > > > > >> >>
> > > > > >> >> +  UINT32    TotalSize;           /* total size of DT block */
> > > > > >> >>
> > > > > >> >> +  UINT32    OffsetDtStruct;      /* offset to structure */
> > > > > >> >>
> > > > > >> >> +  UINT32    OffsetDtStrings;     /* offset to strings */
> > > > > >> >>
> > > > > >> >> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve
> map
> > */
> > > > > >> >>
> > > > > >> >> +  UINT32    Version;             /* format version */
> > > > > >> >>
> > > > > >> >> +  UINT32    LastCompVersion;     /* last compatible version */
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  /* version 2 fields below */
> > > > > >> >>
> > > > > >> >> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
> > > > > >> >>
> > > > > >> >> +                                    booting on */
> > > > > >> >>
> > > > > >> >> +  /* version 3 fields below */
> > > > > >> >>
> > > > > >> >> +  UINT32    SizeDtStrings;       /* size of the strings block */
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  /* version 17 fields below */
> > > > > >> >>
> > > > > >> >> +  UINT32    SizeDtStruct;        /* size of the structure block */
> > > > > >> >>
> > > > > >> >> +} FDT_HEADER;
> > > > > >> >
> > > > > >> >I see the macros below use SwapBytes32() on all the fields from this
> > > > > >> >structure.  Does this mean this structure is big >endian?  If
> > > > > >> that is the case, then the description of this structure and all
> > > > > >> individual fields must make that very clear >so any consumer of the
> > > > > >> structure knows it does not follow the default endianness of UEFI/PI
> > and that consumers >must either use the macros or
> > > consumers
> > > > > must use SwapBytes32() on their own when using this structure directly.
> > > > > >>
> > > > > >> Yes, it's big endian. I will complete more descriptions in patch v4.
> > > > > >
> > > > > >Would it be simpler if we have a lib service that converts the entire
> header
> > from big endian to little endian.
> > > > > >That way, the consumer can use the FDT_HEADER directly without any
> of
> > the macros?
> > > > > >
> > > > > >Also, is the rest of the FDT blob also big endian?
> > > > >
> > > > > FDT blob format is binary encoding of FDT data with big endian. In
> addition,
> > the consumer will set or get FDT data with FDT
> > > blob. We
> > > > > can complete more descriptions to warn consumers to be careful if just
> use
> > header struct for mapping and get/set FDT data
> > > with FDT
> > > > > blob.
> > > > >
> > > > > For provide lib services that converts between big endian and little endian,
> > we can provide a get header function to convert
> > > between
> > > > > big endian and little endian. However, we also need to consider the
> > property value for setting and getting then we can
> > > convert in
> > > > > wrapper functions.
> > > > >
> > > > > For example,
> > > > >
> > > > > INT32
> > > > > EFIAPI
> > > > > FdtSetProp (
> > > > >   IN VOID         *Fdt,
> > > > >   IN INT32        NodeOffset,
> > > > >   IN CONST CHAR8  *Name,
> > > > >   IN CONST VOID   *Value,
> > > > >   IN UINT32       Length
> > > > >   )
> > > > > {
> > > > >   return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > > > > }
> > > > >
> > > > > More functions for various byte width.
> > > > > INT32
> > > > > EFIAPI
> > > > > FdtSetProp16 (
> > > > >   IN VOID         *Fdt,
> > > > >   IN INT32        NodeOffset,
> > > > >   IN CONST CHAR8  *Name,
> > > > >   IN CONST UINT16   *Value,
> > > > >   IN UINT32       Length
> > > > >   )
> > > > > {
> > > > >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value),
> > (int)Length);
> > > > > }
> > > > >
> > > > > INT32
> > > > > EFIAPI
> > > > > FdtSetProp32 (
> > > > >   IN VOID         *Fdt,
> > > > >   IN INT32        NodeOffset,
> > > > >   IN CONST CHAR8  *Name,
> > > > >   IN CONST UINT32   *Value,
> > > > >   IN UINT32       Length
> > > > >   )
> > > > > {
> > > > >   return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value),
> > (int)Length);
> > > > > }
> > > > >
> > > > > >>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +typedef struct {
> > > > > >> >>
> > > > > >> >> +  UINT64    Address;
> > > > > >> >>
> > > > > >> >> +  UINT64    Size;
> > > > > >> >>
> > > > > >> >> +} FDT_RESERVE_ENTRY;
> > > > > >> >
> > > > > >> >
> > > > > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > > > > >> >Can it be removed?
> > > > > >>
> > > > > >> I think we can remove it because it might be not used for further
> usage
> > of FDT support.
> > > > > >>
> > > > > >> >
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +typedef struct {
> > > > > >> >>
> > > > > >> >> +  UINT32    Tag;
> > > > > >> >>
> > > > > >> >> +  CHAR8     Name[];
> > > > > >> >>
> > > > > >> >> +} FDT_NODE_HEADER;
> > > > > >> >
> > > > > >> >
> > > > > >> >I do not see this type used anywhere in the lib class or the lib instance.
> > > > > >> >Can it be removed?
> > > > > >>
> > > > > >> When we need retrieve a node from a FDT blob, we will get a node
> > > > > >> offset then we could use the struct to map the node content. It's very
> > useful.
> > > > > >
> > > > > >Please add a comment header for this structure and describe the usage
> as
> > it related to the rest of the FdtLib >services.
> > > > >
> > > > > I will add descriptions for the usage and remove FDT_RESERVE_ENTRY in
> > patch v4.
> > > > >
> > > > > >
> > > > > >>
> > > > > >> >
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +typedef struct {
> > > > > >> >>
> > > > > >> >> +  UINT32    Tag;
> > > > > >> >>
> > > > > >> >> +  UINT32    Length;
> > > > > >> >>
> > > > > >> >> +  UINT32    NameOffset;
> > > > > >> >>
> > > > > >> >> +  CHAR8     Data[];
> > > > > >> >>
> > > > > >> >> +} FDT_PROPERTY;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST
> > FDT_HEADER
> > > > > >> >> +*)(Fdt))->Field)
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
> > > > > >> >>
> > > > > >> >> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt,
> > TotalSize))
> > > > > >> >>
> > > > > >> >> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt,
> > OffsetDtStruct))
> > > > > >> >>
> > > > > >> >> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
> > > > > >> >> +OffsetDtStrings))
> > > > > >> >>
> > > > > >> >> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
> > > > > >> >> +OffsetMemRsvmap))
> > > > > >> >>
> > > > > >> >> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
> > > > > >> >>
> > > > > >> >> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
> > > > > >> >> +LastCompVersion))
> > > > > >> >>
> > > > > >> >> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt,
> > BootCpuidPhys))
> > > > > >> >>
> > > > > >> >> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt,
> > SizeDtStrings))
> > > > > >> >>
> > > > > >> >> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt,
> > SizeDtStruct))
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Verify the header of the Flattened Device Tree
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return Zero for successfully, otherwise failed.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtCheckHeader (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Create a empty Flattened Device Tree.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT
> blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return Zero for successfully, otherwise failed.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +RETURN_STATUS
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtCreateEmptyTree (
> > > > > >> >>
> > > > > >> >> +  IN VOID   *Buffer,
> > > > > >> >>
> > > > > >> >> +  IN UINTN  BufferSize
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of next node from the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > > >> >>
> > > > > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to next node offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtNextNode (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset,
> > > > > >> >>
> > > > > >> >> +  IN INT32       *Depth
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of first node under the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to next node offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtFirstSubnode (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of next node from the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to next node offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtNextSubnode (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of first node which includes the given name.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] ParentOffset    The offset to the node which start
> find
> > under.
> > > > > >> >>
> > > > > >> >> +  @param[in] Name            The name to search the node with the
> > name.
> > > > > >> >>
> > > > > >> >> +  @param[in] NameLength      The length of the name to check
> only.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to node offset with given node name.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtSubnodeOffsetNameLen (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        ParentOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *Name,
> > > > > >> >>
> > > > > >> >> +  IN INT32        NameLength
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of first node which includes the given property
> > name and value.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > > > > >> >>
> > > > > >> >> +  @param[in] PropertyName    The property name to search the
> > node including the named property.
> > > > > >> >>
> > > > > >> >> +  @param[in] PropertyValue   The property value to check the
> same
> > property value.
> > > > > >> >>
> > > > > >> >> +  @param[in] PropertyLength  The length of the value in
> > PropertValue.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to node offset with given property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtNodeOffsetByPropValue (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        StartOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *PropertyName,
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *PropertyValue,
> > > > > >> >>
> > > > > >> >> +  IN INT32        PropertyLength
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a property with the given name from the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > > > > >> >>
> > > > > >> >> +  @param[in] Name           The name to the property which need
> be
> > searched
> > > > > >> >>
> > > > > >> >> +  @param[in] Length         The length to the size of the property
> > found.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The property to the structure of the found property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +CONST FDT_PROPERTY *
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtGetProperty (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        NodeOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *Name,
> > > > > >> >>
> > > > > >> >> +  IN INT32        *Length
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of first property in the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to the node which need be
> > searched.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to first property offset in the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtFirstPropertyOffset (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       NodeOffset
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of next property from the given property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to previous property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to next property offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtNextPropertyOffset (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a property from the given offset of the property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to the given offset of the
> > property.
> > > > > >> >>
> > > > > >> >> +  @param[in] Length         The length to the size of the property
> > found.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The property to the structure of the given property
> offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +CONST FDT_PROPERTY *
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtGetPropertyByOffset (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset,
> > > > > >> >>
> > > > > >> >> +  IN INT32       *Length
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a string by the given string offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] StrOffset      The offset to the location in the strings
> > block of FDT.
> > > > > >> >>
> > > > > >> >> +  @param[in] Length         The length to the size of string which
> need
> > be retrieved.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The string to the given string offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +CONST CHAR8 *
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtGetString (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       StrOffset,
> > > > > >> >>
> > > > > >> >> +  IN INT32       *Length        OPTIONAL
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Add a new node to the FDT.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] ParentOffset   The offset to the node offset which
> > want to add in.
> > > > > >> >>
> > > > > >> >> +  @param[in] Name           The name to name the node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return  The offset to the new node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtAddSubnode (
> > > > > >> >>
> > > > > >> >> +  IN VOID         *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        ParentOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *Name
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Add or modify a property in the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] NodeOffset     The offset to the node offset which
> > want to add in.
> > > > > >> >>
> > > > > >> >> +  @param[in] Name           The name to name the property.
> > > > > >> >>
> > > > > >> >> +  @param[in] Value          The value to the property value.
> > > > > >> >>
> > > > > >> >> +  @param[in] Length         The length to the size of the property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return  Zero for successfully, otherwise failed.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtSetProp (
> > > > > >> >>
> > > > > >> >> +  IN VOID         *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        NodeOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *Name,
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *Value,
> > > > > >> >>
> > > > > >> >> +  IN UINT32       Length
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#endif /* FDT_LIB_H_ */
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..730e568ff6
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > > > >> >> @@ -0,0 +1,62 @@
> > > > > >> >> +## @file
> > > > > >> >>
> > > > > >> >> +# Flattened Device Tree Library.
> > > > > >> >>
> > > > > >> >> +#
> > > > > >> >>
> > > > > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +#
> > > > > >> >>
> > > > > >> >> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +#
> > > > > >> >>
> > > > > >> >> +#
> > > > > >> >>
> > > > > >> >> +##
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +[Defines]
> > > > > >> >>
> > > > > >> >> +  INF_VERSION                    = 0x0001001B
> > > > > >> >>
> > > > > >> >> +  BASE_NAME                      = BaseFdtLib
> > > > > >> >>
> > > > > >> >> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> > > > > >> >>
> > > > > >> >> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-
> > E8CEC206DE04
> > > > > >> >>
> > > > > >> >> +  MODULE_TYPE                    = BASE
> > > > > >> >>
> > > > > >> >> +  VERSION_STRING                 = 1.0
> > > > > >> >>
> > > > > >> >> +  LIBRARY_CLASS                  = FdtLib
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#
> > > > > >> >>
> > > > > >> >> +#  VALID_ARCHITECTURES           = IA32 X64
> > > > > >> >>
> > > > > >> >> +#
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +[Sources]
> > > > > >> >>
> > > > > >> >> +  FdtLib.c
> > > > > >> >>
> > > > > >> >> +  LibFdtWrapper.c
> > > > > >> >>
> > > > > >> >> +  # header Wrapper files
> > > > > >> >>
> > > > > >> >> +  limits.h
> > > > > >> >>
> > > > > >> >> +  stdbool.h
> > > > > >> >>
> > > > > >> >> +  stddef.h
> > > > > >> >>
> > > > > >> >> +  stdint.h
> > > > > >> >>
> > > > > >> >> +  stdlib.h
> > > > > >> >>
> > > > > >> >> +  string.h
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt.h
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt_addresses.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt_check.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt_overlay.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt_ro.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt_rw.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt_strerror.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt_sw.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/fdt_wip.c
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/libfdt.h
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/libfdt_env.h
> > > > > >> >>
> > > > > >> >> +  $(FDT_LIB_PATH)/libfdt_internal.h
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +[Packages]
> > > > > >> >>
> > > > > >> >> +  MdePkg/MdePkg.dec
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +[LibraryClasses]
> > > > > >> >>
> > > > > >> >> +  BaseLib
> > > > > >> >>
> > > > > >> >> +  BaseMemoryLib
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +[BuildOptions]
> > > > > >> >>
> > > > > >> >> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> > > > > >> >>
> > > > > >> >> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245
> /wd4267
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..3f7e45ea6f
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > > > >> >> @@ -0,0 +1,14 @@
> > > > > >> >> +// /** @file
> > > > > >> >>
> > > > > >> >> +// Flattened Device Tree Library.
> > > > > >> >>
> > > > > >> >> +//
> > > > > >> >>
> > > > > >> >> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +//
> > > > > >> >>
> > > > > >> >> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +//
> > > > > >> >>
> > > > > >> >> +// **/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#string STR_MODULE_ABSTRACT             #language en-US
> "Instance
> > of FDT Library"
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#string STR_MODULE_DESCRIPTION          #language en-US "This
> > module provides FDT Library implementation."
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..200a496c7e
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > > > >> >> @@ -0,0 +1,301 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  Flattened Device Tree Library.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#include <libfdt/libfdt/libfdt.h>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Verify the header of the Flattened Device Tree
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return Zero for successfully, otherwise failed.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtCheckHeader (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_check_header(Fdt);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Create a empty Flattened Device Tree.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Buffer         The pointer to allocate a pool for FDT
> blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] BufferSize     The BufferSize to the pool size.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return Zero for successfully, otherwise failed.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtCreateEmptyTree (
> > > > > >> >>
> > > > > >> >> +  IN VOID    *Buffer,
> > > > > >> >>
> > > > > >> >> +  IN UINT32  BufferSize
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of next node from the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > > >> >>
> > > > > >> >> +  @param[in] Depth          The depth to the level of tree hierarchy.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to next node offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtNextNode (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset,
> > > > > >> >>
> > > > > >> >> +  IN INT32       *Depth
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_next_node (Fdt, Offset, Depth);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of first node under the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to next node offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtFirstSubnode (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_first_subnode (Fdt, Offset);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of next node from the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to previous node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to next node offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtNextSubnode (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_next_subnode (Fdt, Offset);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of first node which includes the given name.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] ParentOffset    The offset to the node which start
> find
> > under.
> > > > > >> >>
> > > > > >> >> +  @param[in] Name            The name to search the node with the
> > name.
> > > > > >> >>
> > > > > >> >> +  @param[in] NameLength      The length of the name to check
> only.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to node offset with given node name.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtSubnodeOffsetNameLen (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        ParentOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *Name,
> > > > > >> >>
> > > > > >> >> +  IN INT32        NameLength
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name,
> > > > > >> >> + NameLength);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of first node which includes the given property
> > name and value.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt             The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] StartOffset     The offset to the starting node to find.
> > > > > >> >>
> > > > > >> >> +  @param[in] PropertyName    The property name to search the
> > node including the named property.
> > > > > >> >>
> > > > > >> >> +  @param[in] PropertyValue   The property value to check the
> same
> > property value.
> > > > > >> >>
> > > > > >> >> +  @param[in] PropertyLength  The length of the value in
> > PropertValue.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to node offset with given property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtNodeOffsetByPropValue (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        StartOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *PropertyName,
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *PropertyValue,
> > > > > >> >>
> > > > > >> >> +  IN INT32        PropertyLength
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> > > > > >> >> + PropertyName, PropertyValue, PropertyLength);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a property with the given name from the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] NodeOffset     The offset to the given node.
> > > > > >> >>
> > > > > >> >> +  @param[in] Name           The name to the property which need
> be
> > searched
> > > > > >> >>
> > > > > >> >> +  @param[in] Length         The length to the size of the property
> > found.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The property to the structure of the found property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +CONST struct fdt_property *
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtGetProperty (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        NodeOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *Name,
> > > > > >> >>
> > > > > >> >> +  IN INT32        *Length
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of first property in the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] NodeOffset     The offset to the node which need be
> > searched.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to first property offset in the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtFirstPropertyOffset (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       NodeOffset
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_first_property_offset (Fdt, NodeOffset);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a offset of next property from the given property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to previous property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The offset to next property offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtNextPropertyOffset (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_next_property_offset (Fdt, Offset);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a property from the given offset of the property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] Offset         The offset to the given offset of the
> > property.
> > > > > >> >>
> > > > > >> >> +  @param[in] Length         The length to the size of the property
> > found.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The property to the structure of the given property
> offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +CONST struct fdt_property *
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtGetPropertyByOffset (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       Offset,
> > > > > >> >>
> > > > > >> >> +  IN INT32       *Length
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Returns a string by the given string offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] StrOffset      The offset to the location in the strings
> > block of FDT.
> > > > > >> >>
> > > > > >> >> +  @param[in] Length         The length to the size of string which
> need
> > be retrieved.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return The string to the given string offset.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +CONST CHAR8 *
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtGetString (
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID  *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32       StrOffset,
> > > > > >> >>
> > > > > >> >> +  IN INT32       *Length        OPTIONAL
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_get_string (Fdt, StrOffset, Length);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Add a new node to the FDT.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] ParentOffset   The offset to the node offset which
> > want to add in.
> > > > > >> >>
> > > > > >> >> +  @param[in] Name           The name to name the node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return  The offset to the new node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtAddSubnode (
> > > > > >> >>
> > > > > >> >> +  IN VOID         *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        ParentOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *Name
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +/**
> > > > > >> >>
> > > > > >> >> +  Add or modify a property in the given node.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @param[in] Fdt            The pointer to FDT blob.
> > > > > >> >>
> > > > > >> >> +  @param[in] NodeOffset     The offset to the node offset which
> > want to add in.
> > > > > >> >>
> > > > > >> >> +  @param[in] Name           The name to name the property.
> > > > > >> >>
> > > > > >> >> +  @param[in] Value          The value to the property value.
> > > > > >> >>
> > > > > >> >> +  @param[in] Length         The length to the size of the property.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  @return  Zero for successfully, otherwise failed.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +INT32
> > > > > >> >>
> > > > > >> >> +EFIAPI
> > > > > >> >>
> > > > > >> >> +FdtSetProp (
> > > > > >> >>
> > > > > >> >> +  IN VOID         *Fdt,
> > > > > >> >>
> > > > > >> >> +  IN INT32        NodeOffset,
> > > > > >> >>
> > > > > >> >> +  IN CONST CHAR8  *Name,
> > > > > >> >>
> > > > > >> >> +  IN CONST VOID   *Value,
> > > > > >> >>
> > > > > >> >> +  IN UINT32       Length
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..e738f4ded4
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > > > >> >> @@ -0,0 +1,99 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  Root include file of C runtime library to support building the
> > > > > >> >> + third-party
> > > > > >> >>
> > > > > >> >> +  libfdt library.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#ifndef FDT_LIB_SUPPORT_H_
> > > > > >> >>
> > > > > >> >> +#define FDT_LIB_SUPPORT_H_
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#include <Base.h>
> > > > > >> >>
> > > > > >> >> +#include <Library/BaseLib.h>
> > > > > >> >>
> > > > > >> >> +#include <Library/BaseMemoryLib.h>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +typedef UINT8    uint8_t;
> > > > > >> >>
> > > > > >> >> +typedef UINT16   uint16_t;
> > > > > >> >>
> > > > > >> >> +typedef INT32    int32_t;
> > > > > >> >>
> > > > > >> >> +typedef UINT32   uint32_t;
> > > > > >> >>
> > > > > >> >> +typedef UINT64   uint64_t;
> > > > > >> >>
> > > > > >> >> +typedef UINTN    uintptr_t;
> > > > > >> >>
> > > > > >> >> +typedef UINTN    size_t;
> > > > > >> >>
> > > > > >> >> +typedef BOOLEAN  bool;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#define true   (1 == 1)
> > > > > >> >>
> > > > > >> >> +#define false  (1 == 0)
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +//
> > > > > >> >>
> > > > > >> >> +// Definitions for global constants used by libfdt library
> > > > > >> >> +routines
> > > > > >> >>
> > > > > >> >> +//
> > > > > >> >>
> > > > > >> >> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int
> value
> > */
> > > > > >> >>
> > > > > >> >> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32
> > value */
> > > > > >> >>
> > > > > >> >> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned
> int32
> > value */
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +//
> > > > > >> >>
> > > > > >> >> +// Function prototypes of libfdt Library routines
> > > > > >> >>
> > > > > >> >> +//
> > > > > >> >>
> > > > > >> >> +void *
> > > > > >> >>
> > > > > >> >> +memset     (
> > > > > >> >>
> > > > > >> >> +  void *,
> > > > > >> >>
> > > > > >> >> +  int,
> > > > > >> >>
> > > > > >> >> +  size_t
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +int
> > > > > >> >>
> > > > > >> >> +memcmp      (
> > > > > >> >>
> > > > > >> >> +  const void *,
> > > > > >> >>
> > > > > >> >> +  const void *,
> > > > > >> >>
> > > > > >> >> +  size_t
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +int
> > > > > >> >>
> > > > > >> >> +strcmp      (
> > > > > >> >>
> > > > > >> >> +  const char *,
> > > > > >> >>
> > > > > >> >> +  const char *
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +char *
> > > > > >> >>
> > > > > >> >> +strchr     (
> > > > > >> >>
> > > > > >> >> +  const char *,
> > > > > >> >>
> > > > > >> >> +  int
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +char *
> > > > > >> >>
> > > > > >> >> +strrchr    (
> > > > > >> >>
> > > > > >> >> +  const char *,
> > > > > >> >>
> > > > > >> >> +  int
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +unsigned long
> > > > > >> >>
> > > > > >> >> +strtoul     (
> > > > > >> >>
> > > > > >> >> +  const char *,
> > > > > >> >>
> > > > > >> >> +  char **,
> > > > > >> >>
> > > > > >> >> +  int
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +char *
> > > > > >> >>
> > > > > >> >> +strcpy (
> > > > > >> >>
> > > > > >> >> +  char        *strDest,
> > > > > >> >>
> > > > > >> >> +  const char  *strSource
> > > > > >> >>
> > > > > >> >> +  );
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +//
> > > > > >> >>
> > > > > >> >> +// Macros that directly map functions to BaseLib, BaseMemoryLib,
> > > > > >> >> +and DebugLib functions
> > > > > >> >>
> > > > > >> >> +//
> > > > > >> >>
> > > > > >> >> +#define memcpy(dest, source, count)         CopyMem(dest,source,
> > (UINTN)(count))
> > > > > >> >>
> > > > > >> >> +#define memset(dest, ch, count)             SetMem(dest,
> > (UINTN)(count),(UINT8)(ch))
> > > > > >> >>
> > > > > >> >> +#define memchr(buf, ch, count)              ScanMem8(buf,
> > (UINTN)(count),(UINT8)ch)
> > > > > >> >>
> > > > > >> >> +#define memcmp(buf1, buf2, count)
> (int)(CompareMem(buf1,
> > buf2, (UINTN)(count)))
> > > > > >> >>
> > > > > >> >> +#define memmove(dest, source, count)        CopyMem(dest,
> source,
> > (UINTN)(count))
> > > > > >> >>
> > > > > >> >> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> > > > > >> >>
> > > > > >> >> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str,
> count))
> > > > > >> >>
> > > > > >> >> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest,
> > > > > >> >> +MAX_STRING_SIZE, strSource, (UINTN)count)
> > > > > >> >>
> > > > > >> >> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest,
> > MAX_STRING_SIZE, strSource)
> > > > > >> >>
> > > > > >> >> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1,
> > string2))
> > > > > >> >>
> > > > > >> >> +#define strncmp(string1, string2, count)
> (int)(AsciiStrnCmp(string1,
> > string2, (UINTN)(count)))
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#endif /* FDT_LIB_SUPPORT_H_ */
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..772bba4839
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > > > >> >> @@ -0,0 +1,173 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  ISO C implementations of strchr, strrchr and strtoul.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> > > > > >> >>
> > > > > >> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#include <Base.h>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned
> long
> > value */
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +// Very quick notes:
> > > > > >> >>
> > > > > >> >> +// We only go through the string once for both functions
> > > > > >> >>
> > > > > >> >> +// They are minimal implementations (not speed optimized) of ISO
> C
> > > > > >> >> +semantics
> > > > > >> >>
> > > > > >> >> +// strchr and strrchr also include the null terminator as part of
> > > > > >> >> +the string
> > > > > >> >>
> > > > > >> >> +// so the code gets a bit clunky to handle that case specifically.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +char *
> > > > > >> >>
> > > > > >> >> +strchr (
> > > > > >> >>
> > > > > >> >> +  const char  *Str,
> > > > > >> >>
> > > > > >> >> +  int         Char
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  char  *S;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  S = (char *)Str;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  for ( ; ; S++) {
> > > > > >> >>
> > > > > >> >> +    if (*S == Char) {
> > > > > >> >>
> > > > > >> >> +      return S;
> > > > > >> >>
> > > > > >> >> +    }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +    if (*S == '\0') {
> > > > > >> >>
> > > > > >> >> +      return NULL;
> > > > > >> >>
> > > > > >> >> +    }
> > > > > >> >>
> > > > > >> >> +  }
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +char *
> > > > > >> >>
> > > > > >> >> +strrchr (
> > > > > >> >>
> > > > > >> >> +  const char  *Str,
> > > > > >> >>
> > > > > >> >> +  int         Char
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  char  *S, *last;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  S    = (char *)Str;
> > > > > >> >>
> > > > > >> >> +  last = NULL;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  for ( ; ; S++) {
> > > > > >> >>
> > > > > >> >> +    if (*S == Char) {
> > > > > >> >>
> > > > > >> >> +      last = S;
> > > > > >> >>
> > > > > >> >> +    }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +    if (*S == '\0') {
> > > > > >> >>
> > > > > >> >> +      return last;
> > > > > >> >>
> > > > > >> >> +    }
> > > > > >> >>
> > > > > >> >> +  }
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +STATIC
> > > > > >> >>
> > > > > >> >> +int
> > > > > >> >>
> > > > > >> >> +__isspace (
> > > > > >> >>
> > > > > >> >> +  int  ch
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  // basic ASCII ctype.h:isspace(). Not efficient
> > > > > >> >>
> > > > > >> >> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
> > > > > >> >> + == '\v' || ch == '\f';
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +unsigned long
> > > > > >> >>
> > > > > >> >> +strtoul (
> > > > > >> >>
> > > > > >> >> +  const char  *Nptr,
> > > > > >> >>
> > > > > >> >> +  char        **EndPtr,
> > > > > >> >>
> > > > > >> >> +  int         Base
> > > > > >> >>
> > > > > >> >> +  )
> > > > > >> >>
> > > > > >> >> +{
> > > > > >> >>
> > > > > >> >> +  BOOLEAN        Negate;
> > > > > >> >>
> > > > > >> >> +  BOOLEAN        Overflow;
> > > > > >> >>
> > > > > >> >> +  unsigned long  Val;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  Negate   = FALSE;
> > > > > >> >>
> > > > > >> >> +  Overflow = FALSE;
> > > > > >> >>
> > > > > >> >> +  Val      = 0;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  // Reject bad numeric bases
> > > > > >> >>
> > > > > >> >> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> > > > > >> >>
> > > > > >> >> +    return 0;
> > > > > >> >>
> > > > > >> >> +  }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  // Skip whitespace
> > > > > >> >>
> > > > > >> >> +  while (__isspace (*Nptr)) {
> > > > > >> >>
> > > > > >> >> +    Nptr++;
> > > > > >> >>
> > > > > >> >> +  }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  // Check for + or - prefixes
> > > > > >> >>
> > > > > >> >> +  if (*Nptr == '-') {
> > > > > >> >>
> > > > > >> >> +    Negate = TRUE;
> > > > > >> >>
> > > > > >> >> +    Nptr++;
> > > > > >> >>
> > > > > >> >> +  } else if (*Nptr == '+') {
> > > > > >> >>
> > > > > >> >> +    Nptr++;
> > > > > >> >>
> > > > > >> >> +  }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  // Consume the start, autodetecting base if needed
> > > > > >> >>
> > > > > >> >> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
> > > > > >> >> + && ((Base == 0) || (Base == 16))) {
> > > > > >> >>
> > > > > >> >> +    // Hex
> > > > > >> >>
> > > > > >> >> +    Nptr += 2;
> > > > > >> >>
> > > > > >> >> +    Base  = 16;
> > > > > >> >>
> > > > > >> >> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> > > > > >> >> + 'B')) && ((Base == 0) || (Base == 2))) {
> > > > > >> >>
> > > > > >> >> +    // Binary (standard pending C23)
> > > > > >> >>
> > > > > >> >> +    Nptr += 2;
> > > > > >> >>
> > > > > >> >> +    Base  = 2;
> > > > > >> >>
> > > > > >> >> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> > > > > >> >>
> > > > > >> >> +    // Octal
> > > > > >> >>
> > > > > >> >> +    Nptr++;
> > > > > >> >>
> > > > > >> >> +    Base = 8;
> > > > > >> >>
> > > > > >> >> +  } else {
> > > > > >> >>
> > > > > >> >> +    if (Base == 0) {
> > > > > >> >>
> > > > > >> >> +      // Assume decimal
> > > > > >> >>
> > > > > >> >> +      Base = 10;
> > > > > >> >>
> > > > > >> >> +    }
> > > > > >> >>
> > > > > >> >> +  }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  while (TRUE) {
> > > > > >> >>
> > > > > >> >> +    int            Digit;
> > > > > >> >>
> > > > > >> >> +    char           C;
> > > > > >> >>
> > > > > >> >> +    unsigned long  NewVal;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +    C     = *Nptr;
> > > > > >> >>
> > > > > >> >> +    Digit = -1;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +    if ((C >= '0') && (C <= '9')) {
> > > > > >> >>
> > > > > >> >> +      Digit = C - '0';
> > > > > >> >>
> > > > > >> >> +    } else if ((C >= 'a') && (C <= 'z')) {
> > > > > >> >>
> > > > > >> >> +      Digit = C - 'a' + 10;
> > > > > >> >>
> > > > > >> >> +    } else if ((C >= 'A') && (C <= 'Z')) {
> > > > > >> >>
> > > > > >> >> +      Digit = C - 'A' + 10;
> > > > > >> >>
> > > > > >> >> +    }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +    if ((Digit == -1) || (Digit >= Base)) {
> > > > > >> >>
> > > > > >> >> +      // Note that this case also handles the \0
> > > > > >> >>
> > > > > >> >> +      if (EndPtr) {
> > > > > >> >>
> > > > > >> >> +        *EndPtr = (char *)Nptr;
> > > > > >> >>
> > > > > >> >> +      }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +      break;
> > > > > >> >>
> > > > > >> >> +    }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +    NewVal = Val * Base + Digit;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +    if (NewVal < Val) {
> > > > > >> >>
> > > > > >> >> +      // Overflow
> > > > > >> >>
> > > > > >> >> +      Overflow = TRUE;
> > > > > >> >>
> > > > > >> >> +    }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +    Val = NewVal;
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +    Nptr++;
> > > > > >> >>
> > > > > >> >> +  }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  if (Negate) {
> > > > > >> >>
> > > > > >> >> +    Val = -Val;
> > > > > >> >>
> > > > > >> >> +  }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  if (Overflow) {
> > > > > >> >>
> > > > > >> >> +    Val = ULONG_MAX;
> > > > > >> >>
> > > > > >> >> +  }
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +  // TODO: We're lacking errno here.
> > > > > >> >>
> > > > > >> >> +  return Val;
> > > > > >> >>
> > > > > >> >> +}
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/limits.h
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..f6cf8d5702
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> > > > > >> >> @@ -0,0 +1,10 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#include <LibFdtSupport.h>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/stdbool.h
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..f6cf8d5702
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> > > > > >> >> @@ -0,0 +1,10 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#include <LibFdtSupport.h>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/stddef.h
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..f6cf8d5702
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> > > > > >> >> @@ -0,0 +1,10 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#include <LibFdtSupport.h>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/stdint.h
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..f6cf8d5702
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> > > > > >> >> @@ -0,0 +1,10 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#include <LibFdtSupport.h>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/stdlib.h
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..f6cf8d5702
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> > > > > >> >> @@ -0,0 +1,10 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#include <LibFdtSupport.h>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> > > > > >> >> b/MdePkg/Library/BaseFdtLib/string.h
> > > > > >> >> new file mode 100644
> > > > > >> >> index 0000000000..f6cf8d5702
> > > > > >> >> --- /dev/null
> > > > > >> >> +++ b/MdePkg/Library/BaseFdtLib/string.h
> > > > > >> >> @@ -0,0 +1,10 @@
> > > > > >> >> +/** @file
> > > > > >> >>
> > > > > >> >> +  Include file to support building the third-party libfdt library.
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +**/
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> +#include <LibFdtSupport.h>
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
> > index
> > > > > >> >> 6ba85ebe61..f039daccdb 100644
> > > > > >> >> --- a/MdePkg/MdePkg.ci.yaml
> > > > > >> >> +++ b/MdePkg/MdePkg.ci.yaml
> > > > > >> >> @@ -2,7 +2,7 @@
> > > > > >> >>  # CI configuration for MdePkg
> > > > > >> >>
> > > > > >> >>  #
> > > > > >> >>
> > > > > >> >>  # Copyright (c) Microsoft Corporation
> > > > > >> >>
> > > > > >> >> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >>  # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> > > > > >> >>
> > > > > >> >>  # Copyright (c) 2023, Loongson Technology Corporation Limited.
> All
> > > > > >> >> rights reserved.<BR>
> > > > > >> >>
> > > > > >> >>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > >> >>
> > > > > >> >> @@ -67,7 +67,8 @@
> > > > > >> >>              "Include/Library/PcdLib.h",
> > > > > >> >>
> > > > > >> >>              "Include/Library/SafeIntLib.h",
> > > > > >> >>
> > > > > >> >>              "Include/Protocol/DebugSupport.h",
> > > > > >> >>
> > > > > >> >> -
> "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> > > > > >> >>
> > > > > >> >> +            "Library/BaseFdtLib"
> > > > > >> >>
> > > > > >> >>          ]
> > > > > >> >>
> > > > > >> >>      },
> > > > > >> >>
> > > > > >> >>      ## options defined ci/Plugin/CompilerPlugin
> > > > > >> >>
> > > > > >> >> @@ -164,5 +165,17 @@
> > > > > >> >>          "ExtendWords": [],           # words to extend to the dictionary
> for
> > this package
> > > > > >> >>
> > > > > >> >>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths
> that
> > should be ignore
> > > > > >> >>
> > > > > >> >>          "AdditionalIncludePaths": [] # Additional paths to spell
> > > > > >> >> check (wildcards supported)
> > > > > >> >>
> > > > > >> >> +    },
> > > > > >> >>
> > > > > >> >> +    # options defined in .pytool/Plugin/UncrustifyCheck
> > > > > >> >>
> > > > > >> >> +    "UncrustifyCheck": {
> > > > > >> >>
> > > > > >> >> +        "IgnoreFiles": [
> > > > > >> >>
> > > > > >> >> +            "Library/BaseFdtLib/libfdt",
> > > > > >> >>
> > > > > >> >> +            "Library/BaseFdtLib/limits.h",
> > > > > >> >>
> > > > > >> >> +            "Library/BaseFdtLib/stdbool.h",
> > > > > >> >>
> > > > > >> >> +            "Library/BaseFdtLib/stddef.h",
> > > > > >> >>
> > > > > >> >> +            "Library/BaseFdtLib/stdint.h",
> > > > > >> >>
> > > > > >> >> +            "Library/BaseFdtLib/stdlib.h",
> > > > > >> >>
> > > > > >> >> +            "Library/BaseFdtLib/string.h"
> > > > > >> >>
> > > > > >> >> +        ]
> > > > > >> >>
> > > > > >> >>      }
> > > > > >> >>
> > > > > >> >>  }
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> > > > > >> >> e70182bf7f..9804a7a6bd 100644
> > > > > >> >> --- a/MdePkg/MdePkg.dec
> > > > > >> >> +++ b/MdePkg/MdePkg.dec
> > > > > >> >> @@ -289,6 +289,10 @@
> > > > > >> >>    #
> > > > > >> >>
> > > > > >> >>    ArmTrngLib|Include/Library/ArmTrngLib.h
> > > > > >> >>
> > > > > >> >>
> > > > > >> >>
> > > > > >> >> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> > > > > >> >>
> > > > > >> >> +  #
> > > > > >> >>
> > > > > >> >> +  FdtLib|Include/Library/FdtLib.h
> > > > > >> >>
> > > > > >> >> +
> > > > > >> >>
> > > > > >> >>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> > > > > >> >>
> > > > > >> >>    ##  @libraryclass  Provides services to generate random number.
> > > > > >> >>
> > > > > >> >>    #
> > > > > >> >>
> > > > > >> >> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> > > > > >> >> 152c02991a..b38c863812 100644
> > > > > >> >> --- a/MdePkg/MdePkg.dsc
> > > > > >> >> +++ b/MdePkg/MdePkg.dsc
> > > > > >> >> @@ -137,6 +137,7 @@
> > > > > >> >>
> > > > > >> >>
> > MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> > > > > >> >>
> > > > > >> >>
> > > > > >> >>
> > > > > >> >>    MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> > > > > >> >>
> > > > > >> >> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > > > >> >>
> > > > > >> >>
> > > > > >> >>
> > > > > >> >>  [Components.IA32, Components.X64, Components.ARM,
> > > > > >> >> Components.AARCH64]
> > > > > >> >>
> > > > > >> >>    #
> > > > > >> >>
> > > > > >> >> --
> > > > > >> >> 2.39.1.windows.1
> > > > > >
> > > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> >
> >
> >
> >
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-05-01 16:31                   ` Chiu, Chasel
@ 2023-05-02 11:41                     ` Leif Lindholm
  2023-05-03  2:34                       ` Chiu, Chasel
  0 siblings, 1 reply; 20+ messages in thread
From: Leif Lindholm @ 2023-05-02 11:41 UTC (permalink / raw)
  To: devel, chasel.chiu, Kinney, Michael D
  Cc: Lin, Benny, Gao, Liming, Liu, Zhiguang, Pedro Falcato

Hi Chasel,

Apologies, spent last week at Linaro Connect with little time to follow 
the list.

If we're seeing this purely as a wrapper on libfdt, then it shouldn't 
need to provide additional functionality on top of what it provides.
My initial impression was that this library was attempting to do more, 
but then I mostly skimmed it, and that appears to have been incorrect.

What I *really* don't want is mixing abstractions. I.e. if we're getting 
the pointers through libfdt calls, we should be using the libfdt 
accessor functions to extract the data correctly. And expose the 
cpu_to_fdt*/fdt*_to_cpu accessors through the library. Presumably as 
Fdt*ToCpu/CpuToFdt*.

Regards,

Leif


On 2023-05-01 17:31, Chiu, Chasel wrote:
> 
> Hi Leif,
> 
> Would you please share your ideas and respond Mike's question too?
> 
> Thanks,
> Chasel
> 
> 
> 
>> -----Original Message-----
>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chiu, Chasel
>> Sent: Tuesday, April 25, 2023 10:22 PM
>> To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>;
>> Leif Lindholm <quic_llindhol@quicinc.com>
>> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
>> <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu,
>> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
>> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
>>
>>
>> Hello,
>>
>> Since platform may also define other FDT structures, this EDK2 library may not
>> be able to convert all the FDT structures to little endian.
>> We might define a generic MACRO in library like
>> CONVERT_FDT_DATA_TO_LITTLE_ENDIAN which can be used for all structure
>> data, but it will be almost like calling SwapBytes** directly.
>> Any other suggestion?
>>
>> Thanks,
>> Chasel
>>
>>
>>> -----Original Message-----
>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Michael D
>>> Kinney
>>> Sent: Monday, April 24, 2023 10:41 AM
>>> To: Leif Lindholm <quic_llindhol@quicinc.com>; devel@edk2.groups.io
>>> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
>>> <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
>> Liu,
>>> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
>> <pedro.falcato@gmail.com>;
>>> Kinney, Michael D <michael.d.kinney@intel.com>
>>> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
>>>
>>> Hi Leif,
>>>
>>> Do you have a proposal or small example on what you want to see
>>> in the library?
>>>
>>> Mike
>>>
>>>> -----Original Message-----
>>>> From: Leif Lindholm <quic_llindhol@quicinc.com>
>>>> Sent: Monday, April 24, 2023 10:29 AM
>>>> To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>
>>>> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
>>> <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
>> Liu,
>>>> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
>>> <pedro.falcato@gmail.com>
>>>> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
>>>>
>>>> Apologies, I was refactoring a git tree and switched off the world :)
>>>>
>>>> Well, being a bit late to the party ... my view is it would be
>>>> preferable if we put the byteswapping in the library.
>>>>
>>>> The DT format is *defined* to be big-endian, 32-bit cells. So frankly,
>>>> I have no problems with pushing responsibility onto individual
>>>> platforms if they have decided to be "clever" by ignoring that -
>>>> if that gets rid of a bunch of boilerplate for sensibly behaving platforms.
>>>>
>>>> Maybe another excuse for getting
>>>> https://github.com/tianocore/edk2-
>>> platforms/blob/master/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
>>>> into MdePkg?
>>>>
>>>> /
>>>>      Leif
>>>>
>>>> On Thu, Apr 20, 2023 at 16:44:03 +0000, Michael D Kinney wrote:
>>>>> Hi Leif,
>>>>>
>>>>> What is your opinion on FDT being big endian.
>>>>>
>>>>> Do we want the lib to help with that aspect, or leave it up to the consumer
>> of
>>> the lib to
>>>>> convert as needed?  Seems like an area that could be very error prone if we
>>> are not
>>>>> careful.
>>>>>
>>>>> Mike
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Lin, Benny <benny.lin@intel.com>
>>>>>> Sent: Wednesday, April 19, 2023 9:25 PM
>>>>>> To: Kinney, Michael D <michael.d.kinney@intel.com>;
>>> devel@edk2.groups.io
>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
>>> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
>>>>>>
>>>>>>
>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: Kinney, Michael D <michael.d.kinney@intel.com>
>>>>>>> Sent: Thursday, April 20, 2023 5:04 AM
>>>>>>> To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
>>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
>>> <zhiguang.liu@intel.com>; Pedro Falcato
>>>> <pedro.falcato@gmail.com>; Kinney,
>>>>>> Michael D <michael.d.kinney@intel.com>
>>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
>>>>>>>
>>>>>>> Responses below
>>>>>>>
>>>>>>> Mike
>>>>>>>
>>>>>>>> -----Original Message-----
>>>>>>>> From: Lin, Benny <benny.lin@intel.com>
>>>>>>>> Sent: Wednesday, April 19, 2023 10:12 AM
>>>>>>>> To: Kinney, Michael D <michael.d.kinney@intel.com>;
>>>>>>>> devel@edk2.groups.io
>>>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
>>>>>>>> <zhiguang.liu@intel.com>; Pedro Falcato
>> <pedro.falcato@gmail.com>
>>>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
>>>>>>>>
>>>>>>>> Please find my feedback below.
>>>>>>>> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER,
>>> what do you think?
>>>>>>>>
>>>>>>>> QQQ
>>>>>>>> Benny
>>>>>>>>
>>>>>>>>> -----Original Message-----
>>>>>>>>> From: Kinney, Michael D <michael.d.kinney@intel.com>
>>>>>>>>> Sent: Wednesday, April 19, 2023 11:54 PM
>>>>>>>>> To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
>>>>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
>>>>>>>>> <zhiguang.liu@intel.com>; Pedro Falcato
>> <pedro.falcato@gmail.com>;
>>>>>>>>> Kinney,
>>>>>>>> Michael D <michael.d.kinney@intel.com>
>>>>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
>>>>>>>>>
>>>>>>>>> A few comments below.
>>>>>>>>>
>>>>>>>>> Mike
>>>>>>>>>
>>>>>>>>>> -----Original Message-----
>>>>>>>>>> From: Lin, Benny <benny.lin@intel.com>
>>>>>>>>>> Sent: Sunday, April 16, 2023 10:35 PM
>>>>>>>>>> To: devel@edk2.groups.io
>>>>>>>>>> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
>>>>>>>>>> <michael.d.kinney@intel.com>; Gao, Liming
>>>>>>>>>> <gaoliming@byosoft.com.cn>; Liu, Zhiguang
>>> <zhiguang.liu@intel.com>;
>>>>>>>>>> Pedro Falcato <pedro.falcato@gmail.com>
>>>>>>>>>> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
>>>>>>>>>>
>>>>>>>>>> From: Benny Lin <benny.lin@intel.com>
>>>>>>>>>>
>>>>>>>>>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
>>>>>>>>>> Add FDT support in EDK2 by submodule 3rd party libfdt
>>>>>>>>>> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
>>>>>>>>>> and refer to LibcLib implementation by Pedro.
>>>>>>>>>>
>>>>>>>>>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>>>>>>>>>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>>>>>>>>>> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
>>>>>>>>>> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
>>>>>>>>>> Signed-off-by: Benny Lin <benny.lin@intel.com>
>>>>>>>>>> ---
>>>>>>>>>>   MdePkg/Include/Library/FdtLib.h           | 314
>>> ++++++++++++++++++++
>>>>>>>>>>   MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
>>>>>>>>>> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
>>>>>>>>>>   MdePkg/Library/BaseFdtLib/FdtLib.c        | 301
>>> +++++++++++++++++++
>>>>>>>>>>   MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
>>>>>>>>>> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
>>>>>>>>>>   MdePkg/Library/BaseFdtLib/limits.h        |  10 +
>>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
>>>>>>>>>>   MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
>>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
>>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
>>>>>>>>>>   MdePkg/Library/BaseFdtLib/string.h        |  10 +
>>>>>>>>>>   MdePkg/MdePkg.ci.yaml                     |  17 +-
>>>>>>>>>>   MdePkg/MdePkg.dec                         |   4 +
>>>>>>>>>>   MdePkg/MdePkg.dsc                         |   1 +
>>>>>>>>>>   15 files changed, 1043 insertions(+), 2 deletions(-)
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Include/Library/FdtLib.h
>>>>>>>>>> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
>>>>>>>>>> 0000000000..d59b749c25
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Include/Library/FdtLib.h
>>>>>>>>>> @@ -0,0 +1,314 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  Flattened Device Tree Library.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#ifndef FDT_LIB_H_
>>>>>>>>>>
>>>>>>>>>> +#define FDT_LIB_H_
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +///
>>>>>>>>>>
>>>>>>>>>> +/// Flattened Device Tree definition
>>>>>>>>>>
>>>>>>>>>> +///
>>>>>>>>>>
>>>>>>>>>> +typedef struct {
>>>>>>>>>>
>>>>>>>>>> +  UINT32    Magic;               /* magic word FDT_MAGIC */
>>>>>>>>>>
>>>>>>>>>> +  UINT32    TotalSize;           /* total size of DT block */
>>>>>>>>>>
>>>>>>>>>> +  UINT32    OffsetDtStruct;      /* offset to structure */
>>>>>>>>>>
>>>>>>>>>> +  UINT32    OffsetDtStrings;     /* offset to strings */
>>>>>>>>>>
>>>>>>>>>> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve
>> map
>>> */
>>>>>>>>>>
>>>>>>>>>> +  UINT32    Version;             /* format version */
>>>>>>>>>>
>>>>>>>>>> +  UINT32    LastCompVersion;     /* last compatible version */
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  /* version 2 fields below */
>>>>>>>>>>
>>>>>>>>>> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
>>>>>>>>>>
>>>>>>>>>> +                                    booting on */
>>>>>>>>>>
>>>>>>>>>> +  /* version 3 fields below */
>>>>>>>>>>
>>>>>>>>>> +  UINT32    SizeDtStrings;       /* size of the strings block */
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  /* version 17 fields below */
>>>>>>>>>>
>>>>>>>>>> +  UINT32    SizeDtStruct;        /* size of the structure block */
>>>>>>>>>>
>>>>>>>>>> +} FDT_HEADER;
>>>>>>>>>
>>>>>>>>> I see the macros below use SwapBytes32() on all the fields from this
>>>>>>>>> structure.  Does this mean this structure is big >endian?  If
>>>>>>>> that is the case, then the description of this structure and all
>>>>>>>> individual fields must make that very clear >so any consumer of the
>>>>>>>> structure knows it does not follow the default endianness of UEFI/PI
>>> and that consumers >must either use the macros or
>>>> consumers
>>>>>> must use SwapBytes32() on their own when using this structure directly.
>>>>>>>>
>>>>>>>> Yes, it's big endian. I will complete more descriptions in patch v4.
>>>>>>>
>>>>>>> Would it be simpler if we have a lib service that converts the entire
>> header
>>> from big endian to little endian.
>>>>>>> That way, the consumer can use the FDT_HEADER directly without any
>> of
>>> the macros?
>>>>>>>
>>>>>>> Also, is the rest of the FDT blob also big endian?
>>>>>>
>>>>>> FDT blob format is binary encoding of FDT data with big endian. In
>> addition,
>>> the consumer will set or get FDT data with FDT
>>>> blob. We
>>>>>> can complete more descriptions to warn consumers to be careful if just
>> use
>>> header struct for mapping and get/set FDT data
>>>> with FDT
>>>>>> blob.
>>>>>>
>>>>>> For provide lib services that converts between big endian and little endian,
>>> we can provide a get header function to convert
>>>> between
>>>>>> big endian and little endian. However, we also need to consider the
>>> property value for setting and getting then we can
>>>> convert in
>>>>>> wrapper functions.
>>>>>>
>>>>>> For example,
>>>>>>
>>>>>> INT32
>>>>>> EFIAPI
>>>>>> FdtSetProp (
>>>>>>    IN VOID         *Fdt,
>>>>>>    IN INT32        NodeOffset,
>>>>>>    IN CONST CHAR8  *Name,
>>>>>>    IN CONST VOID   *Value,
>>>>>>    IN UINT32       Length
>>>>>>    )
>>>>>> {
>>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
>>>>>> }
>>>>>>
>>>>>> More functions for various byte width.
>>>>>> INT32
>>>>>> EFIAPI
>>>>>> FdtSetProp16 (
>>>>>>    IN VOID         *Fdt,
>>>>>>    IN INT32        NodeOffset,
>>>>>>    IN CONST CHAR8  *Name,
>>>>>>    IN CONST UINT16   *Value,
>>>>>>    IN UINT32       Length
>>>>>>    )
>>>>>> {
>>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value),
>>> (int)Length);
>>>>>> }
>>>>>>
>>>>>> INT32
>>>>>> EFIAPI
>>>>>> FdtSetProp32 (
>>>>>>    IN VOID         *Fdt,
>>>>>>    IN INT32        NodeOffset,
>>>>>>    IN CONST CHAR8  *Name,
>>>>>>    IN CONST UINT32   *Value,
>>>>>>    IN UINT32       Length
>>>>>>    )
>>>>>> {
>>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value),
>>> (int)Length);
>>>>>> }
>>>>>>
>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +typedef struct {
>>>>>>>>>>
>>>>>>>>>> +  UINT64    Address;
>>>>>>>>>>
>>>>>>>>>> +  UINT64    Size;
>>>>>>>>>>
>>>>>>>>>> +} FDT_RESERVE_ENTRY;
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I do not see this type used anywhere in the lib class or the lib instance.
>>>>>>>>> Can it be removed?
>>>>>>>>
>>>>>>>> I think we can remove it because it might be not used for further
>> usage
>>> of FDT support.
>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +typedef struct {
>>>>>>>>>>
>>>>>>>>>> +  UINT32    Tag;
>>>>>>>>>>
>>>>>>>>>> +  CHAR8     Name[];
>>>>>>>>>>
>>>>>>>>>> +} FDT_NODE_HEADER;
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I do not see this type used anywhere in the lib class or the lib instance.
>>>>>>>>> Can it be removed?
>>>>>>>>
>>>>>>>> When we need retrieve a node from a FDT blob, we will get a node
>>>>>>>> offset then we could use the struct to map the node content. It's very
>>> useful.
>>>>>>>
>>>>>>> Please add a comment header for this structure and describe the usage
>> as
>>> it related to the rest of the FdtLib >services.
>>>>>>
>>>>>> I will add descriptions for the usage and remove FDT_RESERVE_ENTRY in
>>> patch v4.
>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +typedef struct {
>>>>>>>>>>
>>>>>>>>>> +  UINT32    Tag;
>>>>>>>>>>
>>>>>>>>>> +  UINT32    Length;
>>>>>>>>>>
>>>>>>>>>> +  UINT32    NameOffset;
>>>>>>>>>>
>>>>>>>>>> +  CHAR8     Data[];
>>>>>>>>>>
>>>>>>>>>> +} FDT_PROPERTY;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST
>>> FDT_HEADER
>>>>>>>>>> +*)(Fdt))->Field)
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
>>>>>>>>>>
>>>>>>>>>> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt,
>>> TotalSize))
>>>>>>>>>>
>>>>>>>>>> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt,
>>> OffsetDtStruct))
>>>>>>>>>>
>>>>>>>>>> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
>>>>>>>>>> +OffsetDtStrings))
>>>>>>>>>>
>>>>>>>>>> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
>>>>>>>>>> +OffsetMemRsvmap))
>>>>>>>>>>
>>>>>>>>>> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
>>>>>>>>>>
>>>>>>>>>> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
>>>>>>>>>> +LastCompVersion))
>>>>>>>>>>
>>>>>>>>>> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt,
>>> BootCpuidPhys))
>>>>>>>>>>
>>>>>>>>>> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt,
>>> SizeDtStrings))
>>>>>>>>>>
>>>>>>>>>> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt,
>>> SizeDtStruct))
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Verify the header of the Flattened Device Tree
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return Zero for successfully, otherwise failed.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtCheckHeader (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Create a empty Flattened Device Tree.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Buffer         The pointer to allocate a pool for FDT
>> blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] BufferSize     The BufferSize to the pool size.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return Zero for successfully, otherwise failed.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +RETURN_STATUS
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtCreateEmptyTree (
>>>>>>>>>>
>>>>>>>>>> +  IN VOID   *Buffer,
>>>>>>>>>>
>>>>>>>>>> +  IN UINTN  BufferSize
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of next node from the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to previous node.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Depth          The depth to the level of tree hierarchy.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to next node offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtNextNode (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       *Depth
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of first node under the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to previous node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to next node offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtFirstSubnode (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of next node from the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to previous node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to next node offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtNextSubnode (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of first node which includes the given name.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] ParentOffset    The offset to the node which start
>> find
>>> under.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Name            The name to search the node with the
>>> name.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] NameLength      The length of the name to check
>> only.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to node offset with given node name.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtSubnodeOffsetNameLen (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        ParentOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *Name,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        NameLength
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of first node which includes the given property
>>> name and value.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] StartOffset     The offset to the starting node to find.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] PropertyName    The property name to search the
>>> node including the named property.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] PropertyValue   The property value to check the
>> same
>>> property value.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] PropertyLength  The length of the value in
>>> PropertValue.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to node offset with given property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtNodeOffsetByPropValue (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        StartOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *PropertyName,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *PropertyValue,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        PropertyLength
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a property with the given name from the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] NodeOffset     The offset to the given node.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Name           The name to the property which need
>> be
>>> searched
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Length         The length to the size of the property
>>> found.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The property to the structure of the found property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +CONST FDT_PROPERTY *
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtGetProperty (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        NodeOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *Name,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        *Length
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of first property in the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to the node which need be
>>> searched.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to first property offset in the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtFirstPropertyOffset (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       NodeOffset
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of next property from the given property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to previous property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to next property offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtNextPropertyOffset (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a property from the given offset of the property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to the given offset of the
>>> property.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Length         The length to the size of the property
>>> found.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The property to the structure of the given property
>> offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +CONST FDT_PROPERTY *
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtGetPropertyByOffset (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       *Length
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a string by the given string offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] StrOffset      The offset to the location in the strings
>>> block of FDT.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Length         The length to the size of string which
>> need
>>> be retrieved.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The string to the given string offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +CONST CHAR8 *
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtGetString (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       StrOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       *Length        OPTIONAL
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Add a new node to the FDT.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] ParentOffset   The offset to the node offset which
>>> want to add in.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Name           The name to name the node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return  The offset to the new node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtAddSubnode (
>>>>>>>>>>
>>>>>>>>>> +  IN VOID         *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        ParentOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *Name
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Add or modify a property in the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] NodeOffset     The offset to the node offset which
>>> want to add in.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Name           The name to name the property.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Value          The value to the property value.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Length         The length to the size of the property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return  Zero for successfully, otherwise failed.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtSetProp (
>>>>>>>>>>
>>>>>>>>>> +  IN VOID         *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        NodeOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *Name,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *Value,
>>>>>>>>>>
>>>>>>>>>> +  IN UINT32       Length
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#endif /* FDT_LIB_H_ */
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..730e568ff6
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>>>>>>>>>> @@ -0,0 +1,62 @@
>>>>>>>>>> +## @file
>>>>>>>>>>
>>>>>>>>>> +# Flattened Device Tree Library.
>>>>>>>>>>
>>>>>>>>>> +#
>>>>>>>>>>
>>>>>>>>>> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +#
>>>>>>>>>>
>>>>>>>>>> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +#
>>>>>>>>>>
>>>>>>>>>> +#
>>>>>>>>>>
>>>>>>>>>> +##
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +[Defines]
>>>>>>>>>>
>>>>>>>>>> +  INF_VERSION                    = 0x0001001B
>>>>>>>>>>
>>>>>>>>>> +  BASE_NAME                      = BaseFdtLib
>>>>>>>>>>
>>>>>>>>>> +  MODULE_UNI_FILE                = BaseFdtLib.uni
>>>>>>>>>>
>>>>>>>>>> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-
>>> E8CEC206DE04
>>>>>>>>>>
>>>>>>>>>> +  MODULE_TYPE                    = BASE
>>>>>>>>>>
>>>>>>>>>> +  VERSION_STRING                 = 1.0
>>>>>>>>>>
>>>>>>>>>> +  LIBRARY_CLASS                  = FdtLib
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#
>>>>>>>>>>
>>>>>>>>>> +#  VALID_ARCHITECTURES           = IA32 X64
>>>>>>>>>>
>>>>>>>>>> +#
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +[Sources]
>>>>>>>>>>
>>>>>>>>>> +  FdtLib.c
>>>>>>>>>>
>>>>>>>>>> +  LibFdtWrapper.c
>>>>>>>>>>
>>>>>>>>>> +  # header Wrapper files
>>>>>>>>>>
>>>>>>>>>> +  limits.h
>>>>>>>>>>
>>>>>>>>>> +  stdbool.h
>>>>>>>>>>
>>>>>>>>>> +  stddef.h
>>>>>>>>>>
>>>>>>>>>> +  stdint.h
>>>>>>>>>>
>>>>>>>>>> +  stdlib.h
>>>>>>>>>>
>>>>>>>>>> +  string.h
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt.h
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_addresses.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_check.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_overlay.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_ro.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_rw.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_strerror.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_sw.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_wip.c
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt.h
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt_env.h
>>>>>>>>>>
>>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt_internal.h
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +[Packages]
>>>>>>>>>>
>>>>>>>>>> +  MdePkg/MdePkg.dec
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +[LibraryClasses]
>>>>>>>>>>
>>>>>>>>>> +  BaseLib
>>>>>>>>>>
>>>>>>>>>> +  BaseMemoryLib
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +[BuildOptions]
>>>>>>>>>>
>>>>>>>>>> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
>>>>>>>>>>
>>>>>>>>>> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245
>> /wd4267
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..3f7e45ea6f
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
>>>>>>>>>> @@ -0,0 +1,14 @@
>>>>>>>>>> +// /** @file
>>>>>>>>>>
>>>>>>>>>> +// Flattened Device Tree Library.
>>>>>>>>>>
>>>>>>>>>> +//
>>>>>>>>>>
>>>>>>>>>> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +//
>>>>>>>>>>
>>>>>>>>>> +// SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +//
>>>>>>>>>>
>>>>>>>>>> +// **/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#string STR_MODULE_ABSTRACT             #language en-US
>> "Instance
>>> of FDT Library"
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#string STR_MODULE_DESCRIPTION          #language en-US "This
>>> module provides FDT Library implementation."
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/FdtLib.c
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..200a496c7e
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
>>>>>>>>>> @@ -0,0 +1,301 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  Flattened Device Tree Library.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#include <libfdt/libfdt/libfdt.h>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Verify the header of the Flattened Device Tree
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return Zero for successfully, otherwise failed.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtCheckHeader (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_check_header(Fdt);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Create a empty Flattened Device Tree.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Buffer         The pointer to allocate a pool for FDT
>> blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] BufferSize     The BufferSize to the pool size.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return Zero for successfully, otherwise failed.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtCreateEmptyTree (
>>>>>>>>>>
>>>>>>>>>> +  IN VOID    *Buffer,
>>>>>>>>>>
>>>>>>>>>> +  IN UINT32  BufferSize
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of next node from the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to previous node.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Depth          The depth to the level of tree hierarchy.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to next node offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtNextNode (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       *Depth
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_next_node (Fdt, Offset, Depth);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of first node under the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to previous node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to next node offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtFirstSubnode (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_first_subnode (Fdt, Offset);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of next node from the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to previous node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to next node offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtNextSubnode (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_next_subnode (Fdt, Offset);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of first node which includes the given name.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] ParentOffset    The offset to the node which start
>> find
>>> under.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Name            The name to search the node with the
>>> name.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] NameLength      The length of the name to check
>> only.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to node offset with given node name.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtSubnodeOffsetNameLen (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        ParentOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *Name,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        NameLength
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name,
>>>>>>>>>> + NameLength);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of first node which includes the given property
>>> name and value.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] StartOffset     The offset to the starting node to find.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] PropertyName    The property name to search the
>>> node including the named property.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] PropertyValue   The property value to check the
>> same
>>> property value.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] PropertyLength  The length of the value in
>>> PropertValue.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to node offset with given property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtNodeOffsetByPropValue (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        StartOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *PropertyName,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *PropertyValue,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        PropertyLength
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
>>>>>>>>>> + PropertyName, PropertyValue, PropertyLength);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a property with the given name from the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] NodeOffset     The offset to the given node.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Name           The name to the property which need
>> be
>>> searched
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Length         The length to the size of the property
>>> found.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The property to the structure of the found property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +CONST struct fdt_property *
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtGetProperty (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        NodeOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *Name,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        *Length
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of first property in the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] NodeOffset     The offset to the node which need be
>>> searched.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to first property offset in the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtFirstPropertyOffset (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       NodeOffset
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_first_property_offset (Fdt, NodeOffset);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a offset of next property from the given property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to previous property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The offset to next property offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtNextPropertyOffset (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_next_property_offset (Fdt, Offset);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a property from the given offset of the property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Offset         The offset to the given offset of the
>>> property.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Length         The length to the size of the property
>>> found.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The property to the structure of the given property
>> offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +CONST struct fdt_property *
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtGetPropertyByOffset (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       Offset,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       *Length
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Returns a string by the given string offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] StrOffset      The offset to the location in the strings
>>> block of FDT.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Length         The length to the size of string which
>> need
>>> be retrieved.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return The string to the given string offset.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +CONST CHAR8 *
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtGetString (
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID  *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       StrOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32       *Length        OPTIONAL
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_get_string (Fdt, StrOffset, Length);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Add a new node to the FDT.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] ParentOffset   The offset to the node offset which
>>> want to add in.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Name           The name to name the node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return  The offset to the new node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtAddSubnode (
>>>>>>>>>>
>>>>>>>>>> +  IN VOID         *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        ParentOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *Name
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +/**
>>>>>>>>>>
>>>>>>>>>> +  Add or modify a property in the given node.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] NodeOffset     The offset to the node offset which
>>> want to add in.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Name           The name to name the property.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Value          The value to the property value.
>>>>>>>>>>
>>>>>>>>>> +  @param[in] Length         The length to the size of the property.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  @return  Zero for successfully, otherwise failed.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +INT32
>>>>>>>>>>
>>>>>>>>>> +EFIAPI
>>>>>>>>>>
>>>>>>>>>> +FdtSetProp (
>>>>>>>>>>
>>>>>>>>>> +  IN VOID         *Fdt,
>>>>>>>>>>
>>>>>>>>>> +  IN INT32        NodeOffset,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST CHAR8  *Name,
>>>>>>>>>>
>>>>>>>>>> +  IN CONST VOID   *Value,
>>>>>>>>>>
>>>>>>>>>> +  IN UINT32       Length
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..e738f4ded4
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
>>>>>>>>>> @@ -0,0 +1,99 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  Root include file of C runtime library to support building the
>>>>>>>>>> + third-party
>>>>>>>>>>
>>>>>>>>>> +  libfdt library.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#ifndef FDT_LIB_SUPPORT_H_
>>>>>>>>>>
>>>>>>>>>> +#define FDT_LIB_SUPPORT_H_
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#include <Base.h>
>>>>>>>>>>
>>>>>>>>>> +#include <Library/BaseLib.h>
>>>>>>>>>>
>>>>>>>>>> +#include <Library/BaseMemoryLib.h>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +typedef UINT8    uint8_t;
>>>>>>>>>>
>>>>>>>>>> +typedef UINT16   uint16_t;
>>>>>>>>>>
>>>>>>>>>> +typedef INT32    int32_t;
>>>>>>>>>>
>>>>>>>>>> +typedef UINT32   uint32_t;
>>>>>>>>>>
>>>>>>>>>> +typedef UINT64   uint64_t;
>>>>>>>>>>
>>>>>>>>>> +typedef UINTN    uintptr_t;
>>>>>>>>>>
>>>>>>>>>> +typedef UINTN    size_t;
>>>>>>>>>>
>>>>>>>>>> +typedef BOOLEAN  bool;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#define true   (1 == 1)
>>>>>>>>>>
>>>>>>>>>> +#define false  (1 == 0)
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +//
>>>>>>>>>>
>>>>>>>>>> +// Definitions for global constants used by libfdt library
>>>>>>>>>> +routines
>>>>>>>>>>
>>>>>>>>>> +//
>>>>>>>>>>
>>>>>>>>>> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int
>> value
>>> */
>>>>>>>>>>
>>>>>>>>>> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32
>>> value */
>>>>>>>>>>
>>>>>>>>>> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned
>> int32
>>> value */
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +//
>>>>>>>>>>
>>>>>>>>>> +// Function prototypes of libfdt Library routines
>>>>>>>>>>
>>>>>>>>>> +//
>>>>>>>>>>
>>>>>>>>>> +void *
>>>>>>>>>>
>>>>>>>>>> +memset     (
>>>>>>>>>>
>>>>>>>>>> +  void *,
>>>>>>>>>>
>>>>>>>>>> +  int,
>>>>>>>>>>
>>>>>>>>>> +  size_t
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +int
>>>>>>>>>>
>>>>>>>>>> +memcmp      (
>>>>>>>>>>
>>>>>>>>>> +  const void *,
>>>>>>>>>>
>>>>>>>>>> +  const void *,
>>>>>>>>>>
>>>>>>>>>> +  size_t
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +int
>>>>>>>>>>
>>>>>>>>>> +strcmp      (
>>>>>>>>>>
>>>>>>>>>> +  const char *,
>>>>>>>>>>
>>>>>>>>>> +  const char *
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +char *
>>>>>>>>>>
>>>>>>>>>> +strchr     (
>>>>>>>>>>
>>>>>>>>>> +  const char *,
>>>>>>>>>>
>>>>>>>>>> +  int
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +char *
>>>>>>>>>>
>>>>>>>>>> +strrchr    (
>>>>>>>>>>
>>>>>>>>>> +  const char *,
>>>>>>>>>>
>>>>>>>>>> +  int
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +unsigned long
>>>>>>>>>>
>>>>>>>>>> +strtoul     (
>>>>>>>>>>
>>>>>>>>>> +  const char *,
>>>>>>>>>>
>>>>>>>>>> +  char **,
>>>>>>>>>>
>>>>>>>>>> +  int
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +char *
>>>>>>>>>>
>>>>>>>>>> +strcpy (
>>>>>>>>>>
>>>>>>>>>> +  char        *strDest,
>>>>>>>>>>
>>>>>>>>>> +  const char  *strSource
>>>>>>>>>>
>>>>>>>>>> +  );
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +//
>>>>>>>>>>
>>>>>>>>>> +// Macros that directly map functions to BaseLib, BaseMemoryLib,
>>>>>>>>>> +and DebugLib functions
>>>>>>>>>>
>>>>>>>>>> +//
>>>>>>>>>>
>>>>>>>>>> +#define memcpy(dest, source, count)         CopyMem(dest,source,
>>> (UINTN)(count))
>>>>>>>>>>
>>>>>>>>>> +#define memset(dest, ch, count)             SetMem(dest,
>>> (UINTN)(count),(UINT8)(ch))
>>>>>>>>>>
>>>>>>>>>> +#define memchr(buf, ch, count)              ScanMem8(buf,
>>> (UINTN)(count),(UINT8)ch)
>>>>>>>>>>
>>>>>>>>>> +#define memcmp(buf1, buf2, count)
>> (int)(CompareMem(buf1,
>>> buf2, (UINTN)(count)))
>>>>>>>>>>
>>>>>>>>>> +#define memmove(dest, source, count)        CopyMem(dest,
>> source,
>>> (UINTN)(count))
>>>>>>>>>>
>>>>>>>>>> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
>>>>>>>>>>
>>>>>>>>>> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str,
>> count))
>>>>>>>>>>
>>>>>>>>>> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest,
>>>>>>>>>> +MAX_STRING_SIZE, strSource, (UINTN)count)
>>>>>>>>>>
>>>>>>>>>> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest,
>>> MAX_STRING_SIZE, strSource)
>>>>>>>>>>
>>>>>>>>>> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1,
>>> string2))
>>>>>>>>>>
>>>>>>>>>> +#define strncmp(string1, string2, count)
>> (int)(AsciiStrnCmp(string1,
>>> string2, (UINTN)(count)))
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#endif /* FDT_LIB_SUPPORT_H_ */
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..772bba4839
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
>>>>>>>>>> @@ -0,0 +1,173 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  ISO C implementations of strchr, strrchr and strtoul.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
>>>>>>>>>>
>>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#include <Base.h>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned
>> long
>>> value */
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +// Very quick notes:
>>>>>>>>>>
>>>>>>>>>> +// We only go through the string once for both functions
>>>>>>>>>>
>>>>>>>>>> +// They are minimal implementations (not speed optimized) of ISO
>> C
>>>>>>>>>> +semantics
>>>>>>>>>>
>>>>>>>>>> +// strchr and strrchr also include the null terminator as part of
>>>>>>>>>> +the string
>>>>>>>>>>
>>>>>>>>>> +// so the code gets a bit clunky to handle that case specifically.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +char *
>>>>>>>>>>
>>>>>>>>>> +strchr (
>>>>>>>>>>
>>>>>>>>>> +  const char  *Str,
>>>>>>>>>>
>>>>>>>>>> +  int         Char
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  char  *S;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  S = (char *)Str;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  for ( ; ; S++) {
>>>>>>>>>>
>>>>>>>>>> +    if (*S == Char) {
>>>>>>>>>>
>>>>>>>>>> +      return S;
>>>>>>>>>>
>>>>>>>>>> +    }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +    if (*S == '\0') {
>>>>>>>>>>
>>>>>>>>>> +      return NULL;
>>>>>>>>>>
>>>>>>>>>> +    }
>>>>>>>>>>
>>>>>>>>>> +  }
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +char *
>>>>>>>>>>
>>>>>>>>>> +strrchr (
>>>>>>>>>>
>>>>>>>>>> +  const char  *Str,
>>>>>>>>>>
>>>>>>>>>> +  int         Char
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  char  *S, *last;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  S    = (char *)Str;
>>>>>>>>>>
>>>>>>>>>> +  last = NULL;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  for ( ; ; S++) {
>>>>>>>>>>
>>>>>>>>>> +    if (*S == Char) {
>>>>>>>>>>
>>>>>>>>>> +      last = S;
>>>>>>>>>>
>>>>>>>>>> +    }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +    if (*S == '\0') {
>>>>>>>>>>
>>>>>>>>>> +      return last;
>>>>>>>>>>
>>>>>>>>>> +    }
>>>>>>>>>>
>>>>>>>>>> +  }
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +STATIC
>>>>>>>>>>
>>>>>>>>>> +int
>>>>>>>>>>
>>>>>>>>>> +__isspace (
>>>>>>>>>>
>>>>>>>>>> +  int  ch
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  // basic ASCII ctype.h:isspace(). Not efficient
>>>>>>>>>>
>>>>>>>>>> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
>>>>>>>>>> + == '\v' || ch == '\f';
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +unsigned long
>>>>>>>>>>
>>>>>>>>>> +strtoul (
>>>>>>>>>>
>>>>>>>>>> +  const char  *Nptr,
>>>>>>>>>>
>>>>>>>>>> +  char        **EndPtr,
>>>>>>>>>>
>>>>>>>>>> +  int         Base
>>>>>>>>>>
>>>>>>>>>> +  )
>>>>>>>>>>
>>>>>>>>>> +{
>>>>>>>>>>
>>>>>>>>>> +  BOOLEAN        Negate;
>>>>>>>>>>
>>>>>>>>>> +  BOOLEAN        Overflow;
>>>>>>>>>>
>>>>>>>>>> +  unsigned long  Val;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  Negate   = FALSE;
>>>>>>>>>>
>>>>>>>>>> +  Overflow = FALSE;
>>>>>>>>>>
>>>>>>>>>> +  Val      = 0;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  // Reject bad numeric bases
>>>>>>>>>>
>>>>>>>>>> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
>>>>>>>>>>
>>>>>>>>>> +    return 0;
>>>>>>>>>>
>>>>>>>>>> +  }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  // Skip whitespace
>>>>>>>>>>
>>>>>>>>>> +  while (__isspace (*Nptr)) {
>>>>>>>>>>
>>>>>>>>>> +    Nptr++;
>>>>>>>>>>
>>>>>>>>>> +  }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  // Check for + or - prefixes
>>>>>>>>>>
>>>>>>>>>> +  if (*Nptr == '-') {
>>>>>>>>>>
>>>>>>>>>> +    Negate = TRUE;
>>>>>>>>>>
>>>>>>>>>> +    Nptr++;
>>>>>>>>>>
>>>>>>>>>> +  } else if (*Nptr == '+') {
>>>>>>>>>>
>>>>>>>>>> +    Nptr++;
>>>>>>>>>>
>>>>>>>>>> +  }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  // Consume the start, autodetecting base if needed
>>>>>>>>>>
>>>>>>>>>> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
>>>>>>>>>> + && ((Base == 0) || (Base == 16))) {
>>>>>>>>>>
>>>>>>>>>> +    // Hex
>>>>>>>>>>
>>>>>>>>>> +    Nptr += 2;
>>>>>>>>>>
>>>>>>>>>> +    Base  = 16;
>>>>>>>>>>
>>>>>>>>>> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
>>>>>>>>>> + 'B')) && ((Base == 0) || (Base == 2))) {
>>>>>>>>>>
>>>>>>>>>> +    // Binary (standard pending C23)
>>>>>>>>>>
>>>>>>>>>> +    Nptr += 2;
>>>>>>>>>>
>>>>>>>>>> +    Base  = 2;
>>>>>>>>>>
>>>>>>>>>> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
>>>>>>>>>>
>>>>>>>>>> +    // Octal
>>>>>>>>>>
>>>>>>>>>> +    Nptr++;
>>>>>>>>>>
>>>>>>>>>> +    Base = 8;
>>>>>>>>>>
>>>>>>>>>> +  } else {
>>>>>>>>>>
>>>>>>>>>> +    if (Base == 0) {
>>>>>>>>>>
>>>>>>>>>> +      // Assume decimal
>>>>>>>>>>
>>>>>>>>>> +      Base = 10;
>>>>>>>>>>
>>>>>>>>>> +    }
>>>>>>>>>>
>>>>>>>>>> +  }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  while (TRUE) {
>>>>>>>>>>
>>>>>>>>>> +    int            Digit;
>>>>>>>>>>
>>>>>>>>>> +    char           C;
>>>>>>>>>>
>>>>>>>>>> +    unsigned long  NewVal;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +    C     = *Nptr;
>>>>>>>>>>
>>>>>>>>>> +    Digit = -1;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +    if ((C >= '0') && (C <= '9')) {
>>>>>>>>>>
>>>>>>>>>> +      Digit = C - '0';
>>>>>>>>>>
>>>>>>>>>> +    } else if ((C >= 'a') && (C <= 'z')) {
>>>>>>>>>>
>>>>>>>>>> +      Digit = C - 'a' + 10;
>>>>>>>>>>
>>>>>>>>>> +    } else if ((C >= 'A') && (C <= 'Z')) {
>>>>>>>>>>
>>>>>>>>>> +      Digit = C - 'A' + 10;
>>>>>>>>>>
>>>>>>>>>> +    }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +    if ((Digit == -1) || (Digit >= Base)) {
>>>>>>>>>>
>>>>>>>>>> +      // Note that this case also handles the \0
>>>>>>>>>>
>>>>>>>>>> +      if (EndPtr) {
>>>>>>>>>>
>>>>>>>>>> +        *EndPtr = (char *)Nptr;
>>>>>>>>>>
>>>>>>>>>> +      }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +      break;
>>>>>>>>>>
>>>>>>>>>> +    }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +    NewVal = Val * Base + Digit;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +    if (NewVal < Val) {
>>>>>>>>>>
>>>>>>>>>> +      // Overflow
>>>>>>>>>>
>>>>>>>>>> +      Overflow = TRUE;
>>>>>>>>>>
>>>>>>>>>> +    }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +    Val = NewVal;
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +    Nptr++;
>>>>>>>>>>
>>>>>>>>>> +  }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  if (Negate) {
>>>>>>>>>>
>>>>>>>>>> +    Val = -Val;
>>>>>>>>>>
>>>>>>>>>> +  }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  if (Overflow) {
>>>>>>>>>>
>>>>>>>>>> +    Val = ULONG_MAX;
>>>>>>>>>>
>>>>>>>>>> +  }
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +  // TODO: We're lacking errno here.
>>>>>>>>>>
>>>>>>>>>> +  return Val;
>>>>>>>>>>
>>>>>>>>>> +}
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/limits.h
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..f6cf8d5702
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/limits.h
>>>>>>>>>> @@ -0,0 +1,10 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  Include file to support building the third-party libfdt library.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#include <LibFdtSupport.h>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdbool.h
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..f6cf8d5702
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
>>>>>>>>>> @@ -0,0 +1,10 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  Include file to support building the third-party libfdt library.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#include <LibFdtSupport.h>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stddef.h
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..f6cf8d5702
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
>>>>>>>>>> @@ -0,0 +1,10 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  Include file to support building the third-party libfdt library.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#include <LibFdtSupport.h>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdint.h
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..f6cf8d5702
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
>>>>>>>>>> @@ -0,0 +1,10 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  Include file to support building the third-party libfdt library.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#include <LibFdtSupport.h>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdlib.h
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..f6cf8d5702
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
>>>>>>>>>> @@ -0,0 +1,10 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  Include file to support building the third-party libfdt library.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#include <LibFdtSupport.h>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/string.h
>>>>>>>>>> b/MdePkg/Library/BaseFdtLib/string.h
>>>>>>>>>> new file mode 100644
>>>>>>>>>> index 0000000000..f6cf8d5702
>>>>>>>>>> --- /dev/null
>>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/string.h
>>>>>>>>>> @@ -0,0 +1,10 @@
>>>>>>>>>> +/** @file
>>>>>>>>>>
>>>>>>>>>> +  Include file to support building the third-party libfdt library.
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +**/
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> +#include <LibFdtSupport.h>
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
>>> index
>>>>>>>>>> 6ba85ebe61..f039daccdb 100644
>>>>>>>>>> --- a/MdePkg/MdePkg.ci.yaml
>>>>>>>>>> +++ b/MdePkg/MdePkg.ci.yaml
>>>>>>>>>> @@ -2,7 +2,7 @@
>>>>>>>>>>   # CI configuration for MdePkg
>>>>>>>>>>
>>>>>>>>>>   #
>>>>>>>>>>
>>>>>>>>>>   # Copyright (c) Microsoft Corporation
>>>>>>>>>>
>>>>>>>>>> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>>   # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>>   # Copyright (c) 2023, Loongson Technology Corporation Limited.
>> All
>>>>>>>>>> rights reserved.<BR>
>>>>>>>>>>
>>>>>>>>>>   # SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>>>>>>>
>>>>>>>>>> @@ -67,7 +67,8 @@
>>>>>>>>>>               "Include/Library/PcdLib.h",
>>>>>>>>>>
>>>>>>>>>>               "Include/Library/SafeIntLib.h",
>>>>>>>>>>
>>>>>>>>>>               "Include/Protocol/DebugSupport.h",
>>>>>>>>>>
>>>>>>>>>> -
>> "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
>>>>>>>>>>
>>>>>>>>>> +            "Library/BaseFdtLib"
>>>>>>>>>>
>>>>>>>>>>           ]
>>>>>>>>>>
>>>>>>>>>>       },
>>>>>>>>>>
>>>>>>>>>>       ## options defined ci/Plugin/CompilerPlugin
>>>>>>>>>>
>>>>>>>>>> @@ -164,5 +165,17 @@
>>>>>>>>>>           "ExtendWords": [],           # words to extend to the dictionary
>> for
>>> this package
>>>>>>>>>>
>>>>>>>>>>           "IgnoreStandardPaths": [],   # Standard Plugin defined paths
>> that
>>> should be ignore
>>>>>>>>>>
>>>>>>>>>>           "AdditionalIncludePaths": [] # Additional paths to spell
>>>>>>>>>> check (wildcards supported)
>>>>>>>>>>
>>>>>>>>>> +    },
>>>>>>>>>>
>>>>>>>>>> +    # options defined in .pytool/Plugin/UncrustifyCheck
>>>>>>>>>>
>>>>>>>>>> +    "UncrustifyCheck": {
>>>>>>>>>>
>>>>>>>>>> +        "IgnoreFiles": [
>>>>>>>>>>
>>>>>>>>>> +            "Library/BaseFdtLib/libfdt",
>>>>>>>>>>
>>>>>>>>>> +            "Library/BaseFdtLib/limits.h",
>>>>>>>>>>
>>>>>>>>>> +            "Library/BaseFdtLib/stdbool.h",
>>>>>>>>>>
>>>>>>>>>> +            "Library/BaseFdtLib/stddef.h",
>>>>>>>>>>
>>>>>>>>>> +            "Library/BaseFdtLib/stdint.h",
>>>>>>>>>>
>>>>>>>>>> +            "Library/BaseFdtLib/stdlib.h",
>>>>>>>>>>
>>>>>>>>>> +            "Library/BaseFdtLib/string.h"
>>>>>>>>>>
>>>>>>>>>> +        ]
>>>>>>>>>>
>>>>>>>>>>       }
>>>>>>>>>>
>>>>>>>>>>   }
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
>>>>>>>>>> e70182bf7f..9804a7a6bd 100644
>>>>>>>>>> --- a/MdePkg/MdePkg.dec
>>>>>>>>>> +++ b/MdePkg/MdePkg.dec
>>>>>>>>>> @@ -289,6 +289,10 @@
>>>>>>>>>>     #
>>>>>>>>>>
>>>>>>>>>>     ArmTrngLib|Include/Library/ArmTrngLib.h
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
>>>>>>>>>>
>>>>>>>>>> +  #
>>>>>>>>>>
>>>>>>>>>> +  FdtLib|Include/Library/FdtLib.h
>>>>>>>>>>
>>>>>>>>>> +
>>>>>>>>>>
>>>>>>>>>>   [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
>>>>>>>>>>
>>>>>>>>>>     ##  @libraryclass  Provides services to generate random number.
>>>>>>>>>>
>>>>>>>>>>     #
>>>>>>>>>>
>>>>>>>>>> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
>>>>>>>>>> 152c02991a..b38c863812 100644
>>>>>>>>>> --- a/MdePkg/MdePkg.dsc
>>>>>>>>>> +++ b/MdePkg/MdePkg.dsc
>>>>>>>>>> @@ -137,6 +137,7 @@
>>>>>>>>>>
>>>>>>>>>>
>>> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>     MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
>>>>>>>>>>
>>>>>>>>>> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>   [Components.IA32, Components.X64, Components.ARM,
>>>>>>>>>> Components.AARCH64]
>>>>>>>>>>
>>>>>>>>>>     #
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> 2.39.1.windows.1
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>
> 
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-05-02 11:41                     ` Leif Lindholm
@ 2023-05-03  2:34                       ` Chiu, Chasel
  2023-05-03  5:39                         ` Michael D Kinney
  0 siblings, 1 reply; 20+ messages in thread
From: Chiu, Chasel @ 2023-05-03  2:34 UTC (permalink / raw)
  To: devel@edk2.groups.io, quic_llindhol@quicinc.com,
	Kinney, Michael D
  Cc: Lin, Benny, Gao, Liming, Liu, Zhiguang, Pedro Falcato


Thanks Leif!
To align with your suggestion I think we can define below MACROs in FdtLib.h.
Library consumers can use those MACROs to convert structure data between Big endian and Little endian. (better readability)

Mike, what do you think?

Thanks,
Chasel



//
// Definitions for transferring FDT structure data between big-endian (FDT) and little-endian (CPU)
//
#define CPU_TO_FDT16(x)  SwapBytes16 (x)
#define FDT16_TO_CPU(x)  SwapBytes16 (x)

#define CPU_TO_FDT32(x)  SwapBytes32 (x)
#define FDT32_TO_CPU(x)  SwapBytes32 (x)

#define CPU_TO_FDT64(x)  SwapBytes64 (x)
#define FDT64_TO_CPU(x)  SwapBytes64 (x)




> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Leif
> Lindholm
> Sent: Tuesday, May 2, 2023 4:42 AM
> To: devel@edk2.groups.io; Chiu, Chasel <chasel.chiu@intel.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>
> Cc: Lin, Benny <benny.lin@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro
> Falcato <pedro.falcato@gmail.com>
> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> Hi Chasel,
> 
> Apologies, spent last week at Linaro Connect with little time to follow
> the list.
> 
> If we're seeing this purely as a wrapper on libfdt, then it shouldn't
> need to provide additional functionality on top of what it provides.
> My initial impression was that this library was attempting to do more,
> but then I mostly skimmed it, and that appears to have been incorrect.
> 
> What I *really* don't want is mixing abstractions. I.e. if we're getting
> the pointers through libfdt calls, we should be using the libfdt
> accessor functions to extract the data correctly. And expose the
> cpu_to_fdt*/fdt*_to_cpu accessors through the library. Presumably as
> Fdt*ToCpu/CpuToFdt*.
> 
> Regards,
> 
> Leif
> 
> 
> On 2023-05-01 17:31, Chiu, Chasel wrote:
> >
> > Hi Leif,
> >
> > Would you please share your ideas and respond Mike's question too?
> >
> > Thanks,
> > Chasel
> >
> >
> >
> >> -----Original Message-----
> >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chiu,
> Chasel
> >> Sent: Tuesday, April 25, 2023 10:22 PM
> >> To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>;
> >> Leif Lindholm <quic_llindhol@quicinc.com>
> >> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> >> <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
> Liu,
> >> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> <pedro.falcato@gmail.com>
> >> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> >>
> >>
> >> Hello,
> >>
> >> Since platform may also define other FDT structures, this EDK2 library may
> not
> >> be able to convert all the FDT structures to little endian.
> >> We might define a generic MACRO in library like
> >> CONVERT_FDT_DATA_TO_LITTLE_ENDIAN which can be used for all
> structure
> >> data, but it will be almost like calling SwapBytes** directly.
> >> Any other suggestion?
> >>
> >> Thanks,
> >> Chasel
> >>
> >>
> >>> -----Original Message-----
> >>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Michael
> D
> >>> Kinney
> >>> Sent: Monday, April 24, 2023 10:41 AM
> >>> To: Leif Lindholm <quic_llindhol@quicinc.com>; devel@edk2.groups.io
> >>> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> >>> <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
> >> Liu,
> >>> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> >> <pedro.falcato@gmail.com>;
> >>> Kinney, Michael D <michael.d.kinney@intel.com>
> >>> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> >>>
> >>> Hi Leif,
> >>>
> >>> Do you have a proposal or small example on what you want to see
> >>> in the library?
> >>>
> >>> Mike
> >>>
> >>>> -----Original Message-----
> >>>> From: Leif Lindholm <quic_llindhol@quicinc.com>
> >>>> Sent: Monday, April 24, 2023 10:29 AM
> >>>> To: devel@edk2.groups.io; Kinney, Michael D
> <michael.d.kinney@intel.com>
> >>>> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> >>> <llindhol@qti.qualcomm.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
> >> Liu,
> >>>> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> >>> <pedro.falcato@gmail.com>
> >>>> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> >>>>
> >>>> Apologies, I was refactoring a git tree and switched off the world :)
> >>>>
> >>>> Well, being a bit late to the party ... my view is it would be
> >>>> preferable if we put the byteswapping in the library.
> >>>>
> >>>> The DT format is *defined* to be big-endian, 32-bit cells. So frankly,
> >>>> I have no problems with pushing responsibility onto individual
> >>>> platforms if they have decided to be "clever" by ignoring that -
> >>>> if that gets rid of a bunch of boilerplate for sensibly behaving platforms.
> >>>>
> >>>> Maybe another excuse for getting
> >>>> https://github.com/tianocore/edk2-
> >>> platforms/blob/master/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
> >>>> into MdePkg?
> >>>>
> >>>> /
> >>>>      Leif
> >>>>
> >>>> On Thu, Apr 20, 2023 at 16:44:03 +0000, Michael D Kinney wrote:
> >>>>> Hi Leif,
> >>>>>
> >>>>> What is your opinion on FDT being big endian.
> >>>>>
> >>>>> Do we want the lib to help with that aspect, or leave it up to the
> consumer
> >> of
> >>> the lib to
> >>>>> convert as needed?  Seems like an area that could be very error prone if
> we
> >>> are not
> >>>>> careful.
> >>>>>
> >>>>> Mike
> >>>>>
> >>>>>> -----Original Message-----
> >>>>>> From: Lin, Benny <benny.lin@intel.com>
> >>>>>> Sent: Wednesday, April 19, 2023 9:25 PM
> >>>>>> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> >>> devel@edk2.groups.io
> >>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> >>> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> >>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>> -----Original Message-----
> >>>>>>> From: Kinney, Michael D <michael.d.kinney@intel.com>
> >>>>>>> Sent: Thursday, April 20, 2023 5:04 AM
> >>>>>>> To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> >>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> >>> <zhiguang.liu@intel.com>; Pedro Falcato
> >>>> <pedro.falcato@gmail.com>; Kinney,
> >>>>>> Michael D <michael.d.kinney@intel.com>
> >>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> >>>>>>>
> >>>>>>> Responses below
> >>>>>>>
> >>>>>>> Mike
> >>>>>>>
> >>>>>>>> -----Original Message-----
> >>>>>>>> From: Lin, Benny <benny.lin@intel.com>
> >>>>>>>> Sent: Wednesday, April 19, 2023 10:12 AM
> >>>>>>>> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> >>>>>>>> devel@edk2.groups.io
> >>>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> >>>>>>>> <zhiguang.liu@intel.com>; Pedro Falcato
> >> <pedro.falcato@gmail.com>
> >>>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> >>>>>>>>
> >>>>>>>> Please find my feedback below.
> >>>>>>>> We can remove FDT_RESERVE_ENTRY but keep FDT_NODE_HEADER,
> >>> what do you think?
> >>>>>>>>
> >>>>>>>> QQQ
> >>>>>>>> Benny
> >>>>>>>>
> >>>>>>>>> -----Original Message-----
> >>>>>>>>> From: Kinney, Michael D <michael.d.kinney@intel.com>
> >>>>>>>>> Sent: Wednesday, April 19, 2023 11:54 PM
> >>>>>>>>> To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> >>>>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> >>>>>>>>> <zhiguang.liu@intel.com>; Pedro Falcato
> >> <pedro.falcato@gmail.com>;
> >>>>>>>>> Kinney,
> >>>>>>>> Michael D <michael.d.kinney@intel.com>
> >>>>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> >>>>>>>>>
> >>>>>>>>> A few comments below.
> >>>>>>>>>
> >>>>>>>>> Mike
> >>>>>>>>>
> >>>>>>>>>> -----Original Message-----
> >>>>>>>>>> From: Lin, Benny <benny.lin@intel.com>
> >>>>>>>>>> Sent: Sunday, April 16, 2023 10:35 PM
> >>>>>>>>>> To: devel@edk2.groups.io
> >>>>>>>>>> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> >>>>>>>>>> <michael.d.kinney@intel.com>; Gao, Liming
> >>>>>>>>>> <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> >>> <zhiguang.liu@intel.com>;
> >>>>>>>>>> Pedro Falcato <pedro.falcato@gmail.com>
> >>>>>>>>>> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> >>>>>>>>>>
> >>>>>>>>>> From: Benny Lin <benny.lin@intel.com>
> >>>>>>>>>>
> >>>>>>>>>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> >>>>>>>>>> Add FDT support in EDK2 by submodule 3rd party libfdt
> >>>>>>>>>> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> >>>>>>>>>> and refer to LibcLib implementation by Pedro.
> >>>>>>>>>>
> >>>>>>>>>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> >>>>>>>>>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> >>>>>>>>>> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> >>>>>>>>>> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> >>>>>>>>>> Signed-off-by: Benny Lin <benny.lin@intel.com>
> >>>>>>>>>> ---
> >>>>>>>>>>   MdePkg/Include/Library/FdtLib.h           | 314
> >>> ++++++++++++++++++++
> >>>>>>>>>>   MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> >>>>>>>>>> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> >>>>>>>>>>   MdePkg/Library/BaseFdtLib/FdtLib.c        | 301
> >>> +++++++++++++++++++
> >>>>>>>>>>   MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> >>>>>>>>>> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173 +++++++++++
> >>>>>>>>>>   MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> >>>>>>>>>>   MdePkg/Library/BaseFdtLib/string.h        |  10 +
> >>>>>>>>>>   MdePkg/MdePkg.ci.yaml                     |  17 +-
> >>>>>>>>>>   MdePkg/MdePkg.dec                         |   4 +
> >>>>>>>>>>   MdePkg/MdePkg.dsc                         |   1 +
> >>>>>>>>>>   15 files changed, 1043 insertions(+), 2 deletions(-)
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Include/Library/FdtLib.h
> >>>>>>>>>> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
> >>>>>>>>>> 0000000000..d59b749c25
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Include/Library/FdtLib.h
> >>>>>>>>>> @@ -0,0 +1,314 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  Flattened Device Tree Library.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#ifndef FDT_LIB_H_
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_LIB_H_
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +///
> >>>>>>>>>>
> >>>>>>>>>> +/// Flattened Device Tree definition
> >>>>>>>>>>
> >>>>>>>>>> +///
> >>>>>>>>>>
> >>>>>>>>>> +typedef struct {
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    TotalSize;           /* total size of DT block */
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    OffsetDtStruct;      /* offset to structure */
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    OffsetDtStrings;     /* offset to strings */
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    OffsetMemRsvmap;     /* offset to memory reserve
> >> map
> >>> */
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    Version;             /* format version */
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    LastCompVersion;     /* last compatible version */
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  /* version 2 fields below */
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    BootCpuidPhys;       /* Which physical CPU id we're
> >>>>>>>>>>
> >>>>>>>>>> +                                    booting on */
> >>>>>>>>>>
> >>>>>>>>>> +  /* version 3 fields below */
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    SizeDtStrings;       /* size of the strings block */
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  /* version 17 fields below */
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    SizeDtStruct;        /* size of the structure block */
> >>>>>>>>>>
> >>>>>>>>>> +} FDT_HEADER;
> >>>>>>>>>
> >>>>>>>>> I see the macros below use SwapBytes32() on all the fields from this
> >>>>>>>>> structure.  Does this mean this structure is big >endian?  If
> >>>>>>>> that is the case, then the description of this structure and all
> >>>>>>>> individual fields must make that very clear >so any consumer of the
> >>>>>>>> structure knows it does not follow the default endianness of UEFI/PI
> >>> and that consumers >must either use the macros or
> >>>> consumers
> >>>>>> must use SwapBytes32() on their own when using this structure directly.
> >>>>>>>>
> >>>>>>>> Yes, it's big endian. I will complete more descriptions in patch v4.
> >>>>>>>
> >>>>>>> Would it be simpler if we have a lib service that converts the entire
> >> header
> >>> from big endian to little endian.
> >>>>>>> That way, the consumer can use the FDT_HEADER directly without any
> >> of
> >>> the macros?
> >>>>>>>
> >>>>>>> Also, is the rest of the FDT blob also big endian?
> >>>>>>
> >>>>>> FDT blob format is binary encoding of FDT data with big endian. In
> >> addition,
> >>> the consumer will set or get FDT data with FDT
> >>>> blob. We
> >>>>>> can complete more descriptions to warn consumers to be careful if just
> >> use
> >>> header struct for mapping and get/set FDT data
> >>>> with FDT
> >>>>>> blob.
> >>>>>>
> >>>>>> For provide lib services that converts between big endian and little
> endian,
> >>> we can provide a get header function to convert
> >>>> between
> >>>>>> big endian and little endian. However, we also need to consider the
> >>> property value for setting and getting then we can
> >>>> convert in
> >>>>>> wrapper functions.
> >>>>>>
> >>>>>> For example,
> >>>>>>
> >>>>>> INT32
> >>>>>> EFIAPI
> >>>>>> FdtSetProp (
> >>>>>>    IN VOID         *Fdt,
> >>>>>>    IN INT32        NodeOffset,
> >>>>>>    IN CONST CHAR8  *Name,
> >>>>>>    IN CONST VOID   *Value,
> >>>>>>    IN UINT32       Length
> >>>>>>    )
> >>>>>> {
> >>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> >>>>>> }
> >>>>>>
> >>>>>> More functions for various byte width.
> >>>>>> INT32
> >>>>>> EFIAPI
> >>>>>> FdtSetProp16 (
> >>>>>>    IN VOID         *Fdt,
> >>>>>>    IN INT32        NodeOffset,
> >>>>>>    IN CONST CHAR8  *Name,
> >>>>>>    IN CONST UINT16   *Value,
> >>>>>>    IN UINT32       Length
> >>>>>>    )
> >>>>>> {
> >>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value),
> >>> (int)Length);
> >>>>>> }
> >>>>>>
> >>>>>> INT32
> >>>>>> EFIAPI
> >>>>>> FdtSetProp32 (
> >>>>>>    IN VOID         *Fdt,
> >>>>>>    IN INT32        NodeOffset,
> >>>>>>    IN CONST CHAR8  *Name,
> >>>>>>    IN CONST UINT32   *Value,
> >>>>>>    IN UINT32       Length
> >>>>>>    )
> >>>>>> {
> >>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value),
> >>> (int)Length);
> >>>>>> }
> >>>>>>
> >>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +typedef struct {
> >>>>>>>>>>
> >>>>>>>>>> +  UINT64    Address;
> >>>>>>>>>>
> >>>>>>>>>> +  UINT64    Size;
> >>>>>>>>>>
> >>>>>>>>>> +} FDT_RESERVE_ENTRY;
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> I do not see this type used anywhere in the lib class or the lib
> instance.
> >>>>>>>>> Can it be removed?
> >>>>>>>>
> >>>>>>>> I think we can remove it because it might be not used for further
> >> usage
> >>> of FDT support.
> >>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +typedef struct {
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    Tag;
> >>>>>>>>>>
> >>>>>>>>>> +  CHAR8     Name[];
> >>>>>>>>>>
> >>>>>>>>>> +} FDT_NODE_HEADER;
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> I do not see this type used anywhere in the lib class or the lib
> instance.
> >>>>>>>>> Can it be removed?
> >>>>>>>>
> >>>>>>>> When we need retrieve a node from a FDT blob, we will get a node
> >>>>>>>> offset then we could use the struct to map the node content. It's very
> >>> useful.
> >>>>>>>
> >>>>>>> Please add a comment header for this structure and describe the usage
> >> as
> >>> it related to the rest of the FdtLib >services.
> >>>>>>
> >>>>>> I will add descriptions for the usage and remove FDT_RESERVE_ENTRY in
> >>> patch v4.
> >>>>>>
> >>>>>>>
> >>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +typedef struct {
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    Tag;
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    Length;
> >>>>>>>>>>
> >>>>>>>>>> +  UINT32    NameOffset;
> >>>>>>>>>>
> >>>>>>>>>> +  CHAR8     Data[];
> >>>>>>>>>>
> >>>>>>>>>> +} FDT_PROPERTY;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST
> >>> FDT_HEADER
> >>>>>>>>>> +*)(Fdt))->Field)
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt, Magic))
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt,
> >>> TotalSize))
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_OFFSET_DT_STRUCT(Fdt)   (FDT_GET_HEADER(Fdt,
> >>> OffsetDtStruct))
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_OFFSET_DT_STRINGS(Fdt)  (FDT_GET_HEADER(Fdt,
> >>>>>>>>>> +OffsetDtStrings))
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)  (FDT_GET_HEADER(Fdt,
> >>>>>>>>>> +OffsetMemRsvmap))
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt, Version))
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_LAST_COMP_VERSION(Fdt)  (FDT_GET_HEADER(Fdt,
> >>>>>>>>>> +LastCompVersion))
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_BOOT_CPUID_PHYS(Fdt)    (FDT_GET_HEADER(Fdt,
> >>> BootCpuidPhys))
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_SIZE_DT_STRINGS(Fdt)    (FDT_GET_HEADER(Fdt,
> >>> SizeDtStrings))
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_SIZE_DT_STRUCT(Fdt)     (FDT_GET_HEADER(Fdt,
> >>> SizeDtStruct))
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Verify the header of the Flattened Device Tree
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtCheckHeader (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Create a empty Flattened Device Tree.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Buffer         The pointer to allocate a pool for FDT
> >> blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] BufferSize     The BufferSize to the pool size.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +RETURN_STATUS
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtCreateEmptyTree (
> >>>>>>>>>>
> >>>>>>>>>> +  IN VOID   *Buffer,
> >>>>>>>>>>
> >>>>>>>>>> +  IN UINTN  BufferSize
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of next node from the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Depth          The depth to the level of tree hierarchy.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to next node offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtNextNode (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       *Depth
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of first node under the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to next node offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtFirstSubnode (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of next node from the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to next node offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtNextSubnode (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of first node which includes the given name.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] ParentOffset    The offset to the node which start
> >> find
> >>> under.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Name            The name to search the node with the
> >>> name.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] NameLength      The length of the name to check
> >> only.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to node offset with given node name.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtSubnodeOffsetNameLen (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        ParentOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *Name,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        NameLength
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of first node which includes the given property
> >>> name and value.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] StartOffset     The offset to the starting node to find.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] PropertyName    The property name to search the
> >>> node including the named property.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] PropertyValue   The property value to check the
> >> same
> >>> property value.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] PropertyLength  The length of the value in
> >>> PropertValue.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to node offset with given property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtNodeOffsetByPropValue (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        StartOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *PropertyName,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *PropertyValue,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        PropertyLength
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a property with the given name from the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] NodeOffset     The offset to the given node.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Name           The name to the property which need
> >> be
> >>> searched
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Length         The length to the size of the property
> >>> found.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The property to the structure of the found property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +CONST FDT_PROPERTY *
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtGetProperty (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        NodeOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *Name,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        *Length
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of first property in the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to the node which need be
> >>> searched.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to first property offset in the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtFirstPropertyOffset (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       NodeOffset
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of next property from the given property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to previous property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to next property offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtNextPropertyOffset (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a property from the given offset of the property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to the given offset of the
> >>> property.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Length         The length to the size of the property
> >>> found.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The property to the structure of the given property
> >> offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +CONST FDT_PROPERTY *
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtGetPropertyByOffset (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       *Length
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a string by the given string offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] StrOffset      The offset to the location in the strings
> >>> block of FDT.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Length         The length to the size of string which
> >> need
> >>> be retrieved.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The string to the given string offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +CONST CHAR8 *
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtGetString (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       StrOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       *Length        OPTIONAL
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Add a new node to the FDT.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] ParentOffset   The offset to the node offset which
> >>> want to add in.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Name           The name to name the node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return  The offset to the new node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtAddSubnode (
> >>>>>>>>>>
> >>>>>>>>>> +  IN VOID         *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        ParentOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *Name
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Add or modify a property in the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] NodeOffset     The offset to the node offset which
> >>> want to add in.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Name           The name to name the property.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Value          The value to the property value.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Length         The length to the size of the property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return  Zero for successfully, otherwise failed.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtSetProp (
> >>>>>>>>>>
> >>>>>>>>>> +  IN VOID         *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        NodeOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *Name,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *Value,
> >>>>>>>>>>
> >>>>>>>>>> +  IN UINT32       Length
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#endif /* FDT_LIB_H_ */
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..730e568ff6
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >>>>>>>>>> @@ -0,0 +1,62 @@
> >>>>>>>>>> +## @file
> >>>>>>>>>>
> >>>>>>>>>> +# Flattened Device Tree Library.
> >>>>>>>>>>
> >>>>>>>>>> +#
> >>>>>>>>>>
> >>>>>>>>>> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +#
> >>>>>>>>>>
> >>>>>>>>>> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +#
> >>>>>>>>>>
> >>>>>>>>>> +#
> >>>>>>>>>>
> >>>>>>>>>> +##
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +[Defines]
> >>>>>>>>>>
> >>>>>>>>>> +  INF_VERSION                    = 0x0001001B
> >>>>>>>>>>
> >>>>>>>>>> +  BASE_NAME                      = BaseFdtLib
> >>>>>>>>>>
> >>>>>>>>>> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> >>>>>>>>>>
> >>>>>>>>>> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-
> >>> E8CEC206DE04
> >>>>>>>>>>
> >>>>>>>>>> +  MODULE_TYPE                    = BASE
> >>>>>>>>>>
> >>>>>>>>>> +  VERSION_STRING                 = 1.0
> >>>>>>>>>>
> >>>>>>>>>> +  LIBRARY_CLASS                  = FdtLib
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#
> >>>>>>>>>>
> >>>>>>>>>> +#  VALID_ARCHITECTURES           = IA32 X64
> >>>>>>>>>>
> >>>>>>>>>> +#
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +[Sources]
> >>>>>>>>>>
> >>>>>>>>>> +  FdtLib.c
> >>>>>>>>>>
> >>>>>>>>>> +  LibFdtWrapper.c
> >>>>>>>>>>
> >>>>>>>>>> +  # header Wrapper files
> >>>>>>>>>>
> >>>>>>>>>> +  limits.h
> >>>>>>>>>>
> >>>>>>>>>> +  stdbool.h
> >>>>>>>>>>
> >>>>>>>>>> +  stddef.h
> >>>>>>>>>>
> >>>>>>>>>> +  stdint.h
> >>>>>>>>>>
> >>>>>>>>>> +  stdlib.h
> >>>>>>>>>>
> >>>>>>>>>> +  string.h
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt.h
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_addresses.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_check.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_overlay.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_ro.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_rw.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_strerror.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_sw.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_wip.c
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt.h
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt_env.h
> >>>>>>>>>>
> >>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt_internal.h
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +[Packages]
> >>>>>>>>>>
> >>>>>>>>>> +  MdePkg/MdePkg.dec
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +[LibraryClasses]
> >>>>>>>>>>
> >>>>>>>>>> +  BaseLib
> >>>>>>>>>>
> >>>>>>>>>> +  BaseMemoryLib
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +[BuildOptions]
> >>>>>>>>>>
> >>>>>>>>>> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> >>>>>>>>>>
> >>>>>>>>>> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245
> >> /wd4267
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..3f7e45ea6f
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> >>>>>>>>>> @@ -0,0 +1,14 @@
> >>>>>>>>>> +// /** @file
> >>>>>>>>>>
> >>>>>>>>>> +// Flattened Device Tree Library.
> >>>>>>>>>>
> >>>>>>>>>> +//
> >>>>>>>>>>
> >>>>>>>>>> +// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +//
> >>>>>>>>>>
> >>>>>>>>>> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +//
> >>>>>>>>>>
> >>>>>>>>>> +// **/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#string STR_MODULE_ABSTRACT             #language en-US
> >> "Instance
> >>> of FDT Library"
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#string STR_MODULE_DESCRIPTION          #language en-US "This
> >>> module provides FDT Library implementation."
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..200a496c7e
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> >>>>>>>>>> @@ -0,0 +1,301 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  Flattened Device Tree Library.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#include <libfdt/libfdt/libfdt.h>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Verify the header of the Flattened Device Tree
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtCheckHeader (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_check_header(Fdt);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Create a empty Flattened Device Tree.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Buffer         The pointer to allocate a pool for FDT
> >> blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] BufferSize     The BufferSize to the pool size.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtCreateEmptyTree (
> >>>>>>>>>>
> >>>>>>>>>> +  IN VOID    *Buffer,
> >>>>>>>>>>
> >>>>>>>>>> +  IN UINT32  BufferSize
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of next node from the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Depth          The depth to the level of tree hierarchy.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to next node offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtNextNode (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       *Depth
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_next_node (Fdt, Offset, Depth);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of first node under the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to next node offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtFirstSubnode (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_first_subnode (Fdt, Offset);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of next node from the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to next node offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtNextSubnode (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_next_subnode (Fdt, Offset);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of first node which includes the given name.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] ParentOffset    The offset to the node which start
> >> find
> >>> under.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Name            The name to search the node with the
> >>> name.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] NameLength      The length of the name to check
> >> only.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to node offset with given node name.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtSubnodeOffsetNameLen (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        ParentOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *Name,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        NameLength
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset, Name,
> >>>>>>>>>> + NameLength);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of first node which includes the given property
> >>> name and value.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] StartOffset     The offset to the starting node to find.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] PropertyName    The property name to search the
> >>> node including the named property.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] PropertyValue   The property value to check the
> >> same
> >>> property value.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] PropertyLength  The length of the value in
> >>> PropertValue.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to node offset with given property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtNodeOffsetByPropValue (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        StartOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *PropertyName,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *PropertyValue,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        PropertyLength
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> >>>>>>>>>> + PropertyName, PropertyValue, PropertyLength);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a property with the given name from the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] NodeOffset     The offset to the given node.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Name           The name to the property which need
> >> be
> >>> searched
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Length         The length to the size of the property
> >>> found.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The property to the structure of the found property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +CONST struct fdt_property *
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtGetProperty (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        NodeOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *Name,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        *Length
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of first property in the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] NodeOffset     The offset to the node which need be
> >>> searched.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to first property offset in the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtFirstPropertyOffset (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       NodeOffset
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_first_property_offset (Fdt, NodeOffset);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a offset of next property from the given property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to previous property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The offset to next property offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtNextPropertyOffset (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_next_property_offset (Fdt, Offset);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a property from the given offset of the property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Offset         The offset to the given offset of the
> >>> property.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Length         The length to the size of the property
> >>> found.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The property to the structure of the given property
> >> offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +CONST struct fdt_property *
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtGetPropertyByOffset (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       Offset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       *Length
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Returns a string by the given string offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] StrOffset      The offset to the location in the strings
> >>> block of FDT.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Length         The length to the size of string which
> >> need
> >>> be retrieved.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return The string to the given string offset.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +CONST CHAR8 *
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtGetString (
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID  *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       StrOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32       *Length        OPTIONAL
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_get_string (Fdt, StrOffset, Length);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Add a new node to the FDT.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] ParentOffset   The offset to the node offset which
> >>> want to add in.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Name           The name to name the node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return  The offset to the new node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtAddSubnode (
> >>>>>>>>>>
> >>>>>>>>>> +  IN VOID         *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        ParentOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *Name
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +/**
> >>>>>>>>>>
> >>>>>>>>>> +  Add or modify a property in the given node.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] NodeOffset     The offset to the node offset which
> >>> want to add in.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Name           The name to name the property.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Value          The value to the property value.
> >>>>>>>>>>
> >>>>>>>>>> +  @param[in] Length         The length to the size of the property.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  @return  Zero for successfully, otherwise failed.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +INT32
> >>>>>>>>>>
> >>>>>>>>>> +EFIAPI
> >>>>>>>>>>
> >>>>>>>>>> +FdtSetProp (
> >>>>>>>>>>
> >>>>>>>>>> +  IN VOID         *Fdt,
> >>>>>>>>>>
> >>>>>>>>>> +  IN INT32        NodeOffset,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST CHAR8  *Name,
> >>>>>>>>>>
> >>>>>>>>>> +  IN CONST VOID   *Value,
> >>>>>>>>>>
> >>>>>>>>>> +  IN UINT32       Length
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..e738f4ded4
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> >>>>>>>>>> @@ -0,0 +1,99 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  Root include file of C runtime library to support building the
> >>>>>>>>>> + third-party
> >>>>>>>>>>
> >>>>>>>>>> +  libfdt library.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#ifndef FDT_LIB_SUPPORT_H_
> >>>>>>>>>>
> >>>>>>>>>> +#define FDT_LIB_SUPPORT_H_
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#include <Base.h>
> >>>>>>>>>>
> >>>>>>>>>> +#include <Library/BaseLib.h>
> >>>>>>>>>>
> >>>>>>>>>> +#include <Library/BaseMemoryLib.h>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +typedef UINT8    uint8_t;
> >>>>>>>>>>
> >>>>>>>>>> +typedef UINT16   uint16_t;
> >>>>>>>>>>
> >>>>>>>>>> +typedef INT32    int32_t;
> >>>>>>>>>>
> >>>>>>>>>> +typedef UINT32   uint32_t;
> >>>>>>>>>>
> >>>>>>>>>> +typedef UINT64   uint64_t;
> >>>>>>>>>>
> >>>>>>>>>> +typedef UINTN    uintptr_t;
> >>>>>>>>>>
> >>>>>>>>>> +typedef UINTN    size_t;
> >>>>>>>>>>
> >>>>>>>>>> +typedef BOOLEAN  bool;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#define true   (1 == 1)
> >>>>>>>>>>
> >>>>>>>>>> +#define false  (1 == 0)
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +//
> >>>>>>>>>>
> >>>>>>>>>> +// Definitions for global constants used by libfdt library
> >>>>>>>>>> +routines
> >>>>>>>>>>
> >>>>>>>>>> +//
> >>>>>>>>>>
> >>>>>>>>>> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed) int
> >> value
> >>> */
> >>>>>>>>>>
> >>>>>>>>>> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed) int32
> >>> value */
> >>>>>>>>>>
> >>>>>>>>>> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum unsigned
> >> int32
> >>> value */
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +//
> >>>>>>>>>>
> >>>>>>>>>> +// Function prototypes of libfdt Library routines
> >>>>>>>>>>
> >>>>>>>>>> +//
> >>>>>>>>>>
> >>>>>>>>>> +void *
> >>>>>>>>>>
> >>>>>>>>>> +memset     (
> >>>>>>>>>>
> >>>>>>>>>> +  void *,
> >>>>>>>>>>
> >>>>>>>>>> +  int,
> >>>>>>>>>>
> >>>>>>>>>> +  size_t
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +int
> >>>>>>>>>>
> >>>>>>>>>> +memcmp      (
> >>>>>>>>>>
> >>>>>>>>>> +  const void *,
> >>>>>>>>>>
> >>>>>>>>>> +  const void *,
> >>>>>>>>>>
> >>>>>>>>>> +  size_t
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +int
> >>>>>>>>>>
> >>>>>>>>>> +strcmp      (
> >>>>>>>>>>
> >>>>>>>>>> +  const char *,
> >>>>>>>>>>
> >>>>>>>>>> +  const char *
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +char *
> >>>>>>>>>>
> >>>>>>>>>> +strchr     (
> >>>>>>>>>>
> >>>>>>>>>> +  const char *,
> >>>>>>>>>>
> >>>>>>>>>> +  int
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +char *
> >>>>>>>>>>
> >>>>>>>>>> +strrchr    (
> >>>>>>>>>>
> >>>>>>>>>> +  const char *,
> >>>>>>>>>>
> >>>>>>>>>> +  int
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +unsigned long
> >>>>>>>>>>
> >>>>>>>>>> +strtoul     (
> >>>>>>>>>>
> >>>>>>>>>> +  const char *,
> >>>>>>>>>>
> >>>>>>>>>> +  char **,
> >>>>>>>>>>
> >>>>>>>>>> +  int
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +char *
> >>>>>>>>>>
> >>>>>>>>>> +strcpy (
> >>>>>>>>>>
> >>>>>>>>>> +  char        *strDest,
> >>>>>>>>>>
> >>>>>>>>>> +  const char  *strSource
> >>>>>>>>>>
> >>>>>>>>>> +  );
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +//
> >>>>>>>>>>
> >>>>>>>>>> +// Macros that directly map functions to BaseLib, BaseMemoryLib,
> >>>>>>>>>> +and DebugLib functions
> >>>>>>>>>>
> >>>>>>>>>> +//
> >>>>>>>>>>
> >>>>>>>>>> +#define memcpy(dest, source, count)         CopyMem(dest,source,
> >>> (UINTN)(count))
> >>>>>>>>>>
> >>>>>>>>>> +#define memset(dest, ch, count)             SetMem(dest,
> >>> (UINTN)(count),(UINT8)(ch))
> >>>>>>>>>>
> >>>>>>>>>> +#define memchr(buf, ch, count)              ScanMem8(buf,
> >>> (UINTN)(count),(UINT8)ch)
> >>>>>>>>>>
> >>>>>>>>>> +#define memcmp(buf1, buf2, count)
> >> (int)(CompareMem(buf1,
> >>> buf2, (UINTN)(count)))
> >>>>>>>>>>
> >>>>>>>>>> +#define memmove(dest, source, count)        CopyMem(dest,
> >> source,
> >>> (UINTN)(count))
> >>>>>>>>>>
> >>>>>>>>>> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> >>>>>>>>>>
> >>>>>>>>>> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str,
> >> count))
> >>>>>>>>>>
> >>>>>>>>>> +#define strncpy(strDest, strSource, count)  AsciiStrnCpyS(strDest,
> >>>>>>>>>> +MAX_STRING_SIZE, strSource, (UINTN)count)
> >>>>>>>>>>
> >>>>>>>>>> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest,
> >>> MAX_STRING_SIZE, strSource)
> >>>>>>>>>>
> >>>>>>>>>> +#define strcmp(string1, string2, count)     (int)(AsciiStrCmp(string1,
> >>> string2))
> >>>>>>>>>>
> >>>>>>>>>> +#define strncmp(string1, string2, count)
> >> (int)(AsciiStrnCmp(string1,
> >>> string2, (UINTN)(count)))
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#endif /* FDT_LIB_SUPPORT_H_ */
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..772bba4839
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> >>>>>>>>>> @@ -0,0 +1,173 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  ISO C implementations of strchr, strrchr and strtoul.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> >>>>>>>>>>
> >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#include <Base.h>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum unsigned
> >> long
> >>> value */
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +// Very quick notes:
> >>>>>>>>>>
> >>>>>>>>>> +// We only go through the string once for both functions
> >>>>>>>>>>
> >>>>>>>>>> +// They are minimal implementations (not speed optimized) of ISO
> >> C
> >>>>>>>>>> +semantics
> >>>>>>>>>>
> >>>>>>>>>> +// strchr and strrchr also include the null terminator as part of
> >>>>>>>>>> +the string
> >>>>>>>>>>
> >>>>>>>>>> +// so the code gets a bit clunky to handle that case specifically.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +char *
> >>>>>>>>>>
> >>>>>>>>>> +strchr (
> >>>>>>>>>>
> >>>>>>>>>> +  const char  *Str,
> >>>>>>>>>>
> >>>>>>>>>> +  int         Char
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  char  *S;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  S = (char *)Str;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  for ( ; ; S++) {
> >>>>>>>>>>
> >>>>>>>>>> +    if (*S == Char) {
> >>>>>>>>>>
> >>>>>>>>>> +      return S;
> >>>>>>>>>>
> >>>>>>>>>> +    }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +    if (*S == '\0') {
> >>>>>>>>>>
> >>>>>>>>>> +      return NULL;
> >>>>>>>>>>
> >>>>>>>>>> +    }
> >>>>>>>>>>
> >>>>>>>>>> +  }
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +char *
> >>>>>>>>>>
> >>>>>>>>>> +strrchr (
> >>>>>>>>>>
> >>>>>>>>>> +  const char  *Str,
> >>>>>>>>>>
> >>>>>>>>>> +  int         Char
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  char  *S, *last;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  S    = (char *)Str;
> >>>>>>>>>>
> >>>>>>>>>> +  last = NULL;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  for ( ; ; S++) {
> >>>>>>>>>>
> >>>>>>>>>> +    if (*S == Char) {
> >>>>>>>>>>
> >>>>>>>>>> +      last = S;
> >>>>>>>>>>
> >>>>>>>>>> +    }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +    if (*S == '\0') {
> >>>>>>>>>>
> >>>>>>>>>> +      return last;
> >>>>>>>>>>
> >>>>>>>>>> +    }
> >>>>>>>>>>
> >>>>>>>>>> +  }
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +STATIC
> >>>>>>>>>>
> >>>>>>>>>> +int
> >>>>>>>>>>
> >>>>>>>>>> +__isspace (
> >>>>>>>>>>
> >>>>>>>>>> +  int  ch
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  // basic ASCII ctype.h:isspace(). Not efficient
> >>>>>>>>>>
> >>>>>>>>>> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
> >>>>>>>>>> + == '\v' || ch == '\f';
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +unsigned long
> >>>>>>>>>>
> >>>>>>>>>> +strtoul (
> >>>>>>>>>>
> >>>>>>>>>> +  const char  *Nptr,
> >>>>>>>>>>
> >>>>>>>>>> +  char        **EndPtr,
> >>>>>>>>>>
> >>>>>>>>>> +  int         Base
> >>>>>>>>>>
> >>>>>>>>>> +  )
> >>>>>>>>>>
> >>>>>>>>>> +{
> >>>>>>>>>>
> >>>>>>>>>> +  BOOLEAN        Negate;
> >>>>>>>>>>
> >>>>>>>>>> +  BOOLEAN        Overflow;
> >>>>>>>>>>
> >>>>>>>>>> +  unsigned long  Val;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  Negate   = FALSE;
> >>>>>>>>>>
> >>>>>>>>>> +  Overflow = FALSE;
> >>>>>>>>>>
> >>>>>>>>>> +  Val      = 0;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  // Reject bad numeric bases
> >>>>>>>>>>
> >>>>>>>>>> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> >>>>>>>>>>
> >>>>>>>>>> +    return 0;
> >>>>>>>>>>
> >>>>>>>>>> +  }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  // Skip whitespace
> >>>>>>>>>>
> >>>>>>>>>> +  while (__isspace (*Nptr)) {
> >>>>>>>>>>
> >>>>>>>>>> +    Nptr++;
> >>>>>>>>>>
> >>>>>>>>>> +  }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  // Check for + or - prefixes
> >>>>>>>>>>
> >>>>>>>>>> +  if (*Nptr == '-') {
> >>>>>>>>>>
> >>>>>>>>>> +    Negate = TRUE;
> >>>>>>>>>>
> >>>>>>>>>> +    Nptr++;
> >>>>>>>>>>
> >>>>>>>>>> +  } else if (*Nptr == '+') {
> >>>>>>>>>>
> >>>>>>>>>> +    Nptr++;
> >>>>>>>>>>
> >>>>>>>>>> +  }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  // Consume the start, autodetecting base if needed
> >>>>>>>>>>
> >>>>>>>>>> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
> >>>>>>>>>> + && ((Base == 0) || (Base == 16))) {
> >>>>>>>>>>
> >>>>>>>>>> +    // Hex
> >>>>>>>>>>
> >>>>>>>>>> +    Nptr += 2;
> >>>>>>>>>>
> >>>>>>>>>> +    Base  = 16;
> >>>>>>>>>>
> >>>>>>>>>> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> >>>>>>>>>> + 'B')) && ((Base == 0) || (Base == 2))) {
> >>>>>>>>>>
> >>>>>>>>>> +    // Binary (standard pending C23)
> >>>>>>>>>>
> >>>>>>>>>> +    Nptr += 2;
> >>>>>>>>>>
> >>>>>>>>>> +    Base  = 2;
> >>>>>>>>>>
> >>>>>>>>>> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> >>>>>>>>>>
> >>>>>>>>>> +    // Octal
> >>>>>>>>>>
> >>>>>>>>>> +    Nptr++;
> >>>>>>>>>>
> >>>>>>>>>> +    Base = 8;
> >>>>>>>>>>
> >>>>>>>>>> +  } else {
> >>>>>>>>>>
> >>>>>>>>>> +    if (Base == 0) {
> >>>>>>>>>>
> >>>>>>>>>> +      // Assume decimal
> >>>>>>>>>>
> >>>>>>>>>> +      Base = 10;
> >>>>>>>>>>
> >>>>>>>>>> +    }
> >>>>>>>>>>
> >>>>>>>>>> +  }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  while (TRUE) {
> >>>>>>>>>>
> >>>>>>>>>> +    int            Digit;
> >>>>>>>>>>
> >>>>>>>>>> +    char           C;
> >>>>>>>>>>
> >>>>>>>>>> +    unsigned long  NewVal;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +    C     = *Nptr;
> >>>>>>>>>>
> >>>>>>>>>> +    Digit = -1;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +    if ((C >= '0') && (C <= '9')) {
> >>>>>>>>>>
> >>>>>>>>>> +      Digit = C - '0';
> >>>>>>>>>>
> >>>>>>>>>> +    } else if ((C >= 'a') && (C <= 'z')) {
> >>>>>>>>>>
> >>>>>>>>>> +      Digit = C - 'a' + 10;
> >>>>>>>>>>
> >>>>>>>>>> +    } else if ((C >= 'A') && (C <= 'Z')) {
> >>>>>>>>>>
> >>>>>>>>>> +      Digit = C - 'A' + 10;
> >>>>>>>>>>
> >>>>>>>>>> +    }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +    if ((Digit == -1) || (Digit >= Base)) {
> >>>>>>>>>>
> >>>>>>>>>> +      // Note that this case also handles the \0
> >>>>>>>>>>
> >>>>>>>>>> +      if (EndPtr) {
> >>>>>>>>>>
> >>>>>>>>>> +        *EndPtr = (char *)Nptr;
> >>>>>>>>>>
> >>>>>>>>>> +      }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +      break;
> >>>>>>>>>>
> >>>>>>>>>> +    }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +    NewVal = Val * Base + Digit;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +    if (NewVal < Val) {
> >>>>>>>>>>
> >>>>>>>>>> +      // Overflow
> >>>>>>>>>>
> >>>>>>>>>> +      Overflow = TRUE;
> >>>>>>>>>>
> >>>>>>>>>> +    }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +    Val = NewVal;
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +    Nptr++;
> >>>>>>>>>>
> >>>>>>>>>> +  }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  if (Negate) {
> >>>>>>>>>>
> >>>>>>>>>> +    Val = -Val;
> >>>>>>>>>>
> >>>>>>>>>> +  }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  if (Overflow) {
> >>>>>>>>>>
> >>>>>>>>>> +    Val = ULONG_MAX;
> >>>>>>>>>>
> >>>>>>>>>> +  }
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +  // TODO: We're lacking errno here.
> >>>>>>>>>>
> >>>>>>>>>> +  return Val;
> >>>>>>>>>>
> >>>>>>>>>> +}
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/limits.h
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..f6cf8d5702
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> >>>>>>>>>> @@ -0,0 +1,10 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#include <LibFdtSupport.h>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdbool.h
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..f6cf8d5702
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> >>>>>>>>>> @@ -0,0 +1,10 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#include <LibFdtSupport.h>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stddef.h
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..f6cf8d5702
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> >>>>>>>>>> @@ -0,0 +1,10 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#include <LibFdtSupport.h>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdint.h
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..f6cf8d5702
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> >>>>>>>>>> @@ -0,0 +1,10 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#include <LibFdtSupport.h>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdlib.h
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..f6cf8d5702
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> >>>>>>>>>> @@ -0,0 +1,10 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#include <LibFdtSupport.h>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/string.h
> >>>>>>>>>> new file mode 100644
> >>>>>>>>>> index 0000000000..f6cf8d5702
> >>>>>>>>>> --- /dev/null
> >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/string.h
> >>>>>>>>>> @@ -0,0 +1,10 @@
> >>>>>>>>>> +/** @file
> >>>>>>>>>>
> >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +**/
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> +#include <LibFdtSupport.h>
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
> >>> index
> >>>>>>>>>> 6ba85ebe61..f039daccdb 100644
> >>>>>>>>>> --- a/MdePkg/MdePkg.ci.yaml
> >>>>>>>>>> +++ b/MdePkg/MdePkg.ci.yaml
> >>>>>>>>>> @@ -2,7 +2,7 @@
> >>>>>>>>>>   # CI configuration for MdePkg
> >>>>>>>>>>
> >>>>>>>>>>   #
> >>>>>>>>>>
> >>>>>>>>>>   # Copyright (c) Microsoft Corporation
> >>>>>>>>>>
> >>>>>>>>>> -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>> +# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>>   # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>>   # Copyright (c) 2023, Loongson Technology Corporation Limited.
> >> All
> >>>>>>>>>> rights reserved.<BR>
> >>>>>>>>>>
> >>>>>>>>>>   # SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>>>>>>>
> >>>>>>>>>> @@ -67,7 +67,8 @@
> >>>>>>>>>>               "Include/Library/PcdLib.h",
> >>>>>>>>>>
> >>>>>>>>>>               "Include/Library/SafeIntLib.h",
> >>>>>>>>>>
> >>>>>>>>>>               "Include/Protocol/DebugSupport.h",
> >>>>>>>>>>
> >>>>>>>>>> -
> >> "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> >>>>>>>>>>
> >>>>>>>>>> +            "Library/BaseFdtLib"
> >>>>>>>>>>
> >>>>>>>>>>           ]
> >>>>>>>>>>
> >>>>>>>>>>       },
> >>>>>>>>>>
> >>>>>>>>>>       ## options defined ci/Plugin/CompilerPlugin
> >>>>>>>>>>
> >>>>>>>>>> @@ -164,5 +165,17 @@
> >>>>>>>>>>           "ExtendWords": [],           # words to extend to the dictionary
> >> for
> >>> this package
> >>>>>>>>>>
> >>>>>>>>>>           "IgnoreStandardPaths": [],   # Standard Plugin defined paths
> >> that
> >>> should be ignore
> >>>>>>>>>>
> >>>>>>>>>>           "AdditionalIncludePaths": [] # Additional paths to spell
> >>>>>>>>>> check (wildcards supported)
> >>>>>>>>>>
> >>>>>>>>>> +    },
> >>>>>>>>>>
> >>>>>>>>>> +    # options defined in .pytool/Plugin/UncrustifyCheck
> >>>>>>>>>>
> >>>>>>>>>> +    "UncrustifyCheck": {
> >>>>>>>>>>
> >>>>>>>>>> +        "IgnoreFiles": [
> >>>>>>>>>>
> >>>>>>>>>> +            "Library/BaseFdtLib/libfdt",
> >>>>>>>>>>
> >>>>>>>>>> +            "Library/BaseFdtLib/limits.h",
> >>>>>>>>>>
> >>>>>>>>>> +            "Library/BaseFdtLib/stdbool.h",
> >>>>>>>>>>
> >>>>>>>>>> +            "Library/BaseFdtLib/stddef.h",
> >>>>>>>>>>
> >>>>>>>>>> +            "Library/BaseFdtLib/stdint.h",
> >>>>>>>>>>
> >>>>>>>>>> +            "Library/BaseFdtLib/stdlib.h",
> >>>>>>>>>>
> >>>>>>>>>> +            "Library/BaseFdtLib/string.h"
> >>>>>>>>>>
> >>>>>>>>>> +        ]
> >>>>>>>>>>
> >>>>>>>>>>       }
> >>>>>>>>>>
> >>>>>>>>>>   }
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> >>>>>>>>>> e70182bf7f..9804a7a6bd 100644
> >>>>>>>>>> --- a/MdePkg/MdePkg.dec
> >>>>>>>>>> +++ b/MdePkg/MdePkg.dec
> >>>>>>>>>> @@ -289,6 +289,10 @@
> >>>>>>>>>>     #
> >>>>>>>>>>
> >>>>>>>>>>     ArmTrngLib|Include/Library/ArmTrngLib.h
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> >>>>>>>>>>
> >>>>>>>>>> +  #
> >>>>>>>>>>
> >>>>>>>>>> +  FdtLib|Include/Library/FdtLib.h
> >>>>>>>>>>
> >>>>>>>>>> +
> >>>>>>>>>>
> >>>>>>>>>>   [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> >>>>>>>>>>
> >>>>>>>>>>     ##  @libraryclass  Provides services to generate random number.
> >>>>>>>>>>
> >>>>>>>>>>     #
> >>>>>>>>>>
> >>>>>>>>>> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> >>>>>>>>>> 152c02991a..b38c863812 100644
> >>>>>>>>>> --- a/MdePkg/MdePkg.dsc
> >>>>>>>>>> +++ b/MdePkg/MdePkg.dsc
> >>>>>>>>>> @@ -137,6 +137,7 @@
> >>>>>>>>>>
> >>>>>>>>>>
> >>> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>     MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> >>>>>>>>>>
> >>>>>>>>>> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>   [Components.IA32, Components.X64, Components.ARM,
> >>>>>>>>>> Components.AARCH64]
> >>>>>>>>>>
> >>>>>>>>>>     #
> >>>>>>>>>>
> >>>>>>>>>> --
> >>>>>>>>>> 2.39.1.windows.1
> >>>>>>>
> >>>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >
> >
> >
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-05-03  2:34                       ` Chiu, Chasel
@ 2023-05-03  5:39                         ` Michael D Kinney
  2023-05-03 18:31                           ` Chiu, Chasel
  0 siblings, 1 reply; 20+ messages in thread
From: Michael D Kinney @ 2023-05-03  5:39 UTC (permalink / raw)
  To: Chiu, Chasel, devel@edk2.groups.io, quic_llindhol@quicinc.com
  Cc: Lin, Benny, Gao, Liming, Liu, Zhiguang, Pedro Falcato,
	Kinney, Michael D

I don't think the macros that are identical to BaseLib functions help.

My preference if for caller of FdtLib to know use SwapBytesxx() as needed.

Mike

> -----Original Message-----
> From: Chiu, Chasel <chasel.chiu@intel.com>
> Sent: Tuesday, May 2, 2023 7:35 PM
> To: devel@edk2.groups.io; quic_llindhol@quicinc.com; Kinney, Michael D
> <michael.d.kinney@intel.com>
> Cc: Lin, Benny <benny.lin@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> Pedro Falcato <pedro.falcato@gmail.com>
> Subject: RE: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> 
> Thanks Leif!
> To align with your suggestion I think we can define below MACROs in
> FdtLib.h.
> Library consumers can use those MACROs to convert structure data between
> Big endian and Little endian. (better readability)
> 
> Mike, what do you think?
> 
> Thanks,
> Chasel
> 
> 
> 
> //
> // Definitions for transferring FDT structure data between big-endian (FDT)
> and little-endian (CPU)
> //
> #define CPU_TO_FDT16(x)  SwapBytes16 (x)
> #define FDT16_TO_CPU(x)  SwapBytes16 (x)
> 
> #define CPU_TO_FDT32(x)  SwapBytes32 (x)
> #define FDT32_TO_CPU(x)  SwapBytes32 (x)
> 
> #define CPU_TO_FDT64(x)  SwapBytes64 (x)
> #define FDT64_TO_CPU(x)  SwapBytes64 (x)
> 
> 
> 
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Leif
> > Lindholm
> > Sent: Tuesday, May 2, 2023 4:42 AM
> > To: devel@edk2.groups.io; Chiu, Chasel <chasel.chiu@intel.com>; Kinney,
> > Michael D <michael.d.kinney@intel.com>
> > Cc: Lin, Benny <benny.lin@intel.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> Pedro
> > Falcato <pedro.falcato@gmail.com>
> > Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> >
> > Hi Chasel,
> >
> > Apologies, spent last week at Linaro Connect with little time to follow
> > the list.
> >
> > If we're seeing this purely as a wrapper on libfdt, then it shouldn't
> > need to provide additional functionality on top of what it provides.
> > My initial impression was that this library was attempting to do more,
> > but then I mostly skimmed it, and that appears to have been incorrect.
> >
> > What I *really* don't want is mixing abstractions. I.e. if we're getting
> > the pointers through libfdt calls, we should be using the libfdt
> > accessor functions to extract the data correctly. And expose the
> > cpu_to_fdt*/fdt*_to_cpu accessors through the library. Presumably as
> > Fdt*ToCpu/CpuToFdt*.
> >
> > Regards,
> >
> > Leif
> >
> >
> > On 2023-05-01 17:31, Chiu, Chasel wrote:
> > >
> > > Hi Leif,
> > >
> > > Would you please share your ideas and respond Mike's question too?
> > >
> > > Thanks,
> > > Chasel
> > >
> > >
> > >
> > >> -----Original Message-----
> > >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> Chiu,
> > Chasel
> > >> Sent: Tuesday, April 25, 2023 10:22 PM
> > >> To: devel@edk2.groups.io; Kinney, Michael D
> <michael.d.kinney@intel.com>;
> > >> Leif Lindholm <quic_llindhol@quicinc.com>
> > >> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> > >> <llindhol@qti.qualcomm.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>;
> > Liu,
> > >> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> > <pedro.falcato@gmail.com>
> > >> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> > >>
> > >>
> > >> Hello,
> > >>
> > >> Since platform may also define other FDT structures, this EDK2 library
> may
> > not
> > >> be able to convert all the FDT structures to little endian.
> > >> We might define a generic MACRO in library like
> > >> CONVERT_FDT_DATA_TO_LITTLE_ENDIAN which can be used for all
> > structure
> > >> data, but it will be almost like calling SwapBytes** directly.
> > >> Any other suggestion?
> > >>
> > >> Thanks,
> > >> Chasel
> > >>
> > >>
> > >>> -----Original Message-----
> > >>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> Michael
> > D
> > >>> Kinney
> > >>> Sent: Monday, April 24, 2023 10:41 AM
> > >>> To: Leif Lindholm <quic_llindhol@quicinc.com>; devel@edk2.groups.io
> > >>> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> > >>> <llindhol@qti.qualcomm.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>;
> > >> Liu,
> > >>> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> > >> <pedro.falcato@gmail.com>;
> > >>> Kinney, Michael D <michael.d.kinney@intel.com>
> > >>> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> > >>>
> > >>> Hi Leif,
> > >>>
> > >>> Do you have a proposal or small example on what you want to see
> > >>> in the library?
> > >>>
> > >>> Mike
> > >>>
> > >>>> -----Original Message-----
> > >>>> From: Leif Lindholm <quic_llindhol@quicinc.com>
> > >>>> Sent: Monday, April 24, 2023 10:29 AM
> > >>>> To: devel@edk2.groups.io; Kinney, Michael D
> > <michael.d.kinney@intel.com>
> > >>>> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> > >>> <llindhol@qti.qualcomm.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>;
> > >> Liu,
> > >>>> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> > >>> <pedro.falcato@gmail.com>
> > >>>> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT
> library.
> > >>>>
> > >>>> Apologies, I was refactoring a git tree and switched off the world :)
> > >>>>
> > >>>> Well, being a bit late to the party ... my view is it would be
> > >>>> preferable if we put the byteswapping in the library.
> > >>>>
> > >>>> The DT format is *defined* to be big-endian, 32-bit cells. So frankly,
> > >>>> I have no problems with pushing responsibility onto individual
> > >>>> platforms if they have decided to be "clever" by ignoring that -
> > >>>> if that gets rid of a bunch of boilerplate for sensibly behaving
> platforms.
> > >>>>
> > >>>> Maybe another excuse for getting
> > >>>> https://github.com/tianocore/edk2-
> > >>> platforms/blob/master/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
> > >>>> into MdePkg?
> > >>>>
> > >>>> /
> > >>>>      Leif
> > >>>>
> > >>>> On Thu, Apr 20, 2023 at 16:44:03 +0000, Michael D Kinney wrote:
> > >>>>> Hi Leif,
> > >>>>>
> > >>>>> What is your opinion on FDT being big endian.
> > >>>>>
> > >>>>> Do we want the lib to help with that aspect, or leave it up to the
> > consumer
> > >> of
> > >>> the lib to
> > >>>>> convert as needed?  Seems like an area that could be very error
> prone if
> > we
> > >>> are not
> > >>>>> careful.
> > >>>>>
> > >>>>> Mike
> > >>>>>
> > >>>>>> -----Original Message-----
> > >>>>>> From: Lin, Benny <benny.lin@intel.com>
> > >>>>>> Sent: Wednesday, April 19, 2023 9:25 PM
> > >>>>>> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > >>> devel@edk2.groups.io
> > >>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > >>> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > >>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > >>>>>>> -----Original Message-----
> > >>>>>>> From: Kinney, Michael D <michael.d.kinney@intel.com>
> > >>>>>>> Sent: Thursday, April 20, 2023 5:04 AM
> > >>>>>>> To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > >>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > >>> <zhiguang.liu@intel.com>; Pedro Falcato
> > >>>> <pedro.falcato@gmail.com>; Kinney,
> > >>>>>> Michael D <michael.d.kinney@intel.com>
> > >>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >>>>>>>
> > >>>>>>> Responses below
> > >>>>>>>
> > >>>>>>> Mike
> > >>>>>>>
> > >>>>>>>> -----Original Message-----
> > >>>>>>>> From: Lin, Benny <benny.lin@intel.com>
> > >>>>>>>> Sent: Wednesday, April 19, 2023 10:12 AM
> > >>>>>>>> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > >>>>>>>> devel@edk2.groups.io
> > >>>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > >>>>>>>> <zhiguang.liu@intel.com>; Pedro Falcato
> > >> <pedro.falcato@gmail.com>
> > >>>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >>>>>>>>
> > >>>>>>>> Please find my feedback below.
> > >>>>>>>> We can remove FDT_RESERVE_ENTRY but keep
> FDT_NODE_HEADER,
> > >>> what do you think?
> > >>>>>>>>
> > >>>>>>>> QQQ
> > >>>>>>>> Benny
> > >>>>>>>>
> > >>>>>>>>> -----Original Message-----
> > >>>>>>>>> From: Kinney, Michael D <michael.d.kinney@intel.com>
> > >>>>>>>>> Sent: Wednesday, April 19, 2023 11:54 PM
> > >>>>>>>>> To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > >>>>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > >>>>>>>>> <zhiguang.liu@intel.com>; Pedro Falcato
> > >> <pedro.falcato@gmail.com>;
> > >>>>>>>>> Kinney,
> > >>>>>>>> Michael D <michael.d.kinney@intel.com>
> > >>>>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >>>>>>>>>
> > >>>>>>>>> A few comments below.
> > >>>>>>>>>
> > >>>>>>>>> Mike
> > >>>>>>>>>
> > >>>>>>>>>> -----Original Message-----
> > >>>>>>>>>> From: Lin, Benny <benny.lin@intel.com>
> > >>>>>>>>>> Sent: Sunday, April 16, 2023 10:35 PM
> > >>>>>>>>>> To: devel@edk2.groups.io
> > >>>>>>>>>> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> > >>>>>>>>>> <michael.d.kinney@intel.com>; Gao, Liming
> > >>>>>>>>>> <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > >>> <zhiguang.liu@intel.com>;
> > >>>>>>>>>> Pedro Falcato <pedro.falcato@gmail.com>
> > >>>>>>>>>> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> > >>>>>>>>>>
> > >>>>>>>>>> From: Benny Lin <benny.lin@intel.com>
> > >>>>>>>>>>
> > >>>>>>>>>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> > >>>>>>>>>> Add FDT support in EDK2 by submodule 3rd party libfdt
> > >>>>>>>>>> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> > >>>>>>>>>> and refer to LibcLib implementation by Pedro.
> > >>>>>>>>>>
> > >>>>>>>>>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > >>>>>>>>>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > >>>>>>>>>> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > >>>>>>>>>> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> > >>>>>>>>>> Signed-off-by: Benny Lin <benny.lin@intel.com>
> > >>>>>>>>>> ---
> > >>>>>>>>>>   MdePkg/Include/Library/FdtLib.h           | 314
> > >>> ++++++++++++++++++++
> > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> > >>>>>>>>>> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/FdtLib.c        | 301
> > >>> +++++++++++++++++++
> > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> > >>>>>>>>>> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173
> +++++++++++
> > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/string.h        |  10 +
> > >>>>>>>>>>   MdePkg/MdePkg.ci.yaml                     |  17 +-
> > >>>>>>>>>>   MdePkg/MdePkg.dec                         |   4 +
> > >>>>>>>>>>   MdePkg/MdePkg.dsc                         |   1 +
> > >>>>>>>>>>   15 files changed, 1043 insertions(+), 2 deletions(-)
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Include/Library/FdtLib.h
> > >>>>>>>>>> b/MdePkg/Include/Library/FdtLib.h new file mode 100644
> index
> > >>>>>>>>>> 0000000000..d59b749c25
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Include/Library/FdtLib.h
> > >>>>>>>>>> @@ -0,0 +1,314 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  Flattened Device Tree Library.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#ifndef FDT_LIB_H_
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_LIB_H_
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +///
> > >>>>>>>>>>
> > >>>>>>>>>> +/// Flattened Device Tree definition
> > >>>>>>>>>>
> > >>>>>>>>>> +///
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef struct {
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    TotalSize;           /* total size of DT block */
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    OffsetDtStruct;      /* offset to structure */
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    OffsetDtStrings;     /* offset to strings */
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    OffsetMemRsvmap;     /* offset to memory
> reserve
> > >> map
> > >>> */
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    Version;             /* format version */
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    LastCompVersion;     /* last compatible version */
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  /* version 2 fields below */
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    BootCpuidPhys;       /* Which physical CPU id
> we're
> > >>>>>>>>>>
> > >>>>>>>>>> +                                    booting on */
> > >>>>>>>>>>
> > >>>>>>>>>> +  /* version 3 fields below */
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    SizeDtStrings;       /* size of the strings block */
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  /* version 17 fields below */
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    SizeDtStruct;        /* size of the structure block */
> > >>>>>>>>>>
> > >>>>>>>>>> +} FDT_HEADER;
> > >>>>>>>>>
> > >>>>>>>>> I see the macros below use SwapBytes32() on all the fields from
> this
> > >>>>>>>>> structure.  Does this mean this structure is big >endian?  If
> > >>>>>>>> that is the case, then the description of this structure and all
> > >>>>>>>> individual fields must make that very clear >so any consumer of
> the
> > >>>>>>>> structure knows it does not follow the default endianness of
> UEFI/PI
> > >>> and that consumers >must either use the macros or
> > >>>> consumers
> > >>>>>> must use SwapBytes32() on their own when using this structure
> directly.
> > >>>>>>>>
> > >>>>>>>> Yes, it's big endian. I will complete more descriptions in patch
> v4.
> > >>>>>>>
> > >>>>>>> Would it be simpler if we have a lib service that converts the
> entire
> > >> header
> > >>> from big endian to little endian.
> > >>>>>>> That way, the consumer can use the FDT_HEADER directly
> without any
> > >> of
> > >>> the macros?
> > >>>>>>>
> > >>>>>>> Also, is the rest of the FDT blob also big endian?
> > >>>>>>
> > >>>>>> FDT blob format is binary encoding of FDT data with big endian. In
> > >> addition,
> > >>> the consumer will set or get FDT data with FDT
> > >>>> blob. We
> > >>>>>> can complete more descriptions to warn consumers to be careful if
> just
> > >> use
> > >>> header struct for mapping and get/set FDT data
> > >>>> with FDT
> > >>>>>> blob.
> > >>>>>>
> > >>>>>> For provide lib services that converts between big endian and little
> > endian,
> > >>> we can provide a get header function to convert
> > >>>> between
> > >>>>>> big endian and little endian. However, we also need to consider
> the
> > >>> property value for setting and getting then we can
> > >>>> convert in
> > >>>>>> wrapper functions.
> > >>>>>>
> > >>>>>> For example,
> > >>>>>>
> > >>>>>> INT32
> > >>>>>> EFIAPI
> > >>>>>> FdtSetProp (
> > >>>>>>    IN VOID         *Fdt,
> > >>>>>>    IN INT32        NodeOffset,
> > >>>>>>    IN CONST CHAR8  *Name,
> > >>>>>>    IN CONST VOID   *Value,
> > >>>>>>    IN UINT32       Length
> > >>>>>>    )
> > >>>>>> {
> > >>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > >>>>>> }
> > >>>>>>
> > >>>>>> More functions for various byte width.
> > >>>>>> INT32
> > >>>>>> EFIAPI
> > >>>>>> FdtSetProp16 (
> > >>>>>>    IN VOID         *Fdt,
> > >>>>>>    IN INT32        NodeOffset,
> > >>>>>>    IN CONST CHAR8  *Name,
> > >>>>>>    IN CONST UINT16   *Value,
> > >>>>>>    IN UINT32       Length
> > >>>>>>    )
> > >>>>>> {
> > >>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value),
> > >>> (int)Length);
> > >>>>>> }
> > >>>>>>
> > >>>>>> INT32
> > >>>>>> EFIAPI
> > >>>>>> FdtSetProp32 (
> > >>>>>>    IN VOID         *Fdt,
> > >>>>>>    IN INT32        NodeOffset,
> > >>>>>>    IN CONST CHAR8  *Name,
> > >>>>>>    IN CONST UINT32   *Value,
> > >>>>>>    IN UINT32       Length
> > >>>>>>    )
> > >>>>>> {
> > >>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value),
> > >>> (int)Length);
> > >>>>>> }
> > >>>>>>
> > >>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef struct {
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT64    Address;
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT64    Size;
> > >>>>>>>>>>
> > >>>>>>>>>> +} FDT_RESERVE_ENTRY;
> > >>>>>>>>>
> > >>>>>>>>>
> > >>>>>>>>> I do not see this type used anywhere in the lib class or the lib
> > instance.
> > >>>>>>>>> Can it be removed?
> > >>>>>>>>
> > >>>>>>>> I think we can remove it because it might be not used for further
> > >> usage
> > >>> of FDT support.
> > >>>>>>>>
> > >>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef struct {
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    Tag;
> > >>>>>>>>>>
> > >>>>>>>>>> +  CHAR8     Name[];
> > >>>>>>>>>>
> > >>>>>>>>>> +} FDT_NODE_HEADER;
> > >>>>>>>>>
> > >>>>>>>>>
> > >>>>>>>>> I do not see this type used anywhere in the lib class or the lib
> > instance.
> > >>>>>>>>> Can it be removed?
> > >>>>>>>>
> > >>>>>>>> When we need retrieve a node from a FDT blob, we will get a
> node
> > >>>>>>>> offset then we could use the struct to map the node content. It's
> very
> > >>> useful.
> > >>>>>>>
> > >>>>>>> Please add a comment header for this structure and describe the
> usage
> > >> as
> > >>> it related to the rest of the FdtLib >services.
> > >>>>>>
> > >>>>>> I will add descriptions for the usage and remove
> FDT_RESERVE_ENTRY in
> > >>> patch v4.
> > >>>>>>
> > >>>>>>>
> > >>>>>>>>
> > >>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef struct {
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    Tag;
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    Length;
> > >>>>>>>>>>
> > >>>>>>>>>> +  UINT32    NameOffset;
> > >>>>>>>>>>
> > >>>>>>>>>> +  CHAR8     Data[];
> > >>>>>>>>>>
> > >>>>>>>>>> +} FDT_PROPERTY;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST
> > >>> FDT_HEADER
> > >>>>>>>>>> +*)(Fdt))->Field)
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt,
> Magic))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt,
> > >>> TotalSize))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_OFFSET_DT_STRUCT(Fdt)
> (FDT_GET_HEADER(Fdt,
> > >>> OffsetDtStruct))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_OFFSET_DT_STRINGS(Fdt)
> (FDT_GET_HEADER(Fdt,
> > >>>>>>>>>> +OffsetDtStrings))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)
> (FDT_GET_HEADER(Fdt,
> > >>>>>>>>>> +OffsetMemRsvmap))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt,
> Version))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_LAST_COMP_VERSION(Fdt)
> (FDT_GET_HEADER(Fdt,
> > >>>>>>>>>> +LastCompVersion))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_BOOT_CPUID_PHYS(Fdt)
> (FDT_GET_HEADER(Fdt,
> > >>> BootCpuidPhys))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_SIZE_DT_STRINGS(Fdt)
> (FDT_GET_HEADER(Fdt,
> > >>> SizeDtStrings))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_SIZE_DT_STRUCT(Fdt)
> (FDT_GET_HEADER(Fdt,
> > >>> SizeDtStruct))
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Verify the header of the Flattened Device Tree
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtCheckHeader (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Create a empty Flattened Device Tree.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Buffer         The pointer to allocate a pool for
> FDT
> > >> blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] BufferSize     The BufferSize to the pool size.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +RETURN_STATUS
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtCreateEmptyTree (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN VOID   *Buffer,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN UINTN  BufferSize
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of next node from the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Depth          The depth to the level of tree
> hierarchy.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to next node offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtNextNode (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       *Depth
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of first node under the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to next node offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtFirstSubnode (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of next node from the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to next node offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtNextSubnode (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of first node which includes the given
> name.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] ParentOffset    The offset to the node which
> start
> > >> find
> > >>> under.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Name            The name to search the node with
> the
> > >>> name.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] NameLength      The length of the name to
> check
> > >> only.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to node offset with given node name.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtSubnodeOffsetNameLen (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        ParentOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        NameLength
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of first node which includes the given
> property
> > >>> name and value.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] StartOffset     The offset to the starting node to
> find.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] PropertyName    The property name to search
> the
> > >>> node including the named property.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] PropertyValue   The property value to check
> the
> > >> same
> > >>> property value.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] PropertyLength  The length of the value in
> > >>> PropertValue.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to node offset with given property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtNodeOffsetByPropValue (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        StartOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *PropertyName,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *PropertyValue,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        PropertyLength
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a property with the given name from the given
> node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Name           The name to the property which
> need
> > >> be
> > >>> searched
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> property
> > >>> found.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The property to the structure of the found
> property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +CONST FDT_PROPERTY *
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtGetProperty (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        NodeOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        *Length
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of first property in the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to the node which need
> be
> > >>> searched.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to first property offset in the given
> node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtFirstPropertyOffset (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       NodeOffset
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of next property from the given property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to previous property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to next property offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtNextPropertyOffset (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a property from the given offset of the property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to the given offset of the
> > >>> property.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> property
> > >>> found.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The property to the structure of the given
> property
> > >> offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +CONST FDT_PROPERTY *
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtGetPropertyByOffset (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       *Length
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a string by the given string offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] StrOffset      The offset to the location in the
> strings
> > >>> block of FDT.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Length         The length to the size of string
> which
> > >> need
> > >>> be retrieved.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The string to the given string offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +CONST CHAR8 *
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtGetString (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       StrOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       *Length        OPTIONAL
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Add a new node to the FDT.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] ParentOffset   The offset to the node offset
> which
> > >>> want to add in.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Name           The name to name the node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return  The offset to the new node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtAddSubnode (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN VOID         *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        ParentOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *Name
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Add or modify a property in the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the node offset
> which
> > >>> want to add in.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Name           The name to name the property.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Value          The value to the property value.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return  Zero for successfully, otherwise failed.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtSetProp (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN VOID         *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        NodeOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *Value,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN UINT32       Length
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#endif /* FDT_LIB_H_ */
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..730e568ff6
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >>>>>>>>>> @@ -0,0 +1,62 @@
> > >>>>>>>>>> +## @file
> > >>>>>>>>>>
> > >>>>>>>>>> +# Flattened Device Tree Library.
> > >>>>>>>>>>
> > >>>>>>>>>> +#
> > >>>>>>>>>>
> > >>>>>>>>>> +# Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +#
> > >>>>>>>>>>
> > >>>>>>>>>> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +#
> > >>>>>>>>>>
> > >>>>>>>>>> +#
> > >>>>>>>>>>
> > >>>>>>>>>> +##
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +[Defines]
> > >>>>>>>>>>
> > >>>>>>>>>> +  INF_VERSION                    = 0x0001001B
> > >>>>>>>>>>
> > >>>>>>>>>> +  BASE_NAME                      = BaseFdtLib
> > >>>>>>>>>>
> > >>>>>>>>>> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> > >>>>>>>>>>
> > >>>>>>>>>> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-
> > >>> E8CEC206DE04
> > >>>>>>>>>>
> > >>>>>>>>>> +  MODULE_TYPE                    = BASE
> > >>>>>>>>>>
> > >>>>>>>>>> +  VERSION_STRING                 = 1.0
> > >>>>>>>>>>
> > >>>>>>>>>> +  LIBRARY_CLASS                  = FdtLib
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#
> > >>>>>>>>>>
> > >>>>>>>>>> +#  VALID_ARCHITECTURES           = IA32 X64
> > >>>>>>>>>>
> > >>>>>>>>>> +#
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +[Sources]
> > >>>>>>>>>>
> > >>>>>>>>>> +  FdtLib.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  LibFdtWrapper.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  # header Wrapper files
> > >>>>>>>>>>
> > >>>>>>>>>> +  limits.h
> > >>>>>>>>>>
> > >>>>>>>>>> +  stdbool.h
> > >>>>>>>>>>
> > >>>>>>>>>> +  stddef.h
> > >>>>>>>>>>
> > >>>>>>>>>> +  stdint.h
> > >>>>>>>>>>
> > >>>>>>>>>> +  stdlib.h
> > >>>>>>>>>>
> > >>>>>>>>>> +  string.h
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt.h
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_addresses.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_check.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_overlay.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_ro.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_rw.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_strerror.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_sw.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_wip.c
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt.h
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt_env.h
> > >>>>>>>>>>
> > >>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt_internal.h
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +[Packages]
> > >>>>>>>>>>
> > >>>>>>>>>> +  MdePkg/MdePkg.dec
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +[LibraryClasses]
> > >>>>>>>>>>
> > >>>>>>>>>> +  BaseLib
> > >>>>>>>>>>
> > >>>>>>>>>> +  BaseMemoryLib
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +[BuildOptions]
> > >>>>>>>>>>
> > >>>>>>>>>> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> > >>>>>>>>>>
> > >>>>>>>>>> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245
> > >> /wd4267
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..3f7e45ea6f
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > >>>>>>>>>> @@ -0,0 +1,14 @@
> > >>>>>>>>>> +// /** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +// Flattened Device Tree Library.
> > >>>>>>>>>>
> > >>>>>>>>>> +//
> > >>>>>>>>>>
> > >>>>>>>>>> +// Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +//
> > >>>>>>>>>>
> > >>>>>>>>>> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +//
> > >>>>>>>>>>
> > >>>>>>>>>> +// **/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#string STR_MODULE_ABSTRACT             #language en-US
> > >> "Instance
> > >>> of FDT Library"
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#string STR_MODULE_DESCRIPTION          #language en-US
> "This
> > >>> module provides FDT Library implementation."
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..200a496c7e
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > >>>>>>>>>> @@ -0,0 +1,301 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  Flattened Device Tree Library.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <libfdt/libfdt/libfdt.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Verify the header of the Flattened Device Tree
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtCheckHeader (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_check_header(Fdt);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Create a empty Flattened Device Tree.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Buffer         The pointer to allocate a pool for
> FDT
> > >> blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] BufferSize     The BufferSize to the pool size.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtCreateEmptyTree (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN VOID    *Buffer,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN UINT32  BufferSize
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of next node from the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Depth          The depth to the level of tree
> hierarchy.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to next node offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtNextNode (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       *Depth
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_next_node (Fdt, Offset, Depth);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of first node under the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to next node offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtFirstSubnode (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_first_subnode (Fdt, Offset);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of next node from the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to next node offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtNextSubnode (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_next_subnode (Fdt, Offset);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of first node which includes the given
> name.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] ParentOffset    The offset to the node which
> start
> > >> find
> > >>> under.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Name            The name to search the node with
> the
> > >>> name.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] NameLength      The length of the name to
> check
> > >> only.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to node offset with given node name.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtSubnodeOffsetNameLen (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        ParentOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        NameLength
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset,
> Name,
> > >>>>>>>>>> + NameLength);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of first node which includes the given
> property
> > >>> name and value.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] StartOffset     The offset to the starting node to
> find.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] PropertyName    The property name to search
> the
> > >>> node including the named property.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] PropertyValue   The property value to check
> the
> > >> same
> > >>> property value.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] PropertyLength  The length of the value in
> > >>> PropertValue.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to node offset with given property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtNodeOffsetByPropValue (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        StartOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *PropertyName,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *PropertyValue,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        PropertyLength
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> > >>>>>>>>>> + PropertyName, PropertyValue, PropertyLength);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a property with the given name from the given
> node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Name           The name to the property which
> need
> > >> be
> > >>> searched
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> property
> > >>> found.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The property to the structure of the found
> property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +CONST struct fdt_property *
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtGetProperty (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        NodeOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        *Length
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of first property in the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the node which
> need be
> > >>> searched.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to first property offset in the given
> node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtFirstPropertyOffset (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       NodeOffset
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_first_property_offset (Fdt, NodeOffset);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a offset of next property from the given property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to previous property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The offset to next property offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtNextPropertyOffset (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_next_property_offset (Fdt, Offset);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a property from the given offset of the property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Offset         The offset to the given offset of the
> > >>> property.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> property
> > >>> found.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The property to the structure of the given
> property
> > >> offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +CONST struct fdt_property *
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtGetPropertyByOffset (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       Offset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       *Length
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Returns a string by the given string offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] StrOffset      The offset to the location in the
> strings
> > >>> block of FDT.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Length         The length to the size of string
> which
> > >> need
> > >>> be retrieved.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return The string to the given string offset.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +CONST CHAR8 *
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtGetString (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       StrOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32       *Length        OPTIONAL
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_get_string (Fdt, StrOffset, Length);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Add a new node to the FDT.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] ParentOffset   The offset to the node offset
> which
> > >>> want to add in.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Name           The name to name the node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return  The offset to the new node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtAddSubnode (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN VOID         *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        ParentOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *Name
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +/**
> > >>>>>>>>>>
> > >>>>>>>>>> +  Add or modify a property in the given node.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the node offset
> which
> > >>> want to add in.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Name           The name to name the property.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Value          The value to the property value.
> > >>>>>>>>>>
> > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> property.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  @return  Zero for successfully, otherwise failed.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +INT32
> > >>>>>>>>>>
> > >>>>>>>>>> +EFIAPI
> > >>>>>>>>>>
> > >>>>>>>>>> +FdtSetProp (
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN VOID         *Fdt,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN INT32        NodeOffset,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN CONST VOID   *Value,
> > >>>>>>>>>>
> > >>>>>>>>>> +  IN UINT32       Length
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  return fdt_setprop (Fdt, NodeOffset, Name, Value,
> (int)Length);
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..e738f4ded4
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > >>>>>>>>>> @@ -0,0 +1,99 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  Root include file of C runtime library to support building the
> > >>>>>>>>>> + third-party
> > >>>>>>>>>>
> > >>>>>>>>>> +  libfdt library.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#ifndef FDT_LIB_SUPPORT_H_
> > >>>>>>>>>>
> > >>>>>>>>>> +#define FDT_LIB_SUPPORT_H_
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <Base.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <Library/BaseLib.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <Library/BaseMemoryLib.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef UINT8    uint8_t;
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef UINT16   uint16_t;
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef INT32    int32_t;
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef UINT32   uint32_t;
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef UINT64   uint64_t;
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef UINTN    uintptr_t;
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef UINTN    size_t;
> > >>>>>>>>>>
> > >>>>>>>>>> +typedef BOOLEAN  bool;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#define true   (1 == 1)
> > >>>>>>>>>>
> > >>>>>>>>>> +#define false  (1 == 0)
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +//
> > >>>>>>>>>>
> > >>>>>>>>>> +// Definitions for global constants used by libfdt library
> > >>>>>>>>>> +routines
> > >>>>>>>>>>
> > >>>>>>>>>> +//
> > >>>>>>>>>>
> > >>>>>>>>>> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed)
> int
> > >> value
> > >>> */
> > >>>>>>>>>>
> > >>>>>>>>>> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed)
> int32
> > >>> value */
> > >>>>>>>>>>
> > >>>>>>>>>> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum
> unsigned
> > >> int32
> > >>> value */
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +//
> > >>>>>>>>>>
> > >>>>>>>>>> +// Function prototypes of libfdt Library routines
> > >>>>>>>>>>
> > >>>>>>>>>> +//
> > >>>>>>>>>>
> > >>>>>>>>>> +void *
> > >>>>>>>>>>
> > >>>>>>>>>> +memset     (
> > >>>>>>>>>>
> > >>>>>>>>>> +  void *,
> > >>>>>>>>>>
> > >>>>>>>>>> +  int,
> > >>>>>>>>>>
> > >>>>>>>>>> +  size_t
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +int
> > >>>>>>>>>>
> > >>>>>>>>>> +memcmp      (
> > >>>>>>>>>>
> > >>>>>>>>>> +  const void *,
> > >>>>>>>>>>
> > >>>>>>>>>> +  const void *,
> > >>>>>>>>>>
> > >>>>>>>>>> +  size_t
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +int
> > >>>>>>>>>>
> > >>>>>>>>>> +strcmp      (
> > >>>>>>>>>>
> > >>>>>>>>>> +  const char *,
> > >>>>>>>>>>
> > >>>>>>>>>> +  const char *
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +char *
> > >>>>>>>>>>
> > >>>>>>>>>> +strchr     (
> > >>>>>>>>>>
> > >>>>>>>>>> +  const char *,
> > >>>>>>>>>>
> > >>>>>>>>>> +  int
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +char *
> > >>>>>>>>>>
> > >>>>>>>>>> +strrchr    (
> > >>>>>>>>>>
> > >>>>>>>>>> +  const char *,
> > >>>>>>>>>>
> > >>>>>>>>>> +  int
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +unsigned long
> > >>>>>>>>>>
> > >>>>>>>>>> +strtoul     (
> > >>>>>>>>>>
> > >>>>>>>>>> +  const char *,
> > >>>>>>>>>>
> > >>>>>>>>>> +  char **,
> > >>>>>>>>>>
> > >>>>>>>>>> +  int
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +char *
> > >>>>>>>>>>
> > >>>>>>>>>> +strcpy (
> > >>>>>>>>>>
> > >>>>>>>>>> +  char        *strDest,
> > >>>>>>>>>>
> > >>>>>>>>>> +  const char  *strSource
> > >>>>>>>>>>
> > >>>>>>>>>> +  );
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +//
> > >>>>>>>>>>
> > >>>>>>>>>> +// Macros that directly map functions to BaseLib,
> BaseMemoryLib,
> > >>>>>>>>>> +and DebugLib functions
> > >>>>>>>>>>
> > >>>>>>>>>> +//
> > >>>>>>>>>>
> > >>>>>>>>>> +#define memcpy(dest, source, count)
> CopyMem(dest,source,
> > >>> (UINTN)(count))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define memset(dest, ch, count)             SetMem(dest,
> > >>> (UINTN)(count),(UINT8)(ch))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define memchr(buf, ch, count)              ScanMem8(buf,
> > >>> (UINTN)(count),(UINT8)ch)
> > >>>>>>>>>>
> > >>>>>>>>>> +#define memcmp(buf1, buf2, count)
> > >> (int)(CompareMem(buf1,
> > >>> buf2, (UINTN)(count)))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define memmove(dest, source, count)        CopyMem(dest,
> > >> source,
> > >>> (UINTN)(count))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str,
> > >> count))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define strncpy(strDest, strSource, count)
> AsciiStrnCpyS(strDest,
> > >>>>>>>>>> +MAX_STRING_SIZE, strSource, (UINTN)count)
> > >>>>>>>>>>
> > >>>>>>>>>> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest,
> > >>> MAX_STRING_SIZE, strSource)
> > >>>>>>>>>>
> > >>>>>>>>>> +#define strcmp(string1, string2, count)
> (int)(AsciiStrCmp(string1,
> > >>> string2))
> > >>>>>>>>>>
> > >>>>>>>>>> +#define strncmp(string1, string2, count)
> > >> (int)(AsciiStrnCmp(string1,
> > >>> string2, (UINTN)(count)))
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#endif /* FDT_LIB_SUPPORT_H_ */
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..772bba4839
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > >>>>>>>>>> @@ -0,0 +1,173 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  ISO C implementations of strchr, strrchr and strtoul.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> > >>>>>>>>>>
> > >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <Base.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum
> unsigned
> > >> long
> > >>> value */
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +// Very quick notes:
> > >>>>>>>>>>
> > >>>>>>>>>> +// We only go through the string once for both functions
> > >>>>>>>>>>
> > >>>>>>>>>> +// They are minimal implementations (not speed optimized)
> of ISO
> > >> C
> > >>>>>>>>>> +semantics
> > >>>>>>>>>>
> > >>>>>>>>>> +// strchr and strrchr also include the null terminator as part
> of
> > >>>>>>>>>> +the string
> > >>>>>>>>>>
> > >>>>>>>>>> +// so the code gets a bit clunky to handle that case
> specifically.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +char *
> > >>>>>>>>>>
> > >>>>>>>>>> +strchr (
> > >>>>>>>>>>
> > >>>>>>>>>> +  const char  *Str,
> > >>>>>>>>>>
> > >>>>>>>>>> +  int         Char
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  char  *S;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  S = (char *)Str;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  for ( ; ; S++) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    if (*S == Char) {
> > >>>>>>>>>>
> > >>>>>>>>>> +      return S;
> > >>>>>>>>>>
> > >>>>>>>>>> +    }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +    if (*S == '\0') {
> > >>>>>>>>>>
> > >>>>>>>>>> +      return NULL;
> > >>>>>>>>>>
> > >>>>>>>>>> +    }
> > >>>>>>>>>>
> > >>>>>>>>>> +  }
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +char *
> > >>>>>>>>>>
> > >>>>>>>>>> +strrchr (
> > >>>>>>>>>>
> > >>>>>>>>>> +  const char  *Str,
> > >>>>>>>>>>
> > >>>>>>>>>> +  int         Char
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  char  *S, *last;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  S    = (char *)Str;
> > >>>>>>>>>>
> > >>>>>>>>>> +  last = NULL;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  for ( ; ; S++) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    if (*S == Char) {
> > >>>>>>>>>>
> > >>>>>>>>>> +      last = S;
> > >>>>>>>>>>
> > >>>>>>>>>> +    }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +    if (*S == '\0') {
> > >>>>>>>>>>
> > >>>>>>>>>> +      return last;
> > >>>>>>>>>>
> > >>>>>>>>>> +    }
> > >>>>>>>>>>
> > >>>>>>>>>> +  }
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +STATIC
> > >>>>>>>>>>
> > >>>>>>>>>> +int
> > >>>>>>>>>>
> > >>>>>>>>>> +__isspace (
> > >>>>>>>>>>
> > >>>>>>>>>> +  int  ch
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  // basic ASCII ctype.h:isspace(). Not efficient
> > >>>>>>>>>>
> > >>>>>>>>>> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
> > >>>>>>>>>> + == '\v' || ch == '\f';
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +unsigned long
> > >>>>>>>>>>
> > >>>>>>>>>> +strtoul (
> > >>>>>>>>>>
> > >>>>>>>>>> +  const char  *Nptr,
> > >>>>>>>>>>
> > >>>>>>>>>> +  char        **EndPtr,
> > >>>>>>>>>>
> > >>>>>>>>>> +  int         Base
> > >>>>>>>>>>
> > >>>>>>>>>> +  )
> > >>>>>>>>>>
> > >>>>>>>>>> +{
> > >>>>>>>>>>
> > >>>>>>>>>> +  BOOLEAN        Negate;
> > >>>>>>>>>>
> > >>>>>>>>>> +  BOOLEAN        Overflow;
> > >>>>>>>>>>
> > >>>>>>>>>> +  unsigned long  Val;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  Negate   = FALSE;
> > >>>>>>>>>>
> > >>>>>>>>>> +  Overflow = FALSE;
> > >>>>>>>>>>
> > >>>>>>>>>> +  Val      = 0;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  // Reject bad numeric bases
> > >>>>>>>>>>
> > >>>>>>>>>> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    return 0;
> > >>>>>>>>>>
> > >>>>>>>>>> +  }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  // Skip whitespace
> > >>>>>>>>>>
> > >>>>>>>>>> +  while (__isspace (*Nptr)) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    Nptr++;
> > >>>>>>>>>>
> > >>>>>>>>>> +  }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  // Check for + or - prefixes
> > >>>>>>>>>>
> > >>>>>>>>>> +  if (*Nptr == '-') {
> > >>>>>>>>>>
> > >>>>>>>>>> +    Negate = TRUE;
> > >>>>>>>>>>
> > >>>>>>>>>> +    Nptr++;
> > >>>>>>>>>>
> > >>>>>>>>>> +  } else if (*Nptr == '+') {
> > >>>>>>>>>>
> > >>>>>>>>>> +    Nptr++;
> > >>>>>>>>>>
> > >>>>>>>>>> +  }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  // Consume the start, autodetecting base if needed
> > >>>>>>>>>>
> > >>>>>>>>>> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
> > >>>>>>>>>> + && ((Base == 0) || (Base == 16))) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    // Hex
> > >>>>>>>>>>
> > >>>>>>>>>> +    Nptr += 2;
> > >>>>>>>>>>
> > >>>>>>>>>> +    Base  = 16;
> > >>>>>>>>>>
> > >>>>>>>>>> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> > >>>>>>>>>> + 'B')) && ((Base == 0) || (Base == 2))) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    // Binary (standard pending C23)
> > >>>>>>>>>>
> > >>>>>>>>>> +    Nptr += 2;
> > >>>>>>>>>>
> > >>>>>>>>>> +    Base  = 2;
> > >>>>>>>>>>
> > >>>>>>>>>> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    // Octal
> > >>>>>>>>>>
> > >>>>>>>>>> +    Nptr++;
> > >>>>>>>>>>
> > >>>>>>>>>> +    Base = 8;
> > >>>>>>>>>>
> > >>>>>>>>>> +  } else {
> > >>>>>>>>>>
> > >>>>>>>>>> +    if (Base == 0) {
> > >>>>>>>>>>
> > >>>>>>>>>> +      // Assume decimal
> > >>>>>>>>>>
> > >>>>>>>>>> +      Base = 10;
> > >>>>>>>>>>
> > >>>>>>>>>> +    }
> > >>>>>>>>>>
> > >>>>>>>>>> +  }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  while (TRUE) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    int            Digit;
> > >>>>>>>>>>
> > >>>>>>>>>> +    char           C;
> > >>>>>>>>>>
> > >>>>>>>>>> +    unsigned long  NewVal;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +    C     = *Nptr;
> > >>>>>>>>>>
> > >>>>>>>>>> +    Digit = -1;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +    if ((C >= '0') && (C <= '9')) {
> > >>>>>>>>>>
> > >>>>>>>>>> +      Digit = C - '0';
> > >>>>>>>>>>
> > >>>>>>>>>> +    } else if ((C >= 'a') && (C <= 'z')) {
> > >>>>>>>>>>
> > >>>>>>>>>> +      Digit = C - 'a' + 10;
> > >>>>>>>>>>
> > >>>>>>>>>> +    } else if ((C >= 'A') && (C <= 'Z')) {
> > >>>>>>>>>>
> > >>>>>>>>>> +      Digit = C - 'A' + 10;
> > >>>>>>>>>>
> > >>>>>>>>>> +    }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +    if ((Digit == -1) || (Digit >= Base)) {
> > >>>>>>>>>>
> > >>>>>>>>>> +      // Note that this case also handles the \0
> > >>>>>>>>>>
> > >>>>>>>>>> +      if (EndPtr) {
> > >>>>>>>>>>
> > >>>>>>>>>> +        *EndPtr = (char *)Nptr;
> > >>>>>>>>>>
> > >>>>>>>>>> +      }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +      break;
> > >>>>>>>>>>
> > >>>>>>>>>> +    }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +    NewVal = Val * Base + Digit;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +    if (NewVal < Val) {
> > >>>>>>>>>>
> > >>>>>>>>>> +      // Overflow
> > >>>>>>>>>>
> > >>>>>>>>>> +      Overflow = TRUE;
> > >>>>>>>>>>
> > >>>>>>>>>> +    }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +    Val = NewVal;
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +    Nptr++;
> > >>>>>>>>>>
> > >>>>>>>>>> +  }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  if (Negate) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    Val = -Val;
> > >>>>>>>>>>
> > >>>>>>>>>> +  }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  if (Overflow) {
> > >>>>>>>>>>
> > >>>>>>>>>> +    Val = ULONG_MAX;
> > >>>>>>>>>>
> > >>>>>>>>>> +  }
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +  // TODO: We're lacking errno here.
> > >>>>>>>>>>
> > >>>>>>>>>> +  return Val;
> > >>>>>>>>>>
> > >>>>>>>>>> +}
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/limits.h
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..f6cf8d5702
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> > >>>>>>>>>> @@ -0,0 +1,10 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <LibFdtSupport.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdbool.h
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..f6cf8d5702
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> > >>>>>>>>>> @@ -0,0 +1,10 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <LibFdtSupport.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stddef.h
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..f6cf8d5702
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> > >>>>>>>>>> @@ -0,0 +1,10 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <LibFdtSupport.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdint.h
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..f6cf8d5702
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> > >>>>>>>>>> @@ -0,0 +1,10 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <LibFdtSupport.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdlib.h
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..f6cf8d5702
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> > >>>>>>>>>> @@ -0,0 +1,10 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <LibFdtSupport.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/string.h
> > >>>>>>>>>> new file mode 100644
> > >>>>>>>>>> index 0000000000..f6cf8d5702
> > >>>>>>>>>> --- /dev/null
> > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/string.h
> > >>>>>>>>>> @@ -0,0 +1,10 @@
> > >>>>>>>>>> +/** @file
> > >>>>>>>>>>
> > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +**/
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> +#include <LibFdtSupport.h>
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/MdePkg.ci.yaml
> b/MdePkg/MdePkg.ci.yaml
> > >>> index
> > >>>>>>>>>> 6ba85ebe61..f039daccdb 100644
> > >>>>>>>>>> --- a/MdePkg/MdePkg.ci.yaml
> > >>>>>>>>>> +++ b/MdePkg/MdePkg.ci.yaml
> > >>>>>>>>>> @@ -2,7 +2,7 @@
> > >>>>>>>>>>   # CI configuration for MdePkg
> > >>>>>>>>>>
> > >>>>>>>>>>   #
> > >>>>>>>>>>
> > >>>>>>>>>>   # Copyright (c) Microsoft Corporation
> > >>>>>>>>>>
> > >>>>>>>>>> -# Copyright (c) 2020, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>> +# Copyright (c) 2023, Intel Corporation. All rights
> reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>>   # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>>   # Copyright (c) 2023, Loongson Technology Corporation
> Limited.
> > >> All
> > >>>>>>>>>> rights reserved.<BR>
> > >>>>>>>>>>
> > >>>>>>>>>>   # SPDX-License-Identifier: BSD-2-Clause-Patent
> > >>>>>>>>>>
> > >>>>>>>>>> @@ -67,7 +67,8 @@
> > >>>>>>>>>>               "Include/Library/PcdLib.h",
> > >>>>>>>>>>
> > >>>>>>>>>>               "Include/Library/SafeIntLib.h",
> > >>>>>>>>>>
> > >>>>>>>>>>               "Include/Protocol/DebugSupport.h",
> > >>>>>>>>>>
> > >>>>>>>>>> -
> > >> "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> > >>>>>>>>>>
> > >>>>>>>>>> +            "Library/BaseFdtLib"
> > >>>>>>>>>>
> > >>>>>>>>>>           ]
> > >>>>>>>>>>
> > >>>>>>>>>>       },
> > >>>>>>>>>>
> > >>>>>>>>>>       ## options defined ci/Plugin/CompilerPlugin
> > >>>>>>>>>>
> > >>>>>>>>>> @@ -164,5 +165,17 @@
> > >>>>>>>>>>           "ExtendWords": [],           # words to extend to the
> dictionary
> > >> for
> > >>> this package
> > >>>>>>>>>>
> > >>>>>>>>>>           "IgnoreStandardPaths": [],   # Standard Plugin defined
> paths
> > >> that
> > >>> should be ignore
> > >>>>>>>>>>
> > >>>>>>>>>>           "AdditionalIncludePaths": [] # Additional paths to spell
> > >>>>>>>>>> check (wildcards supported)
> > >>>>>>>>>>
> > >>>>>>>>>> +    },
> > >>>>>>>>>>
> > >>>>>>>>>> +    # options defined in .pytool/Plugin/UncrustifyCheck
> > >>>>>>>>>>
> > >>>>>>>>>> +    "UncrustifyCheck": {
> > >>>>>>>>>>
> > >>>>>>>>>> +        "IgnoreFiles": [
> > >>>>>>>>>>
> > >>>>>>>>>> +            "Library/BaseFdtLib/libfdt",
> > >>>>>>>>>>
> > >>>>>>>>>> +            "Library/BaseFdtLib/limits.h",
> > >>>>>>>>>>
> > >>>>>>>>>> +            "Library/BaseFdtLib/stdbool.h",
> > >>>>>>>>>>
> > >>>>>>>>>> +            "Library/BaseFdtLib/stddef.h",
> > >>>>>>>>>>
> > >>>>>>>>>> +            "Library/BaseFdtLib/stdint.h",
> > >>>>>>>>>>
> > >>>>>>>>>> +            "Library/BaseFdtLib/stdlib.h",
> > >>>>>>>>>>
> > >>>>>>>>>> +            "Library/BaseFdtLib/string.h"
> > >>>>>>>>>>
> > >>>>>>>>>> +        ]
> > >>>>>>>>>>
> > >>>>>>>>>>       }
> > >>>>>>>>>>
> > >>>>>>>>>>   }
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> > >>>>>>>>>> e70182bf7f..9804a7a6bd 100644
> > >>>>>>>>>> --- a/MdePkg/MdePkg.dec
> > >>>>>>>>>> +++ b/MdePkg/MdePkg.dec
> > >>>>>>>>>> @@ -289,6 +289,10 @@
> > >>>>>>>>>>     #
> > >>>>>>>>>>
> > >>>>>>>>>>     ArmTrngLib|Include/Library/ArmTrngLib.h
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> > >>>>>>>>>>
> > >>>>>>>>>> +  #
> > >>>>>>>>>>
> > >>>>>>>>>> +  FdtLib|Include/Library/FdtLib.h
> > >>>>>>>>>>
> > >>>>>>>>>> +
> > >>>>>>>>>>
> > >>>>>>>>>>   [LibraryClasses.IA32, LibraryClasses.X64,
> LibraryClasses.AARCH64]
> > >>>>>>>>>>
> > >>>>>>>>>>     ##  @libraryclass  Provides services to generate random
> number.
> > >>>>>>>>>>
> > >>>>>>>>>>     #
> > >>>>>>>>>>
> > >>>>>>>>>> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> > >>>>>>>>>> 152c02991a..b38c863812 100644
> > >>>>>>>>>> --- a/MdePkg/MdePkg.dsc
> > >>>>>>>>>> +++ b/MdePkg/MdePkg.dsc
> > >>>>>>>>>> @@ -137,6 +137,7 @@
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>
> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>>     MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> > >>>>>>>>>>
> > >>>>>>>>>> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>>   [Components.IA32, Components.X64, Components.ARM,
> > >>>>>>>>>> Components.AARCH64]
> > >>>>>>>>>>
> > >>>>>>>>>>     #
> > >>>>>>>>>>
> > >>>>>>>>>> --
> > >>>>>>>>>> 2.39.1.windows.1
> > >>>>>>>
> > >>>>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> > 
> >


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
  2023-05-03  5:39                         ` Michael D Kinney
@ 2023-05-03 18:31                           ` Chiu, Chasel
  0 siblings, 0 replies; 20+ messages in thread
From: Chiu, Chasel @ 2023-05-03 18:31 UTC (permalink / raw)
  To: Kinney, Michael D, devel@edk2.groups.io,
	quic_llindhol@quicinc.com
  Cc: Lin, Benny, Gao, Liming, Liu, Zhiguang, Pedro Falcato


Hi Leif, Mike,

Thanks for all the feedbacks and basing on offline discussion, we will implement CpuToFdt*() and Fdt*ToCpu() functions to align with original libfdt functionality.
Will update patch series accordingly.

Thanks,
Chasel





> -----Original Message-----
> From: Kinney, Michael D <michael.d.kinney@intel.com>
> Sent: Tuesday, May 2, 2023 10:39 PM
> To: Chiu, Chasel <chasel.chiu@intel.com>; devel@edk2.groups.io;
> quic_llindhol@quicinc.com
> Cc: Lin, Benny <benny.lin@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Pedro
> Falcato <pedro.falcato@gmail.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>
> Subject: RE: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> 
> I don't think the macros that are identical to BaseLib functions help.
> 
> My preference if for caller of FdtLib to know use SwapBytesxx() as needed.
> 
> Mike
> 
> > -----Original Message-----
> > From: Chiu, Chasel <chasel.chiu@intel.com>
> > Sent: Tuesday, May 2, 2023 7:35 PM
> > To: devel@edk2.groups.io; quic_llindhol@quicinc.com; Kinney, Michael D
> > <michael.d.kinney@intel.com>
> > Cc: Lin, Benny <benny.lin@intel.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> > Pedro Falcato <pedro.falcato@gmail.com>
> > Subject: RE: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> >
> >
> > Thanks Leif!
> > To align with your suggestion I think we can define below MACROs in
> > FdtLib.h.
> > Library consumers can use those MACROs to convert structure data between
> > Big endian and Little endian. (better readability)
> >
> > Mike, what do you think?
> >
> > Thanks,
> > Chasel
> >
> >
> >
> > //
> > // Definitions for transferring FDT structure data between big-endian (FDT)
> > and little-endian (CPU)
> > //
> > #define CPU_TO_FDT16(x)  SwapBytes16 (x)
> > #define FDT16_TO_CPU(x)  SwapBytes16 (x)
> >
> > #define CPU_TO_FDT32(x)  SwapBytes32 (x)
> > #define FDT32_TO_CPU(x)  SwapBytes32 (x)
> >
> > #define CPU_TO_FDT64(x)  SwapBytes64 (x)
> > #define FDT64_TO_CPU(x)  SwapBytes64 (x)
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Leif
> > > Lindholm
> > > Sent: Tuesday, May 2, 2023 4:42 AM
> > > To: devel@edk2.groups.io; Chiu, Chasel <chasel.chiu@intel.com>; Kinney,
> > > Michael D <michael.d.kinney@intel.com>
> > > Cc: Lin, Benny <benny.lin@intel.com>; Gao, Liming
> > > <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> > Pedro
> > > Falcato <pedro.falcato@gmail.com>
> > > Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> > >
> > > Hi Chasel,
> > >
> > > Apologies, spent last week at Linaro Connect with little time to follow
> > > the list.
> > >
> > > If we're seeing this purely as a wrapper on libfdt, then it shouldn't
> > > need to provide additional functionality on top of what it provides.
> > > My initial impression was that this library was attempting to do more,
> > > but then I mostly skimmed it, and that appears to have been incorrect.
> > >
> > > What I *really* don't want is mixing abstractions. I.e. if we're getting
> > > the pointers through libfdt calls, we should be using the libfdt
> > > accessor functions to extract the data correctly. And expose the
> > > cpu_to_fdt*/fdt*_to_cpu accessors through the library. Presumably as
> > > Fdt*ToCpu/CpuToFdt*.
> > >
> > > Regards,
> > >
> > > Leif
> > >
> > >
> > > On 2023-05-01 17:31, Chiu, Chasel wrote:
> > > >
> > > > Hi Leif,
> > > >
> > > > Would you please share your ideas and respond Mike's question too?
> > > >
> > > > Thanks,
> > > > Chasel
> > > >
> > > >
> > > >
> > > >> -----Original Message-----
> > > >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> > Chiu,
> > > Chasel
> > > >> Sent: Tuesday, April 25, 2023 10:22 PM
> > > >> To: devel@edk2.groups.io; Kinney, Michael D
> > <michael.d.kinney@intel.com>;
> > > >> Leif Lindholm <quic_llindhol@quicinc.com>
> > > >> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> > > >> <llindhol@qti.qualcomm.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>;
> > > Liu,
> > > >> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> > > <pedro.falcato@gmail.com>
> > > >> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >>
> > > >>
> > > >> Hello,
> > > >>
> > > >> Since platform may also define other FDT structures, this EDK2 library
> > may
> > > not
> > > >> be able to convert all the FDT structures to little endian.
> > > >> We might define a generic MACRO in library like
> > > >> CONVERT_FDT_DATA_TO_LITTLE_ENDIAN which can be used for all
> > > structure
> > > >> data, but it will be almost like calling SwapBytes** directly.
> > > >> Any other suggestion?
> > > >>
> > > >> Thanks,
> > > >> Chasel
> > > >>
> > > >>
> > > >>> -----Original Message-----
> > > >>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> > Michael
> > > D
> > > >>> Kinney
> > > >>> Sent: Monday, April 24, 2023 10:41 AM
> > > >>> To: Leif Lindholm <quic_llindhol@quicinc.com>; devel@edk2.groups.io
> > > >>> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> > > >>> <llindhol@qti.qualcomm.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>;
> > > >> Liu,
> > > >>> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> > > >> <pedro.falcato@gmail.com>;
> > > >>> Kinney, Michael D <michael.d.kinney@intel.com>
> > > >>> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >>>
> > > >>> Hi Leif,
> > > >>>
> > > >>> Do you have a proposal or small example on what you want to see
> > > >>> in the library?
> > > >>>
> > > >>> Mike
> > > >>>
> > > >>>> -----Original Message-----
> > > >>>> From: Leif Lindholm <quic_llindhol@quicinc.com>
> > > >>>> Sent: Monday, April 24, 2023 10:29 AM
> > > >>>> To: devel@edk2.groups.io; Kinney, Michael D
> > > <michael.d.kinney@intel.com>
> > > >>>> Cc: Lin, Benny <benny.lin@intel.com>; Leif Lindholm
> > > >>> <llindhol@qti.qualcomm.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>;
> > > >> Liu,
> > > >>>> Zhiguang <zhiguang.liu@intel.com>; Pedro Falcato
> > > >>> <pedro.falcato@gmail.com>
> > > >>>> Subject: Re: [edk2-devel] [PATCH v3 2/3] MdePkg: Support FDT
> > library.
> > > >>>>
> > > >>>> Apologies, I was refactoring a git tree and switched off the world :)
> > > >>>>
> > > >>>> Well, being a bit late to the party ... my view is it would be
> > > >>>> preferable if we put the byteswapping in the library.
> > > >>>>
> > > >>>> The DT format is *defined* to be big-endian, 32-bit cells. So frankly,
> > > >>>> I have no problems with pushing responsibility onto individual
> > > >>>> platforms if they have decided to be "clever" by ignoring that -
> > > >>>> if that gets rid of a bunch of boilerplate for sensibly behaving
> > platforms.
> > > >>>>
> > > >>>> Maybe another excuse for getting
> > > >>>> https://github.com/tianocore/edk2-
> > > >>> platforms/blob/master/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
> > > >>>> into MdePkg?
> > > >>>>
> > > >>>> /
> > > >>>>      Leif
> > > >>>>
> > > >>>> On Thu, Apr 20, 2023 at 16:44:03 +0000, Michael D Kinney wrote:
> > > >>>>> Hi Leif,
> > > >>>>>
> > > >>>>> What is your opinion on FDT being big endian.
> > > >>>>>
> > > >>>>> Do we want the lib to help with that aspect, or leave it up to the
> > > consumer
> > > >> of
> > > >>> the lib to
> > > >>>>> convert as needed?  Seems like an area that could be very error
> > prone if
> > > we
> > > >>> are not
> > > >>>>> careful.
> > > >>>>>
> > > >>>>> Mike
> > > >>>>>
> > > >>>>>> -----Original Message-----
> > > >>>>>> From: Lin, Benny <benny.lin@intel.com>
> > > >>>>>> Sent: Wednesday, April 19, 2023 9:25 PM
> > > >>>>>> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > >>> devel@edk2.groups.io
> > > >>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > >>> <zhiguang.liu@intel.com>; Pedro Falcato <pedro.falcato@gmail.com>
> > > >>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >>>>>>
> > > >>>>>>
> > > >>>>>>
> > > >>>>>>> -----Original Message-----
> > > >>>>>>> From: Kinney, Michael D <michael.d.kinney@intel.com>
> > > >>>>>>> Sent: Thursday, April 20, 2023 5:04 AM
> > > >>>>>>> To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > > >>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > >>> <zhiguang.liu@intel.com>; Pedro Falcato
> > > >>>> <pedro.falcato@gmail.com>; Kinney,
> > > >>>>>> Michael D <michael.d.kinney@intel.com>
> > > >>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >>>>>>>
> > > >>>>>>> Responses below
> > > >>>>>>>
> > > >>>>>>> Mike
> > > >>>>>>>
> > > >>>>>>>> -----Original Message-----
> > > >>>>>>>> From: Lin, Benny <benny.lin@intel.com>
> > > >>>>>>>> Sent: Wednesday, April 19, 2023 10:12 AM
> > > >>>>>>>> To: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > >>>>>>>> devel@edk2.groups.io
> > > >>>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > >>>>>>>> <zhiguang.liu@intel.com>; Pedro Falcato
> > > >> <pedro.falcato@gmail.com>
> > > >>>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >>>>>>>>
> > > >>>>>>>> Please find my feedback below.
> > > >>>>>>>> We can remove FDT_RESERVE_ENTRY but keep
> > FDT_NODE_HEADER,
> > > >>> what do you think?
> > > >>>>>>>>
> > > >>>>>>>> QQQ
> > > >>>>>>>> Benny
> > > >>>>>>>>
> > > >>>>>>>>> -----Original Message-----
> > > >>>>>>>>> From: Kinney, Michael D <michael.d.kinney@intel.com>
> > > >>>>>>>>> Sent: Wednesday, April 19, 2023 11:54 PM
> > > >>>>>>>>> To: Lin, Benny <benny.lin@intel.com>; devel@edk2.groups.io
> > > >>>>>>>>> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > >>>>>>>>> <zhiguang.liu@intel.com>; Pedro Falcato
> > > >> <pedro.falcato@gmail.com>;
> > > >>>>>>>>> Kinney,
> > > >>>>>>>> Michael D <michael.d.kinney@intel.com>
> > > >>>>>>>>> Subject: RE: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >>>>>>>>>
> > > >>>>>>>>> A few comments below.
> > > >>>>>>>>>
> > > >>>>>>>>> Mike
> > > >>>>>>>>>
> > > >>>>>>>>>> -----Original Message-----
> > > >>>>>>>>>> From: Lin, Benny <benny.lin@intel.com>
> > > >>>>>>>>>> Sent: Sunday, April 16, 2023 10:35 PM
> > > >>>>>>>>>> To: devel@edk2.groups.io
> > > >>>>>>>>>> Cc: Lin, Benny <benny.lin@intel.com>; Kinney, Michael D
> > > >>>>>>>>>> <michael.d.kinney@intel.com>; Gao, Liming
> > > >>>>>>>>>> <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > >>> <zhiguang.liu@intel.com>;
> > > >>>>>>>>>> Pedro Falcato <pedro.falcato@gmail.com>
> > > >>>>>>>>>> Subject: [PATCH v3 2/3] MdePkg: Support FDT library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> From: Benny Lin <benny.lin@intel.com>
> > > >>>>>>>>>>
> > > >>>>>>>>>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4392
> > > >>>>>>>>>> Add FDT support in EDK2 by submodule 3rd party libfdt
> > > >>>>>>>>>> (https://github.com/devicetree-org/pylibfdt/tree/main/libfdt)
> > > >>>>>>>>>> and refer to LibcLib implementation by Pedro.
> > > >>>>>>>>>>
> > > >>>>>>>>>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > > >>>>>>>>>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > > >>>>>>>>>> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > > >>>>>>>>>> Acked-by: Pedro Falcato <pedro.falcato@gmail.com>
> > > >>>>>>>>>> Signed-off-by: Benny Lin <benny.lin@intel.com>
> > > >>>>>>>>>> ---
> > > >>>>>>>>>>   MdePkg/Include/Library/FdtLib.h           | 314
> > > >>> ++++++++++++++++++++
> > > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/BaseFdtLib.inf  |  62 ++++
> > > >>>>>>>>>> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni  |  14 +
> > > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/FdtLib.c        | 301
> > > >>> +++++++++++++++++++
> > > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/LibFdtSupport.h |  99 ++++++
> > > >>>>>>>>>> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 173
> > +++++++++++
> > > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/limits.h        |  10 +
> > > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdbool.h       |  10 +
> > > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stddef.h        |  10 +
> > > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdint.h        |  10 +
> > > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/stdlib.h        |  10 +
> > > >>>>>>>>>>   MdePkg/Library/BaseFdtLib/string.h        |  10 +
> > > >>>>>>>>>>   MdePkg/MdePkg.ci.yaml                     |  17 +-
> > > >>>>>>>>>>   MdePkg/MdePkg.dec                         |   4 +
> > > >>>>>>>>>>   MdePkg/MdePkg.dsc                         |   1 +
> > > >>>>>>>>>>   15 files changed, 1043 insertions(+), 2 deletions(-)
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Include/Library/FdtLib.h
> > > >>>>>>>>>> b/MdePkg/Include/Library/FdtLib.h new file mode 100644
> > index
> > > >>>>>>>>>> 0000000000..d59b749c25
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Include/Library/FdtLib.h
> > > >>>>>>>>>> @@ -0,0 +1,314 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Flattened Device Tree Library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#ifndef FDT_LIB_H_
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_LIB_H_
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +///
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/// Flattened Device Tree definition
> > > >>>>>>>>>>
> > > >>>>>>>>>> +///
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef struct {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    Magic;               /* magic word FDT_MAGIC */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    TotalSize;           /* total size of DT block */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    OffsetDtStruct;      /* offset to structure */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    OffsetDtStrings;     /* offset to strings */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    OffsetMemRsvmap;     /* offset to memory
> > reserve
> > > >> map
> > > >>> */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    Version;             /* format version */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    LastCompVersion;     /* last compatible version */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  /* version 2 fields below */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    BootCpuidPhys;       /* Which physical CPU id
> > we're
> > > >>>>>>>>>>
> > > >>>>>>>>>> +                                    booting on */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  /* version 3 fields below */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    SizeDtStrings;       /* size of the strings block */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  /* version 17 fields below */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    SizeDtStruct;        /* size of the structure block */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +} FDT_HEADER;
> > > >>>>>>>>>
> > > >>>>>>>>> I see the macros below use SwapBytes32() on all the fields from
> > this
> > > >>>>>>>>> structure.  Does this mean this structure is big >endian?  If
> > > >>>>>>>> that is the case, then the description of this structure and all
> > > >>>>>>>> individual fields must make that very clear >so any consumer of
> > the
> > > >>>>>>>> structure knows it does not follow the default endianness of
> > UEFI/PI
> > > >>> and that consumers >must either use the macros or
> > > >>>> consumers
> > > >>>>>> must use SwapBytes32() on their own when using this structure
> > directly.
> > > >>>>>>>>
> > > >>>>>>>> Yes, it's big endian. I will complete more descriptions in patch
> > v4.
> > > >>>>>>>
> > > >>>>>>> Would it be simpler if we have a lib service that converts the
> > entire
> > > >> header
> > > >>> from big endian to little endian.
> > > >>>>>>> That way, the consumer can use the FDT_HEADER directly
> > without any
> > > >> of
> > > >>> the macros?
> > > >>>>>>>
> > > >>>>>>> Also, is the rest of the FDT blob also big endian?
> > > >>>>>>
> > > >>>>>> FDT blob format is binary encoding of FDT data with big endian. In
> > > >> addition,
> > > >>> the consumer will set or get FDT data with FDT
> > > >>>> blob. We
> > > >>>>>> can complete more descriptions to warn consumers to be careful if
> > just
> > > >> use
> > > >>> header struct for mapping and get/set FDT data
> > > >>>> with FDT
> > > >>>>>> blob.
> > > >>>>>>
> > > >>>>>> For provide lib services that converts between big endian and little
> > > endian,
> > > >>> we can provide a get header function to convert
> > > >>>> between
> > > >>>>>> big endian and little endian. However, we also need to consider
> > the
> > > >>> property value for setting and getting then we can
> > > >>>> convert in
> > > >>>>>> wrapper functions.
> > > >>>>>>
> > > >>>>>> For example,
> > > >>>>>>
> > > >>>>>> INT32
> > > >>>>>> EFIAPI
> > > >>>>>> FdtSetProp (
> > > >>>>>>    IN VOID         *Fdt,
> > > >>>>>>    IN INT32        NodeOffset,
> > > >>>>>>    IN CONST CHAR8  *Name,
> > > >>>>>>    IN CONST VOID   *Value,
> > > >>>>>>    IN UINT32       Length
> > > >>>>>>    )
> > > >>>>>> {
> > > >>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, Value, (int)Length);
> > > >>>>>> }
> > > >>>>>>
> > > >>>>>> More functions for various byte width.
> > > >>>>>> INT32
> > > >>>>>> EFIAPI
> > > >>>>>> FdtSetProp16 (
> > > >>>>>>    IN VOID         *Fdt,
> > > >>>>>>    IN INT32        NodeOffset,
> > > >>>>>>    IN CONST CHAR8  *Name,
> > > >>>>>>    IN CONST UINT16   *Value,
> > > >>>>>>    IN UINT32       Length
> > > >>>>>>    )
> > > >>>>>> {
> > > >>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes16(Value),
> > > >>> (int)Length);
> > > >>>>>> }
> > > >>>>>>
> > > >>>>>> INT32
> > > >>>>>> EFIAPI
> > > >>>>>> FdtSetProp32 (
> > > >>>>>>    IN VOID         *Fdt,
> > > >>>>>>    IN INT32        NodeOffset,
> > > >>>>>>    IN CONST CHAR8  *Name,
> > > >>>>>>    IN CONST UINT32   *Value,
> > > >>>>>>    IN UINT32       Length
> > > >>>>>>    )
> > > >>>>>> {
> > > >>>>>>    return fdt_setprop (Fdt, NodeOffset, Name, SwapBytes32(Value),
> > > >>> (int)Length);
> > > >>>>>> }
> > > >>>>>>
> > > >>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef struct {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT64    Address;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT64    Size;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +} FDT_RESERVE_ENTRY;
> > > >>>>>>>>>
> > > >>>>>>>>>
> > > >>>>>>>>> I do not see this type used anywhere in the lib class or the lib
> > > instance.
> > > >>>>>>>>> Can it be removed?
> > > >>>>>>>>
> > > >>>>>>>> I think we can remove it because it might be not used for further
> > > >> usage
> > > >>> of FDT support.
> > > >>>>>>>>
> > > >>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef struct {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    Tag;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  CHAR8     Name[];
> > > >>>>>>>>>>
> > > >>>>>>>>>> +} FDT_NODE_HEADER;
> > > >>>>>>>>>
> > > >>>>>>>>>
> > > >>>>>>>>> I do not see this type used anywhere in the lib class or the lib
> > > instance.
> > > >>>>>>>>> Can it be removed?
> > > >>>>>>>>
> > > >>>>>>>> When we need retrieve a node from a FDT blob, we will get a
> > node
> > > >>>>>>>> offset then we could use the struct to map the node content. It's
> > very
> > > >>> useful.
> > > >>>>>>>
> > > >>>>>>> Please add a comment header for this structure and describe the
> > usage
> > > >> as
> > > >>> it related to the rest of the FdtLib >services.
> > > >>>>>>
> > > >>>>>> I will add descriptions for the usage and remove
> > FDT_RESERVE_ENTRY in
> > > >>> patch v4.
> > > >>>>>>
> > > >>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef struct {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    Tag;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    Length;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  UINT32    NameOffset;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  CHAR8     Data[];
> > > >>>>>>>>>>
> > > >>>>>>>>>> +} FDT_PROPERTY;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_GET_HEADER(Fdt, Field)  SwapBytes32(((CONST
> > > >>> FDT_HEADER
> > > >>>>>>>>>> +*)(Fdt))->Field)
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_MAGIC(Fdt)              (FDT_GET_HEADER(Fdt,
> > Magic))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_TOTAL_SIZE(Fdt)         (FDT_GET_HEADER(Fdt,
> > > >>> TotalSize))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_OFFSET_DT_STRUCT(Fdt)
> > (FDT_GET_HEADER(Fdt,
> > > >>> OffsetDtStruct))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_OFFSET_DT_STRINGS(Fdt)
> > (FDT_GET_HEADER(Fdt,
> > > >>>>>>>>>> +OffsetDtStrings))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_OFFSET_MEM_RSVMAP(Fdt)
> > (FDT_GET_HEADER(Fdt,
> > > >>>>>>>>>> +OffsetMemRsvmap))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_VERSION(Fdt)            (FDT_GET_HEADER(Fdt,
> > Version))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_LAST_COMP_VERSION(Fdt)
> > (FDT_GET_HEADER(Fdt,
> > > >>>>>>>>>> +LastCompVersion))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_BOOT_CPUID_PHYS(Fdt)
> > (FDT_GET_HEADER(Fdt,
> > > >>> BootCpuidPhys))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_SIZE_DT_STRINGS(Fdt)
> > (FDT_GET_HEADER(Fdt,
> > > >>> SizeDtStrings))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_SIZE_DT_STRUCT(Fdt)
> > (FDT_GET_HEADER(Fdt,
> > > >>> SizeDtStruct))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Verify the header of the Flattened Device Tree
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtCheckHeader (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Create a empty Flattened Device Tree.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Buffer         The pointer to allocate a pool for
> > FDT
> > > >> blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] BufferSize     The BufferSize to the pool size.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +RETURN_STATUS
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtCreateEmptyTree (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN VOID   *Buffer,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN UINTN  BufferSize
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of next node from the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Depth          The depth to the level of tree
> > hierarchy.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to next node offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtNextNode (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       *Depth
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of first node under the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to next node offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtFirstSubnode (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of next node from the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to next node offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtNextSubnode (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of first node which includes the given
> > name.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] ParentOffset    The offset to the node which
> > start
> > > >> find
> > > >>> under.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Name            The name to search the node with
> > the
> > > >>> name.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] NameLength      The length of the name to
> > check
> > > >> only.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to node offset with given node name.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtSubnodeOffsetNameLen (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        ParentOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        NameLength
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of first node which includes the given
> > property
> > > >>> name and value.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] StartOffset     The offset to the starting node to
> > find.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] PropertyName    The property name to search
> > the
> > > >>> node including the named property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] PropertyValue   The property value to check
> > the
> > > >> same
> > > >>> property value.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] PropertyLength  The length of the value in
> > > >>> PropertValue.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to node offset with given property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtNodeOffsetByPropValue (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        StartOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *PropertyName,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *PropertyValue,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        PropertyLength
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a property with the given name from the given
> > node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Name           The name to the property which
> > need
> > > >> be
> > > >>> searched
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> > property
> > > >>> found.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The property to the structure of the found
> > property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +CONST FDT_PROPERTY *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtGetProperty (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        NodeOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        *Length
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of first property in the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to the node which need
> > be
> > > >>> searched.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to first property offset in the given
> > node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtFirstPropertyOffset (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       NodeOffset
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of next property from the given property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to previous property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to next property offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtNextPropertyOffset (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a property from the given offset of the property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to the given offset of the
> > > >>> property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> > property
> > > >>> found.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The property to the structure of the given
> > property
> > > >> offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +CONST FDT_PROPERTY *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtGetPropertyByOffset (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       *Length
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a string by the given string offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] StrOffset      The offset to the location in the
> > strings
> > > >>> block of FDT.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Length         The length to the size of string
> > which
> > > >> need
> > > >>> be retrieved.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The string to the given string offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +CONST CHAR8 *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtGetString (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       StrOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       *Length        OPTIONAL
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Add a new node to the FDT.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] ParentOffset   The offset to the node offset
> > which
> > > >>> want to add in.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Name           The name to name the node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return  The offset to the new node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtAddSubnode (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN VOID         *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        ParentOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *Name
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Add or modify a property in the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the node offset
> > which
> > > >>> want to add in.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Name           The name to name the property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Value          The value to the property value.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> > property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return  Zero for successfully, otherwise failed.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtSetProp (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN VOID         *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        NodeOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *Value,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN UINT32       Length
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#endif /* FDT_LIB_H_ */
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..730e568ff6
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > >>>>>>>>>> @@ -0,0 +1,62 @@
> > > >>>>>>>>>> +## @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +# Flattened Device Tree Library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#
> > > >>>>>>>>>>
> > > >>>>>>>>>> +# Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#
> > > >>>>>>>>>>
> > > >>>>>>>>>> +##
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +[Defines]
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  INF_VERSION                    = 0x0001001B
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  BASE_NAME                      = BaseFdtLib
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  MODULE_UNI_FILE                = BaseFdtLib.uni
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  FILE_GUID                      = C64DCB01-B037-4FF6-9CF3-
> > > >>> E8CEC206DE04
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  MODULE_TYPE                    = BASE
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  VERSION_STRING                 = 1.0
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  LIBRARY_CLASS                  = FdtLib
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  DEFINE FDT_LIB_PATH            = libfdt/libfdt
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#  VALID_ARCHITECTURES           = IA32 X64
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +[Sources]
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  FdtLib.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  LibFdtWrapper.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  # header Wrapper files
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  limits.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  stdbool.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  stddef.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  stdint.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  stdlib.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  string.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_addresses.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_check.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_empty_tree.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_overlay.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_ro.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_rw.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_strerror.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_sw.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/fdt_wip.c
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt_env.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  $(FDT_LIB_PATH)/libfdt_internal.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +[Packages]
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  MdePkg/MdePkg.dec
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +[LibraryClasses]
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  BaseLib
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  BaseMemoryLib
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +[BuildOptions]
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245
> > > >> /wd4267
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..3f7e45ea6f
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.uni
> > > >>>>>>>>>> @@ -0,0 +1,14 @@
> > > >>>>>>>>>> +// /** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// Flattened Device Tree Library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +//
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +//
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +//
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// **/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#string STR_MODULE_ABSTRACT             #language en-US
> > > >> "Instance
> > > >>> of FDT Library"
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#string STR_MODULE_DESCRIPTION          #language en-US
> > "This
> > > >>> module provides FDT Library implementation."
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..200a496c7e
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> > > >>>>>>>>>> @@ -0,0 +1,301 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Flattened Device Tree Library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <libfdt/libfdt/libfdt.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Verify the header of the Flattened Device Tree
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtCheckHeader (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_check_header(Fdt);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Create a empty Flattened Device Tree.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Buffer         The pointer to allocate a pool for
> > FDT
> > > >> blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] BufferSize     The BufferSize to the pool size.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return Zero for successfully, otherwise failed.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtCreateEmptyTree (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN VOID    *Buffer,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN UINT32  BufferSize
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_create_empty_tree (Buffer, (int)BufferSize);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of next node from the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Depth          The depth to the level of tree
> > hierarchy.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to next node offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtNextNode (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       *Depth
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_next_node (Fdt, Offset, Depth);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of first node under the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to next node offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtFirstSubnode (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_first_subnode (Fdt, Offset);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of next node from the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to previous node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to next node offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtNextSubnode (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_next_subnode (Fdt, Offset);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of first node which includes the given
> > name.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] ParentOffset    The offset to the node which
> > start
> > > >> find
> > > >>> under.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Name            The name to search the node with
> > the
> > > >>> name.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] NameLength      The length of the name to
> > check
> > > >> only.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to node offset with given node name.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtSubnodeOffsetNameLen (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        ParentOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        NameLength
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_subnode_offset_namelen (Fdt, ParentOffset,
> > Name,
> > > >>>>>>>>>> + NameLength);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of first node which includes the given
> > property
> > > >>> name and value.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt             The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] StartOffset     The offset to the starting node to
> > find.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] PropertyName    The property name to search
> > the
> > > >>> node including the named property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] PropertyValue   The property value to check
> > the
> > > >> same
> > > >>> property value.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] PropertyLength  The length of the value in
> > > >>> PropertValue.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to node offset with given property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtNodeOffsetByPropValue (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        StartOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *PropertyName,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *PropertyValue,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        PropertyLength
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_node_offset_by_prop_value (Fdt, StartOffset,
> > > >>>>>>>>>> + PropertyName, PropertyValue, PropertyLength);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a property with the given name from the given
> > node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Name           The name to the property which
> > need
> > > >> be
> > > >>> searched
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> > property
> > > >>> found.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The property to the structure of the found
> > property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +CONST struct fdt_property *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtGetProperty (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        NodeOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        *Length
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_get_property (Fdt, NodeOffset, Name, Length);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of first property in the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the node which
> > need be
> > > >>> searched.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to first property offset in the given
> > node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtFirstPropertyOffset (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       NodeOffset
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_first_property_offset (Fdt, NodeOffset);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a offset of next property from the given property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to previous property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The offset to next property offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtNextPropertyOffset (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_next_property_offset (Fdt, Offset);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a property from the given offset of the property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Offset         The offset to the given offset of the
> > > >>> property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> > property
> > > >>> found.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The property to the structure of the given
> > property
> > > >> offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +CONST struct fdt_property *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtGetPropertyByOffset (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       Offset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       *Length
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_get_property_by_offset (Fdt, Offset, Length);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Returns a string by the given string offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] StrOffset      The offset to the location in the
> > strings
> > > >>> block of FDT.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Length         The length to the size of string
> > which
> > > >> need
> > > >>> be retrieved.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return The string to the given string offset.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +CONST CHAR8 *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtGetString (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID  *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       StrOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32       *Length        OPTIONAL
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_get_string (Fdt, StrOffset, Length);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Add a new node to the FDT.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] ParentOffset   The offset to the node offset
> > which
> > > >>> want to add in.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Name           The name to name the node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return  The offset to the new node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtAddSubnode (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN VOID         *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        ParentOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *Name
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_add_subnode (Fdt, ParentOffset, Name);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +/**
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Add or modify a property in the given node.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Fdt            The pointer to FDT blob.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] NodeOffset     The offset to the node offset
> > which
> > > >>> want to add in.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Name           The name to name the property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Value          The value to the property value.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @param[in] Length         The length to the size of the
> > property.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  @return  Zero for successfully, otherwise failed.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +INT32
> > > >>>>>>>>>>
> > > >>>>>>>>>> +EFIAPI
> > > >>>>>>>>>>
> > > >>>>>>>>>> +FdtSetProp (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN VOID         *Fdt,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN INT32        NodeOffset,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST CHAR8  *Name,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN CONST VOID   *Value,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  IN UINT32       Length
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return fdt_setprop (Fdt, NodeOffset, Name, Value,
> > (int)Length);
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..e738f4ded4
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> > > >>>>>>>>>> @@ -0,0 +1,99 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Root include file of C runtime library to support building the
> > > >>>>>>>>>> + third-party
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  libfdt library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#ifndef FDT_LIB_SUPPORT_H_
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define FDT_LIB_SUPPORT_H_
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <Base.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <Library/BaseLib.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <Library/BaseMemoryLib.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef UINT8    uint8_t;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef UINT16   uint16_t;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef INT32    int32_t;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef UINT32   uint32_t;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef UINT64   uint64_t;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef UINTN    uintptr_t;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef UINTN    size_t;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +typedef BOOLEAN  bool;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define true   (1 == 1)
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define false  (1 == 0)
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +//
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// Definitions for global constants used by libfdt library
> > > >>>>>>>>>> +routines
> > > >>>>>>>>>>
> > > >>>>>>>>>> +//
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define INT_MAX          0x7FFFFFFF      /* Maximum (signed)
> > int
> > > >> value
> > > >>> */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define INT32_MAX        0x7FFFFFFF      /* Maximum (signed)
> > int32
> > > >>> value */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define UINT32_MAX       0xFFFFFFFF      /* Maximum
> > unsigned
> > > >> int32
> > > >>> value */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +//
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// Function prototypes of libfdt Library routines
> > > >>>>>>>>>>
> > > >>>>>>>>>> +//
> > > >>>>>>>>>>
> > > >>>>>>>>>> +void *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +memset     (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  void *,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  int,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  size_t
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +int
> > > >>>>>>>>>>
> > > >>>>>>>>>> +memcmp      (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const void *,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const void *,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  size_t
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +int
> > > >>>>>>>>>>
> > > >>>>>>>>>> +strcmp      (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const char *,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const char *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +char *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +strchr     (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const char *,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  int
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +char *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +strrchr    (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const char *,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  int
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +unsigned long
> > > >>>>>>>>>>
> > > >>>>>>>>>> +strtoul     (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const char *,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  char **,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  int
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +char *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +strcpy (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  char        *strDest,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const char  *strSource
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  );
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +//
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// Macros that directly map functions to BaseLib,
> > BaseMemoryLib,
> > > >>>>>>>>>> +and DebugLib functions
> > > >>>>>>>>>>
> > > >>>>>>>>>> +//
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define memcpy(dest, source, count)
> > CopyMem(dest,source,
> > > >>> (UINTN)(count))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define memset(dest, ch, count)             SetMem(dest,
> > > >>> (UINTN)(count),(UINT8)(ch))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define memchr(buf, ch, count)              ScanMem8(buf,
> > > >>> (UINTN)(count),(UINT8)ch)
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define memcmp(buf1, buf2, count)
> > > >> (int)(CompareMem(buf1,
> > > >>> buf2, (UINTN)(count)))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define memmove(dest, source, count)        CopyMem(dest,
> > > >> source,
> > > >>> (UINTN)(count))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define strlen(str)                         (size_t)(AsciiStrLen(str))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define strnlen(str, count)                 (size_t)(AsciiStrnLenS(str,
> > > >> count))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define strncpy(strDest, strSource, count)
> > AsciiStrnCpyS(strDest,
> > > >>>>>>>>>> +MAX_STRING_SIZE, strSource, (UINTN)count)
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define strcat(strDest, strSource)          AsciiStrCatS(strDest,
> > > >>> MAX_STRING_SIZE, strSource)
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define strcmp(string1, string2, count)
> > (int)(AsciiStrCmp(string1,
> > > >>> string2))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define strncmp(string1, string2, count)
> > > >> (int)(AsciiStrnCmp(string1,
> > > >>> string2, (UINTN)(count)))
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#endif /* FDT_LIB_SUPPORT_H_ */
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..772bba4839
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> > > >>>>>>>>>> @@ -0,0 +1,173 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  ISO C implementations of strchr, strrchr and strtoul.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Copyright (c) 2023 Pedro Falcato All rights reserved.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <Base.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#define ULONG_MAX        0xFFFFFFFF      /* Maximum
> > unsigned
> > > >> long
> > > >>> value */
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// Very quick notes:
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// We only go through the string once for both functions
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// They are minimal implementations (not speed optimized)
> > of ISO
> > > >> C
> > > >>>>>>>>>> +semantics
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// strchr and strrchr also include the null terminator as part
> > of
> > > >>>>>>>>>> +the string
> > > >>>>>>>>>>
> > > >>>>>>>>>> +// so the code gets a bit clunky to handle that case
> > specifically.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +char *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +strchr (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const char  *Str,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  int         Char
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  char  *S;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  S = (char *)Str;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  for ( ; ; S++) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    if (*S == Char) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      return S;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    if (*S == '\0') {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      return NULL;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +char *
> > > >>>>>>>>>>
> > > >>>>>>>>>> +strrchr (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const char  *Str,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  int         Char
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  char  *S, *last;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  S    = (char *)Str;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  last = NULL;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  for ( ; ; S++) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    if (*S == Char) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      last = S;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    if (*S == '\0') {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      return last;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +STATIC
> > > >>>>>>>>>>
> > > >>>>>>>>>> +int
> > > >>>>>>>>>>
> > > >>>>>>>>>> +__isspace (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  int  ch
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  // basic ASCII ctype.h:isspace(). Not efficient
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t' || ch
> > > >>>>>>>>>> + == '\v' || ch == '\f';
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +unsigned long
> > > >>>>>>>>>>
> > > >>>>>>>>>> +strtoul (
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  const char  *Nptr,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  char        **EndPtr,
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  int         Base
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  )
> > > >>>>>>>>>>
> > > >>>>>>>>>> +{
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  BOOLEAN        Negate;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  BOOLEAN        Overflow;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  unsigned long  Val;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Negate   = FALSE;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Overflow = FALSE;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Val      = 0;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  // Reject bad numeric bases
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  if ((Base < 0) || (Base == 1) || (Base > 36)) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    return 0;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  // Skip whitespace
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  while (__isspace (*Nptr)) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Nptr++;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  // Check for + or - prefixes
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  if (*Nptr == '-') {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Negate = TRUE;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Nptr++;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  } else if (*Nptr == '+') {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Nptr++;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  // Consume the start, autodetecting base if needed
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  if ((Nptr[0] == '0') && ((Nptr[1] == 'x') || (Nptr[1] == 'X'))
> > > >>>>>>>>>> + && ((Base == 0) || (Base == 16))) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    // Hex
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Nptr += 2;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Base  = 16;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  } else if ((Nptr[0] == '0') && ((Nptr[1] == 'b') || (Nptr[1] ==
> > > >>>>>>>>>> + 'B')) && ((Base == 0) || (Base == 2))) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    // Binary (standard pending C23)
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Nptr += 2;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Base  = 2;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  } else if ((Nptr[0] == '0') && ((Base == 0) || (Base == 8))) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    // Octal
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Nptr++;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Base = 8;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  } else {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    if (Base == 0) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      // Assume decimal
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      Base = 10;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  while (TRUE) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    int            Digit;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    char           C;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    unsigned long  NewVal;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    C     = *Nptr;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Digit = -1;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    if ((C >= '0') && (C <= '9')) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      Digit = C - '0';
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    } else if ((C >= 'a') && (C <= 'z')) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      Digit = C - 'a' + 10;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    } else if ((C >= 'A') && (C <= 'Z')) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      Digit = C - 'A' + 10;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    if ((Digit == -1) || (Digit >= Base)) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      // Note that this case also handles the \0
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      if (EndPtr) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +        *EndPtr = (char *)Nptr;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      break;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    NewVal = Val * Base + Digit;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    if (NewVal < Val) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      // Overflow
> > > >>>>>>>>>>
> > > >>>>>>>>>> +      Overflow = TRUE;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Val = NewVal;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Nptr++;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  if (Negate) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Val = -Val;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  if (Overflow) {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    Val = ULONG_MAX;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  }
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  // TODO: We're lacking errno here.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  return Val;
> > > >>>>>>>>>>
> > > >>>>>>>>>> +}
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/limits.h
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/limits.h
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..f6cf8d5702
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/limits.h
> > > >>>>>>>>>> @@ -0,0 +1,10 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <LibFdtSupport.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdbool.h
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdbool.h
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..f6cf8d5702
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdbool.h
> > > >>>>>>>>>> @@ -0,0 +1,10 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <LibFdtSupport.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stddef.h
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stddef.h
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..f6cf8d5702
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stddef.h
> > > >>>>>>>>>> @@ -0,0 +1,10 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <LibFdtSupport.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdint.h
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdint.h
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..f6cf8d5702
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdint.h
> > > >>>>>>>>>> @@ -0,0 +1,10 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <LibFdtSupport.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/stdlib.h
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/stdlib.h
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..f6cf8d5702
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/stdlib.h
> > > >>>>>>>>>> @@ -0,0 +1,10 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <LibFdtSupport.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/Library/BaseFdtLib/string.h
> > > >>>>>>>>>> b/MdePkg/Library/BaseFdtLib/string.h
> > > >>>>>>>>>> new file mode 100644
> > > >>>>>>>>>> index 0000000000..f6cf8d5702
> > > >>>>>>>>>> --- /dev/null
> > > >>>>>>>>>> +++ b/MdePkg/Library/BaseFdtLib/string.h
> > > >>>>>>>>>> @@ -0,0 +1,10 @@
> > > >>>>>>>>>> +/** @file
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  Include file to support building the third-party libfdt library.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +**/
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> +#include <LibFdtSupport.h>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/MdePkg.ci.yaml
> > b/MdePkg/MdePkg.ci.yaml
> > > >>> index
> > > >>>>>>>>>> 6ba85ebe61..f039daccdb 100644
> > > >>>>>>>>>> --- a/MdePkg/MdePkg.ci.yaml
> > > >>>>>>>>>> +++ b/MdePkg/MdePkg.ci.yaml
> > > >>>>>>>>>> @@ -2,7 +2,7 @@
> > > >>>>>>>>>>   # CI configuration for MdePkg
> > > >>>>>>>>>>
> > > >>>>>>>>>>   #
> > > >>>>>>>>>>
> > > >>>>>>>>>>   # Copyright (c) Microsoft Corporation
> > > >>>>>>>>>>
> > > >>>>>>>>>> -# Copyright (c) 2020, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +# Copyright (c) 2023, Intel Corporation. All rights
> > reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>>   # Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>>   # Copyright (c) 2023, Loongson Technology Corporation
> > Limited.
> > > >> All
> > > >>>>>>>>>> rights reserved.<BR>
> > > >>>>>>>>>>
> > > >>>>>>>>>>   # SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >>>>>>>>>>
> > > >>>>>>>>>> @@ -67,7 +67,8 @@
> > > >>>>>>>>>>               "Include/Library/PcdLib.h",
> > > >>>>>>>>>>
> > > >>>>>>>>>>               "Include/Library/SafeIntLib.h",
> > > >>>>>>>>>>
> > > >>>>>>>>>>               "Include/Protocol/DebugSupport.h",
> > > >>>>>>>>>>
> > > >>>>>>>>>> -
> > > >> "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>> + "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> > > >>>>>>>>>>
> > > >>>>>>>>>> +            "Library/BaseFdtLib"
> > > >>>>>>>>>>
> > > >>>>>>>>>>           ]
> > > >>>>>>>>>>
> > > >>>>>>>>>>       },
> > > >>>>>>>>>>
> > > >>>>>>>>>>       ## options defined ci/Plugin/CompilerPlugin
> > > >>>>>>>>>>
> > > >>>>>>>>>> @@ -164,5 +165,17 @@
> > > >>>>>>>>>>           "ExtendWords": [],           # words to extend to the
> > dictionary
> > > >> for
> > > >>> this package
> > > >>>>>>>>>>
> > > >>>>>>>>>>           "IgnoreStandardPaths": [],   # Standard Plugin defined
> > paths
> > > >> that
> > > >>> should be ignore
> > > >>>>>>>>>>
> > > >>>>>>>>>>           "AdditionalIncludePaths": [] # Additional paths to spell
> > > >>>>>>>>>> check (wildcards supported)
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    },
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    # options defined in .pytool/Plugin/UncrustifyCheck
> > > >>>>>>>>>>
> > > >>>>>>>>>> +    "UncrustifyCheck": {
> > > >>>>>>>>>>
> > > >>>>>>>>>> +        "IgnoreFiles": [
> > > >>>>>>>>>>
> > > >>>>>>>>>> +            "Library/BaseFdtLib/libfdt",
> > > >>>>>>>>>>
> > > >>>>>>>>>> +            "Library/BaseFdtLib/limits.h",
> > > >>>>>>>>>>
> > > >>>>>>>>>> +            "Library/BaseFdtLib/stdbool.h",
> > > >>>>>>>>>>
> > > >>>>>>>>>> +            "Library/BaseFdtLib/stddef.h",
> > > >>>>>>>>>>
> > > >>>>>>>>>> +            "Library/BaseFdtLib/stdint.h",
> > > >>>>>>>>>>
> > > >>>>>>>>>> +            "Library/BaseFdtLib/stdlib.h",
> > > >>>>>>>>>>
> > > >>>>>>>>>> +            "Library/BaseFdtLib/string.h"
> > > >>>>>>>>>>
> > > >>>>>>>>>> +        ]
> > > >>>>>>>>>>
> > > >>>>>>>>>>       }
> > > >>>>>>>>>>
> > > >>>>>>>>>>   }
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> > > >>>>>>>>>> e70182bf7f..9804a7a6bd 100644
> > > >>>>>>>>>> --- a/MdePkg/MdePkg.dec
> > > >>>>>>>>>> +++ b/MdePkg/MdePkg.dec
> > > >>>>>>>>>> @@ -289,6 +289,10 @@
> > > >>>>>>>>>>     #
> > > >>>>>>>>>>
> > > >>>>>>>>>>     ArmTrngLib|Include/Library/ArmTrngLib.h
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  ##  @libraryclass  Provides APIs for third-party library libfdt.
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  #
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  FdtLib|Include/Library/FdtLib.h
> > > >>>>>>>>>>
> > > >>>>>>>>>> +
> > > >>>>>>>>>>
> > > >>>>>>>>>>   [LibraryClasses.IA32, LibraryClasses.X64,
> > LibraryClasses.AARCH64]
> > > >>>>>>>>>>
> > > >>>>>>>>>>     ##  @libraryclass  Provides services to generate random
> > number.
> > > >>>>>>>>>>
> > > >>>>>>>>>>     #
> > > >>>>>>>>>>
> > > >>>>>>>>>> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index
> > > >>>>>>>>>> 152c02991a..b38c863812 100644
> > > >>>>>>>>>> --- a/MdePkg/MdePkg.dsc
> > > >>>>>>>>>> +++ b/MdePkg/MdePkg.dsc
> > > >>>>>>>>>> @@ -137,6 +137,7 @@
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>
> > MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>>     MdePkg/Library/JedecJep106Lib/JedecJep106Lib.inf
> > > >>>>>>>>>>
> > > >>>>>>>>>> +  MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>>   [Components.IA32, Components.X64, Components.ARM,
> > > >>>>>>>>>> Components.AARCH64]
> > > >>>>>>>>>>
> > > >>>>>>>>>>     #
> > > >>>>>>>>>>
> > > >>>>>>>>>> --
> > > >>>>>>>>>> 2.39.1.windows.1
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > > 
> > >


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2023-05-03 18:33 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-17  5:35 [PATCH v3 0/3] Support FDT library Benny Lin
2023-04-17  5:35 ` [PATCH v3 1/3] Tianocore: " Benny Lin
2023-04-19 15:58   ` Michael D Kinney
2023-04-17  5:35 ` [PATCH v3 2/3] MdePkg: " Benny Lin
2023-04-19 15:54   ` Michael D Kinney
2023-04-19 17:11     ` Benny Lin
2023-04-19 21:04       ` Michael D Kinney
2023-04-20  4:25         ` Benny Lin
2023-04-20 16:44           ` Michael D Kinney
2023-04-21  2:33             ` [edk2-devel] " Chiu, Chasel
2023-04-24 17:28             ` Leif Lindholm
2023-04-24 17:41               ` Michael D Kinney
2023-04-26  5:21                 ` Chiu, Chasel
     [not found]                 ` <17596494A9010E70.30288@groups.io>
2023-05-01 16:31                   ` Chiu, Chasel
2023-05-02 11:41                     ` Leif Lindholm
2023-05-03  2:34                       ` Chiu, Chasel
2023-05-03  5:39                         ` Michael D Kinney
2023-05-03 18:31                           ` Chiu, Chasel
2023-04-17  5:35 ` [PATCH v3 3/3] .pytool: " Benny Lin
2023-04-19 15:58   ` Michael D Kinney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox