Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Arm Trusted Firmware
Commits
9c10e348
Unverified
Commit
9c10e348
authored
6 years ago
by
Antonio Niño Díaz
Committed by
GitHub
6 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #1665 from antonio-nino-diaz-arm/an/fdt-helpers
Introduce new fdt helpers
parents
4eb835f8
73f1ac6c
master
v2.5
v2.5-rc1
v2.5-rc0
v2.4
v2.4-rc2
v2.4-rc1
v2.4-rc0
v2.3
v2.3-rc2
v2.3-rc1
v2.3-rc0
v2.2
v2.2-rc2
v2.2-rc1
v2.2-rc0
v2.1
v2.1-rc1
v2.1-rc0
arm_cca_v0.2
arm_cca_v0.1
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
common/fdt_wrappers.c
+72
-1
common/fdt_wrappers.c
include/common/fdt_wrappers.h
+5
-0
include/common/fdt_wrappers.h
include/lib/libc/string.h
+1
-0
include/lib/libc/string.h
lib/libc/libc.mk
+1
-0
lib/libc/libc.mk
lib/libc/strlcpy.c
+52
-0
lib/libc/strlcpy.c
with
131 additions
and
1 deletion
+131
-1
common/fdt_wrappers.c
View file @
9c10e348
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include <debug.h>
#include <debug.h>
#include <fdt_wrappers.h>
#include <fdt_wrappers.h>
#include <libfdt.h>
#include <libfdt.h>
#include <string.h>
/*
/*
* Read cells from a given property of the given node. At most 2 cells of the
* Read cells from a given property of the given node. At most 2 cells of the
...
@@ -39,7 +40,6 @@ int fdtw_read_cells(const void *dtb, int node, const char *prop,
...
@@ -39,7 +40,6 @@ int fdtw_read_cells(const void *dtb, int node, const char *prop,
return
-
1
;
return
-
1
;
}
}
/* Verify that property length accords with cell length */
/* Verify that property length accords with cell length */
if
(
NCELLS
((
unsigned
int
)
value_len
)
!=
cells
)
{
if
(
NCELLS
((
unsigned
int
)
value_len
)
!=
cells
)
{
WARN
(
"Property length mismatch
\n
"
);
WARN
(
"Property length mismatch
\n
"
);
...
@@ -61,6 +61,77 @@ int fdtw_read_cells(const void *dtb, int node, const char *prop,
...
@@ -61,6 +61,77 @@ int fdtw_read_cells(const void *dtb, int node, const char *prop,
return
0
;
return
0
;
}
}
/*
* Read cells from a given property of the given node. Any number of 32-bit
* cells of the property can be read. The fdt pointer is updated. Returns 0 on
* success, and -1 on error.
*/
int
fdtw_read_array
(
const
void
*
dtb
,
int
node
,
const
char
*
prop
,
unsigned
int
cells
,
void
*
value
)
{
const
uint32_t
*
value_ptr
;
int
value_len
;
assert
(
dtb
!=
NULL
);
assert
(
prop
!=
NULL
);
assert
(
value
!=
NULL
);
assert
(
node
>=
0
);
/* Access property and obtain its length (in bytes) */
value_ptr
=
fdt_getprop_namelen
(
dtb
,
node
,
prop
,
(
int
)
strlen
(
prop
),
&
value_len
);
if
(
value_ptr
==
NULL
)
{
WARN
(
"Couldn't find property %s in dtb
\n
"
,
prop
);
return
-
1
;
}
/* Verify that property length accords with cell length */
if
(
NCELLS
((
unsigned
int
)
value_len
)
!=
cells
)
{
WARN
(
"Property length mismatch
\n
"
);
return
-
1
;
}
uint32_t
*
dst
=
value
;
for
(
unsigned
int
i
=
0U
;
i
<
cells
;
i
++
)
{
dst
[
i
]
=
fdt32_to_cpu
(
value_ptr
[
i
]);
}
return
0
;
}
/*
* Read string from a given property of the given node. Up to 'size - 1'
* characters are read, and a NUL terminator is added. Returns 0 on success,
* and -1 upon error.
*/
int
fdtw_read_string
(
const
void
*
dtb
,
int
node
,
const
char
*
prop
,
char
*
str
,
size_t
size
)
{
const
char
*
ptr
;
size_t
len
;
assert
(
dtb
!=
NULL
);
assert
(
node
>=
0
);
assert
(
prop
!=
NULL
);
assert
(
str
!=
NULL
);
assert
(
size
>
0U
);
ptr
=
fdt_getprop_namelen
(
dtb
,
node
,
prop
,
(
int
)
strlen
(
prop
),
NULL
);
if
(
ptr
==
NULL
)
{
WARN
(
"Couldn't find property %s in dtb
\n
"
,
prop
);
return
-
1
;
}
len
=
strlcpy
(
str
,
ptr
,
size
);
if
(
len
>=
size
)
{
WARN
(
"String of property %s in dtb has been truncated
\n
"
,
prop
);
return
-
1
;
}
return
0
;
}
/*
/*
* Write cells in place to a given property of the given node. At most 2 cells
* Write cells in place to a given property of the given node. At most 2 cells
* of the property are written. Returns 0 on success, and -1 upon error.
* of the property are written. Returns 0 on success, and -1 upon error.
...
...
This diff is collapsed.
Click to expand it.
include/common/fdt_wrappers.h
View file @
9c10e348
...
@@ -14,6 +14,11 @@
...
@@ -14,6 +14,11 @@
int
fdtw_read_cells
(
const
void
*
dtb
,
int
node
,
const
char
*
prop
,
int
fdtw_read_cells
(
const
void
*
dtb
,
int
node
,
const
char
*
prop
,
unsigned
int
cells
,
void
*
value
);
unsigned
int
cells
,
void
*
value
);
int
fdtw_read_array
(
const
void
*
dtb
,
int
node
,
const
char
*
prop
,
unsigned
int
cells
,
void
*
value
);
int
fdtw_read_string
(
const
void
*
dtb
,
int
node
,
const
char
*
prop
,
char
*
str
,
size_t
size
);
int
fdtw_write_inplace_cells
(
void
*
dtb
,
int
node
,
const
char
*
prop
,
int
fdtw_write_inplace_cells
(
void
*
dtb
,
int
node
,
const
char
*
prop
,
unsigned
int
cells
,
void
*
value
);
unsigned
int
cells
,
void
*
value
);
#endif
/* __FDT_WRAPPERS__ */
#endif
/* __FDT_WRAPPERS__ */
This diff is collapsed.
Click to expand it.
include/lib/libc/string.h
View file @
9c10e348
...
@@ -28,5 +28,6 @@ void *memset(void *dst, int val, size_t count);
...
@@ -28,5 +28,6 @@ void *memset(void *dst, int val, size_t count);
size_t
strlen
(
const
char
*
s
);
size_t
strlen
(
const
char
*
s
);
size_t
strnlen
(
const
char
*
s
,
size_t
maxlen
);
size_t
strnlen
(
const
char
*
s
,
size_t
maxlen
);
char
*
strrchr
(
const
char
*
p
,
int
ch
);
char
*
strrchr
(
const
char
*
p
,
int
ch
);
size_t
strlcpy
(
char
*
dst
,
const
char
*
src
,
size_t
dsize
);
#endif
/* STRING_H */
#endif
/* STRING_H */
This diff is collapsed.
Click to expand it.
lib/libc/libc.mk
View file @
9c10e348
...
@@ -19,6 +19,7 @@ LIBC_SRCS := $(addprefix lib/libc/, \
...
@@ -19,6 +19,7 @@ LIBC_SRCS := $(addprefix lib/libc/, \
snprintf.c
\
snprintf.c
\
strchr.c
\
strchr.c
\
strcmp.c
\
strcmp.c
\
strlcpy.c
\
strlen.c
\
strlen.c
\
strncmp.c
\
strncmp.c
\
strnlen.c
\
strnlen.c
\
...
...
This diff is collapsed.
Click to expand it.
lib/libc/strlcpy.c
0 → 100644
View file @
9c10e348
/* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdint.h>
#include <string.h>
/*
* Copy string src to buffer dst of size dsize. At most dsize-1
* chars will be copied. Always NUL terminates (unless dsize == 0).
* Returns strlen(src); if retval >= dsize, truncation occurred.
*/
size_t
strlcpy
(
char
*
dst
,
const
char
*
src
,
size_t
dsize
)
{
const
char
*
osrc
=
src
;
size_t
nleft
=
dsize
;
/* Copy as many bytes as will fit. */
if
(
nleft
!=
0
)
{
while
(
--
nleft
!=
0
)
{
if
((
*
dst
++
=
*
src
++
)
==
'\0'
)
break
;
}
}
/* Not enough room in dst, add NUL and traverse rest of src. */
if
(
nleft
==
0
)
{
if
(
dsize
!=
0
)
*
dst
=
'\0'
;
/* NUL-terminate dst */
while
(
*
src
++
)
;
}
return
(
src
-
osrc
-
1
);
/* count does not include NUL */
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help