在带有 DAS U-Boot 的 Raspberry Pi 计算模块上使用 GPIO-Poweroff 关闭 PSU

Using GPIO-Poweroff on a Raspberry Pi Compute Module with DAS U-Boot to turn off the PSU

我一直在尝试让 GPIO-Poweroff 使用 GPIO 关闭板 PSU,但无论我尝试什么,它似乎都没有用。如果我手动切换 GPIO 引脚,设备会立即关闭。如果我盘点 Raspbian-Lite 并将以下行添加到 config.txt 它会起作用。但是U-Boot似乎忽略了它。我正在使用 Raspbian Lite 2017-07-5 和最新的主线 U-Boot:git://git.denx.de/u-boot.git 使用 rpi_defconfig.

dtoverlay=gpio-poweroff,gpiopin=6,active_low=1

使用 U-Boot,Raspberry Pi 可以正常启动和工作,它甚至会关闭但不会切换 GPIO6。这会留下 PSU 运行,修复它的唯一方法是按住电源按钮至少 5 秒钟。我知道 dt-blob.bin 已加载并应用,因为板上有一个只能与正确的 dt-blob.bin.

配合使用的相机

至此我没有主意了。我试过:

我尝试的所有方法似乎都不起作用,而且我不确定下一步该怎么做。

供参考,以下是一些正在使用的文件:

boot.cmd:

#Setting default bootargs
setenv original_bootargs console=ttyS0 console=tty1 rootfstype=ext4 fsck.repair=yes hdmi.audio=0 disp.screen0_output_mode=1920x1080p60:1280x720p60:800x600p60:EDID rootwait panic=10 # console MUST be ttyS0 or it WILL NOT BOOT!

# Identify if we are using partition 2 or 3
if fatload mmc 0:1 ${loadaddr} swap; then echo "Using Partition 3"; setenv partition 3; else echo "Using Partition 2"; setenv partition 2; fi

# Check for recovery
if fatload mmc 0:1 ${loadaddr} recovery; then echo "Using Recovery Partition"; setenv partition 4; fi
#if gpio input 32 || fatload mmc 0:1 ${loadaddr} recovery; then echo "Using Recovery Partition"; setenv partition 4; fi

# Create an empty file to detect boot failures
fatwrite mmc 0:1 ${kernel_addr_r} recovery 0

# Set bootargs
setenv bootargs "${original_bootargs} root=/dev/mmcblk0p${partition}"

# Load the existing Linux kernel into RAM
echo Loading partition ${partition}
ext4load mmc 0:${partition} ${kernel_addr_r} kernel.img
# Boot the kernel we have just loaded
bootz ${kernel_addr_r} - ${fdt_addr}

不知道为什么,但它以低分辨率启动,红色和蓝色互换。使用 mkimage -A arm -O linux -T script -C none -a 0x00000000 -e 0x00000000 -n "Boot Script" -d boot.cmd boot.scr

编译

config.txt:

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on

gpu_mem=128

start_x=1

dtoverlay=gpio-poweroff,gpiopin=6,active_low=1

dtdebug=1

因此,我通过编译我自己的 bcm27***.dtb 文件并在其原始内容后连接以下内容来修复它:

/ {
    compatible = "brcm,bcm2709";

   power_ctrl: power_ctrl {
       compatible = "gpio-poweroff";
       gpios = <&gpio 6 1>;
   };
};

然而,这已经彻底破坏了GPIO和i2c。所以这不是一个完整的解决方案。我的下一步是恢复原始文件,并尝试将其添加到 dt-blob.bin

的末尾

我做到了,这是答案:

# Manually apply overlay
setenv fdt_length 50000
setexpr kernel_addr_r ${fdt_addr} + ${fdt_length}
fdt addr ${fdt_addr} # Load the existing tree
fdt boardsetup # Device specific setup
fdt move ${fdt_addr} ${fdt_addr} ${fdt_length} # Resize the loaded fdt to ${fdt_length}
fatload mmc 0:1 ${kernel_addr_r} overlays/gpio-poweroff.dtbo
fdt apply ${kernel_addr_r} # Apply the overlay

编辑默认设备树和 dt-blob.bin 以徒劳而告终。您需要做的是在 uboot.src.

内手动应用叠加层

第一步是找到所需overlay的源代码,并将默认值更改为您想要的值,您不能在U-Boot中使用overlay参数。

在应用覆盖之前,您需要使用 fdt move 增加加载的设备树的大小,然后您可以从 fat 加载和应用。如果您想应用更多叠加层,您只需添加额外的行,例如:

fatload mmc 0:1 ${kernel_addr_r} overlays/rpi-tv.dtbo
fdt apply ${kernel_addr_r} # Apply the overlay

请注意,您的设备树不会 运行 超出 space!