Group: Hardware/Components/GPUs/radeon/How to patch and test linux-libre in Parabola
Contents
How to patch and test linux-libre in Parabola
Warning: This tutorial is a work in progress and it's not finished yet. Feel free to help improving it.
Risks
The probability of breaking the GPU should be low as no GPUs have been broken in this process
However the probability of loosing some data is higher. If you have to power off your computer by pressing the power button for a long time, it may corrupt some data.
To mitigate the risk you can force your computer to check the filesystems at each boot for the duration of the test.
This way if there is some corruptions, you will be informed of it and it might be fixed by the filesystem check.
If you use ext4, that can easily be done with tune2fs. To do that, first write down the default values that your rootfs uses. Replace /dev/sda1 by the block devices of your rootfs. If you use LVM, encryption or other partitioning schemes, it might differ:
sudo tune2fs -l /dev/sda1
This will show the mount count and maximum mount count:
[...] Mount count: 15 Maximum mount count: 30 [...]
Write it down if you want to restore it after the tests.
To force checking the filesystem at each boot you can use the following commands:
sudo tune2fs -c 1 /dev/sda1 sudo tune2fs -C 1 /dev/sda1
Other setup required for testing
TODO:
- /etc/default/grub: GRUB_CMDLINE_LINUX_DEFAULT: modprobe.blacklist=radeon
- ?
First verify if your GPU is supported by the lastest linux-libre
Parabola usually have very recent linux-libre versions, so if you already have linux-libre installed it is usually good.
TODO: add radeon to modprobe.blacklist and don't start graphical sessions.
Once you booted on that kernel, look if the radeon driver loaded.
TODO: Document how to do that.
If the radeon driver still doesn't work with the lastest version of linux-libre you can safely proceed to the next section.
Patching linux-libre
First get the linux-libre source scripts. I find it handy to download the git version as I'm used to git:
git clone https://jxself.org/git/linux-libre.git cd linux-libre git checkout deblob-5.3.4-gnu -b radeon-test
After doing that, I patched the deblob-5.3 file to:
- add a clean_sed line for the driver, so it would not fail if the firmware is absent
- Move the reject_firmware and clean_blob before the clean_sed as it is done this way for other Radeon GPUs
clean_blob drivers/gpu/drm/radeon/r100.c reject_firmware drivers/gpu/drm/radeon/r600.c clean_blob drivers/gpu/drm/radeon/r600.c +reject_firmware drivers/gpu/drm/radeon/ni.c +clean_blob drivers/gpu/drm/radeon/ni.c # Something like this might work on other radeon cards too. If you # have such cards, please give it a try, and report back either way, # so that we can make more cards work, or at least add comments so @@ -891,8 +893,9 @@ clean_sed ' clean_sed ' /r = r600_init_microcode(rdev);/,/}/ s,return r;,/*(DEBLOBBED)*/, ' drivers/gpu/drm/radeon/rv770.c 'enable blobless activation' -reject_firmware drivers/gpu/drm/radeon/ni.c -clean_blob drivers/gpu/drm/radeon/ni.c +clean_sed ' +/r = ni_init_microcode(rdev);/,/}/ s,return r;,/*(DEBLOBBED)*/, +' drivers/gpu/drm/radeon/ni.c 'enable blobless activation' reject_firmware drivers/gpu/drm/radeon/si.c clean_blob drivers/gpu/drm/radeon/si.c reject_firmware drivers/gpu/drm/radeon/cik.c
Deblobing Linux
Then I downloaded Linux 5.3.4. I used git as I like to be able to see the changes:
cd ../ git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git cd linux git checkout v5.3.4 -b radeon-test
I then ran the deblob-5.3.4 script:
../linux-libre/deblob-5.3
Building linux-libre
I then used the linux-libre build configuration from Parabola:
cd ../ git clone git://git.parabola.nu/abslibre.git cd ../linux-libre cp ../libre/linux-libre/config.x86_64 .config
Since we're already running the lastest version of linux-libre, which comes from Parabola, we need to make sure that the modules will be installed in a different directory. Adding -custom the the kernel version should work for that:
sed 's#^CONFIG_LOCALVERSION=".*"$#CONFIG_LOCALVERSION="-custom"#' -i .config
We can then proceed to compile the kernel:
jobs="-j$(grep processor /proc/cpuinfo | wc -l)" make -j${jobs} make -j${jobs} modules
This will take several hours, even on fast computers, because, as we have the same configuration than Parabola, it will compile many modules. The advantage of doing it this way is that Parabola already took care of selecting the modules required to operate the computer, so we don't need to spend hours and hours researching that. It also helps a lot with testing, as the modified Radeon driver will then be tested with configuration being used by a distribution using linux-libre. So this will decrease the probability of breaking software or hardware.
Installing the modified linux-libre
We then need to install the modules and the kernel image:
make modules_install install -t /boot/vmlinuz-linux-custom arch/x86/boot/bzImage
Once built and installed, we still need to boot on that kernel. To do that we need to:
- Generate an initramfs for it
- Update your bootloader's configuration.
To generate the initramfs, you need to add a configuration file in /etc/mkinitcpio.d/.
To do that you can add the following to /etc/mkinitcpio.d/linux-custom.preset:
ALL_config="/etc/mkinitcpio.conf" ALL_kver="/boot/vmlinuz-linux-custom" PRESETS=('default' 'fallback') default_image="/boot/initramfs-linux-custom.img" fallback_image="/boot/initramfs-linux-custom-fallback.img" fallback_options="-S autodetect"
You can then generate the initramfs with the following command:
sudo mkinitcpio -p linux-custom
Now that the initramfs is generated, you then need to update the bootloader configuration before booting, so it could add an entry with the linux-custom. For GRUB, that can be done with the following command:
sudo grub-mkconfig -o /boot/grub/grub.cfg
Booting and testing
To boot on linux-custom, just select it in the bootloader menu during the boot.
Then you need to login inside the text console.
Once this is done it's advised to clear the kernel log, so that, after loading the radeon module, it will make it easier to retrieve the kenrel logs that are generated by the radeon driver. This can be done with the following command:
sudo dmesg -c
You can then load the radeon driver with the following command:
sudo modprobe radeon
If you have a black screen, something went wrong.
If not, the console typically gets black for less than 10 seconds, and then the display comes back with an increased resolution. It's also a good idea to use the laptop a bit to capture the log and so on to make sure that the laptop was still usable after loading the module.
After loading the radeon module, you can finally look at the new kernel messages with the following command:
dmesg
It should print something like that:
Linux agpgart interface v0.103 [drm] radeon kernel modesetting enabled. radeon 0000:00:01.0: remove_conflicting_pci_framebuffers: bar 0: 0xe0000000 -> 0xefffffff radeon 0000:00:01.0: remove_conflicting_pci_framebuffers: bar 2: 0xf0280000 -> 0xf02bffff radeon 0000:00:01.0: vgaarb: deactivate vga console Console: switching to colour dummy device 80x25 [drm] initializing kernel modesetting (ARUBA 0x1002:0x990B 0x1002:0x990B 0x00). ATOM BIOS: 113 radeon 0000:00:01.0: VRAM: 512M 0x0000000000000000 - 0x000000001FFFFFFF (512M used) radeon 0000:00:01.0: GTT: 1024M 0x0000000020000000 - 0x000000005FFFFFFF [drm] Detected VRAM RAM=512M, BAR=256M [drm] RAM width 64bits DDR [TTM] Zone kernel: Available graphics memory: 3809790 KiB [TTM] Zone dma32: Available graphics memory: 2097152 KiB [TTM] Initializing pool allocator [TTM] Initializing DMA pool allocator [drm] radeon: 512M of VRAM memory ready [drm] radeon: 1024M of GTT memory ready. [drm] Loading ARUBA Microcode 0000:00:01.0: Missing Free firmware (non-Free firmware loading is disabled) ni_cp: Failed to load firmware "/*(DEBLOBBED)*/" [drm:cayman_init [radeon]] *ERROR* Failed to load firmware! [drm] Internal thermal controller without fan control [drm] radeon: power management initialized 0000:00:01.0: Missing Free firmware (non-Free firmware loading is disabled) radeon 0000:00:01.0: radeon_uvd: Can't load firmware "/*(DEBLOBBED)*/" radeon 0000:00:01.0: failed UVD (-2) init. 0000:00:01.0: Missing Free firmware (non-Free firmware loading is disabled) radeon 0000:00:01.0: radeon_vce: Can't load firmware "/*(DEBLOBBED)*/" radeon 0000:00:01.0: failed VCE (-2) init. [drm] GART: num cpu pages 262144, num gpu pages 262144 [drm] PCIE GART of 1024M enabled (table at 0x0000000000040000). radeon 0000:00:01.0: WB enabled radeon 0000:00:01.0: fence driver on ring 0 use gpu addr 0x0000000020000c00 and cpu addr 0x00000000e742fc62 radeon 0000:00:01.0: fence driver on ring 1 use gpu addr 0x0000000020000c04 and cpu addr 0x0000000055d88f08 radeon 0000:00:01.0: fence driver on ring 2 use gpu addr 0x0000000020000c08 and cpu addr 0x000000007193ef67 radeon 0000:00:01.0: fence driver on ring 3 use gpu addr 0x0000000020000c0c and cpu addr 0x00000000f260dfaf radeon 0000:00:01.0: fence driver on ring 4 use gpu addr 0x0000000020000c10 and cpu addr 0x0000000013e54c0e [drm] Supports vblank timestamp caching Rev 2 (21.10.2013). [drm] Driver supports precise vblank timestamp query. radeon 0000:00:01.0: radeon: MSI limited to 32-bit radeon 0000:00:01.0: radeon: using MSI. [drm] radeon: irq initialized. [drm:cayman_startup [radeon]] *ERROR* radeon: IH init failed (-22). radeon 0000:00:01.0: disabling GPU acceleration [drm] radeon atom DIG backlight initialized [drm] Radeon Display Connectors [drm] Connector 0: [drm] eDP-1 [drm] HPD1 [drm] DDC: 0x6530 0x6530 0x6534 0x6534 0x6538 0x6538 0x653c 0x653c [drm] Encoders: [drm] LCD1: INTERNAL_UNIPHY2 [drm] Connector 1: [drm] VGA-1 [drm] HPD2 [drm] DDC: 0x6540 0x6540 0x6544 0x6544 0x6548 0x6548 0x654c 0x654c [drm] Encoders: [drm] CRT1: INTERNAL_UNIPHY2 [drm] CRT1: NUTMEG [drm] Connector 2: [drm] HDMI-A-1 [drm] HPD3 [drm] DDC: 0x6550 0x6550 0x6554 0x6554 0x6558 0x6558 0x655c 0x655c [drm] Encoders: [drm] DFP1: INTERNAL_UNIPHY [drm] fb mappable at 0xE0241000 [drm] vram apper at 0xE0000000 [drm] size 4325376 [drm] fb depth is 24 [drm] pitch is 5632 fbcon: radeondrmfb (fb0) is primary device Console: switching to colour frame buffer device 170x48 radeon 0000:00:01.0: fb0: radeondrmfb frame buffer device [drm] Initialized radeon 2.50.0 20080528 for 0000:00:01.0 on minor 0
You can easily save it to a file with the following command:
sudo dmesg > radeon_test.log
Along with the patch, that information can be useful for linux-libre.
At this point, since everything went fine, you can send the patch to the linux-libre mailing list, along with the log and your observations that everything went fine (the display worked, the resolution increased, etc).
At this point you can also try the radeon driver for Xorg but it may or may not work as some of the features sometimes rely on 3D acceleration. Alternative drivers like "modesettings" are usually available and Xorg can be configured to use that instead of the Radeon driver.