diff --git a/.config b/.config
new file mode 100644
index 0000000000000000000000000000000000000000..22e416f67b0b298aa282555abbf6b01040c480df
--- /dev/null
+++ b/.config
@@ -0,0 +1,48 @@
+
+if [[ -z "${TARGET_PRODUCT}" ]]; then
+   echo "Error: TARGET_PRODUCT not defined.  Looks like you need some |lunch|"
+   exit 1
+fi
+
+cd ${ANDROID_BUILD_TOP}
+B2G_HOME=$PWD
+
+TOOLCHAIN_PREFIX=${ANDROID_TOOLCHAIN}/$(test -x ${ANDROID_TOOLCHAIN}/arm-eabi-gcc && echo arm-eabi- || echo arm-linux-androideabi-)
+GDB=${TOOLCHAIN_PREFIX}gdb
+
+DEVICE=${TARGET_PRODUCT}
+GECKO_PATH=${ANDROID_BUILD_TOP}/gecko
+GAIA_PATH=${ANDROID_BUILD_TOP}/gaia
+
+# TODO: GECKO_OBJDIR must match that in gonk-misc/Android.mk.  Fragile.
+GECKO_OBJDIR=out/target/product/${DEVICE}/obj/objdir-gecko
+
+
+flash_fastboot_ext4()
+{
+	$ADB reboot bootloader
+	$FASTBOOT devices
+
+	if [ $? -ne 0 ]; then
+		echo Couldn\'t setup fastboot
+		return -1
+	fi
+	case $1 in
+	"system" | "boot" | "userdata" | "persist")
+		$FASTBOOT flash $1 out/target/product/$DEVICE/$1.img.ext4 &&
+		$FASTBOOT reboot
+		;;
+
+	*)
+		$FASTBOOT erase cache &&
+		$FASTBOOT erase userdata &&
+		$FASTBOOT flash userdata out/target/product/$DEVICE/userdata.img.ext4 &&
+		$FASTBOOT flash boot out/target/product/$DEVICE/boot.img &&
+		$FASTBOOT flash system out/target/product/$DEVICE/system.img.ext4 &&
+		$FASTBOOT flash persist out/target/product/$DEVICE/persist.img.ext4 &&
+		$FASTBOOT reboot
+		;;
+	esac
+}
+
+eval "flash_${DEVICE}() { flash_fastboot_ext4 $1; }"
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..9fd21937516405d148c101d45d853225111308cc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/lastpatch.md5sum
+/mozilla-b2g/
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000000000000000000000000000000000000..195fcb76fe3d747d8f98c041770d5a9f4768fbbe
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,23 @@
+
+# If this is not a user/userdebug build redefine GAIA_DOMAIN away from
+# gaiamobile.org to prevent the UI from automatically updating itself,
+# which can be somewhat undesirable while in the middle of a debug session.
+ifeq (,$(filter userdebug user,$(TARGET_BUILD_VARIANT)))
+GAIA_DOMAIN?=privategaia.tld
+# 'export' need to propagate the variable into the Gaia sub-make
+export GAIA_DOMAIN
+endif
+
+
+LOCAL_PATH:= $(call my-dir)
+
+FAKETOOLS_DX := $(abspath $(LOCAL_PATH)/faketools/dx)
+FAKETOOLS_AAPT := $(abspath $(LOCAL_PATH)/faketools/aapt)
+
+$(DX):
+	mkdir -p $(@D)
+	ln -sf $(FAKETOOLS_DX) $@
+
+$(AAPT):
+	mkdir -p $(@D)
+	ln -sf $(FAKETOOLS_AAPT) $@
diff --git a/b2g_product.mk b/b2g_product.mk
new file mode 100644
index 0000000000000000000000000000000000000000..20e036a6a1dcf1032a92b7dfd427a0a38fa01b03
--- /dev/null
+++ b/b2g_product.mk
@@ -0,0 +1,5 @@
+
+HTTP=android#  Disable chrome HTTP stack in frameworks/base/media/libstagefright/Android.mk
+
+PRODUCT_PACKAGES += rilproxy init.b2g.rc httpd.conf fakeperm mountvol.sh gaia gecko
+
diff --git a/faketools/aapt b/faketools/aapt
new file mode 100755
index 0000000000000000000000000000000000000000..348e91f928c35a779b7a4f93779813514b588f3f
--- /dev/null
+++ b/faketools/aapt
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo Fake aapt.
diff --git a/faketools/dx b/faketools/dx
new file mode 100755
index 0000000000000000000000000000000000000000..f59838613d60e45639888b602f9ff76ba87abecb
--- /dev/null
+++ b/faketools/dx
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+echo Fake dx.
+
+while [[ -n "$1" ]]; do
+   if [[ "${1#--output=}" != "$1" ]]; then
+      echo touch ${1#--output=}
+      touch ${1#--output=}
+   fi
+   shift
+done
diff --git a/faketools/jdk/bin/jar b/faketools/jdk/bin/jar
new file mode 100755
index 0000000000000000000000000000000000000000..d037e8ad81df3786734d773e462be620d9042cb1
--- /dev/null
+++ b/faketools/jdk/bin/jar
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+echo jar fake 1.6.0
+
+while [[ -n "$1" ]]; do
+   if [[ "${1%%.jar}" != "$1" ]]; then
+      touch dummy
+      zip -q $1 dummy
+   fi
+   if [[ "${1%%.apk}" != "$1" ]]; then
+      touch dummy
+      zip -q $1 dummy
+   fi
+   shift
+done
diff --git a/faketools/jdk/bin/java b/faketools/jdk/bin/java
new file mode 100755
index 0000000000000000000000000000000000000000..86140b4e385c4f0f8e1083f231e6c67b59f54716
--- /dev/null
+++ b/faketools/jdk/bin/java
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+echo java fake 1.6.0
+
+while [[ -n "$1" ]]; do
+   if [[ "${1%%.jar}" != "$1" ]]; then
+      touch dummy
+      zip -q $1 dummy
+   fi
+   if [[ "${1%%.apk.signed}" != "$1" ]]; then
+      touch dummy
+      zip -q $1 dummy
+   fi
+   shift
+done
diff --git a/faketools/jdk/bin/javac b/faketools/jdk/bin/javac
new file mode 100755
index 0000000000000000000000000000000000000000..ee1c228b63cd021feadeb58c80b58e8eb756f16b
--- /dev/null
+++ b/faketools/jdk/bin/javac
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo javac fake 1.6.0
diff --git a/faketools/jdk/bin/javadoc b/faketools/jdk/bin/javadoc
new file mode 100755
index 0000000000000000000000000000000000000000..39c6fb0162f380221cdc27e761d38ee721e129a4
--- /dev/null
+++ b/faketools/jdk/bin/javadoc
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo javadoc fake 1.6.0
diff --git a/faketools/jdk/lib/tools.jar b/faketools/jdk/lib/tools.jar
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/flash.sh b/flash.sh
new file mode 120000
index 0000000000000000000000000000000000000000..2e074612f0bd661d1cc12d34f8088ba8bace267e
--- /dev/null
+++ b/flash.sh
@@ -0,0 +1 @@
+mozilla-b2g/flash.sh
\ No newline at end of file
diff --git a/keymaps/generic.idc b/keymaps/generic.idc
new file mode 100644
index 0000000000000000000000000000000000000000..97ef51518191c4cd62386662c8117ab6af1648af
--- /dev/null
+++ b/keymaps/generic.idc
@@ -0,0 +1,2 @@
+touch.deviceType = touchScreen
+touch.orientationAware = 1
diff --git a/keymaps/keymaps.mk b/keymaps/keymaps.mk
new file mode 100644
index 0000000000000000000000000000000000000000..4bfefb372f2ca1c591a3c9ccd467dd24ff9fd833
--- /dev/null
+++ b/keymaps/keymaps.mk
@@ -0,0 +1,13 @@
+
+# QRD7x27a_SKU1 touchscreen config
+PRODUCT_COPY_FILES += device/qcom/b2g_common/keymaps/generic.idc:system/usr/idc/sensor00fn11.idc
+
+# QRD7x27a_SKU3 touchscreen config
+PRODUCT_COPY_FILES += device/qcom/b2g_common/keymaps/generic.idc:system/usr/idc/ft5x0x_ts.idc
+
+# 8960 LIQUID
+PRODUCT_COPY_FILES += device/qcom/b2g_common/keymaps/generic.idc:system/usr/idc/atmel_mxt_ts.idc
+
+# 7x27a_ffa
+PRODUCT_COPY_FILES += device/qcom/b2g_common/keymaps/generic.idc:system/usr/idc/Atmel_maXTouch_Touchscreen_controller.idc
+
diff --git a/patch/all/dalvik/remove-dx.sh b/patch/all/dalvik/remove-dx.sh
new file mode 100644
index 0000000000000000000000000000000000000000..8f5e7820ce1bff0481e0560639d185ebdb381d81
--- /dev/null
+++ b/patch/all/dalvik/remove-dx.sh
@@ -0,0 +1,2 @@
+echo > dx/Android.mk
+git_add dx/Android.mk
diff --git a/patch/all/device/qcom/b2g_common/mozilla-b2g/TLS-improvements.patch b/patch/all/device/qcom/b2g_common/mozilla-b2g/TLS-improvements.patch
new file mode 100644
index 0000000000000000000000000000000000000000..5b1f82f7b92575346e0bf486d815fa8d1bcf3542
--- /dev/null
+++ b/patch/all/device/qcom/b2g_common/mozilla-b2g/TLS-improvements.patch
@@ -0,0 +1,46 @@
+diff --git a/flash.sh b/flash.sh
+index fe7d3cd..d35efcb 100755
+--- a/flash.sh
++++ b/flash.sh
+@@ -90,6 +90,11 @@ case "$1" in
+ 	make -C gaia install-gaia
+ 	exit $?
+ 	;;
++
++"time")
++	update_time
++	exit $?
++	;;
+ esac
+ 
+ case "$DEVICE" in
+@@ -108,7 +113,11 @@ case "$DEVICE" in
+ 	;;
+ 
+ *)
+-	echo Unsupported device \"$DEVICE\", can\'t flash
+-	exit -1
++	if [[ $(type -t flash_${DEVICE}) = function ]]; then
++		flash_${DEVICE} $1
++	else
++		echo Unsupported device \"$DEVICE\", can\'t flash
++		exit -1
++	fi
+ 	;;
+ esac
+diff --git a/run-gdb.sh b/run-gdb.sh
+index 3a44fbd..4ade5c4 100755
+--- a/run-gdb.sh
++++ b/run-gdb.sh
+@@ -8,7 +8,7 @@ fi
+ 
+ ADB=adb
+ GDB_PORT=22576
+-GDB=prebuilt/`uname -s | tr "[[:upper:]]" "[[:lower:]]"`-x86/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-gdb
++: ${GDB:=prebuilt/`uname -s | tr "[[:upper:]]" "[[:lower:]]"`-x86/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-gdb}
+ B2G_BIN=/system/b2g/b2g
+ GDBINIT=/tmp/b2g.gdbinit.`whoami`
+ 
+-- 
+1.7.8.3
+
diff --git a/patch/all/frameworks/base/remove-aapt.sh b/patch/all/frameworks/base/remove-aapt.sh
new file mode 100644
index 0000000000000000000000000000000000000000..12e47049c90c0b4f33b3256344281af916bd4d57
--- /dev/null
+++ b/patch/all/frameworks/base/remove-aapt.sh
@@ -0,0 +1 @@
+git_rm $(find tools/aapt -name Android.mk)
diff --git a/patch/all/frameworks/base/remove-tests.sh b/patch/all/frameworks/base/remove-tests.sh
new file mode 100644
index 0000000000000000000000000000000000000000..038592ba71f9ee6242a6f12c8ce4320fc7f8b793
--- /dev/null
+++ b/patch/all/frameworks/base/remove-tests.sh
@@ -0,0 +1 @@
+git_rm $(find tests -name Android.mk)
diff --git a/patch/gb/device/qcom/common/device-qcom-common.patch b/patch/gb/device/qcom/common/device-qcom-common.patch
new file mode 100644
index 0000000000000000000000000000000000000000..d8b976b7c210cfd58add9f0c3a2ae13c992e54dd
--- /dev/null
+++ b/patch/gb/device/qcom/common/device-qcom-common.patch
@@ -0,0 +1,15 @@
+diff --git a/common.mk b/common.mk
+index e616489..3a3b1cd 100644
+--- a/common.mk
++++ b/common.mk
+@@ -170,3 +170,7 @@ PRODUCT_PROPERTY_OVERRIDES += \
+     ro.vendor.extension_library=/system/lib/libqc-opt.so
+ 
+ PRODUCT_PRIVATE_KEY := device/qcom/common/qcom.key
++
++$(call inherit-product, device/qcom/b2g_common/b2g_product.mk)
++include device/qcom/b2g_common/keymaps/keymaps.mk
++TARGET_PROVIDES_B2G_INIT_RC=true
+-- 
+1.7.8.3
+
diff --git a/patch/gb/external/clearsilver/clearsilver-stub.sh b/patch/gb/external/clearsilver/clearsilver-stub.sh
new file mode 100644
index 0000000000000000000000000000000000000000..b4a1d7367898ffecb4916261a7bc2936261ff049
--- /dev/null
+++ b/patch/gb/external/clearsilver/clearsilver-stub.sh
@@ -0,0 +1,6 @@
+cat > Android.mk <<-EOF
+\$(HOST_OUT_JAVA_LIBRARIES)/dx.jar:                   ; mkdir -p \$(@D) && touch \$@
+\$(HOST_OUT_SHARED_LIBRARIES)/libclearsilver-jni.so:  ; mkdir -p \$(@D) && touch \$@
+\$(HOST_OUT_JAVA_LIBRARIES)/clearsilver.jar:          ; mkdir -p \$(@D) && touch \$@
+EOF
+git_add Android.mk
diff --git a/patch/gb/frameworks/base/frameworks-base.patch b/patch/gb/frameworks/base/frameworks-base.patch
new file mode 100644
index 0000000000000000000000000000000000000000..3f650eab700fff75e98b7a1aa0c749a27957955f
--- /dev/null
+++ b/patch/gb/frameworks/base/frameworks-base.patch
@@ -0,0 +1,57 @@
+diff --git a/cmds/app_process/Android.mk b/cmds/app_process/Android.mk
+index 2391b72..6f033b5 100644
+--- a/cmds/app_process/Android.mk
++++ b/cmds/app_process/Android.mk
+@@ -1,5 +1,6 @@
+ LOCAL_PATH:= $(call my-dir)
+ include $(CLEAR_VARS)
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_SRC_FILES:= \
+ 	app_main.cpp
+diff --git a/cmds/surfaceflinger/Android.mk b/cmds/surfaceflinger/Android.mk
+index 1df32bb..aa290b8 100644
+--- a/cmds/surfaceflinger/Android.mk
++++ b/cmds/surfaceflinger/Android.mk
+@@ -1,5 +1,6 @@
+ LOCAL_PATH:= $(call my-dir)
+ include $(CLEAR_VARS)
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_SRC_FILES:= \
+ 	main_surfaceflinger.cpp 
+diff --git a/include/utils/String16.h b/include/utils/String16.h
+index 07a0c11..1a6ce23 100644
+--- a/include/utils/String16.h
++++ b/include/utils/String16.h
+@@ -26,8 +26,10 @@
+ // ---------------------------------------------------------------------------
+ 
+ extern "C" {
+-
++// char32_t and char16_t are built-in types as of c++0x.
++#if !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
+ typedef uint16_t char16_t;
++#endif
+ 
+ // Standard string functions on char16 strings.
+ int strcmp16(const char16_t *, const char16_t *);
+diff --git a/include/utils/String8.h b/include/utils/String8.h
+index ef0b51a..8917e5c 100644
+--- a/include/utils/String8.h
++++ b/include/utils/String8.h
+@@ -30,8 +30,10 @@
+ // ---------------------------------------------------------------------------
+ 
+ extern "C" {
+-
++// char32_t and char16_t are built-in types as of c++0x.
++#if !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
+ typedef uint32_t char32_t;
++#endif
+ 
+ size_t strlen32(const char32_t *);
+ size_t strnlen32(const char32_t *, size_t);
+-- 
+1.7.8.3
+
diff --git a/patch/gb/gonk-misc/stubout-Unicode.h.sh b/patch/gb/gonk-misc/stubout-Unicode.h.sh
new file mode 100644
index 0000000000000000000000000000000000000000..f3dabefe42ddb6d62a9f1a15f56d1270b2ba2f2e
--- /dev/null
+++ b/patch/gb/gonk-misc/stubout-Unicode.h.sh
@@ -0,0 +1,3 @@
+# Unicode.h conflicts with GB string headers
+echo > Unicode.h
+git_add Unicode.h
diff --git a/patch/gb/system/core/dhcpcd_ip_default_route.patch b/patch/gb/system/core/dhcpcd_ip_default_route.patch
new file mode 100644
index 0000000000000000000000000000000000000000..518179e9f9adedf8cde0c046ad51c9c9246d475e
--- /dev/null
+++ b/patch/gb/system/core/dhcpcd_ip_default_route.patch
@@ -0,0 +1,16 @@
+diff --git a/rootdir/etc/init.qcom.rc b/rootdir/etc/init.qcom.rc
+index c11c0c9..ed273a9 100755
+--- a/rootdir/etc/init.qcom.rc
++++ b/rootdir/etc/init.qcom.rc
+@@ -244,7 +244,7 @@ service wpa_supplicant /system/bin/logwrapper /system/bin/wpa_supplicant -Dwext
+     disabled
+     oneshot
+ 
+-service dhcpcd_wlan0 /system/bin/dhcpcd -BKLG wlan0
++service dhcpcd_wlan0 /system/bin/dhcpcd -BKL wlan0
+     disabled
+     oneshot
+ 
+-- 
+1.7.8.3
+
diff --git a/patch/gb/system/core/system-core.patch b/patch/gb/system/core/system-core.patch
new file mode 100644
index 0000000000000000000000000000000000000000..84fe08c16062cca51213e65f869f89893cf2e653
--- /dev/null
+++ b/patch/gb/system/core/system-core.patch
@@ -0,0 +1,46 @@
+diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
+index 176f306..778a9d3 100755
+--- a/include/private/android_filesystem_config.h
++++ b/include/private/android_filesystem_config.h
+@@ -163,6 +163,8 @@ static struct fs_path_config android_dirs[] = {
+ ** and will allow partial matches.
+ */
+ static struct fs_path_config android_files[] = {
++    { 00775, AID_ROOT,      AID_ROOT,      "system/b2g/b2g" },
++    { 00775, AID_ROOT,      AID_ROOT,      "system/b2g/updater" },
+     { 00440, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.rc" },
+     { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.sh" },
+     { 00755, AID_SYSTEM,      AID_SYSTEM,      "system/etc/init.qcom.sdio.sh" },
+diff --git a/rootdir/init.rc b/rootdir/init.rc
+index 051f8cb..3af5d32 100644
+--- a/rootdir/init.rc
++++ b/rootdir/init.rc
+@@ -1,5 +1,6 @@
+ on early-init
+     start ueventd
++    import /init.b2g.rc
+ 
+ on init
+ 
+@@ -9,7 +10,9 @@ loglevel 3
+ 
+ # setup the global environment
+     export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
+-    export LD_LIBRARY_PATH /vendor/lib:/system/lib
++    export TMPDIR /data/local/tmp
++    export LD_LIBRARY_PATH /vendor/lib:/system/lib:/system/b2g
++    export GRE_HOME /system/b2g
+     export ANDROID_BOOTLOGO 1
+     export ANDROID_ROOT /system
+     export ANDROID_ASSETS /system/app
+@@ -317,6 +320,7 @@ on boot
+     write /proc/sys/net/core/wmem_max  1220608
+ 
+     class_start default
++    class_start main
+ 
+ ## Daemon processes to be run by init.
+ ##
+-- 
+1.7.8.3
+
diff --git a/patch/ics/build/build.patch b/patch/ics/build/build.patch
new file mode 100644
index 0000000000000000000000000000000000000000..85c097f45a998f91ac4626b171055dd6e90402db
--- /dev/null
+++ b/patch/ics/build/build.patch
@@ -0,0 +1,75 @@
+diff --git a/core/java.mk b/core/java.mk
+index 1cde62b..41d4649 100644
+--- a/core/java.mk
++++ b/core/java.mk
+@@ -194,6 +194,7 @@ endif
+ # common_java.mk, and moving the include of base_rules.mk to
+ # after all the declarations.
+ 
++LOCAL_UNINSTALLABLE_MODULE:=true
+ #######################################
+ include $(BUILD_SYSTEM)/base_rules.mk
+ #######################################
+diff --git a/core/notice_files.mk b/core/notice_files.mk
+index 74beb49..06621d4 100644
+--- a/core/notice_files.mk
++++ b/core/notice_files.mk
+@@ -34,7 +34,7 @@ else
+       module_installed_filename := \
+           $(patsubst $(PRODUCT_OUT)%,%,$($(my_prefix)OUT_JAVA_LIBRARIES))/$(module_leaf)
+     else
+-      $(error Cannot determine where to install NOTICE file for $(LOCAL_MODULE))
++      $(info Cannot determine where to install NOTICE file for $(LOCAL_MODULE))
+     endif # JAVA_LIBRARIES
+   endif # STATIC_LIBRARIES
+ endif
+diff --git a/target/product/core.mk b/target/product/core.mk
+index abb2d9f..0e5afb1 100644
+--- a/target/product/core.mk
++++ b/target/product/core.mk
+@@ -23,43 +23,10 @@ PRODUCT_PROPERTY_OVERRIDES := \
+     ro.config.alarm_alert=Alarm_Classic.ogg
+ 
+ PRODUCT_PACKAGES := \
+-    ApplicationsProvider \
+-    BackupRestoreConfirmation \
+-    Browser \
+-    Contacts \
+-    ContactsProvider \
+-    DefaultContainerService \
+-    DownloadProvider \
+-    DownloadProviderUi \
+-    HTMLViewer \
+-    Home \
+-    KeyChain \
+-    MediaProvider \
+-    PackageInstaller \
+-    PicoTts \
+-    SettingsProvider \
+-    SharedStorageBackup \
+-    TelephonyProvider \
+-    UserDictionaryProvider \
+-    VpnDialogs \
+-    apache-xml \
+-    bouncycastle \
+     bu \
+     cacerts \
+-    com.android.location.provider \
+-    com.android.location.provider.xml \
+-    core \
+-    core-junit \
+-    dalvikvm \
+-    dexdeps \
+-    dexdump \
+-    dexlist \
+-    dexopt \
+     dmtracedump \
+     dx \
+-    ext \
+-    filterfw \
+-    framework-res \
+     hprof-conv \
+     icu.dat \
+     installd \
+-- 
+1.7.6
diff --git a/patch/ics/development/remove-samples.sh b/patch/ics/development/remove-samples.sh
new file mode 100644
index 0000000000000000000000000000000000000000..9e1f4b2728f1c8df0ec5a4a2912a1e8c92c150ab
--- /dev/null
+++ b/patch/ics/development/remove-samples.sh
@@ -0,0 +1 @@
+git_rm $(find samples -name Android.mk)
diff --git a/patch/ics/device/qcom/common/device-qcom-common.patch b/patch/ics/device/qcom/common/device-qcom-common.patch
new file mode 100644
index 0000000000000000000000000000000000000000..91f1c717261dadc194028da1ee7dd5795cfb2ffb
--- /dev/null
+++ b/patch/ics/device/qcom/common/device-qcom-common.patch
@@ -0,0 +1,19 @@
+
+---
+ common.mk |    1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
+
+diff --git a/common.mk b/common.mk
+index 744a9ea..e4c2505 100755
+--- a/common.mk
++++ b/common.mk
+@@ -478,3 +478,6 @@ PRODUCT_PRIVATE_KEY := device/qcom/common/qcom.key
+ $(call inherit-product, frameworks/base/build/phone-xhdpi-1024-dalvik-heap.mk)
+ $(call inherit-product, frameworks/base/data/fonts/fonts.mk)
+ $(call inherit-product, frameworks/base/data/keyboards/keyboards.mk)
++$(call inherit-product, device/qcom/b2g_common/b2g_product.mk)
++include device/qcom/b2g_common/keymaps/keymaps.mk
++TARGET_PROVIDES_B2G_INIT_RC=true
+-- 
+1.7.6
+
diff --git a/patch/ics/frameworks/base/frameworks-base.patch b/patch/ics/frameworks/base/frameworks-base.patch
new file mode 100644
index 0000000000000000000000000000000000000000..1a74f64927be0d3cd6a2658ea2bbad8a1deefb7c
--- /dev/null
+++ b/patch/ics/frameworks/base/frameworks-base.patch
@@ -0,0 +1,105 @@
+diff --git a/Android.mk b/Android.mk
+index 62bb2e5..2819ad6 100644
+--- a/Android.mk
++++ b/Android.mk
+@@ -227,6 +227,7 @@ LOCAL_NO_STANDARD_LIBRARIES := true
+ LOCAL_JAVA_LIBRARIES := bouncycastle core core-junit ext
+ 
+ LOCAL_MODULE := framework
++LOCAL_MODULE_TAGS := optional
+ LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+ 
+ LOCAL_NO_EMMA_INSTRUMENT := true
+diff --git a/cmds/app_process/Android.mk b/cmds/app_process/Android.mk
+index 2391b72..6f033b5 100644
+--- a/cmds/app_process/Android.mk
++++ b/cmds/app_process/Android.mk
+@@ -1,5 +1,6 @@
+ LOCAL_PATH:= $(call my-dir)
+ include $(CLEAR_VARS)
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_SRC_FILES:= \
+ 	app_main.cpp
+diff --git a/cmds/stagefright/Android.mk b/cmds/stagefright/Android.mk
+index bf2c41f..e76640e 100644
+--- a/cmds/stagefright/Android.mk
++++ b/cmds/stagefright/Android.mk
+@@ -1,6 +1,7 @@
+ LOCAL_PATH:= $(call my-dir)
+ 
+ include $(CLEAR_VARS)
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_SRC_FILES:=       \
+ 	stagefright.cpp \
+diff --git a/cmds/surfaceflinger/Android.mk b/cmds/surfaceflinger/Android.mk
+index 1df32bb..aa290b8 100644
+--- a/cmds/surfaceflinger/Android.mk
++++ b/cmds/surfaceflinger/Android.mk
+@@ -1,5 +1,6 @@
+ LOCAL_PATH:= $(call my-dir)
+ include $(CLEAR_VARS)
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_SRC_FILES:= \
+ 	main_surfaceflinger.cpp 
+diff --git a/cmds/system_server/Android.mk b/cmds/system_server/Android.mk
+index ad53797..c0db0f0 100644
+--- a/cmds/system_server/Android.mk
++++ b/cmds/system_server/Android.mk
+@@ -1,5 +1,6 @@
+ LOCAL_PATH:= $(call my-dir)
+ include $(CLEAR_VARS)
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_SRC_FILES:= \
+ 	system_main.cpp
+diff --git a/cmds/system_server/library/Android.mk b/cmds/system_server/library/Android.mk
+index e8afce3..615b52d 100644
+--- a/cmds/system_server/library/Android.mk
++++ b/cmds/system_server/library/Android.mk
+@@ -1,5 +1,6 @@
+ LOCAL_PATH:= $(call my-dir)
+ include $(CLEAR_VARS)
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_SRC_FILES:= \
+ 	system_init.cpp
+diff --git a/services/java/Android.mk b/services/java/Android.mk
+index dffc467..e02f16e 100644
+--- a/services/java/Android.mk
++++ b/services/java/Android.mk
+@@ -12,6 +12,7 @@ LOCAL_SRC_FILES := \
+ LOCAL_MODULE:= services
+ 
+ LOCAL_JAVA_LIBRARIES := android.policy
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_NO_EMMA_INSTRUMENT := true
+ LOCAL_NO_EMMA_COMPILE := true
+diff --git a/services/jni/Android.mk b/services/jni/Android.mk
+index 4ae8351..ae92ed7 100644
+--- a/services/jni/Android.mk
++++ b/services/jni/Android.mk
+@@ -1,5 +1,6 @@
+ LOCAL_PATH:= $(call my-dir)
+ include $(CLEAR_VARS)
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_SRC_FILES:= \
+     com_android_server_AlarmManagerService.cpp \
+diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk
+index 366cacb..ad71698 100644
+--- a/services/surfaceflinger/Android.mk
++++ b/services/surfaceflinger/Android.mk
+@@ -1,5 +1,6 @@
+ LOCAL_PATH:= $(call my-dir)
+ include $(CLEAR_VARS)
++LOCAL_MODULE_TAGS := optional
+ 
+ LOCAL_SRC_FILES:= \
+     Layer.cpp 								\
+-- 
+1.7.8.3
+
diff --git a/patch/ics/frameworks/base/remove-chromium_http.sh b/patch/ics/frameworks/base/remove-chromium_http.sh
new file mode 100644
index 0000000000000000000000000000000000000000..6b40c648f65cc92af05aedbcaad0dfb91d901741
--- /dev/null
+++ b/patch/ics/frameworks/base/remove-chromium_http.sh
@@ -0,0 +1,5 @@
+if [[ -d media/libstagefright/chromium_http ]]; then
+   # chromium_http fails to compile when the chrome HTTP stack is
+   # disabled...
+   git_rm media/libstagefright/chromium_http/Android.mk
+fi
diff --git a/patch/ics/frameworks/base/remove-media-files.sh b/patch/ics/frameworks/base/remove-media-files.sh
new file mode 100644
index 0000000000000000000000000000000000000000..f85166144170d3aa9e6b6996107f8c0e627f7f56
--- /dev/null
+++ b/patch/ics/frameworks/base/remove-media-files.sh
@@ -0,0 +1,6 @@
+# Remove unused media files from system image
+echo > data/videos/VideoPackage1.mk
+git_add data/videos/VideoPackage1.mk
+echo > data/sounds/OriginalAudio.mk
+git_add data/sounds/OriginalAudio.mk
+git_rm data/sounds/AllAudio.mk
diff --git a/patch/ics/system/core/dhcpcd_ip_default_route.patch b/patch/ics/system/core/dhcpcd_ip_default_route.patch
new file mode 100644
index 0000000000000000000000000000000000000000..d6a6446c4382b6d869bcbaa193133fda9ec96e4e
--- /dev/null
+++ b/patch/ics/system/core/dhcpcd_ip_default_route.patch
@@ -0,0 +1,15 @@
+diff --git a/rootdir/etc/init.qcom.rc b/rootdir/etc/init.qcom.rc
+index eea81cc..e3292a1 100755
+--- a/rootdir/etc/init.qcom.rc
++++ b/rootdir/etc/init.qcom.rc
+@@ -318,7 +318,7 @@ service wpa_supplicant /system/bin/logwrapper /system/bin/wpa_supplicant -Dnl802
+     disabled
+     oneshot
+ 
+-service dhcpcd_wlan0 /system/bin/dhcpcd -ABKLG
++service dhcpcd_wlan0 /system/bin/dhcpcd -ABKL
+     class late_start
+     disabled
+     oneshot
+-- 
+1.7.6
diff --git a/patch/ics/system/core/system-core.patch b/patch/ics/system/core/system-core.patch
new file mode 100644
index 0000000000000000000000000000000000000000..60f697b32b767ca9b746bf6dfacb0c6a493b63d1
--- /dev/null
+++ b/patch/ics/system/core/system-core.patch
@@ -0,0 +1,38 @@
+system/core adaptations for Boot2Gecko.
+
+diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
+index 8defc8e..2f056cf 100755
+--- a/include/private/android_filesystem_config.h
++++ b/include/private/android_filesystem_config.h
+@@ -178,6 +178,8 @@ static struct fs_path_config android_dirs[] = {
+ ** and will allow partial matches.
+ */
+ static struct fs_path_config android_files[] = {
++    { 00775, AID_ROOT,      AID_ROOT,      "system/b2g/b2g" },
++    { 00775, AID_ROOT,      AID_ROOT,      "system/b2g/updater" },
+     { 00440, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.rc" },
+     { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.sh" },
+     { 00777, AID_SYSTEM,    AID_SYSTEM,    "system/etc/init.qcom.sdio.sh" },
+diff --git a/rootdir/init.rc b/rootdir/init.rc
+index 6754c4e..cb92e5f 100644
+--- a/rootdir/init.rc
++++ b/rootdir/init.rc
+@@ -6,6 +6,7 @@ on early-init
+
+ # create mountpoints
+     mkdir /mnt 0775 root system
++    import /init.b2g.rc
+
+ on init
+
+@@ -15,7 +16,6 @@ loglevel 3
+ 
+ # setup the global environment
+     export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
+-    export LD_LIBRARY_PATH /vendor/lib:/system/lib
+     export ANDROID_BOOTLOGO 1
+     export ANDROID_ROOT /system
+     export ANDROID_ASSETS /system/app
+-- 
+1.7.6
+
diff --git a/run-gdb.sh b/run-gdb.sh
new file mode 120000
index 0000000000000000000000000000000000000000..cf3d30320e5cf3a89162e1633b9630a7c6a2a4f5
--- /dev/null
+++ b/run-gdb.sh
@@ -0,0 +1 @@
+mozilla-b2g/run-gdb.sh
\ No newline at end of file
diff --git a/treeid.sh b/treeid.sh
new file mode 100755
index 0000000000000000000000000000000000000000..51d620d023690f024344925c0685180f53f47434
--- /dev/null
+++ b/treeid.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# Attempt to identify the Android tree in use.
+#
+# On success, one or more tree identifiers are output to stdout
+
+# Relocate to the root of the Android tree
+
+if [[ ! ( -f build/envsetup.sh ) ]]; then
+   echo $0: Error: CWD does not look like the root of an Android tree. > /dev/stderr
+   exit 1
+fi
+
+
+if [[ -d device/samsung/maguro ]]; then
+   # Check if the ICS tree is the w1205 tree
+   if [[ -d device/qcom/msm7627a/.git ]]; then
+      if [[ "$(cd device/qcom/msm7627a && git log -n 1 --format="%H")" = "eaa6e2865691ffa55109c23edb97eef1ae5e2fde" ]] ; then
+         echo ics_w1205 ics all
+         exit
+      fi
+   fi
+
+   # Android ICS tree
+   echo ics all
+   exit
+fi
+
+# Android GB tree
+echo gb all
+exit
diff --git a/vendorsetup.sh b/vendorsetup.sh
new file mode 100644
index 0000000000000000000000000000000000000000..2f3c513381418a405e21fe05181c124eb28b8193
--- /dev/null
+++ b/vendorsetup.sh
@@ -0,0 +1,149 @@
+#
+# Environment variables influencing operation:
+#    B2G_TREE_ID - Defines the tree ID, used to determine which patches to
+#        apply.  If unset, |treeid.sh| is run to identify the tree
+#
+
+
+tree_md5sum()
+{
+   ( \
+      find device/qcom/b2g_common/patch -type f | \
+      xargs cat device/qcom/b2g_common/vendorsetup.sh device/qcom/b2g_common/treeid.sh; test -d .repo && repo manifest -r -o - 2>/dev/null \
+   ) | md5sum | cut -f1 -d\ 
+}
+
+patch_tree()
+{
+   (
+      cd $(gettop)
+      local TREE_ID=${B2G_TREE_ID:-$(device/qcom/b2g_common/treeid.sh)}
+      local PATCH_DIRS="vendor/qcom/proprietary/b2g_common/patch device/qcom/b2g_common/patch"
+
+      echo >> Android tree IDs: ${TREE_ID}
+      set -e
+      local LASTMD5SUM=invalid
+      test -f device/qcom/b2g_common/lastpatch.md5sum && LASTMD5SUM=$(cat device/qcom/b2g_common/lastpatch.md5sum 2>/dev/null)
+      echo -n ">> Checking for changes to B2G patches and/or manifest..."
+      MD5SUM=$(tree_md5sum)
+      if [[ "$LASTMD5SUM" != "$MD5SUM" ]]; then
+         echo "Change detected.  Applying B2G patches".
+         rm -f device/qcom/b2g_common/lastpatch.md5sum
+
+         if [[ -d .repo ]]; then
+            repo abandon b2g_autogen_ephemeral_branch || true
+         fi
+
+         branch() {
+            [[ -d $1 ]] || return 1
+
+            pushd $1 > /dev/null
+            echo
+            echo [entering $1]
+            if [[ -d .git ]]; then
+               # Try repo first, but if the project is not repo managed then
+               # use a raw git branch instead.
+               repo start b2g_autogen_ephemeral_branch .  ||
+                 ( git checkout master && \
+                   ( git branch -D b2g_autogen_ephemeral_branch || true ) && \
+                   git branch b2g_autogen_ephemeral_branch && \
+                   git checkout b2g_autogen_ephemeral_branch \
+                 )
+            else
+               read -p "Project $1 is not managed by git. Modify anyway?  [y/N] "
+               if [[ $REPLY != "y" ]]; then
+                  echo "No."
+                  popd > /dev/null
+                  return 1
+               fi
+            fi
+         }
+         apply() {
+            if [[ -d .git ]]; then
+               git apply --index $1
+            else
+               patch -p1 < $1
+            fi
+         }
+         git_rm() {
+            if [[ -d .git ]]; then
+               git rm -q $@
+            else
+               rm $@
+            fi
+         }
+         git_add() {
+            if [[ -d .git ]]; then
+               git add $@
+            fi
+         }
+         commit() {
+            if [[ -d .git ]]; then
+               git commit --all -m "B2G Adaptations" -q
+            fi
+            popd > /dev/null
+         }
+
+         # Find all of the patches for TREE_ID
+         # and collate them into an associative array
+         # indexed by project
+         declare -A PRJ_LIST
+         for DIR in ${PATCH_DIRS} ; do
+            for ID in ${TREE_ID} ; do
+               local D=${DIR}/${ID}
+               [[ -d $D ]] || continue
+               PATCHES=$(find $D -type f)
+               for P in ${PATCHES}; do
+                  PRJ=$(dirname ${P#${DIR}/${ID}/})
+                  PRJ_LIST[$PRJ]="${PRJ_LIST[$PRJ]} $P"
+               done
+            done
+         done
+
+         # Run through each project and apply patches
+         ROOT_DIR=${PWD}
+         for PRJ in ${!PRJ_LIST[*]} ; do
+            if branch ${PRJ} ; then
+               declare -A PATCHNAME
+               for P in ${PRJ_LIST[${PRJ}]} ; do
+                  # Skip patches that have already been applied by an earlier ID
+                  if [[ -n "${PATCHNAME[$(basename $P)]}" ]]; then continue; fi
+                  PATCHNAME[$(basename $P)]=1
+
+                  echo "  ${P}"
+                  case $P in
+                  *.patch)  apply ${ROOT_DIR}/$P ;;
+                  *.sh)     source ${ROOT_DIR}/$P ;;
+                  *)        echo Warning: Ignoring $P
+                  esac
+               done
+               commit
+            fi
+         done
+
+         echo
+         echo B2G patches applied.
+         echo $(tree_md5sum) > device/qcom/b2g_common/lastpatch.md5sum
+      else
+         echo no changes detected.
+      fi
+   )
+   return $?
+}
+
+# Stub out all java compilation.
+export JAVA_HOME=$(readlink -f device/qcom/b2g_common/faketools/jdk)
+
+patch_tree
+
+
+flash()
+{
+   ( cd $(gettop)/device/qcom/b2g_common && ./flash.sh $@ )
+}
+
+rungdb()
+{
+   ( cd $(gettop)/device/qcom/b2g_common && ./run-gdb.sh $@ )
+}
+