mbox series

[v5,0/4] Add minimal boot support for Raspberry Pi 5

Message ID cover.1717061147.git.andrea.porta@suse.com
Headers show
Series Add minimal boot support for Raspberry Pi 5 | expand

Message

Andrea della Porta May 30, 2024, 10:11 a.m. UTC
Hi,

This patchset adds minimal support for the Broadcom BCM2712 SoC and for
the on-board SDHCI controller on Broadcom BCM2712 in order to make it
possible to boot (particularly) a Raspberry Pi 5 from SD card and get a
console through uart.
Changes to arm64/defconfig are not needed since the actual options work
as they are.
This work is heavily based on downstream contributions.

Tested on Tumbleweed substituting the stock kernel with upstream one,
either chainloading uboot+grub+kernel or directly booting the kernel
from 1st stage bootloader. Steps to reproduce:
- prepare an SD card from a Raspberry enabled raw image, mount the first
  FAT partition.
- make sure the FAT partition is big enough to contain the kernel,
  anything bigger than 64Mb is usually enough, depending on your kernel
  config options.
- build the kernel and dtbs making sure that the support for your root
  fs type is compiled as builtin.
- copy the kernel image in your FAT partition overwriting the older one
  (e.g. kernel*.img for Raspberry Pi OS or u-boot.bin for Tumbleweed).
- copy arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dtb on FAT partition.
- make sure you have a cmdline.txt file in FAT partition with the
  following content:
  # cat /boot/efi/cmdline.txt
  root=/dev/mmcblk0p3 rootwait rw console=tty ignore_loglevel earlycon
  console=ttyAMA10,115200
- if you experience random SD issues during boot, try to set
  initial_turbo=0 in config.txt.


Changes in V5:

DTS:
- axi node merged into soc node
- redefined the mapping ranges of the soc node to have proper translation,
  and a narrower address and size cell number for child nodes.Child nodes
  reg properties adjusted accordingly
- augemented the comment in 'gio_aon' node

sdhci-brcmstb.c:
- removed unused 'base_clk_mhz' variable


Changes in V4:

sdhci-brcmstb.c:
- dropped the last 4 lines of sdhci_brcmstb_cfginit_2712() function
  to avoid setting the SDIO_CFG_CQ_CAPABILITY register. The rationale
  behind this can be found in [4] and subsequent comments

DT-bindings:
- simplified the compatible item list for 'brcm,bcm2712-sdhci' as per [5]


Changes in V3:

DTS:
- uart0 renamed to uart10 to reflect the current indexing (ttyAMA10
  and serial10)
- updated the license to (GPL-2.0 OR MIT)
- sd_io_1v8_reg 'states' property have second cells as decimal instead
  of hex.
- root node has size-cells=<2> now to accommodate for the DRAM controller
  and the address bus mapping that goes beyond 4GB. As a consequence,
  memory, axi and reserved-memory nodes have also size-cells=<2> and
  subnodes reg and ranges properties have been updated accordingly
- ranges property in 'axi' node has been fixed, reg properties of sdio1
  and gicv2 subnodes have been adjusted according to the new mapping
- 'interrupt-controller@7d517000' node is now enabled by default
- dropped 'arm,cpu-registers-not-fw-configured' as it is no longer
  relevant on A76 core
- l2 cache nodes moved under respective cpus, since they are per-cpu
- dropped psci cpu functions properties
- added the hypervisor EL2 virtual timer interrupt to the 'timer' node
- splitted-lines url are now on a single line

sdhci-brcmstb.c:
- simplified MMC_CAP_HSE_MASK leveraging already existing definitions
- MMC_CAP_UHS_MASK renamed to MMC_CAP_UHS_I_SDR_MASK to better reflect
  its purpose. Added also a comment.
- sdhci_brcmstb_set_power() replaced with the already existing (and
  equivalent) sdhci_set_power_and_bus_voltage()

