mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] scripts: define le32_to_cpup and friends for host/target tools
@ 2025-03-20  5:21 Ahmad Fatoum
  2025-03-20  5:21 ` [PATCH v2 2/2] booti: sanity check image magic before parsing header Ahmad Fatoum
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-03-20  5:21 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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@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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-20  5:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-20  5:21 [PATCH v2 1/2] scripts: define le32_to_cpup and friends for host/target tools Ahmad Fatoum
2025-03-20  5:21 ` [PATCH v2 2/2] booti: sanity check image magic before parsing header Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox