summaryrefslogtreecommitdiff
path: root/board/wmt/flash/spi_flash_lock.c
blob: b82611d7dc8701cd5b9c42a1ceea92140dee30f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * Copyright (c) 2010 WonderMedia Technologies, Inc.
 *
 * 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.
 *
 * 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.
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * WonderMedia Technologies, Inc.
 * 10F, 529, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C.
 */

/* For UBOOT */
#include <common.h>
#include "spi_flash.h"


int spi_flash_wmt_protect(flash_info_t *info, long sector, int prot)
{
	int rc = 0, value;
	char *key = NULL;

	/*key = getenv("wmt.rsa.pem");
	if (!key) {
		return 1;
	}*/
	printf("real ");
	if (prot) {
		/* lock sf */
		if (sector == 0) {
			spi_flash_read_status(0, &value);
			if ((value&0x9C) != 0x9C)
				rc = spi_flash_write_status(0, 0x9C);
			else
				printf("chip 0 already lock\n");
		} else {
			spi_flash_read_status(1, &value);
			if ((value&0x9C) != 0x9C)
				rc = spi_flash_write_status(1, 0x9C);
			else
				printf("chip 1 already lock\n");
		}
		*(volatile unsigned char *)(GPIO_BASE_ADDR + 0xDF) &= ~0x4; /*gpio31 gpio out data*/
		*(volatile unsigned char *)(GPIO_BASE_ADDR + 0x9F) |= 0x4; /*gpio31 enable out enable*/
		*(volatile unsigned char *)(GPIO_BASE_ADDR + 0x5F) |= 0x4; /*gpio31 enable gpio mode*/
		/* printf("SF protect sec %d\n", sector); */
	} else {
		/* unlock sf */
		*(volatile unsigned char *)(GPIO_BASE_ADDR + 0xDF) |= 0x4; /*gpio31 gpio out data*/
		*(volatile unsigned char *)(GPIO_BASE_ADDR + 0x9F) |= 0x4; /*gpio31 enable out enable*/
		*(volatile unsigned char *)(GPIO_BASE_ADDR + 0x5F) |= 0x4; /*gpio31 enable gpio mode*/
		if (sector == 0) {
			spi_flash_read_status(0, &value);
			if ((value&0x9C) != 0)
				rc = spi_flash_write_status(0, 0);
			else
				printf("chip 0 already unlock\n");
		} else {
			spi_flash_read_status(1, &value);
			if ((value&0x9C) != 0)
				rc = spi_flash_write_status(1, 0);
			else
				printf("chip 1 already unlock\n");
		}
		if (rc) {
			*(volatile unsigned char *)(GPIO_BASE_ADDR + 0xDF) &= ~0x4; /*gpio31 gpio pull-high*/
			/* printf("SF unprotect fail\n", sector);*/
		}
	}
	return rc;
}