DT-bindings:
- removed the BCM2712 specific example, as per Rob's request


Changes in V2:

- the patchshet has been considerably simplified, both in terms of dts and
  driver code. Notably, the pinctrl/pinmux driver (and associated binding)
  was not strictly needed to use the SD card so it has been dropped
- dropped the optional SD express support patch
- the patches order has been revisited
- pass all checks (binding, dtb, checkpatch)


Many thanks,
Andrea

References:
[1] - Link to V1: https://lore.kernel.org/all/cover.1713036964.git.andrea.porta@suse.com/
[2] - Link to V2: https://lore.kernel.org/all/cover.1715332922.git.andrea.porta@suse.com/
[3] - Link to V3: https://lore.kernel.org/all/cover.1716277695.git.andrea.porta@suse.com/
[4] - https://lore.kernel.org/all/ZlF5dQbNpZ921e66@apocalypse/
[5] - https://lore.kernel.org/all/bc1eb98c-9d49-4424-ab89-16be6c67c3f5@gmx.net/#t

Andrea della Porta (4):
  dt-bindings: arm: bcm: Add BCM2712 SoC support
  dt-bindings: mmc: Add support for BCM2712 SD host controller
  mmc: sdhci-brcmstb: Add BCM2712 support
  arm64: dts: broadcom: Add minimal support for Raspberry Pi 5

 .../devicetree/bindings/arm/bcm/bcm2835.yaml  |   6 +
 .../bindings/mmc/brcm,sdhci-brcmstb.yaml      |   1 +
 arch/arm64/boot/dts/broadcom/Makefile         |   1 +
 .../boot/dts/broadcom/bcm2712-rpi-5-b.dts     |  64 ++++
 arch/arm64/boot/dts/broadcom/bcm2712.dtsi     | 283 ++++++++++++++++++
 drivers/mmc/host/sdhci-brcmstb.c              |  60 ++++
 6 files changed, 415 insertions(+)
 create mode 100644 arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts
 create mode 100644 arch/arm64/boot/dts/broadcom/bcm2712.dtsi

Comments

