如何更改Raspberry Pi 3 Model B+上U-boot使用的SD卡控制器?

huangapple go评论49阅读模式
英文:

How do I change the SD card controller that's used by U-boot for the Raspberry Pi 3 Model B+?

问题

树莓派3 Model B+具有两个SD卡控制器。

有一个名为sdhost的自定义控制器,如设备树节点所示:

/* SDHOST用于驱动SD卡 */
&sdhost {
	pinctrl-names = "default";
	pinctrl-0 = <&sdhost_gpio48>;
	status = "okay";
	bus-width = <4>;
};

以及一个符合SDHCI标准的控制器,如以下设备树节点所示:

/* SDHCI用于控制无线SDIO */
&amp;sdhci {
	#address-cells = <1>;
	#size-cells = <0>;
	pinctrl-names = "default";
	pinctrl-0 = <&emmc_gpio34>;
	status = "okay";
	bus-width = <4>;
	non-removable;
	mmc-pwrseq = <&wifi_pwrseq>;

	brcmf: wifi@1 {
		reg = <1>;
		compatible = "brcm,bcm4329-fmac";
	};
};

根据U-boot的注释,U-boot使用SDHOST作为SD卡控制器,使用SDHCI作为WiFi控制器。

/* SDHOST用于驱动SD卡 */
...
/* SDHCI用于控制无线SDIO */

我面临的问题是,我无法通过U-boot运行SD卡驱动程序源代码在此),它使用树莓派的SDHCI控制器与SD卡交互。

SD卡驱动程序成功在树莓派的现有引导加载程序中运行,如下所示:

EMMC: GPIO设置完成
EMMC: 复位OK
sd_clk分频器00000068,偏移00000006
EMMC: 发送命令00000000参数00000000
EMMC: 发送命令08020000参数000001AA
EMMC: 发送命令37000000参数00000000
EMMC: 发送命令29020000参数51FF8000
EMMC: CMD_SEND_OP_COND返回电压CCS 0000000040F98000
...

但是,当我尝试通过U-Boot使用go命令运行二进制代码时,代码在SDHCI控制器的初始化阶段卡住了(源代码中的确切行在这里)如下所示:

EMMC: GPIO设置完成
EMMC: 复位OK
sd_clk分频器00000068,偏移00000006
EMMC: 发送命令00000000参数00000000
EMMC: 发送命令08020000参数000001AA
错误:无法发送EMMC命令

我怀疑是因为U-Boot已将SDHCI控制器配置为WiFi(而不是SD卡),所以我无法再将其用作SD卡控制器。但是,我想要使用SDHCI控制器作为SD卡控制器。

如何以最佳方式使我的SD卡二进制代码通过U-boot运行?

唯一的选择是配置/重新编译U-boot以将SDHCI控制器用作主要SD卡控制器(并忘记WiFi)吗?

如果是这样,关于如何进行此操作的一些建议将不胜感激。

或者,是否有一个U-Boot shell命令(类似于某种reset命令),可以为二进制代码提供类似于未经U-Boot修改的裸机环境的运行时环境?

编辑:

到目前为止,这是我的进展。我已经找到了将自定义SDHOST驱动程序排除在外的方法:

  1. 通过将自定义SDHOST驱动程序的DTS文件修改为status = "disabled"而不是status = "okay"来修改DTS文件。
  2. 在U-Boot的configs/rpi_3_b_plus_defconfig文件中添加CONFIG_MMC_BCM2835=n

当我启动U-Boot并运行mmc list时,我只看到SDHCI控制器,这很好:

U-Boot> mmc list
mmc@7e300000: 0

我知道上面是SDHCI控制器,因为它的设备寄存器映射到物理地址7e300000,如下所示:

sdhci: mmc@7e300000 {
	compatible = "brcm,bcm2835-sdhci";
	reg = <0x7e300000 0x100>;
	interrupts = <2 30>;
	clocks = <&clocks BCM2835_CLOCK_EMMC>;
	status = "disabled";
};

但是,如以下引导日志所示,U-Boot仍然无法使用此控制器作为SD卡控制器:

MMC:   mmc@7e300000: 0
Loading Environment from FAT... Card did not respond to voltage select! : -110
** Bad device specification mmc 0 **

以下是整个引导日志:

U-Boot 2023.01-00790-g8c80619653-dirty (Feb 11 2023 - 10:04:49 +1100)

