From: "Lothar Waßmann" <LW@KARO-electronics.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 07/20] common: Generic firmware loader for file system
Date: Thu, 7 Dec 2017 08:49:36 +0100 [thread overview]
Message-ID: <20171207084936.199ddc98@karo-electronics.de> (raw)
In-Reply-To: <1512624561.3114.3.camel@intel.com>
Hi,
On Thu, 7 Dec 2017 05:29:24 +0000 Chee, Tien Fong wrote:
> On Rab, 2017-12-06 at 12:00 +0100, Lothar Waßmann wrote:
> > Hi,
> >
> > On Wed, 6 Dec 2017 10:06:21 +0000 Chee, Tien Fong wrote:
> > >
> > > On Sel, 2017-12-05 at 09:53 +0100, Lothar Waßmann wrote:
> > > >
> > > > Hi,
> > > >
> > > > On Tue, 5 Dec 2017 15:57:57 +0800 tien.fong.chee at intel.com
> > > > wrote:
> > > > >
> > > > >
> > > > > From: Tien Fong Chee <tien.fong.chee@intel.com>
> > > > >
> > > > > This is file system generic loader which can be used to load
> > > > > the file image from the storage into target such as memory.
> > > > > The consumer driver would then use this loader to program
> > > > > whatever,
> > > > > ie. the FPGA device.
> > > > >
> > > > > Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com>
> > > > > ---
> > > > > common/Makefile | 1 +
> > > > > common/fs_loader.c | 304
> > > > > ++++++++++++++++++++++++++++++++++++++++++++++++++++
> > > > > include/fs_loader.h | 30 ++++++
> > > > > 3 files changed, 335 insertions(+)
> > > > > create mode 100644 common/fs_loader.c
> > > > > create mode 100644 include/fs_loader.h
> > > > >
> > > > > diff --git a/common/Makefile b/common/Makefile
> > > > > index 801ea31..419e915 100644
> > > > > --- a/common/Makefile
> > > > > +++ b/common/Makefile
> > > > > @@ -130,3 +130,4 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
> > > > > obj-y += command.o
> > > > > obj-y += s_record.o
> > > > > obj-y += xyzModem.o
> > > > > +obj-y += fs_loader.o
> > > > > diff --git a/common/fs_loader.c b/common/fs_loader.c
> > > > > new file mode 100644
> > > > > index 0000000..04f682b
> > > > > --- /dev/null
> > > > > +++ b/common/fs_loader.c
> > > > > @@ -0,0 +1,304 @@
> > > > > +/*
> > > > > + * Copyright (C) 2017 Intel Corporation <www.intel.com>
> > > > > + *
> > > > > + * SPDX-License-Identifier: GPL-2.0
> > > > > + */
> > > > > +
> > > > > +#include <common.h>
> > > > > +#include <errno.h>
> > > > > +#include <fs.h>
> > > > > +#include <fs_loader.h>
> > > > > +#include <nand.h>
> > > > > +#include <sata.h>
> > > > > +#include <spi.h>
> > > > > +#include <spi_flash.h>
> > > > > +#include <spl.h>
> > > > > +#include <linux/string.h>
> > > > > +#include <usb.h>
> > > > > +
> > > > > +static struct device_location default_locations[] = {
> > > > > + {
> > > > > + .name = "mmc",
> > > > > + .devpart = "0:1",
> > > > > + },
> > > > > + {
> > > > > + .name = "usb",
> > > > > + .devpart = "0:1",
> > > > > + },
> > > > > + {
> > > > > + .name = "sata",
> > > > > + .devpart = "0:1",
> > > > > + },
> > > > > +};
> > > > > +
> > > > > +/* USB build is not supported yet in SPL */
> > > > > +#ifndef CONFIG_SPL_BUILD
> > > > > +#ifdef CONFIG_USB_STORAGE
> > > > > +static int init_usb(void)
> > > > > +{
> > > > > + int err = 0;
> > > > >
> > > > Useless initialization.
> > > >
> > > noted.
> > > >
> > > > >
> > > > >
> > > > > + err = usb_init();
> > > > > +
> > > > > + if (err)
> > > > >
> > > > Unnecessary blank line.
> > > >
> > > Sorry, i'm not catching you because there is no blank line between
> > > "if"
> > > and "return"
> > >
> > I meant the blank line between 'err = ...' and 'if (err)'
> >
> Okay, i can change that.
> > >
> > > >
> > > > >
> > > > >
> > > > > + if (!strcmp(default_locations[i].name, name))
> > > > > + default_locations[i].devpart =
> > > > > devpart;
> > > > > + }
> > > > > +
> > > > > + return;
> > > > > +}
> > > > > +
> > > > > +/*
> > > > > + * Prepare firmware struct;
> > > > > + * return -ve if fail.
> > > > > + */
> > > > > +static int _request_firmware_prepare(struct firmware
> > > > > **firmware_p,
> > > > > + const char *name, void
> > > > > *dbuf,
> > > > > + size_t size, u32 offset)
> > > > > +{
> > > > > + struct firmware *firmware = NULL;
> > > > > + int ret = 0;
> > > > > +
> > > > > + if (!name || name[0] == '\0')
> > > > > + ret = -EINVAL;
> > > > > +
> > > > Is it really useful to continue here initializing the 'firmware'
> > > > struct and returning an error at the end?
> > > >
> > > I try to keep it very close to Linux firmware loader. When more API
> > > ported in from Linux in future, this can be helper function.
> > > Anyway, i
> > > have no strong opinion, i can move to caller if you guys think that
> > > is
> > > better.
> > The Linux firmware loader has this:
> > >
> > > if (!name || name[0] == '\0') {
> > > ret = -EINVAL;
> > > goto out;
> > > }
> > Note the 'goto out' which is missing in your code.
> > If following the Linux code closely, you would have to set
> > *firmware_p
> > to NULL and exit in this case.
> >
> I can set the *firmware_p to NUll in failing case. But, i checked the
> static int _request_firmware_prepare in Linux, there is no goto out
> error handling method in the function. Fyi, there is no allocated
> memory release in U-Boot.
> https://elixir.free-electrons.com/linux/v4.13.15/source/drivers/base/fi
> rmware_class.c#L1191
> >
I was referring to _request_firmware() which calls
request_firmware_prepare() and does the checking of 'name' as your
code does.
Lothar Waßmann
next prev parent reply other threads:[~2017-12-07 7:49 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-05 7:57 [U-Boot] [PATCH v5 00/20] Add FPGA driver, SDRAM driver, generic firmware loader and booting U-Boot tien.fong.chee at intel.com
2017-12-05 7:57 ` [U-Boot] [PATCH v5 01/20] ARM: socfpga: Description on FPGA RBF properties at Arria 10 FPGA manager tien.fong.chee at intel.com
2017-12-05 7:57 ` [U-Boot] [PATCH v5 02/20] dts: Add FPGA bitstream properties to Arria 10 DTS tien.fong.chee at intel.com
2017-12-05 7:57 ` [U-Boot] [PATCH v5 03/20] arm: socfpga: Add Arria 10 SoCFPGA programming interface tien.fong.chee at intel.com
2017-12-05 7:57 ` [U-Boot] [PATCH v5 04/20] dts: Enable fpga-mgr node build for Arria 10 SPL tien.fong.chee at intel.com
2017-12-05 7:57 ` [U-Boot] [PATCH v5 05/20] fs: Enable generic filesystems interface support in SPL tien.fong.chee at intel.com
2017-12-05 7:57 ` [U-Boot] [PATCH v5 06/20] arm: socfpga: Remove static declaration on spl_mmc_find_device function tien.fong.chee at intel.com
2017-12-05 7:57 ` [U-Boot] [PATCH v5 07/20] common: Generic firmware loader for file system tien.fong.chee at intel.com
2017-12-05 8:53 ` Lothar Waßmann
2017-12-06 10:06 ` Chee, Tien Fong
2017-12-06 11:00 ` Lothar Waßmann
2017-12-07 5:29 ` Chee, Tien Fong
2017-12-07 7:49 ` Lothar Waßmann [this message]
2017-12-07 8:10 ` Chee, Tien Fong
2017-12-07 9:00 ` Lothar Waßmann
2017-12-08 5:25 ` Chee, Tien Fong
2017-12-08 8:22 ` Lothar Waßmann
2017-12-05 7:57 ` [U-Boot] [PATCH v5 08/20] arm: socfpga: Fix with the correct polling on bit is set tien.fong.chee at intel.com
2017-12-05 7:57 ` [U-Boot] [PATCH v5 09/20] arm: socfpga: Add FPGA drivers for Arria 10 FPGA loadfs tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 10/20] arm: socfpga: Rename the gen5 sdram driver to more specific name tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 11/20] arm: socfpga: Add DRAM bank size initialization function tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 12/20] arm: socfpga: Add DDR driver for Arria 10 tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 13/20] configs: Add DDR Kconfig support " tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 14/20] arm: socfpga: Enable SPL memory allocation tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 15/20] arm: socfpga: Improve comments for Intel SoCFPGA program header tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 16/20] arm: socfpga: Enhance Intel SoCFPGA program header to support Arria 10 tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 17/20] arm: socfpga: Adding clock frequency info for U-Boot tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 18/20] arm: socfpga: Adding SoCFPGA info for both SPL and U-Boot tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 19/20] arm: socfpga: Enable DDR working tien.fong.chee at intel.com
2017-12-05 7:58 ` [U-Boot] [PATCH v5 20/20] arm: socfpga: Enable SPL booting U-boot tien.fong.chee at intel.com
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=20171207084936.199ddc98@karo-electronics.de \
--to=lw@karo-electronics.de \
--cc=u-boot@lists.denx.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