Skip to content

Commit

Permalink
MdePkg: add FdtStrerror wrapper to BaseFdtLib
Browse files Browse the repository at this point in the history
Add a wrapper for fdt_strerror () and add the currently supported error
code defines from submodule.

Signed-off-by: Leif Lindholm <[email protected]>
  • Loading branch information
leiflindholm authored and mergify[bot] committed Oct 2, 2024
1 parent 8040fdb commit 8292296
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
117 changes: 117 additions & 0 deletions MdePkg/Include/Library/FdtLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,115 @@
#ifndef FDT_LIB_H_
#define FDT_LIB_H_

/* Error codes: informative error codes */
#define FDT_ERR_NOTFOUND 1
/* FDT_ERR_NOTFOUND: The requested node or property does not exist */
#define FDT_ERR_EXISTS 2

/* FDT_ERR_EXISTS: Attempted to create a node or property which
* already exists */
#define FDT_ERR_NOSPACE 3

/* FDT_ERR_NOSPACE: Operation needed to expand the device
* tree, but its buffer did not have sufficient space to
* contain the expanded tree. Use fdt_open_into() to move the
* device tree to a buffer with more space. */

/* Error codes: codes for bad parameters */
#define FDT_ERR_BADOFFSET 4

/* FDT_ERR_BADOFFSET: Function was passed a structure block
* offset which is out-of-bounds, or which points to an
* unsuitable part of the structure for the operation. */
#define FDT_ERR_BADPATH 5

/* FDT_ERR_BADPATH: Function was passed a badly formatted path
* (e.g. missing a leading / for a function which requires an
* absolute path) */
#define FDT_ERR_BADPHANDLE 6

/* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
* This can be caused either by an invalid phandle property
* length, or the phandle value was either 0 or -1, which are
* not permitted. */
#define FDT_ERR_BADSTATE 7

/* FDT_ERR_BADSTATE: Function was passed an incomplete device
* tree created by the sequential-write functions, which is
* not sufficiently complete for the requested operation. */

/* Error codes: codes for bad device tree blobs */
#define FDT_ERR_TRUNCATED 8

/* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
* terminated (overflows, goes outside allowed bounds, or
* isn't properly terminated). */
#define FDT_ERR_BADMAGIC 9

/* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
* device tree at all - it is missing the flattened device
* tree magic number. */
#define FDT_ERR_BADVERSION 10

/* FDT_ERR_BADVERSION: Given device tree has a version which
* can't be handled by the requested operation. For
* read-write functions, this may mean that fdt_open_into() is
* required to convert the tree to the expected version. */
#define FDT_ERR_BADSTRUCTURE 11

/* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
* structure block or other serious error (e.g. misnested
* nodes, or subnodes preceding properties). */
#define FDT_ERR_BADLAYOUT 12

/* FDT_ERR_BADLAYOUT: For read-write functions, the given
* device tree has it's sub-blocks in an order that the
* function can't handle (memory reserve map, then structure,
* then strings). Use fdt_open_into() to reorganize the tree
* into a form suitable for the read-write operations. */

/* "Can't happen" error indicating a bug in libfdt */
#define FDT_ERR_INTERNAL 13

/* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
* Should never be returned, if it is, it indicates a bug in
* libfdt itself. */

/* Errors in device tree content */
#define FDT_ERR_BADNCELLS 14

/* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
* or similar property with a bad format or value */

#define FDT_ERR_BADVALUE 15

/* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
* value. For example: a property expected to contain a string list
* is not NUL-terminated within the length of its value. */

#define FDT_ERR_BADOVERLAY 16

/* FDT_ERR_BADOVERLAY: The device tree overlay, while
* correctly structured, cannot be applied due to some
* unexpected or missing value, property or node. */

#define FDT_ERR_NOPHANDLES 17

/* FDT_ERR_NOPHANDLES: The device tree doesn't have any
* phandle available anymore without causing an overflow */

#define FDT_ERR_BADFLAGS 18

/* FDT_ERR_BADFLAGS: The function was passed a flags field that
* contains invalid flags or an invalid combination of flags. */

#define FDT_ERR_ALIGNMENT 19

/* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte
* aligned. */

#define FDT_ERR_MAX 19

/**
Flattened Device Tree definition
Expand Down Expand Up @@ -483,4 +592,12 @@ FdtNodeOffsetByCompatible (
IN CONST CHAR8 *Compatible
);

/* Debug functions. */
CONST
CHAR8
*
FdtStrerror (
IN INT32 ErrVal
);

#endif /* FDT_LIB_H_ */
11 changes: 11 additions & 0 deletions MdePkg/Library/BaseFdtLib/FdtLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,14 @@ FdtNodeOffsetByCompatible (
{
return fdt_node_offset_by_compatible (Fdt, StartOffset, Compatible);
}

/* Debug functions. */
CONST
CHAR8
*
FdtStrerror (
IN INT32 ErrVal
)
{
return fdt_strerror (ErrVal);
}

0 comments on commit 8292296

Please sign in to comment.