u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 3/5] mtdparts: show net size in mtdparts list
Date: Mon, 30 Aug 2010 15:50:16 -0500	[thread overview]
Message-ID: <20100830155016.38f19def@schlenkerla.am.freescale.net> (raw)
In-Reply-To: <dd55869c0dce98258874d18c6c9c9a4e0d3d871b.1283187599.git.bengardiner@nanometrics.ca>

On Mon, 30 Aug 2010 13:38:58 -0400
Ben Gardiner <bengardiner@nanometrics.ca> wrote:

> +#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
>  /**
> - * Format and print out a partition list for each device from global device
> - * list.
> + * Get the net size (w/o bad blocks) of the given partition.
> + *
> + * @param mtd the mtd info
> + * @param part the partition
> + * @return the calculated net size of this partition
>   */
> -static void list_partitions(void)
> +static uint64_t net_part_size(struct mtd_info *mtd, struct part_info *part)
> +{
> +	uint64_t gross_size, trailing_bad_size = 0;
> +	int truncated = 0;
> +
> +	mtd_get_len_incl_bad(mtd, part->offset, part->size, &gross_size,
> +			     &truncated);
> +
> +	if (!truncated) {
> +			mtd_get_len_incl_bad(mtd, part->offset + part->size,
> +					     mtd->erasesize, &trailing_bad_size,
> +					     &truncated);
> +			trailing_bad_size -= mtd->erasesize;
> +	}
> +
> +	return part->size - (gross_size - trailing_bad_size - part->size);

I'm not sure I follow the logic here...

You're trying to find net size given gross size, but you first treat
the gross size as a net size and get the gross size of *that*.

If it was truncated, then you'll return a value that
is still probably greater than the partition's true net size.  For
example, suppose you called this on the final partition, which includes
at least one bad block (or the BBT, which is marked bad).
mtd_get_len_incl_bad() will return the full partition size and set
truncated.  You'll end up with part->size - (part->size - 0 -
part->size), which evaluates to part->size.  The function should have
returned something less than part->size.

If it was not truncated, suppose the partition had two bad blocks, and
the next partition had its second block bad.  mtd_get_len_incl_bad()
will return part->size plus 3, since it ran into the next partition's
bad block.  The second call to mtd_get_len_incl_bad() will return one
block, since it never got to the next partition's second block.  Thus
net_part_size() will return part->size - ((part->size + 3) - 0 -
part->size), or part->size - 3.  The right answer was part->size - 2.

I don't think a net-to-gross transformation is useful as a base for a
gross-to-net transformation.

