blob: 9d104e2756f9b4fc718578977624a2edc33165e1 [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
Nikolay Petukhov4784c472008-05-17 01:08:58 +000023#include "flash.h"
24
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000025void write_lockbits_49fl00x(chipaddr bios, int size,
Uwe Hermann394131e2008-10-18 21:14:13 +000026 unsigned char bits, int block_size)
Nikolay Petukhov4784c472008-05-17 01:08:58 +000027{
28 int i, left = size;
29
30 for (i = 0; left >= block_size; i++, left -= block_size) {
Nikolay Petukhov4784c472008-05-17 01:08:58 +000031 /* pm49fl002 */
Uwe Hermann394131e2008-10-18 21:14:13 +000032 if (block_size == 16384 && i % 2)
Nikolay Petukhov4784c472008-05-17 01:08:58 +000033 continue;
34
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000035 chip_writeb(bits, bios + (i * block_size) + 2);
Nikolay Petukhov4784c472008-05-17 01:08:58 +000036 }
37}
38
Nikolay Petukhov4784c472008-05-17 01:08:58 +000039int erase_49fl00x(struct flashchip *flash)
40{
41 int i;
42 int total_size = flash->total_size * 1024;
43 int page_size = flash->page_size;
Nikolay Petukhov4784c472008-05-17 01:08:58 +000044
45 /* unprotected */
Uwe Hermann394131e2008-10-18 21:14:13 +000046 write_lockbits_49fl00x(flash->virtual_registers,
47 total_size, 0, page_size);
Nikolay Petukhov4784c472008-05-17 01:08:58 +000048
Uwe Hermann394131e2008-10-18 21:14:13 +000049 /*
50 * erase_chip_jedec() will not work... Datasheet says
51 * "Chip erase is available in A/A Mux Mode only".
52 */
Nikolay Petukhov4784c472008-05-17 01:08:58 +000053 printf("Erasing page: ");
54 for (i = 0; i < total_size / page_size; i++) {
Nikolay Petukhov4784c472008-05-17 01:08:58 +000055 /* erase the page */
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000056 if (erase_block_jedec(flash, i * page_size, page_size)) {
57 fprintf(stderr, "ERASE FAILED!\n");
58 return -1;
59 }
Nikolay Petukhov4784c472008-05-17 01:08:58 +000060 printf("%04d at address: 0x%08x", i, i * page_size);
61 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");
62 fflush(stdout);
63 }
64 printf("\n");
65
66 /* protected */
Uwe Hermann394131e2008-10-18 21:14:13 +000067 write_lockbits_49fl00x(flash->virtual_registers,
68 total_size, 1, page_size);
Nikolay Petukhov4784c472008-05-17 01:08:58 +000069
70 return 0;
71}
72
73int write_49fl00x(struct flashchip *flash, uint8_t *buf)
74{
75 int i;
76 int total_size = flash->total_size * 1024;
77 int page_size = flash->page_size;
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000078 chipaddr bios = flash->virtual_memory;
Nikolay Petukhov4784c472008-05-17 01:08:58 +000079
80 /* unprotected */
Uwe Hermann394131e2008-10-18 21:14:13 +000081 write_lockbits_49fl00x(flash->virtual_registers, total_size, 0,
82 page_size);
Nikolay Petukhov4784c472008-05-17 01:08:58 +000083
84 printf("Programming page: ");
85 for (i = 0; i < total_size / page_size; i++) {
Nikolay Petukhov4784c472008-05-17 01:08:58 +000086 /* erase the page before programming */
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000087 if (erase_block_jedec(flash, i * page_size, page_size)) {
88 fprintf(stderr, "ERASE FAILED!\n");
89 return -1;
90 }
Nikolay Petukhov4784c472008-05-17 01:08:58 +000091
92 /* write to the sector */
93 printf("%04d at address: 0x%08x", i, i * page_size);
Sean Nelsonc57a9202010-01-04 17:15:23 +000094 write_sector_jedec_common(flash, buf + i * page_size,
95 bios + i * page_size, page_size, 0xffff);
Nikolay Petukhov4784c472008-05-17 01:08:58 +000096 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");
97 fflush(stdout);
98 }
99 printf("\n");
Uwe Hermann394131e2008-10-18 21:14:13 +0000100
Nikolay Petukhov4784c472008-05-17 01:08:58 +0000101 /* protected */
Uwe Hermann394131e2008-10-18 21:14:13 +0000102 write_lockbits_49fl00x(flash->virtual_registers, total_size, 1,
103 page_size);
Nikolay Petukhov4784c472008-05-17 01:08:58 +0000104
105 return 0;
106}