From: Trent Piepho <tpiepho@kymetacorp.com>
To: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Cc: "barebox@lists.infradead.org" <barebox@lists.infradead.org>
Subject: Re: [PATCH 3/3] firmware: add support for compressed images
Date: Fri, 20 May 2016 17:51:14 +0000 [thread overview]
Message-ID: <1463766678.15779.45.camel@rtred1test09.kymeta.local> (raw)
In-Reply-To: <1463746903-6676-3-git-send-email-s.trumtrar@pengutronix.de>
On Fri, 2016-05-20 at 14:21 +0200, Steffen Trumtrar wrote:
> Allow using compressed firmware images with the firmware framework.
>
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> ---
> common/firmware.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 78 insertions(+), 4 deletions(-)
>
> diff --git a/common/firmware.c b/common/firmware.c
> index 664f9107d0f8..6437005bf813 100644
> --- a/common/firmware.c
> +++ b/common/firmware.c
> @@ -22,6 +22,8 @@
> #include <linux/list.h>
> #include <linux/stat.h>
> #include <linux/err.h>
> +#include <uncompress.h>
> +#include <filetype.h>
>
> #define BUFSIZ 4096
>
> @@ -197,16 +199,88 @@ out:
> }
>
> /*
> + * firmware_load_compressed - load a compressed firmware to a device
> + */
> +int firmwaremgr_load_compressed(const char *firmware, const char *dst)
> +{
> + int srcfd = 0;
> + int dstfd = 0;
> + int ret;
> +
> + srcfd = open(firmware, O_RDONLY);
> + if (srcfd < 0) {
> + printf("could not open %s: %s\n", firmware, errno_str());
> + ret = srcfd;
> + goto out;
> + }
Since the firmware was already opened, could the fd be passed to this
function so it doesn't need to be opened again?
> +
> + dstfd = open(dst, O_WRONLY | O_TRUNC);
> + if (dstfd < 0) {
> + printf("could not open %s: %s\n", dst, errno_str());
> + ret = dstfd;
> + goto out;
> + }
> +
> + ret = uncompress_fd_to_fd(srcfd, dstfd, uncompress_err_stdout);
> +
> +out:
> + if (dstfd > 0)
> + close(dstfd);
> +
> + return ret;
> +}
> +
> +/*
> * firmware_load_file - load a firmware to a device
> */
> int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware)
> {
> - int ret;
> - char *name = basprintf("/dev/%s", mgr->handler->id);
> + char *dst = basprintf("/dev/%s", mgr->handler->id);
> + enum filetype type;
> + int ret = -ENOENT;
> + int srcfd = 0;
> + char buf[32];
> +
> + if (firmware) {
> + srcfd = open(firmware, O_RDONLY);
> + if (srcfd < 0) {
> + printf("could not open %s: %s\n", firmware, errno_str());
> + ret = srcfd;
> + goto out;
> + }
>
> - ret = copy_file(firmware, name, 0);
> + ret = read(srcfd, buf, sizeof(buf));
> + if (ret < sizeof(buf))
> + goto out;
>
> - free(name);
> + type = file_detect_type(buf, 32);
> + if ((int)type < 0) {
> + printf("could not open %s: %s\n", firmware,
> + strerror(-type));
> + ret = (int)type;
> + goto out;
srcfd is not closed on the error path here.
> + }
> +
> + close(srcfd);
> +
> + switch (type) {
> + case filetype_lzo_compressed:
> + case filetype_lz4_compressed:
> + case filetype_bzip2:
> + case filetype_gzip:
This is missing xz compression.
Instead of trying to list all compressed types here, and also find the
compressed type of the file, would it make more sense to have the
uncompression code do this? This way it's not necessary to have a list
that matches what compression algorithms are supported and compiled in.
And uncompress() already reads the file header and determines if the
file type and if it can be uncompressed. So this code is basically an
incomplete copy of code already in uncompress.c.
> + ret = firmwaremgr_load_compressed(firmware, dst);
> + break;
> + case filetype_unknown:
> + ret = copy_file(firmware, dst, 0);
> + break;
> + default:
> + ret = -ENOSYS;
> + printf("unsupported filetype (%d)\n", (int) type);
> + }
> + }
> +
> +out:
> + free(dst);
>
> return ret;
> }
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-05-20 17:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-20 12:21 [PATCH 1/3] ARM: add fncpy.h from linux v4.6 Steffen Trumtrar
2016-05-20 12:21 ` [PATCH 2/3] firmware: socfpga: set APPLYCFG after loading bitstream Steffen Trumtrar
2016-05-20 18:24 ` Trent Piepho
2016-05-20 12:21 ` [PATCH 3/3] firmware: add support for compressed images Steffen Trumtrar
2016-05-20 17:51 ` Trent Piepho [this message]
2021-06-23 4:33 [PATCH 0/3] firmware: Add " Sascha Hauer
2021-06-23 4:33 ` [PATCH 3/3] firmware: add " 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=1463766678.15779.45.camel@rtred1test09.kymeta.local \
--to=tpiepho@kymetacorp.com \
--cc=barebox@lists.infradead.org \
--cc=s.trumtrar@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