diff mbox series

[v2,2/2] configs: add raspberrypi 5 defconfig

Message ID 20231211155951.4079886-3-gael.portay@rtone.fr
State Changes Requested
Headers show
Series Add support for Pi5 | expand

Commit Message

Gaël PORTAY Dec. 11, 2023, 3:59 p.m. UTC
This configuration builds an image for the RaspberryPi 5.

Signed-off-by: Gaël PORTAY <gael.portay@rtone.fr>
---
 board/raspberrypi/cmdline_5.txt |  1 +
 board/raspberrypi/config_5.txt  | 14 ++++++++++++
 board/raspberrypi/readme.txt    |  6 +++++
 board/raspberrypi5              |  1 +
 configs/raspberrypi5_defconfig  | 40 +++++++++++++++++++++++++++++++++
 5 files changed, 62 insertions(+)
 create mode 100644 board/raspberrypi/cmdline_5.txt
 create mode 100644 board/raspberrypi/config_5.txt
 create mode 120000 board/raspberrypi5
 create mode 100644 configs/raspberrypi5_defconfig

Comments

Yann E. MORIN Jan. 19, 2024, 8:35 p.m. UTC | #1
Gaël, All,

On 2023-12-11 16:59 +0100, Gaël PORTAY spake thusly:
> This configuration builds an image for the RaspberryPi 5.
> 
> Signed-off-by: Gaël PORTAY <gael.portay@rtone.fr>
[--SNIP--]
> --- /dev/null
> +++ b/configs/raspberrypi5_defconfig
> @@ -0,0 +1,40 @@
> +BR2_aarch64=y
> +BR2_cortex_a76_a55=y
> +BR2_ARM_FPU_VFPV4=y
> +BR2_ARM64_PAGE_SIZE_16K=y

So, we choose 16K for the userland page alignment, because...

[--SNIP--]
> +BR2_LINUX_KERNEL=y
> +BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
> +BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,17f135b742c4edb340afb365873c3a574f7e16cb)/linux-17f135b742c4edb340afb365873c3a574f7e16cb.tar.gz"
> +BR2_LINUX_KERNEL_DEFCONFIG="bcm2712"

... the bcm2712_defconfig in the kernel tree default to use 16K pages:
    CONFIG_ARM64_16K_PAGES=y

This is all a little bit murky for me, but the kernel help for
CONFIG_ARM64_16K_PAGES states:

  The system will use 16KB pages support. AArch32 emulation
  requires applications compiled with 16K (or a multiple of 16K)
  aligned segments.

But we are not doing 32-on-64 in Buildroot, we're only doing pure
64-bit.

If I interret the kernel help text correctly, aarch64 userland is not
impacted by the page size the kernel uses, so we can still use 4K pages
in userland.

Or do we just want to avoid any confusion at all, and always consider
that the userland and kernel page size must match? Or did I just
misinterpret the kernel help text, and the two *must* match?

If I missed something, or am wrong somewhere, just yell! ;-)

Regards,
Yann E. MORIN.

> +# Build the DTB from the kernel sources
> +BR2_LINUX_KERNEL_DTS_SUPPORT=y
> +BR2_LINUX_KERNEL_INTREE_DTS_NAME="broadcom/bcm2712-rpi-5-b"
> +
> +BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
> +
> +BR2_PACKAGE_RPI_FIRMWARE=y
> +BR2_PACKAGE_RPI_FIRMWARE_CONFIG_FILE="board/raspberrypi5/config_5.txt"
> +BR2_PACKAGE_RPI_FIRMWARE_CMDLINE_FILE="board/raspberrypi5/cmdline_5.txt"
> +# BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS is not set
> +
> +# Required tools to create the SD image
> +BR2_PACKAGE_HOST_DOSFSTOOLS=y
> +BR2_PACKAGE_HOST_GENIMAGE=y
> +BR2_PACKAGE_HOST_MTOOLS=y
> +
> +# Filesystem / image
> +BR2_TARGET_ROOTFS_EXT2=y
> +BR2_TARGET_ROOTFS_EXT2_4=y
> +BR2_TARGET_ROOTFS_EXT2_SIZE="120M"
> +# BR2_TARGET_ROOTFS_TAR is not set
> +BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi5/post-build.sh"
> +BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi5/post-image.sh"
> -- 
> 2.43.0
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
Adam Duskett Jan. 20, 2024, 3:11 a.m. UTC | #2
Hello;


