[PATCH v2 1/2] scripts: define le32_to_cpup and friends for host/target tools
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Mar 19 22:21:13 PDT 2025
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(+)
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
More information about the barebox
mailing list