am 230cb33f: Make /proc/kmsg and /proc/sysrq-trigger system-process-readable

Merge commit '230cb33fd1ab335c6f808c72db891993b00110a0' into froyo-plus-aosp

* commit '230cb33fd1ab335c6f808c72db891993b00110a0':
  Make /proc/kmsg and /proc/sysrq-trigger system-process-readable
diff --git a/adb/Android.mk b/adb/Android.mk
index 0c93c1e..7faca9b 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -62,7 +62,6 @@
 	file_sync_client.c \
 	$(EXTRA_SRCS) \
 	$(USB_SRCS) \
-	shlist.c \
 	utils.c \
 	usb_vendors.c
 
@@ -74,7 +73,7 @@
 endif
 
 LOCAL_CFLAGS += -O2 -g -DADB_HOST=1  -Wall -Wno-unused-parameter
-LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE -DSH_HISTORY
+LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
 LOCAL_MODULE := adb
 
 LOCAL_STATIC_LIBRARIES := libzipfile libunz $(EXTRA_STATIC_LIBS)
diff --git a/adb/OVERVIEW.TXT b/adb/OVERVIEW.TXT
index 6a5191a..c40695a 100644
--- a/adb/OVERVIEW.TXT
+++ b/adb/OVERVIEW.TXT
@@ -35,7 +35,7 @@
     (through USB for devices, through TCP for emulators) and provide a
     few services for clients that run on the host.
 
-    The ADB server considers that a device is ONLINE when it has succesfully
+    The ADB server considers that a device is ONLINE when it has successfully
     connected to the adbd program within it. Otherwise, the device is OFFLINE,
     meaning that the ADB server detected a new device/emulator, but could not
     connect to the adbd daemon.
diff --git a/adb/SERVICES.TXT b/adb/SERVICES.TXT
index b0124a4..be4d50b 100644
--- a/adb/SERVICES.TXT
+++ b/adb/SERVICES.TXT
@@ -74,7 +74,7 @@
 
 host-local:<request>
     A variant of host-serial used to target the single emulator instance
-    running on the host. This will fail if therre is none or more than one.
+    running on the host. This will fail if there is none or more than one.
 
 host:<request>
     When asking for information related to a device, 'host:' can also be
@@ -146,7 +146,7 @@
 dev:<path>
     Opens a device file and connects the client directly to it for
     read/write purposes. Useful for debugging, but may require special
-    priviledges and thus may not run on all devices. <path> is a full
+    privileges and thus may not run on all devices. <path> is a full
     path from the root of the filesystem.
 
 tcp:<port>
@@ -173,7 +173,7 @@
 
 framebuffer:
     This service is used to send snapshots of the framebuffer to a client.
-    It requires sufficient priviledges but works as follow:
+    It requires sufficient privileges but works as follow:
 
       After the OKAY, the service sends 16-byte binary structure
       containing the following fields (little-endian format):
@@ -190,14 +190,14 @@
       one byte through the channel, which will trigger the service
       to send it 'size' bytes of framebuffer data.
 
-      If the adbd daemon doesn't have sufficient priviledges to open
+      If the adbd daemon doesn't have sufficient privileges to open
       the framebuffer device, the connection is simply closed immediately.
 
 dns:<server-name>
     This service is an exception because it only runs within the ADB server.
     It is used to implement USB networking, i.e. to provide a network connection
     to the device through the host machine (note: this is the exact opposite of
-    network thetering).
+    network tethering).
 
     It is used to perform a gethostbyname(<address>) on the host and return
     the corresponding IP address as a 4-byte string.
@@ -209,7 +209,7 @@
 
        - creating a file named /tmp/update
        - reading 'size' bytes from the client and writing them to /tmp/update
-       - when everything is read succesfully, create a file named /tmp/update.start
+       - when everything is read successfully, create a file named /tmp/update.start
 
     This service can only work when the device is in recovery mode. Otherwise,
     the /tmp directory doesn't exist and the connection will be closed immediately.
diff --git a/adb/adb.c b/adb/adb.c
index a34dd71..dd40eef 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -144,9 +144,6 @@
 void handle_online(void)
 {
     D("adb: online\n");
-#if !ADB_HOST
-    property_set("adb.connected","1");
-#endif
 }
 
 void handle_offline(atransport *t)
@@ -154,9 +151,6 @@
     D("adb: offline\n");
     //Close the associated usb
     run_transport_disconnects(t);
-#if !ADB_HOST
-    property_set("adb.connected","");
-#endif
 }
 
 #if TRACE_PACKETS
@@ -693,7 +687,7 @@
 #endif
 
 #if ADB_HOST
-int launch_server()
+int launch_server(int server_port)
 {
 #ifdef HAVE_WIN32_PROC
     /* we need to start the server in the background                    */
@@ -828,7 +822,17 @@
 }
 #endif
 
-int adb_main(int is_daemon)
+/* Constructs a local name of form tcp:port.
+ * target_str points to the target string, it's content will be overwritten.
+ * target_size is the capacity of the target string.
+ * server_port is the port number to use for the local name.
+ */
+void build_local_name(char* target_str, size_t target_size, int server_port)
+{
+  snprintf(target_str, target_size, "tcp:%d", server_port);
+}
+
+int adb_main(int is_daemon, int server_port)
 {
 #if !ADB_HOST
     int secure = 0;
@@ -851,9 +855,11 @@
     HOST = 1;
     usb_vendors_init();
     usb_init();
-    local_init(ADB_LOCAL_TRANSPORT_PORT);
+    local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
 
-    if(install_listener("tcp:5037", "*smartsocket*", NULL)) {
+    char local_name[30];
+    build_local_name(local_name, sizeof(local_name), server_port);
+    if(install_listener(local_name, "*smartsocket*", NULL)) {
         exit(1);
     }
 #else
@@ -879,7 +885,7 @@
         }
     }
 
-    /* don't listen on port 5037 if we are running in secure mode */
+    /* don't listen on a port (default 5037) if running in secure mode */
     /* don't run as root if we are running in secure mode */
     if (secure) {
         struct __user_cap_header_struct header;
@@ -912,18 +918,23 @@
         cap.inheritable = 0;
         capset(&header, &cap);
 
-        D("Local port 5037 disabled\n");
+        D("Local port disabled\n");
     } else {
-        if(install_listener("tcp:5037", "*smartsocket*", NULL)) {
+        char local_name[30];
+        build_local_name(local_name, sizeof(local_name), server_port);
+        if(install_listener(local_name, "*smartsocket*", NULL)) {
             exit(1);
         }
     }
 
         /* for the device, start the usb transport if the
-        ** android usb device exists and "service.adb.tcp"
-        ** is not set, otherwise start the network transport.
+        ** android usb device exists and the "service.adb.tcp.port" and
+        ** "persist.adb.tcp.port" properties are not set.
+        ** Otherwise start the network transport.
         */
-    property_get("service.adb.tcp.port", value, "0");
+    property_get("service.adb.tcp.port", value, "");
+    if (!value[0])
+        property_get("persist.adb.tcp.port", value, "");
     if (sscanf(value, "%d", &port) == 1 && port > 0) {
         // listen on TCP port specified by service.adb.tcp.port property
         local_init(port);
@@ -932,7 +943,7 @@
         usb_init();
     } else {
         // listen on default port
-        local_init(ADB_LOCAL_TRANSPORT_PORT);
+        local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
     }
     init_jdwp();
 #endif
@@ -956,6 +967,99 @@
     return 0;
 }
 
+#if ADB_HOST
+void connect_device(char* host, char* buffer, int buffer_size)
+{
+    int port, fd;
+    char* portstr = strchr(host, ':');
+    char buf[4096];
+
+    if (!portstr) {
+        snprintf(buffer, buffer_size, "unable to parse %s as <host>:<port>", host);
+        return;
+    }
+    if (find_transport(host)) {
+        snprintf(buffer, buffer_size, "already connected to %s", host);
+        return;
+    }
+
+    // zero terminate host by overwriting the ':'
+    *portstr++ = 0;
+    if (sscanf(portstr, "%d", &port) == 0) {
+        snprintf(buffer, buffer_size, "bad port number %s", portstr);
+        return;
+    }
+
+    fd = socket_network_client(host, port, SOCK_STREAM);
+    if (fd < 0) {
+        snprintf(buffer, buffer_size, "unable to connect to %s:%d", host, port);
+        return;
+    }
+
+    D("client: connected on remote on fd %d\n", fd);
+    close_on_exec(fd);
+    disable_tcp_nagle(fd);
+    snprintf(buf, sizeof buf, "%s:%d", host, port);
+    register_socket_transport(fd, buf, port, 0);
+    snprintf(buffer, buffer_size, "connected to %s:%d", host, port);
+}
+
+void connect_emulator(char* port_spec, char* buffer, int buffer_size)
+{
+    char* port_separator = strchr(port_spec, ',');
+    if (!port_separator) {
+        snprintf(buffer, buffer_size,
+                "unable to parse '%s' as <console port>,<adb port>",
+                port_spec);
+        return;
+    }
+
+    // Zero-terminate console port and make port_separator point to 2nd port.
+    *port_separator++ = 0;
+    int console_port = strtol(port_spec, NULL, 0);
+    int adb_port = strtol(port_separator, NULL, 0);
+    if (!(console_port > 0 && adb_port > 0)) {
+        *(port_separator - 1) = ',';
+        snprintf(buffer, buffer_size,
+                "Invalid port numbers: Expected positive numbers, got '%s'",
+                port_spec);
+        return;
+    }
+
+    /* Check if the emulator is already known.
+     * Note: There's a small but harmless race condition here: An emulator not
+     * present just yet could be registered by another invocation right
+     * after doing this check here. However, local_connect protects
+     * against double-registration too. From here, a better error message
+     * can be produced. In the case of the race condition, the very specific
+     * error message won't be shown, but the data doesn't get corrupted. */
+    atransport* known_emulator = find_emulator_transport_by_adb_port(adb_port);
+    if (known_emulator != NULL) {
+        snprintf(buffer, buffer_size,
+                "Emulator on port %d already registered.", adb_port);
+        return;
+    }
+
+    /* Check if more emulators can be registered. Similar unproblematic
+     * race condition as above. */
+    int candidate_slot = get_available_local_transport_index();
+    if (candidate_slot < 0) {
+        snprintf(buffer, buffer_size, "Cannot accept more emulators.");
+        return;
+    }
+
+    /* Preconditions met, try to connect to the emulator. */
+    if (!local_connect_arbitrary_ports(console_port, adb_port)) {
+        snprintf(buffer, buffer_size,
+                "Connected to emulator on ports %d,%d", console_port, adb_port);
+    } else {
+        snprintf(buffer, buffer_size,
+                "Could not connect to emulator on ports %d,%d",
+                console_port, adb_port);
+    }
+}
+#endif
+
 int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s)
 {
     atransport *transport = NULL;
@@ -1013,43 +1117,16 @@
         return 0;
     }
 
-    // add a new TCP transport
+    // add a new TCP transport, device or emulator
     if (!strncmp(service, "connect:", 8)) {
         char buffer[4096];
-        int port, fd;
         char* host = service + 8;
-        char* portstr = strchr(host, ':');
-
-        if (!portstr) {
-            snprintf(buffer, sizeof(buffer), "unable to parse %s as <host>:<port>", host);
-            goto done;
+        if (!strncmp(host, "emu:", 4)) {
+            connect_emulator(host + 4, buffer, sizeof(buffer));
+        } else {
+            connect_device(host, buffer, sizeof(buffer));
         }
-        if (find_transport(host)) {
-            snprintf(buffer, sizeof(buffer), "Already connected to %s", host);
-            goto done;
-        }
-
-        // zero terminate host by overwriting the ':'
-        *portstr++ = 0;
-        if (sscanf(portstr, "%d", &port) == 0) {
-            snprintf(buffer, sizeof(buffer), "bad port number %s", portstr);
-            goto done;
-        }
-
-        fd = socket_network_client(host, port, SOCK_STREAM);
-        if (fd < 0) {
-            snprintf(buffer, sizeof(buffer), "unable to connect to %s:%d", host, port);
-            goto done;
-        }
-
-        D("client: connected on remote on fd %d\n", fd);
-        close_on_exec(fd);
-        disable_tcp_nagle(fd);
-        snprintf(buf, sizeof buf, "%s:%d", host, port);
-        register_socket_transport(fd, buf, port, 0);
-        snprintf(buffer, sizeof(buffer), "connected to %s:%d", host, port);
-
-done:
+        // Send response for emulator and device
         snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer);
         writex(reply_fd, buf, strlen(buf));
         return 0;
@@ -1173,6 +1250,6 @@
     }
 
     start_device_log();
