SlideShare a Scribd company logo
OpenWorld Forum 2012



      Android System                                                              Free Electrons
      Development                                                                                              Embedded Linux
                                                                                                                   Developers




      Maxime Ripard
      Free Electrons
      maxime.ripard@free-
      electrons.com




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com     1/25
Maxime Ripard


                   Embedded Linux engineer and trainer at Free Electrons since
                   2011
                             Embedded Linux development: kernel and driver development,
                             system integration, boot time and power consumption
                             optimization, consulting, etc.
                             Embedded Linux training, Linux driver development training
                             and Android system development training, with materials
                             freely available under a Creative Commons license.
                             http://www.free-electrons.com
                   Contributor to various open-source projects: Barebox, Linux,
                   Buildroot
                   Living in Toulouse, south west of France



Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   2/25
Why Modify Android ?




                   Because we have a custom set of functions on a given device
                   that isn’t handled by the vanilla Android
                   Because we want to add a different UI/set of features than
                   AOSP
                   Because since we have access to the source code, we can!




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   3/25
The Android Stack




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   4/25
Devices in the Source Tree




                   The build system is using a configuration mechanism based on
                   various layer of hardware design
                   The upper layer, the product is typically the one we want to
                   build a system for
                   The build system has no other configuration mechanism: no
                   Kconfig, text file, or any other mecanism that can be easily
                   modified




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   5/25
Product, devices and boards




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   6/25
Defining new products

                   Devices are well supported by the Android build system. It
                   allows to build multiple devices with the same source tree, to
                   have a per-device configuration, etc.
                   All the product definitions should be put in
                   device/<company>/<device>
                   The entry point is the AndroidProducts.mk file, which
                   should define the PRODUCT_MAKEFILES variable
                   This variable defines where the actual product definitions are
                   located.
                   It follows such an architecture because you can have several
                   products using the same device
                   If you want your product to appear in the lunch menu, you
                   need to create a vendorsetup.sh file in the device
                   directory, with the right calls to add_lunch_combo

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   7/25
Our New Product


                   AndroidProducts.mk
                   PRODUCT_MAKEFILES += 
                           $(LOCAL_DIR)/full_product.mk
                   full_product.mk
                   $(call inherit-product, build/target/product/generic.mk)

                   PRODUCT_NAME := full_MyDevice
                   PRODUCT_DEVICE := MyDevice
                   PRODUCT_MODEL := Full flavor of My Brand New Device
                   vendorsetup.sh
                   add_lunch_combo full_product-eng




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   8/25
Add a New Component




                   The integration of new components into the build system are
                   done through Android.mk files
                   These files just contains where the source code is and what
                   the expected result should be: an executable, a shared library,
                   a jar file, etc.
                   All the build magic is abstracted by the build system




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   9/25
Add a New Library



                   Create a new subfolder under the
                   device/company/product/lib folder
                   This folder will contain the source code in itself, plus the
                   headers and the Android.mk file
                   To include a new package into a given build, you need to add
                   the package name to the content of the PRODUCT_PACKAGES
                   variable
                   Let’s use the libusb as an example




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   10/25
Steps to add the libusb

                   The first step is obviously to untar the source code in the
                   device/company/product/lib/libusb folder
                   Since the Android build system doesn’t rely at all on external
                   build tools, we have some bits that are missing
                   The first one is that the source code is missing the config.h
                   header file, that is usually generated with the autoconf tool,
                   through the ./configure command
                   When we try to compile, it lacks two things: the
                   TIMESPEC_TO_TIMEVAL macro and the timerfd.h header
                   The first one should be declared by the c library, let’s add the
                   macro declaration where the source code is using it
                   The timerfd.h file is one of the header exposed by the Linux
                   Kernel. It is not in the headers found in the toolchain used by
                   Android though, so we will need to disable the use of such
                   feature through the command
                   ./configure --disable-timerfd
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   11/25
Library Makefile

          LOCAL_PATH:= $(call my-dir)
          include $(CLEAR_VARS)

          LOCAL_SRC_FILES := 
                  core.c 
                  descriptor.c 
                  io.c 
                  sync.c 
                  os/linux_usbfs.c

          LOCAL_C_INCLUDES += 
                  $(LOCAL_PATH)/os

          LOCAL_MODULE:= libusb
          LOCAL_MODULE_TAGS:= optional
          LOCAL_PRELINK_MODULE:= false

          include $(BUILD_SHARED_LIBRARY)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   12/25
