From nobody Mon Feb 9 21:00:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+52410+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+52410+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1576757735; cv=none; d=zohomail.com; s=zohoarc; b=WCMLRUXy4tdf0s9XWA35W+Ewvx+jsh0Xcpk55fo6nLtCqlM4CKXLCD3C/v0z2yq9UT3xFZ952x6cHwiOq+d1sFPNcaJiizu7VTcDB9UNIKpMzrYGnXv2CyXixxLsUrOrVlrMlP7uR32P8Icqeqa/gErk6Oz79tzbo9KZtni66Kk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576757735; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=OScA38OCcIPazVxmg1BdtCpPGAdZBE/TtXYyVqIQCcU=; b=LPNkAd+4YG5YjasZRyLYk6FfwuXVe108UfkkavJel94VApPehVnrRpncSKP6wyM+lXmF9TOv45cCNqbKRy6uFF3kxRexmY7lRYusu7JENwd+j4H//pKjVowgjvHwfJ1DNfpxWP7Fho/T8U1tXsusEKoMVlaN/FNNHMCfhp6mlpc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+52410+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1576757735452471.1205267366081; Thu, 19 Dec 2019 04:15:35 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id fhNkYY1788612xJ9mxpfJGBq; Thu, 19 Dec 2019 04:15:34 -0800 X-Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by mx.groups.io with SMTP id smtpd.web11.8711.1576757695652306530 for ; Thu, 19 Dec 2019 04:14:56 -0800 X-Received: by mail-wr1-f65.google.com with SMTP id c9so5743166wrw.8 for ; Thu, 19 Dec 2019 04:14:55 -0800 (PST) X-Gm-Message-State: Cn6KSDcqbupKOPtfonM3fRPWx1787277AA= X-Google-Smtp-Source: APXvYqz9KUMT7V2e9/imPaWXmf8Ngr6a7l3OmXZxdtt0VbYE2aAsBqgYGD3X+84idRVpWIz2q3hB1g== X-Received: by 2002:adf:82f3:: with SMTP id 106mr9384945wrc.69.1576757693804; Thu, 19 Dec 2019 04:14:53 -0800 (PST) X-Received: from localhost.localdomain ([84.203.77.210]) by smtp.gmail.com with ESMTPSA id u8sm5823147wmm.15.2019.12.19.04.14.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Dec 2019 04:14:53 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com Subject: [edk2-devel] [edk2-platforms][PATCH v2 5/7] Platform/RPi4: Add switch to select between PL011 and miniUART Date: Thu, 19 Dec 2019 12:14:32 +0000 Message-Id: <20191219121434.2856-6-pete@akeo.ie> In-Reply-To: <20191219121434.2856-1-pete@akeo.ie> References: <20191219121434.2856-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1576757734; bh=x0zh4eqS4syCPkznp5KRa+Vj6lQfv2oT/FjkHkkQBaQ=; h=Cc:Date:From:Reply-To:Subject:To; b=ZDyC6TDJApxJoBIy5ne6LJZNh/IrIuYndgy+CCriNSXGXz5u9K7wp7IPGVcnvOhiPyv CaJ443KUxBBqs/ct9h3sfDmPwflIk30bwCE2f/ZP+rBU7nDpYwySPS11+7ABCkWOs64Iv YXwYjWl/+sQt9WS6AArdwFgqbpwuFg6aEO0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The PL011 can be a better choice for the serial console on the RPi4, given that its baud clock is not derived from the CPU clock (which may change under our feet unless we keep it fixed at a low rate), and given the fact that the SBSA/SBBR specs that describe ARM specific architectural requirements for ACPI only permit PL011 based UARTs to begin with. Therefore we add a new PL011_ENABLE build switch to tell the firmware to use PL011 for all console serial I/O, including for TF-A, SPCR and DBG2, as well as toggle the BlueTooth module to use the mini UART. For the time being, the option is disabled by default because it requires an overlay to be enabled in config.txt that pinmuxes the PL011 TX/RX lines to the UART pins on the connector block. Signed-off-by: Pete Batard --- Platform/RaspberryPi/RPi4/AcpiTables/Dbg2.aslc | 7 ++++ Platform/RaspberryPi/RPi4/AcpiTables/Spcr.aslc | 11 ++++- Platform/RaspberryPi/RPi4/AcpiTables/Uart.asl | 6 ++- Platform/RaspberryPi/RPi4/RPi4.dsc | 23 +++++++++++ Platform/RaspberryPi/RPi4/RPi4.fdf | 4 ++ Platform/RaspberryPi/RPi4/Readme.md | 43 ++++++++++++++++---- 6 files changed, 82 insertions(+), 12 deletions(-) diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Dbg2.aslc b/Platform/Rasp= berryPi/RPi4/AcpiTables/Dbg2.aslc index b71a149c0c0e..dcad8e205596 100644 --- a/Platform/RaspberryPi/RPi4/AcpiTables/Dbg2.aslc +++ b/Platform/RaspberryPi/RPi4/AcpiTables/Dbg2.aslc @@ -23,6 +23,12 @@ #define RPI_DBG2_NUMBER_OF_GENERIC_ADDRESS_REGISTERS 1 #define RPI_DBG2_NAMESPACESTRING_FIELD_SIZE 10 =20 +#ifdef PL011_ENABLE +#define RPI_UART_INTERFACE_TYPE EFI_ACPI_DBG2_PORT= _SUBTYPE_SERIAL_ARM_PL011_UART +#define RPI_UART_BASE_ADDRESS BCM2836_PL011_UART= _BASE_ADDRESS +#define RPI_UART_LENGTH BCM2836_PL011_UART= _LENGTH +#define RPI_UART_STR { '\\', '_', 'S', = 'B', '.', 'U', 'R', 'T', '0', 0x00 } +#else #define RPI_UART_INTERFACE_TYPE EFI_ACPI_DBG2_PORT= _SUBTYPE_SERIAL_BCM2835_UART #define RPI_UART_BASE_ADDRESS BCM2836_MINI_UART_= BASE_ADDRESS #define RPI_UART_LENGTH BCM2836_MINI_UART_= LENGTH @@ -30,6 +36,7 @@ // RPI_UART_STR should match the value used Uart.asl // #define RPI_UART_STR { '\\', '_', 'S', = 'B', '.', 'U', 'R', 'T', 'M', 0x00 } +#endif =20 typedef struct { EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT Dbg2Device; diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Spcr.aslc b/Platform/Rasp= berryPi/RPi4/AcpiTables/Spcr.aslc index 9931aad8f073..cb17fbe0ff2f 100644 --- a/Platform/RaspberryPi/RPi4/AcpiTables/Spcr.aslc +++ b/Platform/RaspberryPi/RPi4/AcpiTables/Spcr.aslc @@ -17,9 +17,16 @@ #include "AcpiTables.h" =20 #define RPI_UART_FLOW_CONTROL_NONE 0 + +#ifdef PL011_ENABLE +#define RPI_UART_INTERFACE_TYPE EFI_ACPI_SERIAL_PORT_CONSOLE_= REDIRECTION_TABLE_INTERFACE_TYPE_ARM_PL011_UART +#define RPI_UART_BASE_ADDRESS BCM2836_PL011_UART_BASE_ADDRE= SS +#define RPI_UART_INTERRUPT BCM2836_PL011_UART_INTERRUPT +#else +#define RPI_UART_INTERFACE_TYPE EFI_ACPI_SERIAL_PORT_CONSOLE_= REDIRECTION_TABLE_INTERFACE_TYPE_BCM2835_UART #define RPI_UART_BASE_ADDRESS BCM2836_MINI_UART_BASE_ADDRESS #define RPI_UART_INTERRUPT BCM2836_MINI_UART_INTERRUPT - +#endif STATIC EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE Spcr =3D { ACPI_HEADER ( EFI_ACPI_5_1_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE, @@ -27,7 +34,7 @@ STATIC EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE Spc= r =3D { EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION ), // UINT8 InterfaceType; - EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERFACE_TYPE_BCM2835_UA= RT, + RPI_UART_INTERFACE_TYPE, // UINT8 Reserved1[3]; { EFI_ACPI_RESERVED_BYTE, diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Uart.asl b/Platform/Raspb= erryPi/RPi4/AcpiTables/Uart.asl index 15149892f3b0..5b59f2dd3e16 100644 --- a/Platform/RaspberryPi/RPi4/AcpiTables/Uart.asl +++ b/Platform/RaspberryPi/RPi4/AcpiTables/Uart.asl @@ -108,7 +108,7 @@ Device(BTH0) { Name (RBUF, ResourceTemplate () { - // BT UART: UART0 (PL011) + // BT UART: URT0 (PL011) or URTM (miniUART) UARTSerialBus( 115200, // InitialBaudRate: in BPS , // BitsPerByte: default to 8 bits @@ -133,7 +133,11 @@ Device(BTH0) // no flow control. 16, // ReceiveBufferSize 16, // TransmitBufferSize +#ifdef PL011_ENABLE + "\\_SB.URTM", // ResourceSource: +#else "\\_SB.URT0", // ResourceSource: +#endif // UART bus controller name , // ResourceSourceIndex: assumed to be 0 , // ResourceUsage: assumed to be diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index 1624ebda27d7..ccf5bd5b9ef3 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -38,6 +38,7 @@ [Defines] DEFINE SECURE_BOOT_ENABLE =3D FALSE DEFINE INCLUDE_TFTP_COMMAND =3D FALSE DEFINE DEBUG_PRINT_ERROR_LEVEL =3D 0x8000004F + DEFINE PL011_ENABLE =3D FALSE =20 ##########################################################################= ###### # @@ -116,10 +117,16 @@ [LibraryClasses.common] ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/Ar= mGenericTimerPhyCounterLib.inf =20 +!if $(PL011_ENABLE) =3D=3D TRUE + PL011UartClockLib|ArmPlatformPkg/Library/PL011UartClockLib/PL011UartCloc= kLib.inf + PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf + SerialPortLib|ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortL= ib.inf +!else PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatfor= mHookLibNull.inf SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPort= Lib16550.inf +!endif =20 # Cryptographic libraries IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf @@ -229,6 +236,12 @@ [BuildOptions] GCC:*_*_AARCH64_DLINK_FLAGS =3D -Wl,--fix-cortex-a53-843419 GCC:RELEASE_*_*_CC_FLAGS =3D -DMDEPKG_NDEBUG -DNDEBUG =20 +!if $(PL011_ENABLE) =3D=3D TRUE + GCC:*_*_*_CC_FLAGS =3D -DPL011_ENABLE + GCC:*_*_*_ASLPP_FLAGS =3D -DPL011_ENABLE + GCC:*_*_*_ASLCC_FLAGS =3D -DPL011_ENABLE +!endif + [BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] GCC:*_*_AARCH64_DLINK_FLAGS =3D -z common-page-size=3D0x10000 =20 @@ -391,6 +404,13 @@ [PcdsFixedAtBuild.common] gBcm27xxTokenSpaceGuid.PcdBcm27xxPciBusMmioLen|0x3ffffff gBcm27xxTokenSpaceGuid.PcdBcm27xxPciCpuMmioAdr|0x600000000 =20 +!if $(PL011_ENABLE) =3D=3D TRUE + ## PL011 UART + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0xfe201000 + gArmPlatformTokenSpaceGuid.PL011UartInteger|0 + gArmPlatformTokenSpaceGuid.PL011UartFractional|0 + gArmPlatformTokenSpaceGuid.PL011UartClkInHz|48000000 +!else ## NS16550 compatible UART gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0xfe215040 gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE @@ -398,7 +418,10 @@ [PcdsFixedAtBuild.common] gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|500000000 gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|0x27 gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|8 +!endif + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200 + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultReceiveFifoDepth|0 =20 # # ARM General Interrupt Controller diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf b/Platform/RaspberryPi/RPi4= /RPi4.fdf index 7a506bd2813b..50fe554ec9ec 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.fdf +++ b/Platform/RaspberryPi/RPi4/RPi4.fdf @@ -51,7 +51,11 @@ [FD.RPI_EFI] # ATF primary boot image # 0x00000000|0x00020000 +!if $(PL011_ENABLE) =3D=3D TRUE +FILE =3D Platform/RaspberryPi/$(PLATFORM_NAME)/TrustedFirmware/bl31_pl011.= bin +!else FILE =3D Platform/RaspberryPi/$(PLATFORM_NAME)/TrustedFirmware/bl31_miniua= rt.bin +!endif =20 # # DTB. diff --git a/Platform/RaspberryPi/RPi4/Readme.md b/Platform/RaspberryPi/RPi= 4/Readme.md index 2e37646e043d..acfbfee185b0 100644 --- a/Platform/RaspberryPi/RPi4/Readme.md +++ b/Platform/RaspberryPi/RPi4/Readme.md @@ -18,13 +18,21 @@ following __major__ limitations: =20 - USB is likely to work only in pre-OS phase at this stage (nonstandard EC= AM, missing ACPI tables). -- Serial I/O from the OS may not work at all due to CPU throttling affecti= ng - the miniUART baudrate. +- Serial I/O from the OS may not work due to CPU throttling affecting the + miniUART baudrate. This can be worked around by using the `PL011_ENABLE` + compilation option. =20 # Building =20 Build instructions from the top level edk2-platforms Readme.md apply. =20 +The following additional build options are also available: +- `-D PL011_ENABLE=3D1`: Selects PL011 for the serial console instead of t= he + miniUART (default). This doesn't change the GPIO pinout for the UART but + can be useful if you find that the miniUART baud rate changes when the + OS throttles the CPU. Note that this requires one of `disable-bt.dtbo` or + `miniuart-bt.dtbo` overlays to have been applied (see below). + # Booting the firmware =20 1. Format a uSD card as FAT16 or FAT32 @@ -33,14 +41,31 @@ Build instructions from the top level edk2-platforms Re= adme.md apply. - `bcm2711-rpi-4-b.dtb` - `fixup4.dat` - `start4.elf` + - `overlays/miniuart-bt.dbto` or `overlays/disable-bt.dtbo` (Optional) 4. Create a `config.txt` with the following content: - ``` - arm_64bit=3D1 - enable_uart=3D1 - core_freq=3D250 - enable_gic=3D1 - armstub=3DRPI_EFI.fd - ``` + - For a firmware **without** the `PL011_ENABLE` build option: + ``` + arm_64bit=3D1 + enable_uart=3D1 + core_freq=3D250 + enable_gic=3D1 + armstub=3DRPI_EFI.fd + disable_commandline_tags=3D1 + ``` + - For a firmware **with** the `PL011_ENABLE` build option: + ``` + arm_64bit=3D1 + enable_gic=3D1 + armstub=3DRPI_EFI.fd + disable_commandline_tags=3D1 + device_tree_address=3D0x20000 + device_tree_end=3D0x30000 + device_tree=3Dbcm2711-rpi-4-b.dtb + dtoverlay=3Dminiuart-bt + ``` + The above also requires `miniuart-bt.dbto` to have been copied into an= `overlays/` + directory on the uSD card. Alternatively, you may use `disable-bt` ins= tead of + `miniuart-bt` if you don't require BlueTooth. 5. Insert the uSD card and power up the Pi. =20 # Notes --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#52410): https://edk2.groups.io/g/devel/message/52410 Mute This Topic: https://groups.io/mt/68829927/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-