Fairphone 4: Kernel and GPL sources published

We are happy to announce that we have published the sources for the Fairphone 4 kernel and other GPL sources on code.fairphone.com.

You can find the kernel sources and build instructions at Fairphone 4 Kernel Source Code and the other GPL sources at Fairphone 4 Other GPL Sources.

Please feel free to discuss this release in this category of our forum!


Awesome, thanks for the update!

I’m trying to compile it inside a fresh Ubuntu Impish VM and I get 5 errors:

../drivers/staging/wlan-qc/qcacld-3.0/core/hdd/src/wlan_hdd_assoc.c:2135:28: error: variable 'psoc' set but not used [-Werror,-Wunused-but-set-variable]
        struct wlan_objmgr_psoc **psoc;
../techpack/audio/asoc/codecs/bolero/wsa-macro.c:2148:5: error: variable 'bst_state_max' set but not used [-Werror,-Wunused-but-set-variable]
        u8 bst_state_max;
../techpack/audio/asoc/codecs/bolero/wsa-macro.c:2180:5: error: variable 'bst_state_max' set but not used [-Werror,-Wunused-but-set-variable]
        u8 bst_state_max;
../techpack/audio/asoc/msm-dai-q6-v2.c:7221:17: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable]
        int rc, id, i, len;
../techpack/audio/dsp/codecs/q6audio_v2_aio.c:175:6: error: variable 'ret' set but not used [-Werror,-Wunused-but-set-variable]
        int ret;

The VM has been set up from scratch via vagrant with ubuntu/impish64 and provisioned with sudo apt install -y make bison flex clang lld llvm repo libssl-dev gcc-aarch64-linux-gnu.

Any ideas why these errors happen and the build fails?



Thanks for trying, there is indeed an issue when using clang 13. I’ve pushed two commits to fix this issue:

Please run the “repo sync” command and try again.


Cool, it worked! :partying_face:

vagrant@ubuntu-impish:~/boot-fp4$ abootimg -i boot-FP4.img

Android Boot Image Info:

* file name = boot-FP4.img

* image size = 56143872 bytes (53.54 MB)
  page size  = 4096 bytes

* Boot Name = ""

* kernel size       = 44576784 bytes (42.51 MB)
  ramdisk size      = 1149710 bytes (1.10 MB)

* load addresses:
  kernel:       0x00008000
  ramdisk:      0x01000000
  tags:         0x00000100

* cmdline = console=ttyMSM0,115200,n8 earlycon=msm_geni_serial,0x888000 androidboot.hardware=qcom androidboot.console=ttyMSM0 androidboot.memcg=1 lpm_levels.sleep_disabled=1 video=vfb:640x400,bpp=32,memsize=3072000 msm_rtb.filter=0x237 service_locator.enable=1 androidboot.usbcontroller=a600000.dwc3 swiotlb=2048 cgroup.memory=nokmem,nosocket loop.max_part=7 buildvariant=user

* id = 0xb6ec92b1 0x39e4531c 0x8e066b56 0xa20eddb1 0x3d5770da 0x00000000 0x00000000 0x00000000

Now I just need the device for flashing :smiley:


I’m probably doing something really stupid and waste your valuable time - I have no real clue what could be causing this - my thought is maybe you see it at a glance?
If not don’t even bother!

One should be doing it like @phedoreanu with a small clean ubuntu vm anyhow I guess.
(tried it with Manjaro / Arch)

(I will be using some more time to learn about the backgrounds)

