[source] firmware-utils: mktplinkfw: add option for endianness swap

LEDE Commits lede-commits at lists.infradead.org
Tue Jul 4 07:10:39 PDT 2017


pepe2k pushed a commit to source.git, branch master:
https://git.lede-project.org/a3d232e1e6e5a49e7d1c1d9bc56be9ebd8ae6171

commit a3d232e1e6e5a49e7d1c1d9bc56be9ebd8ae6171
Author: Piotr Dymacz <pepe2k at gmail.com>
AuthorDate: Tue Jul 4 15:40:43 2017 +0200

    firmware-utils: mktplinkfw: add option for endianness swap
    
    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 at gmail.com>
---
 tools/firmware-utils/src/mktplinkfw.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/firmware-utils/src/mktplinkfw.c b/tools/firmware-utils/src/mktplinkfw.c
index fbf8960..93db441 100644
--- a/tools/firmware-utils/src/mktplinkfw.c
+++ b/tools/firmware-utils/src/mktplinkfw.c
@@ -19,6 +19,8 @@
 #include <libgen.h>
 #include <getopt.h>     /* for getopt() */
 #include <stdarg.h>
+#include <stdbool.h>
+#include <endian.h>
 #include <errno.h>
 #include <sys/stat.h>
 
@@ -123,6 +125,7 @@ static uint32_t reserved_space;
 
 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,
@@ -256,6 +259,7 @@ static void usage(int status)
 "\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"
@@ -521,6 +525,11 @@ static void fill_header(char *buf, int len)
 		);
 	}
 
+	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);
 }
 
@@ -805,7 +814,7 @@ int main(int argc, char *argv[])
 	while ( 1 ) {
 		int c;
 
-		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:");
 		if (c == -1)
 			break;
 
@@ -873,6 +882,9 @@ int main(int argc, char *argv[])
 		case 'x':
 			extract = 1;
 			break;
+		case 'e':
+			endian_swap = true;
+			break;
 		case 'h':
 			usage(EXIT_SUCCESS);
 			break;



More information about the lede-commits mailing list