From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 1/2] scripts: define le32_to_cpup and friends for host/target tools
Date: Thu, 20 Mar 2025 06:21:13 +0100 [thread overview]
Message-ID: <20250320052114.1732651-1-a.fatoum@pengutronix.de> (raw)
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
next reply other threads:[~2025-03-20 5:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-20 5:21 Ahmad Fatoum [this message]
2025-03-20 5:21 ` [PATCH v2 2/2] booti: sanity check image magic before parsing header Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250320052114.1732651-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox