From: Steffen Trumtrar <str@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Subject: [PATCH 13/13] firmware: add support for compressed images
Date: Thu, 21 Jan 2021 12:29:58 +0100 [thread overview]
Message-ID: <20210121112958.25937-13-str@pengutronix.de> (raw)
In-Reply-To: <20210121112958.25937-1-str@pengutronix.de>
From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
At least bitstreams for FPGAs can consist of a lot of zeros depending on
device utilization. These bitstreams can be compressed very effectively.
Let the firmware code accept these images and decompress them before
handing it to the firmware-manager in question.
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
common/firmware.c | 43 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/common/firmware.c b/common/firmware.c
index 58509d5da6..c617ecc0f1 100644
--- a/common/firmware.c
+++ b/common/firmware.c
@@ -14,6 +14,8 @@
#include <linux/list.h>
#include <linux/stat.h>
#include <linux/err.h>
+#include <uncompress.h>
+#include <filetype.h>
#define BUFSIZ 4096
@@ -211,12 +213,43 @@ out:
*/
int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware)
{
- int ret;
- char *name = basprintf("/dev/%s", mgr->handler->id);
-
- ret = copy_file(firmware, name, 0);
+ char *dst;
+ enum filetype type;
+ int ret = -ENOENT;
+ int srcfd = 0;
+ int dstfd = 0;
+
+ if (mgr->handler->id) {
+ dst = basprintf("/dev/%s", mgr->handler->id);
+ } else {
+ pr_err("id not defined for handler\n");
+ return -ENODEV;
+ }
- free(name);
+ if (firmware) {
+ type = file_name_detect_type(firmware);
+ if (type == filetype_unknown) {
+ ret = copy_file(firmware, dst, 0);
+ } else {
+ srcfd = open(firmware, O_RDONLY);
+ if (srcfd < 0)
+ return srcfd;
+ dstfd = open(dst, O_WRONLY | O_CREAT);
+
+ 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);
+
+ close(dstfd);
+ }
+ }
+out:
+ close(srcfd);
+ free(dst);
return ret;
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-01-21 11:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-21 11:29 [PATCH 01/13] ARM: add fncpy.h from linux v4.6 Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 02/13] ARM: mmu: inherit pte flags from pmd Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 03/13] firmware: socfpga: set APPLYCFG after loading bitstream Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 04/13] reset: add of_reset_control_get to header Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 05/13] drivers: add fpga bridge framework Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 06/13] drivers: fpga: add socfpga bridges Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 07/13] firmware: socfpga: change function prefixes Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 08/13] firmware: import fpga-mgr.h from linux Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 09/13] of: kconfig: of_overlay uses firmwaremgr_load_file Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 10/13] of: of_firmware: add support for fpga bridges Steffen Trumtrar
2021-01-25 9:52 ` Sascha Hauer
2021-01-26 8:47 ` Steffen Trumtrar
2021-01-26 11:02 ` Sascha Hauer
2021-01-21 11:29 ` [PATCH 11/13] commands: firmwareload: allow loading firmware from dt Steffen Trumtrar
2021-01-21 11:29 ` [PATCH 12/13] drivers: firmware: socfpga: remove bridges shutdown Steffen Trumtrar
2021-01-21 11:29 ` Steffen Trumtrar [this message]
2021-01-25 9:56 ` [PATCH 01/13] ARM: add fncpy.h from linux v4.6 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=20210121112958.25937-13-str@pengutronix.de \
--to=str@pengutronix.de \
--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