Rob Herring May 30, 2024, 12:45 p.m. UTC | #1
On Thu, 30 May 2024 12:11:57 +0200, Andrea della Porta wrote:
> Hi,
> 
> This patchset adds minimal support for the Broadcom BCM2712 SoC and for
> the on-board SDHCI controller on Broadcom BCM2712 in order to make it
> possible to boot (particularly) a Raspberry Pi 5 from SD card and get a
> console through uart.
> Changes to arm64/defconfig are not needed since the actual options work
> as they are.
> This work is heavily based on downstream contributions.
> 
> Tested on Tumbleweed substituting the stock kernel with upstream one,
> either chainloading uboot+grub+kernel or directly booting the kernel
> from 1st stage bootloader. Steps to reproduce:
> - prepare an SD card from a Raspberry enabled raw image, mount the first
>   FAT partition.
> - make sure the FAT partition is big enough to contain the kernel,
>   anything bigger than 64Mb is usually enough, depending on your kernel
>   config options.
> - build the kernel and dtbs making sure that the support for your root
>   fs type is compiled as builtin.
> - copy the kernel image in your FAT partition overwriting the older one
>   (e.g. kernel*.img for Raspberry Pi OS or u-boot.bin for Tumbleweed).
> - copy arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dtb on FAT partition.
> - make sure you have a cmdline.txt file in FAT partition with the
>   following content:
>   # cat /boot/efi/cmdline.txt
>   root=/dev/mmcblk0p3 rootwait rw console=tty ignore_loglevel earlycon
>   console=ttyAMA10,115200
> - if you experience random SD issues during boot, try to set
>   initial_turbo=0 in config.txt.
> 
> 
> Changes in V5:
> 
> DTS:
> - axi node merged into soc node
> - redefined the mapping ranges of the soc node to have proper translation,
>   and a narrower address and size cell number for child nodes.Child nodes
>   reg properties adjusted accordingly
> - augemented the comment in 'gio_aon' node
> 
> sdhci-brcmstb.c:
> - removed unused 'base_clk_mhz' variable
> 
> 
> Changes in V4:
> 
> sdhci-brcmstb.c:
> - dropped the last 4 lines of sdhci_brcmstb_cfginit_2712() function
>   to avoid setting the SDIO_CFG_CQ_CAPABILITY register. The rationale
>   behind this can be found in [4] and subsequent comments
> 
> DT-bindings:
> - simplified the compatible item list for 'brcm,bcm2712-sdhci' as per [5]
> 
> 
> Changes in V3:
> 
> DTS:
> - uart0 renamed to uart10 to reflect the current indexing (ttyAMA10
>   and serial10)
> - updated the license to (GPL-2.0 OR MIT)
> - sd_io_1v8_reg 'states' property have second cells as decimal instead
>   of hex.
> - root node has size-cells=<2> now to accommodate for the DRAM controller
>   and the address bus mapping that goes beyond 4GB. As a consequence,
>   memory, axi and reserved-memory nodes have also size-cells=<2> and
>   subnodes reg and ranges properties have been updated accordingly
> - ranges property in 'axi' node has been fixed, reg properties of sdio1
>   and gicv2 subnodes have been adjusted according to the new mapping
> - 'interrupt-controller@7d517000' node is now enabled by default
> - dropped 'arm,cpu-registers-not-fw-configured' as it is no longer
>   relevant on A76 core
> - l2 cache nodes moved under respective cpus, since they are per-cpu
> - dropped psci cpu functions properties
> - added the hypervisor EL2 virtual timer interrupt to the 'timer' node
> - splitted-lines url are now on a single line
> 
> sdhci-brcmstb.c:
> - simplified MMC_CAP_HSE_MASK leveraging already existing definitions
> - MMC_CAP_UHS_MASK renamed to MMC_CAP_UHS_I_SDR_MASK to better reflect
>   its purpose. Added also a comment.
> - sdhci_brcmstb_set_power() replaced with the already existing (and
>   equivalent) sdhci_set_power_and_bus_voltage()
> 
> DT-bindings:
> - removed the BCM2712 specific example, as per Rob's request
> 
> 
> Changes in V2:
> 
> - the patchshet has been considerably simplified, both in terms of dts and
>   driver code. Notably, the pinctrl/pinmux driver (and associated binding)
>   was not strictly needed to use the SD card so it has been dropped
> - dropped the optional SD express support patch
> - the patches order has been revisited
> - pass all checks (binding, dtb, checkpatch)
> 
> 
> Many thanks,
> Andrea
> 
> References:
> [1] - Link to V1: https://lore.kernel.org/all/cover.1713036964.git.andrea.porta@suse.com/
> [2] - Link to V2: https://lore.kernel.org/all/cover.1715332922.git.andrea.porta@suse.com/
> [3] - Link to V3: https://lore.kernel.org/all/cover.1716277695.git.andrea.porta@suse.com/
> [4] - https://lore.kernel.org/all/ZlF5dQbNpZ921e66@apocalypse/
> [5] - https://lore.kernel.org/all/bc1eb98c-9d49-4424-ab89-16be6c67c3f5@gmx.net/#t
> 
> Andrea della Porta (4):
>   dt-bindings: arm: bcm: Add BCM2712 SoC support
>   dt-bindings: mmc: Add support for BCM2712 SD host controller
>   mmc: sdhci-brcmstb: Add BCM2712 support
>   arm64: dts: broadcom: Add minimal support for Raspberry Pi 5
> 
>  .../devicetree/bindings/arm/bcm/bcm2835.yaml  |   6 +
>  .../bindings/mmc/brcm,sdhci-brcmstb.yaml      |   1 +
>  arch/arm64/boot/dts/broadcom/Makefile         |   1 +
>  .../boot/dts/broadcom/bcm2712-rpi-5-b.dts     |  64 ++++
>  arch/arm64/boot/dts/broadcom/bcm2712.dtsi     | 283 ++++++++++++++++++
>  drivers/mmc/host/sdhci-brcmstb.c              |  60 ++++
>  6 files changed, 415 insertions(+)
>  create mode 100644 arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts
>  create mode 100644 arch/arm64/boot/dts/broadcom/bcm2712.dtsi
> 
> --
> 2.35.3
> 
> 
> 