On Fri, Jan 19, 2024 at 1:36 PM Yann E. MORIN <yann.morin.1998@free.fr> wrote:
>
> Gaël, All,
>
> On 2023-12-11 16:59 +0100, Gaël PORTAY spake thusly:
> > This configuration builds an image for the RaspberryPi 5.
> >
> > Signed-off-by: Gaël PORTAY <gael.portay@rtone.fr>
> [--SNIP--]
> > --- /dev/null
> > +++ b/configs/raspberrypi5_defconfig
> > @@ -0,0 +1,40 @@
> > +BR2_aarch64=y
> > +BR2_cortex_a76_a55=y
> > +BR2_ARM_FPU_VFPV4=y
> > +BR2_ARM64_PAGE_SIZE_16K=y
>
> So, we choose 16K for the userland page alignment, because...
>
> [--SNIP--]
> > +BR2_LINUX_KERNEL=y
> > +BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
> > +BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,17f135b742c4edb340afb365873c3a574f7e16cb)/linux-17f135b742c4edb340afb365873c3a574f7e16cb.tar.gz"
> > +BR2_LINUX_KERNEL_DEFCONFIG="bcm2712"
>
> ... the bcm2712_defconfig in the kernel tree default to use 16K pages:
>     CONFIG_ARM64_16K_PAGES=y
>
> This is all a little bit murky for me, but the kernel help for
> CONFIG_ARM64_16K_PAGES states:
>
>   The system will use 16KB pages support. AArch32 emulation
>   requires applications compiled with 16K (or a multiple of 16K)
>   aligned segments.
>
> But we are not doing 32-on-64 in Buildroot, we're only doing pure
> 64-bit.
>
> If I interpret the kernel help text correctly, aarch64 userland is not
> impacted by the page size the kernel uses, so we can still use 4K pages
> in userland.
>
> Or do we just want to avoid any confusion at all, and always consider
> that the userland and kernel page size must match? Or did I just
> misinterpret the kernel help text, and the two *must* match?
>
> If I missed something or am wrong somewhere, just yell! ;-)
>
> Regards,
> Yann E. MORIN.
>

Yes, you are correct. I created board/raspberrypi/rpi5-linux.fragment with the
following line:
CONFIG_ARM64_4K_PAGES=y

I built this config using a Bootlin toolchain, and everything works properly
on my personal RPI5!

Adam

> > +# Build the DTB from the kernel sources
> > +BR2_LINUX_KERNEL_DTS_SUPPORT=y
> > +BR2_LINUX_KERNEL_INTREE_DTS_NAME="broadcom/bcm2712-rpi-5-b"
> > +
> > +BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
> > +
> > +BR2_PACKAGE_RPI_FIRMWARE=y
> > +BR2_PACKAGE_RPI_FIRMWARE_CONFIG_FILE="board/raspberrypi5/config_5.txt"
> > +BR2_PACKAGE_RPI_FIRMWARE_CMDLINE_FILE="board/raspberrypi5/cmdline_5.txt"
> > +# BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS is not set
> > +
> > +# Required tools to create the SD image
> > +BR2_PACKAGE_HOST_DOSFSTOOLS=y
> > +BR2_PACKAGE_HOST_GENIMAGE=y
> > +BR2_PACKAGE_HOST_MTOOLS=y
> > +
> > +# Filesystem / image
> > +BR2_TARGET_ROOTFS_EXT2=y
> > +BR2_TARGET_ROOTFS_EXT2_4=y
> > +BR2_TARGET_ROOTFS_EXT2_SIZE="120M"
> > +# BR2_TARGET_ROOTFS_TAR is not set
> > +BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi5/post-build.sh"
> > +BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi5/post-image.sh"
> > --
> > 2.43.0
> >
> > _______________________________________________
> > buildroot mailing list
> > buildroot@buildroot.org
> > https://lists.buildroot.org/mailman/listinfo/buildroot
>
> --
> .-----------------.--------------------.------------------.--------------------.
> |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
> | +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
> | +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
> | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
> '------------------------------^-------^------------------^--------------------'
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
Gaël PORTAY Jan. 20, 2024, 8:01 a.m. UTC | #3
Yann, Adam,

