public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Chee, Tien Fong <tien.fong.chee@intel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v6 2/2] common: Generic firmware loader for file system
Date: Mon, 22 Jan 2018 07:11:37 +0000	[thread overview]
Message-ID: <1516605096.3256.7.camel@intel.com> (raw)
In-Reply-To: <f96b6054-ada7-4498-73eb-6f22d44036d7@denx.de>

On Thu, 2018-01-18 at 12:12 +0100, Marek Vasut wrote:
> On 01/18/2018 05:33 AM, Chee, Tien Fong wrote:
> > 
> > On Tue, 2018-01-16 at 15:41 +0100, Marek Vasut wrote:
> > > 
> > > On 12/27/2017 06:04 AM, tien.fong.chee at intel.com wrote:
> > > 
> > > Whoa, this improved substantially since last time I checked.
> > > Minor
> > > nitpicks below.
> > > 
> > > [...]
> > > 
> > > > 
> > > > 
> > > > +/* USB build is not supported yet in SPL */
> > > > +#ifndef CONFIG_SPL_BUILD
> > > > +#ifdef CONFIG_USB_STORAGE
> > > > +static int init_usb(void)
> > > > +{
> > > > +	int err;
> > > > +
> > > > +	err = usb_init();
> > > > +	if (err)
> > > > +		return err;
> > > > +
> > > > +#ifndef CONFIG_DM_USB
> > > > +	err = usb_stor_scan(1) < 0 ? -ENODEV : 0;
> > > if (err)
> > > 	return err;
> > > ?
> > > 
> > This is last line code of the function, so it's always return the
> > result regardless error or not.
> You are rewriting the true error code with -ENODEV instead of
> propagating it.
> 
Ohh....are you saying to change the codes as shown in below:

err = usb_stor_scan(1);
if (err)
return err;


> > > 
> > > > 
> > > > 
> > > > +#endif
> > > > +
> > > > +	return err;
> > > > +}
> > > > +#else
> > > > +static int init_usb(void)
> > > > +{
> > > > +	printf("Error: Cannot load flash image: no USB
> > > > support\n");
> > > debug() ? Fix globally ...
> > > 
> > okay.
> > > 
> > > > 
> > > > 
> > > > +	return -ENOSYS;
> > > > +}
> > > > +#endif
> > > > +#endif
> > > > +
> > > > +#ifdef CONFIG_SATA
> > > > +static int init_storage_sata(void)
> > > > +{
> > > > +	return sata_probe(0);
> > > > +}
> > > > +#else
> > > > +static int init_storage_sata(void)
> > > > +{
> > > > +	printf("Error: Cannot load image: no SATA support\n");
> > > > +	return -ENOSYS;
> > > > +}
> > > > +#endif
> > > > +
> > > > +#ifdef CONFIG_CMD_UBIFS
> > > > +static int mount_ubifs(struct device_location *location)
> > > > +{
> > > > +	int ret;
> > > > +	char cmd[32];
> > > > +
> > > > +	sprintf(cmd, "ubi part %s", location->mtdpart);
> > > snprintf() ...
> > > 
> > okay.
> > > 
> > > > 
> > > > 
> > > > +	ret = run_command(cmd, 0);
> > > > +	if (ret)
> > > > +		return ret;
> > > > +
> > > > +	sprintf(cmd, "ubifsmount %s", location->ubivol);
> > > > +
> > > > +	ret = run_command(cmd, 0);
> > > > +
> > > > +	return ret;
> > > > +}
> > > > +
> > > > +static int umount_ubifs(void)
> > > > +{
> > > > +	return run_command("ubifsumount", 0);
> > > Just call the function directly ?
> > > 
> > There are some checking like ubifs_initialized in the cmd/ubifs.c.
> > Direct callng the function would bypass those checking.
> Then factor those out into a function you can all and call that
> function.
> 
Just for curious, is it worth to factor those into a function? Does it
help to boost the performance or for other purpose?
> > 
> > > 
> > > > 
> > > > 
> > > > +}
> > > > +#else
> > > > +static int mount_ubifs(struct device_location *location)
> > > > +{
> > > > +	printf("Error: Cannot load image: no UBIFS
> > > > support\n");
> > > > +	return -ENOSYS;
> > > > +}
> > > > +#endif
> > > > +
> > > > +#if defined(CONFIG_SPL_MMC_SUPPORT) &&
> > > > defined(CONFIG_SPL_BUILD)
> > > > +static int init_mmc(void)
> > > > +{
> > > > +	/* Just for the case MMC is not yet initialized */
> > > > +	struct mmc *mmc = NULL;
> > > > +	int err;
> > > > +
> > > > +	spl_mmc_find_device(&mmc, spl_boot_device());
> > > > +
> > > > +	err = mmc_init(mmc);
> > > > +	if (err) {
> > > > +		printf("spl: mmc init failed with error:
> > > > %d\n",
> > > > err);
> > > > +		return err;
> > > > +	}
> > > > +
> > > > +	return err;
> > > > +}
> > > > +#else
> > > > +static int init_mmc(void)
> > > > +{
> > > > +	/* Expect somewhere already initialize MMC */
> > > > +	return 0;
> > > > +}
> > > > +#endif
> > > > +
> > > > +static int select_fs_dev(struct device_location *location)
> > > > +{
> > > > +	int ret;
> > > > +
> > > > +	if (!strcmp("mmc", location->name)) {
> > > > +		ret = fs_set_blk_dev("mmc", location->devpart,
> > > > FS_TYPE_ANY);
> > > > +	} else if (!strcmp("usb", location->name)) {
> > > > +		ret = fs_set_blk_dev("usb", location->devpart,
> > > > FS_TYPE_ANY);
> > > > +	} else if (!strcmp("sata", location->name)) {
> > > > +		ret = fs_set_blk_dev("sata", location-
> > > > >devpart,
> > > > FS_TYPE_ANY);
> > > > +	} else if (!strcmp("ubi", location->name)) {
> > > > +		if (location->ubivol != NULL)
> > > > +			ret = fs_set_blk_dev("ubi", NULL,
> > > > FS_TYPE_UBIFS);
> > > > +		else
> > > > +			ret = -ENODEV;
> > > > +	} else {
> > > > +		printf("Error: unsupported location
> > > > storage.\n");
> > > > +		return -ENODEV;
> > > > +	}
> > > > +
> > > > +	if (ret)
> > > > +		printf("Error: could not access storage.\n");
> > > > +
> > > > +	return ret;
> > > > +}
> > > > +
> > > > +static int init_storage_device(struct device_location
> > > > *location)
> > > > +{
> > > > +	int ret;
> > > > +
> > > > +	if (!strcmp("mmc", location->name)) {
> > > > +		ret = init_mmc();
> > > > +	} else if (!strcmp("sata", location->name)) {
> > > > +		ret = init_storage_sata();
> > > > +	} else if (location->ubivol != NULL) {
> > > > +		ret = mount_ubifs(location);
> > > > +#ifndef CONFIG_SPL_BUILD
> > > > +	/* USB build is not supported yet in SPL */
> > > > +	} else if (!strcmp("usb", location->name)) {
> > > > +		ret = init_usb();
> > > > +#endif
> > > > +	} else {
> > > > +		printf("Error: no supported storage device is
> > > > available.\n");
> > > > +		ret = -ENODEV;
> > > > +	}
> > > > +
> > > > +	return ret;
> > > > +}
> > > > +
> > > > +static void set_storage_devpart(char *name, char *devpart)
> > > > +{
> > > > +	size_t i;
> > > > +
> > > > +	for (i = 0; i < ARRAY_SIZE(default_locations); i++) {
> > > > +		if (!strcmp(default_locations[i].name, name))
> > > > +			default_locations[i].devpart =
> > > > devpart;
> > > > +	}
> > > > +}
> > > > +
> > > > +/*
> > > > + * Prepare firmware struct;
> > > > + * return -ve if fail.
> > > Use kerneldoc and keep it consistent.
> > > 
> > kerneldoc doesn't has explanation for this function, and this
> > function
> > is not for user. Or you means i shouldn't put the comment and
> > description to the function here?
> Kerneldoc specifies the format of the comment, so that documentation
> can
> be generated from it. If you document functions, use that format.
> 
Okay.
> > 
> > > 
> > > > 
> > > > 
> > > > + */
> > > > +static int _request_firmware_prepare(struct firmware
> > > > **firmware_p,
> > > > +				     const char *name, void
> > > > *dbuf,
> > > > +				     size_t size, u32 offset)
> > > > +{
> > > > +	struct firmware *firmware;
> > > > +	struct firmware_priv *fw_priv;
> > > > +
> > > > +	*firmware_p = NULL;
> > > > +
> > > > +	if (!name || name[0] == '\0')
> > > > +		return -EINVAL;
> > > > +
> > > > +	firmware = calloc(1, sizeof(*firmware));
> > > > +	if (!firmware) {
> > > > +		printf("%s: calloc(struct firmware) failed\n",
> > > > __func__);
> > > If malloc fails, you're screwed anyway and printf will likely
> > > fail
> > > too,
> > > so drop it.
> > > 
> > okay.
> > > 
> > > > 
> > > > 
> > > > +		return -ENOMEM;
> > > > +	}
> > > > +
> > > > +	fw_priv = calloc(1, sizeof(*fw_priv));
> > > > +	if (!fw_priv) {
> > > > +		printf("%s: calloc(struct fw_priv) failed\n",
> > > > __func__);
> > > > +		free(firmware);
> > > > +		return -ENOMEM;
> > > > +	}
> > > > +
> > > > +	fw_priv->name = name;
> > > > +	fw_priv->offset = offset;
> > > > +	firmware->data = dbuf;
> > > > +	firmware->size = size;
> > > > +	firmware->priv = fw_priv;
> > > > +	*firmware_p = firmware;
> > > > +
> > > > +	return 0;
> > > > +}
> > > [...]
> 

  reply	other threads:[~2018-01-22  7:11 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-27  5:04 [U-Boot] [PATCH v6 0/2] Generic firmware loader tien.fong.chee at intel.com
2017-12-27  5:04 ` [U-Boot] [PATCH v6 1/2] spl: Remove static declaration on spl_mmc_find_device function tien.fong.chee at intel.com
2018-01-15 16:35   ` [U-Boot] [U-Boot, v6, " Tom Rini
2017-12-27  5:04 ` [U-Boot] [PATCH v6 2/2] common: Generic firmware loader for file system tien.fong.chee at intel.com
2018-01-15 16:36   ` [U-Boot] [U-Boot, v6, " Tom Rini
2018-01-16  7:58     ` Chee, Tien Fong
2018-01-16 14:35       ` Tom Rini
2018-01-18  3:42         ` Chee, Tien Fong
2018-01-18 13:18           ` Tom Rini
2018-01-22  6:37             ` Chee, Tien Fong
2018-01-16 14:41   ` [U-Boot] [PATCH v6 " Marek Vasut
2018-01-18  4:33     ` Chee, Tien Fong
2018-01-18 11:12       ` Marek Vasut
2018-01-22  7:11         ` Chee, Tien Fong [this message]
2018-01-22  8:44           ` Lothar Waßmann
2018-01-23  4:28             ` Chee, Tien Fong
2018-01-22 12:41           ` Marek Vasut
2018-01-18  5:57   ` Simon Goldschmidt
2018-01-22  8:08     ` Chee, Tien Fong
2018-01-22 11:41       ` Simon Goldschmidt
2018-01-23  6:28         ` Chee, Tien Fong
2018-01-23  7:52           ` Simon Goldschmidt
2018-01-23  7:58   ` Simon Goldschmidt
2018-01-23  8:31     ` Chee, Tien Fong
2018-01-23  9:13       ` Simon Goldschmidt
2018-01-24  5:13         ` Chee, Tien Fong
2018-01-24  5:34           ` Simon Goldschmidt
2018-01-03  8:46 ` [U-Boot] [PATCH v6 0/2] Generic firmware loader Chee, Tien Fong
2018-01-08  8:07   ` Lothar Waßmann
2018-01-09  5:26     ` Chee, Tien Fong
2018-01-15  6:57     ` Chee, Tien Fong
2018-01-15  6:50 ` Chee, Tien Fong

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=1516605096.3256.7.camel@intel.com \
    --to=tien.fong.chee@intel.com \
    --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