-    return adb_main(0);
+    return adb_main(0, DEFAULT_ADB_PORT);
 #endif
 }
diff --git a/adb/adb.h b/adb/adb.h
index aaf8a28..292e415 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -183,6 +183,7 @@
         /* used to identify transports for clients */
     char *serial;
     char *product;
+    int adb_port; // Use for emulators (local transport)
 
         /* a list of adisconnect callbacks called when the transport is kicked */
     int          kicked;
@@ -237,8 +238,8 @@
 void send_packet(apacket *p, atransport *t);
 
 void get_my_path(char *s, size_t maxLen);
-int launch_server();
-int adb_main(int is_daemon);
+int launch_server(int server_port);
+int adb_main(int is_daemon, int server_port);
 
 
 /* transports are ref-counted
@@ -262,6 +263,9 @@
 void   kick_transport( atransport*  t );
 
 /* initialize a transport object's func pointers and state */
+#if ADB_HOST
+int get_available_local_transport_index();
+#endif
 int  init_socket_transport(atransport *t, int s, int port, int local);
 void init_usb_transport(atransport *t, usb_handle *usb, int state);
 
@@ -280,6 +284,9 @@
 void unregister_usb_transport(usb_handle *usb);
 
 atransport *find_transport(const char *serial);
+#if ADB_HOST
+atransport* find_emulator_transport_by_adb_port(int adb_port);
+#endif
 
 int service_to_fd(const char *name);
 #if ADB_HOST
@@ -358,8 +365,8 @@
 #define print_packet(tag,p) do {} while (0)
 #endif
 
-#define ADB_PORT 5037
-#define ADB_LOCAL_TRANSPORT_PORT 5555
+#define DEFAULT_ADB_PORT 5037
+#define DEFAULT_ADB_LOCAL_TRANSPORT_PORT 5555
 
 #define ADB_CLASS              0xff
 #define ADB_SUBCLASS           0x42
@@ -368,6 +375,7 @@
 
 void local_init(int port);
 int  local_connect(int  port);
+int  local_connect_arbitrary_ports(int console_port, int adb_port);
 
 /* usb host/client interface */
 void usb_init();
diff --git a/adb/adb_client.c b/adb/adb_client.c
index 243f0fa..882810a 100644
--- a/adb/adb_client.c
+++ b/adb/adb_client.c
@@ -16,12 +16,19 @@
 static transport_type __adb_transport = kTransportAny;
 static const char* __adb_serial = NULL;
 
+static int __adb_server_port = DEFAULT_ADB_PORT;
+
 void adb_set_transport(transport_type type, const char* serial)
 {
     __adb_transport = type;
     __adb_serial = serial;
 }
 
+void adb_set_tcp_specifics(int server_port)
+{
+    __adb_server_port = server_port;
+}
+
 int  adb_get_emulator_console_port(void)
 {
     const char*   serial = __adb_serial;
@@ -174,7 +181,7 @@
     }
     snprintf(tmp, sizeof tmp, "%04x", len);
 
