/* * readrom: simple code to read 256k of rom from phatbox * usage: readrom * based on code for devmem2, copyright statement appears below: * * devmem2.c: Simple program to read/write from/to any location in memory. * * Copyright (C) 2000, Jan-Derk Bakker (jdb@lartmaker.nl) * * * This software has been developed for the LART computing board * (http://www.lart.tudelft.nl/). The development has been sponsored by * the Mobile MultiMedia Communications (http://www.mmc.tudelft.nl/) * and Ubiquitous Communications (http://www.ubicom.tudelft.nl/) * projects. * * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include #include #include #include #include #include #include #include #include #include #include #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) #define MAP_SIZE 4096UL #define MAP_MASK (MAP_SIZE - 1) int main(int argc, char **argv) { int fd; void *map_base, *virt_addr; FILE *outfile; unsigned long read_result, writeval; off_t target; int pagenum; int access_type = 'w'; printf("readrom started\n"); fflush(stdout); if(argc < 1) { fprintf(stderr, "\nUsage:\t%s outfile\n" "\toutfile : output file to create\n\n", argv[0]); exit(1); } printf("opening /dev/mem\n"); fflush(stdout); if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL; printf("/dev/mem opened, fd = %d.\n",fd); fflush(stdout); if(!(outfile=fopen(argv[1],"w"))) FATAL; printf("Output file %s opened.\n",argv[1]); fflush(stdout); map_base = mmap(0, 256*1024, PROT_READ, MAP_SHARED, fd, 0); if(map_base == (void *) -1) FATAL; printf("Memory mapped at address %p.\n", map_base); fflush(stdout); fwrite(map_base,1,256*1024,outfile); /* if(munmap(map_base, 256*1024) == -1) FATAL;*/ printf("okay, wrote stuff.\n"); fflush(stdout); close(fd); fclose(outfile); return 0; }