More kernel header cleanup.

Modify the generate script to add a new option and copy the types.h
arm header file since it's not currently being created properly. Also
manually generate the arm types.h uapi header since it's not being
properly generated right now.

Modify both generate scripts to delete the target directories before
adding the files to handle moved/deleted header files.

Move the common/scsi headers into android and delete the common
directory. Change the scripts to reflect this change.

Update the scsi headers since they've been modified in upstream kernels.

Bug: 30072483

Change-Id: Ia43d4b238b6a041350d60cc30184ecbd4829d7d5
diff --git a/libc/kernel/android/README.TXT b/libc/kernel/android/README.TXT
index dab5f42..bc2efde 100644
--- a/libc/kernel/android/README.TXT
+++ b/libc/kernel/android/README.TXT
@@ -1,6 +1,17 @@
-The files under this directory are android kernel uapi header files that
+The files under the uapi directory are android kernel uapi header files that
 exist in android kernels, but have not been upstreamed into the regular
 kernel.
 
 None of these files will get updated automatically, and are frozen at their
 current value.
+
+The files under the scsi directory are frozen copies of kernel scsi headers.
+Linux's scsi headers are a mix of userspace-facing and kernel-facing
+declarations that can't be directly used by userspace. The glibc
+maintainers manually copy-and-pasted these definitions into their own
+scsi headers and haven't substantially updated them in 15 years. The
+musl libc project has a similar set of definitions in its scsi headers.
+
+These files are actually maintained in external/kernel-headers/modified/scsi.
+Any modification should first be made there then copied into the scsi
+directory.
diff --git a/libc/kernel/android/scsi/scsi.h b/libc/kernel/android/scsi/scsi.h
new file mode 100644
index 0000000..bcbcffe
--- /dev/null
+++ b/libc/kernel/android/scsi/scsi.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _SCSI_SCSI_H
+#define _SCSI_SCSI_H
+#include <linux/types.h>
+#include <scsi/scsi_proto.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ccs_modesel_head {
+  __u8 _r1;
+  __u8 medium;
+  __u8 _r2;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  __u8 block_desc_length;
+  __u8 density;
+  __u8 number_blocks_hi;
+  __u8 number_blocks_med;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  __u8 number_blocks_lo;
+  __u8 _r3;
+  __u8 block_length_hi;
+  __u8 block_length_med;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  __u8 block_length_lo;
+};
+#define COMMAND_COMPLETE 0x00
+#define EXTENDED_MESSAGE 0x01
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EXTENDED_MODIFY_DATA_POINTER 0x00
+#define EXTENDED_SDTR 0x01
+#define EXTENDED_EXTENDED_IDENTIFY 0x02
+#define EXTENDED_WDTR 0x03
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EXTENDED_PPR 0x04
+#define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05
+#define SAVE_POINTERS 0x02
+#define RESTORE_POINTERS 0x03
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DISCONNECT 0x04
+#define INITIATOR_ERROR 0x05
+#define ABORT_TASK_SET 0x06
+#define MESSAGE_REJECT 0x07
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NOP 0x08
+#define MSG_PARITY_ERROR 0x09
+#define LINKED_CMD_COMPLETE 0x0a
+#define LINKED_FLG_CMD_COMPLETE 0x0b
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TARGET_RESET 0x0c
+#define ABORT_TASK 0x0d
+#define CLEAR_TASK_SET 0x0e
+#define INITIATE_RECOVERY 0x0f
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define RELEASE_RECOVERY 0x10
+#define CLEAR_ACA 0x16
+#define LOGICAL_UNIT_RESET 0x17
+#define SIMPLE_QUEUE_TAG 0x20
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HEAD_OF_QUEUE_TAG 0x21
+#define ORDERED_QUEUE_TAG 0x22
+#define IGNORE_WIDE_RESIDUE 0x23
+#define ACA 0x24
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define QAS_REQUEST 0x55
+#define BUS_DEVICE_RESET TARGET_RESET
+#define ABORT ABORT_TASK_SET
+#define SCSI_IOCTL_GET_IDLUN 0x5382
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SCSI_IOCTL_PROBE_HOST 0x5385
+#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
+#define SCSI_IOCTL_GET_PCI 0x5387
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/common/scsi/scsi_ioctl.h b/libc/kernel/android/scsi/scsi_ioctl.h
similarity index 100%
rename from libc/kernel/common/scsi/scsi_ioctl.h
rename to libc/kernel/android/scsi/scsi_ioctl.h
diff --git a/libc/kernel/common/scsi/scsi.h b/libc/kernel/android/scsi/scsi_proto.h
similarity index 75%
rename from libc/kernel/common/scsi/scsi.h
rename to libc/kernel/android/scsi/scsi_proto.h
index 9e5edd7..acb18e7 100644
--- a/libc/kernel/common/scsi/scsi.h
+++ b/libc/kernel/android/scsi/scsi_proto.h
@@ -16,8 +16,8 @@
  ***
  ****************************************************************************
  ****************************************************************************/
