← Back to team overview

ubuntu-phone team mailing list archive

[PATCH] Enable build to use the pre-built kernel available at Ubuntu

 

Hey,

Follows two patches that allow downloading and extracting the pre-built kernel available at the Ubuntu archive, for the supported devices.

build - 0001-Adding-support-to-fetch-the-kernel-binary-from-the-U.patch:
Adding a script that uses the launchpadlib to retrive the binary package from the archive, and changes the build logic to support additional options. By default it'll try to download the latest every time brunch is called.

device/lge/mako - 0001-BoardConfig.mk-start-using-the-kernel-binary-from-th.patch Enable the usage of the pre-built kernel for mako. Tested with the quantal and raring based image, working the same way as with the standard kernel.

Thanks,
--
Ricardo Salveti de Araujo
>From f65516f8f025c4971601c8a1eadf0c459ac5001e Mon Sep 17 00:00:00 2001
From: Ricardo Salveti de Araujo <ricardo.salveti@xxxxxxxxxxxxx>
Date: Wed, 17 Apr 2013 04:28:45 -0300
Subject: [PATCH] Adding support to fetch the kernel binary from the Ubuntu
 archive

Changing the main kernel.mk file to support retrieving, extracting and
using the kernel binary (vmlinuz) provided by the linux-image-(flavour)
package.

If enabled it'll also skip the kernel build and install process,
depending entirely at the kernel provided by the package (only the
headers will be installed at build-time, in case the kernel source
is available).

To enable just change the device specific BoardConfig.mk file, adding
the following:

TARGET_KERNEL_UBUNTU := true
TARGET_KERNEL_UBUNTU_META := linux-image-nexus4
TARGET_KERNEL_UBUNTU_SERIES := raring

Remember that for it to work properly it needs a working package and
respective meta available at the Ubuntu archive.

Signed-off-by: Ricardo Salveti de Araujo <ricardo.salveti@xxxxxxxxxxxxx>
---
 core/envsetup.mk     |  1 +
 core/tasks/kernel.mk | 73 +++++++++++++++++++++++++++++++++++++++----
 tools/pull-lp-bin.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 156 insertions(+), 6 deletions(-)
 create mode 100755 tools/pull-lp-bin.py

diff --git a/core/envsetup.mk b/core/envsetup.mk
index 862b7f0..1017aad 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -205,6 +205,7 @@ TARGET_OUT_KEYCHARS := $(TARGET_OUT)/usr/keychars
 TARGET_OUT_ETC := $(TARGET_OUT)/etc
 TARGET_OUT_NOTICE_FILES:=$(TARGET_OUT_INTERMEDIATES)/NOTICE_FILES
 TARGET_OUT_FAKE := $(PRODUCT_OUT)/fake_packages
+TARGET_OUT_UBUNTU := $(PRODUCT_OUT)/ubuntu
 
 TARGET_OUT_DATA := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_DATA)
 TARGET_OUT_DATA_EXECUTABLES:= $(TARGET_OUT_EXECUTABLES)
diff --git a/core/tasks/kernel.mk b/core/tasks/kernel.mk
index 1176870..f059f89 100644
--- a/core/tasks/kernel.mk
+++ b/core/tasks/kernel.mk
@@ -27,6 +27,10 @@ KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG)
 KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
 KERNEL_CONFIG := $(KERNEL_OUT)/.config
 
+KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
+KERNEL_MODULES_INSTALL := system
+KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
+
 ifeq ($(BOARD_USES_UBOOT),true)
 	TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/uImage
 	TARGET_PREBUILT_INT_KERNEL_TYPE := uImage
@@ -38,7 +42,32 @@ else
 	TARGET_PREBUILT_INT_KERNEL_TYPE := zImage
 endif
 
