What do you mean exactly by "it is optional"?OK I understand your point after checking the code for the u-boot tool.
I agree with you that an explicit ioctl(MEMLOCK) is order for locking to take place. However, this seems to be the default action for the u-boot environment userspace tools. They will issue a MEMUNLOCK/MEMLOCK pair when trying to write some changes to the environment, without even checking the return value. This would of course fail silently when the feature was not implemented (as it was the case before the original patch was applied) and everything was working as expected.
Now linux supports this feature, and u-boot doesn't, so as soon as you write something to the flash from userspace, it will be locked and u-boot won't ever be able to write to it again.
In my opinion, we're breaking something here (call it userspace API or otherwise). My suggestion would then be to make it an optional feature to be explicitly enabled on the device tree, like Heicho did for CFI flashes:I prefer this suggestion of implementing _is_locked(). It is a simple change so may as well be done while fixing the lock/unlock code anyway. One could say it is counterintuitive for ioctl(MEMLOCK) not to work
http://lists.infradead.org/pipermail/linux-mtd/2013-January/045536.html
Or I guess another way would be to implement the _is_locked() function, so to have the userspace tools check the locking status before unlocking, and only lock it again if was locked in the first place.
It wouldn't fix my issue right away (as the userspace tools don't currenctly perform this check), but at least it would provide some way out here without breaking compatibility with the existing u-boot.
Uhm, I believe it should read like this (unprotected portion is of course "n - protected portion"):Yes sorry that was a typo in the previous email, should have been powers of 2 as above and the patch. Also technically correct about the min macro, as you saw I was just terminating the loop before that condition was met.
SR BPs | Protected portion
---------------------------
0 | 0/n
1 | 1/n
2 | 2/n
3 | min(4,n)/n
4 | min(8,n)/n
5 | min(16,n)/n
6 | min(32,n)/n
7 | min(64,n)/n
It sounds like you have already done your own research but here is what I have: https://docs.google.com/spreadsheet/ccc?key=0AhKBO-EQCLLkdGR1Q05qLUs2RURsMFA4V2s2X1llY3c&usp=sharingA patch with this implementation follows. Let me know what you think. I
have a spreadsheet summarising the block protect bits for the STmicro
devices I can share if it will help.
Could you please share this?