diff --git a/adb/services.c b/adb/services.c
index 951048e58471009b469df8b15a8d24c0371f9836..1c9db0d6ffa2ecb62296052ce39190de1936984c 100644
--- a/adb/services.c
+++ b/adb/services.c
@@ -86,7 +86,7 @@ void restart_tcp_service(int fd, void *cookie)
 {
     char buf[100];
     char value[PROPERTY_VALUE_MAX];
-    int port = (int)cookie;
+    int port = (int) (uintptr_t) cookie;
 
     if (port <= 0) {
         snprintf(buf, sizeof(buf), "invalid port\n");
@@ -269,7 +269,7 @@ static int create_subprocess(const char *cmd, const char *arg0, const char *arg1
 #if !ADB_HOST
 static void subproc_waiter_service(int fd, void *cookie)
 {
-    pid_t pid = (pid_t)cookie;
+    pid_t pid = (pid_t) (uintptr_t) cookie;
 
     D("entered. fd=%d of pid=%d\n", fd, pid);
     for (;;) {
@@ -314,7 +314,7 @@ static int create_subproc_thread(const char *name)
     sti = malloc(sizeof(stinfo));
     if(sti == 0) fatal("cannot allocate stinfo");
     sti->func = subproc_waiter_service;
-    sti->cookie = (void*)pid;
+    sti->cookie = (void*) (uintptr_t) pid;
     sti->fd = ret_fd;
 
     if(adb_thread_create( &t, service_bootstrap_func, sti)){
@@ -397,7 +397,7 @@ int service_to_fd(const char *name)
         if (sscanf(name + 6, "%d", &port) == 0) {
             port = 0;
         }
-        ret = create_service_thread(restart_tcp_service, (void *)port);
+        ret = create_service_thread(restart_tcp_service, (void *) (uintptr_t) port);
     } else if(!strncmp(name, "usb:", 4)) {
         ret = create_service_thread(restart_usb_service, NULL);
 #endif
diff --git a/adb/sockets.c b/adb/sockets.c
index 7f54ad9ff9f05cbcf86ad46b2839b641f74386fc..de14a22548ad8fe2c8620c94425295b6d21415b1 100644
--- a/adb/sockets.c
+++ b/adb/sockets.c
@@ -342,7 +342,7 @@ static void local_socket_event_func(int fd, unsigned ev, void *_s)
 
         while(avail > 0) {
             r = adb_read(fd, x, avail);
-            D("LS(%d): post adb_read(fd=%d,...) r=%d (errno=%d) avail=%d\n", s->id, s->fd, r, r<0?errno:0, avail);
+            D("LS(%d): post adb_read(fd=%d,...) r=%d (errno=%d) avail=%zu\n", s->id, s->fd, r, r<0?errno:0, avail);
             if(r > 0) {
                 avail -= r;
                 x += r;
diff --git a/adb/transport.c b/adb/transport.c
index 224fe556b505a53cf46cb8de46e6c6a65fc0b51d..60025308eb694df2d769323081d03be24bca478a 100644
--- a/adb/transport.c
+++ b/adb/transport.c
@@ -1142,9 +1142,9 @@ int readx(int fd, void *ptr, size_t len)
     char *p = ptr;
     int r;
 #if ADB_TRACE
-    int  len0 = len;
+    size_t len0 = len;
 #endif
-    D("readx: fd=%d wanted=%d\n", fd, (int)len);
+    D("readx: fd=%d wanted=%zu\n", fd, len);
     while(len > 0) {
         r = adb_read(fd, p, len);
         if(r > 0) {
@@ -1163,7 +1163,7 @@ int readx(int fd, void *ptr, size_t len)
     }
 
 #if ADB_TRACE
-    D("readx: fd=%d wanted=%d got=%d\n", fd, len0, len0 - len);
+    D("readx: fd=%d wanted=%zu got=%zu\n", fd, len0, len0 - len);
     dump_hex( ptr, len0 );
 #endif
     return 0;
diff --git a/adb/transport_local.c b/adb/transport_local.c
index 1cfa24d7f3d22cdcccec8741b79b209d27f737d9..d2dbca6f69402010bb3b96f55b3461d32d2a5697 100644
--- a/adb/transport_local.c
+++ b/adb/transport_local.c
@@ -159,7 +159,7 @@ static void *server_socket_thread(void * arg)
     int serverfd, fd;
     struct sockaddr addr;
     socklen_t alen;
-    int port = (int)arg;
+    int port = (int) (uintptr_t) arg;
 
     D("transport: server_socket_thread() starting\n");
     serverfd = -1;
@@ -241,7 +241,7 @@ static const char _start_req[]  = "start";
 /* 'ok' reply from the adb QEMUD service. */
 static const char _ok_resp[]    = "ok";
 
-    const int port = (int)arg;
+    const int port = (int) (uintptr_t) arg;
     int res, fd;
     char tmp[256];
     char con_name[32];
@@ -326,7 +326,7 @@ void local_init(int port)
 
     D("transport: local %s init\n", HOST ? "client" : "server");
 
-    if(adb_thread_create(&thr, func, (void *)port)) {
+    if(adb_thread_create(&thr, func, (void *) (uintptr_t) port)) {
         fatal_errno("cannot create local socket %s thread",
                     HOST ? "client" : "server");
     }
diff --git a/adb/usb_linux.c b/adb/usb_linux.c
index 7bf205753c4f6fa820bf983329e491ec5409d3bc..8ff753e43383462f20cc56a3d6a1c50851d483da 100644
--- a/adb/usb_linux.c
+++ b/adb/usb_linux.c
@@ -179,7 +179,7 @@ static void find_usb_device(const char *base,
 
                 // should have device and configuration descriptors, and atleast two endpoints
             if (desclength < USB_DT_DEVICE_SIZE + USB_DT_CONFIG_SIZE) {
-                D("desclength %d is too small\n", desclength);
+                D("desclength %zu is too small\n", desclength);
                 adb_close(fd);
                 continue;
             }
diff --git a/adb/usb_linux_client.c b/adb/usb_linux_client.c
index fb1dad05fe8e7b795a9c2f10939700fd70c916d2..69d8062770dcaf701909c62036ef94054cba37aa 100644
--- a/adb/usb_linux_client.c
+++ b/adb/usb_linux_client.c
@@ -384,7 +384,7 @@ static int bulk_read(int bulk_out, char *buf, size_t length)
         ret = adb_read(bulk_out, buf + count, length - count);
         if (ret < 0) {
             if (errno != EINTR) {
-                D("[ bulk_read failed fd=%d length=%d count=%d ]\n",
+                D("[ bulk_read failed fd=%d length=%zu count=%zu ]\n",
                                            bulk_out, length, count);
                 return ret;
             }
diff --git a/fastbootd/commands.c b/fastbootd/commands.c
index d8a601f528614fc063569eb8c333a13d19f012d7..063e1a6005efe854f033e1a3193e66602201b1d4 100644
--- a/fastbootd/commands.c
+++ b/fastbootd/commands.c
@@ -29,6 +29,7 @@
  * SUCH DAMAGE.
  */
 
+#include <inttypes.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -319,7 +320,7 @@ static void cmd_flash(struct protocol_handle *phandle, const char *arg)
         return;
     }
 
-    D(INFO, "writing %lld bytes to '%s'\n", sz, arg);
+    D(INFO, "writing %"PRId64" bytes to '%s'\n", sz, arg);
 
     if (flash_write(partition, phandle->download_fd, sz, header_sz)) {
         fastboot_fail(phandle, "flash write failure");
diff --git a/fastbootd/commands/flash.c b/fastbootd/commands/flash.c
index 0954217b58c0d0e5203ed8dedd018b0fedd4420f..1eb4d1b335bea41420369f1b73a530ccfb0024af 100644
--- a/fastbootd/commands/flash.c
+++ b/fastbootd/commands/flash.c
@@ -31,6 +31,7 @@
 
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <inttypes.h>
 #include <sys/mman.h>
 
 #include "flash.h"
@@ -82,7 +83,7 @@ int flash_erase(int fd)
 {
     int64_t size;
     size = get_block_device_size(fd);
-    D(DEBUG, "erase %llu data from %d\n", size, fd);
+    D(DEBUG, "erase %"PRId64" data from %d\n", size, fd);
 
     return wipe_block_device(fd, size);
 }
@@ -97,7 +98,7 @@ int flash_write(int partition_fd, int data_fd, ssize_t size, ssize_t skip)
         int current_size = MIN(size - written, BUFFER_SIZE);
 
         if (gpt_mmap(&input, written + skip, current_size, data_fd)) {
-            D(ERR, "Error in writing data, unable to map data file %d at %d size %d", size, skip, current_size);
+            D(ERR, "Error in writing data, unable to map data file %zd at %zd size %d", size, skip, current_size);
             return -1;
         }
         if (gpt_mmap(&output, written, current_size, partition_fd)) {
diff --git a/fastbootd/secure.c b/fastbootd/secure.c
index a657ad4da9ad4d24fb64d9c1f9f002f97d124289..186e0268d5a6bb19514f2db2db414eeee2d2edbb 100644
--- a/fastbootd/secure.c
+++ b/fastbootd/secure.c
@@ -151,7 +151,7 @@ int cert_verify(BIO *content, CMS_ContentInfo *content_info, X509_STORE *store,
         char buf[256];
         unsigned long err = ERR_peek_last_error();
         D(ERR, "Verification failed with reason: %s, %s", ERR_lib_error_string(err),  ERR_error_string(err, buf));
-        D(ERR, "Data used: content %d", (int) content);
+        D(ERR, "Data used: content %p", content);
     }
 
     ERR_clear_error();
diff --git a/fastbootd/transport.c b/fastbootd/transport.c
index 19a705c6ef9da952887e1e7cd8a1ee8a59dc26c3..ce8f9d096c04104bfba1fd9accff6ef599017a49 100644
--- a/fastbootd/transport.c
+++ b/fastbootd/transport.c
@@ -56,14 +56,14 @@ int transport_handle_download(struct transport_handle *thandle, size_t len)
 
     buffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
     if (buffer == NULL) {
-        D(ERR, "mmap(%u) failed: %d %s", len, errno, strerror(errno));
+        D(ERR, "mmap(%zu) failed: %d %s", len, errno, strerror(errno));
         goto err;
     }
 
     while (n < len) {
         ret = thandle->transport->read(thandle, buffer + n, len - n);
         if (ret <= 0) {
-            D(WARN, "transport read failed, ret=%d %s", ret, strerror(-ret));
+            D(WARN, "transport read failed, ret=%zd %s", ret, strerror(-ret));
             break;
         }
         n += ret;
diff --git a/fastbootd/transport_socket.c b/fastbootd/transport_socket.c
index ff0f3bdc82ccef9acd2cacd3d60402aefab7fc37..664d4737ff501a920397c611acf5e8b7de31218e 100644
--- a/fastbootd/transport_socket.c
+++ b/fastbootd/transport_socket.c
@@ -88,7 +88,7 @@ ssize_t socket_write(struct transport_handle *thandle, const void *data, size_t
     ssize_t ret;
     struct socket_handle *handle = container_of(thandle, struct socket_handle, handle);
 
-    D(DEBUG, "about to write (fd=%d, len=%d)", handle->fd, len);
+    D(DEBUG, "about to write (fd=%d, len=%zu)", handle->fd, len);
     ret = bulk_write(handle->fd, data, len);
     if (ret < 0) {
         D(ERR, "ERROR: fd = %d, ret = %zd", handle->fd, ret);
@@ -103,7 +103,7 @@ ssize_t socket_read(struct transport_handle *thandle, void *data, size_t len)
     ssize_t ret;
     struct socket_handle *handle = container_of(thandle, struct socket_handle, handle);
 
-    D(DEBUG, "about to read (fd=%d, len=%d)", handle->fd, len);
+    D(DEBUG, "about to read (fd=%d, len=%zu)", handle->fd, len);
     ret = bulk_read(handle->fd, data, len);
     if (ret < 0) {
         D(ERR, "ERROR: fd = %d, ret = %zd", handle->fd, ret);
diff --git a/fastbootd/usb_linux_client.c b/fastbootd/usb_linux_client.c
index 7a8e46f3eff0ba04ef5f062790a2c32d2d907649..64420e986174c72c0f8a453936684297db0914f1 100644
--- a/fastbootd/usb_linux_client.c
+++ b/fastbootd/usb_linux_client.c
@@ -217,7 +217,7 @@ static ssize_t usb_write(struct transport_handle *thandle, const void *data, siz
     struct transport *t = thandle->transport;
     struct usb_transport *usb_transport = container_of(t, struct usb_transport, transport);
 
-    D(DEBUG, "about to write (fd=%d, len=%d)", usb_transport->bulk_in, len);
+    D(DEBUG, "about to write (fd=%d, len=%zu)", usb_transport->bulk_in, len);
     ret = bulk_write(usb_transport->bulk_in, data, len);
     if (ret < 0) {
         D(ERR, "ERROR: fd = %d, ret = %zd", usb_transport->bulk_in, ret);
@@ -233,7 +233,7 @@ ssize_t usb_read(struct transport_handle *thandle, void *data, size_t len)
     struct transport *t = thandle->transport;
     struct usb_transport *usb_transport = container_of(t, struct usb_transport, transport);
 
-    D(DEBUG, "about to read (fd=%d, len=%d)", usb_transport->bulk_out, len);
+    D(DEBUG, "about to read (fd=%d, len=%zu)", usb_transport->bulk_out, len);
     ret = bulk_read(usb_transport->bulk_out, data, len);
     if (ret < 0) {
         D(ERR, "ERROR: fd = %d, ret = %zd", usb_transport->bulk_out, ret);
diff --git a/fs_mgr/fs_mgr_verity.c b/fs_mgr/fs_mgr_verity.c
index 969eab2a065e43f9766a1d0e8d5616d102e4085b..154931684daf4406eedb7f26fe83fd4b30dfaa79 100644
--- a/fs_mgr/fs_mgr_verity.c
+++ b/fs_mgr/fs_mgr_verity.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -178,7 +179,7 @@ static int read_verity_metadata(char *block_device, char **signature, char **tab
         goto out;
     }
     if (magic_number != VERITY_METADATA_MAGIC_NUMBER) {
-        ERROR("Couldn't find verity metadata at offset %llu!\n", device_length);
+        ERROR("Couldn't find verity metadata at offset %"PRIu64"!\n", device_length);
         goto out;
     }
 
diff --git a/init/init.c b/init/init.c
index ab52749fd60d29f7fa021a2f54ca3360809c94a0..4266a73c45942e95c8ae98f0344ca87b29b2cf80 100644
--- a/init/init.c
+++ b/init/init.c
@@ -623,7 +623,7 @@ static int mix_hwrng_into_linux_rng_action(int nargs, char **args)
         total_bytes_written += chunk_size;
     }
 
-    INFO("Mixed %d bytes from /dev/hw_random into /dev/urandom",
+    INFO("Mixed %zu bytes from /dev/hw_random into /dev/urandom",
                 total_bytes_written);
     result = 0;
 
diff --git a/init/property_service.c b/init/property_service.c
index c3707691f323e22beab7d139c65c450b23de450e..ac63377ef642f7f78ef2588e7d07959c9a14979f 100644
--- a/init/property_service.c
+++ b/init/property_service.c
@@ -168,7 +168,7 @@ static int check_mac_perms(const char *name, char *sctx)
     if (selabel_lookup(sehandle_prop, &tctx, name, 1) != 0)
         goto err;
 
-    if (selinux_check_access(sctx, tctx, class, perm, name) == 0)
+    if (selinux_check_access(sctx, tctx, class, perm, (void*) name) == 0)
         result = 1;
 
     freecon(tctx);
@@ -382,7 +382,7 @@ void handle_property_set_fd()
 
     r = TEMP_FAILURE_RETRY(recv(s, &msg, sizeof(msg), 0));
     if(r != sizeof(prop_msg)) {
-        ERROR("sys_prop: mis-match msg size received: %d expected: %d errno: %d\n",
+        ERROR("sys_prop: mis-match msg size received: %d expected: %zu errno: %d\n",
               r, sizeof(prop_msg), errno);
         close(s);
         return;
@@ -522,7 +522,7 @@ static void load_persistent_properties()
                     || (sb.st_uid != 0)
                     || (sb.st_gid != 0)
                     || (sb.st_nlink != 1)) {
-                ERROR("skipping insecure property file %s (uid=%lu gid=%lu nlink=%d mode=%o)\n",
+                ERROR("skipping insecure property file %s (uid=%u gid=%u nlink=%d mode=%o)\n",
                       entry->d_name, sb.st_uid, sb.st_gid, sb.st_nlink, sb.st_mode);
                 close(fd);
                 continue;
diff --git a/libdiskconfig/diskconfig.c b/libdiskconfig/diskconfig.c
index d5425de035fef2fb5843be32b04b093623be41ed..6fd81b71486190ff8f0d82450f2b8f6ec3b4c913 100644
--- a/libdiskconfig/diskconfig.c
+++ b/libdiskconfig/diskconfig.c
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -80,7 +81,7 @@ parse_len(const char *str, uint64_t *plen)
         *plen *= multiple;
 
         if (*plen > 0xffffffffULL) {
-            ALOGE("Length specified is too large!: %llu KB", *plen);
+            ALOGE("Length specified is too large!: %"PRIu64" KB", *plen);
             return 1;
         }
     }
@@ -371,8 +372,8 @@ validate(struct disk_info *dinfo)
 
     /* only matters for disks, not files */
     if (S_ISBLK(stat.st_mode) && total_size > disk_size) {
-        ALOGE("Total requested size of partitions (%llu) is greater than disk "
-             "size (%llu).", total_size, disk_size);
+        ALOGE("Total requested size of partitions (%"PRIu64") is greater than disk "
+             "size (%"PRIu64").", total_size, disk_size);
         goto fail;
     }
 
diff --git a/libion/ion_test.c b/libion/ion_test.c
index 12163e9369fa20a922c68544186988ed3a555403..88722828366e65b661009c6522388d3acd71bb43 100644
--- a/libion/ion_test.c
+++ b/libion/ion_test.c
@@ -63,7 +63,7 @@ void ion_alloc_test()
 
     ret = ion_free(fd, handle);
     if (ret) {
-        printf("%s failed: %s %p\n", __func__, strerror(ret), handle);
+        printf("%s failed: %s %d\n", __func__, strerror(ret), handle);
         return;
     }
     ion_close(fd);
diff --git a/libmemtrack/memtrack_test.c b/libmemtrack/memtrack_test.c
index cd94bc5e12e817beef327d626051e926c10d00a1..eaadfa7052f9354361dc4864995fb65ca0123256 100644
--- a/libmemtrack/memtrack_test.c
+++ b/libmemtrack/memtrack_test.c
@@ -35,7 +35,7 @@ static int getprocname(pid_t pid, char *buf, int len) {
         return -1;
     }
 
-    if (asprintf(&filename, "/proc/%zd/cmdline", pid) < 0) {
+    if (asprintf(&filename, "/proc/%d/cmdline", pid) < 0) {
         rc = 1;
         goto exit;
     }
diff --git a/libsparse/output_file.c b/libsparse/output_file.c
index a28b0a5ad9b1400e3e2de4c72d981afc29ed9a1a..e63c4a929d5cb20f066b2cf65b3fb49af0647971 100644
--- a/libsparse/output_file.c
+++ b/libsparse/output_file.c
@@ -18,6 +18,7 @@
 #define _LARGEFILE64_SOURCE 1
 
 #include <fcntl.h>
+#include <inttypes.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -342,7 +343,7 @@ static int write_sparse_skip_chunk(struct output_file *out, int64_t skip_len)
 	int ret, chunk;
 
 	if (skip_len % out->block_size) {
-		error("don't care size %llu is not a multiple of the block size %u",
+		error("don't care size %"PRIi64" is not a multiple of the block size %u",
 				skip_len, out->block_size);
 		return -1;
 	}
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index d44c6796b50f6c2eebe907109615a14636341f02..4c6139cf69a2ebeb7a4b895465a8c36992a87204 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -298,7 +298,7 @@ static void readLogLines(log_device_t* devices)
                     }
                     else if (entry->entry.len != ret - sizeof(struct logger_entry)) {
                         fprintf(stderr, "read: unexpected length. Expected %d, got %d\n",
-                                entry->entry.len, ret - sizeof(struct logger_entry));
+                                entry->entry.len, ret - (int) sizeof(struct logger_entry));
                         exit(EXIT_FAILURE);
                     }
 
diff --git a/logwrapper/logwrapper.c b/logwrapper/logwrapper.c
index db6cb4c3bd0fade9c5a06688633c6e6dfc081f86..9e0385db2f1df33ea8de02a37507b827993eef4b 100644
--- a/logwrapper/logwrapper.c
+++ b/logwrapper/logwrapper.c
@@ -90,7 +90,8 @@ int main(int argc, char* argv[]) {
     }
 
     if (seg_fault_on_exit) {
-        *(int *)status = 0;  // causes SIGSEGV with fault_address = status
+        uintptr_t fault_address = (uintptr_t) status;
+        *(int *) fault_address = 0;  // causes SIGSEGV with fault_address = status
     }
 
     return rc;
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 75ce53f0aa56c6df7b66c6f258dfcea41f30c4e7..436f13d708842d84b9b7837e52bf3e18723d9d71 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -89,6 +89,8 @@ LOCAL_SRC_FILES := \
 
 LOCAL_C_INCLUDES := bionic/libc/bionic
 
+LOCAL_CFLAGS += -Wno-unused-parameter
+
 LOCAL_SHARED_LIBRARIES := \
 	libcutils \
 	liblog \
diff --git a/toolbox/dd.c b/toolbox/dd.c
index a8c12d285a090d54495c08955fc4523c32538174..6b61ffb1290d6fc7ae29d95167bfdc7325cb6ad8 100644
--- a/toolbox/dd.c
+++ b/toolbox/dd.c
@@ -92,9 +92,6 @@ extern u_int		files_cnt;
 extern int		progress;
 extern const u_char	*ctab;
 
-
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
 #define DEFFILEMODE (S_IRUSR | S_IWUSR)
 
 static void dd_close(void);
diff --git a/toolbox/getevent.c b/toolbox/getevent.c
index 5f5e16b771ec46185a6838e18c971e8636ef89f4..ed381f5057c8a596b895daf5441f6bd3a497ebbf 100644
--- a/toolbox/getevent.c
+++ b/toolbox/getevent.c
@@ -166,7 +166,7 @@ static int print_possible_events(int fd, int print_flags)
                     if(bit_labels && (print_flags & PRINT_LABELS)) {
                         bit_label = get_label(bit_labels, j * 8 + k);
                         if(bit_label)
-                            printf(" %.20s%c%*s", bit_label, down, 20 - strlen(bit_label), "");
+                            printf(" %.20s%c%*s", bit_label, down, (int) (20 - strlen(bit_label)), "");
                         else
                             printf(" %04x%c                ", j * 8 + k, down);
                     } else {
diff --git a/toolbox/insmod.c b/toolbox/insmod.c
index 756a64b94d7d5293615608c17b118981b7d4b028..fb1448ba55b5cf786f4e5f33dc92633a3b4692b7 100644
--- a/toolbox/insmod.c
+++ b/toolbox/insmod.c
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <malloc.h>
 #include <errno.h>
+#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -45,7 +46,6 @@ bail:
 	return buffer;
 }
 
-#define min(x,y) ((x) < (y) ? (x) : (y))
 int insmod_main(int argc, char **argv)
 {
 	void *file;
@@ -73,7 +73,7 @@ int insmod_main(int argc, char **argv)
 		char *ptr = opts;
 
 		for (i = 2; (i < argc) && (ptr < end); i++) {
-			len = min(strlen(argv[i]), end - ptr);
+			len = MIN(strlen(argv[i]), end - ptr);
 			memcpy(ptr, argv[i], len);
 			ptr += len;
 			*ptr++ = ' ';
diff --git a/toolbox/ls.c b/toolbox/ls.c
index c740f847ed1fbd24247ad807364bd9a5818cd23b..3cc5bb2c09d4360dfd26c4bda6662c7f0f83c668 100644
--- a/toolbox/ls.c
+++ b/toolbox/ls.c
@@ -182,8 +182,8 @@ static int listfile_long(const char *path, struct stat *s, int flags)
 
     mode2str(s->st_mode, mode);
     if (flags & LIST_LONG_NUMERIC) {
-        snprintf(user, sizeof(user), "%ld", s->st_uid);
-        snprintf(group, sizeof(group), "%ld", s->st_gid);
+        snprintf(user, sizeof(user), "%u", s->st_uid);
+        snprintf(group, sizeof(group), "%u", s->st_gid);
     } else {
         user2str(s->st_uid, user, sizeof(user));
         group2str(s->st_gid, group, sizeof(group));
diff --git a/toolbox/nandread.c b/toolbox/nandread.c
index 4666f2656c32772ab25b568e4a2eaf8dd17aa01d..d43b2febe32a30422f61c04c4e4d9811791e4ebc 100644
--- a/toolbox/nandread.c
+++ b/toolbox/nandread.c
@@ -158,7 +158,7 @@ int nandread_main(int argc, char **argv)
         printf("oobavail: %u\n", ecclayout.oobavail);
     }
     if (ecclayout.oobavail > spare_size)
-        printf("oobavail, %d > image spare size, %d\n", ecclayout.oobavail, spare_size);
+        printf("oobavail, %d > image spare size, %zu\n", ecclayout.oobavail, spare_size);
 
     ret = ioctl(fd, ECCGETSTATS, &initial_ecc);
     if (ret) {
diff --git a/toolbox/newfs_msdos.c b/toolbox/newfs_msdos.c
index 6d78eb6952c63161cd6f7bb106d32c88c76cb9c0..27dca420b6f6e7edea5402c87718260a010df05a 100644
--- a/toolbox/newfs_msdos.c
+++ b/toolbox/newfs_msdos.c
@@ -234,13 +234,6 @@ static void mklabel(u_int8_t *, const char *);
 static void setstr(u_int8_t *, const char *, size_t);
 static void usage(void);
 
-#ifdef ANDROID
-#define powerof2(x)     ((((x) - 1) & (x)) == 0)
-#define howmany(x, y)   (((x) + ((y) - 1)) / (y))
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-
-#endif
 /*
  * Construct a FAT12, FAT16, or FAT32 file system.
  */
diff --git a/toolbox/schedtop.c b/toolbox/schedtop.c
index 6859b50bce0922fbdf015c2134890faa79ededdf..a76f968f34b71affaaad19b8773722d2ec0c9591 100644
--- a/toolbox/schedtop.c
+++ b/toolbox/schedtop.c
@@ -212,7 +212,7 @@ static void update_table(DIR *d, uint32_t flags)
     }
     if (!(flags & FLAG_BATCH))
         printf("\e[H\e[0J");
-    printf("Processes: %d, Threads %d\n", processes.active, threads.active);
+    printf("Processes: %zu, Threads %zu\n", processes.active, threads.active);
     switch (time_dp) {
     case 3:
         printf("   TID --- SINCE LAST ---- ---------- TOTAL ----------\n");
diff --git a/toolbox/setconsole.c b/toolbox/setconsole.c
index 0159c07ee3612d520a12ea198f83b953e2c719ba..85ea7c2f58d84c6a61cfafde3343d37cfade917e 100644
--- a/toolbox/setconsole.c
+++ b/toolbox/setconsole.c
@@ -12,12 +12,9 @@
 static int activate_thread_switch_vc;
 static void *activate_thread(void *arg)
 {
-    int res;
-    int fd = (int)arg;
+    int fd = (int) (uintptr_t) arg;
     while(activate_thread_switch_vc >= 0) {
-        do {
-            res = ioctl(fd, VT_ACTIVATE, (void*)activate_thread_switch_vc);
-        } while(res < 0 && errno == EINTR);
+        int res = TEMP_FAILURE_RETRY(ioctl(fd, VT_ACTIVATE, activate_thread_switch_vc));
         if (res < 0) {
             fprintf(stderr, "ioctl( vcfd, VT_ACTIVATE, vtnum) failed, %d %d %s for %d\n", res, errno, strerror(errno), activate_thread_switch_vc);
         }
@@ -131,11 +128,9 @@ int setconsole_main(int argc, char *argv[])
         activate_thread_switch_vc = switch_vc;
         pthread_attr_init(&attr);
         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-        pthread_create(&thread, &attr, activate_thread, (void*)fd);
-        
-        do {
-            res = ioctl(fd, VT_WAITACTIVE, (void*)switch_vc);
-        } while(res < 0 && errno == EINTR);
+        pthread_create(&thread, &attr, activate_thread, (void*) (uintptr_t) fd);
+
+        res = TEMP_FAILURE_RETRY(ioctl(fd, VT_WAITACTIVE, switch_vc));
         activate_thread_switch_vc = -1;
         if (res < 0) {
             fprintf(stderr, "ioctl( vcfd, VT_WAITACTIVE, vtnum) failed, %d %d %s for %d\n", res, errno, strerror(errno), switch_vc);
@@ -157,7 +152,7 @@ int setconsole_main(int argc, char *argv[])
         }
     }
     if (mode != -1) {
-        if (ioctl(fd, KDSETMODE, (void*)mode) < 0) {
+        if (ioctl(fd, KDSETMODE, mode) < 0) {
             fprintf(stderr, "KDSETMODE %d failed\n", mode);
             return -1;
         }