[FDT] Fix POSIX compatibility for string.h (#6923)

* [FDT] Fix POSIX compatibility for string.h

* [FDT] format libfdt code.

* [FDT] format libfdt code.
This commit is contained in:
Bernard Xiong 2023-02-13 16:36:16 +08:00 committed by GitHub
parent 03bcd0701c
commit fc1aced665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 716 additions and 710 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -201,11 +201,11 @@ int dtb_node_property_read_string_helper(const struct dtb_node *dn,
/**
* of_property_read_string_index() - Find and read a string from a multiple
* strings property.
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @index: index of the string in the list of strings
* @out_string: pointer to null terminated return string, modified only if
* return value is 0.
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @index: index of the string in the list of strings
* @out_string: pointer to null terminated return string, modified only if
* return value is 0.
*
* Search for a property in a device tree node and retrieve a null
* terminated string value (pointer to data, not a copy) in the list of strings
@ -227,8 +227,8 @@ static inline int dtb_node_property_read_string_index(const struct dtb_node *dn,
/**
* of_property_count_strings() - Find and return the number of strings from a
* multiple strings property.
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
*
* Search for a property in a device tree node and retrieve the number of null
* terminated string contain in it. Returns the number of strings on

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,8 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*/
#define _GNU_SOURCE
#include "libfdt.h"
#include "dtb_node.h"
@ -324,7 +322,7 @@ void *dtb_node_get_dtb_node_property_value(const struct dtb_node *dtb_node, cons
if (property_size != NULL)
{
*property_size = dtb_property->size;
*property_size = dtb_property->size;
}
return dtb_property->value;
@ -450,11 +448,11 @@ int dtb_node_property_match_string(const struct dtb_node *dn, const char *propna
/**
* of_property_read_string_helper() - Utility helper for parsing string properties
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @out_strs: output array of string pointers.
* @sz: number of array elements to read.
* @skip: Number of strings to skip over at beginning of list.
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @out_strs: output array of string pointers.
* @sz: number of array elements to read.
* @skip: Number of strings to skip over at beginning of list.
*
* Don't call this function directly. It is a utility helper for the
* of_property_read_string*() family of functions.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -7,51 +7,51 @@
#include "dtb_node.h"
/* Max address size we deal with */
#define FDT_MAX_ADDR_CELLS 4
#define FDT_CHECK_ADDR_COUNT(na) ((na) > 0 && (na) <= FDT_MAX_ADDR_CELLS)
#define FDT_CHECK_COUNTS(na, ns) (FDT_CHECK_ADDR_COUNT(na) && (ns) > 0)
#define FDT_MAX_ADDR_CELLS 4
#define FDT_CHECK_ADDR_COUNT(na) ((na) > 0 && (na) <= FDT_MAX_ADDR_CELLS)
#define FDT_CHECK_COUNTS(na, ns) (FDT_CHECK_ADDR_COUNT(na) && (ns) > 0)
static void dtb_node_default_count_cells(const struct dtb_node *dn,
int *addrc, int *sizec)
int *addrc, int *sizec)
{
if (addrc)
*addrc = dtb_node_n_addr_cells(dn);
if (sizec)
*sizec = dtb_node_n_size_cells(dn);
if (addrc)
*addrc = dtb_node_n_addr_cells(dn);
if (sizec)
*sizec = dtb_node_n_size_cells(dn);
}
const uint32_t *dtb_node_get_address(const struct dtb_node *dev, int index,
uint64_t *size, unsigned int *flags)
uint64_t *size, unsigned int *flags)
{
const uint32_t *prop;
int psize;
struct dtb_node *parent;
int onesize, i, na, ns;
const uint32_t *prop;
int psize;
struct dtb_node *parent;
int onesize, i, na, ns;
/* Get parent */
parent = dtb_node_get_parent(dev);
if (parent == NULL)
return NULL;
/* Get parent */
parent = dtb_node_get_parent(dev);
if (parent == NULL)
return NULL;
dtb_node_default_count_cells(dev, &na, &ns);
if (!FDT_CHECK_ADDR_COUNT(na))
return NULL;
dtb_node_default_count_cells(dev, &na, &ns);
if (!FDT_CHECK_ADDR_COUNT(na))
return NULL;
/* Get "reg" or "assigned-addresses" property */
prop = dtb_node_get_dtb_node_property_value(dev, "reg", &psize);
if (prop == NULL)
return NULL;
psize /= 4;
/* Get "reg" or "assigned-addresses" property */
prop = dtb_node_get_dtb_node_property_value(dev, "reg", &psize);
if (prop == NULL)
return NULL;
psize /= 4;
onesize = na + ns;
for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
if (i == index)
{
if (size)
*size = dtb_node_read_number(prop + na, ns);
if (flags)
*flags = 0x200;
return prop;
}
return NULL;
}
onesize = na + ns;
for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
if (i == index)
{
if (size)
*size = dtb_node_read_number(prop + na, ns);
if (flags)
*flags = 0x200;
return prop;
}
return NULL;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -189,7 +189,7 @@ const char *dtb_node_get_name(const struct dtb_node *node)
}
struct dtb_node *dtb_node_get_by_phandle(uint phandle)
struct dtb_node *dtb_node_get_by_phandle(uint32_t phandle)
{
if (dtb_node_active())
return dtb_node_find_node_by_phandle(phandle);
@ -418,63 +418,63 @@ int dtb_node_set_enabled(const struct dtb_node *node, rt_bool_t value)
*/
static struct dtb_node *dtb_node_irq_find_parent(struct dtb_node *child)
{
struct dtb_node *p;
phandle parent;
struct dtb_node *p;
phandle parent;
if (!dtb_node_get(child))
return NULL;
do
if (!dtb_node_get(child))
return NULL;
do
{
if (dtb_node_read_u32_array(child, "interrupt-parent", &parent, 1))
if (dtb_node_read_u32_array(child, "interrupt-parent", &parent, 1))
{
p = dtb_node_get_parent(child);
}
p = dtb_node_get_parent(child);
}
else
{
p = dtb_node_get_by_phandle(parent);
}
dtb_node_put(child);
child = p;
} while (p && dtb_node_get_property(p, "#interrupt-cells", NULL) == NULL);
p = dtb_node_get_by_phandle(parent);
}
dtb_node_put(child);
child = p;
} while (p && dtb_node_get_property(p, "#interrupt-cells", NULL) == NULL);
return p;
return p;
}
int dtb_node_irq_get(struct dtb_node *dev, int index)
{
int rc = 0;
struct fdt_phandle_args out_irq;
int rc = 0;
struct fdt_phandle_args out_irq;
struct dtb_node *p;
uint32_t intsize;
int res, i;
uint32_t intsize;
int res, i;
p = dtb_node_irq_find_parent(dev);
if (p == NULL)
return -EINVAL;
/* Get size of interrupt specifier */
if (dtb_node_read_u32_array(p, "#interrupt-cells", &intsize, 1))
p = dtb_node_irq_find_parent(dev);
if (p == NULL)
return -EINVAL;
/* Get size of interrupt specifier */
if (dtb_node_read_u32_array(p, "#interrupt-cells", &intsize, 1))
{
res = -EINVAL;
goto out;
}
res = -EINVAL;
goto out;
}
debug(" path:%s, parent=%pOF, intsize=%d\n", p->path,p, intsize);
/* Copy intspec into irq structure */
out_irq.np = p;
out_irq.args_count = intsize;
for (i = 0; i < intsize; i++)
debug(" path:%s, parent=%pOF, intsize=%d\n", p->path,p, intsize);
/* Copy intspec into irq structure */
out_irq.np = p;
out_irq.args_count = intsize;
for (i = 0; i < intsize; i++)
{
res = dtb_node_read_u32_index(dev, "interrupts",
(index * 3 + i),
out_irq.args + i);
if (res)
goto out;
}
res = dtb_node_read_u32_index(dev, "interrupts",
(index * 3 + i),
out_irq.args + i);
if (res)
goto out;
}
rc = out_irq.args[1];
out:
dtb_node_put(p);
return rc;
dtb_node_put(p);
return rc;
}
@ -489,16 +489,16 @@ int dtb_node_irq_get(struct dtb_node *dev, int index)
*/
int dtb_node_irq_get_byname(struct dtb_node *dev, const char *name)
{
int index;
int index;
if (!name)
return -EINVAL;
if (!name)
return -EINVAL;
index = dtb_node_stringlist_search(dev, "interrupt-names", name);
if (index < 0)
return index;
index = dtb_node_stringlist_search(dev, "interrupt-names", name);
if (index < 0)
return index;
return dtb_node_irq_get(dev, index);
return dtb_node_irq_get(dev, index);
}
/**
@ -508,21 +508,21 @@ int dtb_node_irq_get_byname(struct dtb_node *dev, const char *name)
int dtb_node_irq_count(struct dtb_node *device)
{
struct dtb_node *p;
uint32_t intsize;
int nr = 0, res = 0;
uint32_t intsize;
int nr = 0, res = 0;
p = dtb_node_irq_find_parent(device);
if (p == NULL)
return -EINVAL;
p = dtb_node_irq_find_parent(device);
if (p == NULL)
return -EINVAL;
/* Get size of interrupt specifier */
if (dtb_node_read_u32_array(p, "#interrupt-cells", &intsize, 1))
/* Get size of interrupt specifier */
if (dtb_node_read_u32_array(p, "#interrupt-cells", &intsize, 1))
{
res = -EINVAL;
goto out;
}
res = -EINVAL;
goto out;
}
debug(" path:%s, parent=%pOF, intsize=%d\n", p->path,p, intsize);
debug(" path:%s, parent=%pOF, intsize=%d\n", p->path,p, intsize);
res = dtb_node_read_size(device, "interrupts");
if (res < 0)
@ -531,7 +531,7 @@ int dtb_node_irq_count(struct dtb_node *device)
}
nr = res / (intsize * 4);
out:
dtb_node_put(p);
dtb_node_put(p);
return nr;
}
return nr;
}

View File

@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "libfdt.h"
#include <stdio.h>
#include <unistd.h>
#include "dtb_node.h"