Skip to contentSkip to conversation

Fixes and improvements in BCB and Android docs [ver #3]

PATCH New Eugeniu Rosca 3 participants 10 messages Jul 19, 2019 – Jul 24, 2019

lore
Share & tools
lore
#0 lore raw

v3 cover Fixes and improvements in BCB and Android docs [ver #3]

Resubmit the diff between [1] and [2] of the BCB/Android series the former has been pushed to master instead of the latter.

[1] https://patchwork.ozlabs.org/cover/1104242/
("[v3,0/3] Add 'bcb' command to read/modify/write Android BCB")
[2] https://patchwork.ozlabs.org/cover/1128661/
("[v4,0/4] Add 'bcb' command to read/modify/write Android BCB")

v3:
- Rebased after the recent merge of
https://patchwork.ozlabs.org/patch/1126450/ as commit
https://gitlab.denx.de/u-boot/u-boot/commit/d963f64c0bd7
("doc: Move fastboot protocol doc to android dir"), since it created conflicts merging v2
- No other changes

v2:
- Ensured git bisectability for the series
- [Igor Opaniuk] Enriched patch description
- No series-wide changes in the contents
- https://patchwork.ozlabs.org/cover/1131356/

v1:
- https://patchwork.ozlabs.org/cover/1131295/

Eugeniu Rosca (4):
treewide: Fix stale references of Android docs
cmd: bcb: Fix duplicated handling in two case-branches
cmd: bcb: Use strcmp() instead of strncmp() for string literals
cmd: bcb: Apply non-functional refinements

 cmd/Kconfig               |  2 +-
 cmd/bcb.c                 | 68 +++++++++++++++++++--------------------
 test/py/tests/test_avb.py |  2 +-
 3 files changed, 35 insertions(+), 37 deletions(-)
Signature · 1 line
2.22.0
#1 lore raw

PATCH v3 1/4 treewide: Fix stale references of Android docs

Commit 9bdf0e8fef86 ("doc: relocate/rename Android README and add BCB overview") left some obsolete references of Android documents/paths.

This has been pointed out by Sam (thanks!) in:
https://patchwork.ozlabs.org/patch/1104245/#2208134

Fixes 9bdf0e8fef86 ("doc: relocate/rename Android README and add BCB overview")

---
v3:
- Dropped changes in doc/android/fastboot.txt, since the same have been performed by commit
https://gitlab.denx.de/u-boot/u-boot/commit/d963f64c0bd7
("doc: Move fastboot protocol doc to android dir")

v2:
- Added 'Reviewed-by: Igor Opaniuk' from v1
- https://patchwork.ozlabs.org/patch/1131354/

v1:
- https://patchwork.ozlabs.org/patch/1131305/

---
 cmd/Kconfig               | 2 +-
 test/py/tests/test_avb.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
cmd/Kconfig +1 -1
index 175c6ad9e333..e1e050f4ad54 100644
@@ -735,7 +735,7 @@ config CMD_FASTBOOT
 	  Android devices. Fastboot requires either the network stack
 	  enabled or support for acting as a USB device.
 
-	  See doc/README.android-fastboot for more information.
+	  See doc/android/fastboot.txt for more information.
 
 config CMD_FDC
 	bool "fdcboot - Boot from floppy device"
test/py/tests/test_avb.py +1 -1
index 2bb75ed6e2a2..813242343555 100644
@@ -8,7 +8,7 @@
 This tests Android Verified Boot 2.0 support in U-boot:
 
 For additional details about how to build proper vbmeta partition
-check doc/README.avb2
+check doc/android/avb2.txt
 
 For configuration verification:
 - Corrupt boot partition and check for failure
Signature · 1 line
2.22.0
#2 lore raw

PATCH v3 1/4 treewide: Fix stale references of Android docs

Quoted 6 lines · Eugeniu Rosca

Commit 9bdf0e8fef86 ("doc: relocate/rename Android README and add BCB overview") left some obsolete references of Android documents/paths.

This has been pointed out by Sam (thanks!) in:
https://patchwork.ozlabs.org/patch/1104245/#2208134

Quoted 6 lines
Fixes 9bdf0e8fef86 ("doc: relocate/rename Android README and add BCB overview")

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190724/e6db12d2/attachment.sig>
#3 lore raw

PATCH v3 2/4 cmd: bcb: Fix duplicated handling in two case-branches

In reply to Eugeniu Rosca

Fix warning V1037 reported by PVS-Studio Static Analyzer:
Two or more case-branches perform the same actions. Check lines: 49, 53

Fixes db7b7a05b267 ("cmd: Add 'bcb' command to read/modify/write BCB fields")

---
v3:
- No changes
- Added 'Reviewed-by: Sam Protsenko' from v2

v2:
- Added 'Reviewed-by: Igor Opaniuk' from v1
- https://patchwork.ozlabs.org/patch/1131357/

v1:
- https://patchwork.ozlabs.org/patch/1131301/

---
 cmd/bcb.c | 3 ---
 1 file changed, 3 deletions(-)
cmd/bcb.c +0 -3
index 2bd5a744deb5..3b1c7434e287 100644
@@ -46,9 +46,6 @@ static int bcb_is_misused(int argc, char *const argv[])
 
 	switch (cmd) {
 	case BCB_CMD_LOAD:
-		if (argc != 3)
-			goto err;
-		break;
 	case BCB_CMD_FIELD_SET:
 		if (argc != 3)
 			goto err;
Signature · 1 line
2.22.0
#4 lore raw

PATCH v3 2/4 cmd: bcb: Fix duplicated handling in two case-branches

Quoted 7 lines · Eugeniu Rosca

Fix warning V1037 reported by PVS-Studio Static Analyzer:
Two or more case-branches perform the same actions. Check lines: 49, 53

Fixes db7b7a05b267 ("cmd: Add 'bcb' command to read/modify/write BCB fields")

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190724/04721de6/attachment.sig>
#5 lore raw

PATCH v3 3/4 cmd: bcb: Use strcmp() instead of strncmp() for string literals

In reply to Eugeniu Rosca

Quote from https://patchwork.ozlabs.org/patch/1104244/#2210814:

----------8<-----------
strncmp() is chosen for the sake of paranoid/defensive programming. Indeed, strncmp() is not really needed when comparing a variable with a string literal. We expect strcmp() to behave safely even if the string variable is not NUL-terminated.

In the same scenario, Linux v5.2-rc7 uses both strcmp() and strncmp(), but the frequency of strcmp() is higher:

$ git --version
git version 2.22.0
$ (Linux 5.2-rc7) git grep -En 'strncmp\([^"]*"[[:alnum:]]+"' | wc -l
1066
$ (Linux 5.2-rc7) git grep -En 'strcmp\([^"]*"[[:alnum:]]+"' | wc -l
1968

A quick "strcmp vs strncmp" object size test shows that strcmp() generates smaller memory footprint (gcc-8, x86_64):

$ (U-Boot) size cmd/bcb-strncmp.o cmd/bcb-strcmp.o
   text	   data	    bss	    dec	    hex	filename
   3373	    400	   2048	   5821	   16bd	cmd/bcb-strncmp.o
   3314	    400	   2048	   5762	   1682	cmd/bcb-strcmp.o

So, overall, I agree to use strcmp() whenever variables are compared with string literals.
----------8<-----------

Fixes db7b7a05b267 ("cmd: Add 'bcb' command to read/modify/write BCB fields")

---
v3:
- No changes
- Added 'Reviewed-by: Sam Protsenko' from v2

v2:
- Fixed accidental rename of field/size variables in bcb_field_get()
- https://patchwork.ozlabs.org/patch/1131358/

v1:
- https://patchwork.ozlabs.org/patch/1131306/

---
 cmd/bcb.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
cmd/bcb.c +11 -11
index 3b1c7434e287..fa9fdeeb0dfc 100644
@@ -24,17 +24,17 @@ static struct bootloader_message bcb = { { 0 } };
 
 static int bcb_cmd_get(char *cmd)
 {
-	if (!strncmp(cmd, "load", sizeof("load")))
+	if (!strcmp(cmd, "load"))
 		return BCB_CMD_LOAD;
-	if (!strncmp(cmd, "set", sizeof("set")))
+	if (!strcmp(cmd, "set"))
 		return BCB_CMD_FIELD_SET;
-	if (!strncmp(cmd, "clear", sizeof("clear")))
+	if (!strcmp(cmd, "clear"))
 		return BCB_CMD_FIELD_CLEAR;
-	if (!strncmp(cmd, "test", sizeof("test")))
+	if (!strcmp(cmd, "test"))
 		return BCB_CMD_FIELD_TEST;
-	if (!strncmp(cmd, "store", sizeof("store")))
+	if (!strcmp(cmd, "store"))
 		return BCB_CMD_STORE;
-	if (!strncmp(cmd, "dump", sizeof("dump")))
+	if (!strcmp(cmd, "dump"))
 		return BCB_CMD_FIELD_DUMP;
 	else
 		return -1;
@@ -85,19 +85,19 @@ err:
 
 static int bcb_field_get(char *name, char **field, int *size)
 {
-	if (!strncmp(name, "command", sizeof("command"))) {
+	if (!strcmp(name, "command")) {
 		*field = bcb.command;
 		*size = sizeof(bcb.command);
-	} else if (!strncmp(name, "status", sizeof("status"))) {
+	} else if (!strcmp(name, "status")) {
 		*field = bcb.status;
 		*size = sizeof(bcb.status);
-	} else if (!strncmp(name, "recovery", sizeof("recovery"))) {
+	} else if (!strcmp(name, "recovery")) {
 		*field = bcb.recovery;
 		*size = sizeof(bcb.recovery);
-	} else if (!strncmp(name, "stage", sizeof("stage"))) {
+	} else if (!strcmp(name, "stage")) {
 		*field = bcb.stage;
 		*size = sizeof(bcb.stage);
-	} else if (!strncmp(name, "reserved", sizeof("reserved"))) {
+	} else if (!strcmp(name, "reserved")) {
 		*field = bcb.reserved;
 		*size = sizeof(bcb.reserved);
 	} else {
Signature · 1 line
2.22.0
#6 lore raw

PATCH v3 3/4 cmd: bcb: Use strcmp() instead of strncmp() for string literals

Quoted 104 lines · Eugeniu Rosca

Quote from https://patchwork.ozlabs.org/patch/1104244/#2210814:

----------8<-----------
strncmp() is chosen for the sake of paranoid/defensive programming. Indeed, strncmp() is not really needed when comparing a variable with a string literal. We expect strcmp() to behave safely even if the string variable is not NUL-terminated.

In the same scenario, Linux v5.2-rc7 uses both strcmp() and strncmp(), but the frequency of strcmp() is higher:

$ git --version
git version 2.22.0
$ (Linux 5.2-rc7) git grep -En 'strncmp\([^"]*"[[:alnum:]]+"' | wc -l
1066
$ (Linux 5.2-rc7) git grep -En 'strcmp\([^"]*"[[:alnum:]]+"' | wc -l
1968

A quick "strcmp vs strncmp" object size test shows that strcmp() generates smaller memory footprint (gcc-8, x86_64):

$ (U-Boot) size cmd/bcb-strncmp.o cmd/bcb-strcmp.o
   text    data     bss     dec     hex filename
   3373     400    2048    5821    16bd cmd/bcb-strncmp.o
   3314     400    2048    5762    1682 cmd/bcb-strcmp.o

So, overall, I agree to use strcmp() whenever variables are compared with string literals.
----------8<-----------

Fixes db7b7a05b267 ("cmd: Add 'bcb' command to read/modify/write BCB fields")

---
v3:
- No changes
- Added 'Reviewed-by: Sam Protsenko' from v2

v2:
- Fixed accidental rename of field/size variables in bcb_field_get()
- https://patchwork.ozlabs.org/patch/1131358/

v1:
- https://patchwork.ozlabs.org/patch/1131306/

---
 cmd/bcb.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
cmd/bcb.c +11 -12
index 3b1c7434e287..fa9fdeeb0dfc 100644
@@ -24,17 +24,17 @@ static struct bootloader_message bcb = { { 0 } };
 
 static int bcb_cmd_get(char *cmd)
 {
-       if (!strncmp(cmd, "load", sizeof("load")))
+       if (!strcmp(cmd, "load"))
                return BCB_CMD_LOAD;
-       if (!strncmp(cmd, "set", sizeof("set")))
+       if (!strcmp(cmd, "set"))
                return BCB_CMD_FIELD_SET;
-       if (!strncmp(cmd, "clear", sizeof("clear")))
+       if (!strcmp(cmd, "clear"))
                return BCB_CMD_FIELD_CLEAR;
-       if (!strncmp(cmd, "test", sizeof("test")))
+       if (!strcmp(cmd, "test"))
                return BCB_CMD_FIELD_TEST;
-       if (!strncmp(cmd, "store", sizeof("store")))
+       if (!strcmp(cmd, "store"))
                return BCB_CMD_STORE;
-       if (!strncmp(cmd, "dump", sizeof("dump")))
+       if (!strcmp(cmd, "dump"))
                return BCB_CMD_FIELD_DUMP;
        else
                return -1;
@@ -85,19 +85,19 @@ err:
 
 static int bcb_field_get(char *name, char **field, int *size)
 {
-       if (!strncmp(name, "command", sizeof("command"))) {
+       if (!strcmp(name, "command")) {
                *field = bcb.command;
                *size = sizeof(bcb.command);
-       } else if (!strncmp(name, "status", sizeof("status"))) {
+       } else if (!strcmp(name, "status")) {
                *field = bcb.status;
                *size = sizeof(bcb.status);
-       } else if (!strncmp(name, "recovery", sizeof("recovery"))) {
+       } else if (!strcmp(name, "recovery")) {
                *field = bcb.recovery;
                *size = sizeof(bcb.recovery);
-       } else if (!strncmp(name, "stage", sizeof("stage"))) {
+       } else if (!strcmp(name, "stage")) {
                *field = bcb.stage;
                *size = sizeof(bcb.stage);
-       } else if (!strncmp(name, "reserved", sizeof("reserved"))) {
+       } else if (!strcmp(name, "reserved")) {
                *field = bcb.reserved;
                *size = sizeof(bcb.reserved);
        } else {
--
Quoted 2 lines

2.22.0

Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
#7 lore raw

PATCH v3 3/4 cmd: bcb: Use strcmp() instead of strncmp() for string literals

In reply to Eugeniu Rosca
Quoted 30 lines · Eugeniu Rosca

Quote from https://patchwork.ozlabs.org/patch/1104244/#2210814:

----------8<-----------
strncmp() is chosen for the sake of paranoid/defensive programming. Indeed, strncmp() is not really needed when comparing a variable with a string literal. We expect strcmp() to behave safely even if the string variable is not NUL-terminated.

In the same scenario, Linux v5.2-rc7 uses both strcmp() and strncmp(), but the frequency of strcmp() is higher:

$ git --version
git version 2.22.0
$ (Linux 5.2-rc7) git grep -En 'strncmp\([^"]*"[[:alnum:]]+"' | wc -l
1066
$ (Linux 5.2-rc7) git grep -En 'strcmp\([^"]*"[[:alnum:]]+"' | wc -l
1968

A quick "strcmp vs strncmp" object size test shows that strcmp() generates smaller memory footprint (gcc-8, x86_64):

$ (U-Boot) size cmd/bcb-strncmp.o cmd/bcb-strcmp.o
   text	   data	    bss	    dec	    hex	filename
   3373	    400	   2048	   5821	   16bd	cmd/bcb-strncmp.o
   3314	    400	   2048	   5762	   1682	cmd/bcb-strcmp.o

So, overall, I agree to use strcmp() whenever variables are compared with string literals.
----------8<-----------

Quoted 5 lines
Fixes db7b7a05b267 ("cmd: Add 'bcb' command to read/modify/write BCB fields")

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190724/5d90bea4/attachment.sig>
#8 lore raw

PATCH v3 4/4 cmd: bcb: Apply non-functional refinements

In reply to Eugeniu Rosca

These have been reported by Simon in [1] and fixed in [2]. However, since [1] has already been pushed to u-boot/master, the improvements incorporated in [2] are now extracted and resubmitted.

The changes are in the area of coding style and best practices:
* s/field/fieldp/, s/size/sizep/, to convey that the variables return an output to the caller
* s/err_1/err_read_fail/, s/err_2/err_too_small/, to be more descriptive
* Made sure 'static int do_bcb_load' appears on the same line
* Placed a /* on top of multi-line comment

[1] https://patchwork.ozlabs.org/patch/1104244/#2200259
[2] https://patchwork.ozlabs.org/cover/1128661/
("[v4,0/4] Add 'bcb' command to read/modify/write Android BCB")

Fixes db7b7a05b267 ("cmd: Add 'bcb' command to read/modify/write BCB fields")

---
v3:
- No changes
- Added 'Reviewed-by: Sam Protsenko' from v2

v2:
- [Igor Opaniuk] Enriched the patch description
- Fixed inconsistent {field,size} variable rename
- https://patchwork.ozlabs.org/patch/1131359/

v1:
- https://patchwork.ozlabs.org/patch/1131321/

---
 cmd/bcb.c | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)
cmd/bcb.c +22 -21
index fa9fdeeb0dfc..9626f2c69e34 100644
@@ -83,23 +83,23 @@ err:
 	return -1;
 }
 
-static int bcb_field_get(char *name, char **field, int *size)
+static int bcb_field_get(char *name, char **fieldp, int *sizep)
 {
 	if (!strcmp(name, "command")) {
-		*field = bcb.command;
-		*size = sizeof(bcb.command);
+		*fieldp = bcb.command;
+		*sizep = sizeof(bcb.command);
 	} else if (!strcmp(name, "status")) {
-		*field = bcb.status;
-		*size = sizeof(bcb.status);
+		*fieldp = bcb.status;
+		*sizep = sizeof(bcb.status);
 	} else if (!strcmp(name, "recovery")) {
-		*field = bcb.recovery;
-		*size = sizeof(bcb.recovery);
+		*fieldp = bcb.recovery;
+		*sizep = sizeof(bcb.recovery);
 	} else if (!strcmp(name, "stage")) {
-		*field = bcb.stage;
-		*size = sizeof(bcb.stage);
+		*fieldp = bcb.stage;
+		*sizep = sizeof(bcb.stage);
 	} else if (!strcmp(name, "reserved")) {
-		*field = bcb.reserved;
-		*size = sizeof(bcb.reserved);
+		*fieldp = bcb.reserved;
+		*sizep = sizeof(bcb.reserved);
 	} else {
 		printf("Error: Unknown bcb field '%s'\n", name);
 		return -1;
@@ -108,8 +108,8 @@ static int bcb_field_get(char *name, char **field, int *size)
 	return 0;
 }
 
-static int
-do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc,
+		       char * const argv[])
 {
 	struct blk_desc *desc;
 	disk_partition_t info;
@@ -119,28 +119,28 @@ do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	ret = blk_get_device_by_str("mmc", argv[1], &desc);
 	if (ret < 0)
-		goto err_1;
+		goto err_read_fail;
 
 	part = simple_strtoul(argv[2], &endp, 0);
 	if (*endp == '\0') {
 		ret = part_get_info(desc, part, &info);
 		if (ret)
-			goto err_1;
+			goto err_read_fail;
 	} else {
 		part = part_get_info_by_name(desc, argv[2], &info);
 		if (part < 0) {
 			ret = part;
-			goto err_1;
+			goto err_read_fail;
 		}
 	}
 
 	cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
 	if (cnt > info.size)
-		goto err_2;
+		goto err_too_small;
 
 	if (blk_dread(desc, info.start, cnt, &bcb) != cnt) {
 		ret = -EIO;
-		goto err_1;
+		goto err_read_fail;
 	}
 
 	bcb_dev = desc->devnum;
@@ -148,10 +148,10 @@ do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	debug("%s: Loaded from mmc %d:%d\n", __func__, bcb_dev, bcb_part);
 
 	return CMD_RET_SUCCESS;
-err_1:
+err_read_fail:
 	printf("Error: mmc %s:%s read failed (%d)\n", argv[1], argv[2], ret);
 	goto err;
-err_2:
+err_too_small:
 	printf("Error: mmc %s:%s too small!", argv[1], argv[2]);
 	goto err;
 err:
@@ -304,7 +304,8 @@ static int do_bcb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 		return CMD_RET_USAGE;
 
 	if (bcb_is_misused(argc, argv)) {
-		/* We try to improve the user experience by reporting the
+		/*
+		 * We try to improve the user experience by reporting the
 		 * root-cause of misusage, so don't return CMD_RET_USAGE,
 		 * since the latter prints out the full-blown help text
 		 */
Signature · 1 line
2.22.0
#9 lore raw

PATCH v3 4/4 cmd: bcb: Apply non-functional refinements

Quoted 11 lines · Eugeniu Rosca

These have been reported by Simon in [1] and fixed in [2]. However, since [1] has already been pushed to u-boot/master, the improvements incorporated in [2] are now extracted and resubmitted.

The changes are in the area of coding style and best practices:
* s/field/fieldp/, s/size/sizep/, to convey that the variables return an output to the caller
* s/err_1/err_read_fail/, s/err_2/err_too_small/, to be more descriptive
* Made sure 'static int do_bcb_load' appears on the same line
* Placed a /* on top of multi-line comment

Quoted 8 lines

[1] https://patchwork.ozlabs.org/patch/1104244/#2200259
[2] https://patchwork.ozlabs.org/cover/1128661/
("[v4,0/4] Add 'bcb' command to read/modify/write Android BCB")

Fixes db7b7a05b267 ("cmd: Add 'bcb' command to read/modify/write BCB fields")

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190724/022b10fc/attachment.sig>