> +}
> +#endif
> +
> +static void print_partition_table(void)
>  {
>  	struct list_head *dentry, *pentry;
>  	struct part_info *part;
>  	struct mtd_device *dev;
>  	int part_num;
>  
> -	debug("\n---list_partitions---\n");
> -	list_for_each(dentry, &devices) {
> +list_for_each(dentry, &devices) {

Wrong indentation.

>  		dev = list_entry(dentry, struct mtd_device, link);
> +		/* list partitions for given device */
> +		part_num = 0;
> +#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
> +		struct mtd_info *mtd;
> +
> +		if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
> +			return;
> +
> +		printf("\ndevice %s%d <%s>, # parts = %d\n",
> +				MTD_DEV_TYPE(dev->id->type), dev->id->num,
> +				dev->id->mtd_id, dev->num_parts);
> +		printf(" #: name\t\tsize\t\tnet size\toffset\t\tmask_flags\n");
> +
> +		list_for_each(pentry, &dev->parts) {
> +			u32 net_size;
> +			char *size_note;
> +
> +			part = list_entry(pentry, struct part_info, link);
> +			net_size = net_part_size(mtd, part);
> +			size_note = part->size == net_size ? " " : " (!)";
> +			printf("%2d: %-20s0x%08x\t0x%08x%s\t0x%08x\t%d\n",
> +					part_num, part->name, part->size,
> +					net_size, size_note, part->offset,
> +					part->mask_flags);
> +#else /* !defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
>  		printf("\ndevice %s%d <%s>, # parts = %d\n",
>  				MTD_DEV_TYPE(dev->id->type), dev->id->num,
>  				dev->id->mtd_id, dev->num_parts);
>  		printf(" #: name\t\tsize\t\toffset\t\tmask_flags\n");
>  
> -		/* list partitions for given device */
> -		part_num = 0;
>  		list_for_each(pentry, &dev->parts) {
>  			part = list_entry(pentry, struct part_info, link);
>  			printf("%2d: %-20s0x%08x\t0x%08x\t%d\n",
>  					part_num, part->name, part->size,
>  					part->offset, part->mask_flags);
> -
> +#endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */

I'll let Wolfgang speak up if this really is how he wants it done, but
this seems like too much duplication to me.  And what if someone else
wants to add another optional field, do we end up with 4 versions?
Then 8 versions the next time?

Is this really worth ifdeffing at all?

> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index cb86657..211b993 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -143,7 +143,8 @@ void put_mtd_device(struct mtd_info *mtd)
>  	BUG_ON(c < 0);
>  }
>  
> -#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
> +#if defined(CONFIG_CMD_MTDPARTS_SPREAD) || \
> +    defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
>  /**
>   * mtd_get_len_incl_bad
>   *

Let's avoid stuff like this -- I'd define the function
unconditionally.  IMHO, the right solution to saving space from unused
functions is function-sections/gc-sections.

-Scott

  reply	other threads:[~2010-08-30 20:50 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-06 16:28 [U-Boot-Users] [PATCH, resend] Support dynamic/patched NAND ENV offset Harald Welte
2008-07-07 18:47 ` Scott Wood
2008-07-08  0:09   ` Harald Welte
2008-07-08 16:05     ` Scott Wood
2008-07-08 21:12       ` Wolfgang Denk
2008-07-09  0:23         ` Harald Welte
2008-07-09  7:05           ` Wolfgang Denk
2008-07-09  7:25             ` Harald Welte
2008-07-09  8:04               ` Wolfgang Denk
2008-07-09 12:13                 ` Harald Welte
2010-06-01 20:23                 ` [U-Boot] mtdparts: add bad-block skipping Ben Gardiner
2010-06-01 22:20                   ` Wolfgang Denk
2010-06-01 22:34                   ` Wolfgang Denk
2010-06-02  5:08                     ` Ben Gardiner
2010-06-02 15:58                   ` [U-Boot] [PATCH 0/4 v2] " Ben Gardiner
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 0/4] " Ben Gardiner
2010-07-12 19:06                       ` Ben Gardiner
2010-08-09 20:43                       ` [U-Boot] [PATCH v4 " Ben Gardiner
2010-08-30 17:38                         ` [U-Boot] [PATCH v5 0/5] " Ben Gardiner
2010-08-30 17:38                           ` [U-Boot] [PATCH v5 2/5] mtd: add an mtd method for get_len_incl_bad() Ben Gardiner
2010-08-30 20:57                             ` Scott Wood
2010-08-31 13:50                               ` Ben Gardiner
2010-08-31 21:48                             ` [U-Boot] [PATCH v6 " Ben Gardiner
     [not found]                           ` <1283185640-0-git-send-email-bengardiner@nanometrics.ca>
2010-08-30 17:38                             ` [U-Boot] [PATCH v5 3/5] mtdparts: show net size in mtdparts list Ben Gardiner
2010-08-30 20:50                               ` Scott Wood [this message]
2010-08-31 13:51                                 ` Ben Gardiner
2010-08-31 15:57                                   ` Scott Wood
2010-08-31 21:48                               ` [U-Boot] [PATCH v6 " Ben Gardiner
2010-08-31 21:47                           ` [U-Boot] [PATCH v6 0/5] mtdparts: add bad-block skipping Ben Gardiner
2010-09-09 20:54                             ` Scott Wood
2010-08-09 20:43                       ` [U-Boot] [PATCH v4 1/4] mtdparts: regroup calls to get_mtd_device_nm Ben Gardiner
2010-08-09 20:43                       ` [U-Boot] [PATCH v4 2/4] mtdparts: show net size in mtdparts list Ben Gardiner
2010-08-26 18:57                         ` Scott Wood
2010-08-27 13:51                           ` Ben Gardiner
2010-08-27 15:44                           ` Ben Gardiner
2010-08-27 16:02                             ` Scott Wood
2010-08-27 16:45                               ` Ben Gardiner
2010-08-09 20:43                       ` [U-Boot] [PATCH v4 3/4] mtdparts: add new sub-command "spread" Ben Gardiner
2010-08-26 21:12                         ` Scott Wood
2010-08-27 13:51                           ` Ben Gardiner
2010-08-27 21:36                             ` Ben Gardiner
2010-08-27 21:46                               ` Scott Wood
2010-08-27 21:52                                 ` Ben Gardiner
2010-08-27 21:59                                 ` Scott Wood
2010-08-28  3:59                                   ` Ben Gardiner
2010-08-30 20:24                                     ` Scott Wood
2010-08-30 20:30                                       ` Ben Gardiner
2010-08-30 17:38                         ` [U-Boot] [PATCH v5 4/5] " Ben Gardiner
2010-08-30 21:01                           ` Scott Wood
2010-08-30 21:05                             ` Scott Wood
2010-08-31 13:51                             ` Ben Gardiner
2010-08-31 21:48                           ` [U-Boot] [PATCH v6 " Ben Gardiner
2010-08-09 20:44                       ` [U-Boot] [PATCH v4 4/4] mtdparts: new add.spread: add part skipping bad blocks Ben Gardiner
2010-08-26 22:26                         ` Scott Wood
2010-08-27 13:52                           ` Ben Gardiner
2010-08-30 17:39                         ` [U-Boot] [PATCH v5 5/5] " Ben Gardiner
2010-08-31 21:48                           ` [U-Boot] [PATCH v6 " Ben Gardiner
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 1/4] mtdparts: regroup calls to get_mtd_device_nm Ben Gardiner
2010-08-30 17:38                       ` [U-Boot] [PATCH v5 1/5] " Ben Gardiner
2010-08-31 21:48                         ` [U-Boot] [PATCH v6 " Ben Gardiner
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 2/4] mtdparts: show net size in mtdparts list Ben Gardiner
2010-08-07 20:08                       ` Wolfgang Denk
2010-08-08  4:06                         ` Harald Welte
2010-08-08 13:16                           ` Wolfgang Denk
2010-08-09 14:45                         ` Ben Gardiner
2010-09-18 19:42                           ` Wolfgang Denk
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 3/4] mtdparts: add new sub-command "spread" Ben Gardiner
2010-08-07 20:12                       ` Wolfgang Denk
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 4/4] mtdparts: new add.e: add part skipping bad blocks Ben Gardiner
2010-08-07 20:16                       ` Wolfgang Denk
2010-06-02 15:58                   ` [U-Boot] [PATCH 1/4 v2] mtdparts: regroup calls to get_mtd_device_nm Ben Gardiner
2010-06-02 15:58                   ` [U-Boot] [PATCH 2/4 v2] mtdparts: show net size in mtdparts list Ben Gardiner
2010-06-02 15:58                   ` [U-Boot] [PATCH 3/4 v2] mtdparts: add new sub-command "spread" Ben Gardiner
2010-06-02 15:58                   ` [U-Boot] [PATCH 4/4 v2] mtdparts: new add.e: add part skipping bad blocks Ben Gardiner
2010-08-09 18:25                     ` Scott Wood
2010-08-09 18:39                       ` Ben Gardiner
2010-08-09 18:51                         ` Scott Wood
2010-06-01 20:23                 ` [U-Boot] [PATCH 1/4] mtdparts: regroup calls to get_mtd_device_nm Ben Gardiner
2010-06-02  7:06                   ` Stefan Roese
2010-06-01 20:23                 ` [U-Boot] [PATCH 2/4] mtdparts: show net size in mtdparts list Ben Gardiner
2010-06-02  7:15                   ` Stefan Roese
2010-06-01 20:23                 ` [U-Boot] [PATCH 3/4] mtdparts: add new sub-command "spread" Ben Gardiner
2010-06-01 20:23                 ` [U-Boot] [PATCH 4/4] mtdparts: new add.e: add part skipping bad blocks Ben Gardiner
2008-07-09  0:18       ` [U-Boot-Users] [PATCH, resend] Support dynamic/patched NAND ENV offset Harald Welte
2008-07-09  5:28       ` Harald Welte
2008-07-09  7:07         ` Harald Welte
2008-07-09  8:11       ` [U-Boot-Users] [PATCH] " Harald Welte
2008-07-11 17:28         ` Scott Wood
2010-05-17 21:04           ` [U-Boot] [PATCH] NAND: Support dynamic location of enviromnent (CONFIG_ENV_OFFSET_OOB) Ben Gardiner
2010-05-26 22:58             ` Scott Wood
2010-05-26 23:38               ` Ben Gardiner
2010-05-31 21:29               ` [U-Boot] [PATCH v2] NAND: environment offset in OOB (CONFIG_ENV_OFFSET_OOB) Ben Gardiner
2010-06-30 21:32                 ` [U-Boot] [PATCH v3] " Ben Gardiner
2010-06-30 21:41                   ` Wolfgang Denk
2010-07-01  4:09                     ` Ben Gardiner
2010-07-01  3:37                   ` Vipin KUMAR
2010-07-01  5:29                     ` Ben Gardiner
2010-07-01  7:17                   ` Harald Welte
2010-07-05 13:57                     ` Ben Gardiner
2010-07-05 17:27                     ` [U-Boot] [PATCH v4] " Ben Gardiner
2010-07-12 16:17                       ` Ben Gardiner
2010-07-12 16:19                         ` Scott Wood
2010-07-13 19:26                       ` Scott Wood
2010-07-13 21:17                         ` Ben Gardiner

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=20100830155016.38f19def@schlenkerla.am.freescale.net \
    --to=scottwood@freescale.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;
as well as URLs for NNTP newsgroup(s).