nils_z
Posts: 6
Joined: Thu Oct 31, 2019 2:58 pm

Disabling SDIO on GPIO 34-39 in yocto build

Thu Oct 31, 2019 4:39 pm

I am building an image for a CM3+ system using yocto with mender (using this manual with machine cm3: https://hub.mender.io/t/raspberry-pi-3-model-b-b/57). I need a sd card on gpios 22-27.

With raspbian, this works fine by adding

Code: Select all

dtoverlay=sdio,poll_once=off
to /boot/config.txt.
In the yocto build, before adding this line,

Code: Select all

raspi-gpio get
shows that gpios 34-39 are already configured for SD1. After adding the line, both 34-39 and 22-27 are configured for SD1:

Code: Select all

GPIO 22: level=0 fsel=7 alt=3 func=SD1_CLK
GPIO 23: level=1 fsel=7 alt=3 func=SD1_CMD
GPIO 24: level=1 fsel=7 alt=3 func=SD1_DAT0
GPIO 25: level=1 fsel=7 alt=3 func=SD1_DAT1
GPIO 26: level=1 fsel=7 alt=3 func=SD1_DAT2
GPIO 27: level=1 fsel=7 alt=3 func=SD1_DAT3
BANK1 (GPIO 28 to 45):
GPIO 28: level=0 fsel=1 func=OUTPUT
GPIO 29: level=0 fsel=0 func=INPUT
GPIO 30: level=0 fsel=0 func=INPUT
GPIO 31: level=0 fsel=0 func=INPUT
GPIO 32: level=1 fsel=7 alt=3 func=TXD0
GPIO 33: level=0 fsel=7 alt=3 func=RXD0
GPIO 34: level=0 fsel=7 alt=3 func=SD1_CLK
GPIO 35: level=1 fsel=7 alt=3 func=SD1_CMD
GPIO 36: level=1 fsel=7 alt=3 func=SD1_DAT0
GPIO 37: level=1 fsel=7 alt=3 func=SD1_DAT1
GPIO 38: level=1 fsel=7 alt=3 func=SD1_DAT2
GPIO 39: level=1 fsel=7 alt=3 func=SD1_DAT3
The sd card is not recognized. When configuring 34-39 to input with raspi-gpio set, the sd card is recognized (dmesg), but the system freezes a few seconds after that. This is not the case with raspbian.

I think is is a problem with the pre-configuration of 34-39, they should be configured as input initially like in raspbian. How can I find what causes this initial configuration of these pins in my yocto build?

Thank you!

fruitoftheloom
Posts: 20908
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Disabling SDIO on GPIO 34-39 in yocto build

Fri Nov 01, 2019 8:52 am

nils_z wrote:
Thu Oct 31, 2019 4:39 pm
I am building an image for a CM3+ system using yocto with mender (using this manual with machine cm3: https://hub.mender.io/t/raspberry-pi-3-model-b-b/57). I need a sd card on gpios 22-27.

With raspbian, this works fine by adding

Code: Select all

dtoverlay=sdio,poll_once=off
to /boot/config.txt.
In the yocto build, before adding this line,

Code: Select all

raspi-gpio get
shows that gpios 34-39 are already configured for SD1. After adding the line, both 34-39 and 22-27 are configured for SD1:

Code: Select all

GPIO 22: level=0 fsel=7 alt=3 func=SD1_CLK
GPIO 23: level=1 fsel=7 alt=3 func=SD1_CMD
GPIO 24: level=1 fsel=7 alt=3 func=SD1_DAT0
GPIO 25: level=1 fsel=7 alt=3 func=SD1_DAT1
GPIO 26: level=1 fsel=7 alt=3 func=SD1_DAT2
GPIO 27: level=1 fsel=7 alt=3 func=SD1_DAT3
BANK1 (GPIO 28 to 45):
GPIO 28: level=0 fsel=1 func=OUTPUT
GPIO 29: level=0 fsel=0 func=INPUT
GPIO 30: level=0 fsel=0 func=INPUT
GPIO 31: level=0 fsel=0 func=INPUT
GPIO 32: level=1 fsel=7 alt=3 func=TXD0
GPIO 33: level=0 fsel=7 alt=3 func=RXD0
GPIO 34: level=0 fsel=7 alt=3 func=SD1_CLK
GPIO 35: level=1 fsel=7 alt=3 func=SD1_CMD
GPIO 36: level=1 fsel=7 alt=3 func=SD1_DAT0
GPIO 37: level=1 fsel=7 alt=3 func=SD1_DAT1
GPIO 38: level=1 fsel=7 alt=3 func=SD1_DAT2
GPIO 39: level=1 fsel=7 alt=3 func=SD1_DAT3
The sd card is not recognized. When configuring 34-39 to input with raspi-gpio set, the sd card is recognized (dmesg), but the system freezes a few seconds after that. This is not the case with raspbian.

I think is is a problem with the pre-configuration of 34-39, they should be configured as input initially like in raspbian. How can I find what causes this initial configuration of these pins in my yocto build?

Thank you!
Yocto support their Operating System:

https://www.yoctoproject.org/community/
Retired disgracefully.....

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2439
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Disabling SDIO on GPIO 34-39 in yocto build

Fri Nov 01, 2019 9:12 am

Is there a dt-blob.bin present? If so, that is one place where the pin functions may be set.

Running as root ("sudo su" - you want the shell file globbing to have access to the debug directory), look at the output of:

Code: Select all

[email protected]:/home/pi# cat /sys/kernel/debug/pinctrl/*gpio*/pinmux-pins
It will show you whether something in Linux has claimed those pins.

nils_z
Posts: 6
Joined: Thu Oct 31, 2019 2:58 pm

Re: Disabling SDIO on GPIO 34-39 in yocto build

Mon Nov 04, 2019 9:52 am

fruitoftheloom wrote:
Fri Nov 01, 2019 8:52 am
Yocto support their Operating System:

https://www.yoctoproject.org/community/
Thank you, I know. But Yocto supports hundreds of boards and I think this is a raspberry pi specific problem, so I decided to post here as my previous research brought up some posts here by people using yocto on the pi.


Thank you PhilE, I tried the command:
PhilE wrote:
Fri Nov 01, 2019 9:12 am
Is there a dt-blob.bin present? If so, that is one place where the pin functions may be set.
A dt-blob.bin is present (needed for camera) but deleting it doesn't change anything with these pins (camera doesn't work after deleting).

Code: Select all

cat /sys/kernel/debug/pinctrl/*gpio*/pinmux-pins
shows

Code: Select all

pin 34 (gpio34): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 35 (gpio35): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 36 (gpio36): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 37 (gpio37): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 38 (gpio38): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 39 (gpio39): (MUX UNCLAIMED) (GPIO UNCLAIMED)
Adding dtoverlay=sdio,poll_once=off to config.txt changes pins 22-27, but has no effect on pins 34-39.

Code: Select all

pin 22 (gpio22): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio22
pin 23 (gpio23): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio23
pin 24 (gpio24): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio24
pin 25 (gpio25): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio25
pin 26 (gpio26): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio26
pin 27 (gpio27): 3f300000.mmc (GPIO UNCLAIMED) function alt3 group gpio27

Does this mean that it is not "something in Linux" that has claimed pins 34-39? Who else could it be?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2439
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Disabling SDIO on GPIO 34-39 in yocto build

Mon Nov 04, 2019 10:01 am

The default, built-in dt-blob leaves 34-39 as inputs (the default settings) on Computs Modules because it has no idea what they might be used for. If you don't have a custom dt-blob.bin, and if you don't have a "gpio=" directive in config.txt, then it can only be some element of the Yocto Linux configuration - a custom .dtb, overlay, driver or user-space configuration.

Dumping the active Device Tree will help to narrow down the cause - run "dtc -I fs /proc/device-treee > yocto.dts" and upload it somewhere I can see it.

nils_z
Posts: 6
Joined: Thu Oct 31, 2019 2:58 pm

Re: Disabling SDIO on GPIO 34-39 in yocto build

Mon Nov 04, 2019 11:24 am

Removing the dt-blob.bin doesn't help and I also tried using the config.txt form raspbian, no change on these pins. The cause has to be somewhere else.

Here is the output of "dtc -I fs /proc/device-tree > yocto.dts": https://pastebin.com/cfL28uWt

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2439
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Disabling SDIO on GPIO 34-39 in yocto build

Mon Nov 04, 2019 12:03 pm

Device tree isn't configuring those pins. If you search yocto.dts for "pins.*0x22" you'll find one match:

Code: Select all

			emmc_gpio34 {
				brcm,pins = < 0x22 0x23 0x24 0x25 0x26 0x27 >;
				phandle = < 0x32 >;
				brcm,pull = < 0x00 0x02 0x02 0x02 0x02 0x02 >;
				brcm,function = < 0x07 >;
			};
Notice the phandle value of 0x32. Searching for "pinctrl.*0x32" doesn't find any matches. Now compare that with the situation for GPIO 22. "pins.*0x16" finds:

Code: Select all

			sdio_ovl_pins {
				brcm,pins = < 0x16 0x17 0x18 0x19 0x1a 0x1b >;
				phandle = < 0x78 >;
				brcm,pull = < 0x00 0x02 0x02 0x02 0x02 0x02 >;
				brcm,function = < 0x07 >;
			};
and "pinctrl.*0x78" matches:

Code: Select all

		[email protected] {
			compatible = "brcm,bcm2835-mmc\0brcm,bcm2835-sdhci";
			clocks = < 0x03 0x1c >;
			status = "okay";
			interrupts = < 0x02 0x1e >;
			brcm,overclock-50 = < 0x00 >;
			bus-width = < 0x04 >;
			dma-names = "rx-tx";
			phandle = < 0x28 >;
			reg = < 0x7e300000 0x100 >;
			pinctrl-0 = < 0x78 >;
			dmas = < 0x08 0x0b >;
			pinctrl-names = "default";
		};
Since we've eliminated the dt-blob and the .dtb, that leaves a few options I think of:

1. There is a user-space script that runs something like raspi-gpio, gpio, pygpio etc. to configure the bins. This seems unlikely.
2. There is a 3rd-stage loader such as U-boot that is also performing pin configuration. I think this is the most likely option.

nils_z
Posts: 6
Joined: Thu Oct 31, 2019 2:58 pm

Re: Disabling SDIO on GPIO 34-39 in yocto build

Mon Nov 04, 2019 1:15 pm

PhilE wrote:
Mon Nov 04, 2019 12:03 pm
Since we've eliminated the dt-blob and the .dtb, that leaves a few options I think of:

1. There is a user-space script that runs something like raspi-gpio, gpio, pygpio etc. to configure the bins. This seems unlikely.
2. There is a 3rd-stage loader such as U-boot that is also performing pin configuration. I think this is the most likely option.
I also think the user-space script is unlikely. I did not add applications to the image yet.

As I wrote in my first post, I am building this image with mender. Mender uses u-boot and looking through the documentation, I read something about dtb-files (https://docs.mender.io/2.2/devices/yoct ... ntegration) and see recipes depending on dtc-native, looks like there is something done with the device tree.

Thank you for pointing me in this direction, I will now have a detailed look in the u-boot stuff if I can find the source of my problem there.

nils_z
Posts: 6
Joined: Thu Oct 31, 2019 2:58 pm

Re: Disabling SDIO on GPIO 34-39 in yocto build

Tue Nov 05, 2019 6:20 pm

To find the source for the gpio configuration, I removed mender and u-boot from the yocto build. Now the pins were configured as inputs. After adding u-boot again with RPI_USE_U_BOOT = "1" in local.conf, the pi didn't complete the linux start process due to some other problem, so I used the u-boot console by pressing a key after powering the board, where the command "U-Boot> gpio status -a" showed something like this:

Code: Select all

GPIO30: input: 0 [ ]
GPIO31: input: 0 [ ]
GPIO32: func
GPIO33: func
GPIO34: func
GPIO35: func
GPIO36: func
GPIO37: func
GPIO38: func
GPIO39: func
GPIO40: input: 0 [ ]
Seems like the pins are already configured to the alternate functions in u-boot, before starting the linux kernel. This means u-boot must be responsible for the pin configuration.
I will continue searching the u-boot sources and yocto u-boot build recipes for the source of this configuration.

nils_z
Posts: 6
Joined: Thu Oct 31, 2019 2:58 pm

Re: Disabling SDIO on GPIO 34-39 in yocto build

Fri Nov 08, 2019 8:18 pm

U-Boot seems to miss a configuration for the cm3 and uses the config for the rpi 3b where the wifi module is connected via sdio to gpio34-39. I could not discover how to leave these pins unconfigured (like it should be for the cm3), but I found a way to change them to gpio22-27, which is ok for my special case.

I leave this here for anyone coming back later with a similar problem: https://github.com/agherzan/meta-raspbe ... -551112006

Thank you PhilE for your valuable input, thanks to your help I knew that U-Boot was responsible for these gpios!

Return to “Device Tree”