Signed-off by: Matthias Buecher <m...@maddes.net> - - - -
Setting the trx header flags can be very useful, for instance when reverting/switching from DD-Wrt to OpenWrt. It can emulate DD-Wrt's "-noheader" option with "-c 1", so the image can be flashed correctly, e.g. on Buffalo WZR-HP-G300NH with DD-Wrt installed. But it also allows to set any value necessary. Patch inline for comments and also attached. Index: tools/firmware-utils/src/trx.c =================================================================== --- tools/firmware-utils/src/trx.c (revision 32896) +++ tools/firmware-utils/src/trx.c (working copy) @@ -16,8 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* July 29, 2004 +/* + * Copyright (C) 2005-2012 OpenWrt.org * + * July 29, 2004 + * * This is a hacked replacement for the 'trx' utility used to create * wrt54g .trx firmware files. It isn't pretty, but it does the job * for me. @@ -41,6 +44,10 @@ * extend trx header struct for new version * assume v1 for as default * Add option -2 to allow v2 header + * + * July 27, 2012 - maddes + * + * Add option -c to allow specifying the flags in the header */ #include <stdio.h> @@ -85,7 +92,8 @@ void usage(void) { fprintf(stderr, "Usage:\n"); - fprintf(stderr, " trx [-2] [-o outfile] [-m maxlen] [-a align] [-b absolute offset] [-x relative offset]\n"); + fprintf(stderr, " trx [-2] [-o outfile] [-m maxlen] [-a align] [-c flag value]\n"); + fprintf(stderr, " [-b absolute offset] [-x relative offset]\n"); fprintf(stderr, " [-f file] [-f file [-f file [-f file (v2 only)]]]\n"); exit(EXIT_FAILURE); } @@ -103,10 +111,11 @@ uint32_t cur_len, fsmark=0; unsigned long maxlen = TRX_MAX_LEN; struct trx_header *p; - char trx_version = 1; + uint16_t trx_version = 1; unsigned char binheader[32]; + uint16_t trx_flags = 0; - fprintf(stderr, "mjn3's trx replacement - v0.81.1\n"); + fprintf(stderr, "mjn3's trx replacement - v0.81.1 (OpenWrt.org 2012-07-27)\n"); if (!(buf = malloc(maxlen))) { fprintf(stderr, "malloc failed\n"); @@ -121,7 +130,7 @@ in = NULL; i = 0; - while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:")) != -1) { + while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:c:")) != -1) { switch (c) { case '2': /* take care that nothing was written to buf so far */ @@ -243,11 +252,25 @@ } break; + case 'c': + errno = 0; + n = strtoul(optarg, &e, 0); + if (errno || (e == optarg) || *e) { + fprintf(stderr, "-c: illegal numeric string\n"); + usage(); + } + if ((n < 0) || (n > 0xFFFF)) { + fprintf(stderr, "WARNING: current flag value exceeds 16 bits (and is truncated)\n"); + trx_flags = n & 0xFFFF; + } else { + trx_flags = n; + } + break; default: usage(); } } - p->flag_version = STORE32_LE((trx_version << 16)); + p->flag_version = STORE32_LE((trx_version << 16) + trx_flags); if (!in) { fprintf(stderr, "we require atleast one filename\n");
Index: tools/firmware-utils/src/trx.c =================================================================== --- tools/firmware-utils/src/trx.c (revision 32896) +++ tools/firmware-utils/src/trx.c (working copy) @@ -16,8 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* July 29, 2004 +/* + * Copyright (C) 2005-2012 OpenWrt.org * + * July 29, 2004 + * * This is a hacked replacement for the 'trx' utility used to create * wrt54g .trx firmware files. It isn't pretty, but it does the job * for me. @@ -41,6 +44,10 @@ * extend trx header struct for new version * assume v1 for as default * Add option -2 to allow v2 header + * + * July 27, 2012 - maddes + * + * Add option -c to allow specifying the flags in the header */ #include <stdio.h> @@ -85,7 +92,8 @@ void usage(void) { fprintf(stderr, "Usage:\n"); - fprintf(stderr, " trx [-2] [-o outfile] [-m maxlen] [-a align] [-b absolute offset] [-x relative offset]\n"); + fprintf(stderr, " trx [-2] [-o outfile] [-m maxlen] [-a align] [-c flag value]\n"); + fprintf(stderr, " [-b absolute offset] [-x relative offset]\n"); fprintf(stderr, " [-f file] [-f file [-f file [-f file (v2 only)]]]\n"); exit(EXIT_FAILURE); } @@ -103,10 +111,11 @@ uint32_t cur_len, fsmark=0; unsigned long maxlen = TRX_MAX_LEN; struct trx_header *p; - char trx_version = 1; + uint16_t trx_version = 1; unsigned char binheader[32]; + uint16_t trx_flags = 0; - fprintf(stderr, "mjn3's trx replacement - v0.81.1\n"); + fprintf(stderr, "mjn3's trx replacement - v0.81.1 (OpenWrt.org 2012-07-27)\n"); if (!(buf = malloc(maxlen))) { fprintf(stderr, "malloc failed\n"); @@ -121,7 +130,7 @@ in = NULL; i = 0; - while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:")) != -1) { + while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:c:")) != -1) { switch (c) { case '2': /* take care that nothing was written to buf so far */ @@ -243,11 +252,25 @@ } break; + case 'c': + errno = 0; + n = strtoul(optarg, &e, 0); + if (errno || (e == optarg) || *e) { + fprintf(stderr, "-c: illegal numeric string\n"); + usage(); + } + if ((n < 0) || (n > 0xFFFF)) { + fprintf(stderr, "WARNING: current flag value exceeds 16 bits (and is truncated)\n"); + trx_flags = n & 0xFFFF; + } else { + trx_flags = n; + } + break; default: usage(); } } - p->flag_version = STORE32_LE((trx_version << 16)); + p->flag_version = STORE32_LE((trx_version << 16) + trx_flags); if (!in) { fprintf(stderr, "we require atleast one filename\n");
_______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel