mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2024-11-29 17:20:38 +02:00
add -f option to skip trx check
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@1809 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
d89e6bd947
commit
e1487a7c65
@ -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,33 +65,35 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
count = read(trxfd, &trx, sizeof(struct trx_header));
|
if (force == 0) {
|
||||||
if (count < sizeof(struct trx_header)) {
|
count = read(trxfd, &trx, sizeof(struct trx_header));
|
||||||
fprintf(stderr, "Could not trx header, file too small (%ld bytes)\n", count);
|
if (count < sizeof(struct trx_header)) {
|
||||||
close(trxfd);
|
fprintf(stderr, "Could not get trx header, file too small (%ld bytes)\n", count);
|
||||||
exit(1);
|
close(trxfd);
|
||||||
}
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (trx.magic != TRX_MAGIC || trx.len < sizeof(struct trx_header)) {
|
if (trx.magic != TRX_MAGIC || trx.len < sizeof(struct trx_header)) {
|
||||||
fprintf(stderr, "Bad trx header\n");
|
fprintf(stderr, "Bad trx header\n");
|
||||||
fprintf(stderr, "If this is a firmware in bin format, like some of the\n"
|
fprintf(stderr, "If this is a firmware in bin format, like some of the\n"
|
||||||
"original firmware files are, use following command to convert to trx:\n"
|
"original firmware files are, use following command to convert to trx:\n"
|
||||||
"dd if=firmware.bin of=firmware.trx bs=32 skip=1\n");
|
"dd if=firmware.bin of=firmware.trx bs=32 skip=1\n");
|
||||||
close(trxfd);
|
close(trxfd);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user