DRAM:  948 MiB
RPI 3 Model B+ (0xa020d3)
Core:  63 devices, 14 uclasses, devicetree: embed
MMC:   mmc@7e300000: 0
Loading Environment from FAT... Card did not respond to voltage select! : -110
** Bad device specification mmc 0 **
In:    serial
Out:   vidconsole
Err:   vidconsole
Net:   No ethernet found.
starting USB...
Bus usb@7e980000: USB DWC2
scanning bus usb@7e980000 for devices... 4 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot:  0
U-Boot> mmc list
mmc@7e300000: 0

我怀疑U-Boot仍

英文:

The Raspberry Pi 3 Model B+ has two SD card controllers.

There is custom controller called sdhost as shown by the device tree node:

/* SDHOST is used to drive the SD card */
&amp;sdhost {
	pinctrl-names = &quot;default&quot;;
	pinctrl-0 = &lt;&amp;sdhost_gpio48&gt;;
	status = &quot;okay&quot;;
	bus-width = &lt;4&gt;;
};

And an SDHCI-compliant controller as shown by the following device tree node:

/* SDHCI is used to control the SDIO for wireless */
&amp;sdhci {
	#address-cells = &lt;1&gt;;
	#size-cells = &lt;0&gt;;
	pinctrl-names = &quot;default&quot;;
	pinctrl-0 = &lt;&amp;emmc_gpio34&gt;;
	status = &quot;okay&quot;;
	bus-width = &lt;4&gt;;
	non-removable;
	mmc-pwrseq = &lt;&amp;wifi_pwrseq&gt;;

	brcmf: wifi@1 {
		reg = &lt;1&gt;;
		compatible = &quot;brcm,bcm4329-fmac&quot;;
	};
};

As referenced by the U-boot comments, U-boot is using SDHOST as the SD card controller and SDHCI as the WiFi controller.

/* SDHOST is used to drive the SD card */
...
/* SDHCI is used to control the SDIO for wireless */

The problem I'm facing is that I'm unable to run this SD card driver (source code here) via U-boot, which uses the Pi's SDHCI controller to interact with SD cards.

The SD card driver runs successfully bare-metal via the Pi's existing bootloader as shown by the output below:

EMMC: GPIO set up
EMMC: reset OK
sd_clk divisor 00000068, shift 00000006
EMMC: Sending command 00000000 arg 00000000
EMMC: Sending command 08020000 arg 000001AA
EMMC: Sending command 37000000 arg 00000000
EMMC: Sending command 29020000 arg 51FF8000
EMMC: CMD_SEND_OP_COND returned VOLTAGE CCS 0000000040F98000
...

However, when I try to run the binary via U-Boot using the go command, the code is stuck during the initialisation phase of the SDHCI controller (exact line in source code here) as shown below:

EMMC: GPIO set up
EMMC: reset OK
sd_clk divisor 00000068, shift 00000006
EMMC: Sending command 00000000 arg 00000000
EMMC: Sending command 08020000 arg 000001AA
ERROR: failed to send EMMC command

My suspicion is that since U-boot has configured the SDHCI controller for Wifi (and not for SD cards), I can no longer use it as an SD card controller. However, I want to use the SDHCI controller as the SD Card controller.

What is the best way to get my SD card binary running via U-boot?

Is the only option to configure/recompile U-boot to use the SDHCI controller as the main SD card controller (and forget about WiFi)?

If so, some pointers on how to go about this would be much appreciated.

Alternatively, is there a U-boot shell command (like some sort of reset command) that give binaries a runtime environment similar to a bare-metal environment that has been un-modified by U-boot?

Edit:

Here is my progress so far. I've figured out how to exclude the custom SDHOST driver from being initialised via two methods:

  1. Modifying the DTS file by replacing status = &quot;okay&quot; with status = &quot;disabled&quot; for the custom SDHOST driver.
  2. Adding CONFIG_MMC_BCM2835=n to U-Boot's configs/rpi_3_b_plus_defconfig file.

When I launch U-boot, and run mmc list, I see only the SDHCI controller, which is great:

U-Boot&gt; mmc list
mmc@7e300000: 0

I know the above is the SDHCI controller because its device registers are mapped to the physical address of 7e300000 as shown in arch/arm/dts/bcm283x.dtsi below:

