Skip to content

Instantly share code, notes, and snippets.

@erosennin
Last active August 29, 2015 14:08
Show Gist options
  • Save erosennin/593de363a4361411cd4f to your computer and use it in GitHub Desktop.
Save erosennin/593de363a4361411cd4f to your computer and use it in GitHub Desktop.
strace patch: decode (some) framebuffer ioctls on Kobo devices
diff --git a/Makefile.am b/Makefile.am
index 703f4da..3d11c1f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,6 +36,7 @@ strace_SOURCES = \
loop.c \
mem.c \
mtd.c \
+ mxcfb.c \
net.c \
pathtrace.c \
process.c \
diff --git a/defs.h b/defs.h
index d41af96..14b82e0 100644
--- a/defs.h
+++ b/defs.h
@@ -726,6 +726,7 @@ extern int mtd_ioctl(struct tcb *, long, long);
extern int ubi_ioctl(struct tcb *, long, long);
extern int loop_ioctl(struct tcb *, long, long);
extern int ptp_ioctl(struct tcb *, long, long);
+extern int mxcfb_ioctl(struct tcb *, long, long);
extern int tv_nz(const struct timeval *);
extern int tv_cmp(const struct timeval *, const struct timeval *);
diff --git a/ioctl.c b/ioctl.c
index 99b31fb..3df029e 100644
--- a/ioctl.c
+++ b/ioctl.c
@@ -90,6 +90,8 @@ ioctl_decode(struct tcb *tcp, long code, long arg)
case 0x22:
return scsi_ioctl(tcp, code, arg);
#endif
+ case 'F':
+ return mxcfb_ioctl(tcp, code, arg);
case 'L':
return loop_ioctl(tcp, code, arg);
case 'M':
diff --git a/linux/ioctlent.h.in b/linux/ioctlent.h.in
index 8182842..c981eea 100644
--- a/linux/ioctlent.h.in
+++ b/linux/ioctlent.h.in
@@ -26,6 +26,27 @@
{"linux/fd.h", "FDTWADDLE", 0x0259},
{"linux/fd.h", "FDEJECT", 0x025a},
{"linux/fd.h", "FDSETDRVPRM", 0x0290},
+ {"linux/mxcfb.h", "MXCFB_WAIT_FOR_VSYNC", 0x4620},
+ {"linux/mxcfb.h", "MXCFB_SET_GBL_ALPHA", 0x4621},
+ {"linux/mxcfb.h", "MXCFB_SET_CLR_KEY", 0x4622},
+ {"linux/mxcfb.h", "MXCFB_SET_OVERLAY_POS", 0x4624},
+ {"linux/mxcfb.h", "MXCFB_GET_FB_IPU_CHAN", 0x4625},
+ {"linux/mxcfb.h", "MXCFB_SET_LOC_ALPHA", 0x4626},
+ {"linux/mxcfb.h", "MXCFB_SET_LOC_ALP_BUF", 0x4627},
+ {"linux/mxcfb.h", "MXCFB_SET_GAMMA", 0x4628},
+ {"linux/mxcfb.h", "MXCFB_GET_FB_IPU_DI", 0x4629},
+ {"linux/mxcfb.h", "MXCFB_GET_DIFMT", 0x462a},
+ {"linux/mxcfb.h", "MXCFB_GET_FB_BLANK", 0x462b},
+ {"linux/mxcfb.h", "MXCFB_SET_WAVEFORM_MODES", 0x462b},
+ {"linux/mxcfb.h", "MXCFB_SET_DIFMT", 0x462c},
+ {"linux/mxcfb.h", "MXCFB_SET_TEMPERATURE", 0x462c},
+ {"linux/mxcfb.h", "MXCFB_SET_AUTO_UPDATE_MODE", 0x462d},
+ {"linux/mxcfb.h", "MXCFB_SEND_UPDATE", 0x462e},
+ {"linux/mxcfb.h", "MXCFB_WAIT_FOR_UPDATE_COMPLETE", 0x462f},
+ {"linux/mxcfb.h", "MXCFB_SET_PWRDOWN_DELAY", 0x4630},
+ {"linux/mxcfb.h", "MXCFB_GET_PWRDOWN_DELAY", 0x4631},
+ {"linux/mxcfb.h", "MXCFB_SET_UPDATE_SCHEME", 0x4632},
+ {"linux/mxcfb.h", "MXCFB_SET_MERGE_ON_WAVEFORM_MISMATCH", 0x4637},
{"linux/hdreg.h", "HDIO_GETGEO", 0x0301},
{"linux/hdreg.h", "HDIO_GET_UNMASKINTR", 0x0302},
{"linux/hdreg.h", "HDIO_GET_MULTCOUNT", 0x0304},
diff --git a/mxcfb.c b/mxcfb.c
new file mode 100644
index 0000000..f473de4
--- /dev/null
+++ b/mxcfb.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2014 Andrey Golovizin <ag@sologoc.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "defs.h"
+#include <linux/ioctl.h>
+
+#ifndef MXCFB_SEND_UPDATE
+#define MXCFB_SEND_UPDATE _IOW('F', 0x2E, struct mxcfb_update_data)
+#endif
+
+#ifndef MXCFB_WAIT_FOR_UPDATE_COMPLETE
+#define MXCFB_WAIT_FOR_UPDATE_COMPLETE _IOW('F', 0x2F, uint32_t)
+#endif
+
+struct mxcfb_rect {
+ uint32_t top;
+ uint32_t left;
+ uint32_t width;
+ uint32_t height;
+};
+
+struct mxcfb_alt_buffer_data {
+ void *virt_addr;
+ uint32_t phys_addr;
+ uint32_t width; /* width of entire buffer */
+ uint32_t height; /* height of entire buffer */
+ struct mxcfb_rect alt_update_region; /* region within buffer to update */
+};
+
+struct mxcfb_update_data {
+ struct mxcfb_rect update_region;
+ uint32_t waveform_mode;
+ uint32_t update_mode;
+ uint32_t update_marker;
+ int temp;
+ uint flags;
+ struct mxcfb_alt_buffer_data alt_buffer_data;
+};
+
+void print_rect(struct mxcfb_rect *rect)
+{
+ tprintf(
+ "top=%" PRIu32
+ ", left=%" PRIu32
+ ", width=%" PRIu32
+ ", height=%" PRIu32,
+ rect->top,
+ rect->left,
+ rect->width,
+ rect->height
+ );
+}
+
+int
+mxcfb_ioctl(struct tcb *tcp, long code, long arg)
+{
+ struct mxcfb_update_data data;
+ uint32_t uint32_data;
+
+ switch (code) {
+ case MXCFB_SEND_UPDATE:
+ if (!verbose(tcp) || umove(tcp, arg, &data) < 0)
+ return 0;
+
+ if (entering(tcp)) {
+ tprints(", {");
+ tprints("update_region={");
+ print_rect(&data.update_region);
+ tprints("}");
+ tprintf(", waveform_mode=%" PRIu32, data.waveform_mode);
+ tprintf(", update_mode=%" PRIu32, data.update_mode);
+ tprintf(", update_marker=%" PRIu32, data.update_marker);
+ tprintf(", temp=%i", data.temp);
+ tprintf(", flags=%u", data.flags);
+ } else {
+ tprints("}");
+ }
+ return 1;
+
+ case MXCFB_WAIT_FOR_UPDATE_COMPLETE:
+ if (!verbose(tcp) || umove(tcp, arg, &uint32_data) < 0)
+ return 0;
+
+ if (entering(tcp)) {
+ tprintf(", {%" PRIu32, uint32_data);
+ } else {
+ tprints("}");
+ }
+ return 1;
+ default:
+ return 0;
+ }
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment