blob: d688a350d948841afcb2d910fd1810a97e1f155b [file] [log] [blame]
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +00003 *
Uwe Hermannd22a1d42007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
Adam Jurkowski411d7c12009-11-25 15:04:28 +00005 * Copyright (C) 2009 Kontron Modular Computers
Sean Nelson51c83fb2010-01-20 20:55:53 +00006 * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +00007 *
Uwe Hermannd1107642007-08-29 17:52:32 +00008 * 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.
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000012 *
Uwe Hermannd1107642007-08-29 17:52:32 +000013 * 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.
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000017 */
18
Uwe Hermannd1107642007-08-29 17:52:32 +000019/* Adapted from the Intel FW hub stuff for 82802ax parts. */
20
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000021#include "flash.h"
Jacob Garber6c683632019-06-21 15:33:09 -060022#include "chipdrivers.h"
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000023
Nico Huber519be662018-12-23 20:03:35 +010024static int check_sst_fwhub_block_lock(struct flashctx *flash, unsigned int offset)
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000025{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000026 chipaddr registers = flash->virtual_registers;
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000027 uint8_t blockstatus;
28
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000029 blockstatus = chip_readb(flash, registers + offset + 2);
Sean Nelsoned479d22010-03-24 23:14:32 +000030 msg_cdbg("Lock status for 0x%06x (size 0x%06x) is %02x, ",
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +000031 offset, flash->chip->page_size, blockstatus);
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000032 switch (blockstatus & 0x3) {
33 case 0x0:
Sean Nelsoned479d22010-03-24 23:14:32 +000034 msg_cdbg("full access\n");
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000035 break;
36 case 0x1:
Sean Nelsoned479d22010-03-24 23:14:32 +000037 msg_cdbg("write locked\n");
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000038 break;
39 case 0x2:
Sean Nelsoned479d22010-03-24 23:14:32 +000040 msg_cdbg("locked open\n");
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000041 break;
42 case 0x3:
Sean Nelsoned479d22010-03-24 23:14:32 +000043 msg_cdbg("write locked down\n");
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000044 break;
45 }
46 /* Return content of the write_locked bit */
47 return blockstatus & 0x1;
48}
49
Nico Huber519be662018-12-23 20:03:35 +010050static int clear_sst_fwhub_block_lock(struct flashctx *flash, unsigned int offset)
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000051{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000052 chipaddr registers = flash->virtual_registers;
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000053 uint8_t blockstatus;
54
55 blockstatus = check_sst_fwhub_block_lock(flash, offset);
56
57 if (blockstatus) {
Sean Nelsoned479d22010-03-24 23:14:32 +000058 msg_cdbg("Trying to clear lock for 0x%06x... ", offset);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000059 chip_writeb(flash, 0, registers + offset + 2);
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000060
61 blockstatus = check_sst_fwhub_block_lock(flash, offset);
Sean Nelsoned479d22010-03-24 23:14:32 +000062 msg_cdbg("%s\n", (blockstatus) ? "failed" : "OK");
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000063 }
64
65 return blockstatus;
66}
67
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000068int printlock_sst_fwhub(struct flashctx *flash)
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000069{
Nico Huber519be662018-12-23 20:03:35 +010070 unsigned int i;
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000071
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +000072 for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size)
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000073 check_sst_fwhub_block_lock(flash, i);
74
Carl-Daniel Hailfinger81449a22010-03-15 03:48:42 +000075 return 0;
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000076}
77
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000078int unlock_sst_fwhub(struct flashctx *flash)
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000079{
Nico Huber519be662018-12-23 20:03:35 +010080 unsigned int i;
81 int ret = 0;
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000082
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +000083 for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size)
Sean Nelsonccf7a2a2010-03-16 03:09:10 +000084 {
85 if (clear_sst_fwhub_block_lock(flash, i))
86 {
Stefan Taunerc6fa32d2013-01-04 22:54:07 +000087 msg_cwarn("Warning: Unlock Failed for block 0x%06x\n", i);
Sean Nelsonccf7a2a2010-03-16 03:09:10 +000088 ret++;
Stefan Reinauerb7c83232008-03-16 19:44:13 +000089 }
90 }
Sean Nelsonccf7a2a2010-03-16 03:09:10 +000091 return ret;
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000092}