[bliss@bliss-tower-linux msm-4.19]$ make CC=clang LLVM=1 -j$(nproc)
make[1]: Entering directory '/home/bliss/Desktop/fp4-kernel/kernel/msm-4.19/build'
which: no aarch64-linux-gnu-elfedit in (/usr/lib/jvm/java-16-openjdk/bin:/home/bliss/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin)
arch/arm64/Makefile:27: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum
arch/arm64/Makefile:48: Detected assembler with broken .inst; disassembly will be unreliable
which: no ld.lld in (/usr/lib/jvm/java-16-openjdk/bin:/home/bliss/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin)
  UPD     include/config/kernel.release
  GEN     ./Makefile
  WRAP    arch/arm64/include/generated/uapi/asm/errno.h
  WRAP    arch/arm64/include/generated/uapi/asm/ioctl.h
  WRAP    arch/arm64/include/generated/uapi/asm/kvm_para.h
  WRAP    arch/arm64/include/generated/uapi/asm/ioctls.h
  WRAP    arch/arm64/include/generated/uapi/asm/mman.h
  WRAP    arch/arm64/include/generated/uapi/asm/ipcbuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/msgbuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/poll.h
  WRAP    arch/arm64/include/generated/uapi/asm/resource.h
  WRAP    arch/arm64/include/generated/uapi/asm/sembuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/socket.h
  WRAP    arch/arm64/include/generated/uapi/asm/shmbuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/termbits.h
  WRAP    arch/arm64/include/generated/uapi/asm/termios.h
  WRAP    arch/arm64/include/generated/uapi/asm/sockios.h
  WRAP    arch/arm64/include/generated/uapi/asm/swab.h
  WRAP    arch/arm64/include/generated/uapi/asm/types.h
  UPD     include/generated/uapi/linux/version.h
  UPD     include/generated/utsrelease.h
  Using .. as source for kernel
  WRAP    arch/arm64/include/generated/asm/bugs.h
  WRAP    arch/arm64/include/generated/asm/delay.h
  WRAP    arch/arm64/include/generated/asm/div64.h
  WRAP    arch/arm64/include/generated/asm/dma.h
  WRAP    arch/arm64/include/generated/asm/dma-contiguous.h
  WRAP    arch/arm64/include/generated/asm/early_ioremap.h
  WRAP    arch/arm64/include/generated/asm/hw_irq.h
  WRAP    arch/arm64/include/generated/asm/emergency-restart.h
  WRAP    arch/arm64/include/generated/asm/kdebug.h
  WRAP    arch/arm64/include/generated/asm/irq_regs.h
  WRAP    arch/arm64/include/generated/asm/kmap_types.h
  WRAP    arch/arm64/include/generated/asm/local.h
  WRAP    arch/arm64/include/generated/asm/local64.h
  WRAP    arch/arm64/include/generated/asm/mcs_spinlock.h
  WRAP    arch/arm64/include/generated/asm/mm-arch-hooks.h
  WRAP    arch/arm64/include/generated/asm/preempt.h
  WRAP    arch/arm64/include/generated/asm/msi.h
  WRAP    arch/arm64/include/generated/asm/qrwlock.h
  WRAP    arch/arm64/include/generated/asm/rwsem.h
  WRAP    arch/arm64/include/generated/asm/qspinlock.h
  WRAP    arch/arm64/include/generated/asm/segment.h
  WRAP    arch/arm64/include/generated/asm/serial.h
  WRAP    arch/arm64/include/generated/asm/set_memory.h
  WRAP    arch/arm64/include/generated/asm/sizes.h
  WRAP    arch/arm64/include/generated/asm/switch_to.h
  WRAP    arch/arm64/include/generated/asm/trace_clock.h
  WRAP    arch/arm64/include/generated/asm/user.h
  WRAP    arch/arm64/include/generated/asm/unaligned.h
  WRAP    arch/arm64/include/generated/asm/vga.h
  WRAP    arch/arm64/include/generated/asm/xor.h
  HOSTCC  scripts/bin2c
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/sortextable
  HOSTCC  scripts/asn1_compiler
  HOSTCC  scripts/pnmtologo
  HOSTCC  scripts/sign-file
  HOSTCC  scripts/dtc/flattree.o
  HOSTCC  scripts/dtc/dtc.o
  YACC    scripts/genksyms/parse.tab.c
  YACC    scripts/genksyms/parse.tab.h
  HOSTCC  scripts/extract-cert
  HOSTCC  scripts/dtc/fstree.o
  HOSTCC  scripts/genksyms/genksyms.o
  LEX     scripts/genksyms/lex.lex.c
  HOSTCC  scripts/dtc/treesource.o
  HOSTCC  scripts/dtc/data.o
  HOSTCC  scripts/dtc/livetree.o
  HOSTCC  scripts/dtc/srcpos.o
  HOSTCC  scripts/selinux/genheaders/genheaders
  CC      scripts/mod/empty.o
  HOSTCC  scripts/selinux/mdp/mdp
  HOSTCC  scripts/dtc/checks.o
  HOSTCC  scripts/mod/mk_elfconfig
  HOSTCC  scripts/dtc/util.o