-#ifndef _SCSI_SCSI_H
-#define _SCSI_SCSI_H
+#ifndef _SCSI_PROTO_H_
+#define _SCSI_PROTO_H_
 #include <linux/types.h>
 #define TEST_UNIT_READY 0x00
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -112,36 +112,41 @@
 #define EXCHANGE_MEDIUM 0xa6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define READ_12 0xa8
+#define SERVICE_ACTION_OUT_12 0xa9
 #define WRITE_12 0xaa
 #define READ_MEDIA_SERIAL_NUMBER 0xab
-#define WRITE_VERIFY_12 0xae
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SERVICE_ACTION_IN_12 0xab
+#define WRITE_VERIFY_12 0xae
 #define VERIFY_12 0xaf
 #define SEARCH_HIGH_12 0xb0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SEARCH_EQUAL_12 0xb1
 #define SEARCH_LOW_12 0xb2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SECURITY_PROTOCOL_OUT 0xb5
 #define READ_ELEMENT_STATUS 0xb8
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SEND_VOLUME_TAG 0xb6
 #define WRITE_LONG_2 0xea
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define EXTENDED_COPY 0x83
 #define RECEIVE_COPY_RESULTS 0x84
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ACCESS_CONTROL_IN 0x86
 #define ACCESS_CONTROL_OUT 0x87
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define READ_16 0x88
 #define COMPARE_AND_WRITE 0x89
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define WRITE_16 0x8a
 #define READ_ATTRIBUTE 0x8c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define WRITE_ATTRIBUTE 0x8d
 #define VERIFY_16 0x8f
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SYNCHRONIZE_CACHE_16 0x91
 #define WRITE_SAME_16 0x93
+#define SERVICE_ACTION_BIDIRECTIONAL 0x9d
+#define SERVICE_ACTION_IN_16 0x9e
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SERVICE_ACTION_IN 0x9e
+#define SERVICE_ACTION_OUT_16 0x9f
 #define GOOD 0x00
 #define CHECK_CONDITION 0x01
 #define CONDITION_GOOD 0x02
@@ -194,68 +199,5 @@
 #define TYPE_ZBC 0x14
 #define TYPE_WLUN 0x1e
 #define TYPE_NO_LUN 0x7f
