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@xxxxxxxxxxxxx: > >> 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/