Search code examples
stm32embedded-linuxyoctoi2cdevice-tree

`i2cdetect` command not found after enabling it in Busybox and then using `bitbake custom-image`


I'm following every step on Shawn Hymel's (Digi-Key) tutorial on embedded Linux.

Device: STM32MP157D-DK1

Setup: Host PC is Linux Mint 21.1 Vera.

Goal: Run command i2cdetect on the device (using Yocto, flashing the right image onto a micro SD and booting from it).

Steps taken:

  • Copying .dts file to patch:

    cp stm32mp157d-dk1.dts ~/Documents
    

    and create a copy of it, adding .orig at the end:

    cp stm32mp157d-dk1.dts stm32mp157d-dk1.dts.orig
    
  • Modify the first one to add our own node for enabling i2c. The modified file will looks like this:

// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
 * Copyright (C) STMicroelectronics 2019 - All Rights Reserved
 * Author: Alexandre Torgue <[email protected]> for STMicroelectronics.
 */

/dts-v1/;

#include "stm32mp157.dtsi"
#include "stm32mp15xd.dtsi"
#include "stm32mp15-pinctrl.dtsi"
#include "stm32mp15xxac-pinctrl.dtsi"
#include "stm32mp15xx-dkx.dtsi"

/ {
        model = "STMicroelectronics STM32MP157D-DK1 Discovery Board";
        compatible = "st,stm32mp157d-dk1", "st,stm32mp157";

        aliases {
                serial0 = &uart4;
                serial1 = &usart3;
                serial2 = &uart7;
        };

        chosen {
                stdout-path = "serial0:115200n8";
        };
};

&i2c5 {
        pinctrl-names = "default", "sleep";
        pinctrl-0 = <&i2c5_pins_a>;
        pinctrl-1 = <&i2c5_sleep_pins_a>;
        i2c-scl-rising-time-ns = <185>;
        i2c-scl-falling-time-ns = <20>;
        clock-frequency = <100000>;
        status = "okay";
};
  • Create a patch file and use it in our own layer:

    git diff --no-index stm32mp157d-dk1.dts.orig stm32mp157d-dk1.dts > 0001-add-i2c5-userspace-dts.patch
    

Modifying this patch file, editing the path and file names to be the same (except a/ and b/), resulting in:

diff --git a/stm32mp157d-dk1.dts.orig b/stm32mp157d-dk1.dts
index d54dcf1..d8bd859 100644
--- a/arch/boot/dts/stm32mp157d-dk1.dts
+++ b/arch/boot/dts/stm32mp157d-dk1.dts
@@ -16,7 +16,23 @@
        model = "STMicroelectronics STM32MP157D-DK1 Discovery Board";
        compatible = "st,stm32mp157d-dk1", "st,stm32mp157";

+       aliases {
+               serial0 = &uart4;
+               serial1 = &usart3;
+               serial2 = &uart7;
+       };
+
        chosen {
                stdout-path = "serial0:115200n8";
        };
 };
+
+&i2c5 {
+       pinctrl-names = "default", "sleep";
+       pinctrl-0 = <&i2c5_pins_a>;
+       pinctrl-1 = <&i2c5_sleep_pins_a>;
+       i2c-scl-rising-time-ns = <185>;
+       i2c-scl-falling-time-ns = <20>;
+       clock-frequency = <100000>;
+       status = "okay";
+};

Now we want to copy this patch to our custom layer, and tell our recipe that we want to include this patch and to apply it prior to building the device tree.

source poky/oe-init-build-env build-mp1/`
cp ~/Documents/0001-add-i2c5-userspace-dts.patch recipes-kernel/linux/stm32mp1/
  • Create .bbappend file:
    vi recipes-kernel/linux/linux-stm32mp_%.bbappend
    
    which will look like this:
FILESEXTRAPATHS_prepend := "${THISDIR}:"
SRC_URI += "file://0001-add-i2c5-userspace-dts.patch"
  • Adding i2cdetect tool using Busybox:

    bitbake -c menuconfig busybox
    

    Inside Busybox: Miscellaneous Utilities --> [*] i2cdetect --> Select --> Exit --> Yes to save configuration

This only applies it localy in the build-mp1 folder. This hasn't been enabled in our custom layer, so we will have to do this every time we deploy that image, unless creating default configuration (not this case).

bitbake custom image:

bitbake custom-image

Then flashing the image to a micro-SD card with 5 partitions: fsbl1, fsbl2, fip, bootfs, rootfs.

At this stage, ready to start picocom and power the board.

Once logged (root), running some command to check things out, such as:

ls -l /sys/bus/i2c/devices/

But, can't find i2cdetect:

i2cdetect -y 1
-sh: i2cdetect: not found

Does anyone have an idea please of how to resolve this issue of enabling the use of i2cdetect? Any kind of assistance will be much appreciated.

Tried to enable i2cdetect, using Busybox, in a custom image created in Yocto. Doesn't work as the command isn't found.


Solution

  • All the details that you provided do not help in resolving the problem of i2cdetect not found.

    Anyways, the only logical reason for the issue is the following:

    • The modification you did using busybox menuconfig did not get applied.

    Why ?

    Because:

    • The busybox recipe did not get compiled again after the changes

    Why ?

    Because:

    • do_compile is already done and task cache is already created, so it will never run again

    Why ?

    Because:

    • The content of do_compile did not change

    Now, the solution is one of the following:

    1. Create a fragment file like detailed in this answer.
    2. Force the compilation of busybox after menuconfig: bitbake busybox -f -c compile

    [NOTE]

    Before sacrificing the time in:

    • Building the full image
    • Flashing the SD card
    • Booting and testing

    Make sure you debug your image first:

    1. bitbake -e <image_name> | grep ^WORKDIR= , under that path you will find rootfs which is the final rootfs that will go into your SD card, check if i2cdetect is there or not.

    [OTHER SOLUTION]

    You can integrate i2cdetect along side all other i2c-tools via another recipe (meta/recipes-devtools/i2c-tools) with a simple:

    IMAGE_INSTALL:append = " i2c-tools"
    

    but remember to choose one of the two solutions only, otherwise you will get files conflicts between busybox and i2c-tools.