sst_fwhub.c 2.54 KB
Newer Older
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 9 10 11
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
12
 *
13 14 15 16
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
17
 *
18 19 20
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21 22
 */

23 24
/* Adapted from the Intel FW hub stuff for 82802ax parts. */

25 26
#include "flash.h"

27
static int check_sst_fwhub_block_lock(struct flashctx *flash, int offset)
28
{
29
	chipaddr registers = flash->virtual_registers;
30 31
	uint8_t blockstatus;

32
	blockstatus = chip_readb(flash, registers + offset + 2);
33
	msg_cdbg("Lock status for 0x%06x (size 0x%06x) is %02x, ",
34
		     offset, flash->chip->page_size, blockstatus);
35 36
	switch (blockstatus & 0x3) {
	case 0x0:
37
		msg_cdbg("full access\n");
38 39
		break;
	case 0x1:
40
		msg_cdbg("write locked\n");
41 42
		break;
	case 0x2:
43
		msg_cdbg("locked open\n");
44 45
		break;
	case 0x3:
46
		msg_cdbg("write locked down\n");
47 48 49 50 51 52
		break;
	}
	/* Return content of the write_locked bit */
	return blockstatus & 0x1;
}

53
static int clear_sst_fwhub_block_lock(struct flashctx *flash, int offset)
54
{
55
	chipaddr registers = flash->virtual_registers;
56 57 58 59 60
	uint8_t blockstatus;

	blockstatus = check_sst_fwhub_block_lock(flash, offset);

	if (blockstatus) {
61
		msg_cdbg("Trying to clear lock for 0x%06x... ", offset);
62
		chip_writeb(flash, 0, registers + offset + 2);
63 64

		blockstatus = check_sst_fwhub_block_lock(flash, offset);
65
		msg_cdbg("%s\n", (blockstatus) ? "failed" : "OK");
66 67 68 69 70
	}

	return blockstatus;
}

71
int printlock_sst_fwhub(struct flashctx *flash)
72
{
73 74
	int i;

75
	for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size)
76 77
		check_sst_fwhub_block_lock(flash, i);

78
	return 0;
79 80
}

81
int unlock_sst_fwhub(struct flashctx *flash)
82
{
83
	int i, ret=0;
84

85
	for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size)
86 87 88
	{
		if (clear_sst_fwhub_block_lock(flash, i))
		{
Stefan Tauner's avatar
Stefan Tauner committed
89
			msg_cwarn("Warning: Unlock Failed for block 0x%06x\n", i);
90
			ret++;
91 92
		}
	}
93
	return ret;
94 95
}