blob: 62c55f4a0fffc86810edf0daa0d73ca2a232c3e5 [file] [log] [blame]
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2008 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000021#include "flash.h"
Sean Nelson14ba6682010-02-26 05:48:29 +000022#include "chipdrivers.h"
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000023
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000024static int unlock_block_winbond_fwhub(struct flashchip *flash, int offset)
25{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000026 chipaddr wrprotect = flash->virtual_registers + offset + 2;
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000027 uint8_t locking;
28
Sean Nelsoned479d22010-03-24 23:14:32 +000029 msg_cdbg("Trying to unlock block @0x%08x = 0x%02x\n", offset,
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000030 chip_readb(wrprotect));
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000031
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000032 locking = chip_readb(wrprotect);
Uwe Hermann394131e2008-10-18 21:14:13 +000033 switch (locking & 0x7) {
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000034 case 0:
Sean Nelsoned479d22010-03-24 23:14:32 +000035 msg_cdbg("Full Access.\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000036 return 0;
37 case 1:
Sean Nelsoned479d22010-03-24 23:14:32 +000038 msg_cdbg("Write Lock (Default State).\n");
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000039 chip_writeb(0, wrprotect);
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000040 return 0;
41 case 2:
Sean Nelsoned479d22010-03-24 23:14:32 +000042 msg_cdbg("Locked Open (Full Access, Lock Down).\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000043 return 0;
44 case 3:
Sean Nelsoned479d22010-03-24 23:14:32 +000045 msg_cerr("Error: Write Lock, Locked Down.\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000046 return -1;
47 case 4:
Sean Nelsoned479d22010-03-24 23:14:32 +000048 msg_cdbg("Read Lock.\n");
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000049 chip_writeb(0, wrprotect);
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000050 return 0;
51 case 5:
Sean Nelsoned479d22010-03-24 23:14:32 +000052 msg_cdbg("Read/Write Lock.\n");
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000053 chip_writeb(0, wrprotect);
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000054 return 0;
55 case 6:
Sean Nelsoned479d22010-03-24 23:14:32 +000056 msg_cerr("Error: Read Lock, Locked Down.\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000057 return -1;
58 case 7:
Sean Nelsoned479d22010-03-24 23:14:32 +000059 msg_cerr("Error: Read/Write Lock, Locked Down.\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000060 return -1;
61 }
62
63 /* We will never reach this point, but GCC doesn't know */
64 return -1;
65}
66
67int unlock_winbond_fwhub(struct flashchip *flash)
68{
69 int i, total_size = flash->total_size * 1024;
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000070 chipaddr bios = flash->virtual_memory;
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000071 uint8_t locking;
Uwe Hermann394131e2008-10-18 21:14:13 +000072
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000073 /* Are there any hardware restrictions that we can't overcome?
74 * If flashrom fail here, someone's got to check all those GPIOs.
75 */
76
77 /* Product Identification Entry */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000078 chip_writeb(0xAA, bios + 0x5555);
79 chip_writeb(0x55, bios + 0x2AAA);
80 chip_writeb(0x90, bios + 0x5555);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000081 programmer_delay(10);
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000082
83 /* Read Hardware Lock Bits */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000084 locking = chip_readb(bios + 0xffff2);
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000085
86 /* Product Identification Exit */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000087 chip_writeb(0xAA, bios + 0x5555);
88 chip_writeb(0x55, bios + 0x2AAA);
89 chip_writeb(0xF0, bios + 0x5555);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000090 programmer_delay(10);
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000091
Sean Nelsoned479d22010-03-24 23:14:32 +000092 msg_cdbg("Lockout bits:\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000093
Uwe Hermann394131e2008-10-18 21:14:13 +000094 if (locking & (1 << 2))
Sean Nelsoned479d22010-03-24 23:14:32 +000095 msg_cerr("Error: hardware bootblock locking (#TBL).\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000096 else
Sean Nelsoned479d22010-03-24 23:14:32 +000097 msg_cdbg("No hardware bootblock locking (good!)\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +000098
Uwe Hermann394131e2008-10-18 21:14:13 +000099 if (locking & (1 << 3))
Sean Nelsoned479d22010-03-24 23:14:32 +0000100 msg_cerr("Error: hardware block locking (#WP).\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +0000101 else
Sean Nelsoned479d22010-03-24 23:14:32 +0000102 msg_cdbg("No hardware block locking (good!)\n");
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +0000103
Uwe Hermann394131e2008-10-18 21:14:13 +0000104 if (locking & ((1 << 2) | (1 << 3)))
Stefan Reinauerc34ce2e2008-03-18 00:36:18 +0000105 return -1;
106
107 /* Unlock the complete chip */
108 for (i = 0; i < total_size; i += flash->page_size)
109 if (unlock_block_winbond_fwhub(flash, i))
110 return -1;
111
112 return 0;
113}