/usr/bin/as: unrecognized option '-EL'
clang-12: error: assembler command failed with exit code 1 (use -v to see invocation)
make[3]: *** [../scripts/Makefile.build:339: scripts/mod/empty.o] Error 1
make[3]: *** Waiting for unfinished jobs....
  LEX     scripts/dtc/dtc-lexer.lex.c
  CC      kernel/bounds.s
  YACC    scripts/dtc/dtc-parser.tab.h
  YACC    scripts/dtc/dtc-parser.tab.c
  UPD     include/generated/timeconst.h
make[2]: *** [../scripts/Makefile.build:642: scripts/mod] Error 2
make[2]: *** Waiting for unfinished jobs....
  HOSTCC  scripts/genksyms/lex.lex.o
  HOSTCC  scripts/genksyms/parse.tab.o
  HOSTCC  scripts/dtc/dtc-lexer.lex.o
  UPD     include/generated/bounds.h
  CC      arch/arm64/kernel/asm-offsets.s
  HOSTCC  scripts/dtc/dtc-parser.tab.o
  HOSTLD  scripts/dtc/dtc
  HOSTLD  scripts/genksyms/genksyms
make[1]: *** [/home/bliss/Desktop/fp4-kernel/kernel/msm-4.19/Makefile:1225: scripts] Error 2
make[1]: *** Waiting for unfinished jobs....
In file included from ../arch/arm64/kernel/asm-offsets.c:25:
In file included from ../include/linux/kvm_host.h:39:
In file included from ../arch/arm64/include/asm/kvm_host.h:42:
In file included from ../include/kvm/arm_pmu.h:21:
In file included from ../include/linux/perf_event.h:57:
In file included from ../include/linux/cgroup.h:28:
../include/linux/cgroup-defs.h:507:16: warning: field 'cgrp' with variable sized type 'struct cgroup' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
        struct cgroup cgrp;
1 warning generated.
  UPD     include/generated/asm-offsets.h
  CALL    ../scripts/checksyscalls.sh
make[1]: Leaving directory '/home/bliss/Desktop/fp4-kernel/kernel/msm-4.19/build'
make: *** [Makefile:151: sub-make] Error 2
[bliss@bliss-tower-linux msm-4.19]$ 

I got a successful build with a clean Ubuntu.
Though also some compiler errors that are aren’t “set but not used” - idk yet if they are bad.

1 Like
$ pacman -F ld.lld
extra/lld 12.0.1-1

So you should probably install that package :slight_smile:


oooof I knew I did something stupid :upside_down_face:

1 Like

So I tried building as well and I got through a lot of error messages already solved. BUt now I get this message during the build (shows up after ~20min):

make[3]: *** No rule to make target 'net/netfilter/xt_DSCP.o', needed by 'net/netfilter/built-in.a'.  Stop.
make[2]: *** [../scripts/Makefile.build:642: net/netfilter] Error 2

Any idea how I could solve this?

