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



我一直在尝试让 GPIO-Poweroff 使用 GPIO 关闭主板 PSU,但无论我尝试什么,它似乎都不起作用。如果我手动切换 GPIO 引脚,设备会立即关闭。如果我盘点 Raspbian-Lite 并将以下行添加到配置中.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。

在这一点上,我失去了想法。我试过:

  • 使用 rpi-update 更新 Linux 内核
  • 反编译 gpio-poweroff.dtbo 和 dt-blob.bin。在 gpio -poweroff.dtbo 中将0x1a更改为 0x06,0x0更改为0x1,将它们连接在一起,它不起作用。
  • 手动执行上述操作并将反编译代码交织在一起。
  • 使用fdt addr,并在 boot.scr 中fdt apply手动应用它,这不起作用,因为fdt_overlay_apply FDT_ERR_NOSPACE和我似乎无法解决这个问题。
  • 克隆Linux并尝试制作dtsb,目标不存在。
  • 克隆 linux/arch/arm/boot/dts,编写 MakeFile 并使用我的更改编译它们会导致 U-Boot 加载、Raspbian 加载但 gpio-poweroff 不起作用。
  • 其他几乎不值得一提的尝试。

尝试的似乎都不起作用,我不确定该往哪里前进。

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

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编译

配置.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中手动应用覆盖层。

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

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

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

请注意您的设备树不会耗尽空间!

最新更新