My bot found new DTB warnings on the .dts files added or changed in this
series.

Some warnings may be from an existing SoC .dtsi. Or perhaps the warnings
are fixed by another series. Ultimately, it is up to the platform
maintainer whether these warnings are acceptable or not. No need to reply
unless the platform maintainer has comments.

If you already ran DT checks and didn't see these error(s), then
make sure dt-schema is up to date:

  pip3 install dtschema --upgrade


New warnings running 'make CHECK_DTBS=y broadcom/bcm2712-rpi-5-b.dtb' for cover.1717061147.git.andrea.porta@suse.com:

arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dtb: /soc@107c000000/timer@7c003000: failed to match any schema with compatible: ['brcm,bcm2835-system-timer']
arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dtb: /soc@107c000000/local-intc@7cd00000: failed to match any schema with compatible: ['brcm,bcm2836-l1-intc']
Stefan Wahren May 31, 2024, 10 a.m. UTC | #2
Hi Andrea,

Am 30.05.24 um 12:11 schrieb Andrea della Porta:
> Hi,
>
> This patchset adds minimal support for the Broadcom BCM2712 SoC and for
> the on-board SDHCI controller on Broadcom BCM2712 in order to make it
> possible to boot (particularly) a Raspberry Pi 5 from SD card and get a
> console through uart.
> Changes to arm64/defconfig are not needed since the actual options work
> as they are.
> This work is heavily based on downstream contributions.
>
> Tested on Tumbleweed substituting the stock kernel with upstream one,
> either chainloading uboot+grub+kernel or directly booting the kernel
> from 1st stage bootloader. Steps to reproduce:
> - prepare an SD card from a Raspberry enabled raw image, mount the first
>    FAT partition.
> - make sure the FAT partition is big enough to contain the kernel,
>    anything bigger than 64Mb is usually enough, depending on your kernel
>    config options.
> - build the kernel and dtbs making sure that the support for your root
>    fs type is compiled as builtin.
> - copy the kernel image in your FAT partition overwriting the older one
>    (e.g. kernel*.img for Raspberry Pi OS or u-boot.bin for Tumbleweed).
> - copy arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dtb on FAT partition.
> - make sure you have a cmdline.txt file in FAT partition with the
>    following content:
>    # cat /boot/efi/cmdline.txt
>    root=/dev/mmcblk0p3 rootwait rw console=tty ignore_loglevel earlycon
>    console=ttyAMA10,115200
> - if you experience random SD issues during boot, try to set
>    initial_turbo=0 in config.txt.
was this an issue since the beginning of this series?

What kind of SD issues?

Is there a downstream reference?
Andrea della Porta May 31, 2024, 12:59 p.m. UTC | #3
Hi Stefan,

