简体   繁体   English

如何在 u-boot 中禁用串行控制台(非内核)

[英]How to disable serial console(non-kernel) in u-boot

I am building a Yocto image for Intel Edison.我正在为 Intel Edison 构建 Yocto 图像。

One of the image's components is u-boot with an Edison-specific patch.图像的组件之一是带有 Edison 特定补丁的 u-boot。 By default, Edison's UART port is used for u-boot console.默认情况下,Edison 的 UART 端口用于 u-boot 控制台。 I want to disable this feature, but only on the serial interface(u-boot also listens on USB and that needs to stay).我想禁用此功能,但仅限于串行接口(u-boot 还侦听 USB 并且需要保留)。

My main concern is the " Press any key to stop autoboot " feature on the UART port.我主要关心的是 UART 端口上的“按任意键停止自动引导”功能。 I need this port to connect an accessory that might send something during the boot process of the main device.我需要这个端口来连接一个配件,这个配件可能会在主设备的启动过程中发送一些东西。

How do I approach this problem?我该如何解决这个问题? Is there an environment variable for this, or do I need to modify the sources?是否有用于此的环境变量,或者我是否需要修改源代码?

Thanks in advance!提前致谢!

I'm getting back to this issue almost a year later, now I've managed to find a proper solution.差不多一年后我又回到了这个问题,现在我已经设法找到了一个合适的解决方案。

The board I was working on had a reasonably new u-boot in its BSP .我正在开发的主板在其BSP 中有一个相当新的u-boot To disable the serial console I had to do the following:要禁用串行控制台,我必须执行以下操作:

  • Add the following defines to the board's config header(located in include/configs/board.h ):将以下定义添加到板的配置标头(位于include/configs/board.h ):

     #define CONFIG_DISABLE_CONSOLE #define CONFIG_SILENT_CONSOLE #define CONFIG_SYS_DEVICE_NULLDEV
  • Check if your board has early_init_f enabled in the same file:检查您的开发板是否在同一文件中启用了early_init_f

     #define CONFIG_BOARD_EARLY_INIT_F 1
  • Find the arch file(Something like arch/x86/cpu/architecture/architecture.c ) and add this call to its early_init_f function.找到 arch 文件(类似于arch/x86/cpu/architecture/architecture.c )并将此调用添加到它的early_init_f函数中。 It actually modifies board's global data variable to have these flags:它实际上修改了板的全局数据变量以具有这些标志:

     gd->flags |= (GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE);
  • My board did not have one, so I had to add the whole function我的板子没有,所以我不得不添加整个功能

     int board_early_init_f(void) { gd->flags |= (GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE); return 0; }

Example: If you are looking for board_early_init_f of Orange Pi 4B it is in /build/cache/sources/u-boot/v2020.10/board/rockchip/evb_rk3399/evb-rk3399.c示例:如果您正在寻找 Orange Pi 4B 的 board_early_init_f,它位于 /build/cache/sources/u-boot/v2020.10/board/rockchip/evb_rk3399/evb-rk3399.c

That's it.就是这样。 Hope this helps someone else!希望这对其他人有帮助!


see also看到

There's no way to do this, without modifying the source (configuration) of U-Boot.如果不修改 U-Boot 的源(配置),就没有办法做到这一点。

To disable the serial console in U-Boot, you need to reconfigure U-Boot.要在 U-Boot 中禁用串行控制台,您需要重新配置 U-Boot。 The documentation from the master branch of U-Boot: Readme.silent U-Boot master 分支的文档: Readme.silent

According to that one, you need to set:根据那个,你需要设置:

CONFIG_SILENT_CONSOLE
CONFIG_SILENT_CONSOLE_UPDATE_ON_SET
CONFIG_SYS_DEVICE_NULLDEV

CONFIG_SILENT_U_BOOT_ONLY is also needed if you want only U-Boot to be silent.如果您只想让 U-Boot 保持静音,还需要CONFIG_SILENT_U_BOOT_ONLY

You might also need to test with CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC and possibly adding silent 1 to CONFIG_EXTRA_ENV_SETTINGS .您可能还需要使用CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC进行测试,并且可能需要向CONFIG_EXTRA_ENV_SETTINGS添加silent 1

== UPDATE == == 更新 ==

See the following options for a possible workaround:有关可能的解决方法,请参阅以下选项:

CONFIG_ZERO_BOOTDELAY_CHECK
CONFIG_AUTOBOOT_KEYED
CONFIG_AUTOBOOT_KEYED_CTRLC
CONFIG_AUTOBOOT_PROMPT
CONFIG_AUTOBOOT_DELAY_STR
CONFIG_AUTOBOOT_STOP_STR

These options will at least give you a way of requiring a magic string to stop the boot.这些选项至少会为您提供一种需要魔法字符串来停止启动的方法。 It might be enough to help you.这可能足以帮助您。 See README.autoboot参见README.autoboot

Setting the u-boot environment variable bootdelay to -2 disables the ability for the UART to interrupt the boot process on U-Boot 2017.01 release.将 u-boot 环境变量bootdelay-2会禁用 UART 在 U-Boot 2017.01版本上中断启动过程的能力。 It appears that -1 is a special case.看来-1是一个特例。

See common/autoboot.c from your U-Boot source tree for details. 有关详细信息, 请参阅 U-Boot 源代码树中的common/autoboot.c About U-Boot Environment Variables关于U-Boot 环境变量

