diff mbox

[OpenWrt-Devel] Added optional command line option for patch-image tool

Message ID 1463063849-10145-1-git-send-email-duddu.swaroop@intel.com
State Changes Requested
Delegated to: John Crispin
Headers show

Commit Message

duddu.swaroop@intel.com May 12, 2016, 2:37 p.m. UTC
From: Vishnu Swaroop Duddu <duddu.swaroop@intel.com>

Added optional command line option for patch-image tool
Default 16KB size is still maintained as this is an optional argument.
if one wants to specify or increase size they can provide this option.
sample usage: patch-dtb <file> <dtb> [dtb max size]

Signed-off-by: Vishnu Swaroop Duddu <duddu.swaroop@intel.com>
---
 tools/patch-image/src/patch-cmdline.c | 16 +++++++++++-----
 tools/patch-image/src/patch-dtb.c     | 25 +++++++++++++++----------
 2 files changed, 26 insertions(+), 15 deletions(-)

Comments

Hauke Mehrtens June 23, 2016, 9:43 p.m. UTC | #1
On 05/12/2016 04:37 PM, duddu.swaroop@intel.com wrote:
> From: Vishnu Swaroop Duddu <duddu.swaroop@intel.com>
> 
> Added optional command line option for patch-image tool
> Default 16KB size is still maintained as this is an optional argument.
> if one wants to specify or increase size they can provide this option.
> sample usage: patch-dtb <file> <dtb> [dtb max size]
> 
> Signed-off-by: Vishnu Swaroop Duddu <duddu.swaroop@intel.com>
> ---
>  tools/patch-image/src/patch-cmdline.c | 16 +++++++++++-----
>  tools/patch-image/src/patch-dtb.c     | 25 +++++++++++++++----------
>  2 files changed, 26 insertions(+), 15 deletions(-)
> 
Hi Swaroop,

Thank you for the patch, I applied to to LEDE. I do not know if someone
will pick it up for OpenWrt. It did not apply cleanly, I had to do some
changes to it, next time please check if your patch apply before sending.

Hauke
Zoltan HERPAI June 23, 2016, 9:45 p.m. UTC | #2
On Thu, 23 Jun 2016, Hauke Mehrtens wrote:

> On 05/12/2016 04:37 PM, duddu.swaroop@intel.com wrote:
>> From: Vishnu Swaroop Duddu <duddu.swaroop@intel.com>
>> 
>> Added optional command line option for patch-image tool
>> Default 16KB size is still maintained as this is an optional argument.
>> if one wants to specify or increase size they can provide this option.
>> sample usage: patch-dtb <file> <dtb> [dtb max size]
>> 
>> Signed-off-by: Vishnu Swaroop Duddu <duddu.swaroop@intel.com>
>> ---
>>  tools/patch-image/src/patch-cmdline.c | 16 +++++++++++-----
>>  tools/patch-image/src/patch-dtb.c     | 25 +++++++++++++++----------
>>  2 files changed, 26 insertions(+), 15 deletions(-)
>> 
> Hi Swaroop,
>
> Thank you for the patch, I applied to to LEDE. I do not know if someone
> will pick it up for OpenWrt. It did not apply cleanly, I had to do some
> changes to it, next time please check if your patch apply before sending.

Hi Swaroop,

Thanks, OpenWrt will check and pick this up too.

Regards,
Zoltan H
diff mbox

Patch

