Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 2 | * This file is part of the flashrom project. |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 3 | * |
Uwe Hermann | d22a1d4 | 2007-09-09 20:21:05 +0000 | [diff] [blame] | 4 | * Copyright (C) 2000 Silicon Integrated System Corporation |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 5 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 6 | * 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. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 10 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 11 | * 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. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 15 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 16 | * 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. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Ronald G. Minnich | 5eaed68 | 2006-03-14 19:58:14 +0000 | [diff] [blame] | 21 | #include <stdlib.h> |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 22 | #include "flash.h" |
Sean Nelson | 14ba668 | 2010-02-26 05:48:29 +0000 | [diff] [blame] | 23 | #include "chipdrivers.h" |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 24 | |
Carl-Daniel Hailfinger | aca1dce | 2010-01-07 21:23:45 +0000 | [diff] [blame] | 25 | /* FIXME: The datasheet is unclear whether we should use toggle_ready_jedec |
| 26 | * or wait_82802ab. |
| 27 | */ |
| 28 | |
| 29 | int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen) |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 30 | { |
Carl-Daniel Hailfinger | aca1dce | 2010-01-07 21:23:45 +0000 | [diff] [blame] | 31 | chipaddr bios = flash->virtual_memory + blockaddr; |
| 32 | chipaddr wrprotect = flash->virtual_registers + blockaddr + 2; |
Ronald G. Minnich | 5eaed68 | 2006-03-14 19:58:14 +0000 | [diff] [blame] | 33 | uint8_t status; |
| 34 | |
| 35 | // clear status register |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 36 | chip_writeb(0x50, bios); |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 37 | printf("Erase at 0x%lx\n", bios); |
Carl-Daniel Hailfinger | aca1dce | 2010-01-07 21:23:45 +0000 | [diff] [blame] | 38 | status = wait_82802ab(flash->virtual_memory); |
Sean Nelson | e4446e4 | 2010-03-16 00:51:31 +0000 | [diff] [blame^] | 39 | print_82802ab_status(status); |
Ronald G. Minnich | 5eaed68 | 2006-03-14 19:58:14 +0000 | [diff] [blame] | 40 | // clear write protect |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 41 | printf("write protect is at 0x%lx\n", (wrprotect)); |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 42 | printf("write protect is 0x%x\n", chip_readb(wrprotect)); |
| 43 | chip_writeb(0, wrprotect); |
| 44 | printf("write protect is 0x%x\n", chip_readb(wrprotect)); |
Ronald G. Minnich | 5eaed68 | 2006-03-14 19:58:14 +0000 | [diff] [blame] | 45 | |
| 46 | // now start it |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 47 | chip_writeb(0x20, bios); |
| 48 | chip_writeb(0xd0, bios); |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 49 | programmer_delay(10); |
Ronald G. Minnich | 5eaed68 | 2006-03-14 19:58:14 +0000 | [diff] [blame] | 50 | // now let's see what the register is |
Carl-Daniel Hailfinger | aca1dce | 2010-01-07 21:23:45 +0000 | [diff] [blame] | 51 | status = wait_82802ab(flash->virtual_memory); |
Sean Nelson | e4446e4 | 2010-03-16 00:51:31 +0000 | [diff] [blame^] | 52 | print_82802ab_status(status); |
Carl-Daniel Hailfinger | aca1dce | 2010-01-07 21:23:45 +0000 | [diff] [blame] | 53 | printf("DONE BLOCK 0x%x\n", blockaddr); |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 54 | |
Carl-Daniel Hailfinger | aca1dce | 2010-01-07 21:23:45 +0000 | [diff] [blame] | 55 | if (check_erased_range(flash, blockaddr, blocklen)) { |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 56 | fprintf(stderr, "ERASE FAILED!\n"); |
| 57 | return -1; |
| 58 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 59 | return 0; |
Ronald G. Minnich | 5eaed68 | 2006-03-14 19:58:14 +0000 | [diff] [blame] | 60 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 61 | |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 62 | int write_lhf00l04(struct flashchip *flash, uint8_t *buf) |
| 63 | { |
| 64 | int i; |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 65 | int total_size = flash->total_size * 1024; |
| 66 | int page_size = flash->page_size; |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 67 | chipaddr bios = flash->virtual_memory; |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 68 | |
Carl-Daniel Hailfinger | aca1dce | 2010-01-07 21:23:45 +0000 | [diff] [blame] | 69 | if (erase_flash(flash)) { |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 70 | fprintf(stderr, "ERASE FAILED!\n"); |
Ronald G. Minnich | 5eaed68 | 2006-03-14 19:58:14 +0000 | [diff] [blame] | 71 | return -1; |
| 72 | } |
Uwe Hermann | a502dce | 2007-10-17 23:55:15 +0000 | [diff] [blame] | 73 | printf("Programming page: "); |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 74 | for (i = 0; i < total_size / page_size; i++) { |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 75 | printf("%04d at address: 0x%08x", i, i * page_size); |
Sean Nelson | e4446e4 | 2010-03-16 00:51:31 +0000 | [diff] [blame^] | 76 | write_page_82802ab(bios, buf + i * page_size, |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 77 | bios + i * page_size, page_size); |
| 78 | 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. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 79 | } |
| 80 | printf("\n"); |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 81 | |
| 82 | return 0; |
Ronald G. Minnich | 5b582f2 | 2006-02-23 17:16:44 +0000 | [diff] [blame] | 83 | } |