/* * flash_rom.c: Flash programming utility for SiS 630/950 M/Bs * * * Copyright 2000 Silicon Integrated System Corporation * Copyright 2004 Tyan Corp * yhlu yhlu@tyan.com add exclude start and end option * * 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. * * 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. * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. * * * Reference: * 1. SiS 630 Specification * 2. SiS 950 Specification * * $Id: flash_rom.c,v 1.21 2005/01/11 02:48:22 ollie Exp $ */ #include #include #include #include #include #include #include #define UADDR1 0xAAA #define UADDR2 0x554 int main(int argc, char *argv[]) { int fd_mem, fd_flash, i, i2; volatile unsigned short *bios, flash; unsigned long off,valint; unsigned short val, wrote; if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) { perror("Can not open /dev/mem"); exit(1); } if ((fd_flash = open("flash.rom", O_RDONLY)) < 0) { perror("Can not open flash.rom"); exit(1); } bios = mmap((void *)0x70000000, 0x20000, PROT_WRITE | PROT_READ, MAP_SHARED, fd_mem, (off_t) (0x70000000)); if (bios == MAP_FAILED) { perror("Error MMAP /dev/mem"); exit(1); } /* Enter unlock bypass mode */ bios[UADDR1] = 0xf0; //msync((void *)bios, 0x20000, MS_SYNC); i=0; while (read(fd_flash, (void *)&flash, 2) == 2) { if ((bios[i] == 0xffff) && (flash != 0xffff)) { wrote = flash; printf("Setting 0x%02x=0x%04x\n", i, wrote); bios[UADDR1] = 0xAA; //msync((void *)bios, 0x20000, MS_SYNC); bios[UADDR2] = 0x55; //msync((void *)bios, 0x20000, MS_SYNC); bios[UADDR1] = 0xA0; //msync((void *)bios, 0x20000, MS_SYNC); bios[i] = wrote; msync((void *)bios, 0x20000, MS_SYNC); //i2=0x1000; //while(i2-- > 0); i2=0x1000000; while((bios[i] != wrote) && (i2-- > 0)); if (bios[i] != wrote) { printf("Error writing at %x (%x)\n", i, bios[i]); //bios[UADDR1] = 0xf0; } bios[UADDR1] = 0xAA; bios[UADDR2] = 0x55; bios[UADDR1] = 0xf0; msync((void *)bios, 0x20000, MS_SYNC); //msync((void *)bios, 0x20000, MS_SYNC); //printf("0x%02x=0x%04x\n", i, bios[i]); } i++; } bios[UADDR1] = 0xf0; munmap((void *) bios, 0x20000); return 0; }