On 12:00 Fri 31 May     , Stefan Wahren wrote:
> Hi Andrea,
> 
> Am 30.05.24 um 12:11 schrieb Andrea della Porta:
> > Hi,
> > 
> > This patchset adds minimal support for the Broadcom BCM2712 SoC and for
> > the on-board SDHCI controller on Broadcom BCM2712 in order to make it
> > possible to boot (particularly) a Raspberry Pi 5 from SD card and get a
> > console through uart.
> > Changes to arm64/defconfig are not needed since the actual options work
> > as they are.
> > This work is heavily based on downstream contributions.
> > 
> > Tested on Tumbleweed substituting the stock kernel with upstream one,
> > either chainloading uboot+grub+kernel or directly booting the kernel
> > from 1st stage bootloader. Steps to reproduce:
> > - prepare an SD card from a Raspberry enabled raw image, mount the first
> >    FAT partition.
> > - make sure the FAT partition is big enough to contain the kernel,
> >    anything bigger than 64Mb is usually enough, depending on your kernel
> >    config options.
> > - build the kernel and dtbs making sure that the support for your root
> >    fs type is compiled as builtin.
> > - copy the kernel image in your FAT partition overwriting the older one
> >    (e.g. kernel*.img for Raspberry Pi OS or u-boot.bin for Tumbleweed).
> > - copy arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dtb on FAT partition.
> > - make sure you have a cmdline.txt file in FAT partition with the
> >    following content:
> >    # cat /boot/efi/cmdline.txt
> >    root=/dev/mmcblk0p3 rootwait rw console=tty ignore_loglevel earlycon
> >    console=ttyAMA10,115200
> > - if you experience random SD issues during boot, try to set
> >    initial_turbo=0 in config.txt.
> was this an issue since the beginning of this series?
>

I experienced this even during early testing, using the complete downstream
driver. It seems that when initual_turbo != 0, the fw can throttle the clock
to reduce the boot time and it (directly or indirectly) may affect SD functionality.
I believe that the probability of this to happen is likely a function of SD
card speed, whether it requires timing tuning, initial_turbo exact value  and whether
you are booting the kernel directly or chainloading u-boot + grub (or
whatever combination of secondary stage bootloader). For example, your 
boot setup may have a timeout in the grub boot menu that is large enough for the clocks
to settle and the boot process to end successfully, while faster boot time can lead
to the issue described. Since this behaviour seems to depend on all of this factors and
does not necessarily arise in practice, disabling initial_turbo is just a suggestion
in case things go haywire. 

> What kind of SD issues?
>

I wasn't able to boot from SD card due to clock issues.
 
> Is there a downstream reference?

Some (old) reference e.g.:
https://forums.raspberrypi.com/viewtopic.php?t=112480#:~:text=It%20sets%20turbo%20mode%20from,have%20turbo%20during%20the%20boot.

but there are probably more.

Many thanks,
Andrea
Stefan Wahren June 1, 2024, 8:17 a.m. UTC | #4
Hi Andrea,

Am 31.05.24 um 14:59 schrieb Andrea della Porta:
> Hi Stefan,
>
> On 12:00 Fri 31 May     , Stefan Wahren wrote:
>> Hi Andrea,
>>
>> Am 30.05.24 um 12:11 schrieb Andrea della Porta:
>>> Hi,
>>>
>>> This patchset adds minimal support for the Broadcom BCM2712 SoC and for
>>> the on-board SDHCI controller on Broadcom BCM2712 in order to make it
>>> possible to boot (particularly) a Raspberry Pi 5 from SD card and get a
>>> console through uart.
>>> Changes to arm64/defconfig are not needed since the actual options work
>>> as they are.
>>> This work is heavily based on downstream contributions.
>>>
>>> Tested on Tumbleweed substituting the stock kernel with upstream one,
>>> either chainloading uboot+grub+kernel or directly booting the kernel
>>> from 1st stage bootloader. Steps to reproduce:
>>> - prepare an SD card from a Raspberry enabled raw image, mount the first
>>>     FAT partition.
>>> - make sure the FAT partition is big enough to contain the kernel,
>>>     anything bigger than 64Mb is usually enough, depending on your kernel
>>>     config options.
>>> - build the kernel and dtbs making sure that the support for your root
>>>     fs type is compiled as builtin.
>>> - copy the kernel image in your FAT partition overwriting the older one
>>>     (e.g. kernel*.img for Raspberry Pi OS or u-boot.bin for Tumbleweed).
>>> - copy arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dtb on FAT partition.
>>> - make sure you have a cmdline.txt file in FAT partition with the
>>>     following content:
>>>     # cat /boot/efi/cmdline.txt
>>>     root=/dev/mmcblk0p3 rootwait rw console=tty ignore_loglevel earlycon
>>>     console=ttyAMA10,115200
>>> - if you experience random SD issues during boot, try to set
>>>     initial_turbo=0 in config.txt.
>> was this an issue since the beginning of this series?
>>
> I experienced this even during early testing, using the complete downstream
> driver. It seems that when initual_turbo != 0, the fw can throttle the clock
> to reduce the boot time and it (directly or indirectly) may affect SD functionality.
> I believe that the probability of this to happen is likely a function of SD
> card speed, whether it requires timing tuning, initial_turbo exact value  and whether
> you are booting the kernel directly or chainloading u-boot + grub (or
> whatever combination of secondary stage bootloader). For example, your
> boot setup may have a timeout in the grub boot menu that is large enough for the clocks
> to settle and the boot process to end successfully, while faster boot time can lead
> to the issue described. Since this behaviour seems to depend on all of this factors and
> does not necessarily arise in practice, disabling initial_turbo is just a suggestion
> in case things go haywire.
yes in case the VPU changes the SD clock or one of the parent while the
ARM cores tries to boot, they won't be informed about these changes
which could ends up with the wrong SD clock frequency.

