[PATCH u-boot-marvell 17/29] tools: kwboot: Always call kwboot_img_patch_hdr()

Marek Behún marek.behun at nic.cz
Wed Aug 25 15:46:22 CEST 2021


From: Pali Rohár <pali at kernel.org>

The kwboot_img_patch_hdr() function already decides if header patching
is needed. Always call this function and deprecate the unneeded command
line option `-p`.

Signed-off-by: Pali Rohár <pali at kernel.org>
Reviewed-by: Marek Behún <marek.behun at nic.cz>
---
 tools/kwboot.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 6674a253ff..031cea7550 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -692,9 +692,9 @@ out:
 }
 
 static void *
-kwboot_mmap_image(const char *path, size_t *size, int prot)
+kwboot_mmap_image(const char *path, size_t *size)
 {
-	int rc, fd, flags;
+	int rc, fd;
 	struct stat st;
 	void *img;
 
@@ -709,9 +709,7 @@ kwboot_mmap_image(const char *path, size_t *size, int prot)
 	if (rc)
 		goto out;
 
-	flags = (prot & PROT_WRITE) ? MAP_PRIVATE : MAP_SHARED;
-
-	img = mmap(NULL, st.st_size, prot, flags, fd, 0);
+	img = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
 	if (img == MAP_FAILED) {
 		img = NULL;
 		goto out;
@@ -816,7 +814,6 @@ kwboot_usage(FILE *stream, char *progname)
 	fprintf(stream, "\n");
 	fprintf(stream,
 		"  -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP)\n");
-	fprintf(stream, "  -p: patch <image> to type 0x69 (uart boot)\n");
 	fprintf(stream,
 		"  -D <image>: boot <image> without preamble (Dove)\n");
 	fprintf(stream, "  -d: enter debug mode\n");
@@ -836,7 +833,7 @@ int
 main(int argc, char **argv)
 {
 	const char *ttypath, *imgpath;
-	int rv, rc, tty, term, prot, patch;
+	int rv, rc, tty, term;
 	void *bootmsg;
 	void *debugmsg;
 	void *img;
@@ -850,7 +847,6 @@ main(int argc, char **argv)
 	imgpath = NULL;
 	img = NULL;
 	term = 0;
-	patch = 0;
 	size = 0;
 	speed = B115200;
 
@@ -877,7 +873,7 @@ main(int argc, char **argv)
 			break;
 
 		case 'p':
-			patch = 1;
+			/* nop, for backward compatibility */
 			break;
 
 		case 't':
@@ -917,9 +913,6 @@ main(int argc, char **argv)
 	if (!bootmsg && !term && !debugmsg)
 		goto usage;
 
-	if (patch && !imgpath)
-		goto usage;
-
 	if (argc - optind < 1)
 		goto usage;
 
@@ -932,16 +925,12 @@ main(int argc, char **argv)
 	}
 
 	if (imgpath) {
-		prot = PROT_READ | (patch ? PROT_WRITE : 0);
-
-		img = kwboot_mmap_image(imgpath, &size, prot);
+		img = kwboot_mmap_image(imgpath, &size);
 		if (!img) {
 			perror(imgpath);
 			goto out;
 		}
-	}
 
-	if (patch) {
 		rc = kwboot_img_patch_hdr(img, size);
 		if (rc) {
 			fprintf(stderr, "%s: Invalid image.\n", imgpath);
-- 
2.31.1



More information about the U-Boot mailing list