blob: 9669e2021e36642dffd2e2c0050b7883d5f5e10d [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"
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000023
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000024// I need that Berkeley bit-map printer
25void print_lhf00l04_status(uint8_t status)
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000026{
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000027 printf("%s", status & 0x80 ? "Ready:" : "Busy:");
28 printf("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:");
29 printf("%s", status & 0x20 ? "BE ERROR:" : "BE OK:");
30 printf("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:");
31 printf("%s", status & 0x8 ? "VP ERR:" : "VPP OK:");
32 printf("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:");
33 printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000034}
35
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000036/* FIXME: The datasheet is unclear whether we should use toggle_ready_jedec
37 * or wait_82802ab.
38 */
39
40int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen)
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000041{
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000042 chipaddr bios = flash->virtual_memory + blockaddr;
43 chipaddr wrprotect = flash->virtual_registers + blockaddr + 2;
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000044 uint8_t status;
45
46 // clear status register
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000047 chip_writeb(0x50, bios);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000048 printf("Erase at 0x%lx\n", bios);
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000049 status = wait_82802ab(flash->virtual_memory);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000050 print_lhf00l04_status(status);
51 // clear write protect
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000052 printf("write protect is at 0x%lx\n", (wrprotect));
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000053 printf("write protect is 0x%x\n", chip_readb(wrprotect));
54 chip_writeb(0, wrprotect);
55 printf("write protect is 0x%x\n", chip_readb(wrprotect));
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000056
57 // now start it
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000058 chip_writeb(0x20, bios);
59 chip_writeb(0xd0, bios);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000060 programmer_delay(10);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000061 // now let's see what the register is
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000062 status = wait_82802ab(flash->virtual_memory);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000063 print_lhf00l04_status(status);
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000064 printf("DONE BLOCK 0x%x\n", blockaddr);
Uwe Hermannffec5f32007-08-23 16:08:21 +000065
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000066 if (check_erased_range(flash, blockaddr, blocklen)) {
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000067 fprintf(stderr, "ERASE FAILED!\n");
68 return -1;
69 }
Uwe Hermannffec5f32007-08-23 16:08:21 +000070 return 0;
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000071}
Uwe Hermannffec5f32007-08-23 16:08:21 +000072
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000073void write_page_lhf00l04(chipaddr bios, uint8_t *src,
74 chipaddr dst, int page_size)
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000075{
76 int i;
77
78 for (i = 0; i < page_size; i++) {
79 /* transfer data from source to destination */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000080 chip_writeb(0x40, dst);
81 chip_writeb(*src++, dst++);
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000082 wait_82802ab(bios);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000083 }
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000084}
85
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000086int write_lhf00l04(struct flashchip *flash, uint8_t *buf)
87{
88 int i;
Uwe Hermanna7e05482007-05-09 10:17:44 +000089 int total_size = flash->total_size * 1024;
90 int page_size = flash->page_size;
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000091 chipaddr bios = flash->virtual_memory;
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000092
Carl-Daniel Hailfingeraca1dce2010-01-07 21:23:45 +000093 if (erase_flash(flash)) {
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000094 fprintf(stderr, "ERASE FAILED!\n");
Ronald G. Minnich5eaed682006-03-14 19:58:14 +000095 return -1;
96 }
Uwe Hermanna502dce2007-10-17 23:55:15 +000097 printf("Programming page: ");
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000098 for (i = 0; i < total_size / page_size; i++) {
Ronald G. Minnich5b582f22006-02-23 17:16:44 +000099 printf("%04d at address: 0x%08x", i, i * page_size);
Ronald G. Minnich5eaed682006-03-14 19:58:14 +0000100 write_page_lhf00l04(bios, buf + i * page_size,
Uwe Hermanna7e05482007-05-09 10:17:44 +0000101 bios + i * page_size, page_size);
102 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 +0000103 }
104 printf("\n");
Uwe Hermannffec5f32007-08-23 16:08:21 +0000105
106 return 0;
Ronald G. Minnich5b582f22006-02-23 17:16:44 +0000107}