Thanks for your explanations
>
>> What kind of SD issues?
>>
> I wasn't able to boot from SD card due to clock issues.
>
>> Is there a downstream reference?
> Some (old) reference e.g.:
> https://forums.raspberrypi.com/viewtopic.php?t=112480#:~:text=It%20sets%20turbo%20mode%20from,have%20turbo%20during%20the%20boot.
>
> but there are probably more.
>
> Many thanks,
> Andrea
Ulf Hansson June 4, 2024, 11:13 a.m. UTC | #5
On Thu, 30 May 2024 at 12:11, Andrea della Porta <andrea.porta@suse.com> wrote:
>
> Hi,
>
> This patchset adds minimal support for the Broadcom BCM2712 SoC and for
> the on-board SDHCI controller on Broadcom BCM2712 in order to make it
> possible to boot (particularly) a Raspberry Pi 5 from SD card and get a
> console through uart.
> Changes to arm64/defconfig are not needed since the actual options work
> as they are.
> This work is heavily based on downstream contributions.
>
> Tested on Tumbleweed substituting the stock kernel with upstream one,
> either chainloading uboot+grub+kernel or directly booting the kernel
> from 1st stage bootloader. Steps to reproduce:
> - prepare an SD card from a Raspberry enabled raw image, mount the first
>   FAT partition.
> - make sure the FAT partition is big enough to contain the kernel,
>   anything bigger than 64Mb is usually enough, depending on your kernel
>   config options.
> - build the kernel and dtbs making sure that the support for your root
>   fs type is compiled as builtin.
> - copy the kernel image in your FAT partition overwriting the older one
>   (e.g. kernel*.img for Raspberry Pi OS or u-boot.bin for Tumbleweed).
> - copy arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dtb on FAT partition.
> - make sure you have a cmdline.txt file in FAT partition with the
>   following content:
>   # cat /boot/efi/cmdline.txt
>   root=/dev/mmcblk0p3 rootwait rw console=tty ignore_loglevel earlycon
>   console=ttyAMA10,115200
> - if you experience random SD issues during boot, try to set
>   initial_turbo=0 in config.txt.
>
>
> Changes in V5:
>
> DTS:
> - axi node merged into soc node
> - redefined the mapping ranges of the soc node to have proper translation,
>   and a narrower address and size cell number for child nodes.Child nodes
>   reg properties adjusted accordingly
> - augemented the comment in 'gio_aon' node
>
> sdhci-brcmstb.c:
> - removed unused 'base_clk_mhz' variable

Patch 1 ->3 from v5 applied for next, thanks!

[...]

Kind regards
Uffe