On Sat Jan 20, 2024 at 4:11 AM CET, Adam Duskett wrote:
> Hello;
>
>
> On Fri, Jan 19, 2024 at 1:36 PM Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> >
> > Gaël, All,
> >
> > On 2023-12-11 16:59 +0100, Gaël PORTAY spake thusly:
> > > This configuration builds an image for the RaspberryPi 5.
> > >
> > > Signed-off-by: Gaël PORTAY <gael.portay@rtone.fr>
> > [--SNIP--]
> > > --- /dev/null
> > > +++ b/configs/raspberrypi5_defconfig
> > > @@ -0,0 +1,40 @@
> > > +BR2_aarch64=y
> > > +BR2_cortex_a76_a55=y
> > > +BR2_ARM_FPU_VFPV4=y
> > > +BR2_ARM64_PAGE_SIZE_16K=y
> >
> > So, we choose 16K for the userland page alignment, because...
> >
> > [--SNIP--]
> > > +BR2_LINUX_KERNEL=y
> > > +BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
> > > +BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,17f135b742c4edb340afb365873c3a574f7e16cb)/linux-17f135b742c4edb340afb365873c3a574f7e16cb.tar.gz"
> > > +BR2_LINUX_KERNEL_DEFCONFIG="bcm2712"
> >
> > ... the bcm2712_defconfig in the kernel tree default to use 16K pages:
> >     CONFIG_ARM64_16K_PAGES=y
> >

... and because BCM2712 support 16k. Otherwise I would have chosen the
bcm2711_defconfig that is 4K.

> > This is all a little bit murky for me, but the kernel help for
> > CONFIG_ARM64_16K_PAGES states:
> >
> >   The system will use 16KB pages support. AArch32 emulation
> >   requires applications compiled with 16K (or a multiple of 16K)
> >   aligned segments.
> >
> > But we are not doing 32-on-64 in Buildroot, we're only doing pure
> > 64-bit.
> >

Indeed.

> > If I interpret the kernel help text correctly, aarch64 userland is not
> > impacted by the page size the kernel uses, so we can still use 4K pages
> > in userland.
> >
> > Or do we just want to avoid any confusion at all, and always consider
> > that the userland and kernel page size must match? Or did I just
> > misinterpret the kernel help text, and the two *must* match?
> >
> > If I missed something or am wrong somewhere, just yell! ;-)
> >
> > Regards,
> > Yann E. MORIN.
> >

IIRC, I have built with:

- the (internal) buildroot toolchain and it works (16k indeed).
- the external Bootlin toolchain and it fails to run init (4k according
  to Thomas).
- the external Arm AArch64 toolchain and it works (16k I guess ???).

And thus, I suspect both userland and kernel page size must match.

>
> Yes, you are correct. I created board/raspberrypi/rpi5-linux.fragment with the
> following line:
> CONFIG_ARM64_4K_PAGES=y
>
> I built this config using a Bootlin toolchain, and everything works properly
> on my personal RPI5!
>
> Adam

Thanks for this test.

---

So, if the assomption is right (i.e. userland and kernel page sizes must
match), I guess it would be interesting to filter-in (or to filter-out)
the external toolchains that match the config because buildroot prompts
for all the external toolchain; but some of them fail at runtime because
of a mismatch page-size.

What about introducing BR2_TOOLCHAIN_HAS_PAGE_SIZE_{4,16,64}K?

Or, I am totally wrong :/

Regards,
Gaël

PS: Also, BR could have two configs for pi5:
 - raspberrypi5_defconfig: 4k
   BR2_LINUX_KERNEL_DEFCONFIG="bcm2711"
   # BR2_ARM64_PAGE_SIZE_4K=y
 - raspberrypi5-16k_defconfig: 16k
   BR2_LINUX_KERNEL_DEFCONFIG="bcm2712"
   BR2_ARM64_PAGE_SIZE_16K=y
Yann E. MORIN Jan. 20, 2024, 8:53 a.m. UTC | #4
Gaël, All,

On 2024-01-20 09:01 +0100, Gaël PORTAY spake thusly:
> On Sat Jan 20, 2024 at 4:11 AM CET, Adam Duskett wrote:
> > On Fri, Jan 19, 2024 at 1:36 PM Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> > > On 2023-12-11 16:59 +0100, Gaël PORTAY spake thusly:
> > > > This configuration builds an image for the RaspberryPi 5.
> > > > +BR2_ARM64_PAGE_SIZE_16K=y
> > > So, we choose 16K for the userland page alignment, because...
> > > > +BR2_LINUX_KERNEL_DEFCONFIG="bcm2712"
> > > ... the bcm2712_defconfig in the kernel tree default to use 16K pages:
> > >     CONFIG_ARM64_16K_PAGES=y
> ... and because BCM2712 support 16k.

Yes, it _supports_ 16K pages, but it also supports 4K and 64K, so there
is no reason to shoose 16K or 64K over 4K, except for the fact that the
kernel defconfig uses 16K pages.