Can you share the clang version you’ve used (clang --version)? Also you shouldn’t need to modify the sources at all for them to build.
The only special thing I can see about xt_DSCP is that there’s both a xt_DSCP.c and a xt_dscp.c file in the source tree. Are you building on a case insensitive file system like NTFS maybe?

output of clang --version

clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Yeah I am building on NTFS. I have a VM running in docker and linked a windows folder in so I have access to it from outside

Please build on a case sensitive file system, like ext4. Then it should compile without any problem.


Hi, I’ve had a successful build under Ubuntu Impish and Clang 13, thanks for your hard work!
I have a question regarding the DT.
I am new to tinkering around on android. My understanding is that the DT is a description of hardward nodes in the device.
The DTS is the source code of the DT, and compiling the DTS generates the DT.

Here is where I get confused regarding the FP4’s DTS: The Fairphone 4 kernel documentation page says this :

Please note, that currently the sources do not contain the devicetree sources (.dts, .dtsi). You will need to extract the dtb (device tree blob) from the stock image’s boot.img and use that with your self-compiled kernel (e.g. with unpackbootimg from github.com/osm0sis/mkbootimg).

However, next to the Image file I get, I also have a dts folder containing a bunch of hardware-manufacturers-named sub folders (“nvidia”, “broadcom” etc…). They all contain a “modules.order” file, except for the “qcom” folder which also has a bunch of .dtb files

I dont really know what all that is ; dtb makes me think these are the compiled source, but again i dont really know what i’m looking at.

Is the documentation outdated and this is the DTS ? Or do I not understand what the DTS is and what it’s supposed to look like ?

Thanks again for your time !

That did the trick, so don’t try to build on NTFS I guess ^^.
Now I want to Follow this step:

You will need to extract the dtb (device tree blob) from the stock image’s boot.img and use that with your self-compiled kernel (e.g. with unpackbootimg from GitHub - osm0sis/mkbootimg: mkbootimg + unpackbootimg, forked and updated).

I downloaded and built the project, but when I try to run it on the image with

 ./unpackbootimg -i /home/fp4-kernel/kernel/msm-4.19/build/arch/arm64/boot/Image -o /home/test

I get this error:

Boot image magic not found.

When looking in the source code, this message appears when this is the case:

total_read = i;
    if(i > seeklimit) {
        fprintf(stderr, "Boot image magic not found.\n");
        return 1;

Where seeklimit is just this:

int seeklimit = 65536; // arbitrary byte limit to search in input file for ANDROID!/VNDRBOOT magic

I cannot really tell what the problem is. Am I doing something wrong?

Yes, those are included in the sources but just because they come from upstream like that. The files relevant for FP4 would be lagoon.dtsi and friends, but as is mentioned in the docs those are currently not included.

Otherwise yes, normally .dts (plus included .dtsi files) gets compiled into .dtb which is used to describe the hardware and tell the kernel which hardware is available and all the details there.

Building non-Windows on case insensitive file systems is always a bad idea.

Your compiled kernel build/arch/arm64/boot/Image isn’t the boot.img mentioned in the docs, that would be the binary that’s on your device’s boot partition (technically boot_a or boot_b because it’s an A/B device) or distributed in the stock image where the file is normally called boot.img (also note, that the stock image is not yet available for download).

Ok, but then what is it that I build? I thought that I would be building something that I can flash onto my device and that it would consist of the mentioned boot.img.

So I can extract it when I pull the boot.img from my device?

On the open source documentation it says this:

While we’re working on publishing full flashable images, you can directly download the images for the boot and dtbo partitions.

If this isn’t the boot.img for FP4 what is it? (It says FP4 in the link…)

Whoops, I forgot about that. Yes that’s the file you need to unpack.

The file at build/arch/arm64/boot/Image is the Linux kernel which is one of the things contained in a boot.img, there’s also ramdisk, dtb and some offsets contained there.

1 Like

Ok, great :slight_smile:

And how do I build a boot.img out of that compiled kernel?