sst49lf040.c 2.09 KB
Newer Older
1 2
/*
 * This file is part of the flashrom project.
David Hendricks's avatar
David Hendricks committed
3
 *
4
 * Copyright (C) 2000 Silicon Integrated System Corporation
David Hendricks's avatar
David Hendricks committed
5
 *
6 7 8 9
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
David Hendricks's avatar
David Hendricks committed
10
 *
11 12 13 14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
15
 *
16 17 18
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
David Hendricks's avatar
David Hendricks committed
19
 */
Uwe Hermann's avatar
Uwe Hermann committed
20

David Hendricks's avatar
David Hendricks committed
21 22
#include "flash.h"

23 24
int erase_49lf040(struct flashchip *flash)
{
Uwe Hermann's avatar
Uwe Hermann committed
25 26 27
	int i;
	int total_size = flash->total_size * 1024;
	int page_size = flash->page_size;
28

Uwe Hermann's avatar
Uwe Hermann committed
29
	for (i = 0; i < total_size / page_size; i++) {
30 31
		/* Chip erase only works in parallel programming mode
		 * for the 49lf040. Use sector-erase instead */
32 33 34 35
		if (erase_sector_jedec(flash, i * page_size, page_size)) {
			fprintf(stderr, "ERASE FAILED!\n");
			return -1;
		}
Uwe Hermann's avatar
Uwe Hermann committed
36
	}
Uwe Hermann's avatar
Uwe Hermann committed
37

38 39 40
	return 0;
}

41
int write_49lf040(struct flashchip *flash, uint8_t *buf)
David Hendricks's avatar
David Hendricks committed
42 43
{
	int i;
44 45
	int total_size = flash->total_size * 1024;
	int page_size = flash->page_size;
46
	chipaddr bios = flash->virtual_memory;
David Hendricks's avatar
David Hendricks committed
47

48
	printf("Programming page: ");
49
	for (i = 0; i < total_size / page_size; i++) {
Ollie Lho's avatar
Ollie Lho committed
50
		/* erase the page before programming
51 52
		 * Chip erase only works in parallel programming mode
		 * for the 49lf040. Use sector-erase instead */
53 54 55 56
		if (erase_sector_jedec(flash, i * page_size, page_size)) {
			fprintf(stderr, "ERASE FAILED!\n");
			return -1;
		}
David Hendricks's avatar
David Hendricks committed
57 58

		/* write to the sector */
59 60
		if (i % 10 == 0)
			printf("%04d at address: 0x%08x ", i, i * page_size);
Uwe Hermann's avatar
Uwe Hermann committed
61

62 63
		write_sector_jedec(bios, buf + i * page_size,
				   bios + i * page_size, page_size);
64

65 66
		if (i % 10 == 0)
			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\b");
67
		fflush(stdout);
David Hendricks's avatar
David Hendricks committed
68 69 70
	}
	printf("\n");

Uwe Hermann's avatar
Uwe Hermann committed
71
	return 0;
David Hendricks's avatar
David Hendricks committed
72
}