<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.6(BH)" -->
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>Planet Maemo: category &quot;feed:3443cd3b09dca3afd960884d779d28f3&quot;</title>
        <description>Blog entries from Maemo community</description>
        <link>http://maemo.org/news/planet-maemo/</link>
        <lastBuildDate>Sun, 05 Apr 2026 01:38:50 +0000</lastBuildDate>
        <generator>FeedCreator 1.7.6(BH)</generator>
        <language>en</language>
        <managingEditor>planet@maemo.org</managingEditor>
        <item>
            <title>IOCTL Android</title>
            <link>http://raulherbster.blogspot.com/2015/11/ioctl-android.html</link>
            <description><![CDATA[
IOCTL is a very useful system call: it is simple and multiplexes the different commands to the appropriate kernel space function. In this post, I want to describe how you can implement a module with IOCTL support for Android. There are a lot of good articles about it (links below), and I just describe the differences regarding to the Android platform.<br />
<br />
So, let's create a very simple misc device and let's play with it, doing some reads and writes. Initially, let's define a very simple kernel module (most of the code was taken from <a href="http://people.ee.ethz.ch/~arkeller/linux/multi/kernel_user_space_howto-4.html" target="_blank">here</a>).<br />
<br />
<pre class="c" name="code">#include &lt;linux/kernel.h&gt;
#include &lt;linux/module.h&gt;
#include &lt;linux/fs.h&gt;
#include &lt;linux/miscdevice.h&gt;
#include &lt;asm/uaccess.h&gt;


#define MY_MACIG 'G'
#define READ_IOCTL _IOR(MY_MACIG, 0, int)
#define WRITE_IOCTL _IOW(MY_MACIG, 1, int)
 
static int used; 
static char msg[200];

static ssize_t device_read(struct file *filp, char __user *buffer, size_t length, loff_t *offset)
{
  return simple_read_from_buffer(buffer, length, offset, msg, 200);
}

static ssize_t device_write(struct file *filp, const char __user *buff, size_t len, loff_t *off)
{
  if (len &gt; 199)
    return -EINVAL;
  copy_from_user(msg, buff, len);
  msg[len] = '\0';
  return len;
}

static int device_open(struct inode *inode, struct file *file)
{
  used++;
  return 0;
}

static int device_release(struct inode *inode, struct file *file)
{
  used--;
  return 0;
}

char buf[200];
int device_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
{
  int len = 200;
  switch(cmd) {
  case READ_IOCTL: 
    copy_to_user((char *)arg, buf, 200);
    break;
 
  case WRITE_IOCTL:
    copy_from_user(buf, (char *)arg, len);
    break;

  default:
    return -ENOTTY;
  }
  return len;
}

static struct file_operations fops = {
        .owner = THIS_MODULE,
        .read = device_read,
        .write = device_write,
        .open = device_open,
        .release = device_release,
        .unlocked_ioctl = device_ioctl
};

static struct miscdevice my_miscdev = {
        .name         = "my_device",
        .mode         = S_IRWXUGO,
        .fops         = &amp;fops,
};

static int __init cdevexample_module_init(void)
{
  int ret = misc_register(&amp;my_miscdev);
  if (ret &lt; 0) {
    printk ("Registering the character device failed\n");
    return ret;
  }
  printk("create node with mknod /dev/my_device\n");
  return 0;
}

static void __exit cdevexample_module_exit(void)
{
  misc_deregister(&amp;my_miscdev);
}  

module_init(cdevexample_module_init);
module_exit(cdevexample_module_exit);
MODULE_LICENSE("GPL");
</pre>
<br />
Compile it and insert into Android kernel.<br />
<br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ su</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ insmod my_module.ko</span><br />
<br />
Now, we can check the new device in /dev:<br />
<br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ su</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ ls -l /dev</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">...</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">crw-rw---- root&nbsp;&nbsp;&nbsp;&nbsp; mtp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10,&nbsp; 23 2015-11-23 18:04 mtp_usb</span><br />
<b><span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;"><span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">crw------- root&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10,&nbsp;&nbsp; 0 2015-11-23 18:11 my_device</span></span></b><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">crw------- root&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10,&nbsp; 36 2015-11-23 18:04 network_latency<br />crw------- root&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10,&nbsp; 35 2015-11-23 18:04 network_throughput<br />crw-rw-rw- root&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1,&nbsp;&nbsp; 3 2015-11-23 18:04 null</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">... </span><br />
<br />
See that the permissions are limited. Don't forget to set it to:<br />
<br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ chmod 666 /dev/my_device</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ ls -l /dev</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">...</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">crw-rw---- root&nbsp;&nbsp;&nbsp;&nbsp; mtp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10,&nbsp; 23 2015-11-23 18:04 mtp_usb</span><br />
<b><span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;"><span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">crw-rw-rw- root&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10,&nbsp;&nbsp; 0 2015-11-23 18:11 my_device</span></span></b><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">crw------- root&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10,&nbsp; 36 2015-11-23 18:04 network_latency<br />crw------- root&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10,&nbsp; 35 2015-11-23 18:04 network_throughput<br />crw-rw-rw- root&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1,&nbsp;&nbsp; 3 2015-11-23 18:04 null</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">... </span><br />
<br />
Now, let's try to do some operations with our device driver:<br />
<br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ echo "Hello world" &gt; /dev/my_device</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ cat /dev/my_device </span><br />
<br />
You will see the following error on the logcat:<br />
<br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">avc: denied { read write } for name="my_device" dev="tmpfs" scontext=u:r:system_app:s0 tcontext</span><br />
<br />
This means that SELinux (yes, Android makes heavy usage of it) also controls the access to device drivers and you cannot read/write from/to your new drive. You have two options: i) disable SELinux in Android (you need to change some kernel options and rebuild it) or ii) add some new rules into SELinux. Let's do the last to learn a bit more :-)<br />
<br />
So, we change the following files and give access (read, write, getattr, ioctl, open and create) to our new device /dev/my_device. If you need to restrict the access, you can adapt the policies according to your needs. For more information about SELinux and Android, take a look in this <a href="https://source.android.com/security/selinux/" target="_blank">doc</a>&nbsp;(specially the section "Implementation").<br />
<br />
external/sepolicy/device.te<br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">type fscklogs, dev_type;<br />type full_device, dev_type;<br /><b>type my_device, dev_type;</b></span><br />
<br />
external/sepolicy/file_contexts<br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">/dev/rproc_user&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; u:object_r:rpmsg_device:s0<br /><b>/dev/my_device &nbsp; &nbsp; &nbsp; &nbsp; u:object_r:my_device:s0</b><br />/dev/snd(/.*)?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; u:object_r:audio_device:s0</span><br />
<br />
external/sepolicy/app.te<br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">allow appdomain usb_device:chr_file { read write getattr ioctl };<br />allow appdomain usbaccessory_device:chr_file { read write getattr };<br /><b>allow appdomain my_device:chr_file { read write getattr ioctl open create };</b></span><br />
<br />
Now, let's build the Android framework again and flash the device. Everything should work fine.<br />
<br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ echo "Hello world" &gt; /dev/my_device</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">shell@flounder:/ $ cat /dev/my_device</span><br />
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">Hello world</span><br />
<br />
That's it!! You can also check the following links
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;"><span style="font-family: inherit;"><br /></span></span>
<br />
<ul>
<li><span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;"><span style="font-family: inherit;">http://www.all-things-android.com/content/understanding-se-android-policy-files</span></span></li>
<li><span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;"><span style="font-family: inherit;">https://source.android.com/security/selinux/</span></span></li>
</ul>
<br /><span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e5921743a35d58921711e5aad6fbb0ee6c7e6e7e6e&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e5921743a35d58921711e5aad6fbb0ee6c7e6e7e6e/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e5921743a35d58921711e5aad6fbb0ee6c7e6e7e6e&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e5921743a35d58921711e5aad6fbb0ee6c7e6e7e6e/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Mon, 23 Nov 2015 18:33:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e5921743a35d58921711e5aad6fbb0ee6c7e6e7e6e</guid>
        </item>
        <item>
            <title>Latency/Bandwidth and Performance</title>
            <link>http://raulherbster.blogspot.com/2015/11/latencybandwidth-and-performance.html</link>
            <description><![CDATA[
I've been always interested in scrapping a bit more my application... no matter its level: frontend, framework or native. That's why I guess I have decided to study a bit more Software Systems. Some weeks ago, I was implementing some tests to evaluate my current project in terms of "time spent for certain operations". In addition, I had to force some cache/memory fault, work on some *non* cache-friendly program and, at the end, I was thinking about other aspects of my system. Usually, for software systems, we pretty much focus on latency and bandwidth. For example, when you are developing an application to have an efficient access to memory (cache-friendly!), you are thinking about latency, as you want to avoid (expensive) access to a lower-level memory. Of course, depending on the operation (network, memory access, etc.), latency and bandwidth have a bit different meaning. For example, for network, latency is measured by sending a packet that is returned to the sender. For memory access, latency can be explained as "the delay time between the moment a memory controller tells the memory module to access a particular memory column on a RAM module, and the moment the data from the given array location is available on the module's output pins". [<a href="https://en.wikipedia.org/wiki/CAS_latency" target="_blank">Wiki</a>]<br />
<br />
I took a look on some amazing links that gave me a very precise and detailed view about such discussion and here they are:<br />
<br />
<ul>
<li><a href="https://www.youtube.com/watch?v=L7zSU9HI-6I" target="_blank">Herb Sutter @ NWCPP</a> - This is an amazing talk.It shows how your program actually uses your machine's architecture;</li>
<li><a href="http://web.cecs.pdx.edu/~jrb/cs201/lectures/cache.friendly.code.pdf" target="_blank">Gerson Robboy Lecture Note</a> - Very good lecture notes with some examples and exercises; </li>
<li><a href="http://stackoverflow.com/questions/16699247/what-is-cache-friendly-code" target="_blank">Great stackoverflow post</a>;</li>
<li><a href="https://gist.github.com/jboner/2841832" target="_blank">Table</a> with interesting numbers about latency;</li>
<li><a href="http://www.javacodegeeks.com/2012/08/memory-access-patterns-are-important.html" target="_blank">Latency through a Java</a> perspective;</li>
</ul>
<br />
<br /><span class="net_nemein_favourites">1 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e588900f7b951c889011e581c6aba616085eb05eb0&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e588900f7b951c889011e581c6aba616085eb05eb0/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e588900f7b951c889011e581c6aba616085eb05eb0&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e588900f7b951c889011e581c6aba616085eb05eb0/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Wed, 11 Nov 2015 15:43:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e588900f7b951c889011e581c6aba616085eb05eb0</guid>
        </item>
        <item>
            <title>Asynchronous and synchronous I/O in Android NDK</title>
            <link>http://raulherbster.blogspot.com/2015/09/assynchronous-and-synchronous-io-in.html</link>
            <description><![CDATA[
This week, I had some issues on my tests in a Lollipop device with AOSP. I really wanted to have synchronous reads/writes so that I could evaluate my solution in a different way. I am also trying to minimize the effects of caching as much as possible. If you check for async and sync I/O operations for Linux, you'll a lot of references to the flags O_DIRECT, O_SYNC, O_DSYNC, ...<br />
<br />
Actually, that's a good way to implement. However, with Android NDK apps, things are not so straightforward.<br />
<br />
First, to have a good understanding about the O_*SYNC flags, check <a href="https://lwn.net/Articles/350219/" target="_blank">this</a> link. Of course, the <a href="http://linux.die.net/man/2/open" target="_blank">man page</a> for the command open as well.<br />
<br />
First, O_DIRECT does not work in Android since 4.4. See <a href="http://code.google.com/p/android/issues/detail?id=67406" target="_blank">this link</a> for more details about it.&nbsp; That's sad. So, let's try to use the O_*SYNC data.<br />
<br />
O_SYNC and O_DSYNC work fine in Android. But, as the description say, only for writes. Another detail: for Android, O_SYNC has the same semantics as O_DSYNC. That's good, but I still want something similar to reads as well.<br />
<br />
Why don't we use O_RSYNC? Well, Android does not implement it :-( But it's not the only one... there are other Linux distributions that don't do it either.<br />
<br />
What about dropping caches?? See this <a href="http://linux-mm.org/Drop_Caches" target="_blank">link</a> for more details. Hum, that works, but after the first read, the data will be cached again :-(<br />
<br />
So, I am still looking for a solution for Android Lollipop. Hope to post it soon!<br />
<br />
<br /><span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e5554137cde39e554111e5b7d1b3b3358001a701a7&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e5554137cde39e554111e5b7d1b3b3358001a701a7/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e5554137cde39e554111e5b7d1b3b3358001a701a7&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e5554137cde39e554111e5b7d1b3b3358001a701a7/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Mon, 07 Sep 2015 09:13:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e5554137cde39e554111e5b7d1b3b3358001a701a7</guid>
        </item>
        <item>
            <title>Android - Using Crypto extensions</title>
            <link>http://raulherbster.blogspot.com/2015/08/android-using-crypto-extensions.html</link>
            <description><![CDATA[
I had some problems compiling ASM code as part of an Android kernel module.<br />
<br />
As part of my system, I need to encrypt/decrypt data inside the kernel and I decided to use AES CBC with 128 bits keys. I am also using a Nexus 9 (arm64 v8), which means that I have access to crypto extensions, including instructions for AES operations :-)<br />
<br />
Considering this scenario, I implemented 3 options (of course, I picked the most efficient one at the end):<br />
<ol>
<li>A "standard" AES CBC implementation in C (the worst performance);</li>
<li>The Linux kernel Crypto lib with crypto extensions set to ON (good performance and very easy to use);</li>
<li>The AES CBC asm implementation from the OpenSSL lib (good performance and it took me extra time to integrate it into my code);</li>
</ol>
At the end, I took the option #03. Both #02 and #03 have good performance, but #03 is slightly better.<br />
<br />
Let's discuss #02 and #03 in this post.<br />
<br />
As the very first step, check if your kernel has the proper options enabled for the crypto extension usage. The following ones should be set to "y":<br />
<br />
CONFIG_CRYPTO_HW<br />
CONFIG_ARM64_CRYPTO<br />
CONFIG_CRYPTO_AES_ARM64_CE<br />
CONFIG_CRYPTO_AES_ARM64_CE_CCM<br />
CONFIG_CRYPTO_AES_ARM64_CE_BLK<br />
<h4>
The Crypto lib</h4>
The Linux kernel provides the Crypto library, with several cryptography operations, such as AES, including different block/streams ciphers. The following code use AES 128-bits CBC, and a 0-ed IV (don't do that!)<br />
<br />
<pre class="c" name="code">static int pc_aes_encrypt_kernel(const void *key, int key_len,
                                        void *dst, size_t *dst_len,
                                        const void *src, size_t src_len)
{
        struct crypto_blkcipher *blkcipher = NULL;
        char *cipher = "__cbc-aes-ce";
        char iv[AES_BLOCK_SIZE];
        char *charkey = (unsigned char *) key;

        unsigned int ivsize = 0;
        char *scratchpad_in = NULL, *scratchpad_out = NULL; 
        struct scatterlist sg_in, sg_out;
        struct blkcipher_desc desc;
        int ret = -EFAULT;
        int len = ((int)(src_len/16) + 1) * 16;

        memset(iv, 0x00, AES_BLOCK_SIZE); // set the iv to a proper value!!

        blkcipher = crypto_alloc_blkcipher(cipher, 0, 0);
        if (IS_ERR(blkcipher)) {
                PC_LOGV("could not allocate blkcipher handle for %s\n", cipher);
                return -PTR_ERR(blkcipher);
        }

        if (crypto_blkcipher_setkey(blkcipher, charkey, key_len)) {
                PC_LOGV("key could not be set\n");
                ret = -EAGAIN;
                goto out;
        }

        ivsize = crypto_blkcipher_ivsize(blkcipher);
        if (ivsize) {
                if (ivsize != AES_BLOCK_SIZE)
                        PC_LOGV("IV length differs from expected length. It should be : %d\n",ivsize);
                crypto_blkcipher_set_iv(blkcipher, iv, ivsize);
        }

        scratchpad_in = kmalloc(src_len, GFP_KERNEL);
        if (!scratchpad_in) {
                PC_LOGV("could not allocate scratchpad_in for %s\n", cipher);
                goto out;
        }

        scratchpad_out = kmalloc(len, GFP_KERNEL);
        if (!scratchpad_out) {
                PC_LOGV("could not allocate scratchpad_in for %s\n", cipher);
                goto out;
        }

        memcpy(scratchpad_in,src,src_len);

        desc.flags = 0;
        desc.tfm = blkcipher;
        sg_init_one(&amp;sg_in, scratchpad_in, src_len);
        sg_init_one(&amp;sg_out, scratchpad_out, len);

        crypto_blkcipher_encrypt(&amp;desc, &amp;sg_out, &amp;sg_in, src_len);

        // for decryption, use the following
        // crypto_blkcipher_decrypt(&amp;desc, &amp;sg_out, &amp;sg_in, src_len);

        memcpy(dst,scratchpad_out,sg_out.length);

        *dst_len = sg_out.length;

        ret = 0;
        goto out;

out:
        if (blkcipher)
                crypto_free_blkcipher(blkcipher);
        if (scratchpad_out)
                kzfree(scratchpad_out);
        if (scratchpad_in)
                kzfree(scratchpad_in);

        return ret;

}
</pre>
<br />
For decryption, you can use the same code, but use the function crypto_blkcipher_decrypt instead.<br />
<h4>
Integrating a *.S file as part if your module built process</h4>
As said, I used an existing implementation from OpenSSL, which uses the crypto extensions of arm64-v8. I only had to change the "includes" of the asm file. In addition, I included the object file into my Makefile, like this:<br />
<pre class="make" name="code">
</pre>
<pre class="make" name="code">pc_module-objs := ...
                  src/pc_utility.o src/asm/aesv8-armx-64.o \
                  src/crypto/aes.o src/crypto/crypto.o

</pre>
<br />
However, I had some problems with different asm files that I was testing. For example, for the OpenSSL library, some of them will not compile if you use GCC 4.8/4.9. The point is that they use a different architectural syntax (Apple) and you'll see several "Error: unknown mnemonic" error messages.<br />
<br />
So, you can use LLVM to compile the asm files with the Apple architectural syntax. LLVM is available in the Android NDK. Then, you can copy the *.o files into your code and build your project. The symbols should match as a charm.<br />
<br />
The following code shows the usage of the functions defined in the file aesv8-armx-64.S (available into the folder <span style="font-family: Courier New, Courier, monospace;"><android_code>/external/openssl/</android_code></span>)<br />
<pre class="c" name="code">
</pre>
<pre class="c" name="code">static int pc_aes_encrypt_hw(const void *key, int key_len,
                                        void *dst, size_t *dst_len,
                                        const void *src, size_t src_len)
{
        AES_KEY enc_key;

        unsigned char enc_out[src_len];
        unsigned char iv[AES_BLOCK_SIZE];
        unsigned char *aes_input = (unsigned char *) src;
        unsigned char *aes_key = (unsigned char *) key;

        memset(iv, 0x00, AES_BLOCK_SIZE);

        HWAES_set_encrypt_key(aes_key, key_len*8, &amp;enc_key);
        HWAES_cbc_encrypt(aes_input, enc_out, src_len, &amp;enc_key, iv, AES_ENCRYPT);

        *dst_len = src_len;
        memcpy(dst,&amp;enc_out[0],src_len);

        return 0;
}

static int pc_aes_decrypt_hw(const void *key, int key_len,
                                        void *dst, size_t *dst_len,
                                        const void *src, size_t src_len)
{
        AES_KEY dec_key;

        unsigned char iv[AES_BLOCK_SIZE];
        unsigned char dec_out[src_len];
        unsigned char *aes_input = (unsigned char *) src;
        unsigned char *aes_key = (unsigned char *) key;

        memset(iv, 0x00, AES_BLOCK_SIZE);

        HWAES_set_decrypt_key(aes_key, key_len*8, &amp;dec_key);
        HWAES_cbc_encrypt(aes_input, dec_out, src_len, &amp;dec_key, iv, AES_DECRYPT);

        *dst_len = src_len;
        memcpy(dst,&amp;dec_out[0],src_len);

        return 0;
}
</pre>
<br />
<br />
The functions HWAES_set_encrypt_key, HWAES_set_decrypt_key, HWAES_cbc_encrypt and HWAES_cbc_decrypt are implemented in a asm file (aesv8-armx-64.S) and defined in a header file (aes_cbc.h). Again, I used AES 128-bits CBC, with 0-ed IV (don't do that!).<br />
<br />
<br /><span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e54503fa067bae450311e5b12b67530ac280a180a1&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e54503fa067bae450311e5b12b67530ac280a180a1/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e54503fa067bae450311e5b12b67530ac280a180a1&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e54503fa067bae450311e5b12b67530ac280a180a1/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Mon, 17 Aug 2015 16:28:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e54503fa067bae450311e5b12b67530ac280a180a1</guid>
        </item>
        <item>
            <title>New syscalls for armv8-64 kernel</title>
            <link>http://raulherbster.blogspot.com/2015/07/new-syscalls-for-armv8-64-kernel.html</link>
            <description><![CDATA[
I decided to use a different target platform for my project. Initially, I was using Android Kitkat + Galaxy Nexus (ARMv7 + TI OMAP 4460). To obtain best performance with some crypto operations, I am now using Android Lollipop + Nexus 9 (ARMv8 64bits). I did some tests with basic OpenSSL examples (for example, AES-128 and SHA1) and the numbers are impressive.<br />
<br />
The goal of this post is to document some problems that I had building the Android image and its respective kernel. You might think that I am being redundant, as you [might] have the same issues with a traditional Linux kernel. I've done this only for Android platform, so I don't know for other kernels. I'm also having some other problems, such as ARMv8-64 asm file compilation inside the kernel, but this will be described in another poster.<br />
<br />
Basically, in my project, I have to create new syscalls and also change the sys_call_table to intercept existing ones, such as NR_write, NR_open, etc. You can check another post that describes how to create new syscalls and how to intercept existing syscalls. So, what is different?<br />
<br />
<h4>
1. Some syscalls have changed, some have been created and some others are not supported anymore.&nbsp;</h4>
<div>
<br /></div>
<span style="font-family: Courier New, Courier, monospace;">&nbsp;__NR_open, __NR_link, __NR_chmod, __NR_rename,</span> ... are not supported anymore. Instead, you should use <span style="font-family: Courier New, Courier, monospace;">__NR_openat, __NR_mkdirat,</span> ...<br />
<br />
For example, check the syscalls under the #def body <span style="font-family: Courier New, Courier, monospace;">__ARCH_WANT_SYSCALL_DEPRECATED</span> and <span style="font-family: Courier New, Courier, monospace;">__ARCH_WANT_SYSCALL_NO_AT</span> (file include/uapi/asm-generic/unistd.h)<br />
<br />
In addition, the syscall number has also been changed. For example, NR_write changed from 3 to 63. Remember to change your code in userpsace that has any reference to one of these numbers.<br />
<br />
<h4>
2. Much easier than before: now, you only need to change less files. Add the definition of your syscalls in the following files:</h4>
<div>
<br /></div>
<b>include/linux/syscalls.h</b><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;...</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;asmlinkage long sys_seccomp(unsigned int op, unsigned int flags,</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const char __user *uargs);</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">&nbsp;asmlinkage long sys_my_syscall(void __user *buf);</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;...</span><br />
<br />
<b>include/uapi/asm-generic/unistd.h</b><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;...</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;#define __NR_seccomp 277</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;__SYSCALL(__NR_seccomp, sys_seccomp)</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">&nbsp;#define __NR_my_syscall 278</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;__SYSCALL(__NR_my_syscall, sys_my_syscall)</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">&nbsp;#undef __NR_syscalls</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;#define __NR_syscalls 279</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;...</span><br />
<br />
<b>kernel/my_syscall_code.c</b> (this file should contain the implementation of your syscall)<br />
<br />
<b>kernel/Makefile</b><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;obj-y = ....</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;...</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;async.o range.o groups.o lglock.o smpboot.o \</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;my_syscall_code.o</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp;...</span><br />
<br />
<h4>
3. Don't forget to add <i>asm/unistd.h</i> as part of your head files.</h4>
<div>
<br /></div>
<h4>
4. Kernel modules are implemented the same way as before. To build it, remember to set cflags properly</h4>
<div>
<br class="Apple-interchange-newline" />
There's just a small change on building the module. Call make with&nbsp;<span style="font-family: Courier New, Courier, monospace;">CFLAGS_MODULE=-fno-pic</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<h4>
5. And of course, the syscall table address table has changed as well.&nbsp;</h4>
<div>
<br /></div>
<div>
Check the symbol <span style="font-family: Courier New, Courier, monospace;">sys_call_table</span> in the file System.map.</div>
<div>
<br /></div>
As said, I am having other problems with it. In my case, I want to add some assembly files into my module and compile them all together. The point is that they are written in a specific format that GCC does not understand, but clang. So, things would be solved if I could use clang to build my module, but it doesn't work like that :-( Let's what comes next!<br />
<br />
EDIT (31/07/2015) :<a href="http://www.viva64.com/en/a/0065/" target="_blank"> this is a good guide for 32 bits -&gt; 64 bits porting</a><br />
<br /><span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e52d70902a17a42d7011e59a7209becefe44224422&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e52d70902a17a42d7011e59a7209becefe44224422/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e52d70902a17a42d7011e59a7209becefe44224422&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e52d70902a17a42d7011e59a7209becefe44224422/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Sat, 18 Jul 2015 16:17:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e52d70902a17a42d7011e59a7209becefe44224422</guid>
        </item>
        <item>
            <title>UEvents in Android - from kernel events to notifications</title>
            <link>http://raulherbster.blogspot.com/2015/06/uevents-in-android-from-kernel-events.html</link>
            <description><![CDATA[
In my current project, the system has to notify the user about a certain action that actually takes place inside the kernel (in this case, transfer of security keys). I don't want to get into too much details about the tasks, but let's consider that the kernel and the Dalvik are the only trustworthy components and the security keys are stored inside the kernel. I've also seen some pieces of code that helps to implement this, but I could not find a end-to-end solution.<br />
<br />
[This post is a bit long, as it contains a lot of code and I tried to explain some details of it.]<br />
<br />
Ok, let's proceed. This is the flow:<br />
<br />
1) The kernel is asked to perform a certain syscall (transfer securely stored keys inside the kernel);<br />
2) The kernel has to notify the user that some application has asked to do something suspicious, for example, to have access to some security keys;<br />
3) The event is sent all the way to the userspace and a notification appears to the user (UI).<br />
<br />
First, we have to generate one event in the kernel space (you can create a module and insert your code there). For this, we use an UEVENT. In addition, we can also add extra pieces of information into the event, for example strings, integers and so forth. The following code shows a simple UEVENT generated from the kernel space. It contains one integer field called "etype".<br />
<br />
Some pieces of code were taken from the kernel itself (linux/samples/kobject/kset-example.c), and I made small changes to keep it even simpler. For more information, check the original one.<br />
<br />
Initially, we need to create a kobject to embedded an attribute, for instance (https://www.kernel.org/doc/Documentation/kobject.txt). Once the kobject is registered, we broadcast it to other components of the system using&nbsp;<span style="white-space: pre-wrap;">kobject_uevent(). The files foo_kobject.c/h and foo_event.c/h contain code to broadcast an UEvent using a kobject. </span><br />
<br />
foo_kobject.h (kernel code, for example, as part of your module)<br />
<pre class="c" name="code">#ifndef FOO_KOBJECT_
#define FOO_KOBJECT_

/* 
 * Partially copied from linux/samples/kobject/kset-example.c
 *
 * Released under the GPL version 2 only.
 */

/*
 * This is our "object" that we will create and register it with sysfs.
 */
struct foo_obj {
 struct kobject kobj;
 int foo;
};
#define to_foo_obj(x) container_of(x, struct foo_obj, kobj)

struct foo_obj *
create_foo_obj(const char *name);

int 
foo_kobj_init(void);

void
foo_kobj_exit(void);

#endif
</pre>
<br />
foo_kobject.c (kernel code, for example, as part of your module)<br />
<pre class="c" name="code">/*
 * Partially copied from linux/samples/kobject/kset-example.c
 *
 * Released under the GPL version 2 only.
 *
 */

#include &lt;linux/kobject.h&gt;
#include &lt;linux/string.h&gt;
#include &lt;linux/sysfs.h&gt;
#include &lt;linux/slab.h&gt;
#include &lt;linux/module.h&gt;
#include &lt;linux/init.h&gt;

#include "foo_kobject.h"

/*
 * This module shows how to create a kset in sysfs called
 * /sys/kernel/foo
 * Then one kobject is created and assigned to this kset, "foo".  
 * In this kobject, one attribute is also
 * created and if an integer is written to these files, it can be later
 * read out of it.
 */

/* a custom attribute that works just for a struct foo_obj. */
struct foo_attribute {
 struct attribute attr;
 ssize_t (*show)(struct foo_obj *foo, struct foo_attribute *attr, char *buf);
 ssize_t (*store)(struct foo_obj *foo, struct foo_attribute *attr, const char *buf, size_t count);
};
#define to_foo_attr(x) container_of(x, struct foo_attribute, attr)

/*
 * The default show function that must be passed to sysfs.  This will be
 * called by sysfs for whenever a show function is called by the user on a
 * sysfs file associated with the kobjects we have registered.  We need to
 * transpose back from a "default" kobject to our custom struct foo_obj and
 * then call the show function for that specific object.
 */
static ssize_t foo_attr_show(struct kobject *kobj,
        struct attribute *attr,
        char *buf)
{
 struct foo_attribute *attribute;
 struct foo_obj *foo;

 attribute = to_foo_attr(attr);
 foo = to_foo_obj(kobj);

 if (!attribute-&gt;show)
  return -EIO;

 return attribute-&gt;show(foo, attribute, buf);
}

/*
 * Just like the default show function above, but this one is for when the
 * sysfs "store" is requested (when a value is written to a file.)
 */
static ssize_t foo_attr_store(struct kobject *kobj,
         struct attribute *attr,
         const char *buf, size_t len)
{
 struct foo_attribute *attribute;
 struct foo_obj *foo;

 attribute = to_foo_attr(attr);
 foo = to_foo_obj(kobj);

 if (!attribute-&gt;store)
  return -EIO;

 return attribute-&gt;store(foo, attribute, buf, len);
}

/* Our custom sysfs_ops that we will associate with our ktype later on */
static const struct sysfs_ops foo_sysfs_ops = {
 .show = foo_attr_show,
 .store = foo_attr_store,
};

/*
 * The release function for our object.  This is REQUIRED by the kernel to
 * have.  We free the memory held in our object here.
 *
 * NEVER try to get away with just a "blank" release function to try to be
 * smarter than the kernel.  Turns out, no one ever is...
 */
static void foo_release(struct kobject *kobj)
{
 struct foo_obj *foo;

 foo = to_foo_obj(kobj);
 kfree(foo);
}

/*
 * The "foo" file where the .foo variable is read from and written to.
 */
static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *attr,
   char *buf)
{
 return sprintf(buf, "%d\n", foo_obj-&gt;foo);
}

static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
    const char *buf, size_t count)
{
 sscanf(buf, "%du", &amp;foo_obj-&gt;foo);
 return count;
}

static struct foo_attribute foo_attribute =
 __ATTR(foo, 0666, foo_show, foo_store);

/*
 * Create a group of attributes so that we can create and destroy them all
 * at once.
 */
static struct attribute *foo_default_attrs[] = {
 &amp;foo_attribute.attr,
 NULL, /* need to NULL terminate the list of attributes */
};

/*
 * Our own ktype for our kobjects.  Here we specify our sysfs ops, the
 * release function, and the set of default attributes we want created
 * whenever a kobject of this type is registered with the kernel.
 */
static struct kobj_type foo_ktype = {
 .sysfs_ops = &amp;foo_sysfs_ops,
 .release = foo_release,
 .default_attrs = foo_default_attrs,
};

static struct kset *example_kset;

struct foo_obj *create_foo_obj(const char *name)
{
 struct foo_obj *foo;
 int retval;

 /* allocate the memory for the whole object */
 foo = kzalloc(sizeof(*foo), GFP_KERNEL);
 if (!foo)
  return NULL;

 /*
  * As we have a kset for this kobject, we need to set it before calling
  * the kobject core.
         */
 foo-&gt;kobj.kset = example_kset;

 /*
  * Initialize and add the kobject to the kernel.  All the default files
  * will be created here.  As we have already specified a kset for this
  * kobject, we don't have to set a parent for the kobject, the kobject
  * will be placed beneath that kset automatically.
  */
 retval = kobject_init_and_add(&amp;foo-&gt;kobj, &amp;foo_ktype, NULL, "%s", name);
 if (retval) {
  kobject_put(&amp;foo-&gt;kobj);
  return NULL;
 }

 /*
  * We are always responsible for sending the uevent that the kobject
  * was added to the system.
  */
 kobject_uevent(&amp;foo-&gt;kobj, KOBJ_ADD);

 return foo;
}

static void destroy_foo_obj(struct foo_obj *foo)
{
 kobject_put(&amp;foo-&gt;kobj);
}

int
foo_kobject_init(void)
{
 /*
  * Create a kset with the name of "kset_foo",
  * located under /sys/kernel/
  */
 example_kset = kset_create_and_add("kset_foo", NULL, kernel_kobj);
 if (!example_kset)
  return -ENOMEM;

}

void 
foo_kobject_exit(void)
{
 destroy_foo_obj(foo_kobj);
 kset_unregister(example_kset);
}
</pre>
<br />
foo_uevent.h (kernel code, for example, as part of your module)
<br />
<pre class="c" name="code">#ifndef FOO_UEVENT_
#define FOO_UEVENT_

enum FOO_event_type {
  FOO_GET = 1,
  FOO_SET
};

struct foo_event {
  enum foo_event_type etype;
};

int foo_init_events(void);

int foo_send_uevent(struct foo_event *fooe);

#endif

</pre>
<br />
In the following code, we send an event string as part of our new UEvent. In our case, just the type of the event (FOO_GET or FOO_SET).
foo_uevent.c (kernel code, for example, as part of your module)
<br />
<pre class="c" name="code">#include &lt;linux/kobject.h&gt;
#include "foo_kobject.h"
#include "foo_uevent.h"

static struct foo_obj *foo_kobj;

int foo_init_events(void)
{
  int ret;

  ret = example_init();
  if (ret) 
  { 
    printk("error - could not create ksets\n");  
    goto foo_error;
  } 
 
  foo_kobj = create_foo_obj("foo");
  if (!foo_kobj)
  {
    printk("error - could not create kobj\n"); 
    goto foo_error;
  }
 
  return 0;

foo_error:
  return -EINVAL;
}

int foo_send_uevent(struct foo_event *pce)
{
  char event_string[20];
  char *envp[] = { event_string, NULL };

  if (!foo_kobj)
    return -EINVAL;

  snprintf(event_string, 20, "FOO_EVENT=%d", pce-&gt;etype);

  return kobject_uevent_env(&amp;foo_kobj-&gt;kobj, KOBJ_CHANGE, envp);
}

</pre>
So far, we've only made changes in the kernel level. But also, we need to listen to UEVENTs in the userspace. For that, I changed a little bit the Dalvik and added the following binder to listen to UEvents and send notifications, so that the user can see the event.<br />
<br />
For more details on how to add a system service in Android, check this <a href="http://processors.wiki.ti.com/index.php/Android-Adding_SystemService">link</a>. In this case, I added a Binder, as we are not providing any service (setting an integer, for instance). In our example, we simply broadcast events to the user interface.</br>
</br>
To add the following Binder, create a file that contains the code into framework/base/services/java/com/android/server/. You also have to change the file Android.mk at framework/base/services/jni/Android.mk<br />
<br />
<pre class="c" name="code">
...
LOCAL_SRC_FILES:= \
     com_android_server_VibratorService.cpp \
     com_android_server_location_GpsLocationProvider.cpp \
     com_android_server_connectivity_Vpn.cpp \
+    com_android_server_pm_PackageManagerService.cpp \
     onload.cpp
...
</pre>
<br />
Also, don't forget to register the service (check the link that I mentioned before!), by changing the file framework/base/services/java/com/android/server/SystemServer.java
<br />
<br />
<pre name="code" class="java">
class ServerThread extends Thread {
...
         WifiP2pService wifiP2p = null;
         WifiService wifi = null;
         NsdService serviceDiscovery= null;
+        MyServiceBinder myService = null;
         IPackageManager pm = null;
         Context context = null;
         WindowManagerService wm = null;
...
         class ServerThread extends Thread {
...
             }

             try {
+                Slog.i(TAG, "My Service - Example");
+                myService = MyServiceBinder.create(context);
+                ServiceManager.addService(
+                        Context.MY_SERVICE, myService);
+            } catch (Throwable e) {
+                reportWtf("starting Privacy Capsules Service", e);
+            }
+
...
</pre>
<br />
Finally, here is the Java code. This Binder simply listens to UEvents that contains the string "FOO_EVENT", which also embeds the integer as part of the UEvent. Then, we create a UI notification and we attach an Intent to the notification, so that when the user clicks on it, a Activity or a Dialog is launched.
<br />
<pre class="java" name="code">...
public class MyServiceBinder extends Binder {

    private final int FOO_GET = 1;
    private final int FOO_SET = 2;

    private MyServiceWorkerThread mWorker;
    private MyServiceWorkerHandler mHandler;
    private Context mContext;
    private NotificationManager mNotificationManager;

    /*
     * We create an observer to listen to the UEvent we are interested in. 
     * See UEventObserver#startObserving(String). From the UEvent, we extract 
     * an existing integer field and we propagate create a notification to 
     * be seen by the user.
     */
    private final UEventObserver mUEventObserver = new UEventObserver() {
        @Override
        public void onUEvent(UEventObserver.UEvent event) {
            final int eventType = Integer.parseInt(event.get("FOO_EVENT"));
            sendMyServiceNotification(eventType);
        }
    };

    public MyServiceBinder(Context context) {
        super();
        mContext = context;
        mNotificationManager = (NotificationManager)mContext.getSystemService(
                               Context.NOTIFICATION_SERVICE);

         /* We have to specify a filter to receive only certain UEvents from the 
          * kernel. In this case, the UEVENT that we want to listen to contains 
          * the string "FOO_EVENT".
          */
        mUEventObserver.startObserving("FOO_EVENT=");

        mWorker = new MyServiceWorkerThread("MyServiceWorker");
        mWorker.start();
    }

    /*
     * Add potential initialization steps here
     */
    public static MyServiceBinder create(Context context) {
        MyServiceBinder service = new MyServiceBinder(context);
        return service;
    }
    
    /*
     * Sends notification to the user. In this case, we are create notifications. 
     * If the user clicks on the notification, we send an Intent so that an system 
     * application is launched. For example, if we are listening to notifications 
     * for USB UEvents, the USB Settings application can be launched when the 
     * notification is clicked.
     */
    private final void sendNotificationToUser(int type) {
        String notificationMessage = "";
        Resources r = mContext.getResources();
        switch(type) {
                case FOO_GET:
                // do something if the event type is A
                notificationMessage = "This is event type FOO_GET";
                break;
                case FOO_SET:
                // do something if the event type is B
                notificationMessage = "This is event type FOO_SET";      
                break;
                default:
                break;
        }  

        String notificationTitle = r.getString(R.string.my_service_notification_title);
        long notificationWhen = System.currentTimeMillis();
        int requestID = (int) notificationWhen;
 
        Intent intent = new Intent(Intent.ACTION_FOO_EVENT);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
                        | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        intent.putExtra(FooManager.EXTRA_ETYPE, type);
        intent.putExtra(FooManager.EXTRA_MESSAGE, notificationMessage);

        PendingIntent pi = PendingIntent.getActivityAsUser(mContext, requestID,
                                intent, 0, null, UserHandle.CURRENT);

        Notification notification = new Notification.Builder(mContext)
                        .setSmallIcon(R.drawable.indicator_input_error)
                        .setContentTitle(notificationTitle)
                        .setContentText(notificationMessage)
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setDefaults(0)
                        .setWhen(notificationWhen)
                        .setOngoing(true)
                        .setContentIntent(pi)
                        .setAutoCancel(true)
                        .build();

        mNotificationManager.notifyAsUser(null,
                        R.string.my_service_notification_title,
                        notification, UserHandle.ALL);
    }


    /*
     * Runner for the 
     *
     */
    private void sendMyServiceNotification(final int type) {
        
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                sendNotificationToUser(type);
            }
        });

    }

    private class MyServiceWorkerThread extends Thread {

        public MyServiceWorkerThread(String name) {
            super(name);
        }

        public void run() {
            Looper.prepare();
            mHandler = new MyServiceWorkerHandler();
            Looper.loop();
        }

    }
 
    private class MyServiceWorkerHandler extends Handler {

        private static final int MESSAGE_SET = 0;

        @Override
        public void handleMessage(Message msg) {
            try {
                if (msg.what == MESSAGE_SET) {
                    Log.i(TAG, "set message received: " + msg.arg1);
                }
            } catch (Exception e) {
                // Log, don't crash!
                Log.e(TAG, "Exception in MyServiceWorkerHandler.handleMessage:", e);
            }
        }

    }
}
</pre><span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e512b98b036cc012b911e59a48c38503f33bcb3bcb&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e512b98b036cc012b911e59a48c38503f33bcb3bcb/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e512b98b036cc012b911e59a48c38503f33bcb3bcb&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e512b98b036cc012b911e59a48c38503f33bcb3bcb/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Sun, 14 Jun 2015 16:43:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e512b98b036cc012b911e59a48c38503f33bcb3bcb</guid>
        </item>
        <item>
            <title>Android Linux Kernel module building/installation</title>
            <link>http://raulherbster.blogspot.com/2015/05/android-linux-kernel-module.html</link>
            <description><![CDATA[
Let's now show how to install a module into the just compiled Android kernel (see <a href="http://raulherbster.blogspot.de/2014/07/android-imagekernel-buildingflashing.html" target="_blank">this</a>&nbsp;post for more information)<br />
<br />
For compiling the module, it's important that you use the same kernel source that is installed in your device. Otherwise, you cannot install the module.<br />
<br />
a. Go to the code that contains an example of kernel module for Android (for instance, <span style="font-family: Courier New, Courier, monospace;">[your_code]/module/intercept</span>);<br />
b. Update the makefile to point to your kernel source code;<br />
c. You need to set some env variables, including the cross-compiler. In this case, you can use the ones provided by the Android source, in the folder <span style="font-family: Courier New, Courier, monospace;">prebuilts</span>:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp; </span><span style="font-family: Courier New, Courier, monospace;">&nbsp;@desktop:$ export CROSS_COMPILE=[android_sdk]<android_source_code>/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin/arm-eabi-</android_source_code></span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp;@desktop:$ export ARCH=arm</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp;@desktop:$ export PATH=$PATH:<android_source_code>/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin/</android_source_code></span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp;@desktop:$ make</span><br />
&nbsp; &nbsp;(a kernel module file will be generated (<span style="font-family: Courier New, Courier, monospace;">[your_module].ko</span>) and this is the one that we need to install in our rooted device)<br />
<br />
d. Copy the <span style="font-family: Courier New, Courier, monospace;">.ko</span> file to the device using the following command:<br />
<br />
&nbsp; &nbsp;<span style="font-family: Courier New, Courier, monospace;">@desktop:$ adb push [your_module].ko /data/local/tmp</span><br />
<br />
e. Install the kernel module using the following commands:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp; </span><span style="font-family: Courier New, Courier, monospace;">&nbsp;@desktop:$ adb shell</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp;@android:$ su</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp;@android:$ cd /data/local/tmp</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp;@android:$ insmod [your_module].ko</span><br />
<br />
f. You might get some errors, such as "function not implemented". To check more details about what's wrong, you can check the log file by typing the following command.<br />
<br />
&nbsp; <span style="font-family: Courier New, Courier, monospace;">&nbsp;@android:$ dmesg</span><br />
<br /><span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e4f74a64461130f74a11e4bf24153f1fa04fbf4fbf&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e4f74a64461130f74a11e4bf24153f1fa04fbf4fbf/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e4f74a64461130f74a11e4bf24153f1fa04fbf4fbf&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e4f74a64461130f74a11e4bf24153f1fa04fbf4fbf/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Sun, 10 May 2015 18:40:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e4f74a64461130f74a11e4bf24153f1fa04fbf4fbf</guid>
        </item>
        <item>
            <title>Some other tips on building your AOSP for development</title>
            <link>http://raulherbster.blogspot.com/2015/05/some-other-tips-on-building-your-aosp.html</link>
            <description><![CDATA[
As you need to implement your solution into Android system, you end up learning a lot about the different Android layers (kernel, OS and applications) and how to integrate them. I decided to add the following list with some tips, as these small things took me some precious time to get it solved. The list will be often edited:<br />
<br />
#01 - Make sure that you're flashing the device with the proper kernel image<br />
<br />
This is what happened to me: I had previously built the kernel (something like two months before). Then, I had to build the OS image from scratch, that is, cleaning up the previous build (with <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">make clobber</span>). When I used the command <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">make bootimage</span>, including setting the variables properly, the output always had the wrong kernel image (not the one that I had previously built, but the existing one in the directory <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">prebuilts</span>). The build process won't take too old kernel images. Therefore, make sure that the compressed kernel image is always new. Even if you don't make any change on the kernel source, do <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">make</span> again to generate a new file.<br />
<br /><span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e4f5cfdaccb18cf5cf11e4bc300f31a144cd64cd64&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e4f5cfdaccb18cf5cf11e4bc300f31a144cd64cd64/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e4f5cfdaccb18cf5cf11e4bc300f31a144cd64cd64&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e4f5cfdaccb18cf5cf11e4bc300f31a144cd64cd64/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Fri, 08 May 2015 21:57:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e4f5cfdaccb18cf5cf11e4bc300f31a144cd64cd64</guid>
        </item>
        <item>
            <title>Problem on linking OpenSSL into your NDK application</title>
            <link>http://raulherbster.blogspot.com/2014/08/problem-on-linking-openssl-into-your.html</link>
            <description><![CDATA[
This week, I tried to compile a simple NDK application and link it with the OpenSSL library. Most of libraries (including OpenSSL) are not supported by the NDK, what makes it a bit more complicated to use. So, in this post, I describe what I usually do to properly compile applications that need external libs.<br />
<br />
The project structure is as follows:<br />
<br />
my_project/<br />
&nbsp; &nbsp; + jni/my_code.c<br />
&nbsp; &nbsp; + jni/Android.mk<br />
&nbsp; &nbsp; + jni/Application.mk<br />
&nbsp; &nbsp; + libs/system<br />
<br />
<b>Problem #01: How my Android.mk looks like?</b><br />
<br />
In this example, I need two libraries: libcrypto.so and libssl.so. So, the final Android.mk looks like this<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">LOCAL_PATH := $(call my-dir)</span><br />
<span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;">include $(CLEAR_VARS)</span></span><br />
<span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span><span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;">LOCAL_MODU</span></span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">LE := my_exec</span><br />
<span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;">LOCAL_MO</span></span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">DULE_TAGS := optional</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">LOCAL_SRC_FILES := my_code.c</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">LOCAL_C_INCLUDES += $(ANDROID_SRC)/external/openssl/include \&nbsp;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(ANDROID_SRC)/external/openssl/crypto \</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(KERNEL_SRC)/kernel/module</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">LOCAL_LDLIBS += -L$(LOCAL_PATH)/../libs/system</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">LOCAL_SHARED_LIBRARIES := libandroid libdl libz libcrypto libssl</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">LOCAL_LDLIBS += -landroid -ldl -lz</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">include $(BUILD_EXECUTABLE)</span><span style="font-size: x-small;">&nbsp;</span>
<br />
<div>
<br />
See, as an example, that we also include the headers for the library (in <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">ANDROID_SRC/external/openssl/include</span>).<br />
<br />
NDK does not provide support for libcrypto.so and libssl.so -- we need to have access to the libraries somehow. So, you should create a folder (for example, my_project/libs/system) and push the files /system/lib/libcrypto.so and /system/lib/libssl.so from the device to such folder.<br />
<br /></div>
<b>Problem #02: Where do I get the libs from?</b><br />
<br />
You shall get all of them (including libc.so) from your rooted device. The point is that, as I said, NDK does not provide support for libcrypto.so and libssl.so. Therefore, you need to get such libraries from the device. However, there's another problem: most likely, the libcrypto.so and libssl.so libraries don't recognize the symbols from the NDK libc.so and libstdc++.so libraries. Regarding this problem, it will be discussed on item #04.<br />
<br />
<b>Problem #03: Where do I get the headers from?</b><br />
<br />
Usually, you get them from the android source code. For OpenSSL, they are located inside the folder <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">ANDROID_SRC/external</span>.<br />
<br />
<b>Problem #04: Why does my lib complain about libc symbols?</b><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: inherit;">As I described in topic #02, you need to copy the libraries from the device. However, libcrypto.so and libssl.so do not recognize some symbols from the libc.so and libstdc++.so libraries (most likely, the libraries provided by NDK are not compatible with the ones in the device). Usually, you will have the following compilation error:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/home/raul/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/raul/my_project/jni/../libs/system/libcrypto.so: error: undefined reference to '__strlen_chk'</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/home/raul/android_development/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/raul/my_project/jni/../libs/system/libcrypto.so: error: undefined reference to '__memcpy_chk'</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/home/raul/android_development/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/raul/my_project/jni/../libs/system/libcrypto.so: error: undefined reference to '__memset_chk'</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/home/raul/android_development/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:&nbsp;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/home/raul/my_project/jni/../libs/system/libcrypto.so: error: undefined reference to '__strchr_chk'</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/home/raul/android_development/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/raul/my_project/jni/../libs/system/libcrypto.so: error: undefined reference to '__strcat_chk'</span><br />
<div>
<br />
That's easy to solve. Here comes the trick: you have to replace NDK's libraries by those ones from the device. NDK contains several libraries for distinct platforms, as we can see from the path NDK_FOLDER/platforms:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@desktop:$ ls NDK_FOLDER/platforms</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">android-12 &nbsp;android-13 &nbsp;android-14 &nbsp;android-15 &nbsp;android-16 &nbsp;android-17 &nbsp;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">android-18 &nbsp;android-19 &nbsp;android-3 &nbsp; android-4 &nbsp; android-5 &nbsp; android-8 &nbsp;android-9</span><br />
<br />
&nbsp;Considering that your application is using NDK for platform android-17 (you can define that in file Application.mk), replace the main libraries of folder NDK_PATH/platforms/android-17<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">@desktop:$ ls NDK_FOLDER/platforms/android-17</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/arch-arm/usr/lib</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">crtbegin_dynamic.o &nbsp;crtend_android.o &nbsp;libc.a &nbsp; &nbsp;libEGL.so &nbsp; &nbsp; &nbsp; libjnigraphics.so libm_hard.a &nbsp; &nbsp; &nbsp; &nbsp; libOpenSLES.so &nbsp; &nbsp;libthread_db.so</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">crtbegin_so.o &nbsp; &nbsp; &nbsp; crtend_so.o &nbsp; &nbsp; &nbsp; libc.so &nbsp; libGLESv1_CM.so &nbsp;liblog.so &nbsp; &nbsp; &nbsp; libm.so &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; libstdc++.a &nbsp; &nbsp; &nbsp; libz.so</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">crtbegin_static.o &nbsp; libandroid.so &nbsp; &nbsp; libdl.so &nbsp;libGLESv2.so &nbsp; &nbsp; libm.a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; libOpenMAXAL.so &nbsp; &nbsp; libstdc++.so</span><br />
<div>
<br /></div>
<span style="font-family: inherit;">So, push the libraries /system/lib/libc.so, and&nbsp;/system/lib/libstdc++.so from the device to the folder&nbsp;NDK_FOLDER/platforms/android-17/arch-arm/usr/lib. After that, compile the application again and voilà -- all problems solved :-)&nbsp;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span></div>
<span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e41a67f0a721521a6711e49e5045fc43d3d118d118&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e41a67f0a721521a6711e49e5045fc43d3d118d118/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e41a67f0a721521a6711e49e5045fc43d3d118d118&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e41a67f0a721521a6711e49e5045fc43d3d118d118/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Sat, 02 Aug 2014 16:32:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e41a67f0a721521a6711e49e5045fc43d3d118d118</guid>
        </item>
        <item>
            <title>Android image/kernel building/flashing - A *VERY* short guide :-)</title>
            <link>http://raulherbster.blogspot.com/2014/07/android-imagekernel-buildingflashing.html</link>
            <description><![CDATA[
This week, I had to go through the process of Android OS/Kernel building/installation. And it was a lot much better and 6 months ago (maybe, because I built it for a device and not for the emulator?). I compiled the images in Ubuntu 12.04 and I used a <u>Samsung Galaxy Nexus</u> device (maguro with tuna as kernel). Therefore, I decided to summarize the steps that I took. This mini-tutorial is a lot shorter and simpler (and really works!!).<br />
<br />
Update (13/07.2015): info for arm64 =&gt; http://seandroid.bitbucket.org/BuildingKernels.html<br />
<br />
<span style="font-size: large;">1. Android OS</span><br />
<br />
<b>1.0 Setting up the building environment</b><br />
<br />
Check this instructions (<a href="https://source.android.com/source/initializing.html" target="_blank">here</a> and <a href="https://source.android.com/source/initializing.html" target="_blank">here</a>) to set up the basic environment and download the code. I used the branch <span style="font-family: Courier New, Courier, monospace;">[android-4.3_r1.1]</span>.<br />
<br />
<b>1.1 Compiling the Android OS</b><br />
<br />
a. Download and unpack the manufacturer drivers from <a href="https://developers.google.com/android/nexus/drivers#magurojwr66y" target="_blank">this</a> link. They have to be unpacked into the directory <span style="font-family: Courier New, Courier, monospace;">[android_source_code]/vendors</span> -- but don't worry, as the .zip files contain a script that does all the work for you.<br />
<br />
b. Once the drivers are in the proper place, run the following commands:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ cd [android_source_code]</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ make clobber</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ lunch full_maguro-userdebug</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ make -j4</span><br />
<br />
It takes a long time to compile the image.<br />
<br />
After these steps, the Android OS is ready.<br />
<br />
<b>1.2 Flashing the device with the new Android OS</b><br />
<br />
Now, you need two tools from the Android SDK: <u>adb</u> and <u>fastboot</u>. These tools are located in the folder <span style="font-family: Courier New, Courier, monospace;">[androis_sdk]/platform-tools</span>.<br />
<br />
a. Reboot the device in the bootloader mode -- hold VolumeDown and VolumeUp and then press the PowerUp button.<br />
<br />
b. Connect the USB cable.<br />
<br />
c. Run the following commands:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ export PATH=$PATH:[android_sdk]/platform-tools</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ cd [android_source_code]</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ sudo fastboot format cache</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ sudo fastboot format userdata</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ sudo ANDROID_PRODUCT_OUT=[android_source_code]/out/target/product/maguro/ fastboot -w flashall</span><br />
<br />
After these steps, reboot the device. A clean installation will take place. To check the new version of you device, go to "Settings" - - &gt; "About Phone" and check "Model number": now, it should be "AOSP on Maguro" (check attached image)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuhhBI-FaDQSMFunk7Or9y1c2e3iOACM7c_SBq_s5YUrLtgup0AwR46_1-ZwyKS7O0-jOAaNmNuOqgi-Aj3rzjumAA1Et3QAIbzfCLWZHu1qoghCjwhg8yuIfmoP_IK6GkhMoiaC3U07o/s1600/Screenshot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuhhBI-FaDQSMFunk7Or9y1c2e3iOACM7c_SBq_s5YUrLtgup0AwR46_1-ZwyKS7O0-jOAaNmNuOqgi-Aj3rzjumAA1Et3QAIbzfCLWZHu1qoghCjwhg8yuIfmoP_IK6GkhMoiaC3U07o/s1600/Screenshot.png" width="180" /></a></div>
<br />
<br />
<span style="font-size: large;">2. Android Kernel</span><br />
<br />
Ok. Now, we have the AOSP in place and we need to compile a new kernel. But why do you need to compile and install a new kernel? Oh, well, let's say that you want to apply some patches or that you need to change the kernel to enable Linux module support (the default Android Linux Kernel does not support modules).<br />
<br />
<b>2.0 Setting up the building environment</b><br />
<br />
If you have built the Android OS before, you don't need anything special for the kernel building. I used the official code from<span style="font-family: Courier New, Courier, monospace;"> https://android.googlesource.com/kernel/omap.git</span>, branch <span style="font-family: Courier New, Courier, monospace;">android-omap-tuna-3.0-jb-mr2</span>.<br />
<br />
<b>2.1 Compiling the Kernel</b><br />
<br />
First, you need to set some variables that are important for the building process (ARCH and CROSS_COMPILE):<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ export ARCH=arm</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">&nbsp; @desktop:$ export CROSS_COMPILE=[android_source_code]/</span><span style="font-family: Courier New, Courier, monospace;">prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin/arm-eabi-</span><br />
<br />
Now, you have to generate a .config which contains all the options for the kernel building. By running the following command you generate a basic .config file for Android.<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">&nbsp; @desktop:$ cd [android_kernel_code]</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktio:$ make tuna_defconfig</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
Sometimes, you need to set some specific entries of the .config to enable/disable certain features of the kernel. For this specific example, let's set the option CONFIG_MODULES to y (the entry in the .config file should be CONFIG_MODULES=y). With CONFIG_MODULES set to y, it is possible to insert/remove kernel modules. Now, let's build the kernel<br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ cd [android_kernel_code]</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">&nbsp; @desktop:$ make</span><br />
<br />
(it takes some time to compile the kernel)<br />
<br />
<b>2.2 Preparing the kernel for installation</b><br />
<br />
The kernel image is almost ready: it's still necessary to wrap it up properly to flash it into the device. The Android source code contains scripts that do the work for us. Consider that the image was generated at <span style="font-family: Courier New, Courier, monospace;">[android_kernel_code]/arch/arm/boot/zImage</span>.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ cd [android_source_code]</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ export TARGET_PREBUILT_KERNEL= [android_kernel_code]/arch/arm/boot/zImage</span><br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ make bootimage</span><br />
<br />
At the end, a custom image is ready for installation at <span style="font-family: Courier New, Courier, monospace;">[android_source_code]/out/target/product/maguro/boot.img</span><br />
<br />
<b>2.3 Flashing the device with the new Kernel</b><br />
&nbsp; <br />
Now, everything is in place and we can finally flash our kernel image. To do so:<br />
<br />
a. You need to boot the device in bootloader mode (hold VolumeDown and VolumeUp and then press the PowerUp button)<br />
<br />
b. Connect the USB cable<br />
<div>
<br /></div>
<div>
c. Run the following commands</div>
<br />
<span style="font-family: Courier New, Courier, monospace;">&nbsp; @desktop:$ cd [android_source_code]</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">&nbsp; @desktop:$ sudo ANDROID_PRODUCT_OUT=[android_source_code]/out/target/product/maguro/ fastboot flash boot [android_source_code]/out/target/product/maguro/boot.img</span><br />
<br />
After these steps, reboot the device. A clean installation will take place. To check the new version of you kernel, go to "Settings" - - &gt; "About Phone" and check "Kernel version": you will see a different name for you kernel image (as for the previuos image).<br />
<br />
<br /><span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e4168b7d9f1c76168b11e4ba7d5d99f4b4dfdadfda&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e4168b7d9f1c76168b11e4ba7d5d99f4b4dfdadfda/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e4168b7d9f1c76168b11e4ba7d5d99f4b4dfdadfda&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e4168b7d9f1c76168b11e4ba7d5d99f4b4dfdadfda/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Mon, 28 Jul 2014 19:06:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e4168b7d9f1c76168b11e4ba7d5d99f4b4dfdadfda</guid>
        </item>
        <item>
            <title>Building/Running Android Goldfish kernel </title>
            <link>http://raulherbster.blogspot.com/2013/08/buildingrunning-android-goldfish-kernel.html</link>
            <description><![CDATA[
Among the tasks for build an Android kernel development, building the Android Goldfish kernel is the easiest :-) (I mean, no compiling errors...)<br />
<br />
First, you need to have access to the cross-compiling tools. The Android source code provides them in folder <android_src>/prebuilt/linux-x86/toolchain/.&nbsp;</android_src><br />
<br />
<b><span style="font-size: large;">Steps</span></b><br />
<br />
<br />
1. Set the path to include the pre-build toolchain<br />
&nbsp; &nbsp;<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># export PATH=<android_src>/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/:$PATH</android_src></span><br />
2. Set the Kernel config file. In this case, we are compiling for the ARM emulator (armv7).<br />
&nbsp; &nbsp;<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># make ARCH=arm goldfish_armv7_defconfig</span><br />
3. Run make<br />
&nbsp; <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;# CROSS_COMPILE=<android_src>/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- ARCH=arm make</android_src></span><br />
4. Change var ANDROID_PRODUCT_OUT<br />
&nbsp; &nbsp;<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># export ANDROID_PRODUCT_OUT=<android_src>/out/target/product/generic/</android_src></span><br />
5. Run the emulator<br />
&nbsp; <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;# <android_src>/out/host/linux-x86/bin/emulator-arm -system <android_src>/out/target/product/generic/system.img -kernel <android_kernel>/goldfish/arch/arm/boot/zImage -data <android_src>/out/target/product/generic/userdata.img -ramdisk <android_src>/out/target/product/generic/ramdisk.img -skindir <android_src>/sdk/emulator/skins/ -skin HVGA -verbose -show-kernel</android_src></android_src></android_src></android_kernel></android_src></android_src></span><br />
<br />
<b><span style="font-size: large;">Issues</span></b><br />
<br />
<br />
<ul>
<li>The option CONFIG_MODULES is NOT enabled by default. If you want to insert modules into the kernel, make sure to set CONFIG_MODULES;</li>
<li>Android emulator does NOT work with Kernels &gt; 2.6.X So, make sure to use the proper Kernel. For devices, any support Kernel will work.</li>
</ul>
<br />
<div>
<br /></div>
<span class="net_nemein_favourites">1 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e30e63cd89fc820e6311e382ee59f0a43fddfaddfa&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e30e63cd89fc820e6311e382ee59f0a43fddfaddfa/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e30e63cd89fc820e6311e382ee59f0a43fddfaddfa&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e30e63cd89fc820e6311e382ee59f0a43fddfaddfa/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Mon, 26 Aug 2013 14:21:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e30e63cd89fc820e6311e382ee59f0a43fddfaddfa</guid>
        </item>
        <item>
            <title>Android (Goldfish) kernel development</title>
            <link>http://raulherbster.blogspot.com/2013/08/android-goldfish-kernel-development.html</link>
            <description><![CDATA[
Finally, back to this :-)<br />
<br />
Lately, I have being developing a new project which basically needs some kernel changes on Android Goldfish kernel. Initially, I thought that this would be something like "traditional" kernel development, but NOT. Android kernel is, of course, a Linux kernel but it has some peculiarities that impact on the development phase.<br />
<br />
[NOTE] I'd rather provide a link to the source that I used than replicating the same information.<br />
<br />
So, I&nbsp;split my experience into the following topics:<br />
<ol>
<li><a href="http://raulherbster.blogspot.fi/2013/08/building-android-ics.html" target="_blank">Building Android ICS</a></li>
<li><a href="http://raulherbster.blogspot.fi/2013/08/buildingrunning-android-goldfish-kernel.html" target="_blank">Building/Running Android Goldfish kernel&nbsp;</a></li>
<li>Creating a Goldfish kernel module</li>
<li>Adding new syscalls into the Goldfish kernel</li>
</ol>
<span class="net_nemein_favourites">1 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e30e63c85cac780e6311e382ee59f0a43fddfaddfa&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e30e63c85cac780e6311e382ee59f0a43fddfaddfa/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e30e63c85cac780e6311e382ee59f0a43fddfaddfa&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e30e63c85cac780e6311e382ee59f0a43fddfaddfa/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Mon, 26 Aug 2013 14:02:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e30e63c85cac780e6311e382ee59f0a43fddfaddfa</guid>
        </item>
        <item>
            <title>Building Android ICS</title>
            <link>http://raulherbster.blogspot.com/2013/08/building-android-ics.html</link>
            <description><![CDATA[
<br />
To compile ICS (and probably any new version of Android platform &gt;= 4.0), you<br />
might have some problems with the compilation tools.<br />
<br />
<ul>
<li>Follow the instructions described on http://source.android.com/source/building.html</li>
<ul>
<li>It also provides information about Android Kernel building.</li>
</ul>
<li>Check which compiler best fits into the version of Android platform you are using.</li>
<ul>
<li>Usually, due to new features (for example, C++11 support on GCC/++ 4.7), it is a bit more complicated to build it with new compilers... you will see several compiling errors. For example, for the ICS, GCC/++ 4.6 works better than GCC/++ 4.7.</li>
</ul>
<li>You may need some changes in order to compile it properly (mostly on Makefile). Again, depending on your compiler, you may apply more or less changes on your code.</li>
<li>For ICS, GCC/++ 4.6 works better.</li>
</ul>
<div>
<a href="https://groups.google.com/forum/#!topic/android-building/2EwtWQTqjdI" target="_blank">This link</a> provides a good discussion about it (and solutions!). In my case, for compiling ICS, I made only a few changes (see below) and I also used GCC/++ 4.6.</div>
<div>
<br /></div>
<div>
=================================================================</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">project build/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/core/combo/HOST_linux-x86.mk b/core/combo/HOST_linux-x86.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index 5ae4972..7df2893 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/core/combo/HOST_linux-x86.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/core/combo/HOST_linux-x86.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -53,6 +53,6 @@ HOST_GLOBAL_CFLAGS += \</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;<span class="Apple-tab-span" style="white-space: pre;"> </span>-include $(call select-android-config-h,linux-x86)</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;# Disable new longjmp in glibc 2.11 and later. See bug 2967937.</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;HOST_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">project dalvik/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/vm/native/dalvik_system_Zygote.cpp b/vm/native/dalvik_system_Zygote.cpp</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index 31fecfd..b3b745a 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/vm/native/dalvik_system_Zygote.cpp</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/vm/native/dalvik_system_Zygote.cpp</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -19,6 +19,7 @@</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp; */</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#include "Dalvik.h"</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#include "native/InternalNativePriv.h"</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+#include "sys/resource.h"</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#include <signal .h=""></signal></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#include <sys types.h=""></sys></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">project development/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/tools/emulator/opengl/host/renderer/Android.mk b/tools/emulator/opengl/host/renderer/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index 55fcb80..613179c 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/tools/emulator/opengl/host/renderer/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/tools/emulator/opengl/host/renderer/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -6,6 +6,8 @@ $(call emugl-import,libOpenglRender)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_SRC_FILES := main.cpp</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_CFLAGS &nbsp; &nbsp;+= -O0 -g</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+LOCAL_LDLIBS += -lX11</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#ifeq ($(HOST_OS),windows)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#LOCAL_LDLIBS += -lws2_32</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#endif</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">project external/gtest/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/include/gtest/internal/gtest-param-util.h b/include/gtest/internal/gtest-param-util.h</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index 5559ab4..0af13b0 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/include/gtest/internal/gtest-param-util.h</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/include/gtest/internal/gtest-param-util.h</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -39,6 +39,7 @@</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#include <vector></vector></span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#include <gtest gtest-port.h="" internal=""></gtest></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+#include <stddef .h=""></stddef></span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;#if GTEST_HAS_PARAM_TEST</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/src/Android.mk b/src/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index 2465e16..1d93ac8 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/src/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/src/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -49,7 +49,7 @@ LOCAL_SRC_FILES := gtest-all.cc</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_C_INCLUDES := $(libgtest_host_includes)</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-LOCAL_CFLAGS += -O0</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+LOCAL_CFLAGS += -O0 -fpermissive</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_MODULE := libgtest_host</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_MODULE_TAGS := eng</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -67,7 +67,7 @@ LOCAL_SRC_FILES := gtest_main.cc</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_C_INCLUDES := $(libgtest_host_includes)</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-LOCAL_CFLAGS += -O0</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+LOCAL_CFLAGS += -O0 -fpermissive</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_STATIC_LIBRARIES := libgtest</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">project external/llvm/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/llvm-host-build.mk b/llvm-host-build.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index 5219efd..cc91ee0 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/llvm-host-build.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/llvm-host-build.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -44,6 +44,8 @@ LOCAL_C_INCLUDES :=<span class="Apple-tab-span" style="white-space: pre;"> </span>\</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_IS_HOST_MODULE := true</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+LOCAL_LDLIBS := -lpthread -ldl</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;###########################################################</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;## Commands for running tblgen to compile a td file</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;###########################################################</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">project external/oprofile/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/libpp/format_output.h b/libpp/format_output.h</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index b6c4592..8e527d5 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/libpp/format_output.h</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/libpp/format_output.h</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -91,7 +91,7 @@ protected:</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;<span class="Apple-tab-span" style="white-space: pre;">  </span>symbol_entry const &amp; symbol;</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;<span class="Apple-tab-span" style="white-space: pre;">  </span>sample_entry const &amp; sample;</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;<span class="Apple-tab-span" style="white-space: pre;">  </span>size_t pclass;</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-<span class="Apple-tab-span" style="white-space: pre;">  </span>mutable counts_t &amp; counts;</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+<span class="Apple-tab-span" style="white-space: pre;">  </span>counts_t &amp; counts;</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;<span class="Apple-tab-span" style="white-space: pre;">  </span>extra_images const &amp; extra;</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;<span class="Apple-tab-span" style="white-space: pre;">  </span>double diff;</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;<span class="Apple-tab-span" style="white-space: pre;"> </span>};</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">project frameworks/base/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/libs/utils/Android.mk b/libs/utils/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index 638f72f..127cad9 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/libs/utils/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/libs/utils/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -61,7 +61,7 @@ LOCAL_SRC_FILES:= $(commonSources)</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_MODULE:= libutils</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_C_INCLUDES += external/zlib</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;ifeq ($(HOST_OS),windows)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index a3e5d9a..4c415d6 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/tools/aapt/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/tools/aapt/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -28,7 +28,7 @@ LOCAL_SRC_FILES := \</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp; &nbsp; &nbsp;ZipFile.cpp</span></div>
<div>
</div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-LOCAL_CFLAGS += -Wno-format-y2k</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+LOCAL_CFLAGS += -Wno-format-y2k -fpermissive</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_C_INCLUDES += external/expat/lib</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_C_INCLUDES += external/libpng</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">project frameworks/compile/slang/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/Android.mk b/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">index fce3637..8ffe68f 100644</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--- a/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ b/Android.mk</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@@ -19,7 +19,7 @@ ifeq ($(TARGET_BUILD_APPS),)</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;LOCAL_PATH := $(call my-dir)</span></div>
<div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">-local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter -Werror</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;ifneq ($(TARGET_BUILD_VARIANT),eng)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;local_cflags_for_slang += -D__DISABLE_ASSERTS</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp;endif</span></div>
</div>
<br /><span class="net_nemein_favourites">1 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e30e63caf9ed380e6311e382ee59f0a43fddfaddfa&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e30e63caf9ed380e6311e382ee59f0a43fddfaddfa/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e30e63caf9ed380e6311e382ee59f0a43fddfaddfa&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e30e63caf9ed380e6311e382ee59f0a43fddfaddfa/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Mon, 26 Aug 2013 14:02:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e30e63caf9ed380e6311e382ee59f0a43fddfaddfa</guid>
        </item>
        <item>
            <title>Moving...</title>
            <link>http://raulherbster.blogspot.com/2013/01/moving.html</link>
            <description><![CDATA[
My life has changed upside down recently: I have been accepted to Saarland University Graduate School and I will move to Germany soon. I will try to keep this updated as possible.<span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=1e28ced39984daa8ced11e289fddf839aaa37e737e7&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/1e28ced39984daa8ced11e289fddf839aaa37e737e7/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=1e28ced39984daa8ced11e289fddf839aaa37e737e7&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/1e28ced39984daa8ced11e289fddf839aaa37e737e7/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Fri, 25 Jan 2013 00:25:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-1e28ced39984daa8ced11e289fddf839aaa37e737e7</guid>
        </item>
        <item>
            <title>LLVM - ARM cross-compilation using Raspberry!!</title>
            <link>http://raulherbster.blogspot.com/2012/11/llvm-arm-cross-compilation-using.html</link>
            <description><![CDATA[
Well, a short break on continuous integration posts!<br />
<br />
I bought my Raspberry Pi (http://www.raspberrypi.org/<span style="background-color: white; color: #009933; font-family: arial, sans-serif; font-size: x-small; line-height: 15px;">)</span>&nbsp;board some weeks ago mainly to use it as a developer board (pretty&nbsp;affordable&nbsp;and efficient). So, I decided to use it to cross-compile LLVM (http://www.llvm.org).<br />
<br />
So, here you go.<br />
<br />
<span style="font-size: large;">Building</span><br />
<br />
First of all, download LLVM (from either SVN or GIT repositories). I got the following information from &nbsp;LLVM documentation. For more details,&nbsp;<a href="http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary" target="_blank">check this out</a>!<br />
<br />
<ul>
<li>Checkout LLVM:
<br /><span style="font-family: Courier New, Courier, monospace;">$ cd where-you-want-llvm-to-live
<br />$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
</span><br />
</li>
<li>Checkout Clang:
<br /><span style="font-family: Courier New, Courier, monospace;">$ cd where-you-want-llvm-to-live
<br />$ cd llvm/tools
<br />$ svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
</span></li>
<li>Checkout Compiler-RT:
<br /><span style="font-family: Courier New, Courier, monospace;">$ cd where-you-want-llvm-to-live
<br />$ cd llvm/projects
<br />$ svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
</span></li>
<li>Get the Test Suite Source Code [Optional]
<br /><span style="font-family: Courier New, Courier, monospace;">$ cd where-you-want-llvm-to-live
<br />$ cd llvm/projects
<br />$ svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite</span></li>
</ul>
<br />
To cross-compile it to ARM platform, you need a toolchain. I use Sourcery G++ Lite 2011.03-41 (<a href="http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/" target="_blank">MentorGraphics Sourcery CodeBench Lite Edition</a>) - it is free and contains everything we need. Install it and also remember to set the PATH variable so that you can use your toolchain.<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">$ export $PATH=$PATH:/home/user/CodeSourcery/Sourcery_G++_Lite/bin</span></blockquote>
Now, it´s time to build the application (and remember: for further details,&nbsp;<a href="http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary" target="_blank">check this out</a>!)<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">$ cd where-you-want-to-build-llvm<br />$ mkdir build </span><span style="font-family: inherit;">(for building without polluting the source dir)</span><br />
<span style="font-family: Courier New, Courier, monospace;">$ cd build</span><br />
<span style="font-family: Courier New, Courier, monospace;">$ ../configure&nbsp;</span><span style="font-family: Courier New, Courier, monospace;">--target=arm-none-linux-gnueabi --host=arm-none-linux-gnueabi --enable-optimized </span><span style="font-family: inherit;">(</span><span style="font-family: inherit;">the target/host value may change depending on the toolchain that you have&nbsp;chosen.)</span><br />
<span style="font-family: Courier New, Courier, monospace;">$ make</span></blockquote>
<br />
Now, you just need to wait for a couple of minutes :-) Next step is NFS-mounting the LLVM dir in your Raspberry Pi.<br />
<br />
<span style="font-size: large;">NFS-Mounting</span><br />
<br />
Now, LLVM is cross-compiled and we are able to use it and perform some tests on Raspberry Pi. I prefer NFS as partition mounting solution. An important information is that you have to have the same path on both environments (desktop and remote). It means that if you are building LLVM on <span style="font-family: Courier New, Courier, monospace;">/home/user/llvm</span> desktop folder, you have to mount it on<span style="font-family: Courier New, Courier, monospace;"> /home/user/llvm</span> remote folder (in most of cases, you have to create the user <span style="font-family: Courier New, Courier, monospace;"><user></user></span> on your Raspberry environment - just use the <span style="font-family: Courier New, Courier, monospace;"><useradd></useradd></span> command). &nbsp;Firstly, set up your desktop machine:<br />
<ul>
<li>Install NFS packages<br /><span style="font-family: Courier New, Courier, monospace;">@desktop$&nbsp;sudo apt-get install portmap&nbsp;nfs-kernel-server nfs-common</span></li>
<li>Edit /etc/exports and add the following line<br /><span style="font-family: Courier New, Courier, monospace;">
/home/user/llvm 192.168.1.0/24(rw,sync,no_subtree_check)
</span></li>
<li>Restart NFS system<br /><span style="font-family: Courier New, Courier, monospace;">@desktop$&nbsp;sudo service nfs-kernel-server restart</span></li>
<li>Change access permission of your shared folder (in this case, I use the same folder)<br /><span style="font-family: Courier New, Courier, monospace;">@desktop$ chmod -R 777 /home/user/llvm
</span></li>
</ul>
<br />
Configuration on Raspberry Pi is also straightforward:<br />
<br />
<ul>
<li>Install NFS packages (most of Raspberry distributions contain NFS installed, so maybe this step is not necessary)<br /><span style="font-family: Courier New, Courier, monospace;">@remote$ sudo apt-get install&nbsp;</span><span style="font-family: 'Courier New', Courier, monospace;">portmap&nbsp;</span><span style="font-family: 'Courier New', Courier, monospace;">nfs-kernel-server nfs-common</span></li>
<li>Create the host folder<br /><span style="font-family: Courier New, Courier, monospace;">@remote$ mkdir llvm <br /> @remote$ chmod 777 llvm
</span></li>
<li>Mount the NFS-shared folder<br /><span style="font-family: Courier New, Courier, monospace;">@remote$ sudo mount 192.168.1.4:/home/user/llvm /home/user/llvm</span></li>
</ul>
<div>
Now it is done and you can use your cross-compiled LLVM on your Raspberry.</div>
<br />
<span style="font-size: large;">Testing</span><br />
<br />
<div>
Let´s now focus on LLVM tests and how we can run them on ARM platforms. In this case, I am running tests under <span style="font-family: Courier New, Courier, monospace;">/home/user/llvm/tests</span> folder.<br />
<br />
<ul>
<li>CD to <span style="font-family: Courier New, Courier, monospace;">test</span> dir<br /><span style="font-family: Courier New, Courier, monospace;">@remote$ cd llvm/build/test</span></li>
<li>Run tests<br /><span style="font-family: Courier New, Courier, monospace;">@remote:/home/user/llvm/build/test$ make</span><span style="font-family: 'Courier New', Courier, monospace;">&nbsp;</span></li>
</ul>
<br />
After some minutes, LLVM test suite runs all integration tests and provides a report with results.<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">@remote:/home/user/llvm/build/test$ make<br />...<br />PASS: LLVM :: ExecutionEngine/MCJIT/test-shift.ll (59 of 59)<br />Testing Time: 11.65s<br />********************<br />Unexpected Passing Tests (1):<br />&nbsp; &nbsp; LLVM :: ExecutionEngine/MCJIT/test-data-align-remote.ll<br />********************<br />Failing Tests (7):<br />&nbsp; &nbsp; LLVM :: ExecutionEngine/MCJIT/2003-01-04-ArgumentBug.ll<br />&nbsp; &nbsp; LLVM :: ExecutionEngine/MCJIT/2005-12-02-TailCallBug.ll<br />&nbsp; &nbsp; LLVM :: ExecutionEngine/MCJIT/fpbitcast.ll<br />&nbsp; &nbsp; LLVM :: ExecutionEngine/MCJIT/pr13727.ll<br />&nbsp; &nbsp; LLVM :: ExecutionEngine/MCJIT/test-call.ll<br />&nbsp; &nbsp; LLVM :: ExecutionEngine/MCJIT/test-common-symbols.ll<br />&nbsp; &nbsp; LLVM :: ExecutionEngine/MCJIT/test-ret.ll<br />&nbsp; Expected Passes &nbsp; &nbsp;: 45<br />&nbsp; Expected Failures &nbsp;: 6<br />&nbsp; Unexpected Passes &nbsp;: 1<br />&nbsp; Unexpected Failures: 7</span></blockquote>
<b>UPDATE</b>: Raspberry Pi <is not=""> the ARM target platform for LLVM project at this moment. If you want to contribute to LLVM project by supporting ARM features, check a <a href="http://www.pandaboard.org/" target="_blank">PandaBoard development kit.</a></is><br />
<div>
<br /></div>
</div>
<span class="net_nemein_favourites">2 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=c3bb013e3a4b11e298b6b36d8d11a1c4a1c4&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/c3bb013e3a4b11e298b6b36d8d11a1c4a1c4/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>1 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=c3bb013e3a4b11e298b6b36d8d11a1c4a1c4&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/c3bb013e3a4b11e298b6b36d8d11a1c4a1c4/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Thu, 29 Nov 2012 17:33:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-c3bb013e3a4b11e298b6b36d8d11a1c4a1c4</guid>
        </item>
        <item>
            <title>Setting up your Continuous Integration environment - Part I</title>
            <link>http://raulherbster.blogspot.com/2012/11/setting-up-your-continuous-integration.html</link>
            <description><![CDATA[
Continuous Integration is such a great idea: it works as a trainee that constantly downloads/builds/tests/deploys you application and notifies you whether something goes wrong or nice. I really do believe that (of course, besides several other advantages) it improves the project overall quality and also helps you to keep the application ready to be reviewed by a stakeholder.<br />
<br />
If you are still skeptical about it, please take a look that this marvelous post <a href="http://martinfowler.com/articles/continuousIntegration.html" target="_blank">here [Martin Fowler]</a>&nbsp;.<br />
<br />
Let´s discuss how you can set up a environment for a more complex project. So, unfortunately, this is tutorial for beginners (for basic/how-to-install-and-run instructions, check it on internet).<br />
<br />
<span style="font-size: large;">Introduction</span><br />
<br />
The system consists of one server located in a external environment (for example, AWS services) and several mobile clients (iOS, Android and QT clients). Basically, the mobile applications fetch content/data from the server.<br />
<br />
We need to constantly build/deploy the server and build all mobile clients. 

One very interesting point in this scenario is the amount of platforms: iOS (to build iOS client), Linux (to build Android/QT client - I´d rather use Linux for Android projects) and Windows (to build the server).<br />
<br />
Besides svn checking-out + building + testing + deployment, we will also use QA solutions, such as Sonar and some static analysis tools for different platforms.<br />
<br />
We will use Jenkins as CI server.<br />
<br />
<span style="font-size: large;">Proposed design</span><br />
<span style="font-size: large;"><br /></span>
<br />
As I said, the system consists of several components: mobile clients (iOS, Qt and Android) and also servers. In this case, I´d rather use master-slave approach. You can create one slave for each mobile platform and also another one for for servers. To the given example, the solution is defined as it follows:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7LFCVm4UXiUXES1rsDaHqKde65cfq2z3sKpe5LMN9hSc4pxl8c0pyrRLyt4janxbG2-qQhTAnMsZUxjabKBbjOkGOG2vPo2BvttKrtLPeY3nLT9s2lcTSANzo_IcqaGXcskAGfm2zjN4/s1600/jenkins.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7LFCVm4UXiUXES1rsDaHqKde65cfq2z3sKpe5LMN9hSc4pxl8c0pyrRLyt4janxbG2-qQhTAnMsZUxjabKBbjOkGOG2vPo2BvttKrtLPeY3nLT9s2lcTSANzo_IcqaGXcskAGfm2zjN4/s1600/jenkins.png" height="289" width="640" /></a></div>
<br />
You might ask me why this is too complicated! But believe on me. If you have complex systems to build, this approach works a lot better: it´s easier to organize and to maintain, and each component on its own environment. In my next post, I describe how we set up all of this :-)<br />
<!--[endif]--><span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=5a96870039e711e2904d27bbad6666ee66ee&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/5a96870039e711e2904d27bbad6666ee66ee/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>2 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=5a96870039e711e2904d27bbad6666ee66ee&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/5a96870039e711e2904d27bbad6666ee66ee/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Thu, 29 Nov 2012 05:37:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-5a96870039e711e2904d27bbad6666ee66ee</guid>
        </item>
        <item>
            <title>Back!!!</title>
            <link>http://raulherbster.blogspot.com/2012/10/back.html</link>
            <description><![CDATA[
After a loooong break, I am back to this. I have to confess that I had had several new/cool stuff during this pause: new projects, mind-blowing findings, exciting/stressful experiences, lovely/irritating people. And all of this had consumed a lot of my free time. I am not saying that I hadn´t had time at all: I had done some new/different things with such slots of time than only writing about technical stuff.
</BR></BR>
Well, but anyway, let´s keep track of new stuff. The main reason to start blogging again was the simply fact that I am not used to describe all solutions for tricky problems in general: how to cross-compile certain applications for ARM devices, how to set up a smart CI environment, and so forth. I swear I have tried it really hard, but my evil side always tells to myself: "if you need it some other day, you will remember it". So, this is also a kind of "Raul´s Recipes Book".
</BR></BR>
I am really convinced that it will work :-) 
</BR></BR>
As part of my next posts, I will describe a bit more about how lovely is a CI environment for a relative huge project (of course, how you can set up all of this and put the pieces together). Specially, when it has such different clients, such as iOS, Android and QT applications.<span class="net_nemein_favourites">3 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=9edfd0d01fc811e2ae4b97ddcd952a782a78&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/9edfd0d01fc811e2ae4b97ddcd952a782a78/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>1 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=9edfd0d01fc811e2ae4b97ddcd952a782a78&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/9edfd0d01fc811e2ae4b97ddcd952a782a78/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Fri, 26 Oct 2012 23:20:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-9edfd0d01fc811e2ae4b97ddcd952a782a78</guid>
        </item>
        <item>
            <title>DBus - How to pass dict as parameter</title>
            <link>http://raulherbster.blogspot.com/2010/11/dbus-how-to-pass-dict-as-parameter.html</link>
            <description><![CDATA[
This tutorial is designed for those ones that need DBus but suffer a lot to find documentation even about simple things, such as how to pass a dictionary as parameter.<br /><br />Initially, I had to invoke a Bluez method that needs a dictionary as parameter. But how could I do it? It not easy at all to find a detailed documentation about it and I had to look for a solution at BlueZ source code.<br /><br />In this case, I'm using the newest BlueZ Health API (support for HDP/MCAP). The following piece of code shows<br /><br /><pre lang="c" style="font-size: small;"><br />static char *start_health_session(DBusConnection *conn)<br />{<br /><br />  DBusMessage *msg, *reply;<br />  DBusMessageIter args;<br />  DBusError err;<br />  const char *reply_path;<br />  char *path;<br /><br />  msg = dbus_message_new_method_call("org.bluez", <br />                                     "/org/bluez", <br />                                     "org.bluez.HealthManager",<br />                                     "CreateApplication");<br /><br />  if (!msg) {<br />      printf(" network:dbus Can't allocate new method call\n");<br />      return NULL;<br />  }<br /><br />  // append arguments<br /><br />  dbus_message_iter_init_append(msg, &amp;args);<br /><br />  if ( !iter_append_dictionary(&amp;args, DATA_TYPE_VALUE, <br />                                          ROLE_VALUE,<br />                                          DESCRIPTION_VALUE, <br />                                          CHANNEL_TYPE_VALUE) ) {<br />      printf(" network:dbus Can't append parameters\n");<br />      dbus_message_unref(msg);<br />      return NULL;<br />  }<br /><br />  dbus_error_init(&amp;err);<br /><br />....<br />}<br /></pre><br />A DBus dict type needs a message iterator, which is properly initialised before it is used.<br /><br />Once the message iterator is properly created, let's open it and add tuples <key, value=""> to it.<br /><br /><pre lang="c" style="font-size: small;"><br />static int iter_append_dictionary(DBusMessageIter *iter, <br />                                  dbus_uint16_t dataType,<br />                                  const char *role,<br />                                  const char *description,<br />                                  const char *channelType)<br />{<br />  DBusMessageIter dict;<br /><br />  dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,<br />            DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING<br />            DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING<br />            DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &amp;dict);<br /><br />  dict_append_entry(&amp;dict, "DataType", DBUS_TYPE_UINT16, &amp;dataType);<br /><br />  dict_append_entry(&amp;dict, "Role", DBUS_TYPE_STRING, &amp;role);<br /><br />  dict_append_entry(&amp;dict, "Description", DBUS_TYPE_STRING, &amp;description);<br /><br />  dict_append_entry(&amp;dict, "ChannelType", DBUS_TYPE_STRING, &amp;channelType);<br /><br />  dbus_message_iter_close_container(iter, &amp;dict);<br />}<br /></pre><br /><br />At first, you have to open the container and specify the data type of each tuple. In this case, the dictionary consists of tuples <"DataType",uint16>, <"Role",string>, <"Description",string>, and <"ChannelType",string>. Once the value data type for each tuple varies (uint16 or string), we declare it as a variant. Therefore, the dictionary data type definition is:<br /><br /><pre lang="c" style="font-size: small;"><br />DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING<br /><span style="font-weight: bold;">DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING</span><br />DBUS_DICT_ENTRY_END_CHAR_AS_STRING<br /></pre><br /><br />Finally, you simply add the basic data type to message iterator (the dictionary itself).<br /><br /><pre lang="c" style="font-size: small;"><br />static void append_variant(DBusMessageIter *iter, int type, void *val)<br />{<br />  DBusMessageIter value;<br />  char sig[2] = { type, '\0' };<br /><br />  dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, sig, &amp;value);<br /><br />  dbus_message_iter_append_basic(&amp;value, type, val);<br /><br />  dbus_message_iter_close_container(iter, &amp;value);<br />}<br /><br />static void dict_append_entry(DBusMessageIter *dict,<br />   const char *key, int type, void *val)<br />{<br />  DBusMessageIter entry;<br /><br />  if (type == DBUS_TYPE_STRING) {<br />    const char *str = *((const char **) val);<br />    if (str == NULL)<br />      return;<br />  }<br /><br />  dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,<br />                                   NULL, &amp;entry);<br /><br />  dbus_message_iter_append_basic(&amp;entry, DBUS_TYPE_STRING, &amp;key);<br /><br />  append_variant(&amp;entry, type, val);<br /><br />  dbus_message_iter_close_container(dict, &amp;entry);<br />}<br /><br /></pre></key,><span class="net_nemein_favourites">5 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=86e9990af3da11dfb16435e5442cafd1afd1&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/86e9990af3da11dfb16435e5442cafd1afd1/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=86e9990af3da11dfb16435e5442cafd1afd1&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/86e9990af3da11dfb16435e5442cafd1afd1/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Thu, 18 Nov 2010 14:02:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-86e9990af3da11dfb16435e5442cafd1afd1</guid>
        </item>
        <item>
            <title>CUnit on ARM platforms.</title>
            <link>http://raulherbster.blogspot.com/2010/08/cunit-on-arm-platforms.html</link>
            <description><![CDATA[
Let's use this stuff :P Anyway, it's a good tool and I need to put some ideas anywhere.<br /><br />So, today's tip is how to compile your CUnit tests on Embedded platforms - in this case, on a N900 (ARM) with MeeGo installed on it.<br /><br />You should download the CUnit source code from http://sourceforge.net/projects/cunit/ (I only tested versions 2.0.X and 2.1.X). The process is very simple: download the code, copy to your development environment, and build it (./bootstrap &amp;&amp; make). However, things are not soooo easy as it seems :P<br /><br />Probably, you'll face problems at initial steps.<br /><br />If you have any problems on , execute the following command to change modification time/time:<br /><br /><pre lang="c"><br />find /path/to/files -exec touch {} \;<br /></pre><br /><br /><br />It seems to work.<span class="net_nemein_favourites">0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=b1ec8324f32111df83557984bb23c14ec14e&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/b1ec8324f32111df83557984bb23c14ec14e/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=b1ec8324f32111df83557984bb23c14ec14e&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/b1ec8324f32111df83557984bb23c14ec14e/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Mon, 16 Aug 2010 17:33:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-b1ec8324f32111df83557984bb23c14ec14e</guid>
        </item>
        <item>
            <title>Give us your opinion!</title>
            <link>http://raulherbster.blogspot.com/2009/08/give-us-your-oppinion.html</link>
            <description><![CDATA[
IDE Integration 2nd edition is comming soon, including new <a href="http://pluthon.garage.maemo.org">PluThon Eclipse product</a>. It comes with new and interesting features, such as ltrace integration. However, we know that Maemo community has a lot of valuable feedback and ideas that certainly improves PluThon and any other IDE Integration components (ESbox, PC Connectivity, etc.)<br /><br />Please, visit <a href="http://pluthon.garage.maemo.org/2nd_edition">PluThon 2nd edition web site</a>, check how features you´d see implemented on PluThon and provide a feedback to eclipse-integration AT maemo DOT org. Your comments are welcomed!<span class="net_nemein_favourites">15 <a href="http://maemo.org/news/?net_nemein_favourites_execute=fav&net_nemein_favourites_execute_for=f2c82710867411debd9cdf9ac38507a107a1&net_nemein_favourites_url=https://maemo.org/news/favorites//json/fav/midgard_article/f2c82710867411debd9cdf9ac38507a107a1/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-favorite.png" style="border: none;" alt="Add to favourites" title="Add to favourites" /></a>0 <a href="http://maemo.org/news/?net_nemein_favourites_execute=bury&net_nemein_favourites_execute_for=f2c82710867411debd9cdf9ac38507a107a1&net_nemein_favourites_url=https://maemo.org/news/favorites//json/bury/midgard_article/f2c82710867411debd9cdf9ac38507a107a1/" class="net_nemein_favourites_create"><img src="http://static.maemo.org:81/net.nemein.favourites/not-buried.png" style="border: none;" alt="Bury" title="Bury" /></a></span>]]></description>
            <author>Raul Herbster &lt;raulherbster@gmail.com&gt;</author>
            <category>feed:3443cd3b09dca3afd960884d779d28f3</category>
            <pubDate>Tue, 11 Aug 2009 12:05:00 +0000</pubDate>
            <guid>http://maemo.org/midcom-permalink-f2c82710867411debd9cdf9ac38507a107a1</guid>
        </item>
    </channel>
</rss>
