2019-06-20 23:19:39 +02:00
|
|
|
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
2017-10-18 08:22:40 +02:00
|
|
|
#ifndef LIBFDT_ENV_H
|
|
|
|
#define LIBFDT_ENV_H
|
2013-02-15 17:06:10 +01:00
|
|
|
/*
|
|
|
|
* libfdt - Flat Device Tree manipulation
|
|
|
|
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
|
|
|
* Copyright 2012 Kim Phillips, Freescale Semiconductor.
|
|
|
|
*/
|
2006-12-01 05:02:10 +01:00
|
|
|
|
2019-03-26 16:33:00 +01:00
|
|
|
#include <stdbool.h>
|
2006-11-27 06:21:28 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2016-09-30 15:57:16 +02:00
|
|
|
#include <stdlib.h>
|
2006-11-27 06:21:28 +01:00
|
|
|
#include <string.h>
|
2017-10-23 05:45:56 +02:00
|
|
|
#include <limits.h>
|
2006-11-27 06:21:28 +01:00
|
|
|
|
2012-11-29 00:33:01 +01:00
|
|
|
#ifdef __CHECKER__
|
2017-03-06 02:16:56 +01:00
|
|
|
#define FDT_FORCE __attribute__((force))
|
|
|
|
#define FDT_BITWISE __attribute__((bitwise))
|
2012-11-29 00:33:01 +01:00
|
|
|
#else
|
2017-03-06 02:16:56 +01:00
|
|
|
#define FDT_FORCE
|
|
|
|
#define FDT_BITWISE
|
2012-11-29 00:33:01 +01:00
|
|
|
#endif
|
|
|
|
|
2017-03-06 02:16:56 +01:00
|
|
|
typedef uint16_t FDT_BITWISE fdt16_t;
|
|
|
|
typedef uint32_t FDT_BITWISE fdt32_t;
|
|
|
|
typedef uint64_t FDT_BITWISE fdt64_t;
|
2012-11-29 00:33:01 +01:00
|
|
|
|
|
|
|
#define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n])
|
|
|
|
#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1))
|
|
|
|
#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \
|
|
|
|
(EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3))
|
|
|
|
#define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \
|
|
|
|
(EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \
|
|
|
|
(EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \
|
|
|
|
(EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7))
|
|
|
|
|
|
|
|
static inline uint16_t fdt16_to_cpu(fdt16_t x)
|
|
|
|
{
|
2017-03-06 02:16:56 +01:00
|
|
|
return (FDT_FORCE uint16_t)CPU_TO_FDT16(x);
|
2012-11-29 00:33:01 +01:00
|
|
|
}
|
|
|
|
static inline fdt16_t cpu_to_fdt16(uint16_t x)
|
2011-10-11 19:22:27 +02:00
|
|
|
{
|
2017-03-06 02:16:56 +01:00
|
|
|
return (FDT_FORCE fdt16_t)CPU_TO_FDT16(x);
|
2011-10-11 19:22:27 +02:00
|
|
|
}
|
|
|
|
|
2012-11-29 00:33:01 +01:00
|
|
|
static inline uint32_t fdt32_to_cpu(fdt32_t x)
|
dtc: Address an assortment of portability problems
I've recently worked with a FreeBSD developer, getting dtc and libfdt
working on FreeBSD. This showed up a number of portability problems
in the dtc package which this patch addresses. Changes are as
follows:
- the parent_offset and supernode_atdepth_offset testcases
used the glibc extension functions strchrnul() and strndupa(). Those
are removed, using slightly longer coding with standard C functions
instead.
- some other testcases had a #define _GNU_SOURCE for no
particular reason. This is removed.
- run_tests.sh has bash specific constructs removed, and the
interpreter changed to /bin/sh. This apparently now runs fine on
FreeBSD's /bin/sh, and I've also tested it with both ash and dash.
- convert-dtsv0-lexer.l has some extra #includes added. These
must have been included indirectly with Linux and glibc, but aren't on
FreeBSD.
- the endian handling functions in libfdt_env.h, based on
endian.h and byteswap.h are replaced with some portable open-coded
versions. Unfortunately, these result in fairly crappy code when
compiled, but as far as I can determine there doesn't seem to be any
POSIX, SUS or de facto standard way of determining endianness at
compile time, nor standard names for byteswapping functions.
- some more endian handling, from testdata.h using the
problematic endian.h is simply removed, since it wasn't actually being
used anyway.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-06-26 03:03:49 +02:00
|
|
|
{
|
2017-03-06 02:16:56 +01:00
|
|
|
return (FDT_FORCE uint32_t)CPU_TO_FDT32(x);
|
2012-11-29 00:33:01 +01:00
|
|
|
}
|
|
|
|
static inline fdt32_t cpu_to_fdt32(uint32_t x)
|
|
|
|
{
|
2017-03-06 02:16:56 +01:00
|
|
|
return (FDT_FORCE fdt32_t)CPU_TO_FDT32(x);
|
dtc: Address an assortment of portability problems
I've recently worked with a FreeBSD developer, getting dtc and libfdt
working on FreeBSD. This showed up a number of portability problems
in the dtc package which this patch addresses. Changes are as
follows:
- the parent_offset and supernode_atdepth_offset testcases
used the glibc extension functions strchrnul() and strndupa(). Those
are removed, using slightly longer coding with standard C functions
instead.
- some other testcases had a #define _GNU_SOURCE for no
particular reason. This is removed.
- run_tests.sh has bash specific constructs removed, and the
interpreter changed to /bin/sh. This apparently now runs fine on
FreeBSD's /bin/sh, and I've also tested it with both ash and dash.
- convert-dtsv0-lexer.l has some extra #includes added. These
must have been included indirectly with Linux and glibc, but aren't on
FreeBSD.
- the endian handling functions in libfdt_env.h, based on
endian.h and byteswap.h are replaced with some portable open-coded
versions. Unfortunately, these result in fairly crappy code when
compiled, but as far as I can determine there doesn't seem to be any
POSIX, SUS or de facto standard way of determining endianness at
compile time, nor standard names for byteswapping functions.
- some more endian handling, from testdata.h using the
problematic endian.h is simply removed, since it wasn't actually being
used anyway.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-06-26 03:03:49 +02:00
|
|
|
}
|
|
|
|
|
2012-11-29 00:33:01 +01:00
|
|
|
static inline uint64_t fdt64_to_cpu(fdt64_t x)
|
|
|
|
{
|
2017-03-06 02:16:56 +01:00
|
|
|
return (FDT_FORCE uint64_t)CPU_TO_FDT64(x);
|
2012-11-29 00:33:01 +01:00
|
|
|
}
|
|
|
|
static inline fdt64_t cpu_to_fdt64(uint64_t x)
|
dtc: Address an assortment of portability problems
I've recently worked with a FreeBSD developer, getting dtc and libfdt
working on FreeBSD. This showed up a number of portability problems
in the dtc package which this patch addresses. Changes are as
follows:
- the parent_offset and supernode_atdepth_offset testcases
used the glibc extension functions strchrnul() and strndupa(). Those
are removed, using slightly longer coding with standard C functions
instead.
- some other testcases had a #define _GNU_SOURCE for no
particular reason. This is removed.
- run_tests.sh has bash specific constructs removed, and the
interpreter changed to /bin/sh. This apparently now runs fine on
FreeBSD's /bin/sh, and I've also tested it with both ash and dash.
- convert-dtsv0-lexer.l has some extra #includes added. These
must have been included indirectly with Linux and glibc, but aren't on
FreeBSD.
- the endian handling functions in libfdt_env.h, based on
endian.h and byteswap.h are replaced with some portable open-coded
versions. Unfortunately, these result in fairly crappy code when
compiled, but as far as I can determine there doesn't seem to be any
POSIX, SUS or de facto standard way of determining endianness at
compile time, nor standard names for byteswapping functions.
- some more endian handling, from testdata.h using the
problematic endian.h is simply removed, since it wasn't actually being
used anyway.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-06-26 03:03:49 +02:00
|
|
|
{
|
2017-03-06 02:16:56 +01:00
|
|
|
return (FDT_FORCE fdt64_t)CPU_TO_FDT64(x);
|
dtc: Address an assortment of portability problems
I've recently worked with a FreeBSD developer, getting dtc and libfdt
working on FreeBSD. This showed up a number of portability problems
in the dtc package which this patch addresses. Changes are as
follows:
- the parent_offset and supernode_atdepth_offset testcases
used the glibc extension functions strchrnul() and strndupa(). Those
are removed, using slightly longer coding with standard C functions
instead.
- some other testcases had a #define _GNU_SOURCE for no
particular reason. This is removed.
- run_tests.sh has bash specific constructs removed, and the
interpreter changed to /bin/sh. This apparently now runs fine on
FreeBSD's /bin/sh, and I've also tested it with both ash and dash.
- convert-dtsv0-lexer.l has some extra #includes added. These
must have been included indirectly with Linux and glibc, but aren't on
FreeBSD.
- the endian handling functions in libfdt_env.h, based on
endian.h and byteswap.h are replaced with some portable open-coded
versions. Unfortunately, these result in fairly crappy code when
compiled, but as far as I can determine there doesn't seem to be any
POSIX, SUS or de facto standard way of determining endianness at
compile time, nor standard names for byteswapping functions.
- some more endian handling, from testdata.h using the
problematic endian.h is simply removed, since it wasn't actually being
used anyway.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-06-26 03:03:49 +02:00
|
|
|
}
|
2012-11-29 00:33:01 +01:00
|
|
|
#undef CPU_TO_FDT64
|
|
|
|
#undef CPU_TO_FDT32
|
|
|
|
#undef CPU_TO_FDT16
|
2012-04-10 17:00:15 +02:00
|
|
|
#undef EXTRACT_BYTE
|
2006-11-27 06:21:28 +01:00
|
|
|
|
2017-10-26 03:13:46 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <AvailabilityMacros.h>
|
|
|
|
|
|
|
|
/* strnlen() is not available on Mac OS < 10.7 */
|
|
|
|
# if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < \
|
|
|
|
MAC_OS_X_VERSION_10_7)
|
|
|
|
|
|
|
|
#define strnlen fdt_strnlen
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fdt_strnlen: returns the length of a string or max_count - which ever is
|
|
|
|
* smallest.
|
|
|
|
* Input 1 string: the string whose size is to be determined
|
|
|
|
* Input 2 max_count: the maximum value returned by this function
|
|
|
|
* Output: length of the string or max_count (the smallest of the two)
|
|
|
|
*/
|
|
|
|
static inline size_t fdt_strnlen(const char *string, size_t max_count)
|
|
|
|
{
|
|
|
|
const char *p = memchr(string, 0, max_count);
|
|
|
|
return p ? p - string : max_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED <
|
|
|
|
MAC_OS_X_VERSION_10_7) */
|
|
|
|
|
|
|
|
#endif /* __APPLE__ */
|
|
|
|
|
2017-10-18 08:22:40 +02:00
|
|
|
#endif /* LIBFDT_ENV_H */
|