rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 1 | /* |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 2 | * This file is part of the flashrom project. |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 3 | * |
uwe | 555dd97 | 2007-09-09 20:21:05 +0000 | [diff] [blame] | 4 | * Copyright (C) 2000 Silicon Integrated System Corporation |
hailfinger | 4d25b2d | 2009-11-25 15:04:28 +0000 | [diff] [blame] | 5 | * Copyright (C) 2009 Kontron Modular Computers |
snelson | 264e57c | 2010-01-20 20:55:53 +0000 | [diff] [blame] | 6 | * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com> |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 7 | * |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 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. |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 12 | * |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 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. |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 19 | /* Adapted from the Intel FW hub stuff for 82802ax parts. */ |
| 20 | |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 21 | #include "flash.h" |
Edward O'Callaghan | 6b75443 | 2019-08-02 17:14:16 +1000 | [diff] [blame] | 22 | #include "chipdrivers.h" |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 23 | |
Edward O'Callaghan | 6b75443 | 2019-08-02 17:14:16 +1000 | [diff] [blame] | 24 | static int check_sst_fwhub_block_lock(struct flashctx *flash, unsigned int offset) |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 25 | { |
hailfinger | 8271963 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 26 | chipaddr registers = flash->virtual_registers; |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 27 | uint8_t blockstatus; |
| 28 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 29 | blockstatus = chip_readb(flash, registers + offset + 2); |
snelson | fc007bb | 2010-03-24 23:14:32 +0000 | [diff] [blame] | 30 | msg_cdbg("Lock status for 0x%06x (size 0x%06x) is %02x, ", |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 31 | offset, flash->chip->page_size, blockstatus); |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 32 | switch (blockstatus & 0x3) { |
| 33 | case 0x0: |
snelson | fc007bb | 2010-03-24 23:14:32 +0000 | [diff] [blame] | 34 | msg_cdbg("full access\n"); |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 35 | break; |
| 36 | case 0x1: |
snelson | fc007bb | 2010-03-24 23:14:32 +0000 | [diff] [blame] | 37 | msg_cdbg("write locked\n"); |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 38 | break; |
| 39 | case 0x2: |
snelson | fc007bb | 2010-03-24 23:14:32 +0000 | [diff] [blame] | 40 | msg_cdbg("locked open\n"); |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 41 | break; |
| 42 | case 0x3: |
snelson | fc007bb | 2010-03-24 23:14:32 +0000 | [diff] [blame] | 43 | msg_cdbg("write locked down\n"); |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 44 | break; |
| 45 | } |
| 46 | /* Return content of the write_locked bit */ |
| 47 | return blockstatus & 0x1; |
| 48 | } |
| 49 | |
Edward O'Callaghan | 6b75443 | 2019-08-02 17:14:16 +1000 | [diff] [blame] | 50 | static int clear_sst_fwhub_block_lock(struct flashctx *flash, unsigned int offset) |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 51 | { |
hailfinger | 8271963 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 52 | chipaddr registers = flash->virtual_registers; |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 53 | uint8_t blockstatus; |
| 54 | |
| 55 | blockstatus = check_sst_fwhub_block_lock(flash, offset); |
| 56 | |
| 57 | if (blockstatus) { |
snelson | fc007bb | 2010-03-24 23:14:32 +0000 | [diff] [blame] | 58 | msg_cdbg("Trying to clear lock for 0x%06x... ", offset); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 59 | chip_writeb(flash, 0, registers + offset + 2); |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 60 | |
| 61 | blockstatus = check_sst_fwhub_block_lock(flash, offset); |
snelson | fc007bb | 2010-03-24 23:14:32 +0000 | [diff] [blame] | 62 | msg_cdbg("%s\n", (blockstatus) ? "failed" : "OK"); |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | return blockstatus; |
| 66 | } |
| 67 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 68 | int printlock_sst_fwhub(struct flashctx *flash) |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 69 | { |
Edward O'Callaghan | 6b75443 | 2019-08-02 17:14:16 +1000 | [diff] [blame] | 70 | unsigned int i; |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 71 | |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 72 | for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size) |
hailfinger | 8577ad1 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 73 | check_sst_fwhub_block_lock(flash, i); |
| 74 | |
hailfinger | b8e4e21 | 2010-03-15 03:48:42 +0000 | [diff] [blame] | 75 | return 0; |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 78 | int unlock_sst_fwhub(struct flashctx *flash) |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 79 | { |
Edward O'Callaghan | 6b75443 | 2019-08-02 17:14:16 +1000 | [diff] [blame] | 80 | unsigned int i; |
| 81 | int ret = 0; |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 82 | |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 83 | for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size) |
snelson | 712e72d | 2010-03-16 03:09:10 +0000 | [diff] [blame] | 84 | { |
| 85 | if (clear_sst_fwhub_block_lock(flash, i)) |
| 86 | { |
Patrick Georgi | dbde2f1 | 2017-02-03 18:07:45 +0100 | [diff] [blame] | 87 | msg_cwarn("Warning: Unlock Failed for block 0x%06x\n", i); |
snelson | 712e72d | 2010-03-16 03:09:10 +0000 | [diff] [blame] | 88 | ret++; |
stepan | e467ea0 | 2008-03-16 19:44:13 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
snelson | 712e72d | 2010-03-16 03:09:10 +0000 | [diff] [blame] | 91 | return ret; |
rminnich | dfcbaa7 | 2004-09-30 16:37:01 +0000 | [diff] [blame] | 92 | } |