stm50flw0x0x.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2008 Claus Gindhart <claus.gindhart@kontron.com>
  5. * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
  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. /*
  22. * This module is designed for supporting the devices
  23. * ST M50FLW040A (not yet tested)
  24. * ST M50FLW040B (not yet tested)
  25. * ST M50FLW080A
  26. * ST M50FLW080B (not yet tested)
  27. */
  28. #include "flash.h"
  29. #include "flashchips.h"
  30. #include "chipdrivers.h"
  31. /*
  32. * claus.gindhart@kontron.com
  33. * The ST M50FLW080B and STM50FLW080B chips have to be unlocked,
  34. * before you can erase them or write to them.
  35. */
  36. static int unlock_block_stm50flw0x0x(struct flashctx *flash, int offset)
  37. {
  38. chipaddr wrprotect = flash->virtual_registers + 2;
  39. static const uint8_t unlock_sector = 0x00;
  40. int j;
  41. /*
  42. * These chips have to be unlocked before you can erase them or write
  43. * to them. The size of the locking sectors depends on the type
  44. * of chip.
  45. *
  46. * Sometimes, the BIOS does this for you; so you probably
  47. * don't need to worry about that.
  48. */
  49. /* Check, if it's is a top/bottom-block with 4k-sectors. */
  50. /* TODO: What about the other types? */
  51. if ((offset == 0) ||
  52. (offset == (flash->model_id == ST_M50FLW080A ? 0xE0000 : 0x10000))
  53. || (offset == 0xF0000)) {
  54. // unlock each 4k-sector
  55. for (j = 0; j < 0x10000; j += 0x1000) {
  56. msg_cdbg("unlocking at 0x%x\n", offset + j);
  57. chip_writeb(flash, unlock_sector, wrprotect + offset + j);
  58. if (chip_readb(flash, wrprotect + offset + j) != unlock_sector) {
  59. msg_cerr("Cannot unlock sector @ 0x%x\n",
  60. offset + j);
  61. return -1;
  62. }
  63. }
  64. } else {
  65. msg_cdbg("unlocking at 0x%x\n", offset);
  66. chip_writeb(flash, unlock_sector, wrprotect + offset);
  67. if (chip_readb(flash, wrprotect + offset) != unlock_sector) {
  68. msg_cerr("Cannot unlock sector @ 0x%x\n", offset);
  69. return -1;
  70. }
  71. }
  72. return 0;
  73. }
  74. int unlock_stm50flw0x0x(struct flashctx *flash)
  75. {
  76. int i;
  77. for (i = 0; i < flash->total_size * 1024; i+= flash->page_size) {
  78. if(unlock_block_stm50flw0x0x(flash, i)) {
  79. msg_cerr("UNLOCK FAILED!\n");
  80. return -1;
  81. }
  82. }
  83. return 0;
  84. }
  85. /* This function is unused. */
  86. int erase_sector_stm50flw0x0x(struct flashctx *flash, unsigned int sector, unsigned int sectorsize)
  87. {
  88. chipaddr bios = flash->virtual_memory + sector;
  89. // clear status register
  90. chip_writeb(flash, 0x50, bios);
  91. // now start it
  92. chip_writeb(flash, 0x32, bios);
  93. chip_writeb(flash, 0xd0, bios);
  94. programmer_delay(10);
  95. wait_82802ab(flash);
  96. /* FIXME: Check the status register for errors. */
  97. return 0;
  98. }