-ifeq "$(wildcard $(KERNEL_SRC) )" ""
+ifeq ($(TARGET_KERNEL_UBUNTU),true)
+    ifneq ($(TARGET_PREBUILT_INT_KERNEL_TYPE),zImage)
+        $(warning ***************************************************************)
+        $(warning * At the moment only zImage kernel is supported when fetching *)
+        $(warning * kernel from the Ubuntu archive. Make sure your device does  *)
+        $(warning * not use BOARD_USES_UBOOT or BOARD_USES_UNCOMPRESSED_BOOT    *)
+        $(warning ***************************************************************)
+        $(error "INCOMPATIBLE KERNEL TYPE")
+    endif
+
+    ifneq ($(TARGET_KERNEL_UBUNTU_META),)
+        NEEDS_KERNEL_COPY := true
+        FETCH_KERNEL_UBUNTU := true
+        FULL_KERNEL_BUILD := false
+        KERNEL_BIN := $(TARGET_OUT_UBUNTU)/vmlinuz
+    else
+        $(warning ***************************************************************)
+        $(warning * As the Ubuntu kernel package ABI version in part of the     *)
+        $(warning * package name, a meta package is used to track the latest    *)
+        $(warning * version available in the archive. Please make that the      *)
+        $(warning * required meta package is available and defined by the       *)
+        $(warning * variable TARGET_KERNEL_UBUNTU_META                          *)
+        $(warning ***************************************************************)
+        $(error "MISSING TARGET_KERNEL_UBUNTU_META")
+    endif
+else ifeq "$(wildcard $(KERNEL_SRC) )" ""
     ifneq ($(TARGET_PREBUILT_KERNEL),)
         HAS_PREBUILT_KERNEL := true
         NEEDS_KERNEL_COPY := true
@@ -97,11 +126,43 @@ else
     endif
 endif
 
