[libcamera-devel,0/5] Add a params buffer dump tool for IPU3
diff mbox

Message ID 20220630101702.45781-1-jeanmichel.hautbois@ideasonboard.com
State New
Headers show

Commit Message

Jean-Michel Hautbois June 30, 2022, 10:16 a.m. UTC
Hello !

This patch series is a branch I had for long locally and I want to
share. The params buffer on IPU3 is big, and quite difficult to read
without having the documentation on another screen :-).

To simplify the debug, I wrote a very simple C tool which takes the
parameters buffer dumped in a binary form and parses it in a human
readable form.

I have a patch, not part of the series, to dump the parameter buffer [1].
It is a dumb one, as for every buffer it overwrites the file. It might
be interesting to keep all the buffers through time later, if we want to
see the changes during time. Or call it only when requested (but there
is no way to pass this internal buffer to the userspace).

I hope this tool can help, it does not contain all the structures of the
parameters buffer, but the model is there, and can be upgraded ;-).

Thanks !

[1] For reference:

Jean-Michel Hautbois (5):
  utils: ipu3: Introduce a parameters dump tool
  utils: ipu3: Display only if it is modified by userspace
  utils: ipu3: Display BNR configuration
  utils: ipu3: display green disparity params
  utils: ipu3: dump lens shading params

 utils/ipu3/ipu3-dump-params.c | 222 ++++++++++++++++++++++++++++++++++
 utils/ipu3/meson.build        |   5 +
 2 files changed, 227 insertions(+)
 create mode 100644 utils/ipu3/ipu3-dump-params.c

diff mbox

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 6c5617cd..651069c6 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -6,9 +6,12 @@ 
 #include <algorithm>
+#include <fcntl.h>
 #include <iomanip>
 #include <memory>
 #include <queue>
+#include <sys/mman.h>
+#include <unistd.h>
 #include <vector>
 #include <libcamera/base/log.h>
@@ -61,6 +64,7 @@  public:
        void queuePendingRequests();
        void cancelPendingRequests();
        void frameStart(uint32_t sequence);
+       void dumpBuffer(FrameBuffer *paramBuffer);
        CIO2Device cio2_;
        ImgUDevice *imgu_;
@@ -1288,6 +1292,7 @@  void IPU3CameraData::queueFrameAction(unsigned int id,
+               dumpBuffer(info->paramBuffer);
@@ -1313,6 +1318,24 @@  void IPU3CameraData::queueFrameAction(unsigned int id,
+void IPU3CameraData::dumpBuffer(FrameBuffer *buffer)
+       for (const FrameBuffer::Plane &plane : buffer->planes()) {
+               void *address = mmap(nullptr, plane.length, PROT_WRITE,
+                                    MAP_SHARED, plane.fd.get(), 0);
+               if (address == MAP_FAILED) {
+                       LOG(IPU3, Error) << "Failed to mmap plane";
+                       break;
+               }
+               int out_fd = open("/tmp/IPU3_params.bin",
+                                 O_WRONLY | O_TRUNC | O_CREAT, 0644);
+               write(out_fd, address, plane.length);
+               close(out_fd);
+               munmap(address, plane.length);
+       }
 /* -----------------------------------------------------------------------------
  * Buffer Ready slots