> Otherwise I would have chosen the
> bcm2711_defconfig that is 4K.

Isn't bcm2711_defconfig for the rpi4? It would be weird to use th rpi4
defconfig for the rpi5. Presumably, also, the rpi4 defconfig does not
enmable the drivers for the rpi5-only rp1 IOs...

So, using bcm2712_defconfig is understandable...

[--SNIP--]
> IIRC, I have built with:
> 
> - the (internal) buildroot toolchain and it works (16k indeed).
> - the external Bootlin toolchain and it fails to run init (4k according
>   to Thomas).
> - the external Arm AArch64 toolchain and it works (16k I guess ???).
> 
> And thus, I suspect both userland and kernel page size must match.

Now I read buildroot/arch/Config.in.arm, which states:

    ... the kernel
    configuration must match this choice. If your kernel is
    built by Buildroot, the kernel configuration is
    automatically adjusted, ...

So, it currently works, because:

  - the toolchain is built by buildroot,
  - the kernel is built by buildroot

So, if we were to set BR2_ARM64_PAGE_SIZE_4K instead, then it would
*also* work.

Which is my point. We should not be doing 16K pages on the rpi5 by
default.

The tests Adam did (thanks!), was to use your defconfig, and just switch
to the bootlin toolchain, which uncovered the two issues at hand.

> So, if the assomption is right (i.e. userland and kernel page sizes must
> match), I guess it would be interesting to filter-in (or to filter-out)
> the external toolchains that match the config because buildroot prompts
> for all the external toolchain; but some of them fail at runtime because
> of a mismatch page-size.
> 
> What about introducing BR2_TOOLCHAIN_HAS_PAGE_SIZE_{4,16,64}K?

Yes, we'll have to do so.

The thing is, we are passing the proper ld flags in our wrapper (e.g.
for 16K):

    ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384

so we would eventually generated binaries that are 16K-enabled.

The problem is that the C library in an external toolchain will have
been built with an arbitrary page size, and we need to be able to find
out, if we want to check that.

For preconfigured toolchains, that's OK: all those we now ahve are
configured for 4K pages. They have to be, because nothing in Buildroot
enables non-4K pages for now.

But for a custom external toolchain, the user may not know, so we need
to validate that their choice is correct, e.g. lie we do for the type of
C library, the gcc or kernel headers versions, etc...

So, we need to:

 1. add a depends on BR2_ARM64_PAGE_SIZE_4K to all current external
    pre-configured aarch64 toolchains; ditto for arc; indeed, we should
    simply hide the toolchains that do not have the page size the user
    selected.

 2. introduce BR2_TOOLCHAIN_EXTERNAL_PAGE_SIZE_{4,8,16,64}K  (8K is for
    arc) and BR2_TOOLCHAIN_EXTERNAL_PAGE_SIZE="{4,8,16,64}K" in
    toolchain/toolchain-external/toolchain-external-custom/Config.in.options
    and add a checkpage_size helper in toolchain/helpers.mk, that
    validates that the C library was indeed built with the page size
    BR2_TOOLCHAIN_EXTERNAL_PAGE_SIZE.

The last item, checking the page size a .so was built for, is not
something I know how to do, though... Any idea?

Note that 1. and 2. are separate, and doing 1. should be relatively
easy, and does not require 2.

> Or, I am totally wrong :/

Hehe! I am happy I would not walk alone! :-)

> Regards,
> Gaël
> 
> PS: Also, BR could have two configs for pi5:
>  - raspberrypi5_defconfig: 4k
>    BR2_LINUX_KERNEL_DEFCONFIG="bcm2711"
>    # BR2_ARM64_PAGE_SIZE_4K=y
>  - raspberrypi5-16k_defconfig: 16k
>    BR2_LINUX_KERNEL_DEFCONFIG="bcm2712"
>    BR2_ARM64_PAGE_SIZE_16K=y

Not sure it would make much sense, if all the above proves to be
correct.

Regards,
Yann E. MORIN.
diff mbox series

Patch

