|
|
@ -55,7 +55,7 @@ struct trx_header { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int |
|
|
|
trx_check(const char *trxfile, const char *mtd) |
|
|
|
trx_check(const char *trxfile, const char *mtd, int force) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct mtd_info_user mtdInfo; |
|
|
|
struct mtd_info_user mtdInfo; |
|
|
|
int trxfd, fd; |
|
|
|
int trxfd, fd; |
|
|
@ -65,19 +65,20 @@ trx_check(const char *trxfile, const char *mtd) |
|
|
|
|
|
|
|
|
|
|
|
trxfd = open(trxfile,O_RDONLY);
|
|
|
|
trxfd = open(trxfile,O_RDONLY);
|
|
|
|
if(trxfd < 0) { |
|
|
|
if(trxfd < 0) { |
|
|
|
fprintf(stderr, "Could not open trx image: %s\n", trxfile); |
|
|
|
fprintf(stderr, "Could not open image: %s\n", trxfile); |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (fstat(trxfd,&trxstat) < 0) { |
|
|
|
if (fstat(trxfd,&trxstat) < 0) { |
|
|
|
fprintf(stderr, "Could not get trx image file status: %s\n", trxfile); |
|
|
|
fprintf(stderr, "Could not get image file status: %s\n", trxfile); |
|
|
|
close(trxfd); |
|
|
|
close(trxfd); |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (force == 0) { |
|
|
|
count = read(trxfd, &trx, sizeof(struct trx_header)); |
|
|
|
count = read(trxfd, &trx, sizeof(struct trx_header)); |
|
|
|
if (count < sizeof(struct trx_header)) { |
|
|
|
if (count < sizeof(struct trx_header)) { |
|
|
|
fprintf(stderr, "Could not trx header, file too small (%ld bytes)\n", count); |
|
|
|
fprintf(stderr, "Could not get trx header, file too small (%ld bytes)\n", count); |
|
|
|
close(trxfd); |
|
|
|
close(trxfd); |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
@ -92,6 +93,7 @@ trx_check(const char *trxfile, const char *mtd) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lseek(trxfd, 0, SEEK_SET); |
|
|
|
lseek(trxfd, 0, SEEK_SET); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* check if image fits to mtd device */ |
|
|
|
/* check if image fits to mtd device */ |
|
|
|
|
|
|
|
|
|
|
@ -283,6 +285,7 @@ void usage(void) |
|
|
|
" write <imagefile> write imagefile to device\n" |
|
|
|
" write <imagefile> write imagefile to device\n" |
|
|
|
"Following options are available:\n" |
|
|
|
"Following options are available:\n" |
|
|
|
" -r reboot after successful command\n" |
|
|
|
" -r reboot after successful command\n" |
|
|
|
|
|
|
|
" -f force write without trx checks\n" |
|
|
|
" -e <device> erase <device> before executing the command\n\n" |
|
|
|
" -e <device> erase <device> before executing the command\n\n" |
|
|
|
"Example: To write linux.trx to mtd4 labeled as linux and reboot afterwards\n" |
|
|
|
"Example: To write linux.trx to mtd4 labeled as linux and reboot afterwards\n" |
|
|
|
" mtd -r write linux.trx linux\n\n"); |
|
|
|
" mtd -r write linux.trx linux\n\n"); |
|
|
@ -291,7 +294,7 @@ void usage(void) |
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char **argv) |
|
|
|
int main (int argc, char **argv) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int ch, i, boot, unlock, trxfd; |
|
|
|
int ch, i, boot, unlock, trxfd, force; |
|
|
|
char *erase[MAX_ARGS], *device; |
|
|
|
char *erase[MAX_ARGS], *device; |
|
|
|
enum { |
|
|
|
enum { |
|
|
|
CMD_ERASE, |
|
|
|
CMD_ERASE, |
|
|
@ -301,9 +304,13 @@ int main (int argc, char **argv) |
|
|
|
|
|
|
|
|
|
|
|
erase[0] = NULL; |
|
|
|
erase[0] = NULL; |
|
|
|
boot = 0; |
|
|
|
boot = 0; |
|
|
|
|
|
|
|
force = 0; |
|
|
|
|
|
|
|
|
|
|
|
while ((ch = getopt(argc, argv, "re:")) != -1) |
|
|
|
while ((ch = getopt(argc, argv, "fre:")) != -1) |
|
|
|
switch (ch) { |
|
|
|
switch (ch) { |
|
|
|
|
|
|
|
case 'f': |
|
|
|
|
|
|
|
force = 1; |
|
|
|
|
|
|
|
break; |
|
|
|
case 'r': |
|
|
|
case 'r': |
|
|
|
boot = 1; |
|
|
|
boot = 1; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -336,7 +343,7 @@ int main (int argc, char **argv) |
|
|
|
cmd = CMD_WRITE; |
|
|
|
cmd = CMD_WRITE; |
|
|
|
device = argv[2]; |
|
|
|
device = argv[2]; |
|
|
|
/* check trx file before erasing or writing anything */ |
|
|
|
/* check trx file before erasing or writing anything */ |
|
|
|
trxfd = trx_check(argv[1], device); |
|
|
|
trxfd = trx_check(argv[1], device, force); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
usage(); |
|
|
|
usage(); |
|
|
|
} |
|
|
|
} |
|
|
|