[PATCH v2 1/2] scripts: define le32_to_cpup and friends for host/target tools
Sascha Hauer
s.hauer at pengutronix.de
Tue Mar 25 00:22:01 PDT 2025
On Thu, Mar 20, 2025 at 06:21:13AM +0100, Ahmad Fatoum wrote:
> We already define le32_to_cpu and friends, but were missing so far the
> p-suffixed variant, which accepts a pointer.
>
> This is easily implemented with a bit of macro boilerplate, so let's do
> that.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> v1 -> v2:
> - new patch
> ---
> scripts/compiler.h | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
This breaks compilation on riscv:
scripts/compiler.h:182:1: note: in expansion of macro 'DEFINE_CONV_P'
182 | DEFINE_CONV_P(be, 64)
| ^~~~~~~~~~~~~
scripts/compiler.h:170:55: error: unknown type name __be64'
170 | static inline u##bits cpu_to_##endian##bits##p(const __##endian##bits *p) \
| ^~
scripts/compiler.h:182:1: note: in expansion of macro 'DEFINE_CONV_P'
182 | DEFINE_CONV_P(be, 64)
| ^~~~~~~~~~~~~
I added a
#include <linux/types.h>
to scripts/compiler.h
Sascha
>
> diff --git a/scripts/compiler.h b/scripts/compiler.h
> index d8d0e1b906df..d6807b027e03 100644
> --- a/scripts/compiler.h
> +++ b/scripts/compiler.h
> @@ -160,6 +160,27 @@ typedef uint32_t __u32;
> # define be64_to_cpu(x) (x)
> #endif
>
> +#define DEFINE_CONV_P(endian, bits) \
> + static inline __##endian##bits endian##bits##_to_cpup(const u##bits *p) \
> + { \
> + u##bits val; \
> + memmove(&val, p, sizeof(val)); \
> + return endian##bits##_to_cpu(val); \
> + } \
> + static inline u##bits cpu_to_##endian##bits##p(const __##endian##bits *p) \
> + { \
> + __##endian##bits val; \
> + memmove(&val, p, sizeof(val)); \
> + return cpu_to_##endian##bits(val); \
> + }
> +
> +DEFINE_CONV_P(le, 16)
> +DEFINE_CONV_P(le, 32)
> +DEFINE_CONV_P(le, 64)
> +DEFINE_CONV_P(be, 16)
> +DEFINE_CONV_P(be, 32)
> +DEFINE_CONV_P(be, 64)
> +
> #ifndef min
> #define min(x, y) ({ \
> typeof(x) _min1 = (x); \
> --
> 2.39.5
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list