sdhci: mmc@7e300000 {
	compatible = &quot;brcm,bcm2835-sdhci&quot;;
	reg = &lt;0x7e300000 0x100&gt;;
	interrupts = &lt;2 30&gt;;
	clocks = &lt;&amp;clocks BCM2835_CLOCK_EMMC&gt;;
	status = &quot;disabled&quot;;
};

However, as shown in the following boot logs, U-boot is still not happy to use this controller as the SD card controller:

MMC:   mmc@7e300000: 0
Loading Environment from FAT... Card did not respond to voltage select! : -110
** Bad device specification mmc 0 **

Below is the entire boot log:

U-Boot 2023.01-00790-g8c80619653-dirty (Feb 11 2023 - 10:04:49 +1100)

DRAM:  948 MiB
RPI 3 Model B+ (0xa020d3)
Core:  63 devices, 14 uclasses, devicetree: embed
MMC:   mmc@7e300000: 0
Loading Environment from FAT... Card did not respond to voltage select! : -110
** Bad device specification mmc 0 **
In:    serial
Out:   vidconsole
Err:   vidconsole
Net:   No ethernet found.
starting USB...
Bus usb@7e980000: USB DWC2
scanning bus usb@7e980000 for devices... 4 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot:  0
U-Boot&gt; mmc list
mmc@7e300000: 0

My suspicion is that the SDHCI controller is still being treated by U-Boot as a WiFi controller (I can't tell for sure). What are some troubleshooting steps I can take to figure out what is going on?

答案1

得分: 1

我的解决方案是在位于arch/arm/dts/bcm2837-rpi-3-b-plus.dts中的sdhci 设备树节点 中更改以下行:

pinctrl-0 = &lt;&amp;emmc_gpio34&gt;;

更改为

pinctrl-0 = &lt;&amp;sdhost_gpio48&gt;;

然后,重新编译U-boot并将生成的U-boot二进制文件用作树莓派的引导加载程序。

最终期望的结果是:

  1. U-boot仍然可以在运行时使用sdhost驱动程序和控制器来访问SD卡(这是U-boot的默认首选项)。
  2. 由U-boot运行的二进制文件(通过go命令)还可以操作sdhci控制器的设备寄存器以与SD卡进行交互。

为了提供解决方案的额外背景信息,上面提到的sdhost_gpio48参考位于此DTSI文件,位于arch/arm/dts/bcm283x.dtsi中:

sdhost_gpio48: sdhost_gpio48 {
    brcm,pins = &lt;48 49 50 51 52 53&gt;;
    brcm,function = &lt;BCM2835_FSEL_ALT0&gt;;
};

我们所更改的pinctrl-0参数涉及到“引脚控制”,有关该参数的详细文档可以在此处找到。

根据我的理解,我们的更改指定了与SDHOST控制器相同的GPIO引脚,这些引脚用于SDHCI控制器,这使得在二进制文件运行时可以将SDHCI控制器用作SD卡控制器。

英文:

My solution is to change the following line in the sdhci node of the DT located at arch/arm/dts/bcm2837-rpi-3-b-plus.dts from

pinctrl-0 = &lt;&amp;emmc_gpio34&gt;;

to

pinctrl-0 = &lt;&amp;sdhost_gpio48&gt;;

Then I recompile U-boot and use the resultant U-boot binary as the Pi’s bootloader.

The final and desired result is that:

  1. U-boot can still use the sdhost driver and controller to access the SD card when it is running (which is U-boot’s default preference).
  2. The binary run by U-boot (via the go command) can also manipulate the sdhci controller’s device registers to interact with the SD card.

For additional context around the solution, the sdhost_gpio48 reference above is located in this DTSI file located at arch/arm/dts/bcm283x.dtsi:

sdhost_gpio48: sdhost_gpio48 {
	brcm,pins = &lt;48 49 50 51 52 53&gt;;
	brcm,function = &lt;BCM2835_FSEL_ALT0&gt;;
};

The pinctrl-0 parameter we have changed refers to “Pin Control” and detailed documentation about this parameter can be found here.

From my understanding, our change specifies the same GPIO pins that are being used for the SDHOST controller for the SDHCI controller, which enables us to use the SDHCI controller as an SD card controller when the binary is running.

huangapple
  • 本文由 发表于 2023年2月10日 13:19:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75407246.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定