raspberrypi / linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
Other
11.08k stars 4.97k forks source link

Broken EFI Support in the Raspberry Pi Kernel #5543

Open alsldlflglhljlk opened 1 year ago

alsldlflglhljlk commented 1 year ago

Describe the bug

For some reason, compiling the Raspberry Pi kernel with EFI boot support breaks many features of Raspberry Pi OS. For example, I lose the following features when booting with EFI: • The ability for audio output • WiFi support • The ability to power off (I get [23634.13552] Rebooting system but it never turns off) • Bluetooth support • Crashes with overclocking • etc

However, when booting with the stock Debian kernel, have none of the above issues (except bluetooth), but I don't have /dev/gpiomem, /dev/vcio, nor /dev/vc-mem. This is why I wish to enable the EFI stub in the Raspberry Pi kernel.

Steps to reproduce the behaviour

  1. Download the latest kernel source git clone --depth=1 --branch=rpi-6.2.y https://github.com/raspberrypi/linux
  2. Download my configuration cd ./linux && make -j distclean && wget https://pastebin.com/raw/AVmn0AgF -O ./.config
  3. Update configuration in case anything has changed make -j oldconfig
  4. Compile the kernel make -j6 dtbs Image modules
  5. Install devicetree and modules make -j6 dtbs_install modules_install
  6. Paste the kernel in /boot sudo cp ./arch/arm64/boot/Image /boot
  7. Download EFI Firmware and unzip its contents in /boot.
  8. Reboot
  9. Press F1 when you see the Raspberry Pi Logo to enter the EFI Shell.
  10. Type fs0: in the EFI shell.
  11. Type Image root=/dev/mmcblk0p2 rootwait ro (replacing /dev/mmcblk0p2 with whatever device you boot from)

All of the above steps have been performed on a Raspberry Pi, I have not cross-compiled anything

Device (s)

Raspberry Pi 4 Mod. B

System

  1. cat /etc/rpi-issue Not found
  2. vcgencmd version Dec 12 2022 11:56:56 Copyright (c) 2021 Broadcom version ed6f6b8fcdc6476410b9cf75d141633461d34bdd (clean) (release) (start)
  3. uname -a Linux raspberrypi 6.2.16-v8+ #5 SMP PREEMT Sun Jul 16 18:48:02 CDT 2023 aarch64 GNU/Linux

Logs

No response

Additional context

No response

pelwell commented 1 year ago

Your config (when saved as a defconfig file) shows a lot of differences from bcm2711_defconfig:

$ diff arch/arm64/configs/bcm2711_defconfig  defconfig
2a3,4
> CONFIG_KERNEL_XZ=y
> CONFIG_DEFAULT_INIT="/sbin/init"
45c47
< CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
---
> CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/sda2 rootfstype=ext4 rootwait"
60a63,64
> CONFIG_NVHE_EL2_DEBUG=y
> CONFIG_PROTECTED_NVHE_STACKTRACE=y
65a70,72
> CONFIG_MODULE_SIG=y
> CONFIG_MODULE_SIG_FORCE=y
> CONFIG_MODULE_SIG_SHA512=y
66a74,75
> CONFIG_MODULE_DECOMPRESS=y
> CONFIG_TRIM_UNUSED_KSYMS=y
449a459
> CONFIG_FIRMWARE_MEMMAP=y
451c461,469
< # CONFIG_EFI_VARS_PSTORE is not set
---
> CONFIG_FW_CFG_SYSFS=m
> CONFIG_FW_CFG_SYSFS_CMDLINE=y
> CONFIG_SYSFB_SIMPLEFB=y
> CONFIG_EFI_ZBOOT=y
> CONFIG_EFI_BOOTLOADER_CONTROL=y
> CONFIG_EFI_CAPSULE_LOADER=y
> CONFIG_EFI_TEST=y
> CONFIG_RESET_ATTACK_MITIGATION=y
> CONFIG_EFI_COCO_SECRET=y
459a478
> CONFIG_ZRAM_DEF_COMP_ZSTD=y
465a485
> CONFIG_BCM2835_SMI=y
707a728
> CONFIG_I3C=m

What is the minimal set of changes needed to show the problem? I can ignore DEFAULT_INIT and CMDLINE changes.

pelwell commented 1 year ago

Have you tried using your custom kernel without the EFI firmware?

alsldlflglhljlk commented 1 year ago

Have you tried using your custom kernel without the EFI firmware?

@pelwell Yes, and the only advantage of doing so is the ability to power off / reboot.

pelwell commented 1 year ago

If the kernel works as expected without the EFI firmware (i.e. if you have audio output, WiFi support, e.tc.), then isn't the problem in the EFI firmware?

alsldlflglhljlk commented 1 year ago

@pelwell I'm currently recompiling the kernel with only a minimal set of changes.

CONFIG_FW_CFG_SYSFS=m CONFIG_FW_CFG_SYSFS_CMDLINE=y CONFIG_SYSFB_SIMPLEFB=y CONFIG_EFI_ZBOOT=y CONFIG_EFI_BOOTLOADER_CONTROL=y CONFIG_EFI_CAPSULE_LOADER=y CONFIG_EFI_TEST=y CONFIG_RESET_ATTACK_MITIGATION=y CONFIG_EFI_COCO_SECRET=y

is necessary because otherwise I wouldn't be able to see the earliest kernel messages and wouldn't be able to see if my kernel panicked at the very beginning.

alsldlflglhljlk commented 1 year ago

If the kernel works as expected without the EFI firmware (i.e. if you have audio output, WiFi support, e.tc.), then isn't the problem in the EFI firmware?

No, if I boot without the EFI firmware, I can power off correctly. That's the only difference.

pelwell commented 1 year ago

Ah, you mean difference from with EFI firmware, not difference from the standard kernel without EFI.

pelwell commented 1 year ago

I'm keen to try with a minimal set of changes when you have it. As I said, my limited set of changes showed no problems without the EFI firmware.

alsldlflglhljlk commented 1 year ago

(don't mind the crazy idea) Is it possible to patch the mainline kernel to include support for /dev/gpiomem, /dev/vcio, etc?

pelwell commented 1 year ago

Of course it's possible - you just need to copy across the drivers, config settings and possibly some Device Tree settings.

alsldlflglhljlk commented 1 year ago

Alas, it was not meant to be. I reconfigured my kernel with the smallest possible amount of changes to bcm2711_defconfig, but I still observe the same behaviours I described earlier. I think the best way to do this would be to copy over the required files to the mainline kernel. I think I know the drivers I'll need to copy over, but I'm not sure how to tell the configuration how to compile those drivers.