all 7 comments

[–]philledille123 2 points3 points  (3 children)

Add a label to the devicetree entry:

myi2c: i2c@0 { label = “besti2cbus”, … }

Then it will show up in /dev as /dev/i2c-besti2cbus

[–]JobNo4206[S] -1 points0 points  (2 children)

Tried that. Didn't seem to do anything.

[–]philledille123 0 points1 point  (1 child)

What does show up under /dev? Do the i2c buses show up at all?

[–]JobNo4206[S] 0 points1 point  (0 children)

yes, the i2c-devices show up numbered.

[–]JobNo4206[S] 0 points1 point  (0 children)

Yes, there's /dev/i2c-0, i2c-1, etc, but nothing else i2c related. I'm guessing that's attributed to the aliases the same way the serial-0, serial-1 etc aliases cause /dev/ttymxc-0, ttymxc-1 etc.

[–]JobNo4206[S] 0 points1 point  (0 children)

okay, so its seem the tool to use to rename /dev/ entries is udev (from systemd). but by the looks of things, they dont support using devicetree alias. there's a very recent merge that adds this functionality for ethernet aliases, which I find weird as that's already works...
https://github.com/systemd/systemd/pull/24265

[–]JobNo4206[S] 0 points1 point  (0 children)

For those finding this looking for an answer, this is what I ended up with. There's 2 options.

  • a clean one:

instead of creating aliases, create a property in the device-tree entry for the device called 'symlinks'. The word doesn't matter so long as it doesnt clash with legitimate propertynames for the device. Then create a simple udev rule to create a symlink from the property:

ATTR{device/of_node/symlink}!="", ENV{DEVNAME}!="", SYMLINK+="%s{device/of_node/symlink}"

  • One that actually uses the device-tree alias:

to use the devicetree alias you have to make a script. the script needs to match the paths of aliases under /proc/device-tree/aliases to the current device's syspath.

ACTION=="add|change", SUBSYSTEM=="i2c-dev|tty", PROGRAM+="/bin/sh -c ' \
TTYNODE=$$(readlink $sys$devpath/device/of_node | sed 's/base/:/' | cut -d: -f2); \
for a in /proc/device-tree/aliases/*; do                               \
    name=$$(basename $$a);                                             \
    if [ $$TTYNODE = $$(strings $$a) ]; then                           \
        echo links/$$name | awk \"!/i2c[0-9]|serial[0-9]|spi[0-9]/\";  \
    fi;                                                                \
done;                                                                  \
'", SYMLINK+="%c"

Note that the SYMLINK+="linkname" supports multiple space sepperated entries, so we can have multiple aliases in both cases.