From: <Tudor.Ambarus@microchip.com>
To: <michael@walle.cc>, <js07.lee@samsung.com>
Cc: linux-mtd@lists.infradead.org, vigneshr@ti.com, js07.lee@gmail.com
Subject: Re: [PATCH v3 2/3] mtd: spi-nor: add 4bit block protection support
Date: Fri, 21 Feb 2020 09:30:22 +0000 [thread overview]
Message-ID: <21102931.kdR8orL0iI@localhost.localdomain> (raw)
In-Reply-To: <9aaabe654603679dffdbf4c57bcfe0ff@walle.cc>
On Thursday, February 20, 2020 9:09:03 PM EET Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> Am 2020-02-19 11:50, schrieb Jungseung Lee:
> > Hi, Tudor and all
Hi, Jungseung, Michael,
> >
> > 2020-02-10 (Mon), 11:26 +0000, Tudor.Ambarus@microchip.com:
> >> On Monday, February 10, 2020 12:29:34 PM EET Michael Walle wrote:
> >> > > It's bytes. Take a look at W25Q128JV. The sector size for this
> >> > > flash is
> >> > > 64KByte. The flash has 256 sectors. For this specific case:
> >> > > bp_slots_available = 6;
> >> > > bp_slots_needed = 8;
> >> > >
> >> > > The if condition is true, so
> >> > > bp_slot_count = 6;
> >> > > bp_min_slot_size = 64k << (8 - 6); //256k
> >> >
> >> > But nor->info->n_sectors is not 64k, its 256. Do you mean
> >> > sector_size
> >> > (like in
> >> > my example below? Then we are on the same page
> >>
> >> Indeed, there is a typo in the pseudo code; I'm happy that the
> >> example is
> >> correct at least. I meant sector_size, not sectors. Now we should
> >> exercise the
> >> logic to all the known (corner) cases. Maybe Jungseung will tell us
> >> if he
> >> spots a flaw in the overall logic.
> >
> > I didn't find any flaw in this logic. But IMHO for the pseudo code.
> >
> > bp_slots_available = (bp_mask >> shift) + 1 - 2;
> > bp_slots_needed = ilog2(nor->info->n_sectors);
> >
> > if (bp_slots_needed > bp_slots_available) {
> >
> > bp_slot_count = bp_slots_available;
> > bp_min_slot_size = nor->info->sector_size <<
> >
> > (bp_slots_needed - bp_slots_available);
> >
> > } else {
> >
> > bp_slot_count = bp_slots_needed;
> > bp_min_slot_size = mtd->size >> bp_slot_count;
> >
> > }
> >
> > Probably we can use directly nor->info->sector_size for bp_min_slot_
> > size.
> >
> > sector_size x n_sectors = mtd->size
> > mtd->size / n_sectors = mtd->size >>
> > ilog2(n_sectors) = sector_size
> >
> > bp_slot_count is equal to log2(n_sectors) now so if we can trust the
> > value, we can also trust sector_size.
> >
> > After change it,
> >
> > if (bp_slots_needed > bp_slots_available)
> >
> > bp_min_slot_size = nor->info->sector_size <<
> >
> > (bp_slots_needed - bp_slots_available);
> >
> > else
> >
> > bp_min_slot_size = nor->info->sector_size
>
> Yes, thats what I pointed out in my previous mail, too. So I guess we
> agree on that.
Yes, agreed on this.
>
> > This is a comment from my previous mail.
> >
> >> > The exact fact is that locks operate in two different ways
> >> > according to flash model.
> >> >
> >> > (1) the smallest protected portion is fixed.
> >> >
> >> > for BP0-2 : 1/64
> >> > for BP0-1 : 1/4
> >> >
> >> > (2) the smallest protected portion is inversely propotional with
> >> > number of sectors.
>
> Again. please don't consider the ratio of the protected area to the
> flash size.
> This is only the result of applying the sector size and IMHO really bad
> for
> understanding. Use the number of protected sectors. Thus your (2) is
> actually
> always one sector (as you've already pointed out above).
>
> > (1) - if the slot is insufficient.
> > (2) - if the slot is sufficient.
> >
> > From the fact, that could be rewritten like below. I think it's more
> > intuitive one.
> >
> > if (bp_slots_needed > bp_slots_available) // (1)
> >
> > bp_min_slot_size = mtd->size >> bp_slots_available;
>
> Given the reasoning above, I'd prefer having the number of sectors and
> thus
> the sector_size. Eg. keep the following
>
> bp_min_slot_size = nor->info->sector_size <<
> (bp_slots_needed - bp_slots_available);
Both variants seem to work, this is a matter of taste. I would also use the
sector_size variant because it emphasizes that the sector size is not enough
large to be used as the min protected density. And it is in correlation with
the else case, it's easier (for me) to read it.
>
> > else // (2)
> >
> > bp_min_slot_size = nor->info->sector_size;
> >
> > We could also find a few flashes that does not following the overall
> > logic. For example, "en25qh256" and "en25qh16" which was manufactured
oh, the horror! :)
> > by EON. They are always following way (2) no matter what the number of
> > slot is. It seems that it could be handled like below with custom hook
> > later.
> >
> > if (bp_slots_needed < bp_slots_available || force)
>
> For the en25qh16 the "bp_slots_needed < bp_slots_available" is already
> true, isn't it?
yes, en25qh16 is covered. BP3 for EON is what the other manufacturers refer to
TB.
> But good catch for the en25qh256. IMHO the rework of the BP bits should
> already
> add a flag (together with a reference to this flash) so this information
Is en25qh256 the only flash that breaks the rule? EON did the locking wrong
for this flash. BP bits are pretty useless in this example because they can
either protect the upper/lower 32 sectors, or the entire flash. They have a
bad locking granularity.
I don't like that the info->flags is growing.
If we consider that what EON did was an error, we can introduce a
post_info_init hook, where we can set a SPI_NOR_BP_SECTOR_LOCK flag into a
nor->params.locking_ops->flags.
Either way, the introduction of such flag should be done in a separate patch.
The eon entries do not advertise lock support, we can deal with them with a
patch on top of the generic bp lock support. A dedicated patch will be smaller
and easier for readers to grasp.
> is not lost. what about sth like MIN_LOCK_SIZE_IS_ONE_SECTOR.
Yes, we should fix/add support for this. How about SPI_NOR_BP_SECTOR_LOCK?
Jungseung, are there any other caveats that you found? Would you work towards
implementing this generic bp lock proposal?
Great discussion guys. Cheers,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2020-02-21 9:30 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20200113055910epcas1p4f97dfeb465b00d66649d6321cffc7b5a@epcas1p4.samsung.com>
2020-01-13 5:59 ` [PATCH v3 1/3] mtd: spi-nor: introduce SR_BP_SHIFT define Jungseung Lee
2020-01-13 5:59 ` [PATCH v3 2/3] mtd: spi-nor: add 4bit block protection support Jungseung Lee
2020-01-14 10:49 ` Tudor.Ambarus
2020-01-17 15:06 ` Jungseung Lee
2020-01-22 11:42 ` Jungseung Lee
2020-01-22 14:31 ` Tudor.Ambarus
2020-01-22 17:14 ` Michael Walle
2020-01-23 3:59 ` Jungseung Lee
2020-01-23 8:15 ` Michael Walle
2020-02-11 7:52 ` chenxiang (M)
2020-03-04 5:20 ` Jungseung Lee
2020-03-04 8:36 ` chenxiang (M)
2020-03-07 7:40 ` Jungseung Lee
2020-01-22 19:36 ` Michael Walle
2020-01-23 6:22 ` Jungseung Lee
2020-01-23 8:10 ` Michael Walle
2020-01-23 8:53 ` Jungseung Lee
2020-01-23 9:31 ` Michael Walle
2020-01-28 11:01 ` Jungseung Lee
2020-01-28 12:29 ` [SPAM] " Michael Walle
2020-01-30 8:17 ` Jungseung Lee
2020-01-30 8:36 ` [SPAM] " Michael Walle
2020-01-30 10:07 ` Jungseung Lee
2020-02-03 13:56 ` Vignesh Raghavendra
2020-02-03 14:38 ` [SPAM] " Michael Walle
2020-02-03 14:58 ` Jungseung Lee
2020-02-03 17:31 ` Vignesh Raghavendra
2020-02-07 12:17 ` Tudor.Ambarus
2020-02-10 8:33 ` Michael Walle
2020-02-10 9:47 ` Tudor.Ambarus
2020-02-10 9:59 ` Tudor.Ambarus
2020-02-10 10:40 ` Michael Walle
2020-02-10 11:27 ` Tudor.Ambarus
2020-02-10 12:14 ` Michael Walle
2020-02-10 15:50 ` Tudor.Ambarus
2020-02-10 10:29 ` Michael Walle
2020-02-10 11:26 ` Tudor.Ambarus
2020-02-19 10:50 ` Jungseung Lee
2020-02-19 11:08 ` Michael Walle
2020-02-19 11:23 ` Jungseung Lee
2020-02-19 11:36 ` Michael Walle
2020-02-20 19:09 ` Michael Walle
2020-02-21 9:30 ` Tudor.Ambarus [this message]
2020-02-25 8:20 ` Tudor.Ambarus
2020-02-25 9:25 ` Jungseung Lee
2020-01-13 5:59 ` [PATCH v3 3/3] mtd: spi-nor: support lock/unlock for a few Micron chips Jungseung Lee
2020-01-13 12:30 ` John Garry
2020-01-13 12:40 ` Jungseung Lee
2020-01-13 12:45 ` Jungseung Lee
2020-01-13 13:00 ` John Garry
2020-02-17 0:18 ` [PATCH v3 1/3] mtd: spi-nor: introduce SR_BP_SHIFT define Tudor.Ambarus
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=21102931.kdR8orL0iI@localhost.localdomain \
--to=tudor.ambarus@microchip.com \
--cc=js07.lee@gmail.com \
--cc=js07.lee@samsung.com \
--cc=linux-mtd@lists.infradead.org \
--cc=michael@walle.cc \
--cc=vigneshr@ti.com \
/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