blob: 86f3497185a1b3b2fb1c80532befb3c690b1150a [file] [log] [blame]
Nikolay Petukhov4784c472008-05-17 01:08:58 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2004 Tyan Corporation
5 * Copyright (C) 2007 Nikolay Petukhov <nikolay.petukhov@gmail.com>
6 * Copyright (C) 2007 Reinder E.N. de Haan <lb_reha@mveas.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#include <stdio.h>
24#include "flash.h"
25
26extern int exclude_start_page, exclude_end_page;
27
28void write_lockbits_49fl00x(volatile uint8_t *bios, int size,
Uwe Hermann394131e2008-10-18 21:14:13 +000029 unsigned char bits, int block_size)
Nikolay Petukhov4784c472008-05-17 01:08:58 +000030{
31 int i, left = size;
32
33 for (i = 0; left >= block_size; i++, left -= block_size) {
Nikolay Petukhov4784c472008-05-17 01:08:58 +000034 /* pm49fl002 */
Uwe Hermann394131e2008-10-18 21:14:13 +000035 if (block_size == 16384 && i % 2)
Nikolay Petukhov4784c472008-05-17 01:08:58 +000036 continue;
37
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000038 chip_writeb(bits, bios + (i * block_size) + 2);
Nikolay Petukhov4784c472008-05-17 01:08:58 +000039 }
40}
41
42int probe_49fl00x(struct flashchip *flash)
43{
44 int ret = probe_jedec(flash);
Uwe Hermann394131e2008-10-18 21:14:13 +000045
Nikolay Petukhov4784c472008-05-17 01:08:58 +000046 if (ret == 1)
47 map_flash_registers(flash);
48
49 return ret;
50}
51
52int erase_49fl00x(struct flashchip *flash)
53{
54 int i;
55 int total_size = flash->total_size * 1024;
56 int page_size = flash->page_size;
57 volatile uint8_t *bios = flash->virtual_memory;
58
59 /* unprotected */
Uwe Hermann394131e2008-10-18 21:14:13 +000060 write_lockbits_49fl00x(flash->virtual_registers,
61 total_size, 0, page_size);
Nikolay Petukhov4784c472008-05-17 01:08:58 +000062
Uwe Hermann394131e2008-10-18 21:14:13 +000063 /*
64 * erase_chip_jedec() will not work... Datasheet says
65 * "Chip erase is available in A/A Mux Mode only".
66 */
Nikolay Petukhov4784c472008-05-17 01:08:58 +000067 printf("Erasing page: ");
68 for (i = 0; i < total_size / page_size; i++) {
69 if ((i >= exclude_start_page) && (i < exclude_end_page))
70 continue;
71
72 /* erase the page */
73 erase_block_jedec(bios, i * page_size);
74 printf("%04d at address: 0x%08x", i, i * page_size);
75 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
76 fflush(stdout);
77 }
78 printf("\n");
79
80 /* protected */
Uwe Hermann394131e2008-10-18 21:14:13 +000081 write_lockbits_49fl00x(flash->virtual_registers,
82 total_size, 1, page_size);
Nikolay Petukhov4784c472008-05-17 01:08:58 +000083
84 return 0;
85}
86
87int write_49fl00x(struct flashchip *flash, uint8_t *buf)
88{
89 int i;
90 int total_size = flash->total_size * 1024;
91 int page_size = flash->page_size;
92 volatile uint8_t *bios = flash->virtual_memory;
93
94 /* unprotected */
Uwe Hermann394131e2008-10-18 21:14:13 +000095 write_lockbits_49fl00x(flash->virtual_registers, total_size, 0,
96 page_size);
Nikolay Petukhov4784c472008-05-17 01:08:58 +000097
98 printf("Programming page: ");
99 for (i = 0; i < total_size / page_size; i++) {
100 if ((i >= exclude_start_page) && (i < exclude_end_page))
101 continue;
102
103 /* erase the page before programming */
104 erase_block_jedec(bios, i * page_size);
105
106 /* write to the sector */
107 printf("%04d at address: 0x%08x", i, i * page_size);
108 write_sector_jedec(bios, buf + i * page_size,
109 bios + i * page_size, page_size);
110 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
111 fflush(stdout);
112 }
113 printf("\n");
Uwe Hermann394131e2008-10-18 21:14:13 +0000114
Nikolay Petukhov4784c472008-05-17 01:08:58 +0000115 /* protected */
Uwe Hermann394131e2008-10-18 21:14:13 +0000116 write_lockbits_49fl00x(flash->virtual_registers, total_size, 1,
117 page_size);
Nikolay Petukhov4784c472008-05-17 01:08:58 +0000118
119 return 0;
120}