As told by Kyle you can set the bootdelay u-boot environment variable to -2.正如 Kyle 所说,您可以将 bootdelay u-boot 环境变量设置为 -2。 This can even be done from a booted system using the fw_setenv utility.这甚至可以使用fw_setenv实用程序从引导系统完成。 On my mender raspberry pi image this utility was preinstalled.在我的 mender raspberry pi 映像上预安装了此实用程序。

Using sudo fw_printenv bootdelay showed it was set to 2, i set it to -2 with sudo fw_setenv bootdelay -- -2 (note the -- before the value, so -2 is interpreted as the value, not an option).使用sudo fw_printenv bootdelay显示它已设置为 2,我使用sudo fw_setenv bootdelay -- -2 (注意值之前的-- ,因此-2被解释为值,而不是选项)。

In my case it was a similar issue than the OP, with a LoraWAN node on a raspberry pi connected over the serial port that interrupted the boot.在我的例子中,这是一个与 OP 类似的问题,树莓派上的 LoraWAN 节点通过中断启动的串行端口连接。

So所以

  • remove the serial device causing issue删除导致问题的串行设备
  • set bootdelay either from the booted system or from the bootloader从引导系统或引导加载程序设置引导延迟
  • shutdown and add the serial device back关闭并重新添加串行设备

Here is the video where it is explained step by step how to prevent U-boot console from interrupting autoboot and sending debug messages on UART on Raspberry Pi - it should work similarly for other boards, provided they use U-boot.这是逐步解释如何防止 U-boot 控制台中断自动引导并在 Raspberry Pi 上的 UART 上发送调试消息的视频 - 如果其他板使用 U-boot,它应该可以类似地工作。 You will however need to find the right config files for your board in u-boot source folder.但是,您需要在 u-boot 源文件夹中为您的开发板找到正确的配置文件。 I know links only answers are frowned upon, so here' sa quick breakdown of a solution:我知道只有链接的答案不受欢迎,所以这里有一个解决方案的快速分解:

Install the dependencies安装依赖项

sudo apt install git make gcc gcc-aarch64-linux-gnu

Git clone the official u-boot repository. Git 克隆官方 u-boot 存储库。 Alternatively you can git clone my fork of repository , where I already have the necessary changes for silent autoboot - but if you need the latest version, then you need to clone the official repository and make changes yourself.或者,您可以 git clone my fork of repository ,我已经对静默自动启动进行了必要的更改 - 但是如果您需要最新版本,那么您需要克隆官方存储库并自己进行更改。

git clone --depth 1 git://git.denx.de/u-boot.git

cd u-boot

Find your board config files - they depend on the model, eg rpi_3_defconfig for Raspberry Pi 3, rpi_4_defconfig for Raspberry Pi 4 and so on.找到您的电路板配置文件 - 它们取决于型号,例如 rpi_3_defconfig 用于 Raspberry Pi 3,rpi_4_defconfig 用于 Raspberry Pi 4 等等。 Add the following lines to the end of the file将以下行添加到文件末尾

CONFIG_BOOTDELAY=-2
CONFIG_SILENT_CONSOLE=y
CONFIG_SYS_DEVICE_NULLDEV=y
CONFIG_SILENT_CONSOLE_UPDATE_ON_SET=y
CONFIG_SILENT_U_BOOT_ONLY=y

The first line removes the boot delay, so autoboot will not be interrupted by messages sent on UART interface.第一行消除了启动延迟,因此自动启动不会被 UART 接口上发送的消息中断。 Next four lines enable silent boot, so U-boot will not send any messages on UART itself, because the messages might in turn confuse your device.接下来的四行启用静默启动,因此 U-boot 不会在 UART 本身上发送任何消息,因为这些消息可能会反过来混淆您的设备。 One more little thing left, set silent boot environmental variable.还有一件小事,设置静默启动环境变量。 Change the header file for your board (ro raspberry pi it is include/configs/rpi.h ):更改板子的头文件(ro raspberry pi 它是 include/configs/rpi.h ):

#define CONFIG_EXTRA_ENV_SETTINGS \
    "dhcpuboot=usb start; dhcp u-boot.uimg; bootm\0" \
    "silent=1\0" \
    ENV_DEVICE_SETTINGS \
    ENV_DFU_SETTINGS \
    ENV_MEM_LAYOUT_SETTINGS \
    BOOTENV

Now configure with现在配置

make rpi_3_defconfig

from repository main folder And build with从存储库主文件夹并构建

make CROSS_COMPILE=aarch64-linux-gnu-

When build process finishes you will have a u-boot.bin file, which you need to rename and copy to Raspberry Pi SD card.构建过程完成后,您将拥有一个 u-boot.bin 文件,您需要将其重命名并复制到 Raspberry Pi SD 卡。 Now you Raspberry Pi will not be disturbed by any messages on UART during boot.现在,您的 Raspberry Pi 在启动期间不会受到 UART 上的任何消息的干扰。 The UART functionality after boot will not be affected.启动后的 UART 功能不会受到影响。

Relevant docs: https://gitlab.denx.de/u-boot/u-boot/blob/HEAD/doc/README.autoboot https://gitlab.denx.de/u-boot/u-boot/blob/HEAD/doc/README.silent https://wiki.ubuntu.com/ARM/RaspberryPi相关文档: https : //gitlab.denx.de/u-boot/u-boot/blob/HEAD/doc/README.autoboot https://gitlab.denx.de/u-boot/u-boot/blob/ HEAD/doc/README.silent https://wiki.ubuntu.com/ARM/RaspberryPi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM