This guide is a step-by-step explanation of the process of porting a new device to Replicant 4.0.
If your device fails to comply with one of these requirements, it won't be possible to port Replicant to it.
If you don't know about whether your device complies or not, you'll probably learn it along the way.
First of all, you'll have to find out the device's codename that was given by its manufacturer. Wikipedia usually has that information on the device's article. For instance, the codename for the European version of the Nexus S given by Samsung is i9023. This codename will help in the process of getting informations about the device.
Then, a second codename (that can turn out the be the same as the previous one) is given to the device at Android-level. If your device is supported by CyanogenMod, you can find it out from the CyanogenMod Wiki or on CyanogenMod download page. For instance, the Nexus S codename is: crespo
.
It is useful to have a general idea of what kind of hardware is present in the phone. From the Wikipedia and CyanogenMod pages about the device, it's already possible to know what System on a Chip (SoC) it uses and a couple other details.
To learn more details, you can consider looking for a teardown of the device (for instance on iFixit), that will reveal what chips are used on the device. Looking at the kernel defconfig for the device will also help a lot, you can also try to find the service manual for the device.
You can then compare that to the devices that are already supported in Replicant to get an idea of what will possibly work.
One very important step is to find out if the device is Tivoized: that means that even though the manufacturer releases the kernel source code for the device, the bootloader checks the kernel signature and will refuse to start it if it's not properly signed by the manufacturer. In other words, if you build the kernel yourself, the device will refuse to run it since it's not signed by the manufacturer. Since the Linux kernel is released under the GPLv2, there are no specific dispositions to counter Tivoization, and so porting the device to Replicant is pointless as it will require a prebuilt and signed kernel from the manufacturer.
This is not an easy information to find out, but the developers involved in the CyanogenMod port will probably know that information. It's a good idea to just ask them.
To install the future Replicant image on the device, you have to find out how the device can be flashed with a new operating system. The CyanogenMod Wiki has install guides for the supported devices and you'll probably find install guides for non-official CM ports as well. It is very important to understand the flashing procedure as it will have to be documented on the Replicant wiki.
There are basically two ways of flashing a new operating system:The key information to get before starting the port is the list of the non-free components that are required by CyanogenMod.
The easiest way to do this is to spot the device repository in CyanogenMod repos and look for the extract-files.sh
or proprietary-blobs.txt
file on the ics
branch.
There is usually a link to the device repository from the CyanogenMod Wiki
For instance, the list of non-free components for the Nexus S is extract-files.sh
From that list, spot what is related to what hardware component (audio, camera, sensors, gps, modem, etc): that gives an idea of the amount of work required to add support for the phone.
android_device_vendor_device
.android_device_vendor_devices-common
.android_kernel_samsung_devices
.You can find the device-specific repo from the device's page on the CyanogenMod Wiki.
Make sure you check out the branches that match the CM 9.0 version (the branch may be called ics
).
Once you have cloned the device-specific repo for your device and checked out the correct branch, refer to the cm.dependencies
file to find what repos are left to clone.
Clone these repos in the correct locations and remove the prefix (e.g. android_device_samsung_crespo
must be cloned in device/samsung/
and renamed to crespo
).
If your cloned the kernel source for your device, it is likely that the kernel build is already integrated, so you can skip the next sections below.
Once you have the kernel sources, read the instructions to find out which defconfig to use.
Since manufacturers usually don't release the git history along with the files, you'll need to recreate a git repo:git add -A
) and commit (git commit
) with a message explaining what you just imported (e.g. "GT-I9000 GB Opensource Update 2")Now that you have a git repo, you can move it to the Replicant code tree, under the name: kernel/vendor/devices
(e.g. kernel/samsung/aries
).
Make sure to make the devices
name match the devices
in android_device_vendor_devices-common
if the kernel is shared across these devices or to match the device
in android_device_vendor_device
.
Some devices are still using a prebuilt kernel. Even though the CyanogenMod team is trying to avoid that, it remains in many repos.
For such devices, you will need to remove the prebuilt binaries and the instructions to copy the prebuilt kernel and its modules.
In the device repository (device/vendor/device
) and common repository for your device (if any), remove the prebuilt kernel and modules (usually called kernel
and module.ko
(replace module with the name of a module) or a modules
directory).
Remove the instructions to copy these prebuilts on the makefiles. Remove instructions such as:
PRODUCT_COPY_FILES += \ $(LOCAL_KERNEL):kernel LOCAL_KERNEL := $(LOCAL_PATH)/kernel
TARGET_PREBUILT_KERNEL
as well as the instructions to copy the prebuilt modules.
The BoardConfig.mk
(or BoardConfigCommon.mk
in the common directory for your device) will most likely hold a line like:
TARGET_PREBUILT_KERNEL := device/samsung/p5/kernel
Now that the device repository has no prebuilt instructions, you can add the instructions to build the kernel. In the BoardConfig.mk
file, add the following lines:
TARGET_KERNEL_SOURCE := kernel/samsung/p3 TARGET_KERNEL_CONFIG := samsung_p5_defconfig
You need to find out which type of kernel image your device uses. Asking people who know about that is the best idea.
This is the easiest case to handle: just make sure the CONFIG_INITRAMFS_SOURCE
option in the kernel defonfig is left blank or undefined:
CONFIG_INITRAMFS_SOURCE=""
Building a zImage with a built-in initramfs requires the following steps:
In the kernel defconfig, define the CONFIG_INITRAMFS_SOURCE
option that way:
CONFIG_INITRAMFS_SOURCE="../../root"
Once this is done, duplicate the defconfig and add the _recovery
prefix before the _defconfig
ending (e.g. herring_recovery_defconfig
), edit that file and replace CONFIG_INITRAMFS_SOURCE
with:
CONFIG_INITRAMFS_SOURCE="../../recovery/root"
Back to the device repository, edit the BoardConfig.mk
file and add the following line:
TARGET_KERNEL_RECOVERY_CONFIG := samsung_p5_recovery_defconfig
_recovery_defconfig
ending).
Still in the device repository, create a bootimg.mk
file containing the following:
LOCAL_PATH := $(call my-dir) $(INSTALLED_BOOTIMAGE_TARGET): $(INSTALLED_KERNEL_TARGET) $(ACP) $(INSTALLED_KERNEL_TARGET) $@ $(INSTALLED_RECOVERYIMAGE_TARGET): $(INSTALLED_RECOVERY_KERNEL_TARGET) $(ACP) $(INSTALLED_RECOVERY_KERNEL_TARGET) $@
Edit the BoardConfig.mk
file and add the following line:
BOARD_CUSTOM_BOOTIMG_MK := device/vendor/device/bootimg.mk
device/vendor/device/
to the correct path to your device's repository.
Follow the previous instructions (zImage with built-in initramfs) and set the BOARD_USES_UBOOT
variable in the BoardConfig.mk
file:
BOARD_USES_UBOOT := true