Next steps


                   The libusb uses the device files under the folder
                   /dev/bus/usb, that are only readable by the root user and
                   the usb group.
                   The device files creations are handled by the init application,
                   so that when a new device appears on the system, its
                   associated device files will be created as well
                   The specific part of init that handles these files is called
                   ueventd
                   It uses a set of rules to create device files with the correct
                   permissions at runtime
                   If we want to use a binary running as user and that has access
                   to the USB devices, we’ll have to modify these permissions


Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   13/25
Modify the permissions of the device files



                   Permissions on the files are the enforced thanks to two
                   components:
                             Permissions on files on the system are defined in a C header:
                             android_filesystem_config.h
                             Permissions for device files are handled by ueventd that uses a
                             file called ueventd.rc
                   We can modify the permissions on the device files by adding
                   or modifying a ueventd.rc file
                   /dev/bus/usb/*                            0666             root               usb




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   14/25
Integrate a binary that uses the libusb

          LOCAL_PATH := $(call my-dir)
          include $(CLEAR_VARS)

          LOCAL_SRC_FILES:= usb_bin.c

          LOCAL_C_INCLUDES += 
              $(JNI_H_INCLUDE) 
              device/company/device/lib/libusb

          LOCAL_SHARED_LIBRARIES := libusb

          LOCAL_MODULE := usbbin
          LOCAL_MODULE_TAGS := optional
          LOCAL_PRELINK_MODULE := false

          include $(BUILD_EXECUTABLE)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   15/25
JNI Bindings



                   A Java framework to call and be called by native applications
                   written in other languages
                   Mostly used for:
                             Writing Java bindings to C/C++ libraries
                             Accessing platform-specific features
                             Writing high-performance sections
                   It is used extensively across the Android userspace to interface
                   between the Java Framework and the native daemons
                   Since Gingerbread, you can develop apps in a purely native
                   way, possibly calling Java methods through JNI




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   16/25
Libusb bindings




                   Create a new subfolder under
                   device/company/device/framework/USBFramework/jni
                   Write the JNI bindings so that the Java can call functions
                   from the libusb




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   17/25
Libusb bindings
          static struct libusb_device_handle *devh;

          JNIEXPORT void JNICALL Java_com_fe_USB_init(JNIEnv *env,
                                                      jobject obj)
          {
          ret = libusb_init(NULL);
          if (ret < 0)
                          return ret;

                            devh = libusb_open_device_with_vid_pid(NULL,
                                                                   0xdead,
                                                                   0xbeef);
                            if (!devh) {
                                    libusb_exit(NULL);
                                    return -EINVAL;
                            }

                            return 0;
          }
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   18/25
Android.mk for the bindings

          LOCAL_PATH := $(call my-dir)
          include $(CLEAR_VARS)

          LOCAL_SRC_FILES:= 
              usb_jni.c

          LOCAL_C_INCLUDES += 
              $(JNI_H_INCLUDE) 
              device/company/device/lib/libusb

          LOCAL_SHARED_LIBRARIES := 
              libusb

          LOCAL_MODULE := libusb_jni
          LOCAL_MODULE_TAGS := optional
          LOCAL_PRELINK_MODULE := false

          include $(BUILD_SHARED_LIBRARY)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   19/25
Java Framework


          package com.fe;

          class USB {
              private native void init();

                    public USB() {
                        init();
                    }

                    static {
                        System.loadLibrary("usb_jni");
                    }
          }


Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   20/25
Android.mk for the framework



          LOCAL_PATH := $(call my-dir)
          include $(CLEAR_VARS)

          LOCAL_SRC_FILES := 
                      $(call all-subdir-java-files)

          LOCAL_MODULE_TAGS := optional

          LOCAL_MODULE:= com.fe.usb

          include $(BUILD_JAVA_LIBRARY)




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   21/25
Permissions file




          <?xml version="1.0" encoding="utf-8"?>
          <permissions>
              <library name="com.fe.usb"
                      file="/system/framework/com.fe.usb.jar"/>
          </permissions>




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   22/25
Applications using that code



                   Any applications can now use the part of the framework we
                   just added, using a regular Java call
                   However, by default, the jar file generated won’t be loaded by
                   dalvik, resulting in a error at runtime.
                   You need to add extra bits to the manifest file so that both
                   the Play Store and Dalvik knows that you need the given jar
                   file to work properly
                   You need to add the <uses-library> XML tag




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   23/25
Android Manifest


          <?xml version="1.0" encoding="utf-8"?>
          <manifest
                xmlns:android="http://schemas.android.com/apk/res/android"
                package="com.fe.usb">

                  <application
                        android:icon="@drawable/icon"
                        android:label="@string/app_name">

          ...

                  <uses-library android:name="com.fe.usb"
                                android:required="true" />
              </application>
          </manifest>




Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   24/25
Questions?

                                                 Maxime Ripard
                                maxime.ripard@free-electrons.com



                                              Slides under CC-BY-SA 3.0.



Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com   25/25

More Related Content

Similar to OWF12/PAUG Conf Days Android system development, maxime ripard, free electrons

Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Tushar B Kute
 
Fight with linux reverse
Fight with linux reverseFight with linux reverse
Fight with linux reverse
chao yang
 
Kernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using BuildrootKernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using Buildroot
Anne Nicolas
 
Linux Device Driver’s
Linux Device Driver’sLinux Device Driver’s
Linux Device Driver’s
Rashmi Warghade
 
Linux internals v4
Linux internals v4Linux internals v4
Linux internals v4
Liran Ben Haim
 
Introduction to Software Build Technology
Introduction to Software Build TechnologyIntroduction to Software Build Technology
Introduction to Software Build TechnologyPhilip Johnson
 
Dedicated embedded linux af Esben Haabendal, Prevas A/S
Dedicated embedded linux af Esben Haabendal, Prevas A/SDedicated embedded linux af Esben Haabendal, Prevas A/S
Dedicated embedded linux af Esben Haabendal, Prevas A/S
InfinIT - Innovationsnetværket for it
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
Priyank Kapadia
 
Module 18 (linux hacking)
Module 18 (linux hacking)Module 18 (linux hacking)
Module 18 (linux hacking)
Wail Hassan
 
Tracing The Evolution Open Source & Embedded Systems - Mr. Jayakumar Balasubr...
Tracing The Evolution Open Source & Embedded Systems - Mr. Jayakumar Balasubr...Tracing The Evolution Open Source & Embedded Systems - Mr. Jayakumar Balasubr...
Tracing The Evolution Open Source & Embedded Systems - Mr. Jayakumar Balasubr...
Lounge47
 
J+s
J+sJ+s
J+s
happyuk
 
Rebuild presentation - IoT Israel MeetUp
Rebuild presentation - IoT Israel MeetUpRebuild presentation - IoT Israel MeetUp
Rebuild presentation - IoT Israel MeetUp
Yan Vugenfirer
 
Embedded linux system development (slides)
Embedded linux system development (slides)Embedded linux system development (slides)
Embedded linux system development (slides)
Jaime Barragan
 
Essay About ISS 418 Lab 7 And 8
Essay About ISS 418 Lab 7 And 8Essay About ISS 418 Lab 7 And 8
Essay About ISS 418 Lab 7 And 8
Paula Smith
 
127 iio a-new-subsystem
127 iio a-new-subsystem127 iio a-new-subsystem
127 iio a-new-subsystem
tarak reddy
 
Dotnet Basics Presentation
Dotnet Basics PresentationDotnet Basics Presentation
Dotnet Basics Presentation
Sudhakar Sharma
 
Rebuild - Simplifying Embedded and IoT Development Using Linux Containers
Rebuild - Simplifying Embedded and IoT Development Using Linux ContainersRebuild - Simplifying Embedded and IoT Development Using Linux Containers
Rebuild - Simplifying Embedded and IoT Development Using Linux Containers
LinuxCon ContainerCon CloudOpen China
 

Similar to OWF12/PAUG Conf Days Android system development, maxime ripard, free electrons (20)

Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
 
Fight with linux reverse
Fight with linux reverseFight with linux reverse
Fight with linux reverse
 
Kernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using BuildrootKernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using Buildroot
 
Linux Device Driver’s
Linux Device Driver’sLinux Device Driver’s
Linux Device Driver’s
 
Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
 
Linux internals v4
Linux internals v4Linux internals v4
Linux internals v4
 
Introduction to Software Build Technology
Introduction to Software Build TechnologyIntroduction to Software Build Technology
Introduction to Software Build Technology
 
Dedicated embedded linux af Esben Haabendal, Prevas A/S
Dedicated embedded linux af Esben Haabendal, Prevas A/SDedicated embedded linux af Esben Haabendal, Prevas A/S
Dedicated embedded linux af Esben Haabendal, Prevas A/S
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 
Module 18 (linux hacking)
Module 18 (linux hacking)Module 18 (linux hacking)
Module 18 (linux hacking)
 
Device drivers tsp
Device drivers tspDevice drivers tsp
Device drivers tsp
 
Tracing The Evolution Open Source & Embedded Systems - Mr. Jayakumar Balasubr...
Tracing The Evolution Open Source & Embedded Systems - Mr. Jayakumar Balasubr...Tracing The Evolution Open Source & Embedded Systems - Mr. Jayakumar Balasubr...
Tracing The Evolution Open Source & Embedded Systems - Mr. Jayakumar Balasubr...
 
J+s
J+sJ+s
J+s
 
Rebuild presentation - IoT Israel MeetUp
Rebuild presentation - IoT Israel MeetUpRebuild presentation - IoT Israel MeetUp
Rebuild presentation - IoT Israel MeetUp
 
Embedded linux system development (slides)
Embedded linux system development (slides)Embedded linux system development (slides)
Embedded linux system development (slides)
 
Essay About ISS 418 Lab 7 And 8
Essay About ISS 418 Lab 7 And 8Essay About ISS 418 Lab 7 And 8
Essay About ISS 418 Lab 7 And 8
 
127 iio a-new-subsystem
127 iio a-new-subsystem127 iio a-new-subsystem
127 iio a-new-subsystem
 
127 iio a-new-subsystem
127 iio a-new-subsystem127 iio a-new-subsystem
127 iio a-new-subsystem
 
Dotnet Basics Presentation
Dotnet Basics PresentationDotnet Basics Presentation
Dotnet Basics Presentation
 
Rebuild - Simplifying Embedded and IoT Development Using Linux Containers
Rebuild - Simplifying Embedded and IoT Development Using Linux ContainersRebuild - Simplifying Embedded and IoT Development Using Linux Containers
Rebuild - Simplifying Embedded and IoT Development Using Linux Containers
 

More from Paris Open Source Summit

#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...
#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...
#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...
Paris Open Source Summit
 
#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...
#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...
#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...
Paris Open Source Summit
 
#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...
#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...
#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...
Paris Open Source Summit
 
#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino
#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino
#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino
Paris Open Source Summit
 
#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...
#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...
#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...
Paris Open Source Summit
 
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
Paris Open Source Summit
 
#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix
#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix
#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix
Paris Open Source Summit
 
#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria
#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria
#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria
Paris Open Source Summit
 
#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...
#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...
#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...
Paris Open Source Summit
 
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches ...
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches  ...#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches  ...
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches ...
Paris Open Source Summit
 
#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...
#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...
#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...
Paris Open Source Summit
 
#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...
#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...
#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...
Paris Open Source Summit
 
#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...
#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...
#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...
Paris Open Source Summit
 
#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...
#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...
#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...
Paris Open Source Summit
 
#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...
#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...
#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...
Paris Open Source Summit
 
#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...
#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...
#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...
Paris Open Source Summit
 
#OSSPARIS19 - Table ronde : souveraineté des données
#OSSPARIS19 - Table ronde : souveraineté des données #OSSPARIS19 - Table ronde : souveraineté des données
#OSSPARIS19 - Table ronde : souveraineté des données
Paris Open Source Summit
 
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
Paris Open Source Summit
 
#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...
#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...
#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...
Paris Open Source Summit
 
#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...
#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...
#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...
Paris Open Source Summit
 

More from Paris Open Source Summit (20)

#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...
#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...
#OSSPARIS19 : Control your Embedded Linux remotely by using WebSockets - Gian...
 
#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...
#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...
#OSSPARIS19 : A virtual machine approach for microcontroller programming : th...
 
#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...
#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...
#OSSPARIS19 : RIOT: towards open source, secure DevOps on microcontroller-bas...
 
#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino
#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino
#OSSPARIS19 : The evolving (IoT) security landscape - Gianluca Varisco, Arduino
 
#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...
#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...
#OSSPARIS19: Construire des applications IoT "secure-by-design" - Thomas Gaza...
 
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
 
#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix
#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix
#OSSPARIS19 : Supervision d'objets connectés industriels - Eric DOANE, Zabbix
 
#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria
#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria
#OSSPARIS19: Introduction to scikit-learn - Olivier Grisel, Inria
 
#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...
#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...
#OSSPARIS19 - Fostering disruptive innovation in AI with JEDI - André Loesekr...
 
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches ...
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches  ...#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches  ...
#OSSPARIS19 : Comment ONLYOFFICE aide à organiser les travaux de recherches ...
 
#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...
#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...
#OSSPARIS19 : MDPH : une solution collaborative open source pour l'instructio...
 
#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...
#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...
#OSSPARIS19 - Understanding Open Source Governance - Gilles Gravier, Wipro Li...
 
#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...
#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...
#OSSPARIS19 : Publier du code Open Source dans une banque : Mission impossibl...
 
#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...
#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...
#OSSPARIS19 : Libre à vous ! Raconter les libertés informatiques à la radio -...
 
#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...
#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...
#OSSPARIS19 - Le logiciel libre : un enjeu politique et social - Etienne Gonn...
 
#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...
#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...
#OSSPARIS19 - Conflits d’intérêt & concurrence : la place de l’éditeur dans l...
 
#OSSPARIS19 - Table ronde : souveraineté des données
#OSSPARIS19 - Table ronde : souveraineté des données #OSSPARIS19 - Table ronde : souveraineté des données
#OSSPARIS19 - Table ronde : souveraineté des données
 
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
#OSSPARIS19 - Comment financer un projet de logiciel libre - LUDOVIC DUBOST, ...
 
#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...
#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...
#OSSPARIS19 - BlueMind v4 : les dessous technologiques de 10 ans de travail p...
 
#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...
#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...
#OSSPARIS19 - Tuto de première installation de VITAM, un système d'archivage ...
 

OWF12/PAUG Conf Days Android system development, maxime ripard, free electrons

  • 1. OpenWorld Forum 2012 Android System Free Electrons Development Embedded Linux Developers Maxime Ripard Free Electrons maxime.ripard@free- electrons.com Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 1/25
  • 2. Maxime Ripard Embedded Linux engineer and trainer at Free Electrons since 2011 Embedded Linux development: kernel and driver development, system integration, boot time and power consumption optimization, consulting, etc. Embedded Linux training, Linux driver development training and Android system development training, with materials freely available under a Creative Commons license. http://www.free-electrons.com Contributor to various open-source projects: Barebox, Linux, Buildroot Living in Toulouse, south west of France Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 2/25
  • 3. Why Modify Android ? Because we have a custom set of functions on a given device that isn’t handled by the vanilla Android Because we want to add a different UI/set of features than AOSP Because since we have access to the source code, we can! Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 3/25
  • 4. The Android Stack Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 4/25
  • 5. Devices in the Source Tree The build system is using a configuration mechanism based on various layer of hardware design The upper layer, the product is typically the one we want to build a system for The build system has no other configuration mechanism: no Kconfig, text file, or any other mecanism that can be easily modified Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 5/25
  • 6. Product, devices and boards Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 6/25
  • 7. Defining new products Devices are well supported by the Android build system. It allows to build multiple devices with the same source tree, to have a per-device configuration, etc. All the product definitions should be put in device/<company>/<device> The entry point is the AndroidProducts.mk file, which should define the PRODUCT_MAKEFILES variable This variable defines where the actual product definitions are located. It follows such an architecture because you can have several products using the same device If you want your product to appear in the lunch menu, you need to create a vendorsetup.sh file in the device directory, with the right calls to add_lunch_combo Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 7/25
  • 8. Our New Product AndroidProducts.mk PRODUCT_MAKEFILES += $(LOCAL_DIR)/full_product.mk full_product.mk $(call inherit-product, build/target/product/generic.mk) PRODUCT_NAME := full_MyDevice PRODUCT_DEVICE := MyDevice PRODUCT_MODEL := Full flavor of My Brand New Device vendorsetup.sh add_lunch_combo full_product-eng Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 8/25
  • 9. Add a New Component The integration of new components into the build system are done through Android.mk files These files just contains where the source code is and what the expected result should be: an executable, a shared library, a jar file, etc. All the build magic is abstracted by the build system Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 9/25
  • 10. Add a New Library Create a new subfolder under the device/company/product/lib folder This folder will contain the source code in itself, plus the headers and the Android.mk file To include a new package into a given build, you need to add the package name to the content of the PRODUCT_PACKAGES variable Let’s use the libusb as an example Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 10/25
  • 11. Steps to add the libusb The first step is obviously to untar the source code in the device/company/product/lib/libusb folder Since the Android build system doesn’t rely at all on external build tools, we have some bits that are missing The first one is that the source code is missing the config.h header file, that is usually generated with the autoconf tool, through the ./configure command When we try to compile, it lacks two things: the TIMESPEC_TO_TIMEVAL macro and the timerfd.h header The first one should be declared by the c library, let’s add the macro declaration where the source code is using it The timerfd.h file is one of the header exposed by the Linux Kernel. It is not in the headers found in the toolchain used by Android though, so we will need to disable the use of such feature through the command ./configure --disable-timerfd Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 11/25
  • 12. Library Makefile LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := core.c descriptor.c io.c sync.c os/linux_usbfs.c LOCAL_C_INCLUDES += $(LOCAL_PATH)/os LOCAL_MODULE:= libusb LOCAL_MODULE_TAGS:= optional LOCAL_PRELINK_MODULE:= false include $(BUILD_SHARED_LIBRARY) Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 12/25
  • 13. Next steps The libusb uses the device files under the folder /dev/bus/usb, that are only readable by the root user and the usb group. The device files creations are handled by the init application, so that when a new device appears on the system, its associated device files will be created as well The specific part of init that handles these files is called ueventd It uses a set of rules to create device files with the correct permissions at runtime If we want to use a binary running as user and that has access to the USB devices, we’ll have to modify these permissions Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 13/25
  • 14. Modify the permissions of the device files Permissions on the files are the enforced thanks to two components: Permissions on files on the system are defined in a C header: android_filesystem_config.h Permissions for device files are handled by ueventd that uses a file called ueventd.rc We can modify the permissions on the device files by adding or modifying a ueventd.rc file /dev/bus/usb/* 0666 root usb Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 14/25
  • 15. Integrate a binary that uses the libusb LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= usb_bin.c LOCAL_C_INCLUDES += $(JNI_H_INCLUDE) device/company/device/lib/libusb LOCAL_SHARED_LIBRARIES := libusb LOCAL_MODULE := usbbin LOCAL_MODULE_TAGS := optional LOCAL_PRELINK_MODULE := false include $(BUILD_EXECUTABLE) Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 15/25
  • 16. JNI Bindings A Java framework to call and be called by native applications written in other languages Mostly used for: Writing Java bindings to C/C++ libraries Accessing platform-specific features Writing high-performance sections It is used extensively across the Android userspace to interface between the Java Framework and the native daemons Since Gingerbread, you can develop apps in a purely native way, possibly calling Java methods through JNI Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 16/25
  • 17. Libusb bindings Create a new subfolder under device/company/device/framework/USBFramework/jni Write the JNI bindings so that the Java can call functions from the libusb Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 17/25
  • 18. Libusb bindings static struct libusb_device_handle *devh; JNIEXPORT void JNICALL Java_com_fe_USB_init(JNIEnv *env, jobject obj) { ret = libusb_init(NULL); if (ret < 0) return ret; devh = libusb_open_device_with_vid_pid(NULL, 0xdead, 0xbeef); if (!devh) { libusb_exit(NULL); return -EINVAL; } return 0; } Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 18/25
  • 19. Android.mk for the bindings LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= usb_jni.c LOCAL_C_INCLUDES += $(JNI_H_INCLUDE) device/company/device/lib/libusb LOCAL_SHARED_LIBRARIES := libusb LOCAL_MODULE := libusb_jni LOCAL_MODULE_TAGS := optional LOCAL_PRELINK_MODULE := false include $(BUILD_SHARED_LIBRARY) Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 19/25
  • 20. Java Framework package com.fe; class USB { private native void init(); public USB() { init(); } static { System.loadLibrary("usb_jni"); } } Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 20/25
  • 21. Android.mk for the framework LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_MODULE_TAGS := optional LOCAL_MODULE:= com.fe.usb include $(BUILD_JAVA_LIBRARY) Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 21/25
  • 22. Permissions file <?xml version="1.0" encoding="utf-8"?> <permissions> <library name="com.fe.usb" file="/system/framework/com.fe.usb.jar"/> </permissions> Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 22/25
  • 23. Applications using that code Any applications can now use the part of the framework we just added, using a regular Java call However, by default, the jar file generated won’t be loaded by dalvik, resulting in a error at runtime. You need to add extra bits to the manifest file so that both the Play Store and Dalvik knows that you need the given jar file to work properly You need to add the <uses-library> XML tag Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 23/25
  • 24. Android Manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.fe.usb"> <application android:icon="@drawable/icon" android:label="@string/app_name"> ... <uses-library android:name="com.fe.usb" android:required="true" /> </application> </manifest> Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 24/25
  • 25. Questions? Maxime Ripard maxime.ripard@free-electrons.com Slides under CC-BY-SA 3.0. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 25/25