mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: mfe@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] env: export getenv_ullx() helper
Date: Wed, 28 Feb 2024 18:51:28 +0100	[thread overview]
Message-ID: <20240228175128.2734265-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240228175128.2734265-1-a.fatoum@pengutronix.de>

getenv_ull() will parse values according to prefix:

  - If it starts with 0x, it's hexadecimal
  - If it's just 0, it's octal
  - otherwise, it's decimal

Some variables like i.MX8M soc0.soc_uid are hexadecimal without leading
0x. Therefore add a getenv_ullx helper, so code that used to do:

  uid = imx8m_uid();

can be replaced with

  getenv_ullx("soc0.soc_uid", &uid);

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/env.c          | 15 +++++++++++++--
 include/environment.h |  6 ++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/common/env.c b/common/env.c
index d673b061ab7a..b68e998e46b1 100644
--- a/common/env.c
+++ b/common/env.c
@@ -343,17 +343,28 @@ const char *getenv_nonempty(const char *var)
 }
 EXPORT_SYMBOL(getenv_nonempty);
 
-int getenv_ull(const char *var , unsigned long long *val)
+static int getenv_ull_base(const char *var, int base, unsigned long long *val)
 {
 	const char *valstr = getenv(var);
 
 	if (!valstr || !*valstr)
 		return -EINVAL;
 
-	*val = simple_strtoull(valstr, NULL, 0);
+	*val = simple_strtoull(valstr, NULL, base);
 
 	return 0;
 }
+
+int getenv_ull(const char *var , unsigned long long *val)
+{
+	return getenv_ull_base(var, 0, val);
+}
+EXPORT_SYMBOL(getenv_ull);
+
+int getenv_ullx(const char *var , unsigned long long *val)
+{
+	return getenv_ull_base(var, 16, val);
+}
 EXPORT_SYMBOL(getenv_ull);
 
 int getenv_ul(const char *var , unsigned long *val)
diff --git a/include/environment.h b/include/environment.h
index 1557c3a1d730..8b143c16b7ad 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -35,6 +35,7 @@ int setenv(const char *, const char *);
 int pr_setenv(const char *, const char *fmt, ...)  __attribute__ ((format(__printf__, 2, 3)));
 void export_env_ull(const char *name, unsigned long long val);
 int getenv_ull(const char *name, unsigned long long *val);
+int getenv_ullx(const char *name, unsigned long long *val);
 int getenv_ul(const char *name, unsigned long *val);
 int getenv_uint(const char *name, unsigned int *val);
 int getenv_bool(const char *var, int *val);
@@ -63,6 +64,11 @@ static inline int getenv_ull(const char *name, unsigned long long *val)
 	return -EINVAL;
 }
 
+static inline int getenv_ullx(const char *name, unsigned long long *val)
+{
+	return -EINVAL;
+}
+
 static inline int getenv_ul(const char *name, unsigned long *val)
 {
 	return -EINVAL;
-- 
2.39.2




  reply	other threads:[~2024-02-28 17:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 17:51 [PATCH 1/2] ARM: i.MX8M: drop function prototype for removed imx8m_uid Ahmad Fatoum
2024-02-28 17:51 ` Ahmad Fatoum [this message]
2024-02-29  8:20 ` Sascha Hauer

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=20240228175128.2734265-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=mfe@pengutronix.de \
    /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