flashrom: Only write the flash if the image has the same size

Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Segher Boessenkool <segher@kernel.crashing.org>



git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2503 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Stefan Reinauer 2006-11-21 23:48:51 +00:00 committed by Stefan Reinauer
parent 9e2019200f
commit 3a998642f5
1 changed files with 13 additions and 0 deletions

View File

@ -28,6 +28,8 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -332,10 +334,21 @@ int main(int argc, char *argv[])
fclose(image); fclose(image);
printf("done\n"); printf("done\n");
} else { } else {
struct stat image_stat;
if ((image = fopen(filename, "r")) == NULL) { if ((image = fopen(filename, "r")) == NULL) {
perror(filename); perror(filename);
exit(1); exit(1);
} }
if (fstat(fileno(image), &image_stat) != 0) {
perror(filename);
exit(1);
}
if(image_stat.st_size!=flash->total_size*1024) {
perror("Image size doesnt match");
exit(1);
}
fread(buf, sizeof(char), size, image); fread(buf, sizeof(char), size, image);
show_id(buf, size); show_id(buf, size);
fclose(image); fclose(image);