Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Raspberry Pi 5 support #2914

Merged
merged 31 commits into from
Dec 12, 2023
Merged

Initial Raspberry Pi 5 support #2914

merged 31 commits into from
Dec 12, 2023

Conversation

agners
Copy link
Member

@agners agners commented Nov 7, 2023

This produces a bootable system image. Currently no U-Boot is being used, the Home Assistant OS kernel is directly deployed onto the Raspberry Pi boot partition. System update support and A/B partition is not yet functional.

@agners agners added the board/raspberrypi Raspberry Pi Boards label Nov 7, 2023
@jens-maus
Copy link
Contributor

@agners

System update support and A/B partition is not yet functional.

Have you noticed/checked the relatively new tryboot capabilities of the RaspberryPi own bootloader? See https://www.raspberrypi.com/documentation/computers/config_txt.html#the-tryboot-filter

Perhaps this can be used as an alternative to waiting for U-Boot to be compatible with RaspberryPi5? Or is there already some early patchset for U-Boot which I am not aware of since I would also prefer to continue with using U-Boot as it is still more flexible...

@agners
Copy link
Member Author

agners commented Nov 9, 2023

Have you noticed/checked the relatively new tryboot capabilities of the RaspberryPi own bootloader? See https://www.raspberrypi.com/documentation/computers/config_txt.html#the-tryboot-filter

Perhaps this can be used as an alternative to waiting for U-Boot to be compatible with RaspberryPi5? Or is there already some early patchset for U-Boot which I am not aware of since I would also prefer to continue with using U-Boot as it is still more flexible...

Yes I've noticed tryboot, and started to look into it. I think it can be done with tryboot, although it will need quite some adjustment. A second question would be if we would then stick with that (essentially supporting another bootloader) or move to U-Boot when available. If the second, then the question is if the above mentioned adjustment still would allow that. I hope I have a better idea once I've (tried) implementing it)

I am not aware of any progress on U-Boot side. A couple days back I reached out to some folks previously working on Raspberry Pi support for U-Boot, but no progress from what I've heard.

@agners agners marked this pull request as ready for review December 8, 2023 11:54
@agners
Copy link
Member Author

agners commented Dec 8, 2023

So this implementation has a custom bootloader integration for RAUC using a script. I am deploying kernel and device-tree to the boot partition, maintaining two slots in a separate directory and using os_prefix to switch between the two. The regular A/B kernel partitions are unused (they do contain the kernel, but are not relevant). It is not entirely pretty but should be quite solid in general. It should be possible to migrate away from this scheme and uses the kernel partitions again, but it requires some type of bootloader.

What I am not happy about currently is 7f2c69b. It also changes the data layout. The only reason is the kernel size, but it should possible to use gzip compressed kernels instead, then we should get away with a 64MB boot partition.

Changing partition layout is a bit tricky. On one hand can (and do) make board specific partition layout. But we probably should increase regular kernel and rootfs partition as well... But then, does it help if we only do it for RPi 5? 🤔 🤷‍♂️

@agners
Copy link
Member Author

agners commented Dec 8, 2023

Some notes wrt tryboot mechanism: To activate tryboot mechanism a reboot parameter must be passed (see the relevant Raspberry Pi documentation). By default, the reboot command is symlinked to systemctl. A reboot "0 tryboot" seems to generally work on Home Assistant OS.

However, with Supervisor installing the update, the reboot command is invoked through D-Bus by the Supervisor.

We could modify Supervisor to pass 0 tryboot as well (logind supports RebootWithFlags() or SetRebootParameter()). However, looking at how systemd passes the parameter, we can have the RAUC tryboot integration setting the flag directly (by writing /run/systemd/reboot-param). Testing shows this works with the way Supervisor invokes the reboot.

⚠️ However, when manually updating using rauc install, using just reboot seems to clear the reboot parameters! Instead systemctl reboot seems to preserve the parameters, so to test updates, one of these two options need to be used:

rauc install haos_rpi5-64-11.3.dev0.raucb
reboot "0 tryboot"
# or
systemctl reboot

This means that the new slot only gets booted when reboot is being used. This is a limitation of how tryboot works. 🤷‍♂️

@agners agners changed the title WIP: Initial Raspberry Pi 5 support Initial Raspberry Pi 5 support Dec 8, 2023
Copy link
Member

@sairon sairon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good and the changes are still quite sustainable, nice work!

There's bunch of minor issues I spotted on the first sight, see the comments in code. I will do some more testing here but so far the rest looks fine from the overall perspective 👍

