diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-03-17 16:14:32 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-04-01 10:38:55 +0200 |
commit | 7f73e64e8b369e655a322cd2877b5a1222f5b245 (patch) | |
tree | d4c6a932c6b889c84adc98e135b8c235f048ee66 | |
parent | b8837986a0a828577426c9d7eb41ca712bfca067 (diff) | |
download | barebox-7f73e64e8b369e655a322cd2877b5a1222f5b245.tar.gz barebox-7f73e64e8b369e655a322cd2877b5a1222f5b245.tar.xz |
imd: Add function to read parameters
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/imd.c | 31 | ||||
-rw-r--r-- | include/image-metadata.h | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/common/imd.c b/common/imd.c index 1cc4d719ec..241ebbdaed 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 33ca9c6bf6..0ba92469a4 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); |