-    fd = socket_loopback_client(ADB_PORT, SOCK_STREAM);
+    fd = socket_loopback_client(__adb_server_port, SOCK_STREAM);
     if(fd < 0) {
         strcpy(__adb_error, "cannot connect to daemon");
         return -2;
@@ -204,9 +211,10 @@
     int fd = _adb_connect("host:version");
 
     if(fd == -2) {
-        fprintf(stdout,"* daemon not running. starting it now *\n");
+        fprintf(stdout,"* daemon not running. starting it now on port %d *\n",
+                __adb_server_port);
     start_server:
-        if(launch_server(0)) {
+        if(launch_server(__adb_server_port)) {
             fprintf(stderr,"* failed to start daemon *\n");
             return -1;
         } else {
@@ -314,5 +322,3 @@
     adb_close(fd);
     return 0;
 }
-
-
diff --git a/adb/adb_client.h b/adb/adb_client.h
index 8061579..40ab189 100644
--- a/adb/adb_client.h
+++ b/adb/adb_client.h
@@ -25,6 +25,10 @@
 */
 void adb_set_transport(transport_type type, const char* serial);
 
+/* Set TCP specifics of the transport to use
+*/
+void adb_set_tcp_specifics(int server_port);
+
 /* Return the console port of the currently connected emulator (if any)
  * of -1 if there is no emulator, and -2 if there is more than one.
  * assumes adb_set_transport() was alled previously...
diff --git a/adb/commandline.c b/adb/commandline.c
index 857cee3..4d7d357 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -37,11 +37,6 @@
 #include "adb_client.h"
 #include "file_sync_service.h"
 
-#ifdef SH_HISTORY
-#include "shlist.h"
-#include "history.h"
-#endif
-
 enum {
     IGNORE_DATA,
     WIPE_DATA,
@@ -112,6 +107,7 @@
         "  adb push <local> <remote>    - copy file/dir to device\n"
         "  adb pull <remote> [<local>]  - copy file/dir from device\n"
         "  adb sync [ <directory> ]     - copy host->device only if changed\n"
+        "                                 (-l means list but don't copy)\n"
         "                                 (see 'adb help all')\n"
         "  adb shell                    - run remote shell interactively\n"
         "  adb shell <command>          - run remote shell command\n"
@@ -170,6 +166,12 @@
         "\n"
         "  - If it is \"system\" or \"data\", only the corresponding partition\n"
         "    is updated.\n"
+        "\n"
+        "environmental variables:\n"
+        "  ADB_TRACE                    - Print debug information. A comma separated list of the following values\n"
+        "                                 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp\n"
+        "  ANDROID_SERIAL               - The serial number to connect to. -s takes priority over this if given.\n"
+        "  ANDROID_LOG_TAGS             - When used with the logcat option, only these debug tags are printed.\n"
         );
 }
 
@@ -226,23 +228,10 @@
     }
 }
 
-#ifdef SH_HISTORY
-int shItemCmp( void *val, void *idata )
-{
-    return( (strcmp( val, idata ) == 0) );
-}
-#endif
-
 static void *stdin_read_thread(void *x)
 {
     int fd, fdi;
     unsigned char buf[1024];
-#ifdef SH_HISTORY
-    unsigned char realbuf[1024], *buf_ptr;
-    SHLIST history;
-    SHLIST *item = &history;
-    int cmdlen = 0, ins_flag = 0;
-#endif
     int r, n;
     int state = 0;
 
@@ -251,9 +240,6 @@
     fdi = fds[1];
     free(fds);
 
-#ifdef SH_HISTORY
-    shListInitList( &history );
-#endif
     for(;;) {
         /* fdi is really the client's stdin, so use read, not adb_read here */
         r = unix_read(fdi, buf, 1024);
@@ -262,97 +248,34 @@
             if(errno == EINTR) continue;
             break;
         }
-#ifdef SH_HISTORY
-        if( (r == 3) &&                                       /* Arrow processing */
-            (memcmp( (void *)buf, SH_ARROW_ANY, 2 ) == 0) ) {
-            switch( buf[2] ) {
-                case SH_ARROW_UP:
-                    item = shListGetNextItem( &history, item );
-                    break;
-                case SH_ARROW_DOWN:
-                    item = shListGetPrevItem( &history, item );
-                    break;
-                default:
-                    item = NULL;
-                    break;
-            }
-            memset( buf, SH_DEL_CHAR, cmdlen );
-            if( item != NULL ) {
-                n = snprintf( (char *)(&buf[cmdlen]), sizeof buf - cmdlen, "%s", (char *)(item->data) );
-                memcpy( realbuf, item->data, n );
-            }
-            else { /* Clean buffer */
-                item = &history;
-                n = 0;
-            }
-            r = n + cmdlen;
-            cmdlen = n;
-            ins_flag = 0;
-            if( r == 0 )
-                continue;
-        }
-        else {
+        for(n = 0; n < r; n++){
+            switch(buf[n]) {
+            case '\n':
+                state = 1;
+                break;
+            case '\r':
+                state = 1;
+                break;
+            case '~':
+                if(state == 1) state++;
+                break;
+            case '.':
+                if(state == 2) {
+                    fprintf(stderr,"\n* disconnect *\n");
+#ifdef HAVE_TERMIO_H
+                    stdin_raw_restore(fdi);
 #endif
-            for(n = 0; n < r; n++){
-                switch(buf[n]) {
-                case '\n':
-#ifdef SH_HISTORY
-                    if( ins_flag && (SH_BLANK_CHAR <= realbuf[0]) ) {
-                        buf_ptr = malloc(cmdlen + 1);
-                        if( buf_ptr != NULL ) {
-                            memcpy( buf_ptr, realbuf, cmdlen );
-                            buf_ptr[cmdlen] = '\0';
-                            if( (item = shListFindItem( &history, (void *)buf_ptr, shItemCmp )) == NULL ) {
-                                shListInsFirstItem( &history, (void *)buf_ptr );
-                                item = &history;
-                            }
-                        }
-                    }
-                    cmdlen = 0;
-                    ins_flag = 0;
-#endif
-                    state = 1;
-                    break;
-                case '\r':
-                    state = 1;
-                    break;
-                case '~':
-                    if(state == 1) state++;
-                    break;
-                case '.':
-                    if(state == 2) {
-                        fprintf(stderr,"\n* disconnect *\n");
-    #ifdef HAVE_TERMIO_H
-                        stdin_raw_restore(fdi);
-    #endif
-                        exit(0);
-                    }
-                default:
-#ifdef SH_HISTORY
-                    if( buf[n] == SH_DEL_CHAR ) {
-                        if( cmdlen > 0 )
-                            cmdlen--;
-                    }
-                    else {
-                        realbuf[cmdlen] = buf[n];
-                        cmdlen++;
-                    }
-                    ins_flag = 1;
-#endif
-                    state = 0;
+                    exit(0);
                 }
+            default:
+                state = 0;
             }
-#ifdef SH_HISTORY
         }
-#endif
         r = adb_write(fd, buf, r);
         if(r <= 0) {
             break;
         }
     }
-#ifdef SH_HISTORY
-    shListDelAllItems( &history, (shListFree)free );
-#endif
     return 0;
 }
 
@@ -761,6 +684,7 @@
     int quote;
     transport_type ttype = kTransportAny;
     char* serial = NULL;
+    char* server_port_str = NULL;
 
         /* If defined, this should be an absolute path to
          * the directory containing all of the various system images
@@ -776,7 +700,20 @@
 
     serial = getenv("ANDROID_SERIAL");
 
-        /* modifiers and flags */
+    /* Validate and assign the server port */
+    server_port_str = getenv("ANDROID_ADB_SERVER_PORT");
+    int server_port = DEFAULT_ADB_PORT;
+    if (server_port_str && strlen(server_port_str) > 0) {
+        server_port = (int) strtol(server_port_str, NULL, 0);
+        if (server_port <= 0) {
+            fprintf(stderr,
+                    "adb: Env var ANDROID_ADB_SERVER_PORT must be a positive number. Got \"%s\"\n",
+                    server_port_str);
+            return usage();
+        }
+    }
+
+    /* modifiers and flags */
     while(argc > 0) {
         if(!strcmp(argv[0],"nodaemon")) {
             no_daemon = 1;
@@ -805,7 +742,7 @@
             if (isdigit(argv[0][2])) {
                 serial = argv[0] + 2;
             } else {
-                if(argc < 2) return usage();
+                if(argc < 2 || argv[0][2] != '\0') return usage();
                 serial = argv[1];
                 argc--;
                 argv++;
@@ -823,12 +760,13 @@
     }
 
     adb_set_transport(ttype, serial);
+    adb_set_tcp_specifics(server_port);
 
     if ((argc > 0) && (!strcmp(argv[0],"server"))) {
         if (no_daemon || is_daemon) {
-            r = adb_main(is_daemon);
+            r = adb_main(is_daemon, server_port);
         } else {
-            r = launch_server();
+            r = launch_server(server_port);
         }
         if(r) {
             fprintf(stderr,"* could not start server *\n");
@@ -893,10 +831,10 @@
             /* quote empty strings and strings with spaces */
             quote = (**argv == 0 || strchr(*argv, ' '));
             if (quote)
-            	strcat(buf, "\"");
+                strcat(buf, "\"");
             strcat(buf, *argv++);
             if (quote)
-            	strcat(buf, "\"");
+                strcat(buf, "\"");
         }
 
         for(;;) {
@@ -1042,10 +980,19 @@
 
     if(!strcmp(argv[0], "sync")) {
         char *srcarg, *android_srcpath, *data_srcpath;
+        int listonly = 0;
+
         int ret;
         if(argc < 2) {
             /* No local path was specified. */
             srcarg = NULL;
+        } else if (argc >= 2 && strcmp(argv[1], "-l") == 0) {
+            listonly = 1;
+            if (argc == 3) {
+                srcarg = argv[2];
+            } else {
+                srcarg = NULL;
+            }
         } else if(argc == 2) {
             /* A local path or "android"/"data" arg was specified. */
             srcarg = argv[1];
@@ -1056,9 +1003,9 @@
         if(ret != 0) return usage();
 
         if(android_srcpath != NULL)
-            ret = do_sync_sync(android_srcpath, "/system");
+            ret = do_sync_sync(android_srcpath, "/system", listonly);
         if(ret == 0 && data_srcpath != NULL)
-            ret = do_sync_sync(data_srcpath, "/data");
+            ret = do_sync_sync(data_srcpath, "/data", listonly);
 
         free(android_srcpath);
         free(data_srcpath);
diff --git a/adb/file_sync_client.c b/adb/file_sync_client.c
index 0ebfe73..da25ae8 100644
--- a/adb/file_sync_client.c
+++ b/adb/file_sync_client.c
@@ -670,7 +670,7 @@
 }
 
 
-static int copy_local_dir_remote(int fd, const char *lpath, const char *rpath, int checktimestamps)
+static int copy_local_dir_remote(int fd, const char *lpath, const char *rpath, int checktimestamps, int listonly)
 {
     copyinfo *filelist = 0;
     copyinfo *ci, *next;
@@ -718,8 +718,9 @@
     for(ci = filelist; ci != 0; ci = next) {
         next = ci->next;
         if(ci->flag == 0) {
-            fprintf(stderr,"push: %s -> %s\n", ci->src, ci->dst);
-            if(sync_send(fd, ci->src, ci->dst, ci->time, ci->mode, 0 /* no verify APK */)){
+            fprintf(stderr,"%spush: %s -> %s\n", listonly ? "would " : "", ci->src, ci->dst);
+            if(!listonly &&
+               sync_send(fd, ci->src, ci->dst, ci->time, ci->mode, 0 /* no verify APK */)){
                 return 1;
             }
             pushed++;
@@ -757,7 +758,7 @@
 
     if(S_ISDIR(st.st_mode)) {
         BEGIN();
-        if(copy_local_dir_remote(fd, lpath, rpath, 0)) {
+        if(copy_local_dir_remote(fd, lpath, rpath, 0, 0)) {
             return 1;
         } else {
             END();
@@ -959,7 +960,7 @@
         return 1;
     }
 
-    if(S_ISREG(mode) || S_ISCHR(mode) || S_ISBLK(mode)) {
+    if(S_ISREG(mode) || S_ISLNK(mode) || S_ISCHR(mode) || S_ISBLK(mode)) {
         if(stat(lpath, &st) == 0) {
             if(S_ISDIR(st.st_mode)) {
                     /* if we're copying a remote file to a local directory,
@@ -1001,7 +1002,7 @@
     }
 }
 
-int do_sync_sync(const char *lpath, const char *rpath)
+int do_sync_sync(const char *lpath, const char *rpath, int listonly)
 {
     fprintf(stderr,"syncing %s...\n",rpath);
 
@@ -1012,7 +1013,7 @@
     }
 
     BEGIN();
-    if(copy_local_dir_remote(fd, lpath, rpath, 1)){
+    if(copy_local_dir_remote(fd, lpath, rpath, 1, listonly)){
         return 1;
     } else {
         END();
diff --git a/adb/file_sync_service.h b/adb/file_sync_service.h
index 4ee40ba..11ea06b 100644
--- a/adb/file_sync_service.h
+++ b/adb/file_sync_service.h
@@ -79,7 +79,7 @@
 void file_sync_service(int fd, void *cookie);
 int do_sync_ls(const char *path);
 int do_sync_push(const char *lpath, const char *rpath, int verifyApk);
-int do_sync_sync(const char *lpath, const char *rpath);
+int do_sync_sync(const char *lpath, const char *rpath, int listonly);
 int do_sync_pull(const char *rpath, const char *lpath);
 
 #define SYNC_DATA_MAX (64*1024)
diff --git a/adb/history.h b/adb/history.h
deleted file mode 100755
index ef86ad9..0000000
--- a/adb/history.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _HISTORY_H_

-#define _HISTORY_H_

-

-#define SH_ARROW_ANY    "\x1b\x5b"

-#define SH_ARROW_UP     '\x41'

-#define SH_ARROW_DOWN   '\x42'

-#define SH_ARROW_RIGHT  '\x43'

-#define SH_ARROW_LEFT   '\x44'

-#define SH_DEL_CHAR     '\x7F'

-#define SH_BLANK_CHAR   '\x20'

-

-#endif

-

diff --git a/adb/remount_service.c b/adb/remount_service.c
index 26bc841..4cb41e7 100644
--- a/adb/remount_service.c
+++ b/adb/remount_service.c
@@ -30,19 +30,19 @@
 
 static int system_ro = 1;
 
-/* Returns the mount number of the requested partition from /proc/mtd */
-static int find_mount(const char *findme)
+/* Returns the device used to mount a directory in /proc/mounts */
+static char *find_mount(const char *dir)
 {
     int fd;
     int res;
     int size;
     char *token = NULL;
     const char delims[] = "\n";
-    char buf[1024];
+    char buf[4096];
 
-    fd = unix_open("/proc/mtd", O_RDONLY);
+    fd = unix_open("/proc/mounts", O_RDONLY);
     if (fd < 0)
-        return -errno;
+        return NULL;
 
     buf[sizeof(buf) - 1] = '\0';
     size = adb_read(fd, buf, sizeof(buf) - 1);
@@ -51,33 +51,41 @@
     token = strtok(buf, delims);
 
     while (token) {
-        char mtdname[16];
-        int mtdnum, mtdsize, mtderasesize;
+        char mount_dev[256];
+        char mount_dir[256];
+        int mount_freq;
+        int mount_passno;
 
-        res = sscanf(token, "mtd%d: %x %x %15s",
-                     &mtdnum, &mtdsize, &mtderasesize, mtdname);
-
-        if (res == 4 && !strcmp(mtdname, findme))
-            return mtdnum;
+        res = sscanf(token, "%255s %255s %*s %*s %d %d\n",
+                     mount_dev, mount_dir, &mount_freq, &mount_passno);
+        mount_dev[255] = 0;
+        mount_dir[255] = 0;
+        if (res == 4 && (strcmp(dir, mount_dir) == 0))
+            return strdup(mount_dev);
 
         token = strtok(NULL, delims);
     }
-    return -1;
+    return NULL;
 }
 
 /* Init mounts /system as read only, remount to enable writes. */
 static int remount_system()
 {
-    int num;
-    char source[64];
+    char *dev;
+
     if (system_ro == 0) {
         return 0;
     }
-    if ((num = find_mount("\"system\"")) < 0)
+
+    dev = find_mount("/system");
+
+    if (!dev)
         return -1;
 
-    snprintf(source, sizeof source, "/dev/block/mtdblock%d", num);
-    system_ro = mount(source, "/system", "yaffs2", MS_REMOUNT, NULL);
+    system_ro = mount(dev, "/system", "none", MS_REMOUNT, NULL);
+
+    free(dev);
+
     return system_ro;
 }
 
diff --git a/adb/shlist.c b/adb/shlist.c
deleted file mode 100755
index 44919ef..0000000
--- a/adb/shlist.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*-------------------------------------------------------------------*/
-/*                         List  Functionality                       */
-/*-------------------------------------------------------------------*/
-/* #define SH_LIST_DEBUG */
-/*-------------------------------------------------------------------*/
-#include <stdio.h>
-#include <stdlib.h>
-#include "shlist.h"
-/*-------------------------------------------------------------------*/
-void shListInitList( SHLIST *listPtr )
-{
-  listPtr->data = (void *)0L;
-  listPtr->next = listPtr;
-  listPtr->prev = listPtr;
-}
-
-SHLIST *shListFindItem( SHLIST *head, void *val, shListEqual func )
-{
-  SHLIST *item;
-
-  for(item=head->next;( item != head );item=item->next)
-    if( func ) {
-      if( func( val, item->data ) ) {
-        return( item );
-      }
-    }
-    else {
-      if( item->data == val ) {
-        return( item );
-      }
-    }
-  return( NULL );
-}
-
-SHLIST *shListGetLastItem( SHLIST *head )
-{
-  if( head->prev != head )
-    return( head->prev );
-  return( NULL );
-}
-
-SHLIST *shListGetFirstItem( SHLIST *head )
-{
-  if( head->next != head )
-    return( head->next );
-  return( NULL );
-}
-
-SHLIST *shListGetNItem( SHLIST *head, unsigned long num )
-{
-  SHLIST *item;
-  unsigned long i;
-
-  for(i=0,item=head->next;( (i < num) && (item != head) );i++,item=item->next);
-  if( item != head )
-    return( item );
-  return( NULL );
-}
-
-SHLIST *shListGetNextItem( SHLIST *head, SHLIST *item )
-{
-  if( item == NULL )
-    return( NULL );
-  if( item->next != head )
-    return( item->next );
-  return( NULL );
-}
-
-SHLIST *shListGetPrevItem( SHLIST *head, SHLIST *item )
-{
-  if( item == NULL )
-    return( NULL );
-  if( item->prev != head )
-    return( item->prev );
-  return( NULL );
-}
-
-void shListDelItem( SHLIST *head, SHLIST *item, shListFree func )
-{
-  if( item == NULL )
-    return;
-#ifdef SH_LIST_DEBUG
-  fprintf(stderr, "Del %lx\n", (unsigned long)(item->data));
-#endif
-  (item->prev)->next = item->next;
-  (item->next)->prev = item->prev;
-  if( func && item->data ) {
-    func( (void *)(item->data) );
-  }
-  free( item );
-  head->data = (void *)((unsigned long)(head->data) - 1);
-}
-
-void shListInsFirstItem( SHLIST *head, void *val )
-{ /* Insert to the beginning of the list */
-  SHLIST *item;
-
-  item = (SHLIST *)malloc( sizeof(SHLIST) );
-  if( item == NULL )
-    return;
-  item->data = val;
-  item->next = head->next;
-  item->prev = head;
-  (head->next)->prev = item;
-  head->next = item;
-#ifdef SH_LIST_DEBUG
-  fprintf(stderr, "Ins First %lx\n", (unsigned long)(item->data));
-#endif
-  head->data = (void *)((unsigned long)(head->data) + 1);
-}
-
-void shListInsLastItem( SHLIST *head, void *val )
-{ /* Insert to the end of the list */
-  SHLIST *item;
-
-  item = (SHLIST *)malloc( sizeof(SHLIST) );
-  if( item == NULL )
-    return;
-  item->data = val;
-  item->next = head;
-  item->prev = head->prev;
-  (head->prev)->next = item;
-  head->prev = item;
-#ifdef SH_LIST_DEBUG
-  fprintf(stderr, "Ins Last %lx\n", (unsigned long)(item->data));
-#endif
-  head->data = (void *)((unsigned long)(head->data) + 1);
-}
-
-void shListInsBeforeItem( SHLIST *head, void *val, void *etal, 
-                          shListCmp func )
-{
-  SHLIST *item, *iptr;
-
-  if( func == NULL )
-    shListInsFirstItem( head, val );
-  else {
-    item = (SHLIST *)malloc( sizeof(SHLIST) );
-    if( item == NULL )
-      return;
-    item->data = val;
-    for(iptr=head->next;( iptr != head );iptr=iptr->next)
-      if( func( val, iptr->data, etal ) )
-         break;
-    item->next = iptr;
-    item->prev = iptr->prev;
-    (iptr->prev)->next = item;
-    iptr->prev = item;
-#ifdef SH_LIST_DEBUG
-    fprintf(stderr, "Ins Before %lx\n", (unsigned long)(item->data));
-#endif
-    head->data = (void *)((unsigned long)(head->data) + 1);
-  }
-}
-
-void shListDelAllItems( SHLIST *head, shListFree func )
-{
-  SHLIST *item;
-
-  for(item=head->next;( item != head );) {
-    shListDelItem( head, item, func );
-    item = head->next;
-  }
-  head->data = (void *)0L;
-}
-
-void shListPrintAllItems( SHLIST *head, shListPrint func )
-{
-#ifdef SH_LIST_DEBUG
-  SHLIST *item;
-
-  for(item=head->next;( item != head );item=item->next)
-    if( func ) {
-      func(item->data);
-    }
-    else {
-      fprintf(stderr, "Item: %lx\n",(unsigned long)(item->data));
-    }
-#endif
-}
-
-unsigned long shListGetCount( SHLIST *head )
-{
-  return( (unsigned long)(head->data) );
-}
diff --git a/adb/shlist.h b/adb/shlist.h
deleted file mode 100755
index 0a9b07b..0000000
--- a/adb/shlist.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*-------------------------------------------------------------------*/
-/*                         List  Functionality                       */
-/*-------------------------------------------------------------------*/
-#ifndef _SHLIST_H_
-#define _SHLIST_H_
-
-typedef struct SHLIST_STRUC {
-  void *data;
-  struct SHLIST_STRUC *next;
-  struct SHLIST_STRUC *prev;
-} SHLIST;
-
-typedef int (*shListCmp)( void *valo, void *valn, void *etalon );
-typedef int (*shListPrint)( void *val );
-typedef void (*shListFree)( void *val );
-typedef int (*shListEqual)( void *val,  void *idata );
-
-void shListInitList( SHLIST *listPtr );
-SHLIST *shListFindItem( SHLIST *head, void *val, shListEqual func );
-SHLIST *shListGetFirstItem( SHLIST *head );
-SHLIST *shListGetNItem( SHLIST *head, unsigned long num );
-SHLIST *shListGetLastItem( SHLIST *head );
-SHLIST *shListGetNextItem( SHLIST *head, SHLIST *item );
-SHLIST *shListGetPrevItem( SHLIST *head, SHLIST *item );
-void shListDelItem( SHLIST *head, SHLIST *item, shListFree func );
-void shListInsFirstItem( SHLIST *head, void *val );
-void shListInsBeforeItem( SHLIST *head, void *val, void *etalon, 
-                          shListCmp func );
-void shListInsLastItem( SHLIST *head, void *val );
-void shListDelAllItems( SHLIST *head, shListFree func );
-void shListPrintAllItems( SHLIST *head, shListPrint func );
-unsigned long shListGetCount( SHLIST *head );
-
-#endif
diff --git a/adb/transport_local.c b/adb/transport_local.c
index 81d120e..8dfc98d 100644
--- a/adb/transport_local.c
+++ b/adb/transport_local.c
@@ -41,9 +41,9 @@
 #endif
 
 #if ADB_HOST
-/* we keep a list of opened transports, transport 0 is bound to 5555,
- * transport 1 to 5557, .. transport n to 5555 + n*2. the list is used
- * to detect when we're trying to connect twice to a given local transport
+/* we keep a list of opened transports. The atransport struct knows to which
+ * local transport it is connected. The list is used to detect when we're
+ * trying to connect twice to a given local transport.
  */
 #define  ADB_LOCAL_TRANSPORT_MAX  16
 
@@ -102,7 +102,11 @@
 }
 
 
-int  local_connect(int  port)
+int local_connect(int port) {
+    return local_connect_arbitrary_ports(port-1, port);
+}
+
+int local_connect_arbitrary_ports(int console_port, int adb_port)
 {
     char buf[64];
     int  fd = -1;
@@ -110,19 +114,19 @@
 #if ADB_HOST
     const char *host = getenv("ADBHOST");
     if (host) {
-        fd = socket_network_client(host, port, SOCK_STREAM);
+        fd = socket_network_client(host, adb_port, SOCK_STREAM);
     }
 #endif
     if (fd < 0) {
-        fd = socket_loopback_client(port, SOCK_STREAM);
+        fd = socket_loopback_client(adb_port, SOCK_STREAM);
     }
 
     if (fd >= 0) {
         D("client: connected on remote on fd %d\n", fd);
         close_on_exec(fd);
         disable_tcp_nagle(fd);
-        snprintf(buf, sizeof buf, "%s%d", LOCAL_CLIENT_PREFIX, port - 1);
-        register_socket_transport(fd, buf, port, 1);
+        snprintf(buf, sizeof buf, "%s%d", LOCAL_CLIENT_PREFIX, console_port);
+        register_socket_transport(fd, buf, adb_port, 1);
         return 0;
     }
     return -1;
@@ -132,7 +136,7 @@
 static void *client_socket_thread(void *x)
 {
 #if ADB_HOST
-    int  port  = ADB_LOCAL_TRANSPORT_PORT;
+    int  port  = DEFAULT_ADB_LOCAL_TRANSPORT_PORT;
     int  count = ADB_LOCAL_TRANSPORT_MAX;
 
     D("transport: client_socket_thread() starting\n");
@@ -227,7 +231,50 @@
     adb_close(t->fd);
 }
 
-int init_socket_transport(atransport *t, int s, int port, int local)
+
+#if ADB_HOST
+/* Only call this function if you already hold local_transports_lock. */
+atransport* find_emulator_transport_by_adb_port_locked(int adb_port)
+{
+    int i;
+    for (i = 0; i < ADB_LOCAL_TRANSPORT_MAX; i++) {
+        if (local_transports[i] && local_transports[i]->adb_port == adb_port) {
+            return local_transports[i];
+        }
+    }
+    return NULL;
+}
+
+atransport* find_emulator_transport_by_adb_port(int adb_port)
+{
+    adb_mutex_lock( &local_transports_lock );
+    atransport* result = find_emulator_transport_by_adb_port_locked(adb_port);
+    adb_mutex_unlock( &local_transports_lock );
+    return result;
+}
+
+/* Only call this function if you already hold local_transports_lock. */
+int get_available_local_transport_index_locked()
+{
+    int i;
+    for (i = 0; i < ADB_LOCAL_TRANSPORT_MAX; i++) {
+        if (local_transports[i] == NULL) {
+            return i;
+        }
+    }
+    return -1;
+}
+
+int get_available_local_transport_index()
+{
+    adb_mutex_lock( &local_transports_lock );
+    int result = get_available_local_transport_index_locked();
+    adb_mutex_unlock( &local_transports_lock );
+    return result;
+}
+#endif
+
+int init_socket_transport(atransport *t, int s, int adb_port, int local)
 {
     int  fail = 0;
 
@@ -239,26 +286,30 @@
     t->sync_token = 1;
     t->connection_state = CS_OFFLINE;
     t->type = kTransportLocal;
+    t->adb_port = 0;
 
 #if ADB_HOST
     if (HOST && local) {
         adb_mutex_lock( &local_transports_lock );
         {
-            int  index = (port - ADB_LOCAL_TRANSPORT_PORT)/2;
-
-            if (!(port & 1) || index < 0 || index >= ADB_LOCAL_TRANSPORT_MAX) {
-                D("bad local transport port number: %d\n", port);
-                fail = -1;
-            }
-            else if (local_transports[index] != NULL) {
+            t->adb_port = adb_port;
+            atransport* existing_transport =
+                    find_emulator_transport_by_adb_port_locked(adb_port);
+            int index = get_available_local_transport_index_locked();
+            if (existing_transport != NULL) {
                 D("local transport for port %d already registered (%p)?\n",
-                port, local_transports[index]);
+                adb_port, existing_transport);
                 fail = -1;
-            }
-            else
+            } else if (index < 0) {
+                // Too many emulators.
+                D("cannot register more emulators. Maximum is %d\n",
+                        ADB_LOCAL_TRANSPORT_MAX);
+                fail = -1;
+            } else {
                 local_transports[index] = t;
-        }
-        adb_mutex_unlock( &local_transports_lock );
+            }
+       }
+       adb_mutex_unlock( &local_transports_lock );
     }
 #endif
     return fail;
diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c
index 7f3cb54..6d85fb1 100644
--- a/adb/usb_vendors.c
+++ b/adb/usb_vendors.c
@@ -67,6 +67,8 @@
 #define VENDOR_ID_KYOCERA       0x0482
 // Pantech's USB Vendor ID
 #define VENDOR_ID_PANTECH       0x10A9
+// Qualcomm's USB Vendor ID
+#define VENDOR_ID_QUALCOMM      0x05c6
 
 
 /** built-in vendor list */
@@ -87,6 +89,7 @@
     VENDOR_ID_ZTE,
     VENDOR_ID_KYOCERA,
     VENDOR_ID_PANTECH,
+    VENDOR_ID_QUALCOMM,
 };
 
 #define BUILT_IN_VENDOR_COUNT    (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index 474cfac..1dbe171 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -51,6 +51,7 @@
 #define AID_SDCARD_RW     1015  /* external storage write access */
 #define AID_VPN           1016  /* vpn system */
 #define AID_KEYSTORE      1017  /* keystore subsystem */
+#define AID_USB           1018  /* USB devices */
 
 #define AID_SHELL         2000  /* adb and debug shell user */
 #define AID_CACHE         2001  /* cache access */
@@ -100,6 +101,7 @@
     { "sdcard_rw", AID_SDCARD_RW, },
     { "vpn",       AID_VPN, },
     { "keystore",  AID_KEYSTORE, },
+    { "usb",       AID_USB, },
     { "inet",      AID_INET, },
     { "net_raw",   AID_NET_RAW, },
     { "net_admin", AID_NET_ADMIN, },
diff --git a/init/builtins.c b/init/builtins.c
index b4af700..44faf17 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -255,6 +255,7 @@
     const char *name;
     unsigned flag;
 } mount_flags[] = {
+    { "move",       MS_MOVE },
     { "noatime",    MS_NOATIME },
     { "nosuid",     MS_NOSUID },
     { "nodev",      MS_NODEV },
diff --git a/init/devices.c b/init/devices.c
index bde906b..8789b89 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -157,6 +157,7 @@
     { "/dev/ts0710mux",     0640,   AID_RADIO,      AID_RADIO,      1 },
     { "/dev/ppp",           0660,   AID_RADIO,      AID_VPN,        0 },
     { "/dev/tun",           0640,   AID_VPN,        AID_VPN,        0 },
+    { "/dev/bus/usb/",      0660,   AID_ROOT,       AID_USB,        1 },
     { NULL, 0, 0, 0, 0 },
 };
 
@@ -380,6 +381,7 @@
 static void handle_device_event(struct uevent *uevent)
 {
     char devpath[96];
+    int devpath_ready = 0;
     char *base, *name;
     int block;
 
@@ -405,7 +407,26 @@
     } else {
         block = 0;
             /* this should probably be configurable somehow */
-        if(!strncmp(uevent->subsystem, "graphics", 8)) {
+        if (!strncmp(uevent->subsystem, "usb", 3)) {
+            if (!strcmp(uevent->subsystem, "usb")) {
+                /* This imitates the file system that would be created
+                 * if we were using devfs instead.
+                 * Minors are broken up into groups of 128, starting at "001"
+                 */
+                int bus_id = uevent->minor / 128 + 1;
+                int device_id = uevent->minor % 128 + 1;
+                /* build directories */
+                mkdir("/dev/bus", 0755);
+                mkdir("/dev/bus/usb", 0755);
+                snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id);
+                mkdir(devpath, 0755);
+                snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id);
+                devpath_ready = 1;
+            } else {
+                /* ignore other USB events */
+                return;
+            }
+        } else if (!strncmp(uevent->subsystem, "graphics", 8)) {
             base = "/dev/graphics/";
             mkdir(base, 0755);
         } else if (!strncmp(uevent->subsystem, "oncrpc", 6)) {
@@ -435,7 +456,8 @@
             base = "/dev/";
     }
 
-    snprintf(devpath, sizeof(devpath), "%s%s", base, name);
+    if (!devpath_ready)
+        snprintf(devpath, sizeof(devpath), "%s%s", base, name);
 
     if(!strcmp(uevent->action, "add")) {
         make_device(devpath, block, uevent->major, uevent->minor);
diff --git a/liblinenoise/Android.mk b/liblinenoise/Android.mk
new file mode 100644
index 0000000..b32a5f1
--- /dev/null
+++ b/liblinenoise/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# Static library
+# ========================================================
+
+include $(CLEAR_VARS)
+LOCAL_MODULE:= liblinenoise
+LOCAL_SRC_FILES := linenoise.c
+
+
+include $(BUILD_STATIC_LIBRARY)
diff --git a/liblinenoise/MODULE_LICENSE_BSD_LIKE b/liblinenoise/MODULE_LICENSE_BSD_LIKE
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/liblinenoise/MODULE_LICENSE_BSD_LIKE
diff --git a/liblinenoise/NOTICE b/liblinenoise/NOTICE
new file mode 100644
index 0000000..f61419e
--- /dev/null
+++ b/liblinenoise/NOTICE
@@ -0,0 +1,28 @@
+Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+  * Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+    
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+    
+  * Neither the name of Redis nor the names of its contributors may be used
+    to endorse or promote products derived from this software without
+    specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/liblinenoise/linenoise.c b/liblinenoise/linenoise.c
new file mode 100644
index 0000000..ab57ae6
--- /dev/null
+++ b/liblinenoise/linenoise.c
@@ -0,0 +1,435 @@
+/* linenoise.c -- guerrilla line editing library against the idea that a
+ * line editing lib needs to be 20,000 lines of C code.
+ *
+ * You can find the latest source code at:
+ * 
+ *   http://github.com/antirez/linenoise
+ *
+ * Does a number of crazy assumptions that happen to be true in 99.9999% of
+ * the 2010 UNIX computers around.
+ *
+ * Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   * Redistributions of source code must retain the above copyright notice,
+ *     this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of Redis nor the names of its contributors may be used
+ *     to endorse or promote products derived from this software without
+ *     specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * References:
+ * - http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
+ * - http://www.3waylabs.com/nw/WWW/products/wizcon/vt220.html
+ *
+ * Todo list:
+ * - Switch to gets() if $TERM is something we can't support.
+ * - Filter bogus Ctrl+<char> combinations.
+ * - Win32 support
+ *
+ * Bloat:
+ * - Completion?
+ * - History search like Ctrl+r in readline?
+ *
+ * List of escape sequences used by this program, we do everything just
+ * with three sequences. In order to be so cheap we may have some
+ * flickering effect with some slow terminal, but the lesser sequences
+ * the more compatible.
+ *
+ * CHA (Cursor Horizontal Absolute)
+ *    Sequence: ESC [ n G
+ *    Effect: moves cursor to column n
+ *
+ * EL (Erase Line)
+ *    Sequence: ESC [ n K
+ *    Effect: if n is 0 or missing, clear from cursor to end of line
+ *    Effect: if n is 1, clear from beginning of line to cursor
+ *    Effect: if n is 2, clear entire line
+ *
+ * CUF (CUrsor Forward)
+ *    Sequence: ESC [ n C
+ *    Effect: moves cursor forward of n chars
+ * 
+ */
+
+#include <termios.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#define LINENOISE_MAX_LINE 4096
+static char *unsupported_term[] = {"dumb","cons25",NULL};
+
+static struct termios orig_termios; /* in order to restore at exit */
+static int rawmode = 0; /* for atexit() function to check if restore is needed*/
+static int atexit_registered = 0; /* register atexit just 1 time */
+static int history_max_len = 100;
+static int history_len = 0;
+char **history = NULL;
+
+static void linenoiseAtExit(void);
+int linenoiseHistoryAdd(const char *line);
+
+static int isUnsupportedTerm(void) {
+    char *term = getenv("TERM");
+    int j;
+
+    if (term == NULL) return 0;
+    for (j = 0; unsupported_term[j]; j++)
+        if (!strcasecmp(term,unsupported_term[j])) return 1;
+    return 0;
+}
+
+static void freeHistory(void) {
+    if (history) {
+        int j;
+
+        for (j = 0; j < history_len; j++)
+            free(history[j]);
+        free(history);
+    }
+}
+
+static int enableRawMode(int fd) {
+    struct termios raw;
+
+    if (!isatty(STDIN_FILENO)) goto fatal;
+    if (!atexit_registered) {
+        atexit(linenoiseAtExit);
+        atexit_registered = 1;
+    }
+    if (tcgetattr(fd,&orig_termios) == -1) goto fatal;
+
+    raw = orig_termios;  /* modify the original mode */
+    /* input modes: no break, no CR to NL, no parity check, no strip char,
+     * no start/stop output control. */
+    raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+    /* output modes - disable post processing */
+    raw.c_oflag &= ~(OPOST);
+    /* control modes - set 8 bit chars */
+    raw.c_cflag |= (CS8);
+    /* local modes - choing off, canonical off, no extended functions,
+     * no signal chars (^Z,^C) */
+    raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
+    /* control chars - set return condition: min number of bytes and timer.
+     * We want read to return every single byte, without timeout. */
+    raw.c_cc[VMIN] = 1; raw.c_cc[VTIME] = 0; /* 1 byte, no timer */
+
+    /* put terminal in raw mode after flushing */
+    if (tcsetattr(fd,TCSAFLUSH,&raw) < 0) goto fatal;
+    rawmode = 1;
+    return 0;
+
+fatal:
+    errno = ENOTTY;
+    return -1;
+}
+
+static void disableRawMode(int fd) {
+    /* Don't even check the return value as it's too late. */
+    if (rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1)
+        rawmode = 0;
+}
+
+/* At exit we'll try to fix the terminal to the initial conditions. */
+static void linenoiseAtExit(void) {
+    disableRawMode(STDIN_FILENO);
+    freeHistory();
+}
+
+static int getColumns(void) {
+    struct winsize ws;
+
+    if (ioctl(1, TIOCGWINSZ, &ws) == -1) return 80;
+    if (ws.ws_col == 0) {
+        return 80;
+    }
+    return ws.ws_col;
+}
+
+static void refreshLine(int fd, const char *prompt, char *buf, size_t len, size_t pos, size_t cols) {
+    char seq[64];
+    size_t plen = strlen(prompt);
+    
+    while((plen+pos) >= cols) {
+        buf++;
+        len--;
+        pos--;
+    }
+    while (plen+len > cols) {
+        len--;
+    }
+
+    /* Cursor to left edge */
+    snprintf(seq,64,"\x1b[0G");
+    if (write(fd,seq,strlen(seq)) == -1) return;
+    /* Write the prompt and the current buffer content */
+    if (write(fd,prompt,strlen(prompt)) == -1) return;
+    if (write(fd,buf,len) == -1) return;
+    /* Erase to right */
+    snprintf(seq,64,"\x1b[0K");
+    if (write(fd,seq,strlen(seq)) == -1) return;
+    /* Move cursor to original position. */
+    snprintf(seq,64,"\x1b[0G\x1b[%dC", (int)(pos+plen));
+    if (write(fd,seq,strlen(seq)) == -1) return;
+}
+
+static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt) {
+    size_t plen = strlen(prompt);
+    size_t pos = 0;
+    size_t len = 0;
+    size_t cols = getColumns();
+    int history_index = 0;
+
+    buf[0] = '\0';
+    buflen--; /* Make sure there is always space for the nulterm */
+
+    /* The latest history entry is always our current buffer, that
+     * initially is just an empty string. */
+    linenoiseHistoryAdd("");
+    
+    if (write(fd,prompt,plen) == -1) return -1;
+    while(1) {
+        char c;
+        int nread;
+        char seq[2];
+
+        nread = read(fd,&c,1);
+        if (nread <= 0) return len;
+        switch(c) {
+        case 10:    /* line feed. */
+        case 13:    /* enter */
+            history_len--;
+            return len;
+        case 4:     /* ctrl-d */
+            history_len--;
+            return (len == 0) ? -1 : (int)len;
+        case 3:     /* ctrl-c */
+            errno = EAGAIN;
+            return -1;
+        case 127:   /* backspace */
+        case 8:     /* ctrl-h */
+            if (pos > 0 && len > 0) {
+                memmove(buf+pos-1,buf+pos,len-pos);
+                pos--;
+                len--;
+                buf[len] = '\0';
+                refreshLine(fd,prompt,buf,len,pos,cols);
+            }
+            break;
+        case 20:    /* ctrl-t */
+            if (pos > 0 && pos < len) {
+                int aux = buf[pos-1];
+                buf[pos-1] = buf[pos];
+                buf[pos] = aux;
+                if (pos != len-1) pos++;
+                refreshLine(fd,prompt,buf,len,pos,cols);
+            }
+            break;
+        case 2:     /* ctrl-b */
+            goto left_arrow;
+        case 6:     /* ctrl-f */
+            goto right_arrow;
+        case 16:    /* ctrl-p */
+            seq[1] = 65;
+            goto up_down_arrow;
+        case 14:    /* ctrl-n */
+            seq[1] = 66;
+            goto up_down_arrow;
+            break;
+        case 27:    /* escape sequence */
+            if (read(fd,seq,2) == -1) break;
+            if (seq[0] == 91 && seq[1] == 68) {
+left_arrow:
+                /* left arrow */
+                if (pos > 0) {
+                    pos--;
+                    refreshLine(fd,prompt,buf,len,pos,cols);
+                }
+            } else if (seq[0] == 91 && seq[1] == 67) {
+right_arrow:
+                /* right arrow */
+                if (pos != len) {
+                    pos++;
+                    refreshLine(fd,prompt,buf,len,pos,cols);
+                }
+            } else if (seq[0] == 91 && (seq[1] == 65 || seq[1] == 66)) {
+up_down_arrow:
+                /* up and down arrow: history */
+                if (history_len > 1) {
+                    /* Update the current history entry before to
+                     * overwrite it with tne next one. */
+                    free(history[history_len-1-history_index]);
+                    history[history_len-1-history_index] = strdup(buf);
+                    /* Show the new entry */
+                    history_index += (seq[1] == 65) ? 1 : -1;
+                    if (history_index < 0) {
+                        history_index = 0;
+                        break;
+                    } else if (history_index >= history_len) {
+                        history_index = history_len-1;
+                        break;
+                    }
+                    strncpy(buf,history[history_len-1-history_index],buflen);
+                    buf[buflen] = '\0';
+                    len = pos = strlen(buf);
+                    refreshLine(fd,prompt,buf,len,pos,cols);
+                }
+            }
+            break;
+        default:
+            if (len < buflen) {
+                if (len == pos) {
+                    buf[pos] = c;
+                    pos++;
+                    len++;
+                    buf[len] = '\0';
+                    if (plen+len < cols) {
+                        /* Avoid a full update of the line in the
+                         * trivial case. */
+                        if (write(fd,&c,1) == -1) return -1;
+                    } else {
+                        refreshLine(fd,prompt,buf,len,pos,cols);
+                    }
+                } else {
+                    memmove(buf+pos+1,buf+pos,len-pos);
+                    buf[pos] = c;
+                    len++;
+                    pos++;
+                    buf[len] = '\0';
+                    refreshLine(fd,prompt,buf,len,pos,cols);
+                }
+            }
+            break;
+        case 21: /* Ctrl+u, delete the whole line. */
+            buf[0] = '\0';
+            pos = len = 0;
+            refreshLine(fd,prompt,buf,len,pos,cols);
+            break;
+        case 11: /* Ctrl+k, delete from current to end of line. */
+            buf[pos] = '\0';
+            len = pos;
+            refreshLine(fd,prompt,buf,len,pos,cols);
+            break;
+        case 1: /* Ctrl+a, go to the start of the line */
+            pos = 0;
+            refreshLine(fd,prompt,buf,len,pos,cols);
+            break;
+        case 5: /* ctrl+e, go to the end of the line */
+            pos = len;
+            refreshLine(fd,prompt,buf,len,pos,cols);
+            break;
+        }
+    }
+    return len;
+}
+
+static int linenoiseRaw(char *buf, size_t buflen, const char *prompt) {
+    int fd = STDIN_FILENO;
+    int count;
+
+    if (buflen == 0) {
+        errno = EINVAL;
+        return -1;
+    }
+    if (!isatty(STDIN_FILENO)) {
+        if (fgets(buf, buflen, stdin) == NULL) return -1;
+        count = strlen(buf);
+        if (count && buf[count-1] == '\n') {
+            count--;
+            buf[count] = '\0';
+        }
+    } else {
+        if (enableRawMode(fd) == -1) return -1;
+        count = linenoisePrompt(fd, buf, buflen, prompt);        
+        disableRawMode(fd);
+    }
+    return count;
+}
+
+char *linenoise(const char *prompt) {
+    char buf[LINENOISE_MAX_LINE];
+    int count;
+
+    if (isUnsupportedTerm()) {
+        size_t len;
+
+        printf("%s",prompt);
+        fflush(stdout);
+        if (fgets(buf,LINENOISE_MAX_LINE,stdin) == NULL) return NULL;
+        len = strlen(buf);
+        while(len && (buf[len-1] == '\n' || buf[len-1] == '\r')) {
+            len--;
+            buf[len] = '\0';
+        }
+        return strdup(buf);
+    } else {
+        count = linenoiseRaw(buf,LINENOISE_MAX_LINE,prompt);
+        if (count == -1) return NULL;
+        return strdup(buf);
+    }
+}
+
+/* Using a circular buffer is smarter, but a bit more complex to handle. */
+int linenoiseHistoryAdd(const char *line) {
+    char *linecopy;
+
+    if (history_max_len == 0) return 0;
+    if (history == 0) {
+        history = malloc(sizeof(char*)*history_max_len);
+        if (history == NULL) return 0;
+        memset(history,0,(sizeof(char*)*history_max_len));
+    }
+    linecopy = strdup(line);
+    if (!linecopy) return 0;
+    if (history_len == history_max_len) {
+        memmove(history,history+1,sizeof(char*)*(history_max_len-1));
+        history_len--;
+    }
+    history[history_len] = linecopy;
+    history_len++;
+    return 1;
+}
+
+int linenoiseHistorySetMaxLen(int len) {
+    char **new;
+
+    if (len < 1) return 0;
+    if (history) {
+        int tocopy = history_len;
+
+        new = malloc(sizeof(char*)*len);
+        if (new == NULL) return 0;
+        if (len < tocopy) tocopy = len;
+        memcpy(new,history+(history_max_len-tocopy), sizeof(char*)*tocopy);
+        free(history);
+        history = new;
+    }
+    history_max_len = len;
+    if (history_len > history_max_len)
+        history_len = history_max_len;
+    return 1;
+}
diff --git a/liblinenoise/linenoise.h b/liblinenoise/linenoise.h
new file mode 100644
index 0000000..57bf9d1
--- /dev/null
+++ b/liblinenoise/linenoise.h
@@ -0,0 +1,41 @@
+/* linenoise.h -- guerrilla line editing library against the idea that a
+ * line editing lib needs to be 20,000 lines of C code.
+ *
+ * See linenoise.c for more information.
+ *
+ * Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   * Redistributions of source code must retain the above copyright notice,
+ *     this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of Redis nor the names of its contributors may be used
+ *     to endorse or promote products derived from this software without
+ *     specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __LINENOISE_H
+#define __LINENOISE_H
+
+char *linenoise(const char *prompt);
+int linenoiseHistoryAdd(const char *line);
+int linenoiseHistorySetMaxLen(int len);
+
+#endif /* __LINENOISE_H */
diff --git a/libpixelflinger/Android.mk b/libpixelflinger/Android.mk
index 0cc85d9..6491d24 100644
--- a/libpixelflinger/Android.mk
+++ b/libpixelflinger/Android.mk
@@ -40,7 +40,13 @@
 	buffer.cpp
 
 ifeq ($(TARGET_ARCH),arm)
+ifeq ($(TARGET_ARCH_VERSION),armv7-a)
+PIXELFLINGER_SRC_FILES += col32cb16blend_neon.S
+PIXELFLINGER_SRC_FILES += col32cb16blend.S
+else
 PIXELFLINGER_SRC_FILES += t32cb16blend.S
+PIXELFLINGER_SRC_FILES += col32cb16blend.S
+endif
 endif
 
 ifeq ($(TARGET_ARCH),arm)
diff --git a/libpixelflinger/codeflinger/ARMAssembler.cpp b/libpixelflinger/codeflinger/ARMAssembler.cpp
index ff7b0b3..d3720c3 100644
--- a/libpixelflinger/codeflinger/ARMAssembler.cpp
+++ b/libpixelflinger/codeflinger/ARMAssembler.cpp
@@ -424,5 +424,15 @@
     *mPC++ = (cc<<28) | 0x1200080 | (Rd<<16) | (Rn<<12) | (Rs<<8) | (y<<4) | Rm;
 }
 
+#if 0
+#pragma mark -
+#pragma mark Byte/half word extract and extend (ARMv6+ only)...
+#endif
+
+void ARMAssembler::UXTB16(int cc, int Rd, int Rm, int rotate)
+{
+    *mPC++ = (cc<<28) | 0x6CF0070 | (Rd<<12) | ((rotate >> 3) << 10) | Rm;
+}
+
 }; // namespace android
 
diff --git a/libpixelflinger/codeflinger/ARMAssembler.h b/libpixelflinger/codeflinger/ARMAssembler.h
index ef3b66a..a667cb5 100644
--- a/libpixelflinger/codeflinger/ARMAssembler.h
+++ b/libpixelflinger/codeflinger/ARMAssembler.h
@@ -123,6 +123,7 @@
                 int RdHi, int RdLo, int Rs, int Rm);
     virtual void SMLAW(int cc, int y,
                 int Rd, int Rm, int Rs, int Rn);
+    virtual void UXTB16(int cc, int Rd, int Rm, int rotate);
 
 private:
                 ARMAssembler(const ARMAssembler& rhs);
diff --git a/libpixelflinger/codeflinger/ARMAssemblerInterface.h b/libpixelflinger/codeflinger/ARMAssemblerInterface.h
index 465b3bd..ff6af2a 100644
--- a/libpixelflinger/codeflinger/ARMAssemblerInterface.h
+++ b/libpixelflinger/codeflinger/ARMAssemblerInterface.h
@@ -203,6 +203,9 @@
     virtual void SMLAW(int cc, int y,
                 int Rd, int Rm, int Rs, int Rn) = 0;
 
+    // byte/half word extract...
+    virtual void UXTB16(int cc, int Rd, int Rm, int rotate) = 0;
+
     // -----------------------------------------------------------------------
     // convenience...
     // -----------------------------------------------------------------------
diff --git a/libpixelflinger/codeflinger/ARMAssemblerProxy.cpp b/libpixelflinger/codeflinger/ARMAssemblerProxy.cpp
index 18c4618..7c422db 100644
--- a/libpixelflinger/codeflinger/ARMAssemblerProxy.cpp
+++ b/libpixelflinger/codeflinger/ARMAssemblerProxy.cpp
@@ -195,6 +195,9 @@
     mTarget->SMLAW(cc, y, Rd, Rm, Rs, Rn);
 }
 
+void ARMAssemblerProxy::UXTB16(int cc, int Rd, int Rm, int rotate) {
+    mTarget->UXTB16(cc, Rd, Rm, rotate);
+}
 
 }; // namespace android
 
diff --git a/libpixelflinger/codeflinger/ARMAssemblerProxy.h b/libpixelflinger/codeflinger/ARMAssemblerProxy.h
index 4bdca9c..9134cce 100644
--- a/libpixelflinger/codeflinger/ARMAssemblerProxy.h
+++ b/libpixelflinger/codeflinger/ARMAssemblerProxy.h
@@ -114,6 +114,8 @@
     virtual void SMLAW(int cc, int y,
                 int Rd, int Rm, int Rs, int Rn);
 
+    virtual void UXTB16(int cc, int Rd, int Rm, int rotate);
+
 private:
     ARMAssemblerInterface*  mTarget;
 };
diff --git a/libpixelflinger/codeflinger/disassem.c b/libpixelflinger/codeflinger/disassem.c
index 4676da0..c17f3ec 100644
--- a/libpixelflinger/codeflinger/disassem.c
+++ b/libpixelflinger/codeflinger/disassem.c
@@ -80,6 +80,7 @@
  * f - 1st fp operand (register) (bits 12-14)
  * g - 2nd fp operand (register) (bits 16-18)
  * h - 3rd fp operand (register/immediate) (bits 0-4)
+ * j - xtb rotate literal (bits 10-11)
  * b - branch address
  * t - thumb branch address (bits 24, 0-23)
  * k - breakpoint comment (bits 0-3, 8-19)
@@ -122,6 +123,7 @@
     { 0x0fe000f0, 0x00c00090, "smull",	"Sdnms" },
     { 0x0fe000f0, 0x00a00090, "umlal",	"Sdnms" },
     { 0x0fe000f0, 0x00e00090, "smlal",	"Sdnms" },
+    { 0x0fff03f0, 0x06cf0070, "uxtb16", "dmj" },
     { 0x0d700000, 0x04200000, "strt",	"daW" },
     { 0x0d700000, 0x04300000, "ldrt",	"daW" },
     { 0x0d700000, 0x04600000, "strbt",	"daW" },
@@ -276,7 +278,7 @@
 
 #define insn_condition(x)	arm32_insn_conditions[(x >> 28) & 0x0f]
 #define insn_blktrans(x)	insn_block_transfers[(x >> 23) & 3]
-#define insn_stkblktrans(x)	insn_stack_block_transfers[(x >> 23) & 3]
+#define insn_stkblktrans(x)	insn_stack_block_transfers[(3*((x >> 20)&1))^((x >> 23)&3)]
 #define op2_shift(x)		op_shifts[(x >> 5) & 3]
 #define insn_fparnd(x)		insn_fpa_rounding[(x >> 5) & 0x03]
 #define insn_fpaprec(x)		insn_fpa_precision[(((x >> 18) & 2)|(x >> 7)) & 1]
@@ -406,6 +408,10 @@
 			else
 				di->di_printf("f%d", insn & 7);
 			break;
+		/* j - xtb rotate literal (bits 10-11) */
+		case 'j':
+			di->di_printf("ror #%d", ((insn >> 10) & 3) << 3);
+			break;
 		/* b - branch address */
 		case 'b':
 			branch = ((insn << 2) & 0x03ffffff);
diff --git a/libpixelflinger/codeflinger/texturing.cpp b/libpixelflinger/codeflinger/texturing.cpp
index 90e6584..7f6f8da 100644
--- a/libpixelflinger/codeflinger/texturing.cpp
+++ b/libpixelflinger/codeflinger/texturing.cpp
@@ -25,6 +25,9 @@
 
 #include "codeflinger/GGLAssembler.h"
 
+#ifdef __ARM_ARCH__
+#include <machine/cpu-features.h>
+#endif
 
 namespace android {
 
@@ -567,7 +570,7 @@
                     RSB(GE, 0, height, height, imm(0));
                     MUL(AL, 0, height, stride, height);
                 } else {
-                    // u has not been CLAMPed yet
+                    // v has not been CLAMPed yet
                     CMP(AL, height, reg_imm(v, ASR, FRAC_BITS));
                     MOV(LE, 0, v, reg_imm(height, LSL, FRAC_BITS));
                     MOV(LE, 0, height, imm(0));
@@ -868,6 +871,106 @@
     load(txPtr, texel, 0);
 }
 
+#if __ARM_ARCH__ >= 6
+// ARMv6 version, using UXTB16, and scheduled for Cortex-A8 pipeline
+void GGLAssembler::filter32(
+        const fragment_parts_t& parts,
+        pixel_t& texel, const texture_unit_t& tmu,
+        int U, int V, pointer_t& txPtr,
+        int FRAC_BITS)
+{
+    const int adjust = FRAC_BITS*2 - 8;
+    const int round  = 0;
+    const int prescale = 16 - adjust;
+
+    Scratch scratches(registerFile());
+    
+    int pixel= scratches.obtain();
+    int dh   = scratches.obtain();
+    int u    = scratches.obtain();
+    int k    = scratches.obtain();
+
+    int temp = scratches.obtain();
+    int dl   = scratches.obtain();
+
+    int offsetrt = scratches.obtain();
+    int offsetlb = scratches.obtain();
+
+    int pixellb = offsetlb;
+
+    // RB -> U * V
+    CONTEXT_LOAD(offsetrt, generated_vars.rt);
+    CONTEXT_LOAD(offsetlb, generated_vars.lb);
+    if(!round) {
+        MOV(AL, 0, U, reg_imm(U, LSL, prescale));
+    }
+    ADD(AL, 0, u, offsetrt, offsetlb);
+
+    LDR(AL, pixel, txPtr.reg, reg_scale_pre(u));
+    if (round) {
+        SMULBB(AL, u, U, V);
+        RSB(AL, 0, U, U, imm(1<<FRAC_BITS));
+    } else {
+        SMULWB(AL, u, U, V);
+        RSB(AL, 0, U, U, imm(1<<(FRAC_BITS+prescale)));
+    }
+    UXTB16(AL, temp, pixel, 0);
+    if (round) {
+        ADD(AL, 0, u, u, imm(1<<(adjust-1)));
+        MOV(AL, 0, u, reg_imm(u, LSR, adjust));
+    }
+    LDR(AL, pixellb, txPtr.reg, reg_scale_pre(offsetlb));
+    MUL(AL, 0, dh, temp, u);
+    UXTB16(AL, temp, pixel, 8);
+    MUL(AL, 0, dl, temp, u);
+    RSB(AL, 0, k, u, imm(0x100));
+
+    // LB -> (1-U) * V
+    if (round) {
+        SMULBB(AL, u, U, V);
+    } else {
+        SMULWB(AL, u, U, V);
+    }
+    UXTB16(AL, temp, pixellb, 0);
+    if (round) {
+        ADD(AL, 0, u, u, imm(1<<(adjust-1)));
+        MOV(AL, 0, u, reg_imm(u, LSR, adjust));
+    }
+    MLA(AL, 0, dh, temp, u, dh);    
+    UXTB16(AL, temp, pixellb, 8);
+    MLA(AL, 0, dl, temp, u, dl);
+    SUB(AL, 0, k, k, u);
+
+    // LT -> (1-U)*(1-V)
+    RSB(AL, 0, V, V, imm(1<<FRAC_BITS));
+    LDR(AL, pixel, txPtr.reg);
+    if (round) {
+        SMULBB(AL, u, U, V);
+    } else {
+        SMULWB(AL, u, U, V);
+    }
+    UXTB16(AL, temp, pixel, 0);
+    if (round) {
+        ADD(AL, 0, u, u, imm(1<<(adjust-1)));
+        MOV(AL, 0, u, reg_imm(u, LSR, adjust));
+    }
+    MLA(AL, 0, dh, temp, u, dh);    
+    UXTB16(AL, temp, pixel, 8);
+    MLA(AL, 0, dl, temp, u, dl);
+
+    // RT -> U*(1-V)            
+    LDR(AL, pixel, txPtr.reg, reg_scale_pre(offsetrt));
+    SUB(AL, 0, u, k, u);
+    UXTB16(AL, temp, pixel, 0);
+    MLA(AL, 0, dh, temp, u, dh);    
+    UXTB16(AL, temp, pixel, 8);
+    MLA(AL, 0, dl, temp, u, dl);
+
+    UXTB16(AL, dh, dh, 8);
+    UXTB16(AL, dl, dl, 8);
+    ORR(AL, 0, texel.reg, dh, reg_imm(dl, LSL, 8));
+}
+#else
 void GGLAssembler::filter32(
         const fragment_parts_t& parts,
         pixel_t& texel, const texture_unit_t& tmu,
@@ -955,6 +1058,7 @@
     AND(AL, 0, dl, dl, reg_imm(mask, LSL, 8));
     ORR(AL, 0, texel.reg, dh, dl);
 }
+#endif
 
 void GGLAssembler::build_texture_environment(
         component_t& fragment,
diff --git a/libpixelflinger/col32cb16blend.S b/libpixelflinger/col32cb16blend.S
new file mode 100644
index 0000000..1450bde
--- /dev/null
+++ b/libpixelflinger/col32cb16blend.S
@@ -0,0 +1,78 @@
+/* libs/pixelflinger/col32cb16blend.S
+**
+** (C) COPYRIGHT 2009 ARM Limited.
+**
+** Licensed under the Apache License, Version 2.0 (the "License"); 
+** you may not use this file except in compliance with the License. 
+** You may obtain a copy of the License at 
+**
+**     http://www.apache.org/licenses/LICENSE-2.0 
+**
+** Unless required by applicable law or agreed to in writing, software 
+** distributed under the License is distributed on an "AS IS" BASIS, 
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+** See the License for the specific language governing permissions and 
+** limitations under the License.
+**
+*/
+
+    .text
+    .align
+
+    .global scanline_col32cb16blend_arm
+
+//
+// This function alpha blends a fixed color into a destination scanline, using
+// the formula:
+//
+//     d = s + (((a + (a >> 7)) * d) >> 8)
+//
+// where d is the destination pixel,
+//       s is the source color,
+//       a is the alpha channel of the source color.
+//
+
+// r0 = destination buffer pointer
+// r1 = color value
+// r2 = count
+
+
+scanline_col32cb16blend_arm:
+    push        {r4-r10, lr}                    // stack ARM regs
+
+    mov         r5, r1, lsr #24                 // shift down alpha
+    mov         r9, #0xff                       // create mask
+    add         r5, r5, r5, lsr #7              // add in top bit
+    rsb         r5, r5, #256                    // invert alpha
+    and         r10, r1, #0xff                  // extract red
+    and         r12, r9, r1, lsr #8             // extract green
+    and         r4, r9, r1, lsr #16             // extract blue
+    mov         r10, r10, lsl #5                // prescale red
+    mov         r12, r12, lsl #6                // prescale green
+    mov         r4, r4, lsl #5                  // prescale blue
+    mov         r9, r9, lsr #2                  // create dest green mask
+
+1:
+    ldrh        r8, [r0]                        // load dest pixel
+    subs        r2, r2, #1                      // decrement loop counter
+    mov         r6, r8, lsr #11                 // extract dest red
+    and         r7, r9, r8, lsr #5              // extract dest green
+    and         r8, r8, #0x1f                   // extract dest blue
+
+    smlabb      r6, r6, r5, r10                 // dest red * alpha + src red
+    smlabb      r7, r7, r5, r12                 // dest green * alpha + src green
+    smlabb      r8, r8, r5, r4                  // dest blue * alpha + src blue
+
+    mov         r6, r6, lsr #8                  // shift down red
+    mov         r7, r7, lsr #8                  // shift down green
+    mov         r6, r6, lsl #11                 // shift red into 565
+    orr         r6, r7, lsl #5                  // shift green into 565
+    orr         r6, r8, lsr #8                  // shift blue into 565
+
+    strh        r6, [r0], #2                    // store pixel to dest, update ptr
+    bne         1b                              // if count != 0, loop
+
+    pop         {r4-r10, pc}                    // return
+
+
+
diff --git a/libpixelflinger/col32cb16blend_neon.S b/libpixelflinger/col32cb16blend_neon.S
new file mode 100644
index 0000000..17b0d01
--- /dev/null
+++ b/libpixelflinger/col32cb16blend_neon.S
@@ -0,0 +1,153 @@
+/* libs/pixelflinger/col32cb16blend_neon.S
+**
+** (C) COPYRIGHT 2009 ARM Limited.
+**
+** Licensed under the Apache License, Version 2.0 (the "License"); 
+** you may not use this file except in compliance with the License. 
+** You may obtain a copy of the License at 
+**
+**     http://www.apache.org/licenses/LICENSE-2.0 
+**
+** Unless required by applicable law or agreed to in writing, software 
+** distributed under the License is distributed on an "AS IS" BASIS, 
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+** See the License for the specific language governing permissions and 
+** limitations under the License.
+**
+*/
+
+    .text
+    .align
+
+    .global scanline_col32cb16blend_neon
+
+//
+// This function alpha blends a fixed color into a destination scanline, using
+// the formula:
+//
+//     d = s + (((a + (a >> 7)) * d) >> 8)
+//
+// where d is the destination pixel,
+//       s is the source color,
+//       a is the alpha channel of the source color.
+//
+// The NEON implementation processes 16 pixels per iteration. The remaining 0 - 15
+// pixels are processed in ARM code.
+//
+
+// r0 = destination buffer pointer
+// r1 = color pointer
+// r2 = count
+
+
+scanline_col32cb16blend_neon:
+    push        {r4-r11, lr}                    // stack ARM regs
+
+    vmov.u16    q15, #256                       // create alpha constant
+    movs        r3, r2, lsr #4                  // calc. sixteens iterations
+    vmov.u16    q14, #0x1f                      // create blue mask
+
+    beq         2f                              // if r3 == 0, branch to singles
+
+    vld4.8      {d0[], d2[], d4[], d6[]}, [r1]  // load color into four registers
+                                                //  split and duplicate them, such that
+                                                //  d0 = 8 equal red values
+                                                //  d2 = 8 equal green values
+                                                //  d4 = 8 equal blue values
+                                                //  d6 = 8 equal alpha values
+    vshll.u8    q0, d0, #5                      // shift up red and widen
+    vshll.u8    q1, d2, #6                      // shift up green and widen
+    vshll.u8    q2, d4, #5                      // shift up blue and widen
+
+    vshr.u8     d7, d6, #7                      // extract top bit of alpha
+    vaddl.u8    q3, d6, d7                      // add top bit into alpha
+    vsub.u16    q3, q15, q3                     // invert alpha
+
+1:
+    // This loop processes 16 pixels per iteration. In the comments, references to
+    // the first eight pixels are suffixed with "0" (red0, green0, blue0), 
+    // the second eight are suffixed "1".
+                                                // q8  = dst red0
+                                                // q9  = dst green0
+                                                // q10 = dst blue0
+                                                // q13 = dst red1
+                                                // q12 = dst green1
+                                                // q11 = dst blue1
+
+    vld1.16     {d20, d21, d22, d23}, [r0]      // load 16 dest pixels
+    vshr.u16    q8, q10, #11                    // shift dst red0 to low 5 bits
+    pld         [r0, #63]                       // preload next dest pixels
+    vshl.u16    q9, q10, #5                     // shift dst green0 to top 6 bits
+    vand        q10, q10, q14                   // extract dst blue0
+    vshr.u16    q9, q9, #10                     // shift dst green0 to low 6 bits
+    vmul.u16    q8, q8, q3                      // multiply dst red0 by src alpha
+    vshl.u16    q12, q11, #5                    // shift dst green1 to top 6 bits
+    vmul.u16    q9, q9, q3                      // multiply dst green0 by src alpha
+    vshr.u16    q13, q11, #11                   // shift dst red1 to low 5 bits
+    vmul.u16    q10, q10, q3                    // multiply dst blue0 by src alpha
+    vshr.u16    q12, q12, #10                   // shift dst green1 to low 6 bits
+    vand        q11, q11, q14                   // extract dst blue1
+    vadd.u16    q8, q8, q0                      // add src red to dst red0
+    vmul.u16    q13, q13, q3                    // multiply dst red1 by src alpha
+    vadd.u16    q9, q9, q1                      // add src green to dst green0 
+    vmul.u16    q12, q12, q3                    // multiply dst green1 by src alpha
+    vadd.u16    q10, q10, q2                    // add src blue to dst blue0
+    vmul.u16    q11, q11, q3                    // multiply dst blue1 by src alpha
+    vshr.u16    q8, q8, #8                      // shift down red0
+    vadd.u16    q13, q13, q0                    // add src red to dst red1
+    vshr.u16    q9, q9, #8                      // shift down green0
+    vadd.u16    q12, q12, q1                    // add src green to dst green1
+    vshr.u16    q10, q10, #8                    // shift down blue0
+    vadd.u16    q11, q11, q2                    // add src blue to dst blue1
+    vsli.u16    q10, q9, #5                     // shift & insert green0 into blue0
+    vshr.u16    q13, q13, #8                    // shift down red1
+    vsli.u16    q10, q8, #11                    // shift & insert red0 into blue0    
+    vshr.u16    q12, q12, #8                    // shift down green1
+    vshr.u16    q11, q11, #8                    // shift down blue1
+    subs        r3, r3, #1                      // decrement loop counter
+    vsli.u16    q11, q12, #5                    // shift & insert green1 into blue1
+    vsli.u16    q11, q13, #11                   // shift & insert red1 into blue1
+
+    vst1.16     {d20, d21, d22, d23}, [r0]!     // write 16 pixels back to dst
+    bne         1b                              // if count != 0, loop
+
+2:
+    ands        r3, r2, #15                     // calc. single iterations 
+    beq         4f                              // if r3 == 0, exit
+
+    ldr         r4, [r1]                        // load source color
+    mov         r5, r4, lsr #24                 // shift down alpha
+    add         r5, r5, r5, lsr #7              // add in top bit
+    rsb         r5, r5, #256                    // invert alpha
+    and         r11, r4, #0xff                  // extract red
+    ubfx        r12, r4, #8, #8                 // extract green
+    ubfx        r4, r4, #16, #8                 // extract blue
+    mov         r11, r11, lsl #5                // prescale red
+    mov         r12, r12, lsl #6                // prescale green
+    mov         r4, r4, lsl #5                  // prescale blue
+
+3:
+    ldrh        r8, [r0]                        // load dest pixel
+    subs        r3, r3, #1                      // decrement loop counter
+    mov         r6, r8, lsr #11                 // extract dest red
+    ubfx        r7, r8, #5, #6                  // extract dest green
+    and         r8, r8, #0x1f                   // extract dest blue
+
+    smlabb      r6, r6, r5, r11                 // dest red * alpha + src red
+    smlabb      r7, r7, r5, r12                 // dest green * alpha + src green
+    smlabb      r8, r8, r5, r4                  // dest blue * alpha + src blue
+
+    mov         r6, r6, lsr #8                  // shift down red
+    mov         r7, r7, lsr #8                  // shift down green
+    mov         r6, r6, lsl #11                 // shift red into 565
+    orr         r6, r7, lsl #5                  // shift green into 565
+    orr         r6, r8, lsr #8                  // shift blue into 565
+
+    strh        r6, [r0], #2                    // store pixel to dest, update ptr
+    bne         3b                              // if count != 0, loop
+4:
+
+    pop         {r4-r11, pc}                    // return
+
+
+
diff --git a/libpixelflinger/scanline.cpp b/libpixelflinger/scanline.cpp
index f700306..a2f43eb 100644
--- a/libpixelflinger/scanline.cpp
+++ b/libpixelflinger/scanline.cpp
@@ -80,6 +80,7 @@
 static void scanline_perspective_single(context_t* c);
 static void scanline_t32cb16blend(context_t* c);
 static void scanline_t32cb16(context_t* c);
+static void scanline_col32cb16blend(context_t* c);
 static void scanline_memcpy(context_t* c);
 static void scanline_memset8(context_t* c);
 static void scanline_memset16(context_t* c);
@@ -93,6 +94,8 @@
 
 extern "C" void scanline_t32cb16blend_arm(uint16_t*, uint32_t*, size_t);
 extern "C" void scanline_t32cb16_arm(uint16_t *dst, uint32_t *src, size_t ct);
+extern "C" void scanline_col32cb16blend_neon(uint16_t *dst, uint32_t *col, size_t ct);
+extern "C" void scanline_col32cb16blend_arm(uint16_t *dst, uint32_t col, size_t ct);
 
 // ----------------------------------------------------------------------------
 
@@ -111,6 +114,9 @@
     { { { 0x03010104, 0x00000077, { 0x00000A01, 0x00000000 } },
         { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
         "565 fb, 8888 tx", scanline_t32cb16, init_y_noop  },  
+    { { { 0x03515104, 0x00000077, { 0x00000000, 0x00000000 } },
+        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0xFFFFFFFF } } },
+        "565 fb, 8888 fixed color", scanline_col32cb16blend, init_y_packed  },  
     { { { 0x00000000, 0x00000000, { 0x00000000, 0x00000000 } },
         { 0x00000000, 0x00000007, { 0x00000000, 0x00000000 } } },
         "(nop) alpha test", scanline_noop, init_y_noop },
@@ -943,6 +949,8 @@
     uint8_t f = c->state.buffers.color.format;
     c->packed = ggl_pack_color(c, f,
             c->shade.r0, c->shade.g0, c->shade.b0, c->shade.a0);
+    c->packed8888 = ggl_pack_color(c, GGL_PIXEL_FORMAT_RGBA_8888,
+            c->shade.r0, c->shade.g0, c->shade.b0, c->shade.a0);
     c->iterators.y = y0;
     c->step_y = step_y__nop;
     // choose the rectangle blitter
@@ -1253,6 +1261,45 @@
 
 // ----------------------------------------------------------------------------
 
+void scanline_col32cb16blend(context_t* c)
+{
+    int32_t x = c->iterators.xl;
+    size_t ct = c->iterators.xr - x;
+    int32_t y = c->iterators.y;
+    surface_t* cb = &(c->state.buffers.color);
+    union {
+        uint16_t* dst;
+        uint32_t* dst32;
+    };
+    dst = reinterpret_cast<uint16_t*>(cb->data) + (x+(cb->stride*y));
+
+#if ((ANDROID_CODEGEN >= ANDROID_CODEGEN_ASM) && defined(__arm__))
+#if defined(__ARM_HAVE_NEON) && BYTE_ORDER == LITTLE_ENDIAN
+    scanline_col32cb16blend_neon(dst, &(c->packed8888), ct);
+#else  // defined(__ARM_HAVE_NEON) && BYTE_ORDER == LITTLE_ENDIAN
+    scanline_col32cb16blend_arm(dst, GGL_RGBA_TO_HOST(c->packed8888), ct);
+#endif // defined(__ARM_HAVE_NEON) && BYTE_ORDER == LITTLE_ENDIAN
+#else
+    uint32_t s = GGL_RGBA_TO_HOST(c->packed8888);
+    int sA = (s>>24);
+    int f = 0x100 - (sA + (sA>>7));
+    while (ct--) {
+        uint16_t d = *dst;
+        int dR = (d>>11)&0x1f;
+        int dG = (d>>5)&0x3f;
+        int dB = (d)&0x1f;
+        int sR = (s >> (   3))&0x1F;
+        int sG = (s >> ( 8+2))&0x3F;
+        int sB = (s >> (16+3))&0x1F;
+        sR += (f*dR)>>8;
+        sG += (f*dG)>>8;
+        sB += (f*dB)>>8;
+        *dst++ = uint16_t((sR<<11)|(sG<<5)|sB);
+    }
+#endif
+
+}
+
 void scanline_t32cb16(context_t* c)
 {
     int32_t x = c->iterators.xl;
diff --git a/logwrapper/logwrapper.c b/logwrapper/logwrapper.c
index f00bfbf..6466795 100644
--- a/logwrapper/logwrapper.c
+++ b/logwrapper/logwrapper.c
@@ -60,7 +60,7 @@
                 buffer[b] = '\0';
             } else if (buffer[b] == '\n') {
                 buffer[b] = '\0';
-                LOG(LOG_INFO, tag, &buffer[a]);
+                LOG(LOG_INFO, tag, "%s", &buffer[a]);
                 a = b + 1;
             }
         }
@@ -68,7 +68,7 @@
         if (a == 0 && b == sizeof(buffer) - 1) {
             // buffer is full, flush
             buffer[b] = '\0';
-            LOG(LOG_INFO, tag, &buffer[a]);
+            LOG(LOG_INFO, tag, "%s", &buffer[a]);
             b = 0;
         } else if (a != b) {
             // Keep left-overs
@@ -84,7 +84,7 @@
     // Flush remaining data
     if (a != b) {
         buffer[b] = '\0';
-        LOG(LOG_INFO, tag, &buffer[a]);
+	LOG(LOG_INFO, tag, "%s", &buffer[a]);
     }
     status = 0xAAAA;
     if (wait(&status) != -1) {  // Wait for child
diff --git a/sh/Android.mk b/sh/Android.mk
index 09bb6ac..b5e5c38 100644
--- a/sh/Android.mk
+++ b/sh/Android.mk
@@ -31,7 +31,11 @@
 
 LOCAL_MODULE:= sh
 
-LOCAL_CFLAGS += -DSHELL
+LOCAL_CFLAGS += -DSHELL -DWITH_LINENOISE
+
+LOCAL_STATIC_LIBRARIES := liblinenoise
+
+LOCAL_C_INCLUDES += system/core/liblinenoise
 
 make_ash_files: PRIVATE_SRC_FILES := $(SRC_FILES)
 make_ash_files: PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
diff --git a/sh/input.c b/sh/input.c
index a81fd7b..9377bd0 100644
--- a/sh/input.c
+++ b/sh/input.c
@@ -64,6 +64,10 @@
 #include "parser.h"
 #include "myhistedit.h"
 
+#ifdef WITH_LINENOISE
+#include "linenoise.h"
+#endif
+
 #define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
 
 MKINIT
@@ -203,6 +207,45 @@
 
 	} else
 #endif
+#ifdef WITH_LINENOISE
+    if (parsefile->fd == 0) {
+        static char *rl_start;
+        static const char *rl_cp;
+        static int el_len;
+
+        if (rl_cp == NULL) {
+            rl_cp = rl_start = linenoise(getprompt(""));
+            if (rl_cp != NULL) {
+                el_len = strlen(rl_start);
+                if (el_len != 0) {
+                    /* Add non-blank lines to history. */
+                    linenoiseHistoryAdd(rl_start);
+                }
+                out2str("\r\n");
+                /* Client expects a newline at end of input, doesn't expect null */
+                rl_start[el_len++] = '\n';
+            }
+        }
+        if (rl_cp == NULL)
+            nr = 0;
+        else {
+            nr = el_len;
+            if (nr > BUFSIZ - 8)
+                nr = BUFSIZ - 8;
+            memcpy(buf, rl_cp, nr);
+            if (nr != el_len) {
+                el_len -= nr;
+                rl_cp += nr;
+            } else {
+                rl_cp = 0;
+                if (rl_start != NULL) {
+                    free(rl_start);
+                    rl_start = NULL;
+                }
+            }
+        }
+    } else
+#endif
 		nr = read(parsefile->fd, buf, BUFSIZ - 8);
 
 
diff --git a/sh/parser.c b/sh/parser.c
index 67de58e..d956375 100644
--- a/sh/parser.c
+++ b/sh/parser.c
@@ -1628,7 +1628,10 @@
 #ifdef WITH_HISTORY
 	if (!el)
 #endif
+#ifdef WITH_LINENOISE
+#else
 		out2str(getprompt(NULL));
+#endif
 }
 
 /*
diff --git a/sh/trap.c b/sh/trap.c
index b3b2db4..7cb5201 100644
--- a/sh/trap.c
+++ b/sh/trap.c
@@ -60,20 +60,6 @@
 #include "mystring.h"
 #include "var.h"
 
-static const char *sys_signame[NSIG] = {
-	"Unused",
-	"HUP",      "INT",    "QUIT",    "ILL",
-	"TRAP",     "ABRT",   "BUS",     "FPE",
-	"KILL",     "USR1",   "SEGV",    "USR2",
-	"PIPE",     "ALRM",   "TERM",
-	"Unknown",
-	"CHLD",
-	"CONT",     "STOP",   "TSTP",    "TTIN",
-	"TTOU",     "URG",    "XCPU",    "XFSZ",
-	"VTALRM",   "PROF",   "WINCH",   "IO",
-	"PWR",      "SYS"
-};
-
 /*
  * Sigmode records the current value of the signal handlers for the various
  * modes.  A value of zero means that the current handler is not known.
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index a6114ac..05b2a34 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -50,6 +50,7 @@
 	top \
 	iftop \
 	id \
+	uptime \
 	vmstat \
 	nandread \
         ionice
diff --git a/toolbox/route.c b/toolbox/route.c
index 4f66201..107e48a 100644
--- a/toolbox/route.c
+++ b/toolbox/route.c
@@ -61,7 +61,7 @@
         if (!strcmp(argv[2], "default")) {
             /* route add default dev wlan0 */
             if (argc > 4 && !strcmp(argv[3], "dev")) {
-                rt.rt_flags = RTF_UP | RTF_HOST;
+                rt.rt_flags = RTF_UP;
                 rt.rt_dev = argv[4];
                 errno = 0;
                 goto apply;
diff --git a/toolbox/uptime.c b/toolbox/uptime.c
new file mode 100644
index 0000000..8b1983d
--- /dev/null
+++ b/toolbox/uptime.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/time.h>
+#include <linux/ioctl.h>
+#include <linux/rtc.h>
+#include <linux/android_alarm.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+
+static void format_time(int time, char* buffer) {
+    int seconds, minutes, hours, days;
+
+    seconds = time % 60;
+    time /= 60;
+    minutes = time % 60;
+    time /= 60;
+    hours = time % 24;
+    days = time / 24;
+
+    if (days > 0)
+        sprintf(buffer, "%d days, %02d:%02d:%02d", days, hours, minutes, seconds);
+    else
+        sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
+}
+
+int64_t elapsedRealtime()
+{
+    struct timespec ts;
+    int fd, result;
+
+    fd = open("/dev/alarm", O_RDONLY);
+    if (fd < 0)
+        return fd;
+
+   result = ioctl(fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts);
+   close(fd);
+
+    if (result == 0)
+        return ts.tv_sec;
+    return -1;
+}
+
+int uptime_main(int argc, char *argv[])
+{
+    float up_time, idle_time;
+    char up_string[100], idle_string[100], sleep_string[100];
+    int elapsed;
+
+    FILE* file = fopen("/proc/uptime", "r");
+    if (!file) {
+        fprintf(stderr, "Could not open /proc/uptime\n");
+        return -1;
+    }
+    if (fscanf(file, "%f %f", &up_time, &idle_time) != 2) {
+        fprintf(stderr, "Could not parse /proc/uptime\n");
+        fclose(file);
+        return -1;
+    }
+    fclose(file);
+
+    elapsed = elapsedRealtime();
+    if (elapsed < 0) {
+        fprintf(stderr, "elapsedRealtime failed\n");
+        return -1;
+    }
+
+    format_time(elapsed, up_string);
+    format_time((int)idle_time, idle_string);
+    format_time((int)(elapsed - up_time), sleep_string);
+    printf("up time: %s, idle time: %s, sleep time: %s\n", up_string, idle_string, sleep_string);
+
+    return 0;
+}