Hardware Revision Detection using GPIO Inputs in U-Boot


We’re currently migrating from WinCE to Linux, using Toradex’ provided BSPs based on Yocto.

My current test module is a Colibri IMX8QXP 2GB (No Wifi), existing module is the Colibri T30.

For now, all the development and testing takes place on the IMX8 module (Using BSP 5.7), but keep in mind that at a later time the existing T30 should be ported from CE to Linux as well (BSP 2.8). It’s preferable to keep the changes between the two images as small as possible (That’s why device tree overlays are not used on the imx8, for example).

We’re using a custom carrier board, that has already undergone some hardware revisions, and more are likely. That’s why the IMX8 should be backwards compatible to eralier (but still active) revisions as well.

To determine the current board’s revision, we’re using Digital Inputs, which are binary coded: SODIMM 138,140 and 142. Further SODIMM 129 and 135.

Now my idea would be to create different device trees when required and decide which one to use depending on the revision. As far as I’ve seen, that should be possible from within u-boot, because it’s possible to read the GPIOs there.
However, the problem is that all this pins should be configured to pull down for proper detection, which most aren’t by default. Probably other configuration might be required as well, e.g. changing the default UART for debugging.

I’ve read that it’s possible to modify u-boot to change the pin layout and other hardware configuration. I’ve seen the file “imx8qxp_mek.c” has been mentioned in a few related discussions, most notably here: A step-by-step guide to bringing up your NXP i.MX8 - PathPartnerTech

I think I’ve also found the file on the related git for toradex: imx8qxp_mek.c « imx8qxp_mek « freescale « board - u-boot-toradex.git - U-Boot bootloader for Apalis and Colibri modules

Related files/directories on the site:

  • configs/imx8qxp_mek_defconfig
  • arch/arm/dts/fsl-imx8qxp-mek.dts
  • board/freescale/imx8qxp_mek/

It seems that u-boot is not checked out as source code in yocto, I can’t find the “imx8qxp_mek.c” or other related files in the build/ directory.

Now my questions:

  • Is the approach using u-boot to detect the revision & select dtb sensible? If not, what’s best practice?
  • Where can I find or add the u-boot source in yocto to make my modifications?
  • What’s the best way to modify these files? using a .patch or duplicate the files with a different name?

If something is unclear or more information is required, let me know.



I’d say that u-boot is indeed a good place to put hw revision detection and matching DTB selection. I’ve done the same on Verdin IMX8MP.
What was confusing at first in u-boot is the fact that not only does u-boot handle the kernel DTBs, but also its own DTB(s), and potentially even different DTB(s) for SPL.

I modify u-boot mostly via patches, plus copying in my own board files via SRC_URI like this:

SRC_URI += "file://board/MYCOMPANY/MYPRODUCT/;subdir=git/"
SRC_URI += "file://include/configs/MYPRODUCT.h;subdir=git/"

As I have my own layer, I place the above in meta-MYCOMPANY/recipes-bsp/u-boot/u-boot-toradex_%.bbappend

The board C file reads the GPIO, and sets a u-boot env var which is then used by my u-boot boot script to pass the right DTB name to the kernel.

1 Like

Hi @mbessler

Thanks for your response. I was able to configure & read the GPIOs in u-boot now.

For reference: I’m basically just overwriting these files in u-boot now.

  • board/toradex/colibri-imx8x/colibri-imx8x.c
  • include/configs/colibri-imx8x.h

In the header file, I added some environment variables to CONFIG_EXTRA_ENV_SETTINGS.
In the source file, the PINs are configured as GPIO in board_early_init_f().
Their value is read in board_late_init(), so the fdt_board can then be set via env_set().

After that, the fdt_file is assembled by u-boot containing the new fdt_board name, including the revision.

My layer is similar as yours, looks like that:

FILESEXTRAPATHS_prepend := "${THISDIR}/u-boot-toradex:"

SRC_URI += "\
    file://colibri-imx8x.c \
    file://colibri-imx8x.h \

do_configure_append() {
    cp ${WORKDIR}/colibri-imx8x.c ${S}/board/toradex/colibri-imx8x
    cp ${WORKDIR}/colibri-imx8x.h ${S}/include/configs

And I found out that u-boot is indeed downloaded from git (to build/tmp/work/colibri_imx8x-tdx-linux/u-boot-toradex/2020.04.r0/git), but after a successful build, its files are imediately deleted, that’s why I couldn’t locate them before.