From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 8/8] FIT: Allow to open buffer as FIT image
Date: Wed, 31 Jan 2018 12:11:16 +0100 [thread overview]
Message-ID: <20180131111116.9638-9-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180131111116.9638-1-s.hauer@pengutronix.de>
This adds fit_open_buf() which can open a buffer as FIT image.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/image-fit.c | 113 +++++++++++++++++++++++++++++++++++++---------------
include/image-fit.h | 5 ++-
2 files changed, 85 insertions(+), 33 deletions(-)
diff --git a/common/image-fit.c b/common/image-fit.c
index 4ebd4b8c42..3fab52db2e 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -74,11 +74,11 @@ static int of_read_string_list(struct device_node *np, const char *name, struct
return prop ? 0 : -EINVAL;
}
-static int fit_digest(void *fit, struct digest *digest,
+static int fit_digest(const void *fit, struct digest *digest,
struct string_list *inc_nodes, struct string_list *exc_props,
uint32_t hashed_strings_start, uint32_t hashed_strings_size)
{
- struct fdt_header *fdt = fit;
+ const struct fdt_header *fdt = fit;
uint32_t dt_struct;
void *dt_strings;
struct fdt_header f = {};
@@ -313,7 +313,7 @@ static int fit_check_rsa_signature(struct device_node *sig_node,
/*
* The consistency of the FTD structure was already checked by of_unflatten_dtb()
*/
-static int fit_verify_signature(struct device_node *sig_node, void *fit)
+static int fit_verify_signature(struct device_node *sig_node, const void *fit)
{
uint32_t hashed_strings_start, hashed_strings_size;
struct string_list inc_nodes, exc_props;
@@ -690,61 +690,110 @@ void *fit_open_configuration(struct fit_handle *handle, const char *name)
return conf_node;
}
-struct fit_handle *fit_open(const char *filename, bool verbose,
- enum bootm_verify verify)
+static int fit_do_open(struct fit_handle *handle)
{
- struct fit_handle *handle = NULL;
const char *desc = "(no description)";
struct device_node *root;
+
+ root = of_unflatten_dtb(handle->fit);
+ if (IS_ERR(root))
+ return PTR_ERR(root);
+
+ handle->root = root;
+
+ handle->images = of_get_child_by_name(handle->root, "images");
+ if (!handle->images)
+ return -ENOENT;
+
+ handle->configurations = of_get_child_by_name(handle->root,
+ "configurations");
+
+ of_property_read_string(handle->root, "description", &desc);
+ pr_info("Opened FIT image: %s\n", desc);
+
+ return 0;
+}
+
+/**
+ * fit_open_buf - open a FIT image from a buffer
+ * @buf: The buffer containing the FIT image
+ * @size: Size of the FIT image
+ * @verbose: If true, be more verbose
+ * @verify: The verify mode
+ *
+ * This opens a FIT image found in buf. The returned handle is used as
+ * context for the other FIT functions.
+ *
+ * Return: A handle to a FIT image or a ERR_PTR
+ */
+struct fit_handle *fit_open_buf(const void *buf, size_t size, bool verbose,
+ enum bootm_verify verify)
+{
+ struct fit_handle *handle;
int ret;
handle = xzalloc(sizeof(struct fit_handle));
handle->verbose = verbose;
+ handle->fit = buf;
+ handle->size = size;
+ handle->verify = verify;
- ret = read_file_2(filename, &handle->size, &handle->fit, FILESIZE_MAX);
+ ret = fit_do_open(handle);
if (ret) {
- pr_err("unable to read %s: %s\n", filename, strerror(-ret));
- goto err;
+ fit_close(handle);
+ return ERR_PTR(ret);
}
- root = of_unflatten_dtb(handle->fit);
- if (IS_ERR(root)) {
- ret = PTR_ERR(root);
- goto err;
- }
+ return handle;
+}
- handle->root = root;
+/**
+ * fit_open - open a FIT image
+ * @filename: The filename of the FIT image
+ * @verbose: If true, be more verbose
+ * @verify: The verify mode
+ *
+ * This opens a FIT image found in @filename. The returned handle is used as
+ * context for the other FIT functions.
+ *
+ * Return: A handle to a FIT image or a ERR_PTR
+ */
+struct fit_handle *fit_open(const char *filename, bool verbose,
+ enum bootm_verify verify)
+{
+ struct fit_handle *handle;
+ int ret;
+
+ handle = xzalloc(sizeof(struct fit_handle));
+
+ handle->verbose = verbose;
handle->verify = verify;
- handle->images = of_get_child_by_name(handle->root, "images");
- if (!handle->images) {
- ret = -ENOENT;
- goto err;
+ ret = read_file_2(filename, &handle->size, &handle->fit_alloc,
+ FILESIZE_MAX);
+ if (ret) {
+ pr_err("unable to read %s: %s\n", filename, strerror(-ret));
+ return ERR_PTR(ret);
}
- handle->configurations = of_get_child_by_name(handle->root,
- "configurations");
+ handle->fit = handle->fit_alloc;
- of_property_read_string(handle->root, "description", &desc);
- pr_info("'%s': %s\n", filename, desc);
+ ret = fit_do_open(handle);
+ if (ret) {
+ fit_close(handle);
+ return ERR_PTR(ret);
+ }
return handle;
- err:
- if (handle->root)
- of_delete_node(handle->root);
- free(handle->fit);
- free(handle);
-
- return ERR_PTR(ret);
}
void fit_close(struct fit_handle *handle)
{
if (handle->root)
of_delete_node(handle->root);
- if (handle->fit)
- free(handle->fit);
+
+ free(handle->fit_alloc);
free(handle);
}
diff --git a/include/image-fit.h b/include/image-fit.h
index 79b8101b83..fc0883b5dc 100644
--- a/include/image-fit.h
+++ b/include/image-fit.h
@@ -22,7 +22,8 @@
#include <bootm.h>
struct fit_handle {
- void *fit;
+ const void *fit;
+ void *fit_alloc;
size_t size;
bool verbose;
@@ -35,6 +36,8 @@ struct fit_handle {
struct fit_handle *fit_open(const char *filename, bool verbose,
enum bootm_verify verify);
+struct fit_handle *fit_open_buf(const void *buf, size_t len, bool verbose,
+ enum bootm_verify verify);
void *fit_open_configuration(struct fit_handle *handle, const char *name);
int fit_has_image(struct fit_handle *handle, void *configuration,
const char *name);
--
2.15.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2018-01-31 11:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-31 11:11 [PATCH 0/8] FIT: Add support for opening images without a /configuration/ Sascha Hauer
2018-01-31 11:11 ` [PATCH 1/8] bootm: FIT: do not depend on FIT pre-opened images Sascha Hauer
2018-01-31 11:11 ` [PATCH 2/8] FIT: Do not pre-open images Sascha Hauer
2018-01-31 11:11 ` [PATCH 3/8] FIT: Let user specify the configuration to use Sascha Hauer
2018-01-31 11:11 ` [PATCH 4/8] FIT: store device_nodes in fit_handle Sascha Hauer
2018-01-31 11:11 ` [PATCH 5/8] FIT: move handle->verify check to fit_verify_hash() Sascha Hauer
2018-01-31 11:11 ` [PATCH 6/8] FIT: factor out some helper functions Sascha Hauer
2018-01-31 11:11 ` [PATCH 7/8] FIT: Implement opening images with no configuration Sascha Hauer
2018-01-31 11:11 ` Sascha Hauer [this message]
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=20180131111116.9638-9-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