4

I'm trying to use a Raspberry Pi with a UART peripheral and a non-Raspbian Linux distribution. It seems like most of these distributions use U-Boot. I'm running into two problems:

  1. U-Boot outputs on the serial console by default, which confuses the peripheral (it mistakes the logging messages as input)
  2. My peripheral tries to respond to these messages, which interrupts the U-Boot loader and prevents the kernel from booting

It seems like the possible solutions to this problem are:

  1. Disable the serial console/UART in U-Boot
  2. Boot the kernel directly (i.e. remove U-Boot from the boot process)

I've done a lot of searching, and it doesn't seem like there's a way to disable the U-Boot serial console output at runtime (i.e. without patching and recompiling U-Boot). I'm sure I could figure out how to have the Pi bootloader load the Linux kernel directly (like Raspbian does), but that seems like it might break with kernel updates.

I'm trying to investigate a third option: is it possible to have the UART disabled at boot time and enable it from the operating system instead? Failing that, are there any other workarounds to prevent U-Boot from using the serial console, or should I give up and use Raspbian?

squircle
  • 143
  • 1
  • 5

2 Answers2

5

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. I know links only answers are frowned upon, so here' s a 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. 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 --depth 1 git://git.denx.de/u-boot.git

cd u-boot

Find the raspberry pi config files - they depend on the model, configs/rpi_3_defconfig for Raspberry Pi 3, configs/rpi_4_defconfig for Raspberry Pi 4, and so on. 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. 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. One more little thing left, set silent boot environmental variable. Change include/configs/rpi.h file

#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
# or 
make rpi_4_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 (e.g. to /boot/firmware/uboot_rpi_4.bin for a Raspberry Pi 4). Now your Raspberry Pi will not be disturbed by any messages on UART during boot. The UART functionality after boot will not be affected.

UPDATE 10/06/2024

currently u-boot has migrate to the text-based environment. https://docs.u-boot.org/en/latest/usage/environment.html#text-based-environment

below is my patch for disabling UART console for rpi-4

From 3ced0f1608d6ded3d8474ea4a98aec00ae67fe9e Mon Sep 17 00:00:00 2001
From: Maulik Patel <maulikp163@gmail.com>
Date: Mon, 10 Jun 2024 18:32:25 +0530
Subject: [PATCH] disable uart for u-boot

board/raspberrypi/rpi/rpi.env | 2 ++ configs/rpi_4_defconfig | 5 +++++ 2 files changed, 7 insertions(+)

diff --git a/board/raspberrypi/rpi/rpi.env b/board/raspberrypi/rpi/rpi.env index 30228285ed..44a427512c 100644 --- a/board/raspberrypi/rpi/rpi.env +++ b/board/raspberrypi/rpi/rpi.env @@ -3,6 +3,8 @@ /* environment for Raspberry Pi boards */

dhcpuboot=usb start; dhcp u-boot.uimg; bootm +bootdelay=-2 +silent=1

/* Environment */ stdin=serial,usbkbd diff --git a/configs/rpi_4_defconfig b/configs/rpi_4_defconfig index 2541b83a3d..a5dc879d6a 100644 --- a/configs/rpi_4_defconfig +++ b/configs/rpi_4_defconfig @@ -65,3 +65,8 @@ CONFIG_SYS_WHITE_ON_BLACK=y CONFIG_VIDEO_BCM2835=y CONFIG_CONSOLE_SCROLL_LINES=10 CONFIG_PHYS_TO_BUS=y +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

you can apply this patch as recipe or manually modify both files to add changes.

Relevant docs:

WintermuteAI
  • 76
  • 1
  • 4
0

If you are using nixos on the pi you must also apply the patch https://github.com/NixOS/nixpkgs/blob/master/pkgs/misc/uboot/0001-configs-rpi-allow-for-bigger-kernels.patch Otherwise you get a memory error.

git clone https://github.com/u-boot/u-boot/

cd u-boot

git checkout v2023.07

then follow the original instructions.

Dave
  • 1
  • 1