All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t 1/3] tools/intel_bios_reader: abstract header information dumping
@ 2016-05-12 12:37 Jani Nikula
  2016-05-12 12:37 ` [PATCH i-g-t 2/3] tools/intel_bios_reader: clean up VBT/BDB header dumping Jani Nikula
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jani Nikula @ 2016-05-12 12:37 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 tools/intel_bios_reader.c | 52 +++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/tools/intel_bios_reader.c b/tools/intel_bios_reader.c
index 5bad3f49690d..25460cacd84c 100644
--- a/tools/intel_bios_reader.c
+++ b/tools/intel_bios_reader.c
@@ -62,6 +62,7 @@ struct bdb_block {
 };
 
 struct context {
+	const struct vbt_header *vbt;
 	const struct bdb_header *bdb;
 	int size;
 
@@ -1405,6 +1406,32 @@ static bool dump_section(struct context *context, int section_id)
 	return true;
 }
 
+static void dump_headers(struct context *context)
+{
+	char signature[17];
+	int i;
+
+	printf("VBT vers: %d.%d\n",
+	       context->vbt->version / 100, context->vbt->version % 100);
+
+	strncpy(signature, (char *)context->bdb->signature, 16);
+	signature[16] = 0;
+	printf("BDB sig: %s\n", signature);
+	printf("BDB vers: %d\n", context->bdb->version);
+
+	printf("Available sections: ");
+	for (i = 0; i < 256; i++) {
+		struct bdb_block *block;
+
+		block = find_section(context, i);
+		if (!block)
+			continue;
+		printf("%d ", i);
+		free(block);
+	}
+	printf("\n");
+}
+
 enum opt {
 	OPT_UNKNOWN = '?',
 	OPT_END = -1,
@@ -1441,11 +1468,9 @@ int main(int argc, char **argv)
 	const char *toolname = argv[0];
 	struct stat finfo;
 	int size;
-	struct bdb_header *bdb;
 	struct context context = {
 		.panel_type = -1,
 	};
-	char signature[17];
 	char *endp;
 	int block_number = -1;
 
@@ -1570,34 +1595,17 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	printf("VBT vers: %d.%d\n", vbt->version / 100, vbt->version % 100);
-
 	bdb_off = vbt_off + vbt->bdb_offset;
 	if (bdb_off >= size - sizeof(struct bdb_header)) {
 		printf("Invalid VBT found, BDB points beyond end of data block\n");
 		return 1;
 	}
 
-	bdb = (struct bdb_header *)(VBIOS + bdb_off);
-	strncpy(signature, (char *)bdb->signature, 16);
-	signature[16] = 0;
-	printf("BDB sig: %s\n", signature);
-	printf("BDB vers: %d\n", bdb->version);
-
-	context.bdb = bdb;
+	context.vbt = vbt;
+	context.bdb = (const struct bdb_header *)(VBIOS + bdb_off);
 	context.size = size;
 
-	printf("Available sections: ");
-	for (i = 0; i < 256; i++) {
-		struct bdb_block *block;
-
-		block = find_section(&context, i);
-		if (!block)
-			continue;
-		printf("%d ", i);
-		free(block);
-	}
-	printf("\n");
+	dump_headers(&context);
 
 	if (!context.devid) {
 		const char *devid_string = getenv("DEVICE");
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH i-g-t 2/3] tools/intel_bios_reader: clean up VBT/BDB header dumping
  2016-05-12 12:37 [PATCH i-g-t 1/3] tools/intel_bios_reader: abstract header information dumping Jani Nikula
@ 2016-05-12 12:37 ` Jani Nikula
  2016-05-12 12:38 ` [PATCH i-g-t 3/3] tools/intel_bios_reader: print errors to stderr, return EXIT_FAILURE Jani Nikula
  2016-05-13 13:52 ` [PATCH i-g-t 1/3] tools/intel_bios_reader: abstract header information dumping Jani Nikula
  2 siblings, 0 replies; 4+ messages in thread
From: Jani Nikula @ 2016-05-12 12:37 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Make the output nicer. Do not print the header if a specific block is
requested.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 tools/intel_bios_reader.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/tools/intel_bios_reader.c b/tools/intel_bios_reader.c
index 25460cacd84c..59a90e234582 100644
--- a/tools/intel_bios_reader.c
+++ b/tools/intel_bios_reader.c
@@ -1408,28 +1408,34 @@ static bool dump_section(struct context *context, int section_id)
 
 static void dump_headers(struct context *context)
 {
-	char signature[17];
-	int i;
+	const struct vbt_header *vbt = context->vbt;
+	const struct bdb_header *bdb = context->bdb;
+	int i, j = 0;
 
-	printf("VBT vers: %d.%d\n",
-	       context->vbt->version / 100, context->vbt->version % 100);
+	printf("VBT signature:\t\"%.*s\"\n",
+	       (int)sizeof(vbt->signature), vbt->signature);
+	printf("VBT version:\t%d.%d\n", vbt->version / 100, vbt->version % 100);
 
-	strncpy(signature, (char *)context->bdb->signature, 16);
-	signature[16] = 0;
-	printf("BDB sig: %s\n", signature);
-	printf("BDB vers: %d\n", context->bdb->version);
+	printf("BDB signature:\t\"%.*s\"\n",
+	       (int)sizeof(bdb->signature), bdb->signature);
+	printf("BDB version:\t%d\n", bdb->version);
 
-	printf("Available sections: ");
+	printf("BDB blocks present:");
 	for (i = 0; i < 256; i++) {
 		struct bdb_block *block;
 
 		block = find_section(context, i);
 		if (!block)
 			continue;
-		printf("%d ", i);
+
+		if (j++ % 16)
+			printf(" %3d", i);
+		else
+			printf("\n\t%3d", i);
+
 		free(block);
 	}
-	printf("\n");
+	printf("\n\n");
 }
 
 enum opt {
@@ -1605,8 +1611,6 @@ int main(int argc, char **argv)
 	context.bdb = (const struct bdb_header *)(VBIOS + bdb_off);
 	context.size = size;
 
-	dump_headers(&context);
-
 	if (!context.devid) {
 		const char *devid_string = getenv("DEVICE");
 		if (devid_string)
@@ -1631,6 +1635,8 @@ int main(int argc, char **argv)
 			return EXIT_FAILURE;
 		}
 	} else {
+		dump_headers(&context);
+
 		/* dump all sections  */
 		for (i = 0; i < 256; i++)
 			dump_section(&context, i);
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH i-g-t 3/3] tools/intel_bios_reader: print errors to stderr, return EXIT_FAILURE
  2016-05-12 12:37 [PATCH i-g-t 1/3] tools/intel_bios_reader: abstract header information dumping Jani Nikula
  2016-05-12 12:37 ` [PATCH i-g-t 2/3] tools/intel_bios_reader: clean up VBT/BDB header dumping Jani Nikula
@ 2016-05-12 12:38 ` Jani Nikula
  2016-05-13 13:52 ` [PATCH i-g-t 1/3] tools/intel_bios_reader: abstract header information dumping Jani Nikula
  2 siblings, 0 replies; 4+ messages in thread
From: Jani Nikula @ 2016-05-12 12:38 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Be consistent with exit status and printing errors to stderr.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 tools/intel_bios_reader.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/tools/intel_bios_reader.c b/tools/intel_bios_reader.c
index 59a90e234582..4c4ab666fc55 100644
--- a/tools/intel_bios_reader.c
+++ b/tools/intel_bios_reader.c
@@ -101,7 +101,7 @@ static struct bdb_block *find_section(struct context *context, int section_id)
 	block = malloc(sizeof(*block));
 	if (!block) {
 		fprintf(stderr, "out of memory\n");
-		exit(-1);
+		exit(EXIT_FAILURE);
 	}
 
 	/* walk the sections looking for section_id */
@@ -1551,14 +1551,15 @@ int main(int argc, char **argv)
 
 	fd = open(filename, O_RDONLY);
 	if (fd == -1) {
-		printf("Couldn't open \"%s\": %s\n", filename, strerror(errno));
-		return 1;
+		fprintf(stderr, "Couldn't open \"%s\": %s\n",
+			filename, strerror(errno));
+		return EXIT_FAILURE;
 	}
 
 	if (stat(filename, &finfo)) {
-		printf("failed to stat \"%s\": %s\n", filename,
-		       strerror(errno));
-		return 1;
+		fprintf(stderr, "Failed to stat \"%s\": %s\n",
+			filename, strerror(errno));
+		return EXIT_FAILURE;
 	}
 	size = finfo.st_size;
 
@@ -1568,9 +1569,9 @@ int main(int argc, char **argv)
 		VBIOS = malloc (size);
 		while ((ret = read(fd, VBIOS + len, size - len))) {
 			if (ret < 0) {
-				printf("failed to read \"%s\": %s\n", filename,
-				       strerror(errno));
-				return 1;
+				fprintf(stderr, "Failed to read \"%s\": %s\n",
+					filename, strerror(errno));
+				return EXIT_FAILURE;
 			}
 
 			len += ret;
@@ -1582,8 +1583,9 @@ int main(int argc, char **argv)
 	} else {
 		VBIOS = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
 		if (VBIOS == MAP_FAILED) {
-			printf("failed to map \"%s\": %s\n", filename, strerror(errno));
-			return 1;
+			fprintf(stderr, "Failed to map \"%s\": %s\n",
+				filename, strerror(errno));
+			return EXIT_FAILURE;
 		}
 	}
 
@@ -1597,14 +1599,14 @@ int main(int argc, char **argv)
 	}
 
 	if (!vbt) {
-		printf("VBT signature missing\n");
-		return 1;
+		fprintf(stderr, "VBT signature missing\n");
+		return EXIT_FAILURE;
 	}
 
 	bdb_off = vbt_off + vbt->bdb_offset;
 	if (bdb_off >= size - sizeof(struct bdb_header)) {
-		printf("Invalid VBT found, BDB points beyond end of data block\n");
-		return 1;
+		fprintf(stderr, "Invalid VBT found, BDB points beyond end of data block\n");
+		return EXIT_FAILURE;
 	}
 
 	context.vbt = vbt;
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH i-g-t 1/3] tools/intel_bios_reader: abstract header information dumping
  2016-05-12 12:37 [PATCH i-g-t 1/3] tools/intel_bios_reader: abstract header information dumping Jani Nikula
  2016-05-12 12:37 ` [PATCH i-g-t 2/3] tools/intel_bios_reader: clean up VBT/BDB header dumping Jani Nikula
  2016-05-12 12:38 ` [PATCH i-g-t 3/3] tools/intel_bios_reader: print errors to stderr, return EXIT_FAILURE Jani Nikula
@ 2016-05-13 13:52 ` Jani Nikula
  2 siblings, 0 replies; 4+ messages in thread
From: Jani Nikula @ 2016-05-13 13:52 UTC (permalink / raw)
  To: intel-gfx


Fairly simple stuff, pushed the series to igt.

BR,
Jani.

On Thu, 12 May 2016, Jani Nikula <jani.nikula@intel.com> wrote:
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>  tools/intel_bios_reader.c | 52 +++++++++++++++++++++++++++--------------------
>  1 file changed, 30 insertions(+), 22 deletions(-)
>
> diff --git a/tools/intel_bios_reader.c b/tools/intel_bios_reader.c
> index 5bad3f49690d..25460cacd84c 100644
> --- a/tools/intel_bios_reader.c
> +++ b/tools/intel_bios_reader.c
> @@ -62,6 +62,7 @@ struct bdb_block {
>  };
>  
>  struct context {
> +	const struct vbt_header *vbt;
>  	const struct bdb_header *bdb;
>  	int size;
>  
> @@ -1405,6 +1406,32 @@ static bool dump_section(struct context *context, int section_id)
>  	return true;
>  }
>  
> +static void dump_headers(struct context *context)
> +{
> +	char signature[17];
> +	int i;
> +
> +	printf("VBT vers: %d.%d\n",
> +	       context->vbt->version / 100, context->vbt->version % 100);
> +
> +	strncpy(signature, (char *)context->bdb->signature, 16);
> +	signature[16] = 0;
> +	printf("BDB sig: %s\n", signature);
> +	printf("BDB vers: %d\n", context->bdb->version);
> +
> +	printf("Available sections: ");
> +	for (i = 0; i < 256; i++) {
> +		struct bdb_block *block;
> +
> +		block = find_section(context, i);
> +		if (!block)
> +			continue;
> +		printf("%d ", i);
> +		free(block);
> +	}
> +	printf("\n");
> +}
> +
>  enum opt {
>  	OPT_UNKNOWN = '?',
>  	OPT_END = -1,
> @@ -1441,11 +1468,9 @@ int main(int argc, char **argv)
>  	const char *toolname = argv[0];
>  	struct stat finfo;
>  	int size;
> -	struct bdb_header *bdb;
>  	struct context context = {
>  		.panel_type = -1,
>  	};
> -	char signature[17];
>  	char *endp;
>  	int block_number = -1;
>  
> @@ -1570,34 +1595,17 @@ int main(int argc, char **argv)
>  		return 1;
>  	}
>  
> -	printf("VBT vers: %d.%d\n", vbt->version / 100, vbt->version % 100);
> -
>  	bdb_off = vbt_off + vbt->bdb_offset;
>  	if (bdb_off >= size - sizeof(struct bdb_header)) {
>  		printf("Invalid VBT found, BDB points beyond end of data block\n");
>  		return 1;
>  	}
>  
> -	bdb = (struct bdb_header *)(VBIOS + bdb_off);
> -	strncpy(signature, (char *)bdb->signature, 16);
> -	signature[16] = 0;
> -	printf("BDB sig: %s\n", signature);
> -	printf("BDB vers: %d\n", bdb->version);
> -
> -	context.bdb = bdb;
> +	context.vbt = vbt;
> +	context.bdb = (const struct bdb_header *)(VBIOS + bdb_off);
>  	context.size = size;
>  
> -	printf("Available sections: ");
> -	for (i = 0; i < 256; i++) {
> -		struct bdb_block *block;
> -
> -		block = find_section(&context, i);
> -		if (!block)
> -			continue;
> -		printf("%d ", i);
> -		free(block);
> -	}
> -	printf("\n");
> +	dump_headers(&context);
>  
>  	if (!context.devid) {
>  		const char *devid_string = getenv("DEVICE");

-- 
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-05-13 13:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-12 12:37 [PATCH i-g-t 1/3] tools/intel_bios_reader: abstract header information dumping Jani Nikula
2016-05-12 12:37 ` [PATCH i-g-t 2/3] tools/intel_bios_reader: clean up VBT/BDB header dumping Jani Nikula
2016-05-12 12:38 ` [PATCH i-g-t 3/3] tools/intel_bios_reader: print errors to stderr, return EXIT_FAILURE Jani Nikula
2016-05-13 13:52 ` [PATCH i-g-t 1/3] tools/intel_bios_reader: abstract header information dumping Jani Nikula

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.