Mainlining FAQ: Difference between revisions
→Can I do it without a serial cable?: add more details |
→There's no device tree source (dts) in the kernel fork for my device, how do I make one?: add downstream -> android stable -> mainline idea and docs |
||
Line 47: | Line 47: | ||
See also: {{github|1021}} | See also: {{github|1021}} | ||
Consider updating your device's kernel to the latest Android stable version first ([https://github.com/android-linux-stable/notes these instruction] might make it easier to convert the board files to dtbs) and then going to real mainline from there. | |||
== What options are needed to get USB network? == | == What options are needed to get USB network? == |
Revision as of 21:00, 16 March 2018
"Mainlining isn't fun, but it's hella rewarding"
Various information collected from #postmarketOS. See The Mainline Kernel for a more howto-style page.
How to start?
- Serial cable highly recommended
- First step will be to find out how much your device is already supported by mainline
- Check if your soc is supported.. that will be basic building block
- There's really no point doing display till you have uart or USB working
Serial cable
Can I do it without a serial cable?
- you can try
- but doing it blindly is painful
- once it reliably boots though, and USB comes up properly, you can use the USB serial gadget in the kernel (see below)
- logging to RAM instead of serial:
- requirement is that your kernel starts init in the initramfs
- on msm8974 at least (and probably all qcom devices), reboot to bootloader doesnt clear memory
- so you can use that to get a log (write to a fixed address and read it back from twrp with /dev/mem)
- more detailed: in the initramfs (e.g. postmarketOS initramfs hook), copy /dev/kmsg to the reserved region in /dev/mem and write the reboot registers
- not as good as uart but good enough
How to get serial output? (serial cable)
- enable the serial device for your kernel (e.g. for OMAP: CONFIG_SERIAL_OMAP and CONFIG_SERIAL_OMAP_CONSOLE)
- add console=ttySAC0,115200 to the kernel cmdline
- it might also be ttyO0 (uppercase O for OMAP chipset)
How to get serial output over USB? (USB serial gadget)
The Linux kernel can act like a serial device, and it's possible to output what you would get on the serial port over that fake serial device directly via USB to your PC.
- set CONFIG_USB_G_SERIAL=y and enable USB as console, and add console=ttyGS0,115200 to the cmdline
Is it possible to boot kernels with a serial cable?
- No. Just flash with a normal cable and switch to the serial cable to read the log output.
- Once it reliably boots though, and USB comes up properly, you can use the USB serial gadget in the kernel
There's no device tree source (dts) in the kernel fork for my device, how do I make one?
Previous kernels used board-*.c
files instead of the dts
files. These are in folders such as arch/arm/mach-omap2
(example).
The idea is that you'll need to convert these to dts
files. Doing so manually for each of them is a huge and error-prone task, better use one of the following techniques:
- Strip down
dts
from similar hardware (n900 in case of omap3?) and try to get it to boot - Add support to an existing mainline driver (e.g. mms144 and mms114 are probably pretty similar) rather than forward-porting the old driver
- Forward-port the board files to recent kernels (new kernels still understand board files for some hardware, but not for all!), then strip them down to a bare minimum you can still test (where serial or usb is still working, so you know that the device boots), and then convert that do
dts
.
Finding the best approach is very hardware specific. If you know C and think you have tried some of the methods above without success, consider asking the maintainers of the chipset in the kernel. Regarding OMAP, Pavel offered that you could CC him.
See also: #1021
Consider updating your device's kernel to the latest Android stable version first (these instruction might make it easier to convert the board files to dtbs) and then going to real mainline from there.
What options are needed to get USB network?
- USB_ETH IIRC
- also check the defconfig in aports/main/linux-postmarketos-mainline
How to make OpenRC print its output to the serial port?
- just set
RC_LOGGING
to true in /etc/rc.conf - (it's the init system log like Starting etc.....[ok])
How can I compile kernel sources from a local git repo?
- Clone the kernel with git (~5GB!)
- Use the following command to build the mainline kernel package with the checked out sources
$ pmbootstrap build linux-postmarketos-mainline --src=~/code/linux
How can I repackage the initramfs with custom modules?
Run a normal installation to generate the initramfs:
$ pmbootstrap install
And then writing a short shell script, that repackages the postmarketOS initramfs with the modules you compiled. After reading through it, adjust it as needed and execute it as root:
#!/bin/sh
# Config
device="oneplus-bacon"
tmpdir="/tmp/pmOS-initfs-with-mainline-modules"
work="$(pmbootstrap -q config work)"
# Create temp folder
[ -d "$tmpdir" ] && rm -rf "$tmpdir"
mkdir -p "$tmpdir"
# Extract the pmOS initramfs
cp -v "$work/chroot_rootfs_$device/boot/initramfs-"* initramfs.gz
gzip -d initramfs.gz
cpio -i < initramfs
# Remove existing modules
rm -rf initramfs lib/modules
#
# CHANGEME: you need to write the commands that copy the kernel modules from your
# kernel source folder into the initramfs here!
#
# Package the initramfs again
cd "$tmpdir"
find . -print0 | busybox cpio --quiet -o -H newc | gzip -1 > initramfs-repackaged
How to merge kernel configs?
The idea is, that we have a shared linux-postmarketos-stable
package, which all mainlined devices use. Check Kernel_configuration#Automatically_merging_kernel_configuration for instructions on how to merge kernel configs somewhat efficiently with a script.