This adds command line option in "mktplinkfw" tool for endianness swap
in kernel load address and entry point fields. As in "mktplinkfw2" tool,
we will need this for little-endian targets, like "ramips".
Signed-off-by: Piotr Dymacz <pepe2k@gmail.com>
#include <libgen.h>
#include <getopt.h> /* for getopt() */
#include <stdarg.h>
#include <libgen.h>
#include <getopt.h> /* for getopt() */
#include <stdarg.h>
+#include <stdbool.h>
+#include <endian.h>
#include <errno.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/stat.h>
static struct file_info inspect_info;
static int extract = 0;
static struct file_info inspect_info;
static int extract = 0;
+static bool endian_swap = false;
static const char md5salt_normal[MD5SUM_LEN] = {
0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,
static const char md5salt_normal[MD5SUM_LEN] = {
0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,
"\n"
"Options:\n"
" -c use combined kernel image\n"
"\n"
"Options:\n"
" -c use combined kernel image\n"
+" -e swap endianness in kernel load address and entry point\n"
" -E <ep> overwrite kernel entry point with <ep> (hexval prefixed with 0x)\n"
" -L <la> overwrite kernel load address with <la> (hexval prefixed with 0x)\n"
" -H <hwid> use hardware id specified with <hwid>\n"
" -E <ep> overwrite kernel entry point with <ep> (hexval prefixed with 0x)\n"
" -L <la> overwrite kernel load address with <la> (hexval prefixed with 0x)\n"
" -H <hwid> use hardware id specified with <hwid>\n"
+ if (endian_swap) {
+ hdr->kernel_la = bswap_32(hdr->kernel_la);
+ hdr->kernel_ep = bswap_32(hdr->kernel_ep);
+ }
+
get_md5(buf, len, hdr->md5sum1);
}
get_md5(buf, len, hdr->md5sum1);
}
- c = getopt(argc, argv, "a:H:E:F:L:m:V:N:W:C:ci:k:r:R:o:xX:hsSjv:");
+ c = getopt(argc, argv, "a:H:E:F:L:m:V:N:W:C:ci:k:r:R:o:xX:ehsSjv:");
case 'x':
extract = 1;
break;
case 'x':
extract = 1;
break;
+ case 'e':
+ endian_swap = true;
+ break;
case 'h':
usage(EXIT_SUCCESS);
break;
case 'h':
usage(EXIT_SUCCESS);
break;