local: Respect -s (simulate) flag for dump -e operation

This commit is contained in:
Pali Rohár committed 2021-05-01 20:39:44 +02:00
1 parent bbf438e1a8
commit f144067634
1 file changed
+12
+12
View File
@@ -228,7 +228,10 @@ static int local_nanddump(const char * file, int mtd, int offset, int length) {
snprintf(command, size+1, "nanddump --omitoob -s %d -l %d -f %s /dev/mtd%d", offset, length, file, mtd); snprintf(command, size+1, "nanddump --omitoob -s %d -l %d -f %s /dev/mtd%d", offset, length, file, mtd);
if ( ! simulate )
ret = system(command); ret = system(command);
else
ret = 0;
free(command); free(command);
@@ -452,11 +455,14 @@ int local_dump_image(enum image_type image, const char * file) {
ret = local_nanddump(file, nand_device[device].args[image].mtd, nand_device[device].args[image].offset, header); ret = local_nanddump(file, nand_device[device].args[image].mtd, nand_device[device].args[image].offset, header);
if ( ret != 0 ) { if ( ret != 0 ) {
if ( ! simulate )
unlink(file); unlink(file);
ret = -1; ret = -1;
goto clean; goto clean;
} }
if ( ! simulate ) {
fd = open(file, O_RDONLY); fd = open(file, O_RDONLY);
if ( fd >= 0 ) { if ( fd >= 0 ) {
if ( read(fd, buf, 20) == 20 && memcmp(buf, "NOLO!img\x02\x00\x00\x00\x00\x00\x00\x00", 16) == 0 ) if ( read(fd, buf, 20) == 20 && memcmp(buf, "NOLO!img\x02\x00\x00\x00\x00\x00\x00\x00", 16) == 0 )
@@ -465,6 +471,9 @@ int local_dump_image(enum image_type image, const char * file) {
} }
unlink(file); unlink(file);
}
} }
ret = local_nanddump(file, nand_device[device].args[image].mtd, nand_device[device].args[image].offset + header, nand_device[device].args[image].length - header); ret = local_nanddump(file, nand_device[device].args[image].mtd, nand_device[device].args[image].offset + header, nand_device[device].args[image].length - header);
@@ -476,6 +485,9 @@ int local_dump_image(enum image_type image, const char * file) {
goto clean; goto clean;
} }
if ( simulate )
goto clean;
fd = open(file, O_RDWR); fd = open(file, O_RDWR);
if ( fd < 0 ) if ( fd < 0 )
goto clean; goto clean;