From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lothar =?UTF-8?B?V2HDn21hbm4=?= Date: Mon, 18 Dec 2017 08:39:51 +0100 Subject: [U-Boot] [PATCH v4 2/2] common: Generic firmware loader for file system In-Reply-To: <1513573856-28074-3-git-send-email-tien.fong.chee@intel.com> References: <1513573856-28074-1-git-send-email-tien.fong.chee@intel.com> <1513573856-28074-3-git-send-email-tien.fong.chee@intel.com> Message-ID: <20171218083951.370d2373@karo-electronics.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi, On Mon, 18 Dec 2017 13:10:56 +0800 tien.fong.chee at intel.com wrote: > From: Tien Fong Chee >=20 > 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. >=20 > Signed-off-by: Tien Fong Chee > --- > common/Makefile | 1 + > common/fs_loader.c | 311 +++++++++++++++++++++++++++++++++++++++= ++++++ > doc/README.firmware_loader | 77 +++++++++++ > include/fs_loader.h | 28 ++++ > 4 files changed, 417 insertions(+) > create mode 100644 common/fs_loader.c > create mode 100644 doc/README.firmware_loader > create mode 100644 include/fs_loader.h >=20 [...] > diff --git a/common/fs_loader.c b/common/fs_loader.c > new file mode 100644 > index 0000000..81cf5d6 > --- /dev/null > +++ b/common/fs_loader.c [...] > +/* > + * 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 =3D NULL; > + struct firmware_priv *fw_priv =3D NULL; > + > + *firmware_p =3D NULL; > + > + if (!name || name[0] =3D=3D '\0') > + return -EINVAL; > + > + *firmware_p =3D firmware =3D calloc(1, sizeof(*firmware)); > + > + if (!firmware) { > + printf("%s: calloc(struct firmware) failed\n", __func__); > + return -ENOMEM; > + } > + > + fw_priv =3D calloc(1, sizeof(*fw_priv)); > + > + if (!fw_priv) { > + printf("%s: calloc(struct fw_priv) failed\n", __func__); > + return -ENOMEM; What about freeing 'firmware' and NULLing *firmware_p here? Or better, do the assignment of *firmware_p at the end. > + } > + > + fw_priv->name =3D name; > + fw_priv->offset =3D offset; > + firmware->data =3D dbuf; > + firmware->size =3D size; > + firmware->priv =3D fw_priv; > + > + return 0; > +} > + > +/* > + * fw_get_filesystem_firmware - load firmware into an allocated buffer > + * @location: An array of supported firmware location > + * @firmware_p: pointer to firmware image > + * > + * @return: size of total read > + * -ve when error > + */ > +static int fw_get_filesystem_firmware(struct device_location *location, > + struct firmware *firmware_p) > +{ > + struct firmware_priv *fw_priv =3D NULL; > + loff_t actread; > + char *dev_part; > + int ret; > + > + dev_part =3D env_get("FW_DEV_PART"); > + if (dev_part) > + set_storage_devpart(location->name, dev_part); > + > + ret =3D init_storage_device(location); > + if (ret) > + goto out; > + > + select_fs_dev(location); > + if (ret) > + goto out; > + > + fw_priv =3D (struct firmware_priv *)firmware_p->priv; > + useless type cast. > + ret =3D fs_read(fw_priv->name, (ulong)firmware_p->data, fw_priv->offset, > + firmware_p->size, &actread); > + > + if (ret || (actread !=3D firmware_p->size)) { > + printf("Error: %d Failed to read %s from flash %lld !=3D %d.\n", > + ret, fw_priv->name, actread, firmware_p->size); > + return -EPERM; Quoting myself from an earlier mail (20171212091442.2f6826fe at karo-electronics.de): |That's definitely not the right return code in this situation. |If 'ret' is !=3D 0 you should return 'ret', otherwise EIO is more |appropriate here. Lothar Wa=C3=9Fmann