diff --git a/tools/patch-image/src/patch-cmdline.c b/tools/patch-image/src/patch-cmdline.c
index 571f848..01499ab 100644
--- a/tools/patch-image/src/patch-cmdline.c
+++ b/tools/patch-image/src/patch-cmdline.c
@@ -35,10 +35,16 @@  int main(int argc, char **argv)
 {
 	int fd, found = 0, len, ret = -1;
 	char *ptr, *p;
+	unsigned int search_space;
 
-	if (argc != 3) {
- 	fprintf(stderr, "Usage: %s <file> <cmdline>\n", argv[0]);
-		goto err1;
+	if (argc <= 2 || argc > 4) {
+		fprintf(stderr, "Usage: %s (file) (cmdline) <size>\n", argv[0]);
+		goto err1;
+	} else if (argc == 3) {
+		fprintf(stdout, "search space used is default of 16KB\n");
+		search_space =  SEARCH_SPACE;
+	} else {
+		search_space = atoi(argv[3]);
 	}
 	len = strlen(argv[2]);
 	if (len + 9 > CMDLINE_MAX) {
@@ -47,12 +53,12 @@  int main(int argc, char **argv)
 	}
 	
 	if (((fd = open(argv[1], O_RDWR)) < 0) ||
-		(ptr = (char *) mmap(0, SEARCH_SPACE + CMDLINE_MAX, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1)) {
+		(ptr = (char *) mmap(0, search_space + CMDLINE_MAX, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1)) {
 		fprintf(stderr, "Could not open kernel image");
 		goto err2;
 	}
 	
-	for (p = ptr; p < (ptr + SEARCH_SPACE); p += 4) {
+	for (p = ptr; p < (ptr + search_space); p += 4) {
 		if (memcmp(p, "CMDLINE:", 8) == 0) {
 			found = 1;
 			p += 8;
diff --git a/tools/patch-image/src/patch-dtb.c b/tools/patch-image/src/patch-dtb.c
index 161e1dc..74570ce 100644
--- a/tools/patch-image/src/patch-dtb.c
+++ b/tools/patch-image/src/patch-dtb.c
@@ -30,19 +30,24 @@ 
 #include <sys/stat.h>
 #include <string.h>
 
-#define SEARCH_SPACE	(16 * 1024)
-#define DTB_MAX	(16 * 1024)
-
+#define DTB_MAX (16*1024)
 int main(int argc, char **argv)
 {
 	int fd, fddtb, found = 0, len, ret = -1;
 	char *ptr, *ptrdtb, *p;
 	struct stat s;
+	unsigned int search_space , dtb_max_size;
 
-	if (argc != 3) {
-		fprintf(stderr, "Usage: %s <file> <dtb>\n", argv[0]);
+	if (argc <= 2 || argc > 4) {
+		fprintf(stderr, "Usage: %s (file) (dtb) <size>\n", argv[0]);
 		goto err1;
+	} else if (argc == 3) {
+		fprintf(stdout, "DT size used is default of 16KB\n");
+		search_space = dtb_max_size = DTB_MAX;
+	} else {
+		search_space = dtb_max_size = atoi(argv[3]);
 	}
+
 	fddtb = open(argv[1], O_RDONLY);
 	if (!fddtb)
 		goto err1;
@@ -53,24 +58,24 @@  int main(int argc, char **argv)
 	}
 
 	len = s.st_size;
-	if (len + 8 > DTB_MAX) {
+	if (len + 8 > dtb_max_size) {
 		fprintf(stderr, "DTB too big\n");
 		goto err1;
 	}
 
         if (((fddtb = open(argv[2], O_RDONLY)) < 0) ||
-		(ptrdtb = (char *) mmap(0, DTB_MAX, PROT_READ, MAP_SHARED, fddtb, 0)) == (void *) (-1)) {
+		(ptrdtb = (char *) mmap(0, dtb_max_size, PROT_READ, MAP_SHARED, fddtb, 0)) == (void *) (-1)) {
 		fprintf(stderr, "Could not open DTB");
 		goto err2;
 	}
 
 	if (((fd = open(argv[1], O_RDWR)) < 0) ||
-		(ptr = (char *) mmap(0, SEARCH_SPACE + DTB_MAX, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1)) {
+		(ptr = (char *) mmap(0, search_space + dtb_max_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1)) {
 		fprintf(stderr, "Could not open kernel image");
 		goto err3;
 	}
 
-	for (p = ptr; p < (ptr + SEARCH_SPACE); p += 4) {
+	for (p = ptr; p < (ptr + search_space); p += 4) {
 		if (memcmp(p, "OWRTDTB:", 8) == 0) {
 			found = 1;
 			p += 8;
@@ -82,7 +87,7 @@  int main(int argc, char **argv)
 		goto err4;
 	}
 
-	memset(p, 0, DTB_MAX - 8);
+	memset(p, 0, dtb_max_size - 8);
 	memcpy(p, ptrdtb, len);
 	msync(p, len, MS_SYNC|MS_INVALIDATE);
 	ret = 0;