Difference between revisions of "PineNote Development/Building Kernel"

From PINE64
Jump to navigation Jump to search
(→‎Steps to build: wiki style)
(Fix)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= Building the Kernel =
This page contains information on how to build a linux kernel for the [[PineNote]].


After followed [https://github.com/DorianRudolph/pinenotes#starter-guide Dorian's directions] to get Arch installed you've seen someone [https://github.com/m-weigand/mw_pinenote_misc/blob/main/videos/20220808_bw_dither_mode_picture_doom_video_small.mp4 playing DOOM]  and you want to learn how to get the features that enable that kind of performance. To get your PN running this smoothly, we'll need to build our own kernel. There are two kernel efforts underway right now:
== Available Kernel Repositories ==
 
The following (incomplete?) PineNote-specific kernel repositories are available:
 
* https://github.com/m-weigand/linux/ (based mainly on the repository from smaeul, with additional patches pulled in from other sources, Debian packages available)
* https://gitlab.com/pgwipeout/linux-next/
* https://github.com/smaeul/linux/tree/rk35/pinenote-next
 
== Building the kernel ==
 
{{Info|These following instructions need to be cleaned up and updated, and OS-specific information and tweaks should be moved elsewhere}}
 
After following [https://github.com/DorianRudolph/pinenotes#starter-guide Dorian's directions] to get Arch installed you've seen someone [https://github.com/m-weigand/mw_pinenote_misc/blob/main/videos/20220808_bw_dither_mode_picture_doom_video_small.mp4 playing DOOM]  and you want to learn how to get the features that enable that kind of performance. To get your PN running this smoothly, we'll need to build our own kernel. There are two kernel efforts underway right now:


# pgwipeout: https://gitlab.com/pgwipeout/linux-next
# pgwipeout: https://gitlab.com/pgwipeout/linux-next
Line 18: Line 30:
{{info|If anyone reading this has recommended reading for how we can understand what may damage our panels (IE is the risk in fast updates? The types of updates? something more complicated?), please add it here!}}
{{info|If anyone reading this has recommended reading for how we can understand what may damage our panels (IE is the risk in fast updates? The types of updates? something more complicated?), please add it here!}}


== What you should have already done ==
=== What you should have already done ===


I assume you've already got an operating system installed on your Pinenote other than the stock Android. Doing this isn't trivial, but it is well understood -- you will be following the footsteps of many others. Dorian Rudolph made a guide for doing this, available [https://github.com/DorianRudolph/pinenotes#starter-guide here].
It is assumed you've already got an operating system installed on your Pinenote other than the stock Android. Doing this isn't trivial, but it is well understood - you will be following the footsteps of many others. Dorian Rudolph made a guide for doing this, available [https://github.com/DorianRudolph/pinenotes#starter-guide here].


== What do you need to know? ==
=== What do you need to know? ===


If you followed Dorian's guide to get here and felt semi-comfortable, you'll be fine. This is no more complicated than that. If you are intimidated, that's okay! I'll still encourage you to try :) you will learn a lot, just be patient and don't put any data on your PineNote that you wouldn't be okay losing. If you run into trouble, ask for help in the [https://discord.com/invite/pine64 Discord]/[https://matrix.to/#/#pinenote:matrix.org Matrix]. Please try to solve problems on your own first, and then ask for help -- if nobody replies, please be patient and ask again soon.
If you followed Dorian's guide to get here and felt semi-comfortable, you'll be fine. This is no more complicated than that. If you are intimidated, that's okay! I'll still encourage you to try :) you will learn a lot, just be patient and don't put any data on your PineNote that you wouldn't be okay losing. If you run into trouble, ask for help in the [https://discord.com/invite/pine64 Discord]/[https://matrix.to/#/#pinenote:matrix.org Matrix]. Please try to solve problems on your own first, and then ask for help -- if nobody replies, please be patient and ask again soon.


== Steps to build ==
=== Steps to build ===


1. Clone Maximilian's scripts:
1. Clone Maximilian's scripts:


<code> $ git clone https://github.com/m-weigand/mw_pinenote_misc.git</code>
$ git clone https://github.com/m-weigand/mw_pinenote_misc.git
 
2. Make a separate directory for patching the kernel. Then run Maximilian's ''clone_and_prepare_git.sh''. This will clone smaeul's kernel and a number of patches. Read the script to see which patches it is using. Feel free to open the patches too -- it's helpful to get a slim idea of what's going on, if only looking at the commit messages in them:


2. Make a separate directory for patching the kernel. Then run Maximilian's <code>clone_and_prepare_git.sh</code>. This will clone smaeul's kernel and a number of patches. Read the script to see which patches it is using. Feel free to open the patches too -- it's helpful to get a slim idea of what's going on, if only looking at the commit messages in them:
<pre>
  $ cd ../
  $ cd ../
  $ sh mw_pinenote_misc/custom_kernel/clone_and_prepare_git.sh
  $ sh mw_pinenote_misc/custom_kernel/clone_and_prepare_git.sh
</pre>


3. Compile the kernel:
3. Compile the kernel:


<pre> $ sh ./mw_pinenote_misc/custom_kernel/compile.sh </pre>
$ sh ./mw_pinenote_misc/custom_kernel/compile.sh
4. Next we want to perform the work captured in <code>install_to_pn.sh</code>, but the work may vary slightly from person to person. For example, I believe Maximilian is running Debian Sid, and I am running Manjaro -- because of this, and personal preference, some of our files live at different places. As long as you put them somewhere and configure your <code>extlinux.conf</code> to point at it, things will be okay. Looking at <code>install_to_pn.sh</code>, we can see that there are three pieces to installing the kernel: the kernel image (called <code>Image</code>), the device tree (<code>rk3566-pinenote-v1.2.dtb</code>), and the modules. All of these files have been compiled and placed into the <code>linux/pack</code> folder. The easiest way to send these over is by using scp or rsync -- read the script and decide how you would like to get your files in the correct location. You may need to install rsync on your PineNote if it doesn't already have it.
 
4. Next we want to perform the work captured in '''install_to_pn.sh''', but the work may vary slightly from person to person. As long as you put them somewhere and configure your '''extlinux.conf''' to point at it, things will be okay. Looking at '''install_to_pn.sh''', we can see that there are three pieces to installing the kernel: the kernel image (called ''Image''), the device tree (''rk3566-pinenote-v1.2.dtb''), and the modules. All of these files have been compiled and placed into the '''linux/pack''' folder. The easiest way to send these over is by using ''scp'' or ''rsync'' - read the script and decide how you would like to get your files in the correct location. You may need to install ''rsync'' on your PineNote if it doesn't already have it.


5. DTB was installed like this: <code>$ scp rk3566-pinenote-v1.2.dtb root@pinenote:/boot/dtbs/rockchip/</code>
5. DTB was installed like this: <code>$ scp rk3566-pinenote-v1.2.dtb root@pinenote:/boot/dtbs/rockchip/</code>


6. After installing the DTB as above, I updated my <code>/boot/extlinux/extlinux.conf</code> to point to this new file (previously, my dtb did not have the <code>-v1.2</code> on the end).
6. After installing the DTB as above, the file '''/boot/extlinux/extlinux.conf''' may be updated to point to this new file
 
7. (Perhaps not necessary?) The last step is to generate a new initrd image (see [https://en.wikipedia.org/wiki/Initial_ramdisk Wikipedia] for an explanation about initial ramdisk). This is done on the PineNote itself. Send Maximilian's installation script over and run it. Then place the generated image (from the last step of the shell script) into your boot partition and update '''extlinux.conf''' if needed to point at this new file.


7. (Perhaps not necessary?) The last step is to generate a new initrd image. (If you're like me and don't know what initrd is, the [https://en.wikipedia.org/wiki/Initial_ramdisk wiki] is very enlightening.) This is done on the PineNote itself. Send Maximilian's installation script over and run it. Then place the generated image (from the last step of the shell script) into your boot partition and update <code>extlinux.conf</code> if needed to point at this new file. 
<pre>
  $ scp initrd/gen_uboot_image.sh root@pinenote:/root # Do this part on local to put script on PN
  $ scp initrd/gen_uboot_image.sh root@pinenote:/root # Do this part on local to put script on PN
  $ ssh root@pinenote # Or use UART, the dongle + picocom, and change to root
  $ ssh root@pinenote # Or use UART, the dongle + picocom, and change to root
Line 55: Line 67:
  $ mv initrd.img /boot/initrd.img
  $ mv initrd.img /boot/initrd.img
  $ vim /boot/extlinux/extlinux.conf # Update this to reference this new initrd image
  $ vim /boot/extlinux/extlinux.conf # Update this to reference this new initrd image
</pre>


8. At this point your kernel is in place! However, there are a few more steps you may need to complete to ensure the display and networking continue to work:
8. At this point your kernel is in place! However, there are a few more steps you may need to complete to ensure the display and networking continue to work:
* For display, you may need to change <code>/lib/firmware/waveform.bin</code> to <code>/lib/firmware/rockchip/ebc.wbf</code> (TODO is this a difference between PG and smaeul's kernel? or a patch?)
* For display, you may need to change '''/lib/firmware/waveform.bin''' to '''/lib/firmware/rockchip/ebc.wbf''' (TODO: is this a difference between PG and smaeul's kernel or a patch?)
* For networking (and I imagine more as well), you may need to change <code>/lib/firmware/pinenote.bin</code> to <code>/lib/firmware/pinenote-v1.2.bin</code>
* For networking, you may need to change '''/lib/firmware/pinenote.bin''' to '''/lib/firmware/pinenote-v1.2.bin'''


9. This part technically isn't kernel specific, but we need to install a patched version of Mesa. If you are running an Arch based system, you're in luck! occam_razor provides prebuilt patched packages (say that 5 times fast) [https://github.com/0cc4m/pinenote-misc/releases here]. Simply extract these files, send them to PN, and install them using the package manager. You can also patch it yourself by looking at Maximilian's [https://github.com/m-weigand/mw_pinenote_misc/blob/main/compile_mesa.sh compile_mesa.sh]. {{info|If you frequently update your system with something `pacman -Syu`, you will end up updating these packages and losing the patches. Add this line to your <code>/etc/pacman.conf</code> to prevent them from being updated: <pre>IgnorePkg = libva-mesa-driver mesa mesa-debug mesa-vdpau opencl-mesa vulkan-mesa-layers vulkan-broadcom vulkan-panfrost vulkan-radeon vulkan-swrast</pre>}}
9. This part technically isn't kernel specific, but we need to install a patched version of Mesa. If you are running an Arch based system, you're in luck! occam_razor provides prebuilt patched packages (say that 5 times fast) [https://github.com/0cc4m/pinenote-misc/releases here]. Simply extract these files, send them to PN, and install them using the package manager. You can also patch it yourself by looking at Maximilian's [https://github.com/m-weigand/mw_pinenote_misc/blob/main/compile_mesa.sh compile_mesa.sh].  


10. To ensure the GPU stays on, we need to use Maximilian's [https://github.com/m-weigand/mw_pinenote_misc/blob/main/systemd/mweigand_eglinfo.service mweigand_eglinfo.service]. The Readme.md in that same directory has instructions for how to install this, but basically we need to copy it to <code>/etc/systemd/system/</code>, run <code>sudo systemctl daemon-reload</code> to make sure systemd knows it exists, then execute <code>sudo systemctl enable mweigand_eglinfo.service</code>.
{{Info|If you frequently update your system with ''pacman -Syu'', you will end up updating these packages and losing the patches. Add this line to your <code>/etc/pacman.conf</code> to prevent them from being updated: <pre>IgnorePkg = libva-mesa-driver mesa mesa-debug mesa-vdpau opencl-mesa vulkan-mesa-layers vulkan-broadcom vulkan-panfrost vulkan-radeon vulkan-swrast</pre>}}


= Next Steps =
10. To ensure the GPU stays on, we need to use Maximilian's [https://github.com/m-weigand/mw_pinenote_misc/blob/main/systemd/mweigand_eglinfo.service mweigand_eglinfo.service]. The ''Readme.md'' in that same directory has instructions for how to install this, but basically we need to copy it to '''/etc/systemd/system/''', run <code>sudo systemctl daemon-reload</code> to make sure systemd knows it exists, then execute <code>sudo systemctl enable mweigand_eglinfo.service</code>.
== Configuring the driver ==
The driver has several options that can improve performance. These can be read about [https://github.com/m-weigand/mw_pinenote_misc/tree/main/rockchip_ebc/patches#new-features-as-of-2022august08 here]. Personally, I use <code>rockchip_ebc.bw_mode=1 rockchip_ebc.default_waveform=1 rockchip_ebc.refresh_threshold=30 rockchip_ebc.auto_refresh=1</code> to make the image lower quality, but much faster to update. The auto_refresh setting is also essential to clear ghosting which will otherwise accrue on screen. I added the above settings the <code>APPEND</code> line in my <code>extlinux.conf</code> to make sure they are applied on boot.


== Fixing Suspend ==
== Next steps ==
If you're using a logind system, edit your <code>/etc/systemd/logind.conf</code> config. More information on what to do [https://wiki.archlinux.org/title/Power_management#ACPI_event in Arch's documentation].
=== Configuring the driver ===
The driver has several options that can improve performance. These can be read about [https://github.com/m-weigand/mw_pinenote_misc/tree/main/rockchip_ebc/patches#new-features-as-of-2022august08 here].  <code>rockchip_ebc.bw_mode=1 rockchip_ebc.default_waveform=1 rockchip_ebc.refresh_threshold=30 rockchip_ebc.auto_refresh=1</code> may be used to make the image lower quality, but much faster to update. The auto_refresh setting is also essential to clear ghosting which will otherwise accrue on screen. The ''APPEND'' line in the '''extlinux.conf''' might be added to make sure they are applied on boot.


== Configuring your apps ==
=== Fixing suspend ===
If you're using a logind system, edit your '''/etc/systemd/logind.conf''' config. More information on what to do [https://wiki.archlinux.org/title/Power_management#ACPI_event in Arch's documentation].
 
=== Configuring your apps ===
See [https://wiki.pine64.org/wiki/PineNote_Development/Apps this page].
See [https://wiki.pine64.org/wiki/PineNote_Development/Apps this page].


== Booting Linux instead of Android ==
=== Booting Linux instead of Android ===
[[PineNote Development/Booting Linux]]
[[PineNote Development/Booting Linux]]


== Fixing Bluetooth ==
=== Fixing Bluetooth ===
See [[PineNote Development/Software Tweaks]]
See [[PineNote Development/Software Tweaks]]
[[Category:PineNote]]

Latest revision as of 18:55, 14 April 2023

This page contains information on how to build a linux kernel for the PineNote.

Available Kernel Repositories

The following (incomplete?) PineNote-specific kernel repositories are available:

Building the kernel

Note: These following instructions need to be cleaned up and updated, and OS-specific information and tweaks should be moved elsewhere

After following Dorian's directions to get Arch installed you've seen someone playing DOOM and you want to learn how to get the features that enable that kind of performance. To get your PN running this smoothly, we'll need to build our own kernel. There are two kernel efforts underway right now:

  1. pgwipeout: https://gitlab.com/pgwipeout/linux-next
  2. smaeul: https://github.com/smaeul/linux/tree/rk35/pinenote-next

We'll be using smaeul's kernel + some additional patches provided by DorianRudolph, pgwipeout, Maximilian Weigand, occam_razor, and hrdl. Thanks so much to them, and all the other users who have worked on piecing together drivers, twiddling configs, answering questions, and sharing their work in other ways. Brava!

Perhaps the main component of the kernel is the DRM driver. You can read more about the driver by reading Smaeul's RFC.

A small warning

This guide is completely based off of the scripts provided by Maximilian. We'll be cloning and running them, but he owns them and he -- or others -- might change them. It's smart to have a look at what's going on, check when this page was last updated vs when his scripts were last updated, etc. Be nimble!

Additionally, as Maximilian warns here, these changes are all experimental and may damage your panel.

Note: If anyone reading this has recommended reading for how we can understand what may damage our panels (IE is the risk in fast updates? The types of updates? something more complicated?), please add it here!

What you should have already done

It is assumed you've already got an operating system installed on your Pinenote other than the stock Android. Doing this isn't trivial, but it is well understood - you will be following the footsteps of many others. Dorian Rudolph made a guide for doing this, available here.

What do you need to know?

If you followed Dorian's guide to get here and felt semi-comfortable, you'll be fine. This is no more complicated than that. If you are intimidated, that's okay! I'll still encourage you to try :) you will learn a lot, just be patient and don't put any data on your PineNote that you wouldn't be okay losing. If you run into trouble, ask for help in the Discord/Matrix. Please try to solve problems on your own first, and then ask for help -- if nobody replies, please be patient and ask again soon.

Steps to build

1. Clone Maximilian's scripts:

$ git clone https://github.com/m-weigand/mw_pinenote_misc.git

2. Make a separate directory for patching the kernel. Then run Maximilian's clone_and_prepare_git.sh. This will clone smaeul's kernel and a number of patches. Read the script to see which patches it is using. Feel free to open the patches too -- it's helpful to get a slim idea of what's going on, if only looking at the commit messages in them:

$ cd ../
$ sh mw_pinenote_misc/custom_kernel/clone_and_prepare_git.sh

3. Compile the kernel:

$ sh ./mw_pinenote_misc/custom_kernel/compile.sh

4. Next we want to perform the work captured in install_to_pn.sh, but the work may vary slightly from person to person. As long as you put them somewhere and configure your extlinux.conf to point at it, things will be okay. Looking at install_to_pn.sh, we can see that there are three pieces to installing the kernel: the kernel image (called Image), the device tree (rk3566-pinenote-v1.2.dtb), and the modules. All of these files have been compiled and placed into the linux/pack folder. The easiest way to send these over is by using scp or rsync - read the script and decide how you would like to get your files in the correct location. You may need to install rsync on your PineNote if it doesn't already have it.

5. DTB was installed like this: $ scp rk3566-pinenote-v1.2.dtb root@pinenote:/boot/dtbs/rockchip/

6. After installing the DTB as above, the file /boot/extlinux/extlinux.conf may be updated to point to this new file

7. (Perhaps not necessary?) The last step is to generate a new initrd image (see Wikipedia for an explanation about initial ramdisk). This is done on the PineNote itself. Send Maximilian's installation script over and run it. Then place the generated image (from the last step of the shell script) into your boot partition and update extlinux.conf if needed to point at this new file.

$ scp initrd/gen_uboot_image.sh root@pinenote:/root # Do this part on local to put script on PN
$ ssh root@pinenote # Or use UART, the dongle + picocom, and change to root
$ cd /root
$ ./gen_uboot_image.sh
$ mv initrd.img /boot/initrd.img
$ vim /boot/extlinux/extlinux.conf # Update this to reference this new initrd image

8. At this point your kernel is in place! However, there are a few more steps you may need to complete to ensure the display and networking continue to work:

  • For display, you may need to change /lib/firmware/waveform.bin to /lib/firmware/rockchip/ebc.wbf (TODO: is this a difference between PG and smaeul's kernel or a patch?)
  • For networking, you may need to change /lib/firmware/pinenote.bin to /lib/firmware/pinenote-v1.2.bin

9. This part technically isn't kernel specific, but we need to install a patched version of Mesa. If you are running an Arch based system, you're in luck! occam_razor provides prebuilt patched packages (say that 5 times fast) here. Simply extract these files, send them to PN, and install them using the package manager. You can also patch it yourself by looking at Maximilian's compile_mesa.sh.

Note: If you frequently update your system with pacman -Syu, you will end up updating these packages and losing the patches. Add this line to your /etc/pacman.conf to prevent them from being updated:
IgnorePkg = libva-mesa-driver mesa mesa-debug mesa-vdpau opencl-mesa vulkan-mesa-layers vulkan-broadcom vulkan-panfrost vulkan-radeon vulkan-swrast

10. To ensure the GPU stays on, we need to use Maximilian's mweigand_eglinfo.service. The Readme.md in that same directory has instructions for how to install this, but basically we need to copy it to /etc/systemd/system/, run sudo systemctl daemon-reload to make sure systemd knows it exists, then execute sudo systemctl enable mweigand_eglinfo.service.

Next steps

Configuring the driver

The driver has several options that can improve performance. These can be read about here. rockchip_ebc.bw_mode=1 rockchip_ebc.default_waveform=1 rockchip_ebc.refresh_threshold=30 rockchip_ebc.auto_refresh=1 may be used to make the image lower quality, but much faster to update. The auto_refresh setting is also essential to clear ghosting which will otherwise accrue on screen. The APPEND line in the extlinux.conf might be added to make sure they are applied on boot.

Fixing suspend

If you're using a logind system, edit your /etc/systemd/logind.conf config. More information on what to do in Arch's documentation.

Configuring your apps

See this page.

Booting Linux instead of Android

PineNote Development/Booting Linux

Fixing Bluetooth

See PineNote Development/Software Tweaks