[openwrt/openwrt] firmware-utils: bcm4908img: use "info" command displaying file info

LEDE Commits lede-commits at lists.infradead.org
Thu Apr 8 12:40:52 BST 2021


rmilecki pushed a commit to openwrt/openwrt.git, branch openwrt-21.02:
https://git.openwrt.org/e9a7c22d3ccbcd782233c3f48ba5d20ea363f3f6

commit e9a7c22d3ccbcd782233c3f48ba5d20ea363f3f6
Author: Rafał Miłecki <rafal at milecki.pl>
AuthorDate: Fri Apr 2 14:12:58 2021 +0200

    firmware-utils: bcm4908img: use "info" command displaying file info
    
    BCM4908 image format contains some info that may be useful for info /
    debugging purposes.
    
    Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
    (cherry picked from commit 9b9184f1782489163eb204f3b238de778ae1214b)
---
 tools/firmware-utils/src/bcm4908img.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/tools/firmware-utils/src/bcm4908img.c b/tools/firmware-utils/src/bcm4908img.c
index 16e0afe9de..56a790423b 100644
--- a/tools/firmware-utils/src/bcm4908img.c
+++ b/tools/firmware-utils/src/bcm4908img.c
@@ -262,32 +262,39 @@ static int bcm4908img_parse(FILE *fp, struct bcm4908img_info *info) {
 }
 
 /**************************************************
- * Check
+ * Info
  **************************************************/
 
-static int bcm4908img_check(int argc, char **argv) {
+static int bcm4908img_info(int argc, char **argv) {
 	struct bcm4908img_info info;
 	const char *pathname = NULL;
 	FILE *fp;
+	int c;
 	int err = 0;
 
-	if (argc >= 3)
-		pathname = argv[2];
+	while ((c = getopt(argc, argv, "i:")) != -1) {
+		switch (c) {
+		case 'i':
+			pathname = optarg;
+			break;
+		}
+	}
 
 	fp = bcm4908img_open(pathname, "r");
 	if (!fp) {
-		fprintf(stderr, "Failed to open %s\n", pathname);
+		fprintf(stderr, "Failed to open BCM4908 image\n");
 		err = -EACCES;
 		goto out;
 	}
 
 	err = bcm4908img_parse(fp, &info);
 	if (err) {
-		fprintf(stderr, "Failed to parse %s\n", pathname);
+		fprintf(stderr, "Failed to parse BCM4908 image\n");
 		goto err_close;
 	}
 
-	printf("Found a valid BCM4908 image (crc: 0x%08x)\n", info.crc32);
+	printf("Vendor header length:\t%zu\n", info.vendor_header_size);
+	printf("Checksum:\t0x%08x\n", info.crc32);
 
 err_close:
 	bcm4908img_close(fp);
@@ -438,8 +445,9 @@ out:
 static void usage() {
 	printf("Usage:\n");
 	printf("\n");
-	printf("Checking a BCM4908 image:\n");
-	printf("\tbcm4908img check <file>\t\t\tcheck if images is valid\n");
+	printf("Info about a BCM4908 image:\n");
+	printf("\tbcm4908img info <options>\n");
+	printf("\t-i <file>\t\t\t\tinput BCM490 image\n");
 	printf("\n");
 	printf("Creating a new BCM4908 image:\n");
 	printf("\tbcm4908img create <file> [options]\n");
@@ -450,8 +458,9 @@ static void usage() {
 
 int main(int argc, char **argv) {
 	if (argc > 1) {
-		if (!strcmp(argv[1], "check"))
-			return bcm4908img_check(argc, argv);
+		optind++;
+		if (!strcmp(argv[1], "info"))
+			return bcm4908img_info(argc, argv);
 		else if (!strcmp(argv[1], "create"))
 			return bcm4908img_create(argc, argv);
 	}



More information about the lede-commits mailing list