blob: d5ab38cb2046a31d63b2d00d155f137baa1e2a44 [file] [log] [blame]
Ronald G. Minnich5b582f22006-02-23 17:16:44 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Ronald G. Minnich5b582f22006-02-23 17:16:44 +00003 *
Uwe Hermannd22a1d42007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
Ronald G. Minnich5b582f22006-02-23 17:16:44 +00005 *
Uwe Hermannd1107642007-08-29 17:52:32 +00006 * 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.
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000010 *
Uwe Hermannd1107642007-08-29 17:52:32 +000011 * 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.
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000015 *
Uwe Hermannd1107642007-08-29 17:52:32 +000016 * 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
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000019 */
20
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000021#include <stdlib.h>
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000022#include "flash.h"
Sean Nelson14ba6682010-02-26 05:48:29 +000023#include "chipdrivers.h"
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000024
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000025// I need that Berkeley bit-map printer
26void print_lhf00l04_status(uint8_t status)
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000027{
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000028 printf("%s", status & 0x80 ? "Ready:" : "Busy:");
29 printf("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:");
30 printf("%s", status & 0x20 ? "BE ERROR:" : "BE OK:");
31 printf("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:");
32 printf("%s", status & 0x8 ? "VP ERR:" : "VPP OK:");
33 printf("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:");
34 printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000035}
36
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000037/* FIXME: The datasheet is unclear whether we should use toggle_ready_jedec
38 * or wait_82802ab.
39 */
40
41int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen)
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000042{
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000043 chipaddr bios = flash->virtual_memory + blockaddr;
44 chipaddr wrprotect = flash->virtual_registers + blockaddr + 2;
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000045 uint8_t status;
46
47 // clear status register
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000048 chip_writeb(0x50, bios);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000049 printf("Erase at 0x%lx\n", bios);
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000050 status = wait_82802ab(flash->virtual_memory);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000051 print_lhf00l04_status(status);
52 // clear write protect
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000053 printf("write protect is at 0x%lx\n", (wrprotect));
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000054 printf("write protect is 0x%x\n", chip_readb(wrprotect));
55 chip_writeb(0, wrprotect);
56 printf("write protect is 0x%x\n", chip_readb(wrprotect));
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000057
58 // now start it
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000059 chip_writeb(0x20, bios);
60 chip_writeb(0xd0, bios);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000061 programmer_delay(10);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000062 // now let's see what the register is
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000063 status = wait_82802ab(flash->virtual_memory);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000064 print_lhf00l04_status(status);
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000065 printf("DONE BLOCK 0x%x\n", blockaddr);
Uwe Hermannffec5f32007-08-23 16:08:21 +000066
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000067 if (check_erased_range(flash, blockaddr, blocklen)) {
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000068 fprintf(stderr, "ERASE FAILED!\n");
69 return -1;
70 }
Uwe Hermannffec5f32007-08-23 16:08:21 +000071 return 0;
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000072}
Uwe Hermannffec5f32007-08-23 16:08:21 +000073
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000074void write_page_lhf00l04(chipaddr bios, uint8_t *src,
75 chipaddr dst, int page_size)
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000076{
77 int i;
78
79 for (i = 0; i < page_size; i++) {
80 /* transfer data from source to destination */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000081 chip_writeb(0x40, dst);
82 chip_writeb(*src++, dst++);
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000083 wait_82802ab(bios);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000084 }
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000085}
86
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000087int write_lhf00l04(struct flashchip *flash, uint8_t *buf)
88{
89 int i;
Uwe Hermanna7e05482007-05-09 10:17:44 +000090 int total_size = flash->total_size * 1024;
91 int page_size = flash->page_size;
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000092 chipaddr bios = flash->virtual_memory;
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000093
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000094 if (erase_flash(flash)) {
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000095 fprintf(stderr, "ERASE FAILED!\n");
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000096 return -1;
97 }
Uwe Hermanna502dce2007-10-17 23:55:15 +000098 printf("Programming page: ");
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000099 for (i = 0; i < total_size / page_size; i++) {
Ronald G. Minnich5b582f22006-02-23 17:16:44 +0000100 printf("%04d at address: 0x%08x", i, i * page_size);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +0000101 write_page_lhf00l04(bios, buf + i * page_size,
Uwe Hermanna7e05482007-05-09 10:17:44 +0000102 bios + i * page_size, page_size);
103 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");
Ronald G. Minnich5b582f22006-02-23 17:16:44 +0000104 }
105 printf("\n");
Uwe Hermannffec5f32007-08-23 16:08:21 +0000106
107 return 0;
Ronald G. Minnich5b582f22006-02-23 17:16:44 +0000108}