mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 6/7] imd: Add function to read parameters
Date: Tue, 29 Mar 2016 10:50:53 +0200	[thread overview]
Message-ID: <1459241454-21155-6-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1459241454-21155-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/imd.c             | 31 +++++++++++++++++++++++++++++++
 include/image-metadata.h |  1 +
 2 files changed, 32 insertions(+)

diff --git a/common/imd.c b/common/imd.c
index 06822bb..4b22f41 100644
--- a/common/imd.c
+++ b/common/imd.c
@@ -255,6 +255,37 @@ char *imd_concat_strings(struct imd_header *imd)
 	return str;
 }
 
+/**
+ * imd_get_param - get a parameter
+ * @imd: The IMD entry
+ * @name: The name of the parameter.
+ *
+ * Parameters have the IMD type IMD_TYPE_PARAMETER and the form
+ * "key=value". This function iterates over the IMD entries and when
+ * it finds a parameter with name "key" it returns the value found.
+ *
+ * Return: A pointer to the value or NULL if the string is not found
+ */
+const char *imd_get_param(struct imd_header *imd, const char *name)
+{
+	struct imd_header *cur;
+	int namelen = strlen(name);
+
+	imd_for_each(imd, cur) {
+		char *data = (char *)(cur + 1);
+
+		if (cur->type != IMD_TYPE_PARAMETER)
+			continue;
+		if (strncmp(name, data, namelen))
+			continue;
+		if (data[namelen] != '=')
+			continue;
+		return data + namelen + 1;
+	}
+
+	return NULL;
+}
+
 int imd_command_verbose;
 
 int imd_command(int argc, char *argv[])
diff --git a/include/image-metadata.h b/include/image-metadata.h
index 33ca9c6..0ba9246 100644
--- a/include/image-metadata.h
+++ b/include/image-metadata.h
@@ -84,6 +84,7 @@ struct imd_header *imd_get(void *buf, int size);
 const char *imd_string_data(struct imd_header *imd, int index);
 const char *imd_type_to_name(uint32_t type);
 char *imd_concat_strings(struct imd_header *imd);
+const char *imd_get_param(struct imd_header *imd, const char *name);
 
 extern int imd_command_verbose;
 int imd_command_setenv(const char *variable_name, const char *value);
-- 
2.7.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-03-29  8:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-29  8:50 [PATCH 1/7] imd: use struct imd_header * as argument Sascha Hauer
2016-03-29  8:50 ` [PATCH 2/7] imd: string returned from imd_string_data should be const Sascha Hauer
2016-03-29  9:34   ` Stefan Christ
2016-04-01  8:43     ` Sascha Hauer
2016-03-29  8:50 ` [PATCH 3/7] scripts: Add scripts/include/ to include path for target programs Sascha Hauer
2016-03-29  8:50 ` [PATCH 4/7] imd: rename imd_search_validate to imd_get Sascha Hauer
2016-03-29  8:50 ` [PATCH 5/7] imd: export functions Sascha Hauer
2016-03-29  8:50 ` Sascha Hauer [this message]
2016-03-29  8:50 ` [PATCH 7/7] bbu: print and evaluate image Metadata Sascha Hauer
2016-03-29  9:29   ` Stefan Christ
2016-04-01  8:41     ` 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=1459241454-21155-6-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@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