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 <[email protected]>
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
19 /* Adapted from the Intel FW hub stuff for 82802ax parts. */
20
21 #include "flash.h"
22 #include "chipdrivers.h"
23
check_sst_fwhub_block_lock(struct flashctx * flash,unsigned int offset)24 static int check_sst_fwhub_block_lock(struct flashctx *flash, unsigned int offset)
25 {
26 chipaddr registers = flash->virtual_registers;
27 uint8_t blockstatus;
28
29 blockstatus = chip_readb(flash, registers + offset + 2);
30 msg_cdbg("Lock status for 0x%06x (size 0x%06x) is %02x, ",
31 offset, flash->chip->page_size, blockstatus);
32 switch (blockstatus & 0x3) {
33 case 0x0:
34 msg_cdbg("full access\n");
35 break;
36 case 0x1:
37 msg_cdbg("write locked\n");
38 break;
39 case 0x2:
40 msg_cdbg("locked open\n");
41 break;
42 case 0x3:
43 msg_cdbg("write locked down\n");
44 break;
45 }
46 /* Return content of the write_locked bit */
47 return blockstatus & 0x1;
48 }
49
clear_sst_fwhub_block_lock(struct flashctx * flash,unsigned int offset)50 static int clear_sst_fwhub_block_lock(struct flashctx *flash, unsigned int offset)
51 {
52 chipaddr registers = flash->virtual_registers;
53 uint8_t blockstatus;
54
55 blockstatus = check_sst_fwhub_block_lock(flash, offset);
56
57 if (blockstatus) {
58 msg_cdbg("Trying to clear lock for 0x%06x... ", offset);
59 chip_writeb(flash, 0, registers + offset + 2);
60
61 blockstatus = check_sst_fwhub_block_lock(flash, offset);
62 msg_cdbg("%s\n", (blockstatus) ? "failed" : "OK");
63 }
64
65 return blockstatus;
66 }
67
printlock_sst_fwhub(struct flashctx * flash)68 int printlock_sst_fwhub(struct flashctx *flash)
69 {
70 unsigned int i;
71
72 for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size)
73 check_sst_fwhub_block_lock(flash, i);
74
75 return 0;
76 }
77
unlock_sst_fwhub(struct flashctx * flash)78 int unlock_sst_fwhub(struct flashctx *flash)
79 {
80 unsigned int i;
81 int ret = 0;
82
83 for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size)
84 {
85 if (clear_sst_fwhub_block_lock(flash, i))
86 {
87 msg_cwarn("Warning: Unlock Failed for block 0x%06x\n", i);
88 ret++;
89 }
90 }
91 return ret;
92 }
93