[PATCH 0/1] i2c: add I2C ioctl decoding

Tobias Peter git at tobyp.net
Tue Apr 6 16:47:00 UTC 2021


Hi strace-dev,

I was missing decoding for the I2C ioctls, so I went ahead and
implemented them for myself. If you consider this patch acceptable, I'd
like contribute them upstream.

I based this mostly on the existing gpio_ioctl. I've tested this a bit
using i2c-tools, but not exhaustively. Here's some example output:

> $ strace i2cdetect -y 1
...
> ioctl(3, I2C_FUNCS, I2C_FUNC_I2C|I2C_FUNC_SMBUS_QUICK|
>                     I2C_FUNC_SMBUS_READ_BYTE|
>                     I2C_FUNC_SMBUS_WRITE_BYTE|
>                     I2C_FUNC_SMBUS_READ_BYTE_DATA|
>                     I2C_FUNC_SMBUS_WRITE_BYTE_DATA|
>                     I2C_FUNC_SMBUS_READ_WORD_DATA|
>                     I2C_FUNC_SMBUS_WRITE_WORD_DATA|
>                     I2C_FUNC_SMBUS_READ_BLOCK_DATA|
>                     I2C_FUNC_SMBUS_WRITE_BLOCK_DATA) = 0
...
> ioctl(3, I2C_SLAVE, 0x50) = 0
> ioctl(3, I2C_SMBUS, {read_write=I2C_SMBUS_READ, command=0, 
>       size=I2C_SMBUS_BYTE, data={byte=0x00} => {byte=0xff}}) = 0
...
> $ strace i2cget -y 1 0x50 0x01 wp
...
> ioctl(3, I2C_PEC, 1) = 0
> ioctl(3, I2C_SMBUS, {read_write=I2C_SMBUS_READ, command=0x1,
>       size=I2C_SMBUS_WORD_DATA, data={word=0} => {word=0xffff}}) = 0
...
> $ strace i2ctransfer -y 1 w1 at 0x50 0x01 r8
...
> ioctl(3, I2C_RDWR, {nmsgs=2, [
>                               {addr=0x50, flags=0, len=1, buf="\x01"},
>                               {addr=0x50, flags=I2C_M_RD, len=8, 
>                                buf="\x00\x00\x00\x00\x00\x00\x00\x00"}
>                              ] => [
>                               {addr=0x50, flags=0, len=1, buf="\x01"},
>                               {addr=0x50, flags=I2C_M_RD, len=8,
>                                buf="\xff\xff\xff\xff\xff\xff\x00\x34"}
>                              ]}) = 2
...

I'm not yet sure about the output format as far as changed values are
concerned. The current implementation allows me to get by without a
`saved` construct like e.g. bpf uses it, but has some drawbacks:

 - It currently prints values that are unimportant, like the original
   content of the `buf` or `data` fields on pure read operations.
 - For I2C_RDWR, "request" and "response" i2c_msg objects are not next
   to each other, which makes them hard to read.

If this is something you'd like to merge, please let me know if any
further changes are needed, and what you think about that last point
I mentioned.

Thanks in any case for building such a great tool,
Tobias

Tobias Peter (1):
  i2c: add I2C ioctl decoding

 bundled/linux/include/uapi/linux/i2c-dev.h |  59 +++++
 bundled/linux/include/uapi/linux/i2c.h     | 164 ++++++++++++++
 maint/ioctls_gen.sh                        |   1 +
 src/Makefile.am                            |   1 +
 src/defs.h                                 |   1 +
 src/i2c_ioctl.c                            | 239 +++++++++++++++++++++
 src/ioctl.c                                |   2 +
 src/linux/32/ioctls_inc_align16.h          |   9 +
 src/linux/32/ioctls_inc_align32.h          |   9 +
 src/linux/32/ioctls_inc_align64.h          |   9 +
 src/linux/64/ioctls_inc.h                  |   9 +
 src/xlat/i2c_funcs.in                      |  21 ++
 src/xlat/i2c_msg_flags.in                  |  10 +
 src/xlat/i2c_smbus_read_write.in           |   3 +
 src/xlat/i2c_smbus_size.in                 |  10 +
 15 files changed, 547 insertions(+)
 create mode 100644 bundled/linux/include/uapi/linux/i2c-dev.h
 create mode 100644 bundled/linux/include/uapi/linux/i2c.h
 create mode 100644 src/i2c_ioctl.c
 create mode 100644 src/xlat/i2c_funcs.in
 create mode 100644 src/xlat/i2c_msg_flags.in
 create mode 100644 src/xlat/i2c_smbus_read_write.in
 create mode 100644 src/xlat/i2c_smbus_size.in

-- 
2.31.1



More information about the Strace-devel mailing list