diff --git a/board/raspberrypi/cmdline_5.txt b/board/raspberrypi/cmdline_5.txt
new file mode 100644
index 0000000000..ac457353e2
--- /dev/null
+++ b/board/raspberrypi/cmdline_5.txt
@@ -0,0 +1 @@ 
+root=/dev/mmcblk0p2 rootwait console=tty1 console=ttyAMA10,115200
diff --git a/board/raspberrypi/config_5.txt b/board/raspberrypi/config_5.txt
new file mode 100644
index 0000000000..bbed19fe46
--- /dev/null
+++ b/board/raspberrypi/config_5.txt
@@ -0,0 +1,14 @@ 
+# Please note that this is only a sample, we recommend you to change it to fit
+# your needs.
+# You should override this file using BR2_PACKAGE_RPI_FIRMWARE_CONFIG_FILE.
+# See http://buildroot.org/manual.html#rootfs-custom
+# and http://elinux.org/RPiconfig for a description of config.txt syntax
+
+kernel=Image
+
+# To use an external initramfs file
+#initramfs rootfs.cpio.gz
+
+# Disable overscan assuming the display supports displaying the full resolution
+# If the text shown on the screen disappears off the edge, comment this out
+disable_overscan=1
diff --git a/board/raspberrypi/readme.txt b/board/raspberrypi/readme.txt
index 9202b5ff37..aa6421ea01 100644
--- a/board/raspberrypi/readme.txt
+++ b/board/raspberrypi/readme.txt
@@ -10,6 +10,7 @@  These instructions apply to all models of the Raspberry Pi:
   - the model B3 (aka Raspberry Pi 3).
   - the model B4 (aka Raspberry Pi 4).
   - the model CM4 (aka Raspberry Pi Compute Module 4 and IO Board).
+  - the model B5 (aka Raspberry Pi 5).
 
 How to build it
 ===============
@@ -64,6 +65,10 @@  or for CM4 (on IO Board - 64 bit):
 
   $ make raspberrypicm4io_64_defconfig
 
+For model 5 B:
+
+  $ make raspberrypi5_defconfig
+
 Build the rootfs
 ----------------
 
@@ -94,6 +99,7 @@  After building, you should obtain this tree:
     +-- bcm2710-rpi-cm3.dtb         [1]
     +-- bcm2711-rpi-4-b.dtb         [1]
     +-- bcm2711-rpi-cm4.dtb         [1]
+    +-- bcm2712-rpi-5-b.dtb         [1]
     +-- bcm2837-rpi-3-b.dtb         [1]
     +-- boot.vfat
     +-- rootfs.ext4
diff --git a/board/raspberrypi5 b/board/raspberrypi5
new file mode 120000
index 0000000000..fcdafc81ed
--- /dev/null
+++ b/board/raspberrypi5
@@ -0,0 +1 @@ 
+raspberrypi
\ No newline at end of file
diff --git a/configs/raspberrypi5_defconfig b/configs/raspberrypi5_defconfig
new file mode 100644
index 0000000000..b8cc686ef3
--- /dev/null
+++ b/configs/raspberrypi5_defconfig
@@ -0,0 +1,40 @@ 
+BR2_aarch64=y
+BR2_cortex_a76_a55=y
+BR2_ARM_FPU_VFPV4=y
+BR2_ARM64_PAGE_SIZE_16K=y
+
+BR2_TOOLCHAIN_BUILDROOT_CXX=y
+
+BR2_SYSTEM_DHCP="eth0"
+
+# Linux headers same as kernel, a 6.1 series
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_6_1=y
+
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
+BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,17f135b742c4edb340afb365873c3a574f7e16cb)/linux-17f135b742c4edb340afb365873c3a574f7e16cb.tar.gz"
+BR2_LINUX_KERNEL_DEFCONFIG="bcm2712"
+
+# Build the DTB from the kernel sources
+BR2_LINUX_KERNEL_DTS_SUPPORT=y
+BR2_LINUX_KERNEL_INTREE_DTS_NAME="broadcom/bcm2712-rpi-5-b"
+
+BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
+
+BR2_PACKAGE_RPI_FIRMWARE=y
+BR2_PACKAGE_RPI_FIRMWARE_CONFIG_FILE="board/raspberrypi5/config_5.txt"
+BR2_PACKAGE_RPI_FIRMWARE_CMDLINE_FILE="board/raspberrypi5/cmdline_5.txt"
+# BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS is not set
+
+# Required tools to create the SD image
+BR2_PACKAGE_HOST_DOSFSTOOLS=y
+BR2_PACKAGE_HOST_GENIMAGE=y
+BR2_PACKAGE_HOST_MTOOLS=y
+
+# Filesystem / image
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_4=y
+BR2_TARGET_ROOTFS_EXT2_SIZE="120M"
+# BR2_TARGET_ROOTFS_TAR is not set
+BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi5/post-build.sh"
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi5/post-image.sh"