KaiOS

From MozillaWiki
Jump to: navigation, search

This page contains information about the Mozilla/KaiOS collaboration including building instructions, links to the code and various other resources. The scope of the project is to modernize the old Boot2Gecko codebase to run atop a modern Gecko so that it can be used by KaiOS as a basis for their future phones.

Building

There's two ways to build the project: a full emulator build or a stand-alone Gecko build. Generally speaking you won't need the full emulator build unless you're doing work specifically on it.

Building a stand-alone Gecko

Clone the kaios project branch:

hg clone https://hg.mozilla.org/projects/kaios

Bootstrap your build environment via mach

export LOCAL_NDK_BASE_URL='ftp://ftp.kaiostech.com/ndk/android-ndk' ./mach bootstrap --application-choice='GeckoView/Firefox for Android'

Download the b2g sysroot using mach:

./mach artifact toolchain --from-build toolchain-linux64-b2g-sysroot
rm -rf ~/.mozbuild/b2g-sysroot
mv b2g-sysroot ~/.mozbuild

Add a suitable mozconfig file, you can use the following one for the time being

# Build Boot2Gecko
ac_add_options --enable-application=b2g
ac_add_options --with-app-basename=b2g

# Android
ac_add_options --with-android-version=29
ac_add_options --target=x86_64-linux-android
ac_add_options --with-target-arch-name=x86_64

# Compiler options
CC="$HOME/.mozbuild/clang/bin/clang"
CXX="$HOME/.mozbuild/clang/bin/clang++"
ac_add_options --with-android-ndk="$HOME/.mozbuild/android-ndk-r20b-canary"
mk_add_options "export LD_LIBRARY_PATH=$HOME/.mozbuild/clang/lib"

# Use sccache
ac_add_options --with-ccache=sccache

# B2G-specific options
ac_add_options --with-gonk-gfx
ac_add_options --with-gonk="$HOME/.mozbuild/b2g-sysroot/"
ac_add_options --enable-b2g-camera
ac_add_options --enable-b2g-ril
ac_add_options --enable-b2g-fm
ac_add_options --enable-forkserver

# We don't use the profiler
ac_add_options --disable-profiling

# Only for x86-64
ac_add_options --enable-wasm-simd

# sandbox includes non existent arm64 files
ac_add_options --disable-sandbox

# Compiler/Linker options

# Since we use lld we need to disable elf-hack
ac_add_options --enable-linker=lld
ac_add_options --disable-elf-hack

# Android libraries
ac_add_options --with-binder-b2g-connectivity-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/binder_b2g_connectivity_interface-cpp.so"
ac_add_options --with-binder-b2g-telephony-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/binder_b2g_telephony_interface-cpp.so"
ac_add_options --with-dnsresolver-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/dnsresolver_aidl_interface-V2-cpp.so"
ac_add_options --with-gnss1.0-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.gnss@1.0.so"
ac_add_options --with-gnss1.1-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.gnss@1.1.so"
ac_add_options --with-gnss2.0-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.gnss@2.0.so"
ac_add_options --with-gnss-visibility_control1.0-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.gnss.visibility_control@1.0.so"
ac_add_options --with-hostapd-1.0-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.wifi.hostapd@1.0.so"
ac_add_options --with-hostapd-1.1-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.wifi.hostapd@1.1.so"
ac_add_options --with-mtp-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/libmtp.so"
ac_add_options --with-netd-aidl-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/netd_event_listener_interface-V1-cpp.so"
ac_add_options --with-netd-event-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/netd_aidl_interface-V2-cpp.so"
ac_add_options --with-radio-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.radio@1.0.so"
ac_add_options --with-sensors-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.sensors@1.0.so"
ac_add_options --with-supplicant-1.0-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.wifi.supplicant@1.0.so"
ac_add_options --with-supplicant-1.1-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.wifi.supplicant@1.1.so"
ac_add_options --with-supplicant-1.2-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.wifi.supplicant@1.2.so"
ac_add_options --with-vibrator-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.vibrator@1.0.so"
ac_add_options --with-vold-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/libvold_binder_shared.so"
ac_add_options --with-wifi-1.0-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.wifi@1.0.so"
ac_add_options --with-wifi-1.1-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.wifi@1.1.so"
ac_add_options --with-wifi-1.2-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.wifi@1.2.so"
ac_add_options --with-wifi-1.3-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/android.hardware.wifi@1.3.so"
ac_add_options --with-wificond-so="$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64/libwificond_ipc_shared.so"

export CFLAGS="-Wno-nullability-completeness"

export CPPFLAGS="-DANDROID -DTARGET_OS_GONK \
-DJE_FORCE_SYNC_COMPARE_AND_SWAP_4=1 \
-D_USING_LIBCXX \
-DGR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE=1 \
-isystem $ANDROID_NDK/platforms/$ANDROID_PLATFORM/$ARCH_DIR/usr/include"

export LDFLAGS="-L$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/system/lib64 -Wl,-rpath-link=$HOME/.mozbuild/b2g-sysroot/out/target/product/generic_x86_64/obj/lib64 \
--sysroot=$HOME/.mozbuild/android-ndk-r20b-canary/platforms/android-29/arch-x86_64/ -L$HOME/.mozbuild/b2g-sysroot/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/lib/gcc/x86_64-linux-android/4.9.x/ -ldl -lstdc++ \
-llog -landroid -lnativewindow -lbinder \
-lui -lgui \
-lutils -lcutils -lsysutils \
-lhardware_legacy -lhardware -lsuspend \
-lhidltransport \
-lhidlbase -lbase -lhidlmemory -lhwbinder -laudioclient"

Build as usual with ./mach build

Building the emulator

This involves downloading the entire AOSP tree and building an Android emulator from it, including the Gecko bits. It's a long and slow process and it requires at least 120GB of free space on your disk.

Clone the B2G tree

git clone https://github.com/kaiostech/B2G.git

Configure the tree for building the x86-64 emulator. This step will download all the AOSP sources required for the build which are 10s of GB so be patient

REPO_INIT_FLAGS="--depth=1" ./config.sh emulator-10-x86_64

Setup your environment to fetch the custom NDK

export LOCAL_NDK_BASE_URL='ftp://ftp.kaiostech.com/ndk/android-ndk'

Install Gecko dependencies

cd gecko && ./mach bootstrap --application-choice mobile

Build by invoking the build.sh script in the top-level directory. Depending on your machine this step can take anywhere from 30 minutes to several hours

./build.sh

Running the emulator

If you've built the emulator yourself you can launch it from the root *B2G* folder. First source the setup for your build, you will have to execute this step only once before launching the emulator

source setup.sh

Once the environment is primed launch the emulator with the following command

emulator -writable-system -selinux permissive

Building the desktop version

The desktop version can be used to work on the front-end and debug other non-platform-specific parts of Gecko. Building it is fairly simple:

Clone the kaios project branch:

hg clone https://hg.mozilla.org/projects/kaios

Bootstrap your build environment via mach

./mach bootstrap --application-choice desktop

Build using the mozconfig-b2g-desktop configuration (feel free to tweak it to suite your purposes):

env MOZCONFIG=mozconfig-b2g-desktop ./mach build

Run your build using the same mozconfig, the very simple default homescreen will show up:

env MOZCONFIG=mozconfig-b2g-desktop ./mach run