sst_fwhub.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2000 Silicon Integrated System Corporation
  5. * Copyright (C) 2009 Kontron Modular Computers
  6. * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /* Adapted from the Intel FW hub stuff for 82802ax parts. */
  23. #include "flash.h"
  24. static int check_sst_fwhub_block_lock(struct flashctx *flash, int offset)
  25. {
  26. chipaddr registers = flash->virtual_registers;
  27. uint8_t blockstatus;
  28. blockstatus = chip_readb(flash, registers + offset + 2);
  29. msg_cdbg("Lock status for 0x%06x (size 0x%06x) is %02x, ",
  30. offset, flash->page_size, blockstatus);
  31. switch (blockstatus & 0x3) {
  32. case 0x0:
  33. msg_cdbg("full access\n");
  34. break;
  35. case 0x1:
  36. msg_cdbg("write locked\n");
  37. break;
  38. case 0x2:
  39. msg_cdbg("locked open\n");
  40. break;
  41. case 0x3:
  42. msg_cdbg("write locked down\n");
  43. break;
  44. }
  45. /* Return content of the write_locked bit */
  46. return blockstatus & 0x1;
  47. }
  48. static int clear_sst_fwhub_block_lock(struct flashctx *flash, int offset)
  49. {
  50. chipaddr registers = flash->virtual_registers;
  51. uint8_t blockstatus;
  52. blockstatus = check_sst_fwhub_block_lock(flash, offset);
  53. if (blockstatus) {
  54. msg_cdbg("Trying to clear lock for 0x%06x... ", offset);
  55. chip_writeb(flash, 0, registers + offset + 2);
  56. blockstatus = check_sst_fwhub_block_lock(flash, offset);
  57. msg_cdbg("%s\n", (blockstatus) ? "failed" : "OK");
  58. }
  59. return blockstatus;
  60. }
  61. int printlock_sst_fwhub(struct flashctx *flash)
  62. {
  63. int i;
  64. for (i = 0; i < flash->total_size * 1024; i += flash->page_size)
  65. check_sst_fwhub_block_lock(flash, i);
  66. return 0;
  67. }
  68. int unlock_sst_fwhub(struct flashctx *flash)
  69. {
  70. int i, ret=0;
  71. for (i = 0; i < flash->total_size * 1024; i += flash->page_size)
  72. {
  73. if (clear_sst_fwhub_block_lock(flash, i))
  74. {
  75. msg_cdbg("Warning: Unlock Failed for block 0x%06x\n", i);
  76. ret++;
  77. }
  78. }
  79. return ret;
  80. }