-ifeq ($(FULL_KERNEL_BUILD),true)
-
-KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
-KERNEL_MODULES_INSTALL := system
-KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
+ifeq ($(FETCH_KERNEL_UBUNTU),true)
+
+## Launchpad helper to download binary packages
+PULL_LP_BIN := build/tools/pull-lp-bin.py
+
+## Also install the kernel headers if the source is available
+$(KERNEL_HEADERS_INSTALL):
+	if [ -f $(KERNEL_SRC)/Makefile ]; then \
+		mkdir -p $(KERNEL_OUT); \
+		$(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) headers_install; \
+	fi
+
+.PHONY: $(TARGET_OUT_UBUNTU)
+$(TARGET_OUT_UBUNTU):
+	$(hide) rm -rf $(TARGET_OUT_UBUNTU)
+	$(hide) mkdir -p $(TARGET_OUT_UBUNTU)
+
+.PHONY: $(TARGET_OUT_UBUNTU)/vmlinuz
+$(TARGET_OUT_UBUNTU)/vmlinuz: $(TARGET_OUT_UBUNTU) $(KERNEL_HEADERS_INSTALL)
+	$(hide) $(PULL_LP_BIN) $(TARGET_KERNEL_UBUNTU_META) -o $(TARGET_OUT_UBUNTU) $(TARGET_KERNEL_UBUNTU_SERIES)
+	$(hide) IFS=", "; for dep in \
+		`dpkg-deb -f $(TARGET_OUT_UBUNTU)/$(TARGET_KERNEL_UBUNTU_META)_*.deb Depends`; do \
+			if echo $$dep | grep -q "linux-image-"; then \
+				kernel_image=$$dep; \
+			fi; \
+		done; \
+		if [ -n "$$kernel_image" ]; then \
+			$(PULL_LP_BIN) $$kernel_image -o $(TARGET_OUT_UBUNTU) $(TARGET_KERNEL_UBUNTU_SERIES); \
+			dpkg-deb -x $(TARGET_OUT_UBUNTU)/linux-image-[0-9]*.deb $(TARGET_OUT_UBUNTU); \
+		else \
+			echo -n "Unable to find a valid linux-image dependency from "; \
+			echo "the meta package $(TARGET_KERNEL_UBUNTU_META), aborting."; \
+			exit 1; \
+		fi;
+	cp $(TARGET_OUT_UBUNTU)/boot/vmlinuz-[0-9]* $(TARGET_OUT_UBUNTU)/vmlinuz
+
+else ifeq ($(FULL_KERNEL_BUILD),true)
 
 define mv-modules
     mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.order`;\
diff --git a/tools/pull-lp-bin.py b/tools/pull-lp-bin.py
new file mode 100755
index 0000000..ec41cd0
--- /dev/null
+++ b/tools/pull-lp-bin.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+#
+# pull-lp-bin -- pull a binary package from Launchpad
+#
+# Copyright (C) 2013, Canonical Ltd.
+#
+# Based on the pull-lp-source script (ubuntu-dev-tools) made by:
+#  - Iain Lane <iain@xxxxxxxxxxxxxxxxxxx>
+#  - Stefano Rivera <stefanor@xxxxxxxxxx>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 3
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# See file /usr/share/common-licenses/GPL for more details.
+#
+# Author: Ricardo Salveti <ricardo.salveti@xxxxxxxxxxxxx>
+
+import os
+import sys
+import urllib2
+from optparse import OptionParser
+from launchpadlib.launchpad import Launchpad
+
+cachedir = "~/.launchpadlib/cache"
+
+def main():
+    usage = "Usage: %prog [-a|--arch <arch>] [-o|--output <dir>] <package> [release]"
+    opt_parser = OptionParser(usage)
+    opt_parser.add_option('-a', '--arch', default='armhf', dest='ubuntu_arch',
+                  help='Architecture for the binary package (default: armhf)')
+    opt_parser.add_option('-o', '--output',
+                  help='Directory used to output the desired package')
+    (options, args) = opt_parser.parse_args()
+    if not args:
+        opt_parser.error("Must specify a package name")
+
+    package = str(args[0]).lower()
+
+    # Login anonymously to LP
+    lp = Launchpad.login_anonymously('pull-lp-bin', 'production',
+                                      cachedir, version="devel")
+    distro = lp.distributions['ubuntu']
+    archive = lp.distributions['ubuntu'].main_archive
+
+    if len(args) > 1:
+        release = str(args[1])
+    else:
+        release = distro.current_series_link.split('/')[-1]
+
+    pocket = 'Release'
+    bin_url = None
+    bpph = None
+
+    series = distro.getSeries(name_or_version=release)
+    arch_series = series.getDistroArchSeries(archtag=options.ubuntu_arch)
+    bpph = archive.getPublishedBinaries(binary_name=package,
+                            distro_arch_series=arch_series,
+                            status="Published", pocket=pocket,
+                            exact_match=True)
+
+    if bpph:
+        version = bpph[0].binary_package_version
+        bin_url = bpph[0].binaryFileUrls()[0]
+
+    if bin_url:
+        print 'Downloading %s version %s' % (package, version)
+        url = urllib2.urlopen(bin_url)
+        data = url.read()
+        package_name = "%s_%s_%s.deb" % (package, version, options.ubuntu_arch)
+        if options.output:
+            target = "%s/%s" % (options.output, package_name)
+        else:
+            target = package_name
+        with open(target, "wb") as package:
+            package.write(data)
+    else:
+        print "Unable to find a published version of package %s (%s) at %s" % (
+                                        package, options.ubuntu_arch, release)
+
+if __name__ == '__main__':
+    main()
-- 
1.8.1.2

>From 4af59d8f207380b5d70e069625b0e9f418929fb9 Mon Sep 17 00:00:00 2001
From: Ricardo Salveti de Araujo <ricardo.salveti@xxxxxxxxxxxxx>
Date: Thu, 18 Apr 2013 02:12:04 -0300
Subject: [PATCH] BoardConfig.mk: start using the kernel binary from the
 linux-image-nexus4 package

As the kernel is now produced and maintained by the Ubuntu kernel team,
change the build to skip building the kernel from source locally, and
instead download and extract the pre-built kernel from the
linux-image-nexus4-<version> package.

The Ubuntu based kernel is available at:
http://kernel.ubuntu.com/git?p=ubuntu/ubuntu-nexus4.git;a=summary

Signed-off-by: Ricardo Salveti de Araujo <ricardo.salveti@xxxxxxxxxxxxx>
---
 BoardConfig.mk | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/BoardConfig.mk b/BoardConfig.mk
index d3c3074..f632064 100644
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -32,6 +32,9 @@ BOARD_MKBOOTIMG_ARGS := --ramdisk_offset 0x01600000
 
 # Try to build the kernel
 TARGET_KERNEL_CONFIG := mako_defconfig
+TARGET_KERNEL_UBUNTU := true
+TARGET_KERNEL_UBUNTU_META := linux-image-nexus4
+TARGET_KERNEL_UBUNTU_SERIES := raring
 
 BOARD_USES_ALSA_AUDIO:= true
 BOARD_USES_FLUENCE_INCALL := true
-- 
1.8.1.2