Flashrom

Flashrom Svn Source Tree

Root/trunk/sst_fwhub.c

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

Archive Download this file

Revision: HEAD