-struct ccs_modesel_head {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 _r1;
-  __u8 medium;
-  __u8 _r2;
-  __u8 block_desc_length;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 density;
-  __u8 number_blocks_hi;
-  __u8 number_blocks_med;
-  __u8 number_blocks_lo;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 _r3;
-  __u8 block_length_hi;
-  __u8 block_length_med;
-  __u8 block_length_lo;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-#define COMMAND_COMPLETE 0x00
-#define EXTENDED_MESSAGE 0x01
-#define EXTENDED_MODIFY_DATA_POINTER 0x00
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define EXTENDED_SDTR 0x01
-#define EXTENDED_EXTENDED_IDENTIFY 0x02
-#define EXTENDED_WDTR 0x03
-#define EXTENDED_PPR 0x04
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05
-#define SAVE_POINTERS 0x02
-#define RESTORE_POINTERS 0x03
-#define DISCONNECT 0x04
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define INITIATOR_ERROR 0x05
-#define ABORT_TASK_SET 0x06
-#define MESSAGE_REJECT 0x07
-#define NOP 0x08
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSG_PARITY_ERROR 0x09
-#define LINKED_CMD_COMPLETE 0x0a
-#define LINKED_FLG_CMD_COMPLETE 0x0b
-#define TARGET_RESET 0x0c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ABORT_TASK 0x0d
-#define CLEAR_TASK_SET 0x0e
-#define INITIATE_RECOVERY 0x0f
-#define RELEASE_RECOVERY 0x10
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define CLEAR_ACA 0x16
-#define LOGICAL_UNIT_RESET 0x17
-#define SIMPLE_QUEUE_TAG 0x20
-#define HEAD_OF_QUEUE_TAG 0x21
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ORDERED_QUEUE_TAG 0x22
-#define IGNORE_WIDE_RESIDUE 0x23
-#define ACA 0x24
-#define QAS_REQUEST 0x55
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define BUS_DEVICE_RESET TARGET_RESET
-#define ABORT ABORT_TASK_SET
-#define SCSI_IOCTL_GET_IDLUN 0x5382
-#define SCSI_IOCTL_PROBE_HOST 0x5385
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
-#define SCSI_IOCTL_GET_PCI 0x5387
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/common/scsi/sg.h b/libc/kernel/android/scsi/sg.h
similarity index 99%
rename from libc/kernel/common/scsi/sg.h
rename to libc/kernel/android/scsi/sg.h
index a38eccb..4472385 100644
--- a/libc/kernel/common/scsi/sg.h
+++ b/libc/kernel/android/scsi/sg.h
@@ -127,53 +127,54 @@
 #define SG_SCSI_RESET_HOST 3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SG_SCSI_RESET_TARGET 4
+#define SG_SCSI_RESET_NO_ESCALATE 0x100
 #define SG_IO 0x2285
 #define SG_GET_REQUEST_TABLE 0x2286
-#define SG_SET_KEEP_ORPHAN 0x2287
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_SET_KEEP_ORPHAN 0x2287
 #define SG_GET_KEEP_ORPHAN 0x2288
 #define SG_GET_ACCESS_COUNT 0x2289
 #define SG_SCATTER_SZ (8 * 4096)
-#define SG_DEFAULT_RETRIES 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_DEFAULT_RETRIES 0
 #define SG_DEF_FORCE_LOW_DMA 0
 #define SG_DEF_FORCE_PACK_ID 0
 #define SG_DEF_KEEP_ORPHAN 0
-#define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ
 #define SG_MAX_QUEUE 16
 #define SG_BIG_BUFF SG_DEF_RESERVED_SIZE
 typedef struct sg_io_hdr Sg_io_hdr;
-typedef struct sg_io_vec Sg_io_vec;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct sg_io_vec Sg_io_vec;
 typedef struct sg_scsi_id Sg_scsi_id;
 typedef struct sg_req_info Sg_req_info;
 #define SG_MAX_SENSE 16
-struct sg_header {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct sg_header {
   int pack_len;
   int reply_len;
   int pack_id;
-  int result;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  int result;
   unsigned int twelve_byte : 1;
   unsigned int target_status : 5;
   unsigned int host_status : 8;
-  unsigned int driver_status : 8;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  unsigned int driver_status : 8;
   unsigned int other_flags : 10;
   unsigned char sense_buffer[SG_MAX_SENSE];
 };
-#define SG_SET_TIMEOUT 0x2201
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_SET_TIMEOUT 0x2201
 #define SG_GET_TIMEOUT 0x2202
 #define SG_GET_COMMAND_Q 0x2270
 #define SG_SET_COMMAND_Q 0x2271
-#define SG_SET_DEBUG 0x227e
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_SET_DEBUG 0x227e
 #define SG_NEXT_CMD_LEN 0x2283
 #define SG_DEFAULT_TIMEOUT (60 * HZ)
 #define SG_DEF_COMMAND_Q 0
-#define SG_DEF_UNDERRUN_FLAG 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_DEF_UNDERRUN_FLAG 0
 #endif
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index e84bcf9..99f4c7f 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -117,7 +117,7 @@
                 statics = statics.union(kernel_known_statics.get(arch, set()))
         # common headers (ie non-asm and non-uapi)
         else:
-            dst_path = os.path.join("common", rel_path)
+            dst_path = os.path.join("android", rel_path)
 
     dst_path = os.path.join(dst_dir, dst_path)
 
diff --git a/libc/kernel/tools/generate_uapi_headers.sh b/libc/kernel/tools/generate_uapi_headers.sh
index 3c80d9f..4603fbe 100755
--- a/libc/kernel/tools/generate_uapi_headers.sh
+++ b/libc/kernel/tools/generate_uapi_headers.sh
@@ -30,6 +30,9 @@
 ###   --use-kernel-dir <DIR>
 ###     Do not check out the kernel source, use the kernel directory
 ###     pointed to by <DIR>.
+###   --verify-modified-headers-only <DIR>
+###     Do not build anything, simply verify that the set of modified
+###     kernel headers have not changed.
 
 # Terminate the script if any command fails.
 set -eE
@@ -42,6 +45,7 @@
 ARCH_LIST=("arm" "arm64" "mips" "x86")
 ANDROID_KERNEL_DIR="external/kernel-headers/original"
 SKIP_GENERATION=0
+VERIFY_HEADERS_ONLY=0
 
 function cleanup () {
   if [[ "${TMPDIR}" =~ /tmp ]] && [[ -d "${TMPDIR}" ]]; then
@@ -99,7 +103,7 @@
   done
 }
 
-function check_hdrs () {
+function verify_modified_hdrs () {
   local src_dir=$1
   local tgt_dir=$2
   local kernel_dir=$3
@@ -124,7 +128,7 @@
   done
 
   for dir in "${search_dirs[@]}"; do
-    check_hdrs "${dir}" ${tgt_dir}/$(basename ${dir}) "${kernel_dir}"
+    verify_modified_hdrs "${dir}" ${tgt_dir}/$(basename ${dir}) "${kernel_dir}"
   done
 }
 
@@ -149,6 +153,16 @@
       KERNEL_DIR="$1"
       KERNEL_DOWNLOAD=0
       ;;
+    "--verify-modified-headers-only")
+      if [[ $# -lt 2 ]]; then
+        echo "--verify-modified-headers-only requires an argument."
+        exit 1
+      fi
+      shift
+      KERNEL_DIR="$1"
+      KERNEL_DOWNLOAD=0
+      VERIFY_HEADERS_ONLY=1
+      ;;
     "-h" | "--help")
       usage
       exit 1
@@ -183,6 +197,14 @@
   src_dir="common"
 fi
 
+if [[ ${VERIFY_HEADERS_ONLY} -eq 1 ]]; then
+  # Verify if modified headers have changed.
+  verify_modified_hdrs "${KERNEL_DIR}/${src_dir}/include/scsi" \
+                       "${ANDROID_KERNEL_DIR}/scsi" \
+                       "${KERNEL_DIR}/${src_dir}"
+  exit 0
+fi
+
 if [[ ${KERNEL_DOWNLOAD} -eq 1 ]]; then
   TMPDIR=$(mktemp -d /tmp/android_kernelXXXXXXXX)
   cd "${TMPDIR}"
@@ -202,6 +224,9 @@
 fi
 
 if [[ ${SKIP_GENERATION} -eq 0 ]]; then
+  # Clean up any leftover headers.
+  make distclean
+
   # Build all of the generated headers.
   for arch in "${ARCH_LIST[@]}"; do
     echo "Generating headers for arch ${arch}"
@@ -209,6 +234,11 @@
   done
 fi
 
+# Completely delete the old original headers so that any deleted/moved
+# headers are also removed.
+rm -rf "${ANDROID_KERNEL_DIR}/uapi"
+mkdir -p "${ANDROID_KERNEL_DIR}/uapi"
+
 cd ${ANDROID_BUILD_TOP}
 
 # Copy all of the include/uapi files to the kernel headers uapi directory.
@@ -237,7 +267,12 @@
                  "${ANDROID_KERNEL_DIR}/uapi/asm-${arch}/asm"
 done
 
+# The arm types.h uapi header is not properly being generated, so copy it
+# directly.
+cp "${KERNEL_DIR}/${src_dir}/include/uapi/asm-generic/types.h" \
+   "${ANDROID_KERNEL_DIR}/uapi/asm-arm/asm"
+
 # Verify if modified headers have changed.
-check_hdrs "${KERNEL_DIR}/${src_dir}/include/scsi" \
-           "${ANDROID_KERNEL_DIR}/scsi" \
-           "${KERNEL_DIR}/${src_dir}"
+verify_modified_hdrs "${KERNEL_DIR}/${src_dir}/include/scsi" \
+                     "${ANDROID_KERNEL_DIR}/scsi" \
+                     "${KERNEL_DIR}/${src_dir}"
diff --git a/libc/kernel/tools/update_all.py b/libc/kernel/tools/update_all.py
index 7f3657c..5031168 100755
--- a/libc/kernel/tools/update_all.py
+++ b/libc/kernel/tools/update_all.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess
+import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess, shutil
 from defaults import *
 from utils import *
 
@@ -20,7 +20,7 @@
         android tree
 
       - the clean headers will be placed in 'bionic/libc/kernel/arch-<arch>/asm',
-        'bionic/libc/kernel/common', etc..
+        'bionic/libc/kernel/android', etc..
 """ % { "progname" : os.path.basename(sys.argv[0]) }
     sys.exit(0)
 
@@ -75,7 +75,13 @@
 for arch in kernel_archs:
     b.readDir(os.path.join(kernel_dir, "arch-%s" % arch))
 
-b.readDir(os.path.join(kernel_dir, "common"))
+b.readDir(os.path.join(kernel_dir, "android"))
+
+# Delete the old uapi headers before updating to handle headers that
+# get moved/deleted.
+uapi_dir = os.path.join(get_kernel_dir(), "uapi")
+shutil.rmtree(uapi_dir)
+os.mkdir(uapi_dir, 0755)
 
 oldlen = 120
 android_root_len = len(get_android_root()) + 1