* [PATCH 1/3] ARM: add fncpy.h from linux v4.6
@ 2016-05-20 12:21 Steffen Trumtrar
2016-05-20 12:21 ` [PATCH 2/3] firmware: socfpga: set APPLYCFG after loading bitstream Steffen Trumtrar
2016-05-20 12:21 ` [PATCH 3/3] firmware: add support for compressed images Steffen Trumtrar
0 siblings, 2 replies; 5+ messages in thread
From: Steffen Trumtrar @ 2016-05-20 12:21 UTC (permalink / raw)
To: barebox; +Cc: Steffen Trumtrar
Description from the linux commit 5756e9dd0de6d5c307773f8f734c0684b3098fdd:
ARM: 6640/1: Thumb-2: Symbol manipulation macros for function body copying
In low-level board support code, there is sometimes a need to
copy a function body to another location at run-time.
A straightforward call to memcpy doesn't work in Thumb-2,
because bit 0 of external Thumb function symbols is set to 1,
indicating that the function is Thumb. Without corrective
measures, this will cause an off-by-one copy, and the copy
may be called using the wrong instruction set.
This patch adds an fncpy() macro to help with such copies.
Particular care is needed, because C doesn't guarantee any
defined behaviour when casting a function pointer to any other
type. This has been observed to lead to strange optimisation
side-effects when doing the arithmetic which is required in
order to copy/move function bodies correctly in Thumb-2.
Thanks to Russell King and Nicolas Pitre for their input
on this patch.
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
arch/arm/include/asm/fncpy.h | 82 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
create mode 100644 arch/arm/include/asm/fncpy.h
diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
new file mode 100644
index 000000000000..d13876bffa23
--- /dev/null
+++ b/arch/arm/include/asm/fncpy.h
@@ -0,0 +1,82 @@
+/*
+ * arch/arm/include/asm/fncpy.h - helper macros for function body copying
+ *
+ * Copyright (C) 2011 Linaro Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * These macros are intended for use when there is a need to copy a low-level
+ * function body into special memory.
+ *
+ * For example, when reconfiguring the SDRAM controller, the code doing the
+ * reconfiguration may need to run from SRAM.
+ *
+ * NOTE: that the copied function body must be entirely self-contained and
+ * position-independent in order for this to work properly.
+ *
+ * NOTE: in order for embedded literals and data to get referenced correctly,
+ * the alignment of functions must be preserved when copying. To ensure this,
+ * the source and destination addresses for fncpy() must be aligned to a
+ * multiple of 8 bytes: you will be get a BUG() if this condition is not met.
+ * You will typically need a ".align 3" directive in the assembler where the
+ * function to be copied is defined, and ensure that your allocator for the
+ * destination buffer returns 8-byte-aligned pointers.
+ *
+ * Typical usage example:
+ *
+ * extern int f(args);
+ * extern uint32_t size_of_f;
+ * int (*copied_f)(args);
+ * void *sram_buffer;
+ *
+ * copied_f = fncpy(sram_buffer, &f, size_of_f);
+ *
+ * ... later, call the function: ...
+ *
+ * copied_f(args);
+ *
+ * The size of the function to be copied can't be determined from C:
+ * this must be determined by other means, such as adding assmbler directives
+ * in the file where f is defined.
+ */
+
+#ifndef __ASM_FNCPY_H
+#define __ASM_FNCPY_H
+
+#include <linux/types.h>
+#include <linux/string.h>
+
+/*
+ * Minimum alignment requirement for the source and destination addresses
+ * for function copying.
+ */
+#define FNCPY_ALIGN 8
+
+#define fncpy(dest_buf, funcp, size) ({ \
+ uintptr_t __funcp_address; \
+ typeof(funcp) __result; \
+ \
+ asm("" : "=r" (__funcp_address) : "0" (funcp)); \
+ \
+ memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
+ \
+ asm("" : "=r" (__result) \
+ : "0" ((uintptr_t)(dest_buf) | (__funcp_address & 1))); \
+ \
+ __result; \
+})
+
+#endif /* !__ASM_FNCPY_H */
--
2.8.0.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] firmware: socfpga: set APPLYCFG after loading bitstream
2016-05-20 12:21 [PATCH 1/3] ARM: add fncpy.h from linux v4.6 Steffen Trumtrar
@ 2016-05-20 12:21 ` 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
1 sibling, 1 reply; 5+ messages in thread
From: Steffen Trumtrar @ 2016-05-20 12:21 UTC (permalink / raw)
To: barebox; +Cc: Steffen Trumtrar
If the FPGA-side of the SDRAM controller is reconfigured via the bitstream,
the APPLYCFG bit needs to be set, so the Controller applies the new setup.
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
arch/arm/mach-socfpga/include/mach/socfpga-regs.h | 1 +
drivers/firmware/Makefile | 2 +-
drivers/firmware/socfpga.c | 24 +++++++++++++++++++++++
drivers/firmware/socfpga_sdr.S | 17 ++++++++++++++++
4 files changed, 43 insertions(+), 1 deletion(-)
create mode 100644 drivers/firmware/socfpga_sdr.S
diff --git a/arch/arm/mach-socfpga/include/mach/socfpga-regs.h b/arch/arm/mach-socfpga/include/mach/socfpga-regs.h
index e88daf718917..1a7d787a27bf 100644
--- a/arch/arm/mach-socfpga/include/mach/socfpga-regs.h
+++ b/arch/arm/mach-socfpga/include/mach/socfpga-regs.h
@@ -18,5 +18,6 @@
#define CYCLONE5_SYSMGR_ADDRESS 0xffd08000
#define CYCLONE5_SCANMGR_ADDRESS 0xfff02000
#define CYCLONE5_SMP_TWD_ADDRESS 0xfffec600
+#define CYCLONE5_OCRAM_ADDRESS 0xffff0000
#endif /* __MACH_SOCFPGA_REGS_H */
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index c3a3c3400485..ac4f18bb3d78 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -1,2 +1,2 @@
obj-$(CONFIG_FIRMWARE_ALTERA_SERIAL) += altera_serial.o
-obj-$(CONFIG_FIRMWARE_ALTERA_SOCFPGA) += socfpga.o
+obj-$(CONFIG_FIRMWARE_ALTERA_SOCFPGA) += socfpga.o socfpga_sdr.o
diff --git a/drivers/firmware/socfpga.c b/drivers/firmware/socfpga.c
index a0cd2011cbce..a7a86a03d8fd 100644
--- a/drivers/firmware/socfpga.c
+++ b/drivers/firmware/socfpga.c
@@ -38,6 +38,7 @@
#include <mach/reset-manager.h>
#include <mach/socfpga-regs.h>
#include <mach/sdram.h>
+#include <asm/fncpy.h>
#define FPGAMGRREGS_STAT 0x0
#define FPGAMGRREGS_CTRL 0x4
@@ -77,6 +78,9 @@
#define CDRATIO_x4 0x2
#define CDRATIO_x8 0x3
+extern void socfpga_sdram_apply_static_cfg(void __iomem *sdrctrlgrp);
+extern void socfpga_sdram_apply_static_cfg_end(void *);
+
struct fpgamgr {
struct firmware_handler fh;
struct device_d dev;
@@ -353,6 +357,9 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
{
struct fpgamgr *mgr = container_of(fh, struct fpgamgr, fh);
int status;
+ unsigned int func_size = &socfpga_sdram_apply_static_cfg_end -
+ &socfpga_sdram_apply_static_cfg;
+ void (*ocram_func)(void __iomem *ocram_base);
/* Ensure the FPGA entering config done */
status = fpgamgr_program_poll_cd(mgr);
@@ -382,6 +389,23 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
return status;
}
+ /*
+ * When the f2sdram bridge is used in a bitstream, the configuration
+ * has to be latched into the SDR controller, when no transfers from
+ * or to the SDRAM happen. That means we need to run the code from
+ * OCRAM.
+ *
+ * Copy the assembler code for setting the bit to OCRAM and then
+ * execute the function.
+ */
+ dev_dbg(&mgr->dev, "Setting APPLYCFG bit...\n");
+
+ ocram_func = fncpy((void __iomem *)CYCLONE5_OCRAM_ADDRESS,
+ &socfpga_sdram_apply_static_cfg, func_size);
+
+ ocram_func((void __iomem *) (CYCLONE5_SDR_ADDRESS +
+ SDR_CTRLGRP_STATICCFG_ADDRESS));
+
return 0;
}
diff --git a/drivers/firmware/socfpga_sdr.S b/drivers/firmware/socfpga_sdr.S
new file mode 100644
index 000000000000..d634d6362722
--- /dev/null
+++ b/drivers/firmware/socfpga_sdr.S
@@ -0,0 +1,17 @@
+#include <linux/linkage.h>
+
+ .arch armv7-a
+ .arm
+
+/*
+ * r0 : sdram controller staticcfg
+ */
+
+ENTRY(socfpga_sdram_apply_static_cfg)
+ push {ip,lr}
+ ldr r1, [r0]
+ orr r1, r1, #8
+ str r1, [r0]
+ pop {ip,pc}
+ .align
+ENTRY(socfpga_sdram_apply_static_cfg_end)
--
2.8.0.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] firmware: socfpga: set APPLYCFG after loading bitstream
2016-05-20 12:21 ` [PATCH 2/3] firmware: socfpga: set APPLYCFG after loading bitstream Steffen Trumtrar
@ 2016-05-20 18:24 ` Trent Piepho
0 siblings, 0 replies; 5+ messages in thread
From: Trent Piepho @ 2016-05-20 18:24 UTC (permalink / raw)
To: Steffen Trumtrar; +Cc: barebox
On Fri, 2016-05-20 at 14:21 +0200, Steffen Trumtrar wrote:
> If the FPGA-side of the SDRAM controller is reconfigured via the bitstream,
> the APPLYCFG bit needs to be set, so the Controller applies the new setup.
Might want to mention how this patch uses the OCRAM.
Would an alternative method be to lock the cache line containing the
code in question?
In fact, since the instruction cache would be enabled, why would a
transfer to SDRAM be executing anyway? Is the issue that a cache
write-back could be in progress or the L2 controller could be filling
the rest of a cache line? If that's the case, then does copying only
the function where APPLYCFG bit is set fix that problem?
>
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> ---
> arch/arm/mach-socfpga/include/mach/socfpga-regs.h | 1 +
> drivers/firmware/Makefile | 2 +-
> drivers/firmware/socfpga.c | 24 +++++++++++++++++++++++
> drivers/firmware/socfpga_sdr.S | 17 ++++++++++++++++
> 4 files changed, 43 insertions(+), 1 deletion(-)
> create mode 100644 drivers/firmware/socfpga_sdr.S
>
> diff --git a/arch/arm/mach-socfpga/include/mach/socfpga-regs.h b/arch/arm/mach-socfpga/include/mach/socfpga-regs.h
> index e88daf718917..1a7d787a27bf 100644
> --- a/arch/arm/mach-socfpga/include/mach/socfpga-regs.h
> +++ b/arch/arm/mach-socfpga/include/mach/socfpga-regs.h
> @@ -18,5 +18,6 @@
> #define CYCLONE5_SYSMGR_ADDRESS 0xffd08000
> #define CYCLONE5_SCANMGR_ADDRESS 0xfff02000
> #define CYCLONE5_SMP_TWD_ADDRESS 0xfffec600
> +#define CYCLONE5_OCRAM_ADDRESS 0xffff0000
>
> #endif /* __MACH_SOCFPGA_REGS_H */
> diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
> index c3a3c3400485..ac4f18bb3d78 100644
> --- a/drivers/firmware/Makefile
> +++ b/drivers/firmware/Makefile
> @@ -1,2 +1,2 @@
> obj-$(CONFIG_FIRMWARE_ALTERA_SERIAL) += altera_serial.o
> -obj-$(CONFIG_FIRMWARE_ALTERA_SOCFPGA) += socfpga.o
> +obj-$(CONFIG_FIRMWARE_ALTERA_SOCFPGA) += socfpga.o socfpga_sdr.o
> diff --git a/drivers/firmware/socfpga.c b/drivers/firmware/socfpga.c
> index a0cd2011cbce..a7a86a03d8fd 100644
> --- a/drivers/firmware/socfpga.c
> +++ b/drivers/firmware/socfpga.c
> @@ -38,6 +38,7 @@
> #include <mach/reset-manager.h>
> #include <mach/socfpga-regs.h>
> #include <mach/sdram.h>
> +#include <asm/fncpy.h>
>
> #define FPGAMGRREGS_STAT 0x0
> #define FPGAMGRREGS_CTRL 0x4
> @@ -77,6 +78,9 @@
> #define CDRATIO_x4 0x2
> #define CDRATIO_x8 0x3
>
> +extern void socfpga_sdram_apply_static_cfg(void __iomem *sdrctrlgrp);
> +extern void socfpga_sdram_apply_static_cfg_end(void *);
> +
> struct fpgamgr {
> struct firmware_handler fh;
> struct device_d dev;
> @@ -353,6 +357,9 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
> {
> struct fpgamgr *mgr = container_of(fh, struct fpgamgr, fh);
> int status;
> + unsigned int func_size = &socfpga_sdram_apply_static_cfg_end -
> + &socfpga_sdram_apply_static_cfg;
> + void (*ocram_func)(void __iomem *ocram_base);
>
> /* Ensure the FPGA entering config done */
> status = fpgamgr_program_poll_cd(mgr);
> @@ -382,6 +389,23 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
> return status;
> }
>
> + /*
> + * When the f2sdram bridge is used in a bitstream, the configuration
> + * has to be latched into the SDR controller, when no transfers from
> + * or to the SDRAM happen. That means we need to run the code from
> + * OCRAM.
> + *
> + * Copy the assembler code for setting the bit to OCRAM and then
> + * execute the function.
> + */
> + dev_dbg(&mgr->dev, "Setting APPLYCFG bit...\n");
> +
> + ocram_func = fncpy((void __iomem *)CYCLONE5_OCRAM_ADDRESS,
> + &socfpga_sdram_apply_static_cfg, func_size);
I wonder if there is a way to use request_sdram_region() to make sure
barebox isn't using ocram? Like for the exception vectors, isn't it
possible to place them at this address (0xffff0000) instead of
0x00000000.
> +
> + ocram_func((void __iomem *) (CYCLONE5_SDR_ADDRESS +
> + SDR_CTRLGRP_STATICCFG_ADDRESS));
> +
> return 0;
> }
>
> diff --git a/drivers/firmware/socfpga_sdr.S b/drivers/firmware/socfpga_sdr.S
> new file mode 100644
> index 000000000000..d634d6362722
> --- /dev/null
> +++ b/drivers/firmware/socfpga_sdr.S
> @@ -0,0 +1,17 @@
> +#include <linux/linkage.h>
> +
> + .arch armv7-a
> + .arm
Is there a reason to force arm mode? It seems like it should be possible
to use whatever has been selected for barebox, arm or thumb2.
> +
> +/*
> + * r0 : sdram controller staticcfg
> + */
> +
> +ENTRY(socfpga_sdram_apply_static_cfg)
> + push {ip,lr}
What are the push and pop for? You don't modify lr or ip in this code.
> + ldr r1, [r0]
> + orr r1, r1, #8
> + str r1, [r0]
> + pop {ip,pc}
missing:
ENDPROC(socfpga_sdram_apply_static_cfg)
> + .align
ENTRY() includes an align.
> +ENTRY(socfpga_sdram_apply_static_cfg_end)
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] firmware: add support for compressed images
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 12:21 ` Steffen Trumtrar
2016-05-20 17:51 ` Trent Piepho
1 sibling, 1 reply; 5+ messages in thread
From: Steffen Trumtrar @ 2016-05-20 12:21 UTC (permalink / raw)
To: barebox; +Cc: Steffen Trumtrar
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;
+ }
+
+ 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;
+ }
+
+ close(srcfd);
+
+ switch (type) {
+ case filetype_lzo_compressed:
+ case filetype_lz4_compressed:
+ case filetype_bzip2:
+ case filetype_gzip:
+ 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;
}
--
2.8.0.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 3/3] firmware: add support for compressed images
2016-05-20 12:21 ` [PATCH 3/3] firmware: add support for compressed images Steffen Trumtrar
@ 2016-05-20 17:51 ` Trent Piepho
0 siblings, 0 replies; 5+ messages in thread
From: Trent Piepho @ 2016-05-20 17:51 UTC (permalink / raw)
To: Steffen Trumtrar; +Cc: barebox
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-05-20 18:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox