[libcamera-devel,1/5] utils: ipu3: Introduce a parameters dump tool
diff mbox series

Message ID 20220630101702.45781-2-jeanmichel.hautbois@ideasonboard.com
State New
Headers show
Series
  • [libcamera-devel,1/5] utils: ipu3: Introduce a parameters dump tool
Related show

Commit Message

Jean-Michel Hautbois June 30, 2022, 10:16 a.m. UTC
The parameters buffer for IPU3 contains a lot of structures, and is not
very easy to debug. This tool aims to ease the parsing of it, when it
has been stored as a binary raw file.

This commit introduces the parsing with the support of the AWB grid
configuration.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 utils/ipu3/ipu3-dump-params.c | 74 +++++++++++++++++++++++++++++++++++
 utils/ipu3/meson.build        |  5 +++
 2 files changed, 79 insertions(+)
 create mode 100644 utils/ipu3/ipu3-dump-params.c

Patch
diff mbox series

diff --git a/utils/ipu3/ipu3-dump-params.c b/utils/ipu3/ipu3-dump-params.c
new file mode 100644
index 00000000..9bd61593
--- /dev/null
+++ b/utils/ipu3/ipu3-dump-params.c
@@ -0,0 +1,74 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * ipu3-dump-params - Display IPU3 parameters buffer from a binary dump
+ *
+ * Copyright 2021 Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
+ */
+#define _GNU_SOURCE
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <linux/intel-ipu3.h>
+
+static void usage(const char *argv0)
+{
+	printf("Usage: %s input-file\n", basename(argv0));
+	printf("Display the IPU3 parameters buffer\n");
+}
+
+static void displayGrid(struct ipu3_uapi_grid_config *grid, const char *gridName)
+{
+	printf("Configured %s grid [%d,%d]x[%d,%d] starting at (%d, %d)\n",
+	       gridName,
+	       grid->width,
+	       grid->block_width_log2,
+	       grid->height,
+	       grid->block_height_log2,
+	       grid->x_start,
+	       grid->y_start & ~IPU3_UAPI_GRID_Y_START_EN);
+
+	printf("Grid size is (%d x %d)\n",
+	       grid->width << grid->block_width_log2,
+	       grid->height << grid->block_height_log2);
+}
+
+int main(int argc, char *argv[])
+{
+	int in_fd;
+	int ret = 0;
+	struct ipu3_uapi_params params;
+
+	if (argc != 2) {
+		usage(argv[0]);
+		return 1;
+	}
+
+	in_fd = open(argv[1], O_RDONLY);
+	if (in_fd == -1) {
+		fprintf(stderr, "Failed to open input file '%s': %s\n",
+			argv[1], strerror(errno));
+		return 1;
+	}
+
+start:
+	ret = read(in_fd, &params, sizeof(params));
+	if (ret == -1 && errno == EINTR)
+		goto start;
+
+	printf("Read parameters buffer of size %d\n", ret);
+
+	printf("\n**** AWB parameters ****\n");
+	displayGrid(&params.acc_param.awb.config.grid, "awb");
+	displayGrid(&params.acc_param.awb_fr.grid_cfg, "awb_fr");
+
+	close(in_fd);
+
+	return ret ? 1 : 0;
+}
diff --git a/utils/ipu3/meson.build b/utils/ipu3/meson.build
index 88049f58..b2d5577e 100644
--- a/utils/ipu3/meson.build
+++ b/utils/ipu3/meson.build
@@ -1,3 +1,8 @@ 
 # SPDX-License-Identifier: CC0-1.0
 
+includes = [
+    libcamera_includes,
+]
+
 ipu3_unpack = executable('ipu3-unpack', 'ipu3-unpack.c')
+ipu3_dump_params = executable('ipu3-dump-params', 'ipu3-dump-params.c', include_directories : libcamera_includes)