w39.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2008 coresystems GmbH
  5. * Copyright (C) 2010 Carl-Daniel Hailfinger
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "flash.h"
  22. #include "chipdrivers.h"
  23. static uint8_t w39_idmode_readb(struct flashctx *flash, unsigned int offset)
  24. {
  25. chipaddr bios = flash->virtual_memory;
  26. uint8_t val;
  27. /* Product Identification Entry */
  28. chip_writeb(flash, 0xAA, bios + 0x5555);
  29. chip_writeb(flash, 0x55, bios + 0x2AAA);
  30. chip_writeb(flash, 0x90, bios + 0x5555);
  31. programmer_delay(10);
  32. /* Read something, maybe hardware lock bits */
  33. val = chip_readb(flash, bios + offset);
  34. /* Product Identification Exit */
  35. chip_writeb(flash, 0xAA, bios + 0x5555);
  36. chip_writeb(flash, 0x55, bios + 0x2AAA);
  37. chip_writeb(flash, 0xF0, bios + 0x5555);
  38. programmer_delay(10);
  39. return val;
  40. }
  41. static int printlock_w39_tblwp(uint8_t lock)
  42. {
  43. msg_cdbg("Hardware bootblock locking (#TBL) is %sactive.\n",
  44. (lock & (1 << 2)) ? "" : "not ");
  45. msg_cdbg("Hardware remaining chip locking (#WP) is %sactive..\n",
  46. (lock & (1 << 3)) ? "" : "not ");
  47. if (lock & ((1 << 2) | (1 << 3)))
  48. return -1;
  49. return 0;
  50. }
  51. static int printlock_w39_single_bootblock(uint8_t lock, uint16_t kB)
  52. {
  53. msg_cdbg("Software %d kB bootblock locking is %sactive.\n", kB, (lock & 0x03) ? "" : "not ");
  54. if (lock & 0x03)
  55. return -1;
  56. return 0;
  57. }
  58. static int printlock_w39_bootblock_64k16k(uint8_t lock)
  59. {
  60. msg_cdbg("Software 64 kB bootblock locking is %sactive.\n",
  61. (lock & (1 << 0)) ? "" : "not ");
  62. msg_cdbg("Software 16 kB bootblock locking is %sactive.\n",
  63. (lock & (1 << 1)) ? "" : "not ");
  64. if (lock & ((1 << 1) | (1 << 0)))
  65. return -1;
  66. return 0;
  67. }
  68. static int printlock_w39_common(struct flashctx *flash, unsigned int offset)
  69. {
  70. uint8_t lock;
  71. lock = w39_idmode_readb(flash, offset);
  72. msg_cdbg("Lockout bits:\n");
  73. return printlock_w39_tblwp(lock);
  74. }
  75. int printlock_w39f010(struct flashctx *flash)
  76. {
  77. uint8_t lock;
  78. int ret;
  79. lock = w39_idmode_readb(flash, 0x00002);
  80. msg_cdbg("Bottom boot block:\n");
  81. ret = printlock_w39_single_bootblock(lock, 16);
  82. lock = w39_idmode_readb(flash, 0x1fff2);
  83. msg_cdbg("Top boot block:\n");
  84. ret |= printlock_w39_single_bootblock(lock, 16);
  85. return ret;
  86. }
  87. int printlock_w39l010(struct flashctx *flash)
  88. {
  89. uint8_t lock;
  90. int ret;
  91. lock = w39_idmode_readb(flash, 0x00002);
  92. msg_cdbg("Bottom boot block:\n");
  93. ret = printlock_w39_single_bootblock(lock, 8);
  94. lock = w39_idmode_readb(flash, 0x1fff2);
  95. msg_cdbg("Top boot block:\n");
  96. ret |= printlock_w39_single_bootblock(lock, 8);
  97. return ret;
  98. }
  99. int printlock_w39l020(struct flashctx *flash)
  100. {
  101. uint8_t lock;
  102. int ret;
  103. lock = w39_idmode_readb(flash, 0x00002);
  104. msg_cdbg("Bottom boot block:\n");
  105. ret = printlock_w39_bootblock_64k16k(lock);
  106. lock = w39_idmode_readb(flash, 0x3fff2);
  107. msg_cdbg("Top boot block:\n");
  108. ret |= printlock_w39_bootblock_64k16k(lock);
  109. return ret;
  110. }
  111. int printlock_w39l040(struct flashctx *flash)
  112. {
  113. uint8_t lock;
  114. int ret;
  115. lock = w39_idmode_readb(flash, 0x00002);
  116. msg_cdbg("Bottom boot block:\n");
  117. ret = printlock_w39_bootblock_64k16k(lock);
  118. lock = w39_idmode_readb(flash, 0x7fff2);
  119. msg_cdbg("Top boot block:\n");
  120. ret |= printlock_w39_bootblock_64k16k(lock);
  121. return ret;
  122. }
  123. int printlock_w39v040a(struct flashctx *flash)
  124. {
  125. uint8_t lock;
  126. int ret = 0;
  127. /* The W39V040A datasheet contradicts itself on the lock register
  128. * location: 0x00002 and 0x7fff2 are both mentioned. Pick the one
  129. * which is similar to the other chips of the same family.
  130. */
  131. lock = w39_idmode_readb(flash, 0x7fff2);
  132. msg_cdbg("Lockout bits:\n");
  133. ret = printlock_w39_tblwp(lock);
  134. ret |= printlock_w39_bootblock_64k16k(lock);
  135. return ret;
  136. }
  137. int printlock_w39v040b(struct flashctx *flash)
  138. {
  139. return printlock_w39_common(flash, 0x7fff2);
  140. }
  141. int printlock_w39v040c(struct flashctx *flash)
  142. {
  143. /* Typo in the datasheet? The other chips use 0x7fff2. */
  144. return printlock_w39_common(flash, 0xfff2);
  145. }
  146. int printlock_w39v040fa(struct flashctx *flash)
  147. {
  148. int ret = 0;
  149. ret = printlock_w39v040a(flash);
  150. ret |= printlock_regspace2_uniform_64k(flash);
  151. return ret;
  152. }
  153. int printlock_w39v040fb(struct flashctx *flash)
  154. {
  155. int ret = 0;
  156. ret = printlock_w39v040b(flash);
  157. ret |= printlock_regspace2_uniform_64k(flash);
  158. return ret;
  159. }
  160. int printlock_w39v040fc(struct flashctx *flash)
  161. {
  162. int ret = 0;
  163. /* W39V040C and W39V040FC use different WP/TBL offsets. */
  164. ret = printlock_w39_common(flash, 0x7fff2);
  165. ret |= printlock_regspace2_uniform_64k(flash);
  166. return ret;
  167. }
  168. int printlock_w39v080a(struct flashctx *flash)
  169. {
  170. return printlock_w39_common(flash, 0xffff2);
  171. }
  172. int printlock_w39v080fa(struct flashctx *flash)
  173. {
  174. int ret = 0;
  175. ret = printlock_w39v080a(flash);
  176. ret |= printlock_regspace2_uniform_64k(flash);
  177. return ret;
  178. }
  179. int printlock_w39v080fa_dual(struct flashctx *flash)
  180. {
  181. msg_cinfo("Block locking for W39V080FA in dual mode is "
  182. "undocumented.\n");
  183. /* Better safe than sorry. */
  184. return -1;
  185. }
  186. int printlock_at49f(struct flashctx *flash)
  187. {
  188. uint8_t lock = w39_idmode_readb(flash, 0x00002);
  189. msg_cdbg("Hardware bootblock lockout is %sactive.\n",
  190. (lock & 0x01) ? "" : "not ");
  191. return 0;
  192. }