aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Maier <brandon.maier@collins.com>2022-11-02 17:47:53 -0500
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-11-07 08:24:35 +0100
commit516ba62c6699b1b2d1323013161692d46ae0cbcb (patch)
treef9c8e1ffdcfe875780bdee57592d7f6c2a4aff8d
parenta28c5307d6c32a819521542903e678c3c544fa6c (diff)
misc-utils: flashcp: add safe_memerase
Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--misc-utils/flashcp.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/misc-utils/flashcp.c b/misc-utils/flashcp.c
index 89d3386..718c513 100644
--- a/misc-utils/flashcp.c
+++ b/misc-utils/flashcp.c
@@ -189,6 +189,18 @@ static void safe_rewind (int fd,const char *filename)
safe_lseek(fd,0L,SEEK_SET,filename);
}
+static void safe_memerase (int fd,const char *device,struct erase_info_user *erase,bool verbose)
+{
+ if (ioctl (fd,MEMERASE,erase) < 0)
+ {
+ if (verbose) log_printf (LOG_NORMAL,"\n");
+ log_printf (LOG_ERROR,
+ "While erasing blocks 0x%.8x-0x%.8x on %s: %m\n",
+ (unsigned int) erase->start,(unsigned int) (erase->start + erase->length),device);
+ exit (EXIT_FAILURE);
+ }
+}
+
/******************************************************************************/
static int dev_fd = -1,fil_fd = -1;
@@ -329,14 +341,7 @@ int main (int argc,char *argv[])
for (i = 1; i <= blocks; i++)
{
log_printf (LOG_NORMAL,"\rErasing blocks: %d/%d (%d%%)",i,blocks,PERCENTAGE (i,blocks));
- if (ioctl (dev_fd,MEMERASE,&erase) < 0)
- {
- log_printf (LOG_NORMAL,"\n");
- log_printf (LOG_ERROR,
- "While erasing blocks 0x%.8x-0x%.8x on %s: %m\n",
- (unsigned int) erase.start,(unsigned int) (erase.start + erase.length),device);
- exit (EXIT_FAILURE);
- }
+ safe_memerase(dev_fd,device,&erase,flags & FLAG_VERBOSE);
erase.start += mtd.erasesize;
}
log_printf (LOG_NORMAL,"\rErasing blocks: %d/%d (100%%)\n",blocks,blocks);
@@ -344,13 +349,7 @@ int main (int argc,char *argv[])
else
{
/* if not, erase the whole chunk in one shot */
- if (ioctl (dev_fd,MEMERASE,&erase) < 0)
- {
- log_printf (LOG_ERROR,
- "While erasing blocks from 0x%.8x-0x%.8x on %s: %m\n",
- (unsigned int) erase.start,(unsigned int) (erase.start + erase.length),device);
- exit (EXIT_FAILURE);
- }
+ safe_memerase(dev_fd,device,&erase,flags & FLAG_VERBOSE);
}
DEBUG("Erased %u / %luk bytes\n",erase.length,filestat.st_size);
@@ -474,14 +473,7 @@ DIFF_BLOCKS:
diffBlock++;
/* erase block */
safe_lseek(dev_fd, current_dev_block, SEEK_SET, device);
- if (ioctl (dev_fd,MEMERASE,&erase) < 0)
- {
- log_printf (LOG_NORMAL,"\n");
- log_printf (LOG_ERROR,
- "While erasing blocks 0x%.8x-0x%.8x on %s: %m\n",
- (unsigned int) erase.start,(unsigned int) (erase.start + erase.length),device);
- exit (EXIT_FAILURE);
- }
+ safe_memerase(dev_fd,device,&erase,flags & FLAG_VERBOSE);
/* write to device */
safe_lseek(dev_fd, current_dev_block, SEEK_SET, device);