A new post titled "[GSoC] Multiple status registers, block protection and OTP support, wrap-up (1/2)" has been published on the coreboot blog. Find the full post at http://blogs.coreboot.org/blog/2016/08/26/gsoc-sr-wp-otp-wrap-up-12/

<p>Hello! <img src="https://s.w.org/images/core/emoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>GSoC 2016 coding period has come to an end and mentor’s evaluating students this week. It has been an enriching 13 weeks of reading datasheets, designing structures, coding, learning and hanging out over IRC! <img src="https://s.w.org/images/core/emoji/2/72x72/1f61b.png" alt="😛" class="wp-smiley" style="height: 1em; max-height: 1em;" /> I’d like to take this opportunity to present my work and details on how to use it. <img src="https://s.w.org/images/core/emoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>Firstly, to offer context to the work, here is a list of public mails and blog posts. These should give an idea as to how the discussions and work evolved. A lot of the discussions have happened over IRC, but <a href="irc://irc.freenode.net/#flashrom">#flashrom</a> does not keep any logs.</p>
<ul>
<li>From the mailing list, <a href="https://www.flashrom.org/pipermail/flashrom/2016-May/014658.html">this</a> and <a href="https://www.flashrom.org/pipermail/flashrom/2016-June/014701.html">this</a></li>
<li>And of course <a href="https://blogs.coreboot.org/blog/author/hatim/">my blog posts</a> <img src="https://s.w.org/images/core/emoji/2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></li>
</ul>
<p>The patch sets that I sent to the mailing list can be found at –</p>
<ol>
<li><a href="https://www.flashrom.org/pipermail/flashrom/2016-July/014717.html">Multiple status register and access protection infrastructure</a></li>
<li><a href="https://www.flashrom.org/pipermail/flashrom/2016-July/014737.html">OTP/Security registers infrastructure</a></li>
<li><a href="https://www.flashrom.org/pipermail/flashrom/2016-August/014791.html">Dummy chips</a></li>
</ol>
<p>You can also find these over at <a href="https://patchwork.coreboot.org/project/flashrom/list/">flashrom’s patchwork</a>. The mailing list is where the review happens (although a better alternative, IMHO, is Gerrit which coreboot uses). The patches aren’t currently merged and are under review. In any case, you are most welcome to join review (which will likely be very helpful for me). <img src="https://s.w.org/images/core/emoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> If you’d like to look at something more on the bleeding edge, then I invite you to <a href="https://github.com/hatimak/flashrom/tree/dev">my GitHub</a>.</p>
<p>Now, moving on how to use the work. The most exhaustive documentation on how to use it is the code itself :P, but in the following list I attempt to list scenarios –</p>
<ul>
<li>For SPI chips that have multiple status registers, flashrom’s verbose output will print the status register bits and there values. Most bits are named, i.e., the datasheet refers to the bit by an abbreviation, for instance, <code>WEL</code> for Write Enable Latch, <code>WIP</code> for Work In Progress, <code>BP</code> for Block Protect, <code>LB</code> for Lock Bit and so on. The verbose output will print these names, both in abbreviated and long forms, for most chips (and these abbreviations tend to be generic across many manufacturers). However, the process for adding new chips that leverage this, and adding new bits, is a fairly easy task (I would invite you to have a look at the code <img src="https://s.w.org/images/core/emoji/2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> for more details). The verbose output also prints the write protection mode for status register(s) in effect (software protected, hardware protected, power cycle lock down and so on).</li>
<li>In case you want to disable or enable (a particular type) write protection for status register, you can use the <code>--wp-disable</code> or <code>--wp-enable[=MODE]</code> respectively (where <code>MODE</code> is either of <code>software</code>, <code>hardware</code>, <code>power cycle</code> or <code>permanent</code> – you are encouraged to have a look at the man page <img src="https://s.w.org/images/core/emoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> for more details)</li>
<li>In case you want to protect a particular range of an SPI chip from writes or erases, you will need to alter the <code>BP</code>, <code>TB</code> or <code>SEC</code> bits. Currently, there is a CLI that will enable you to accomplish all that. <img src="https://s.w.org/images/core/emoji/2/72x72/1f61b.png" alt="😛" class="wp-smiley" style="height: 1em; max-height: 1em;" /> First, you’ll want to look at the list of ranges your SPI chip supports – run flashrom with <code>--wp-list</code>. Take note of the start address and the length of the memory range you want to protect. Then again run flashrom with <code>--wp-set-range start=0xfff000,len=4</code> (<code>0xfff000</code> and <code>4</code> are for representational purpose only). By now the memory range is protected, but you can additionally enable status register write protection by following what the foregoing point described.</li>
<li>For SPI chips that support OTP, you can read, write and erase OTP regions (of course for supported chips :P). For OTP operations, you have at your disposal <code>--print-otp-status</code>, <code>--read-otp [,reg=]</code>, <code>--write-otp file=[,reg=]</code>, <code>--erase-otp [reg=]</code> and <code>--lock-otp [reg=]</code>. You can read the OTP memory to a file, or you can write to the OTP region from a file, very much like reading and writing from/to SPI chip. For more details, I would again like to point you to the man page. <img src="https://s.w.org/images/core/emoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" />
</li>
</ul>
<p>Since this is a work-in-progress, the CLI may change (and is very likely). Currently around 10% of SPI chips use this new infrastructure. Models of a few manufacturers (and especially exotic ones like Atmel) are yet to be fully incorporated. You are most welcome to add support for new chips or update the existing ones to support new infrastructure. <img src="https://s.w.org/images/core/emoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>I would like to sincerely thank my mentors Stefan and David for their support and help. I am indebted to them for this opportunity and I hope that we continue to share this relationship in the future while I continue to explore and contribute to flashrom. It has been a pleasure getting to know each of them. I’d also like to thank Urja for pitching in from time to time <img src="https://s.w.org/images/core/emoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> It was fun hanging out over IRC and helping folks asking questions there. And I am looking forward to it for years to come. <img src="https://s.w.org/images/core/emoji/2/72x72/1f61b.png" alt="😛" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>In the next and final part of this post, I will highlight how we intend to improve upon this work in the future, where it will be headed and what more we have in store, so please stay tuned. <img src="https://s.w.org/images/core/emoji/2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <em>Phew, this was a long one, and rightly so as it attempts to summarise a great deal of experiences.</em> If you have any feedback, questions or comments on the blogs or code, please feel to ping me on <a href="irc://irc.freenode.net/#flashrom">#flashrom</a> where I am known as <code>hatim</code>. You can also email me at <a href="mailto:hatim@hatimak.me">hatim@hatimak.me</a>.</p>
<p>Thanks, and looking forward to hearing from you. <img src="https://s.w.org/images/core/emoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> See you in the next and final part.</p>