buildroot-external/configs/rpi5_64_defconfig Outdated Show resolved Hide resolved
buildroot-external/configs/rpi5_64_defconfig Outdated Show resolved Hide resolved
mkdir -p "${BOOT_DATA}/slot-A/"
cp "${BINARIES_DIR}"/*.dtb "${BOOT_DATA}/slot-A/"
gzip --stdout "${BINARIES_DIR}"/Image > "${BOOT_DATA}/slot-A/kernel_2712.img"
cp "${BINARIES_DIR}"/*.dtbo "${BOOT_DATA}/slot-A/overlays/" 2>/dev/null || true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need BR2_PACKAGE_RPI_FIRMWARE=y in the board config, otherwise there will be no DT overlays, as we use those from that package.

Moreover, there should be almost always some overlays (at least in HAOS) - and this currently just fails because the target directory doesn't exist, so even the rpi-rf-mod overlays don't get copied.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the rpi-rf-mod overlays need testing first? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I've added now BR2_PACKAGE_RPI_FIRMWARE=y and an appropriate copy command.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, I wonder if we should do this differently: IMHO either we consider device tree and device tree overlays firmware, and we should both take from there, or we should build both and deploy our builds 🤔 ..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have to pick from those two options, then I vote for using self-built DTBs and overlays. We have to build and supply DTB for Yellow anyway and having the rest built from sources is IMHO more flexible and easier for maintenance than using those from the RPi repo.

Anyway it's been like this for ages and there's no urgency for changing that, but good point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to build and supply DTB for Yellow anyway and having the rest built from sources is IMHO more flexible and easier for maintenance than using those from the RPi repo.

So far we build and supply extra overlays through the rpi-rf-mod package, which is Homematic specific (speaking of which, maybe we should make that more clear in that package name 🤔 ). But other than that we do not supply overlays from the main Linux kernel source tree so far.

IMHO, the current situation is bad, as we mix the device tree from kernel source and overlays from the firmware.

Technically, the device tree is supposed to be provided by the machine's firmware. Like in the x86 world the ACPI tables are part of the BIOS. So there is definitely an argument to make that we should deploy device tree and kernel from the Raspberry Pi provided directory.

However, in the Arm world the boards are much more diverse, and quite often firmware (or part of the firmware) is bundled with the OS. That is also the case in Home Assistant OS: We deploy machine firmware along with the OS (and not just the device trees and overlay, but also Raspberry Pi's start4.elf, or U-Boot which on some boards can be seen as firmware). Now where the individual components of the "firmware" come from are almost implementation detail: The Raspberry Pi device trees and overlays are maintained in their Linux kernel source tree anyway. It is only a matter of do we deploy their pre-built one or do we deploy our own builds.

Deploying our own builds gives us more flexibility and proves to be less confusing/error-prone (as often the newer Linux kernel benefits from a newer/matching device tree).

So with this in mind, I agree let's deploy overlays from our build.

It seems that Buildroot doesn't support that use case yet. But it is a fairly simple extension for the Buildroot build system: home-assistant/buildroot#18.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far we build and supply extra overlays through the rpi-rf-mod package, which is Homematic specific (speaking of which, maybe we should make that more clear in that package name 🤔 ). But other than that we do not supply overlays from the main Linux kernel source tree so far.

Sorry, but didn't follow the discussions closely enough. So what is the exact issue with the rpi-rf-mod since I noticed that you removed its CONFIG options from the rpi5 config file? In fact, it perfectly builds and runs with a rpi5 and the device tree overlay is working nicely AFAICS.

IMHO, the current situation is bad, as we mix the device tree from kernel source and overlays from the firmware.

I am not really sure if this is exactly the case for the RaspberryPi stuff. In fact, AFAIK even for RaspberryPiOS the makers are not directly using the in-tree device tree overlay stuff but rather uses the pre-build rpi-firmware dtbo files from their repository. So I am quite unsure if this would not construct an additional issue here if you guys would now switch to using the dtbo files from the kernel tree rather than pulling them from the rpi-firmware package.

And again. why is disabling/removing the rpi-rf-mod.dtbo required ATM?

Copy link
Member Author

@agners agners Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, it perfectly builds and runs with a rpi5 and the device tree overlay is working nicely AFAICS.

Ok, I wasn't aware that this got tested already, so we can re-enable it if it's known to be working. However, with just these two set:

BR2_PACKAGE_RPI_RF_MOD=y
BR2_PACKAGE_RPI_RF_MOD_DTS=y

I noticed that rpi-rf-mod-rpi1.dtbo gets deployed (besides rpi-rf-mod.dtbo), which I think is just wrong for Raspberry Pi 5? This might be just a config issue, not sure.

Btw, you typically find the rationals behind a change in the individual commits (46fc170 in this case).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jens-maus any thought on the rpi1 mod file? It came in with this commit 9582183.

I am fine re-adding the two config symbols above, but I think we should cleanup the rpi-rf-mod package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's re-add them before merging and eventually address the rf-mod issues in another PR.

buildroot-external/board/raspberrypi/rpi5-64/cmdline.txt Outdated Show resolved Hide resolved
@agners agners requested a review from sairon December 8, 2023 17:45
agners and others added 9 commits December 11, 2023 12:00
Only match actual hexadecimal characters.
* buildroot fd1dc86f40...f13ad03408 (1):
  > linux: add in-tree device tree overlay support
No Raspberry Pi 5 specific device tree overlays are  available, drop RPi
RF mod for now.
* buildroot f13ad03408...07e08e01b2 (1):
  > linux: fix add in-tree device tree overlay support
Copy link
Member

@sairon sairon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good enough (or even better!) for beta testing - let's merge it to dev to make testing easier 🎉

@agners agners merged commit 8e1016d into dev Dec 12, 2023
2 checks passed
@agners agners deleted the add-rpi5 branch December 12, 2023 12:19
@mpadinhabrandao
Copy link

Shall we have a Christmas present? 🎁

Great work everyone 🎊

@KayGundhardt
Copy link

Hello everyone,

Two things first:

  • I would like to thank you very much for all your hard work: especially for finishing the beta so quickly. Really great!

  • I'm just a user and have no programming skills whatsoever.

Buuuuut I've been a very enthusiastic HA user for a very long time and would be happy to make my modest little contribution:

:)

Tried to get the beta running on my RPI5: attached is the log. Maybe this will help someone?

Let me know if I've done something wrong or can do something else for you!

Best wishes

Kay

logs.txt

@agners
Copy link
Member Author

agners commented Dec 18, 2023

Thanks for using Home Assistant 😄

Make sure to change to the beta or dev channel first. There is quite some discussions around it in the Community post e.g. #2844 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants