summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2018-01-30 17:45:15 -0600
committerJohn Klug <john.klug@multitech.com>2018-01-30 17:45:15 -0600
commite3615d09e64b1584b9e7820e2a8bcdb5569d2994 (patch)
tree65ce4e374da578bb8ca301a11b1e06ea7e597421
parent8f4e14a7d89a14b84d577f43e0bdfab3c95d5105 (diff)
downloadmts-id-eeprom-e3615d09e64b1584b9e7820e2a8bcdb5569d2994.tar.gz
mts-id-eeprom-e3615d09e64b1584b9e7820e2a8bcdb5569d2994.tar.bz2
mts-id-eeprom-e3615d09e64b1584b9e7820e2a8bcdb5569d2994.zip
Command to copy bootstrap header for Romboot0.3.4
-rw-r--r--src/Makefile.am2
-rw-r--r--src/mts_hdr_copy.c64
2 files changed, 48 insertions, 18 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b56adf7..a559d8e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,5 +36,5 @@ install-exec-hook:
cd $(DESTDIR)$(sbindir) && \
mv mts-fpga-loader ../../sbin/mts-fpga-loader
cd $(DESTDIR)$(sbindir) && \
- mv mts-hdr-cpy ../../sbin/mts-hdr-cpy
+ mv mts-hdr-copy ../../sbin/mts-hdr-copy
rmdir $(DESTDIR)$(sbindir)
diff --git a/src/mts_hdr_copy.c b/src/mts_hdr_copy.c
index 2f1da3e..dfd6472 100644
--- a/src/mts_hdr_copy.c
+++ b/src/mts_hdr_copy.c
@@ -9,6 +9,9 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
+#include <getopt.h>
+#include <string.h>
+#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -28,31 +31,58 @@ compare(const void *a, const void *b)
return 0;
}
+void
+usage(void)
+{
+ fprintf(stderr,
+ "Usage:\n"
+ " mts-hdr-copy /dev/mtd1 >/tmp/hdr.bin\n"
+ " This comand reads standard input, and if over\n"
+ " half the 32 bit words for the first 52 words\n"
+ " are in agreement, 52 copies of the 32 bit word\n"
+ " are written to stdout. Otherwise we exit with\n"
+ " status 1. This command is intended to read the\n"
+ " existing bootstrap in /dev/mtd1, to create a\n"
+ " new bootstrap\n"
+ );
+ exit(1);
+}
+
#define NMEMB 52
int
-main(int argc, char *argv)
+main(int argc, char *argv[])
{
unsigned int header[NMEMB];
- int i,count;
- int nmax, lastmax;
+ int i,count,opt;
+ int nmax, lastmax, fd;
unsigned int previous, lastmaxval;
- if(argc > 1) {
- fprintf(stderr,
- "Usage:\n"
- " cat /dev/mtd1 | mts_hdr_copy >/tmp/hdr.bin\n"
- " This comand reads standard input, and if over\n"
- " half the 32 bit words for the first 52 words\n"
- " are in agreement, 52 copies of the 32 bit word\n"
- " are written to stdout. Otherwise we exit with\n"
- " status 1. This command is intended to read the\n"
- " existing bootstrap in /dev/mtd1, to create a\n"
- " new bootstrap\n"
- );
+ fclose(stdin);
+
+ while((opt = getopt(argc,argv,"")) != -1) switch(opt){
+ case 'h':
+ usage();
+ break;
+ default:
+ usage();
+ break;
+ }
+ if(argc - optind != 1) {
+ fprintf(stderr,"Missing device parameter\n");
+ usage();
exit(0);
}
- count = read(0,header,sizeof header);
+ fd = open(argv[optind],O_RDONLY);
+
+ if (fd == -1) {
+ fprintf(stderr,"mts-hdr-copy: File argument \"%s\" could not be opened: %s\n",
+ argv[optind],strerror(errno));
+ usage();
+ }
+
+ count = read(fd,header,sizeof header);
+ close(fd);
if (count != sizeof header) {
DBGPRT("Could not read complete input\n");
@@ -90,7 +120,7 @@ main(int argc, char *argv)
if (lastmax > NMEMB/2) {
for (i=0; i< NMEMB; i++)
header[i] = lastmaxval;
- fprintf(stderr,"Attempting to write 52 copies of 0x%8.8x\n",lastmaxval);
+ fprintf(stderr,"Attempting to write 52 copies of 0x%8.8x for the bootstrap header\n",lastmaxval);
if ((count = write(1,header,sizeof header)) == sizeof header)
exit(0);
else {