* [PATCH 0/2] Support FDT library.
@ 2023-03-30 16:52 benny.lin
2023-03-30 16:52 ` [PATCH 1/2] MdePkg: " Benny Lin
` (3 more replies)
0 siblings, 4 replies; 23+ messages in thread
From: benny.lin @ 2023-03-30 16:52 UTC (permalink / raw)
To: devel
Cc: Benny Lin, Michael D Kinney, Liming Gao, Zhiguang Liu,
Sean Brogan, Michael Kubacki
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)
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>
Signed-off-by: Benny Lin <benny.lin@intel.com>
Benny Lin (2):
MdePkg: Support FDT library.
.pytool: Support FDT library.
.gitmodules | 3 +
.pytool/CISettings.py | 2 +
MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
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 | 2 +
ReadMe.rst | 1 +
19 files changed, 988 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] 23+ messages in thread
* [PATCH 1/2] MdePkg: Support FDT library.
2023-03-30 16:52 [PATCH 0/2] Support FDT library benny.lin
@ 2023-03-30 16:52 ` Benny Lin
2023-03-30 17:01 ` Michael D Kinney
2023-03-30 23:19 ` [edk2-devel] " Pedro Falcato
2023-03-30 16:52 ` [PATCH 2/2] .pytool: " Benny Lin
` (2 subsequent siblings)
3 siblings, 2 replies; 23+ messages in thread
From: Benny Lin @ 2023-03-30 16:52 UTC (permalink / raw)
To: devel; +Cc: Benny Lin, Michael D Kinney, Liming Gao, Zhiguang Liu
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)
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Benny Lin <benny.lin@intel.com>
---
.gitmodules | 3 +
MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
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 | 2 +
ReadMe.rst | 1 +
18 files changed, 986 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
diff --git a/.gitmodules b/.gitmodules
index 8011a88d9d..5da342e90c 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -23,3 +23,6 @@
[submodule "UnitTestFrameworkPkg/Library/GoogleTestLib/googletest"]
path = UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
url = https://github.com/google/googletest.git
+[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
+ path = MdePkg/Library/BaseFdtLib/libfdt
+ url = https://github.com/devicetree-org/pylibfdt.git
diff --git a/MdePkg/Include/Library/FdtLib.h b/MdePkg/Include/Library/FdtLib.h
new file mode 100644
index 0000000000..bcb097b77e
--- /dev/null
+++ b/MdePkg/Include/Library/FdtLib.h
@@ -0,0 +1,300 @@
+/** @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) FDT32_TO_CPU(((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))
+
+/**
+ 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 porperty 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..ba9a284e58
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
@@ -0,0 +1,284 @@
+/** @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>
+
+/**
+ 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 porperty 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..58b0bb403e
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
@@ -0,0 +1,102 @@
+/** @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
+//
+#ifndef INT_MAX
+#define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */
+#endif
+#define INT32_MAX 0x7FFFFFFF /* Maximum (signed) int32 value */
+#define UINT32_MAX 0xFFFFFFFF /* Maximum unsigned int32 value */
+#define MAX_STRING_SIZE 0x1000
+
+//
+// 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..3f1cc69dc6
--- /dev/null
+++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
@@ -0,0 +1,138 @@
+/** @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
+
+**/
+
+#include "LibFdtSupport.h"
+#include <Library/DebugLib.h>
+
+/**
+ Returns the first occurrence of a Null-terminated ASCII character
+ in a Null-terminated ASCII string.
+
+ This function scans the contents of the ASCII string specified by s
+ and returns the first occurrence of c. If c is not found in s,
+ then NULL is returned. If the length of c is zero, then s is returned.
+
+ @param s The pointer to a Null-terminated ASCII string.
+ @param c The pointer to a Null-terminated ASCII character to search for.
+
+ @retval NULL If the c does not appear in s.
+ @retval others If there is a match return the first occurrence of c.
+ If the length of c is zero,return s.
+
+**/
+char *
+strchr (
+ const char *s,
+ int c
+ )
+{
+ char pattern[2];
+
+ pattern[0] = (CHAR8)c;
+ pattern[1] = 0;
+ return AsciiStrStr (s, pattern);
+}
+
+/**
+ Returns the last occurrence of a Null-terminated ASCII character
+ in a Null-terminated ASCII string.
+
+ This function scans the contents of the ASCII string specified by s
+ and returns the last occurrence of c. If c is not found in s,
+ then NULL is returned. If the length of c is zero, then s is returned.
+
+ @param s The pointer to a Null-terminated ASCII string.
+ @param c The pointer to a Null-terminated ASCII character to search for.
+
+ @retval NULL If the c does not appear in s.
+ @retval others If there is a match return the last occurrence of c.
+ If the length of c is zero,return s.
+
+**/
+char *
+strrchr (
+ const char *s,
+ int c
+ )
+{
+ char pattern[2];
+ CONST CHAR8 *LastMatch;
+ CONST CHAR8 *StringTmp;
+ CONST CHAR8 *SearchString;
+
+ pattern[0] = (CHAR8)c;
+ pattern[1] = 0;
+ SearchString = pattern;
+
+ //
+ // Return NULL if both strings are less long than PcdMaximumAsciiStringLength
+ //
+ if ((AsciiStrSize (s) == 0) || (AsciiStrSize (SearchString) == 0)) {
+ return NULL;
+ }
+
+ if (*SearchString == '\0') {
+ return (CHAR8 *)s;
+ }
+
+ LastMatch = NULL;
+ do {
+ StringTmp = AsciiStrStr (s, SearchString);
+
+ if (StringTmp == NULL) {
+ break;
+ }
+
+ LastMatch = StringTmp;
+ s = StringTmp + 1;
+ } while (s != NULL);
+
+ return (CHAR8 *)LastMatch;
+}
+
+/**
+ Convert a Null-terminated Ascii decimal or hexadecimal string to a value of type UINTN.
+
+ This function outputs a value of type UINTN by interpreting the contents of
+ the Ascii string specified by String as a decimal or hexadecimal number.
+
+ @param nptr Pointer to a Null-terminated Ascii string.
+ @param endptr Pointer to character that stops scan.
+ @param base Pointer to decimal or hexadecimal.
+
+ @retval MAX_UINTN If nptr is NULL.
+ If endptr is NULL.
+ If base is not 10 or 16.
+ @retval others Value is translated from String.
+
+**/
+unsigned long
+strtoul (
+ const char *nptr,
+ char **endptr,
+ int base
+ )
+{
+ RETURN_STATUS Status;
+ UINTN ReturnValue;
+
+ if (base == 10) {
+ Status = AsciiStrDecimalToUintnS (nptr, endptr, &ReturnValue);
+ } else if (base == 16) {
+ Status = AsciiStrHexToUintnS (nptr, endptr, &ReturnValue);
+ } else {
+ Status = RETURN_INVALID_PARAMETER;
+ }
+
+ if (RETURN_ERROR (Status)) {
+ return MAX_UINTN;
+ }
+
+ return (unsigned long)ReturnValue;
+}
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/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 5cf04bc0cb..3ce7f28b6e 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -285,6 +285,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 0ac7618b46..b262068b67 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -136,6 +136,8 @@
MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf
MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
+ MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
+
[Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
#
# Add UEFI Target Based Unit Tests
diff --git a/ReadMe.rst b/ReadMe.rst
index 497d963559..00514c84ff 100644
--- a/ReadMe.rst
+++ b/ReadMe.rst
@@ -95,6 +95,7 @@ that are covered by additional licenses.
- `UnitTestFrameworkPkg/Library/CmockaLib/cmocka <https://github.com/tianocore/edk2-cmocka/blob/f5e2cd77c88d9f792562888d2b70c5a396bfbf7a/COPYING>`__
- `UnitTestFrameworkPkg/Library/GoogleTestLib/googletest <https://github.com/google/googletest/blob/86add13493e5c881d7e4ba77fb91c1f57752b3a4/LICENSE>`__
- `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] 23+ messages in thread
* [PATCH 2/2] .pytool: Support FDT library.
2023-03-30 16:52 [PATCH 0/2] Support FDT library benny.lin
2023-03-30 16:52 ` [PATCH 1/2] MdePkg: " Benny Lin
@ 2023-03-30 16:52 ` Benny Lin
2023-03-30 21:50 ` [edk2-devel] [PATCH 0/2] " Pedro Falcato
2023-04-01 1:29 ` Andrei Warkentin
3 siblings, 0 replies; 23+ messages in thread
From: Benny Lin @ 2023-03-30 16:52 UTC (permalink / raw)
To: devel; +Cc: Benny Lin, Sean Brogan, Michael Kubacki, Michael D Kinney,
Liming Gao
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 d87c8e838e..126c9f0164 100644
--- a/.pytool/CISettings.py
+++ b/.pytool/CISettings.py
@@ -193,6 +193,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
"BaseTools/Source/C/BrotliCompress/brotli", False))
rs.append(RequiredSubmodule(
"RedfishPkg/Library/JsonLib/jansson", 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] 23+ messages in thread
* Re: [PATCH 1/2] MdePkg: Support FDT library.
2023-03-30 16:52 ` [PATCH 1/2] MdePkg: " Benny Lin
@ 2023-03-30 17:01 ` Michael D Kinney
2023-03-30 23:19 ` [edk2-devel] " Pedro Falcato
1 sibling, 0 replies; 23+ messages in thread
From: Michael D Kinney @ 2023-03-30 17:01 UTC (permalink / raw)
To: Lin, Benny, devel@edk2.groups.io
Cc: Gao, Liming, Liu, Zhiguang, Leif Lindholm,
Andrew Fish (afish@apple.com), Kinney, Michael D
+Leif
+Andrew
For .gitmodules and ReadMe.rst changes
Mike
> -----Original Message-----
> From: Lin, Benny <benny.lin@intel.com>
> Sent: Thursday, March 30, 2023 9:52 AM
> 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>
> Subject: [PATCH 1/2] MdePkg: Support FDT library.
>
> 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)
>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> Signed-off-by: Benny Lin <benny.lin@intel.com>
> ---
> .gitmodules | 3 +
> MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
> MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
> MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
> MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
> 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 | 2 +
> ReadMe.rst | 1 +
> 18 files changed, 986 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
>
> diff --git a/.gitmodules b/.gitmodules
> index 8011a88d9d..5da342e90c 100644
> --- a/.gitmodules
> +++ b/.gitmodules
> @@ -23,3 +23,6 @@
> [submodule "UnitTestFrameworkPkg/Library/GoogleTestLib/googletest"]
> path = UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
> url = https://github.com/google/googletest.git
> +[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
> + path = MdePkg/Library/BaseFdtLib/libfdt
> + url = https://github.com/devicetree-org/pylibfdt.git
> diff --git a/MdePkg/Include/Library/FdtLib.h b/MdePkg/Include/Library/FdtLib.h
> new file mode 100644
> index 0000000000..bcb097b77e
> --- /dev/null
> +++ b/MdePkg/Include/Library/FdtLib.h
> @@ -0,0 +1,300 @@
> +/** @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) FDT32_TO_CPU(((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))
>
> +
>
> +/**
>
> + 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 porperty 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..ba9a284e58
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> @@ -0,0 +1,284 @@
> +/** @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>
>
> +
>
> +/**
>
> + 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 porperty 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..58b0bb403e
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> @@ -0,0 +1,102 @@
> +/** @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
>
> +//
>
> +#ifndef INT_MAX
>
> +#define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */
>
> +#endif
>
> +#define INT32_MAX 0x7FFFFFFF /* Maximum (signed) int32 value */
>
> +#define UINT32_MAX 0xFFFFFFFF /* Maximum unsigned int32 value */
>
> +#define MAX_STRING_SIZE 0x1000
>
> +
>
> +//
>
> +// 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..3f1cc69dc6
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> @@ -0,0 +1,138 @@
> +/** @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
>
> +
>
> +**/
>
> +
>
> +#include "LibFdtSupport.h"
>
> +#include <Library/DebugLib.h>
>
> +
>
> +/**
>
> + Returns the first occurrence of a Null-terminated ASCII character
>
> + in a Null-terminated ASCII string.
>
> +
>
> + This function scans the contents of the ASCII string specified by s
>
> + and returns the first occurrence of c. If c is not found in s,
>
> + then NULL is returned. If the length of c is zero, then s is returned.
>
> +
>
> + @param s The pointer to a Null-terminated ASCII string.
>
> + @param c The pointer to a Null-terminated ASCII character to search for.
>
> +
>
> + @retval NULL If the c does not appear in s.
>
> + @retval others If there is a match return the first occurrence of c.
>
> + If the length of c is zero,return s.
>
> +
>
> +**/
>
> +char *
>
> +strchr (
>
> + const char *s,
>
> + int c
>
> + )
>
> +{
>
> + char pattern[2];
>
> +
>
> + pattern[0] = (CHAR8)c;
>
> + pattern[1] = 0;
>
> + return AsciiStrStr (s, pattern);
>
> +}
>
> +
>
> +/**
>
> + Returns the last occurrence of a Null-terminated ASCII character
>
> + in a Null-terminated ASCII string.
>
> +
>
> + This function scans the contents of the ASCII string specified by s
>
> + and returns the last occurrence of c. If c is not found in s,
>
> + then NULL is returned. If the length of c is zero, then s is returned.
>
> +
>
> + @param s The pointer to a Null-terminated ASCII string.
>
> + @param c The pointer to a Null-terminated ASCII character to search for.
>
> +
>
> + @retval NULL If the c does not appear in s.
>
> + @retval others If there is a match return the last occurrence of c.
>
> + If the length of c is zero,return s.
>
> +
>
> +**/
>
> +char *
>
> +strrchr (
>
> + const char *s,
>
> + int c
>
> + )
>
> +{
>
> + char pattern[2];
>
> + CONST CHAR8 *LastMatch;
>
> + CONST CHAR8 *StringTmp;
>
> + CONST CHAR8 *SearchString;
>
> +
>
> + pattern[0] = (CHAR8)c;
>
> + pattern[1] = 0;
>
> + SearchString = pattern;
>
> +
>
> + //
>
> + // Return NULL if both strings are less long than PcdMaximumAsciiStringLength
>
> + //
>
> + if ((AsciiStrSize (s) == 0) || (AsciiStrSize (SearchString) == 0)) {
>
> + return NULL;
>
> + }
>
> +
>
> + if (*SearchString == '\0') {
>
> + return (CHAR8 *)s;
>
> + }
>
> +
>
> + LastMatch = NULL;
>
> + do {
>
> + StringTmp = AsciiStrStr (s, SearchString);
>
> +
>
> + if (StringTmp == NULL) {
>
> + break;
>
> + }
>
> +
>
> + LastMatch = StringTmp;
>
> + s = StringTmp + 1;
>
> + } while (s != NULL);
>
> +
>
> + return (CHAR8 *)LastMatch;
>
> +}
>
> +
>
> +/**
>
> + Convert a Null-terminated Ascii decimal or hexadecimal string to a value of type UINTN.
>
> +
>
> + This function outputs a value of type UINTN by interpreting the contents of
>
> + the Ascii string specified by String as a decimal or hexadecimal number.
>
> +
>
> + @param nptr Pointer to a Null-terminated Ascii string.
>
> + @param endptr Pointer to character that stops scan.
>
> + @param base Pointer to decimal or hexadecimal.
>
> +
>
> + @retval MAX_UINTN If nptr is NULL.
>
> + If endptr is NULL.
>
> + If base is not 10 or 16.
>
> + @retval others Value is translated from String.
>
> +
>
> +**/
>
> +unsigned long
>
> +strtoul (
>
> + const char *nptr,
>
> + char **endptr,
>
> + int base
>
> + )
>
> +{
>
> + RETURN_STATUS Status;
>
> + UINTN ReturnValue;
>
> +
>
> + if (base == 10) {
>
> + Status = AsciiStrDecimalToUintnS (nptr, endptr, &ReturnValue);
>
> + } else if (base == 16) {
>
> + Status = AsciiStrHexToUintnS (nptr, endptr, &ReturnValue);
>
> + } else {
>
> + Status = RETURN_INVALID_PARAMETER;
>
> + }
>
> +
>
> + if (RETURN_ERROR (Status)) {
>
> + return MAX_UINTN;
>
> + }
>
> +
>
> + return (unsigned long)ReturnValue;
>
> +}
>
> 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/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 5cf04bc0cb..3ce7f28b6e 100644
> --- a/MdePkg/MdePkg.dec
> +++ b/MdePkg/MdePkg.dec
> @@ -285,6 +285,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 0ac7618b46..b262068b67 100644
> --- a/MdePkg/MdePkg.dsc
> +++ b/MdePkg/MdePkg.dsc
> @@ -136,6 +136,8 @@
> MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf
>
> MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
>
>
>
> + MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
>
> +
>
> [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
>
> #
>
> # Add UEFI Target Based Unit Tests
>
> diff --git a/ReadMe.rst b/ReadMe.rst
> index 497d963559..00514c84ff 100644
> --- a/ReadMe.rst
> +++ b/ReadMe.rst
> @@ -95,6 +95,7 @@ that are covered by additional licenses.
> - `UnitTestFrameworkPkg/Library/CmockaLib/cmocka <https://github.com/tianocore/edk2-
> cmocka/blob/f5e2cd77c88d9f792562888d2b70c5a396bfbf7a/COPYING>`__
>
> - `UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
> <https://github.com/google/googletest/blob/86add13493e5c881d7e4ba77fb91c1f57752b3a4/LICENSE>`__
>
> - `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] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-30 16:52 [PATCH 0/2] Support FDT library benny.lin
2023-03-30 16:52 ` [PATCH 1/2] MdePkg: " Benny Lin
2023-03-30 16:52 ` [PATCH 2/2] .pytool: " Benny Lin
@ 2023-03-30 21:50 ` Pedro Falcato
2023-03-30 22:59 ` Michael D Kinney
2023-03-31 12:12 ` Leif Lindholm
2023-04-01 1:29 ` Andrei Warkentin
3 siblings, 2 replies; 23+ messages in thread
From: Pedro Falcato @ 2023-03-30 21:50 UTC (permalink / raw)
To: devel, benny.lin
Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Sean Brogan,
Michael Kubacki
On Thu, Mar 30, 2023 at 6:13 PM Benny Lin <benny.lin@intel.com> wrote:
>
> 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)
>
> 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>
> Signed-off-by: Benny Lin <benny.lin@intel.com>
>
> Benny Lin (2):
> MdePkg: Support FDT library.
> .pytool: Support FDT library.
>
> .gitmodules | 3 +
> .pytool/CISettings.py | 2 +
> MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
> MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
> MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
> MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
> 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 | 2 +
> ReadMe.rst | 1 +
> 19 files changed, 988 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
There's already a copy of libfdt plus "FdtLib" at
https://github.com/tianocore/edk2/tree/master/EmbeddedPkg/Library/FdtLib.
Please figure out what to do with it.
It's an old copy and has been accidentally uncrustify'd so it's
probably a good idea to at least ditch that specific copy for a git
submodule.
Also, NAK to Yet Another libc Implementation (and not a particularly
good one at that).
--
Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-30 21:50 ` [edk2-devel] [PATCH 0/2] " Pedro Falcato
@ 2023-03-30 22:59 ` Michael D Kinney
2023-03-30 23:26 ` Pedro Falcato
2023-03-31 12:12 ` Leif Lindholm
1 sibling, 1 reply; 23+ messages in thread
From: Michael D Kinney @ 2023-03-30 22:59 UTC (permalink / raw)
To: devel@edk2.groups.io, pedro.falcato@gmail.com, Lin, Benny
Cc: Gao, Liming, Liu, Zhiguang, Sean Brogan, Michael Kubacki,
Leif Lindholm, Kinney, Michael D
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Pedro Falcato
> Sent: Thursday, March 30, 2023 2:50 PM
> To: devel@edk2.groups.io; Lin, Benny <benny.lin@intel.com>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu@intel.com>; Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>
> Subject: Re: [edk2-devel] [PATCH 0/2] Support FDT library.
>
> On Thu, Mar 30, 2023 at 6:13 PM Benny Lin <benny.lin@intel.com> wrote:
> >
> > 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)
> >
> > 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>
> > Signed-off-by: Benny Lin <benny.lin@intel.com>
> >
> > Benny Lin (2):
> > MdePkg: Support FDT library.
> > .pytool: Support FDT library.
> >
> > .gitmodules | 3 +
> > .pytool/CISettings.py | 2 +
> > MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
> > MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
> > MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
> > MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
> > MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
> > MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
> > 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 | 2 +
> > ReadMe.rst | 1 +
> > 19 files changed, 988 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
>
> There's already a copy of libfdt plus "FdtLib" at
> https://github.com/tianocore/edk2/tree/master/EmbeddedPkg/Library/FdtLib.
> Please figure out what to do with it.
> It's an old copy and has been accidentally uncrustify'd so it's
> probably a good idea to at least ditch that specific copy for a git
> submodule.
I have discussed this overlap with Leif. After this patch series is
added, the EmbeddedPkg maintainers can convert that package to use
this lib and delete the duplicate sources.
>
> Also, NAK to Yet Another libc Implementation (and not a particularly
> good one at that).
Please provide constructive feedback on what is not good about this specific libc
Implementation so that appropriate code updates could be made for this patch series.
This is following the same pattern as other libs that are consuming a submodule
that requires some amount of libc support.
Getting down to one libc wrapper would be great. Do you want to provide a proposed
implementation? That could be handled as a separate task.
>
> --
> Pedro
>
>
>
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 1/2] MdePkg: Support FDT library.
2023-03-30 16:52 ` [PATCH 1/2] MdePkg: " Benny Lin
2023-03-30 17:01 ` Michael D Kinney
@ 2023-03-30 23:19 ` Pedro Falcato
2023-04-12 16:59 ` Benny Lin
1 sibling, 1 reply; 23+ messages in thread
From: Pedro Falcato @ 2023-03-30 23:19 UTC (permalink / raw)
To: devel, benny.lin; +Cc: Michael D Kinney, Liming Gao, Zhiguang Liu
On Thu, Mar 30, 2023 at 6:13 PM Benny Lin <benny.lin@intel.com> wrote:
>
> 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)
>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> Signed-off-by: Benny Lin <benny.lin@intel.com>
> ---
> .gitmodules | 3 +
> MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
> MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
> MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
> MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
> 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 | 2 +
> ReadMe.rst | 1 +
> 18 files changed, 986 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
>
> diff --git a/.gitmodules b/.gitmodules
> index 8011a88d9d..5da342e90c 100644
> --- a/.gitmodules
> +++ b/.gitmodules
> @@ -23,3 +23,6 @@
> [submodule "UnitTestFrameworkPkg/Library/GoogleTestLib/googletest"]
> path = UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
> url = https://github.com/google/googletest.git
> +[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
> + path = MdePkg/Library/BaseFdtLib/libfdt
> + url = https://github.com/devicetree-org/pylibfdt.git
> diff --git a/MdePkg/Include/Library/FdtLib.h b/MdePkg/Include/Library/FdtLib.h
> new file mode 100644
> index 0000000000..bcb097b77e
> --- /dev/null
> +++ b/MdePkg/Include/Library/FdtLib.h
> @@ -0,0 +1,300 @@
> +/** @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) FDT32_TO_CPU(((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))
> +
> +/**
> + 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 porperty 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_ */
What's the point of all these wrappers if we end up immediately
redirecting to libfdt?
> 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..ba9a284e58
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
> @@ -0,0 +1,284 @@
> +/** @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>
> +
> +/**
> + 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 porperty in the given node.
*property
> +
> + @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..58b0bb403e
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
> @@ -0,0 +1,102 @@
> +/** @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
> +//
> +#ifndef INT_MAX
> +#define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */
> +#endif
Why the ifndef here?
> +#define INT32_MAX 0x7FFFFFFF /* Maximum (signed) int32 value */
> +#define UINT32_MAX 0xFFFFFFFF /* Maximum unsigned int32 value */
> +#define MAX_STRING_SIZE 0x1000
Why the arbitrary MAX_STRING_SIZE here?
> +
> +//
> +// 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..3f1cc69dc6
> --- /dev/null
> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
> @@ -0,0 +1,138 @@
> +/** @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
> +
> +**/
> +
> +#include "LibFdtSupport.h"
> +#include <Library/DebugLib.h>
Why are we pulling DebugLib? I don't see where this should be needed.
> +
> +/**
> + Returns the first occurrence of a Null-terminated ASCII character
> + in a Null-terminated ASCII string.
> +
> + This function scans the contents of the ASCII string specified by s
> + and returns the first occurrence of c. If c is not found in s,
> + then NULL is returned. If the length of c is zero, then s is returned.
> +
> + @param s The pointer to a Null-terminated ASCII string.
> + @param c The pointer to a Null-terminated ASCII character to search for.
> +
> + @retval NULL If the c does not appear in s.
> + @retval others If there is a match return the first occurrence of c.
> + If the length of c is zero,return s.
The doxygen for strchr and strrchr is very wrong and is not ISO C (nor
GNU C nor any other brand of C) compliant. Please refer to a
Linux/macOS/BSD manpage or to an ISO C standard draft.
> +
> +**/
> +char *
> +strchr (
> + const char *s,
> + int c
> + )
> +{
> + char pattern[2];
> +
> + pattern[0] = (CHAR8)c;
> + pattern[1] = 0;
> + return AsciiStrStr (s, pattern);
> +}
> +
> +/**
> + Returns the last occurrence of a Null-terminated ASCII character
> + in a Null-terminated ASCII string.
> +
> + This function scans the contents of the ASCII string specified by s
> + and returns the last occurrence of c. If c is not found in s,
> + then NULL is returned. If the length of c is zero, then s is returned.
> +
> + @param s The pointer to a Null-terminated ASCII string.
> + @param c The pointer to a Null-terminated ASCII character to search for.
> +
> + @retval NULL If the c does not appear in s.
> + @retval others If there is a match return the last occurrence of c.
> + If the length of c is zero,return s.
> +
> +**/
> +char *
> +strrchr (
> + const char *s,
> + int c
> + )
> +{
> + char pattern[2];
> + CONST CHAR8 *LastMatch;
> + CONST CHAR8 *StringTmp;
> + CONST CHAR8 *SearchString;
> +
> + pattern[0] = (CHAR8)c;
> + pattern[1] = 0;
> + SearchString = pattern;
> +
> + //
> + // Return NULL if both strings are less long than PcdMaximumAsciiStringLength
> + //
> + if ((AsciiStrSize (s) == 0) || (AsciiStrSize (SearchString) == 0)) {
> + return NULL;
> + }
> +
> + if (*SearchString == '\0') {
> + return (CHAR8 *)s;
> + }
> +
> + LastMatch = NULL;
> + do {
> + StringTmp = AsciiStrStr (s, SearchString);
> +
> + if (StringTmp == NULL) {
> + break;
> + }
> +
> + LastMatch = StringTmp;
> + s = StringTmp + 1;
> + } while (s != NULL);
> +
> + return (CHAR8 *)LastMatch;
> +}
Better implementations I wrote very quickly, feel free to EFI-it,
public domain: https://gist.github.com/heatd/c1192f3f05148a6271be37fb3160b143
> +
> +/**
> + Convert a Null-terminated Ascii decimal or hexadecimal string to a value of type UINTN.
> +
> + This function outputs a value of type UINTN by interpreting the contents of
> + the Ascii string specified by String as a decimal or hexadecimal number.
> +
> + @param nptr Pointer to a Null-terminated Ascii string.
> + @param endptr Pointer to character that stops scan.
> + @param base Pointer to decimal or hexadecimal.
> +
> + @retval MAX_UINTN If nptr is NULL.
> + If endptr is NULL.
> + If base is not 10 or 16.
> + @retval others Value is translated from String.
> +
> +**/
> +unsigned long
> +strtoul (
> + const char *nptr,
> + char **endptr,
> + int base
> + )
> +{
> + RETURN_STATUS Status;
> + UINTN ReturnValue;
There's no equivalence between UINTN and unsigned long on x64 Windows
(where they use LLP64, so 32-bit longs, while UINTN should be 64-bit).
> +
> + if (base == 10) {
> + Status = AsciiStrDecimalToUintnS (nptr, endptr, &ReturnValue);
> + } else if (base == 16) {
> + Status = AsciiStrHexToUintnS (nptr, endptr, &ReturnValue);
> + } else {
> + Status = RETURN_INVALID_PARAMETER;
> + }
> +
> + if (RETURN_ERROR (Status)) {
> + return MAX_UINTN;
> + }
> +
> + return (unsigned long)ReturnValue;
> +}
Note that this is not ISO C compliant, but seems to work in the libfdt
case (as far as I can see, only a single strtoul call with base 10).
> 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/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>
If we want to be rigorous, strictly speaking, we should not pollute
the namespace. stdbool.h should only include the stdbool.h stuff (see
the ISO C spec), and the same applies for the other headers.
Although I *guess* it doesn't matter much here.
--
Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-30 22:59 ` Michael D Kinney
@ 2023-03-30 23:26 ` Pedro Falcato
2023-03-30 23:32 ` Michael D Kinney
` (2 more replies)
0 siblings, 3 replies; 23+ messages in thread
From: Pedro Falcato @ 2023-03-30 23:26 UTC (permalink / raw)
To: Kinney, Michael D
Cc: devel@edk2.groups.io, Lin, Benny, Gao, Liming, Liu, Zhiguang,
Sean Brogan, Michael Kubacki, Leif Lindholm
On Thu, Mar 30, 2023 at 11:59 PM Kinney, Michael D
<michael.d.kinney@intel.com> wrote:
>
>
>
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Pedro Falcato
> > Sent: Thursday, March 30, 2023 2:50 PM
> > To: devel@edk2.groups.io; Lin, Benny <benny.lin@intel.com>
> > Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > <zhiguang.liu@intel.com>; Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>
> > Subject: Re: [edk2-devel] [PATCH 0/2] Support FDT library.
> >
> > On Thu, Mar 30, 2023 at 6:13 PM Benny Lin <benny.lin@intel.com> wrote:
> > >
> > > 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)
> > >
> > > 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>
> > > Signed-off-by: Benny Lin <benny.lin@intel.com>
> > >
> > > Benny Lin (2):
> > > MdePkg: Support FDT library.
> > > .pytool: Support FDT library.
> > >
> > > .gitmodules | 3 +
> > > .pytool/CISettings.py | 2 +
> > > MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
> > > MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
> > > MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
> > > MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
> > > MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
> > > MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
> > > 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 | 2 +
> > > ReadMe.rst | 1 +
> > > 19 files changed, 988 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
> >
> > There's already a copy of libfdt plus "FdtLib" at
> > https://github.com/tianocore/edk2/tree/master/EmbeddedPkg/Library/FdtLib.
> > Please figure out what to do with it.
> > It's an old copy and has been accidentally uncrustify'd so it's
> > probably a good idea to at least ditch that specific copy for a git
> > submodule.
>
> I have discussed this overlap with Leif. After this patch series is
> added, the EmbeddedPkg maintainers can convert that package to use
> this lib and delete the duplicate sources.
Ok, SGTM.
>
> >
> > Also, NAK to Yet Another libc Implementation (and not a particularly
> > good one at that).
>
> Please provide constructive feedback on what is not good about this specific libc
> Implementation so that appropriate code updates could be made for this patch series.
Done.
> This is following the same pattern as other libs that are consuming a submodule
> that requires some amount of libc support.
>
> Getting down to one libc wrapper would be great. Do you want to provide a proposed
> implementation? That could be handled as a separate task.
I would like it if we could stop contributing to that problem. We very
much *know* there is a problem with both libc fragments and compiler
intrinsic fragments all over edk2.
A proper, correct C standard library is not trivial to implement
(hence the multiple problems I did find from a quick read of the
patch).
We also have a whole libc implementation in edk2-libc that seems to be
permanently gathering dust until Intel touches it for Python purposes
from time to time. So between crypto, libfdt, etc, could we try to
unify things here a bit?
Thanks,
Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-30 23:26 ` Pedro Falcato
@ 2023-03-30 23:32 ` Michael D Kinney
2023-03-31 2:35 ` Pedro Falcato
2023-03-31 11:39 ` Gerd Hoffmann
2023-03-31 12:17 ` Leif Lindholm
2 siblings, 1 reply; 23+ messages in thread
From: Michael D Kinney @ 2023-03-30 23:32 UTC (permalink / raw)
To: Pedro Falcato
Cc: devel@edk2.groups.io, Lin, Benny, Gao, Liming, Liu, Zhiguang,
Sean Brogan, Michael Kubacki, Leif Lindholm, Kinney, Michael D
> -----Original Message-----
> From: Pedro Falcato <pedro.falcato@gmail.com>
> Sent: Thursday, March 30, 2023 4:27 PM
> To: Kinney, Michael D <michael.d.kinney@intel.com>
> Cc: devel@edk2.groups.io; Lin, Benny <benny.lin@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu@intel.com>; Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>; Leif
> Lindholm <llindhol@qti.qualcomm.com>
> Subject: Re: [edk2-devel] [PATCH 0/2] Support FDT library.
>
> On Thu, Mar 30, 2023 at 11:59 PM Kinney, Michael D
> <michael.d.kinney@intel.com> wrote:
> >
> >
> >
> > > -----Original Message-----
> > > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Pedro Falcato
> > > Sent: Thursday, March 30, 2023 2:50 PM
> > > To: devel@edk2.groups.io; Lin, Benny <benny.lin@intel.com>
> > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> > > <zhiguang.liu@intel.com>; Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>
> > > Subject: Re: [edk2-devel] [PATCH 0/2] Support FDT library.
> > >
> > > On Thu, Mar 30, 2023 at 6:13 PM Benny Lin <benny.lin@intel.com> wrote:
> > > >
> > > > 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)
> > > >
> > > > 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>
> > > > Signed-off-by: Benny Lin <benny.lin@intel.com>
> > > >
> > > > Benny Lin (2):
> > > > MdePkg: Support FDT library.
> > > > .pytool: Support FDT library.
> > > >
> > > > .gitmodules | 3 +
> > > > .pytool/CISettings.py | 2 +
> > > > MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
> > > > MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
> > > > MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
> > > > MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
> > > > MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
> > > > MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
> > > > 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 | 2 +
> > > > ReadMe.rst | 1 +
> > > > 19 files changed, 988 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
> > >
> > > There's already a copy of libfdt plus "FdtLib" at
> > > https://github.com/tianocore/edk2/tree/master/EmbeddedPkg/Library/FdtLib.
> > > Please figure out what to do with it.
> > > It's an old copy and has been accidentally uncrustify'd so it's
> > > probably a good idea to at least ditch that specific copy for a git
> > > submodule.
> >
> > I have discussed this overlap with Leif. After this patch series is
> > added, the EmbeddedPkg maintainers can convert that package to use
> > this lib and delete the duplicate sources.
> Ok, SGTM.
> >
> > >
> > > Also, NAK to Yet Another libc Implementation (and not a particularly
> > > good one at that).
> >
> > Please provide constructive feedback on what is not good about this specific libc
> > Implementation so that appropriate code updates could be made for this patch series.
>
> Done.
> > This is following the same pattern as other libs that are consuming a submodule
> > that requires some amount of libc support.
> >
> > Getting down to one libc wrapper would be great. Do you want to provide a proposed
> > implementation? That could be handled as a separate task.
>
> I would like it if we could stop contributing to that problem. We very
> much *know* there is a problem with both libc fragments and compiler
> intrinsic fragments all over edk2.
> A proper, correct C standard library is not trivial to implement
> (hence the multiple problems I did find from a quick read of the
> patch).
Appreciate the feedback. Agree that any libc API that is implemented in a
wrapper should conform to the standard.
> We also have a whole libc implementation in edk2-libc that seems to be
> permanently gathering dust until Intel touches it for Python purposes
> from time to time. So between crypto, libfdt, etc, could we try to
> unify things here a bit?
edk2-libc to too large for FW components and it is out of date.
Would you like to volunteer to lead a design and implementation that
is right-sized for FW modules and could be the one wrapper that works
for all current use cases and could be extended in the future as
needed to support additional use cases? Don’t need all of libc. Just
enough to support the APIs used by the submodules used so far.
>
> Thanks,
> Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-30 23:32 ` Michael D Kinney
@ 2023-03-31 2:35 ` Pedro Falcato
0 siblings, 0 replies; 23+ messages in thread
From: Pedro Falcato @ 2023-03-31 2:35 UTC (permalink / raw)
To: Kinney, Michael D
Cc: devel@edk2.groups.io, Lin, Benny, Gao, Liming, Liu, Zhiguang,
Sean Brogan, Michael Kubacki, Leif Lindholm
On Fri, Mar 31, 2023 at 12:32 AM Kinney, Michael D
<michael.d.kinney@intel.com> wrote:
> Appreciate the feedback. Agree that any libc API that is implemented in a
> wrapper should conform to the standard.
>
> > We also have a whole libc implementation in edk2-libc that seems to be
> > permanently gathering dust until Intel touches it for Python purposes
> > from time to time. So between crypto, libfdt, etc, could we try to
> > unify things here a bit?
>
> edk2-libc to too large for FW components and it is out of date.
>
> Would you like to volunteer to lead a design and implementation that
> is right-sized for FW modules and could be the one wrapper that works
> for all current use cases and could be extended in the future as
> needed to support additional use cases? Don’t need all of libc. Just
> enough to support the APIs used by the submodules used so far.
>
Mike,
I wrote up a quick RFC patch for a bunch of libc bits that you needed
in this case (BaseFdtLib and libfdt).
It's very much a WIP and only supports GCC/clang. MSVC needs some
support when it comes to limits.h (because of LP64 vs Windows's
LLP64), but nothing too hard certainly.
See https://edk2.groups.io/g/devel/topic/rfc_patch_1_1_mdepkg_add_a/97965830?p=,,,20,0,0,0::recentpostdate/sticky,,,20,2,0,97965830,previd%3D1680229851681438282,nextid%3D1680190220621190228&previd=1680229851681438282&nextid=1680190220621190228
Comments welcome.
--
Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-30 23:26 ` Pedro Falcato
2023-03-30 23:32 ` Michael D Kinney
@ 2023-03-31 11:39 ` Gerd Hoffmann
2023-03-31 12:18 ` Pedro Falcato
2023-03-31 12:17 ` Leif Lindholm
2 siblings, 1 reply; 23+ messages in thread
From: Gerd Hoffmann @ 2023-03-31 11:39 UTC (permalink / raw)
To: devel, pedro.falcato
Cc: Kinney, Michael D, Lin, Benny, Gao, Liming, Liu, Zhiguang,
Sean Brogan, Michael Kubacki, Leif Lindholm
Hi,
> > Getting down to one libc wrapper would be great. Do you want to provide a proposed
> > implementation? That could be handled as a separate task.
>
> I would like it if we could stop contributing to that problem. We very
> much *know* there is a problem with both libc fragments and compiler
> intrinsic fragments all over edk2.
I'd suggest to start with what we already have in the tree. Which is
(not fully sure the list is actually complete):
- CryptoPkg/Library/Include/ carrying the bits needed to make openssl
compile, and
- CryptoPkg/Library/IntrinsicLib (again, for openssl, mostly IA32, some
X64) and,
- ArmPkg/Library/CompilerIntrinsicsLib (mostly ARM, some AARCH64).
Can we move that over to MdePkg so everyone can easily share it instead
of adding more copies of the same to the tree?
I have an old branch gathering dust doing that for the intrinsics, I can
try rebasing it to latest master next week ...
take care,
Gerd
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-30 21:50 ` [edk2-devel] [PATCH 0/2] " Pedro Falcato
2023-03-30 22:59 ` Michael D Kinney
@ 2023-03-31 12:12 ` Leif Lindholm
1 sibling, 0 replies; 23+ messages in thread
From: Leif Lindholm @ 2023-03-31 12:12 UTC (permalink / raw)
To: devel, pedro.falcato
Cc: benny.lin, Michael D Kinney, Liming Gao, Zhiguang Liu,
Sean Brogan, Michael Kubacki
On Thu, Mar 30, 2023 at 22:50:18 +0100, Pedro Falcato wrote:
> On Thu, Mar 30, 2023 at 6:13 PM Benny Lin <benny.lin@intel.com> wrote:
> >
> > 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)
> >
> > 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>
> > Signed-off-by: Benny Lin <benny.lin@intel.com>
> >
> > Benny Lin (2):
> > MdePkg: Support FDT library.
> > .pytool: Support FDT library.
> >
> > .gitmodules | 3 +
> > .pytool/CISettings.py | 2 +
> > MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
> > MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
> > MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
> > MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
> > MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
> > MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
> > 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 | 2 +
> > ReadMe.rst | 1 +
> > 19 files changed, 988 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
>
> There's already a copy of libfdt plus "FdtLib" at
> https://github.com/tianocore/edk2/tree/master/EmbeddedPkg/Library/FdtLib.
> Please figure out what to do with it.
Like much of EmbeddedPkg, it's a halfway-house minimal effort legacy thing.
As soon as the actively maintained platforms have moved away from it,
I will delete it.
> It's an old copy and has been accidentally uncrustify'd so it's
> probably a good idea to at least ditch that specific copy for a git
> submodule.
Yes, but a migration path for existing users is preferable to breaking
the world.
/
Leif
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-30 23:26 ` Pedro Falcato
2023-03-30 23:32 ` Michael D Kinney
2023-03-31 11:39 ` Gerd Hoffmann
@ 2023-03-31 12:17 ` Leif Lindholm
2 siblings, 0 replies; 23+ messages in thread
From: Leif Lindholm @ 2023-03-31 12:17 UTC (permalink / raw)
To: devel, pedro.falcato
Cc: Kinney, Michael D, Lin, Benny, Gao, Liming, Liu, Zhiguang,
Sean Brogan, Michael Kubacki, Leif Lindholm
On Fri, Mar 31, 2023 at 00:26:37 +0100, Pedro Falcato wrote:
> We also have a whole libc implementation in edk2-libc that seems to be
> permanently gathering dust until Intel touches it for Python purposes
> from time to time. So between crypto, libfdt, etc, could we try to
> unify things here a bit?
Personally, I'd quite like to nuke edk2-libc. The only effect I'm
seeing from it is that it keeps misleading people into believing it's
sensible to expect full POSIX compliance under UEFI, then embed those
expectations into their organisational workflows.
Meanwhile, it receives (next to) no security fixes.
/
Leif
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-31 11:39 ` Gerd Hoffmann
@ 2023-03-31 12:18 ` Pedro Falcato
0 siblings, 0 replies; 23+ messages in thread
From: Pedro Falcato @ 2023-03-31 12:18 UTC (permalink / raw)
To: Gerd Hoffmann
Cc: devel, Kinney, Michael D, Lin, Benny, Gao, Liming, Liu, Zhiguang,
Sean Brogan, Michael Kubacki, Leif Lindholm
On Fri, Mar 31, 2023 at 12:39 PM Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> Hi,
>
> > > Getting down to one libc wrapper would be great. Do you want to provide a proposed
> > > implementation? That could be handled as a separate task.
> >
> > I would like it if we could stop contributing to that problem. We very
> > much *know* there is a problem with both libc fragments and compiler
> > intrinsic fragments all over edk2.
>
> I'd suggest to start with what we already have in the tree. Which is
> (not fully sure the list is actually complete):
>
> - CryptoPkg/Library/Include/ carrying the bits needed to make openssl
> compile, and
> - CryptoPkg/Library/IntrinsicLib (again, for openssl, mostly IA32, some
> X64) and,
> - ArmPkg/Library/CompilerIntrinsicsLib (mostly ARM, some AARCH64).
>
> Can we move that over to MdePkg so everyone can easily share it instead
> of adding more copies of the same to the tree?
Yes please. The problem with starting with what's in the tree is that
it's very messy and sometimes of super dubious quality.
For instance, on CryptoPkg there's the same lack of rigour in the
headers and CrtWrapper.c that I would rather avoid, as to make this a
relatively proper thing
(did you know if OpenSSL strcpy's over 4KiB it silently fails?).
> I have an old branch gathering dust doing that for the intrinsics, I can
> try rebasing it to latest master next week ...
Yes please! I did think about bringing in compiler-rt from LLVM for
high quality relatively self-contained intrinsics a good while ago.
There's the open question that GCC and clang require intrinsics and a
very small set of libc string functions to properly generate code.
Could BaseTools implicitly link this in? If we do it correctly,
there's no reason why the binaries would grow beyond what it requires
from the intrinsics set.
And I actually did see problems with lacking memcpy when trying out
tree-wide GCC12/clang -ftrivial-auto-var-init...
Anyway, if you want help with this or want to sync up efforts, do ping
me off-list :)
--
Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-03-30 16:52 [PATCH 0/2] Support FDT library benny.lin
` (2 preceding siblings ...)
2023-03-30 21:50 ` [edk2-devel] [PATCH 0/2] " Pedro Falcato
@ 2023-04-01 1:29 ` Andrei Warkentin
2023-04-06 16:33 ` Sheng Lean Tan
3 siblings, 1 reply; 23+ messages in thread
From: Andrei Warkentin @ 2023-04-01 1:29 UTC (permalink / raw)
To: devel@edk2.groups.io, Lin, Benny
Cc: Kinney, Michael D, Gao, Liming, Liu, Zhiguang, Sean Brogan,
Michael Kubacki
How does this relate to the existing EmbeddedPkg/Library/FdtLib code? Is there a specific plan to move away from this in existing components?
I did look in the BZ (https://bugzilla.tianocore.org/show_bug.cgi?id=4392) but this doesn't seem to acknowledge that there is existing Fdt support in EmbeddedPkg.
A
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Benny
> Lin
> Sent: Thursday, March 30, 2023 11:52 AM
> 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>; Sean Brogan
> <sean.brogan@microsoft.com>; Michael Kubacki
> <mikuback@linux.microsoft.com>
> Subject: [edk2-devel] [PATCH 0/2] Support FDT library.
>
> 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)
>
> 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>
> Signed-off-by: Benny Lin <benny.lin@intel.com>
>
> Benny Lin (2):
> MdePkg: Support FDT library.
> .pytool: Support FDT library.
>
> .gitmodules | 3 +
> .pytool/CISettings.py | 2 +
> MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
> MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
> MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
> MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
> 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 | 2 +
> ReadMe.rst | 1 +
> 19 files changed, 988 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] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-04-01 1:29 ` Andrei Warkentin
@ 2023-04-06 16:33 ` Sheng Lean Tan
2023-04-07 13:23 ` Pedro Falcato
0 siblings, 1 reply; 23+ messages in thread
From: Sheng Lean Tan @ 2023-04-06 16:33 UTC (permalink / raw)
To: devel, andrei.warkentin
Cc: Lin, Benny, Kinney, Michael D, Gao, Liming, Liu, Zhiguang,
Sean Brogan, Michael Kubacki
[-- Attachment #1: Type: text/plain, Size: 4035 bytes --]
Thanks for the nice feedback Pedro, Gerd and Andrei! Yeah it seems like a
valid concern here as Mik mentioned on edk2-libc, and it seems to fits edk2
long term interest on this.
Can we file this as an issue in Bugzilla for tracking or something? Since
this will take some time to work on this as it involves a bigger
discussion, personally I think we could get this FDT patch in first
meanwhile, and also remove the FDT from Embedded Pkg as next step, per
discussion with Leif?
What do you think?
On Sat, 1 Apr 2023 at 03:30, Andrei Warkentin <andrei.warkentin@intel.com>
wrote:
> How does this relate to the existing EmbeddedPkg/Library/FdtLib code? Is
> there a specific plan to move away from this in existing components?
>
> I did look in the BZ (https://bugzilla.tianocore.org/show_bug.cgi?id=4392)
> but this doesn't seem to acknowledge that there is existing Fdt support in
> EmbeddedPkg.
>
> A
>
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Benny
> > Lin
> > Sent: Thursday, March 30, 2023 11:52 AM
> > 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>; Sean Brogan
> > <sean.brogan@microsoft.com>; Michael Kubacki
> > <mikuback@linux.microsoft.com>
> > Subject: [edk2-devel] [PATCH 0/2] Support FDT library.
> >
> > 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)
> >
> > 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>
> > Signed-off-by: Benny Lin <benny.lin@intel.com>
> >
> > Benny Lin (2):
> > MdePkg: Support FDT library.
> > .pytool: Support FDT library.
> >
> > .gitmodules | 3 +
> > .pytool/CISettings.py | 2 +
> > MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
> > MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
> > MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
> > MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
> > MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
> > MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
> > 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 | 2 +
> > ReadMe.rst | 1 +
> > 19 files changed, 988 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
> >
> >
> >
> >
> >
>
>
>
>
>
>
>
[-- Attachment #2: Type: text/html, Size: 6515 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-04-06 16:33 ` Sheng Lean Tan
@ 2023-04-07 13:23 ` Pedro Falcato
2023-04-07 22:35 ` Andrei Warkentin
0 siblings, 1 reply; 23+ messages in thread
From: Pedro Falcato @ 2023-04-07 13:23 UTC (permalink / raw)
To: devel, sheng.tan
Cc: andrei.warkentin, Lin, Benny, Kinney, Michael D, Gao, Liming,
Liu, Zhiguang, Sean Brogan, Michael Kubacki
On Thu, Apr 6, 2023 at 5:34 PM Sheng Lean Tan <sheng.tan@9elements.com> wrote:
>
> Thanks for the nice feedback Pedro, Gerd and Andrei! Yeah it seems like a valid concern here as Mik mentioned on edk2-libc, and it seems to fits edk2 long term interest on this.
> Can we file this as an issue in Bugzilla for tracking or something? Since this will take some time to work on this as it involves a bigger discussion, personally I think we could get this FDT patch in first meanwhile, and also remove the FDT from Embedded Pkg as next step, per discussion with Leif?
> What do you think?
I'm all for not merging this without a proper solution in that regard
(I even presented a quick RFC solution which wasn't tested by anyone
involved in this patch, yet).
But if there really is an urgent need for this lib, I'm O-K with
merging this given that all my concerns are addressed (minus libc
duplication).
--
Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-04-07 13:23 ` Pedro Falcato
@ 2023-04-07 22:35 ` Andrei Warkentin
2023-04-07 23:04 ` Michael D Kinney
0 siblings, 1 reply; 23+ messages in thread
From: Andrei Warkentin @ 2023-04-07 22:35 UTC (permalink / raw)
To: Pedro Falcato, devel@edk2.groups.io, Tan, Lean Sheng
Cc: Lin, Benny, Kinney, Michael D, Gao, Liming, Liu, Zhiguang,
Sean Brogan, Michael Kubacki
I think in general it would be nice to understand the long term picture of a change, esp. since there is already FDT support in EDK2 in various forms (with libraries and drivers depending on the existing FdtLib). So it would really of confusing to see another FDT library in MdePkg, without a clear reasoning for the work (this isn't reflected in the BZ) and a clear action plan to end up with just one FDT library in MdePkg in some identified time frame.
I do think FDT lib *does* belong in MdePkg, but it seems the shortest path to get there is to simply move the existing EmbeddedPkg one (and update all users). Subsequent cleanup can be incremental. And regardless, every existing FdtLib user ought to be updated to use the new one, so there need to be more patches (we're not just throwing the code over the wall, right?)
A
> -----Original Message-----
> From: Pedro Falcato <pedro.falcato@gmail.com>
> Sent: Friday, April 7, 2023 8:24 AM
> To: devel@edk2.groups.io; Tan, Lean Sheng <sheng.tan@9elements.com>
> Cc: Warkentin, Andrei <andrei.warkentin@intel.com>; 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>; Sean Brogan <sean.brogan@microsoft.com>;
> Michael Kubacki <mikuback@linux.microsoft.com>
> Subject: Re: [edk2-devel] [PATCH 0/2] Support FDT library.
>
> On Thu, Apr 6, 2023 at 5:34 PM Sheng Lean Tan
> <sheng.tan@9elements.com> wrote:
> >
> > Thanks for the nice feedback Pedro, Gerd and Andrei! Yeah it seems like a
> valid concern here as Mik mentioned on edk2-libc, and it seems to fits edk2
> long term interest on this.
> > Can we file this as an issue in Bugzilla for tracking or something? Since this
> will take some time to work on this as it involves a bigger discussion,
> personally I think we could get this FDT patch in first meanwhile, and also
> remove the FDT from Embedded Pkg as next step, per discussion with Leif?
> > What do you think?
>
> I'm all for not merging this without a proper solution in that regard (I even
> presented a quick RFC solution which wasn't tested by anyone involved in
> this patch, yet).
>
> But if there really is an urgent need for this lib, I'm O-K with merging this
> given that all my concerns are addressed (minus libc duplication).
>
> --
> Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-04-07 22:35 ` Andrei Warkentin
@ 2023-04-07 23:04 ` Michael D Kinney
2023-04-11 13:19 ` Sheng Lean Tan
0 siblings, 1 reply; 23+ messages in thread
From: Michael D Kinney @ 2023-04-07 23:04 UTC (permalink / raw)
To: Warkentin, Andrei, Pedro Falcato, devel@edk2.groups.io,
Tan, Lean Sheng
Cc: Lin, Benny, Gao, Liming, Liu, Zhiguang, Sean Brogan,
Michael Kubacki, Kinney, Michael D
The main advantage of the new lib is that it depends on a submodule for the FDT
content so we can easily move to new releases for bug fixes or features.
The FDT content in the EmbeddedPkg is a snap-shot of the code from a long time
ago. We have been discouraging that approach and trying to move to released
content from a well support submodule if one is available.
Once this new better supported version is accepted, we can then incrementally
remove the duplicate content with the existing consumers moving from use of
EmbeddedPkg version to the MdePkg version and finally the removal of the
duplicate content in the EmbeddedPkg.
Mike
> -----Original Message-----
> From: Warkentin, Andrei <andrei.warkentin@intel.com>
> Sent: Friday, April 7, 2023 3:36 PM
> To: Pedro Falcato <pedro.falcato@gmail.com>; devel@edk2.groups.io; Tan, Lean Sheng <sheng.tan@9elements.com>
> 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>; Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>
> Subject: RE: [edk2-devel] [PATCH 0/2] Support FDT library.
>
> I think in general it would be nice to understand the long term picture of a change, esp. since there is already FDT support in
> EDK2 in various forms (with libraries and drivers depending on the existing FdtLib). So it would really of confusing to see
> another FDT library in MdePkg, without a clear reasoning for the work (this isn't reflected in the BZ) and a clear action plan
> to end up with just one FDT library in MdePkg in some identified time frame.
>
> I do think FDT lib *does* belong in MdePkg, but it seems the shortest path to get there is to simply move the existing
> EmbeddedPkg one (and update all users). Subsequent cleanup can be incremental. And regardless, every existing FdtLib user ought
> to be updated to use the new one, so there need to be more patches (we're not just throwing the code over the wall, right?)
>
> A
>
> > -----Original Message-----
> > From: Pedro Falcato <pedro.falcato@gmail.com>
> > Sent: Friday, April 7, 2023 8:24 AM
> > To: devel@edk2.groups.io; Tan, Lean Sheng <sheng.tan@9elements.com>
> > Cc: Warkentin, Andrei <andrei.warkentin@intel.com>; 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>; Sean Brogan <sean.brogan@microsoft.com>;
> > Michael Kubacki <mikuback@linux.microsoft.com>
> > Subject: Re: [edk2-devel] [PATCH 0/2] Support FDT library.
> >
> > On Thu, Apr 6, 2023 at 5:34 PM Sheng Lean Tan
> > <sheng.tan@9elements.com> wrote:
> > >
> > > Thanks for the nice feedback Pedro, Gerd and Andrei! Yeah it seems like a
> > valid concern here as Mik mentioned on edk2-libc, and it seems to fits edk2
> > long term interest on this.
> > > Can we file this as an issue in Bugzilla for tracking or something? Since this
> > will take some time to work on this as it involves a bigger discussion,
> > personally I think we could get this FDT patch in first meanwhile, and also
> > remove the FDT from Embedded Pkg as next step, per discussion with Leif?
> > > What do you think?
> >
> > I'm all for not merging this without a proper solution in that regard (I even
> > presented a quick RFC solution which wasn't tested by anyone involved in
> > this patch, yet).
> >
> > But if there really is an urgent need for this lib, I'm O-K with merging this
> > given that all my concerns are addressed (minus libc duplication).
> >
> > --
> > Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-04-07 23:04 ` Michael D Kinney
@ 2023-04-11 13:19 ` Sheng Lean Tan
2023-04-11 16:07 ` Pedro Falcato
0 siblings, 1 reply; 23+ messages in thread
From: Sheng Lean Tan @ 2023-04-11 13:19 UTC (permalink / raw)
To: Kinney, Michael D
Cc: Warkentin, Andrei, Pedro Falcato, devel@edk2.groups.io,
Lin, Benny, Gao, Liming, Liu, Zhiguang, Sean Brogan,
Michael Kubacki
[-- Attachment #1: Type: text/plain, Size: 4764 bytes --]
Thanks Mike for the proposal layout!
It sounds good to me :)
*Hi Pedro,*
I went through the email chain again, basically these are 2 of your main
concerns (correct me if I'm wrong):
1. a good idea to at least ditch that specific copy (current FDT in
Embedded Pkg) for a git submodule.
2. Rework to remove/reduce libc Implementation as there is a problem with
both libc fragments and compiler intrinsic fragments all over edk2. Should
unify standards between crypto, libfdt, etc, could we try here
I guess Mike has provided a plan to answer your first question, and the 2nd
question would require a broader discussion with a few key owners.
So it seems like we could get the current patchset from Benny Lin in for
now? Any minor clean up needed for the current patch?
On Sat, 8 Apr 2023 at 01:04, Kinney, Michael D <michael.d.kinney@intel.com>
wrote:
> The main advantage of the new lib is that it depends on a submodule for
> the FDT
> content so we can easily move to new releases for bug fixes or features.
>
> The FDT content in the EmbeddedPkg is a snap-shot of the code from a long
> time
> ago. We have been discouraging that approach and trying to move to
> released
> content from a well support submodule if one is available.
>
> Once this new better supported version is accepted, we can then
> incrementally
> remove the duplicate content with the existing consumers moving from use of
> EmbeddedPkg version to the MdePkg version and finally the removal of the
> duplicate content in the EmbeddedPkg.
>
> Mike
>
> > -----Original Message-----
> > From: Warkentin, Andrei <andrei.warkentin@intel.com>
> > Sent: Friday, April 7, 2023 3:36 PM
> > To: Pedro Falcato <pedro.falcato@gmail.com>; devel@edk2.groups.io; Tan,
> Lean Sheng <sheng.tan@9elements.com>
> > 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>; Sean Brogan <
> sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>
> > Subject: RE: [edk2-devel] [PATCH 0/2] Support FDT library.
> >
> > I think in general it would be nice to understand the long term picture
> of a change, esp. since there is already FDT support in
> > EDK2 in various forms (with libraries and drivers depending on the
> existing FdtLib). So it would really of confusing to see
> > another FDT library in MdePkg, without a clear reasoning for the work
> (this isn't reflected in the BZ) and a clear action plan
> > to end up with just one FDT library in MdePkg in some identified time
> frame.
> >
> > I do think FDT lib *does* belong in MdePkg, but it seems the shortest
> path to get there is to simply move the existing
> > EmbeddedPkg one (and update all users). Subsequent cleanup can be
> incremental. And regardless, every existing FdtLib user ought
> > to be updated to use the new one, so there need to be more patches
> (we're not just throwing the code over the wall, right?)
> >
> > A
> >
> > > -----Original Message-----
> > > From: Pedro Falcato <pedro.falcato@gmail.com>
> > > Sent: Friday, April 7, 2023 8:24 AM
> > > To: devel@edk2.groups.io; Tan, Lean Sheng <sheng.tan@9elements.com>
> > > Cc: Warkentin, Andrei <andrei.warkentin@intel.com>; 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>; Sean Brogan <sean.brogan@microsoft.com>;
> > > Michael Kubacki <mikuback@linux.microsoft.com>
> > > Subject: Re: [edk2-devel] [PATCH 0/2] Support FDT library.
> > >
> > > On Thu, Apr 6, 2023 at 5:34 PM Sheng Lean Tan
> > > <sheng.tan@9elements.com> wrote:
> > > >
> > > > Thanks for the nice feedback Pedro, Gerd and Andrei! Yeah it seems
> like a
> > > valid concern here as Mik mentioned on edk2-libc, and it seems to fits
> edk2
> > > long term interest on this.
> > > > Can we file this as an issue in Bugzilla for tracking or something?
> Since this
> > > will take some time to work on this as it involves a bigger discussion,
> > > personally I think we could get this FDT patch in first meanwhile, and
> also
> > > remove the FDT from Embedded Pkg as next step, per discussion with
> Leif?
> > > > What do you think?
> > >
> > > I'm all for not merging this without a proper solution in that regard
> (I even
> > > presented a quick RFC solution which wasn't tested by anyone involved
> in
> > > this patch, yet).
> > >
> > > But if there really is an urgent need for this lib, I'm O-K with
> merging this
> > > given that all my concerns are addressed (minus libc duplication).
> > >
> > > --
> > > Pedro
>
[-- Attachment #2: Type: text/html, Size: 7141 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-04-11 13:19 ` Sheng Lean Tan
@ 2023-04-11 16:07 ` Pedro Falcato
2023-04-11 17:00 ` Michael D Kinney
0 siblings, 1 reply; 23+ messages in thread
From: Pedro Falcato @ 2023-04-11 16:07 UTC (permalink / raw)
To: Lean Sheng Tan
Cc: Kinney, Michael D, Warkentin, Andrei, devel@edk2.groups.io,
Lin, Benny, Gao, Liming, Liu, Zhiguang, Sean Brogan,
Michael Kubacki
On Tue, Apr 11, 2023 at 2:20 PM Lean Sheng Tan <sheng.tan@9elements.com> wrote:
>
> Thanks Mike for the proposal layout!
> It sounds good to me :)
>
> Hi Pedro,
> I went through the email chain again, basically these are 2 of your main concerns (correct me if I'm wrong):
> 1. a good idea to at least ditch that specific copy (current FDT in Embedded Pkg) for a git submodule.
> 2. Rework to remove/reduce libc Implementation as there is a problem with both libc fragments and compiler intrinsic fragments all over edk2. Should unify standards between crypto, libfdt, etc, could we try here
>
> I guess Mike has provided a plan to answer your first question, and the 2nd question would require a broader discussion with a few key owners.
>
> So it seems like we could get the current patchset from Benny Lin in for now? Any minor clean up needed for the current patch?
>
No.
3. Lots of questions and comments on the actual patch set regarding
the quality of the libc implementation. Which should be fixed,
regardless of centralizing a libc implementation.
Also questions on the FdtLib itself (why are we wrapping pure
libfdt functions with FluffyIdentifierNames and SCARY_TYPEDEFS?).
I also sent out an RFC for a central libc for GCC/clang based
toolchains, which should cover the libc usage of libfdt. Asked for
testing, got ignored.
So a NAK from me, in its current state.
--
Pedro
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 0/2] Support FDT library.
2023-04-11 16:07 ` Pedro Falcato
@ 2023-04-11 17:00 ` Michael D Kinney
0 siblings, 0 replies; 23+ messages in thread
From: Michael D Kinney @ 2023-04-11 17:00 UTC (permalink / raw)
To: devel@edk2.groups.io, pedro.falcato@gmail.com, Tan, Lean Sheng
Cc: Warkentin, Andrei, Lin, Benny, Gao, Liming, Liu, Zhiguang,
Sean Brogan, Michael Kubacki, Kinney, Michael D
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Pedro Falcato
> Sent: Tuesday, April 11, 2023 9:07 AM
> To: Tan, Lean Sheng <sheng.tan@9elements.com>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Warkentin, Andrei <andrei.warkentin@intel.com>; devel@edk2.groups.io;
> Lin, Benny <benny.lin@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Sean
> Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>
> Subject: Re: [edk2-devel] [PATCH 0/2] Support FDT library.
>
> On Tue, Apr 11, 2023 at 2:20 PM Lean Sheng Tan <sheng.tan@9elements.com> wrote:
> >
> > Thanks Mike for the proposal layout!
> > It sounds good to me :)
> >
> > Hi Pedro,
> > I went through the email chain again, basically these are 2 of your main concerns (correct me if I'm wrong):
> > 1. a good idea to at least ditch that specific copy (current FDT in Embedded Pkg) for a git submodule.
> > 2. Rework to remove/reduce libc Implementation as there is a problem with both libc fragments and compiler intrinsic
> fragments all over edk2. Should unify standards between crypto, libfdt, etc, could we try here
> >
> > I guess Mike has provided a plan to answer your first question, and the 2nd question would require a broader discussion
> with a few key owners.
> >
> > So it seems like we could get the current patchset from Benny Lin in for now? Any minor clean up needed for the current
> patch?
> >
>
> No.
>
> 3. Lots of questions and comments on the actual patch set regarding
> the quality of the libc implementation. Which should be fixed,
> regardless of centralizing a libc implementation.
> Also questions on the FdtLib itself (why are we wrapping pure
> libfdt functions with FluffyIdentifierNames and SCARY_TYPEDEFS?).
This is done to accommodate potential future changes to the submodule APIs
and types. The wrapper lib is a common practice in EDK II use of submodules.
The calling code can use the APIs/types defined in EDK II lib class. If
there are changes to the submodule APIs/types, we only have to update one
location. Can also provide flexibility to move to a different submodule or
implementation if there is a better option in the future.
Look at CryptoPkg CryptoLibs as an example. We have an implementation that
layers on top of openssl. We also have experiments looking at mbedtls.
No changes to calling code that uses CrytoLibs.
> I also sent out an RFC for a central libc for GCC/clang based
> toolchains, which should cover the libc usage of libfdt. Asked for
> testing, got ignored.
I provided feedback on your work on a central libc and asked if you are
able to test the libc uses currently checked into edk2. Are you able to
help with that testing?
>
> So a NAK from me, in its current state.
>
> --
> Pedro
>
>
>
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [edk2-devel] [PATCH 1/2] MdePkg: Support FDT library.
2023-03-30 23:19 ` [edk2-devel] " Pedro Falcato
@ 2023-04-12 16:59 ` Benny Lin
0 siblings, 0 replies; 23+ messages in thread
From: Benny Lin @ 2023-04-12 16:59 UTC (permalink / raw)
To: Pedro Falcato, devel@edk2.groups.io
Cc: Kinney, Michael D, Gao, Liming, Liu, Zhiguang, Chiu, Chasel
Hi, Pedro,
Thanks for your feedback.
Sorry for the late response. Please find below my comment.
-----Original Message-----
From: Pedro Falcato <pedro.falcato@gmail.com>
Sent: Friday, March 31, 2023 7:19 AM
To: devel@edk2.groups.io; Lin, Benny <benny.lin@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>
Subject: Re: [edk2-devel] [PATCH 1/2] MdePkg: Support FDT library.
On Thu, Mar 30, 2023 at 6:13 PM Benny Lin <benny.lin@intel.com> wrote:
>>
>> 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)
>>
>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
>> Signed-off-by: Benny Lin <benny.lin@intel.com>
>> ---
>> .gitmodules | 3 +
>> MdePkg/Include/Library/FdtLib.h | 300 ++++++++++++++++++++++
>> MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 62 +++++
>> MdePkg/Library/BaseFdtLib/BaseFdtLib.uni | 14 +
>> MdePkg/Library/BaseFdtLib/FdtLib.c | 284 ++++++++++++++++++++
>> MdePkg/Library/BaseFdtLib/LibFdtSupport.h | 102 ++++++++
>> MdePkg/Library/BaseFdtLib/LibFdtWrapper.c | 138 ++++++++++
>> 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 | 2 +
>> ReadMe.rst | 1 +
>> 18 files changed, 986 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
>>
>> diff --git a/.gitmodules b/.gitmodules index 8011a88d9d..5da342e90c
>> 100644
>> --- a/.gitmodules
>> +++ b/.gitmodules
>> @@ -23,3 +23,6 @@
>> [submodule "UnitTestFrameworkPkg/Library/GoogleTestLib/googletest"]
>> path = UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
>> url = https://github.com/google/googletest.git
>> +[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
>> + path = MdePkg/Library/BaseFdtLib/libfdt
>> + url = https://github.com/devicetree-org/pylibfdt.git
>> diff --git a/MdePkg/Include/Library/FdtLib.h
>> b/MdePkg/Include/Library/FdtLib.h new file mode 100644 index
>> 0000000000..bcb097b77e
>> --- /dev/null
>> +++ b/MdePkg/Include/Library/FdtLib.h
>> @@ -0,0 +1,300 @@
>> +/** @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) FDT32_TO_CPU(((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))
>> +
>> +/**
>> + 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 porperty 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_ */
>What's the point of all these wrappers if we end up immediately redirecting to libfdt?
The purpose of all wrappers is used for following up edk2 style.
>> 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..ba9a284e58
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c
>> @@ -0,0 +1,284 @@
>> +/** @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>
>> +
>> +/**
>> + 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 porperty in the given node.
>*property
Corrected in Patch V2.
>> +
>> + @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..58b0bb403e
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
>> @@ -0,0 +1,102 @@
>> +/** @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
>> +// #ifndef INT_MAX
>> +#define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */
>> +#endif
>Why the ifndef here?
Same with below.
>> +#define INT32_MAX 0x7FFFFFFF /* Maximum (signed) int32 value */
>> +#define UINT32_MAX 0xFFFFFFFF /* Maximum unsigned int32 value */
>> +#define MAX_STRING_SIZE 0x1000
>Why the arbitrary MAX_STRING_SIZE here?
Because there're many standard c wrappers, the sequence of include paths will Influence each other.
At first, I made a mistake with wrong include path so I got build failed with lacked definitions.
However, I forgot to check those definitions when corrected include path.
Remove no use definitions and #ifndef in Patch V2.
>> +
>> +//
>> +// 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..3f1cc69dc6
>> --- /dev/null
>> +++ b/MdePkg/Library/BaseFdtLib/LibFdtWrapper.c
>> @@ -0,0 +1,138 @@
>> +/** @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
>> +
>> +**/
>> +
>> +#include "LibFdtSupport.h"
>> +#include <Library/DebugLib.h>
>Why are we pulling DebugLib? I don't see where this should be needed.
Yes, we do not need. Forgot removal after debugging.
Remove it in Patch V2.
>> +
>> +/**
>> + Returns the first occurrence of a Null-terminated ASCII character
>> + in a Null-terminated ASCII string.
>> +
>> + This function scans the contents of the ASCII string specified by s
>> + and returns the first occurrence of c. If c is not found in s, then
>> + NULL is returned. If the length of c is zero, then s is returned.
>> +
>> + @param s The pointer to a Null-terminated ASCII string.
>> + @param c The pointer to a Null-terminated ASCII character to search for.
>> +
>> + @retval NULL If the c does not appear in s.
>> + @retval others If there is a match return the first occurrence of c.
>> + If the length of c is zero,return s.
>The doxygen for strchr and strrchr is very wrong and is not ISO C (nor GNU C nor any other brand of C) compliant. Please refer to a >Linux/macOS/BSD manpage or to an ISO C standard draft.
Remove doxygen in Patch V2.
>> +
>> +**/
>> +char *
>> +strchr (
>> + const char *s,
>> + int c
>> + )
>> +{
>> + char pattern[2];
>> +
>> + pattern[0] = (CHAR8)c;
>> + pattern[1] = 0;
>> + return AsciiStrStr (s, pattern);
>> +}
>> +
>> +/**
>> + Returns the last occurrence of a Null-terminated ASCII character
>> + in a Null-terminated ASCII string.
>> +
>> + This function scans the contents of the ASCII string specified by s
>> + and returns the last occurrence of c. If c is not found in s, then
>> + NULL is returned. If the length of c is zero, then s is returned.
>> +
>> + @param s The pointer to a Null-terminated ASCII string.
>> + @param c The pointer to a Null-terminated ASCII character to search for.
>> +
>> + @retval NULL If the c does not appear in s.
>> + @retval others If there is a match return the last occurrence of c.
>> + If the length of c is zero,return s.
>> +
>> +**/
>> +char *
>> +strrchr (
>> + const char *s,
>> + int c
>> + )
>> +{
>> + char pattern[2];
>> + CONST CHAR8 *LastMatch;
>> + CONST CHAR8 *StringTmp;
>> + CONST CHAR8 *SearchString;
>> +
>> + pattern[0] = (CHAR8)c;
>> + pattern[1] = 0;
>> + SearchString = pattern;
>> +
>> + //
>> + // Return NULL if both strings are less long than
>> + PcdMaximumAsciiStringLength // if ((AsciiStrSize (s) == 0) ||
>> + (AsciiStrSize (SearchString) == 0)) {
>> + return NULL;
>> + }
>> +
>> + if (*SearchString == '\0') {
>> + return (CHAR8 *)s;
>> + }
>> +
>> + LastMatch = NULL;
>> + do {
>> + StringTmp = AsciiStrStr (s, SearchString);
>> +
>> + if (StringTmp == NULL) {
>> + break;
>> + }
>> +
>> + LastMatch = StringTmp;
>> + s = StringTmp + 1;
>> + } while (s != NULL);
>> +
>> + return (CHAR8 *)LastMatch;
>> +}
>Better implementations I wrote very quickly, feel free to EFI-it, public domain: >https://gist.github.com/heatd/c1192f3f05148a6271be37fb3160b143
In my understanding, I should use those functions provided by edk2 to implement.
Looks like we do not need so I integrated your implementations from libclib.
When integrated libclib functions to wrapper file, I can build successfully with MSVC.
However, I also test with integrated whole changes of libclib. Build failed occurred.
I will keep checking.
>> +
>> +/**
>> + Convert a Null-terminated Ascii decimal or hexadecimal string to a value of type UINTN.
>> +
>> + This function outputs a value of type UINTN by interpreting the
>> + contents of the Ascii string specified by String as a decimal or hexadecimal number.
>> +
>> + @param nptr Pointer to a Null-terminated Ascii string.
>> + @param endptr Pointer to character that stops scan.
>> + @param base Pointer to decimal or hexadecimal.
>> +
>> + @retval MAX_UINTN If nptr is NULL.
>> + If endptr is NULL.
>> + If base is not 10 or 16.
>> + @retval others Value is translated from String.
>> +
>> +**/
>> +unsigned long
>> +strtoul (
>> + const char *nptr,
>> + char **endptr,
>> + int base
>> + )
>> +{
>> + RETURN_STATUS Status;
>> + UINTN ReturnValue;
>There's no equivalence between UINTN and unsigned long on x64 Windows (where they use LLP64, so 32-bit longs, while UINTN should be 64->bit).
Keep unsigned long in Patch V2.
>> +
>> + if (base == 10) {
>> + Status = AsciiStrDecimalToUintnS (nptr, endptr, &ReturnValue); }
>> + else if (base == 16) {
>> + Status = AsciiStrHexToUintnS (nptr, endptr, &ReturnValue); }
>> + else {
>> + Status = RETURN_INVALID_PARAMETER; }
>> +
>> + if (RETURN_ERROR (Status)) {
>> + return MAX_UINTN;
>> + }
>> +
>> + return (unsigned long)ReturnValue;
>> +}
>Note that this is not ISO C compliant, but seems to work in the libfdt case (as far as I can see, only a single strtoul call with base 10).
This will be replaced with libclib functions.
>> 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/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>
>If we want to be rigorous, strictly speaking, we should not pollute the namespace. stdbool.h should only include the stdbool.h stuff (see the ISO >C spec), and the same applies for the other headers.
>Although I *guess* it doesn't matter much here.
I agree with you and I think libclib is better for edk2.
>--
>Pedro
Benny
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2023-04-12 16:59 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-30 16:52 [PATCH 0/2] Support FDT library benny.lin
2023-03-30 16:52 ` [PATCH 1/2] MdePkg: " Benny Lin
2023-03-30 17:01 ` Michael D Kinney
2023-03-30 23:19 ` [edk2-devel] " Pedro Falcato
2023-04-12 16:59 ` Benny Lin
2023-03-30 16:52 ` [PATCH 2/2] .pytool: " Benny Lin
2023-03-30 21:50 ` [edk2-devel] [PATCH 0/2] " Pedro Falcato
2023-03-30 22:59 ` Michael D Kinney
2023-03-30 23:26 ` Pedro Falcato
2023-03-30 23:32 ` Michael D Kinney
2023-03-31 2:35 ` Pedro Falcato
2023-03-31 11:39 ` Gerd Hoffmann
2023-03-31 12:18 ` Pedro Falcato
2023-03-31 12:17 ` Leif Lindholm
2023-03-31 12:12 ` Leif Lindholm
2023-04-01 1:29 ` Andrei Warkentin
2023-04-06 16:33 ` Sheng Lean Tan
2023-04-07 13:23 ` Pedro Falcato
2023-04-07 22:35 ` Andrei Warkentin
2023-04-07 23:04 ` Michael D Kinney
2023-04-11 13:19 ` Sheng Lean Tan
2023-04-11 16:07 ` Pedro Falcato
2023-04-11 17:00 ` 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