General question: So that I can work on this with most ease, can you tell what is the easiest way to recompile and flash on nexus 5 a modified version of the kernel (with just few modifications in some source files)?
Such a thing does not exist I think this is something that could done by pmbootstrap. The workflow is outlined below.
Set up envkernel
$ source pmbootstrap/helpers/envkernel.sh$ make <defconfig>
Incremental compiles
$ make# Flash the kernel# Modify source code# Incremental compile$ make# Flash the updated kernel# Modify source code again# Incremental compile$ make# Flash the updated kernel# etc...
The step we are missing is a way to flash incrementally compiled kernels. What could be implemented in pmbootstrap:
Installing an updated kernel
Leverage mkinitfs to package boot image with kernel compiled in envkernel(?)
Possible methods to flash an updated kernel:
a. Use flasher to install incrementally compiled kernel. $ pmbootstrap flasher flash_kernel
b. Push boot image to device. Write boot partition with dd if=boot.img of=/dev/mmcblkXpY Dangerous: Easy to mistakenly write the wrong partition
c. Package AnyKernel updater with the zImage from envkernel. Then adb sideload the package.
d. Build kernel apk package from envkernel ???
Edited
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
That's funny because I would have said that re-flashing the kernel was the easy part. (and that something like "sudo fastboot flash kernel zImage" would do good while taking few seconds).
If you can explain in details how to incrementally xcompile and modify kernel sources/config for a given device starting from current state of sources, I would be very interested, it would probably avoid me many trial and error testing.
That's funny because I would have said that re-flashing the kernel was the easy part. (and that something like "sudo fastboot flash kernel zImage" would do good while taking few seconds).
Devices can differ in the flashing process. Some devices don't even have fastboot. While there may be easier ways to update a kernel for some devices that may not be the case for all. This is somethign that pmbootstrap could possibly handle in device agnostic way behind the scenes.
If you can explain in details how to incrementally xcompile and modify kernel sources/config for a given device starting from current state of sources, I would be very interested, it would probably avoid me many trial and error testing.
Run make <defconfig> on the first compile and subsequently if the config is modified. When the source code is modified run make to do an incremental compile.
The step that is device specific is flashing the the compiled kernel.
The zImage will be in .output/arch/arm/boot/zImage. If a device uses appended dtb then you may need to do that manually. Looks like hammerhead does. NOTE: This is completely untested but in theory I think this is how it goes for hammerhead.
Set up a build environment from the kernel source directory with envkernel.sh. >There's more detail about using envkernel.sh here:
Ok but first I need to clone kernel sources manually? (Otherwise I get "ERROR: This folder is not a linux source tree: /home/pparent/git/pmbootstrap" ) How do I make sure that I get the exact same version as the current sources used for my device in the binary form?
make
And I don't get how will this know for which arch to compile and which configuration to apply if we did not specify anything before?
Ok but first I need to clone kernel sources manually?
Yes. hammerhead is using linux-postmarketos-qcom so git clone the source.
How do I make sure that I get the exact same version as the current sources used for my device in the binary form?
Checkout the revision in aports/main/linux-postmarketos-qcom/APKBUILD.
And I don't get how will this know for which arch to compile and which configuration to apply if we did not specify anything before?
envkernel.sh will use the device you set when you ran pmbootstrap init. If you've chosen hammerhead then ARCH=arm is already set.
Use the config that linux-postmarketos-qcom is compiled with: aports/main/linux-postmarketos-qcom/config-postmarketos-qcom.armhf
Normally the config is in the kernel source. You could just copy config-postmarketos-qcom.armh temporariliy to arch/arm/config/hammerhead_defconfig. Then do make hammerhead_defconfig.
Regarding the methods in the "Installing an updated kernel" section: I think it would be good if we did not require to have a working kernel running in order to incrementally update the kernel. Otherwise, if you compile a kernel that doesn't boot, you won't be able to use the incremental update unless you flash another kernel first (which breaks the workflow).
Maybe implement something like this:
$ pmbootstrap flasher flash_kernel --kernel=path/to/current/kernel
(the tricky path would be calling mkinitfs with the custom kernel and saving the resulting boot.img and other files in a temporary directory. mkinitfs does not only generate the initramfs in postmarketOS, but also the boot.img file and other image formats that combine the initramfs and kernel.)
We could even add an alias in envkernel.sh to quickly flash the kernel from the source folder, without specifying the path, once we have that. (For example: "flash".)
EDIT: not all devices are Android devices/have adb support. So if we could do it with pmbootstrap flasher, we should be able to make it work for all devices where pmbootstrap flasher is already working.
perform other device/kernel specific steps that are required to build a working kernel.
run pmbootstrap envkernel to create an apk package
do what ever with that package (i.e. pmbootstrap flasher flash_kernel)
What it does is set up an abuild in chroot native (/home/pmos/build). The kernel build output (located in chroot_native /mnt/linux/.output) is symlinked to /home/pmos/build/src. Then it uses abuild to package the build output (abuild rootpkg). The rootpkg command runs prepare() and packaging steps.
Example:
Compile the kernel.
cd ~/code/linuxsource ~/pmbootstrap/helpers/envkernel.shmake tegra_postmarketos_defconfigmake -j6
Some kernels have oddities in the APKBUILD prepare() and build() step.
These things the kernel developer are required to run themselves in the processes of compiling a ready to package kernel.
Examples:
i9100 has some isorec things to prepare.
linux-postmarketos-qcom has some dtbTool command in the build() step.
Subpackages aren't been packaged.
The linux-postmarketos-* kernels have a dev subpackage. That isn't packaging properly at the moment so I'm setting subpackages="".
A benefit of this method is that loadable kernel modules are also easily updated when you have a working kernel. The kernel package can be served locally with the python webserver.
Yeah build --src is fast. I thought there might be faster way especially when running on mechanical hard drives. Previously I was using a basic shell script to repackage a boot.img with the zImage. Then it adb sideloads it.
I've thought about maybe implementing this by calling pmbootstrap as an API or something rather than built in. It's mostly a bunch of calls to chroot run and a couple calls to modify the APKBUILD.
I know that flasher flash_kernel triggers the mkinitfs script but I think it creates a boot.img with the old kernel (the one installed in the chroot), or the build --src also updates the package installed in the chroot?
When I rebuild a package (e.g. pmbootstrap build device-aaa-bbb --force) I usually run something like pmbootstrap chroot -r -- apk add -u /mnt/pmbootstrap-packages/armhf/device-aaa-bbb-0.0.1-r0.apk before triggering a pmbootstrap flasher flash_kernel again
@drebrez: right, from reading the code it seems like we do not update the packages in the rootfs chroot before flashing. (We could add that though, to support this workflow.)
Yeah build --src is fast. I thought there might be faster way especially when running on mechanical hard drives. Previously I was using a basic shell script to repackage a boot.img with the zImage. Then it adb sideloads it.
This sounds pretty cool, but it seems to be hard/impossible to both save the user from compiling the kernel again, but at the same time supporting all the special cases from the APKBUILDs (isorec, dtbtool) as you pointed out. (Now that I've read your patches, I understand why that is the case.)
I've thought about maybe implementing this by calling pmbootstrap as an API or something rather than built in. It's mostly a bunch of calls to chroot run and a couple calls to modify the APKBUILD.
I'm interested in how this would look like, would you like to write up some pseudo code to illustrate this?
I'm interested in how this would look like, would you like to write up some pseudo code to illustrate this?
I hadn't thought that part through very much. I was mostly thinking from utility standpoint. I guess the args param would be required for such calls. I don't know how possible that is.
@ollieparanoid I've investigated a bit and I think the problem is in this piece of code of apk.py
# Local packages: Using the path instead of pkgname makes apk update# packages of the same version if the build date is differentpackages_todo = replace_aports_packages_with_path(args, packages_todo, suffix, arch)
which returns the package with the version of the APKBUILD and not the latest version inside the repository.
When building a package with --src it creates a version with the date inside, the install_is_necessary function correctly identify that there is a new package version
data_installed["version"] = 3.4.113_p20181116230450-r0data_repo["version"] = 3.4.113_p20181116231301-r0compare = pmb.parse.version.compare(data_installed["version"], data_repo["version"])compare is -1 # b) Repo newer
I'm not sure how to solve this...
EDIT:
this might work, but don't know if it breaks some other logic