[Feature]add MT2731_MP2_MR2_SVN388 baseline version

Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/meta/meta-mediatek/recipes-support/ab-tools/abtools.bb b/meta/meta-mediatek/recipes-support/ab-tools/abtools.bb
new file mode 100644
index 0000000..8b2ed6a
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/ab-tools/abtools.bb
@@ -0,0 +1,63 @@
+DESCRIPTION = "A/B update package tools"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=562c740877935f40b262db8af30bca36"
+BBCLASSEXTEND = "native nativesdk"
+
+WORKONSRC = "${TOPDIR}/../src/support/ab_tools"
+OECMAKE_SOURCEPATH = "${S}"
+
+inherit workonsrc
+
+FILES_${PN}-dev = ""
+FILES_${PN} += "${libdir}"
+FILES_${PN} += "${bindir}"
+FILES_${PN} += "${datadir}"
+
+do_install_append() {
+	install -d ${D}${libdir}
+	install -d ${D}${bindir}
+	install -d ${D}${bindir}/lib/shflags
+	install -d ${D}${datadir}/abtools
+	install -d ${D}${datadir}/abtools/scripts
+	install -d ${D}${datadir}/abtools/scripts/lib/shflags
+	install -d ${D}${datadir}/abtools/lib
+	install -d ${D}${datadir}/abtools/security
+
+	install -m 0755 ${S}/security/testkey.pk8 ${D}${datadir}/abtools/security
+	install -m 0755 ${S}/security/testkey.x509.pem ${D}${datadir}/abtools/security
+
+	install -m 0755 ${S}/bin/delta_generator ${D}${bindir}
+	install -m 0755 ${S}/bin/signapk.jar ${D}${bindir}
+	install -m 0755 ${S}/bin/e2fsdroid ${D}${bindir}
+
+	install -m 0755 ${S}/scripts/brillo_update_payload ${D}${datadir}/abtools/scripts 
+	install -m 0755 ${S}/scripts/ota_from_target_files.py ${D}${datadir}/abtools/scripts
+	install -m 0755 ${S}/scripts/add_care_map_to_target_files.py ${D}${datadir}/abtools/scripts
+	install -m 0755 ${S}/scripts/common.py ${D}${datadir}/abtools/scripts
+	install -m 0755 ${S}/scripts/blockimgdiff.py ${D}${datadir}/abtools/scripts
+	install -m 0755 ${S}/scripts/rangelib.py ${D}${datadir}/abtools/scripts
+	install -m 0755 ${S}/scripts/edify_generator.py ${D}${datadir}/abtools/scripts
+	install -m 0755 ${S}/scripts/sparse_img.py ${D}${datadir}/abtools/scripts
+	install -m 0755 ${S}/scripts/lib/shflags/shflags ${D}${datadir}/abtools/scripts/lib/shflags
+
+	install -m 0644 ${S}/lib/libc++.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libbase.so ${D}${libdir} 
+	install -m 0644 ${S}/lib/libbrillo.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libbrillo-stream.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libchrome.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libcrypto_utils.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libcrypto-host.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libevent-host.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libext2fs-host.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/liblog.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libprotobuf-cpp-lite.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libsparse-host.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libssl-host.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libz-host.so  ${D}${libdir}
+	install -m 0644 ${S}/lib/libconscrypt_openjdk_jni.so  ${D}${libdir}
+}
+
+PATH_prepend = "${STAGING_DIR_NATIVE}${datadir}/abtools/scripts:"
+EXTRANATIVEPATH += ""
+
+
diff --git a/meta/meta-mediatek/recipes-support/bootctrl/bootctrl.bb b/meta/meta-mediatek/recipes-support/bootctrl/bootctrl.bb
new file mode 100644
index 0000000..2bbf7f4
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/bootctrl/bootctrl.bb
@@ -0,0 +1,25 @@
+inherit workonsrc autotools
+
+DESCRIPTION = "abupdate bootctrl"
+LICENSE = "MediaTekProprietary"
+# LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173fff"
+
+FILESEXTRAPATHS_prepend := "${THISDIR}:"
+
+WORKONSRC = "${TOPDIR}/../src/support/bootctrl"
+
+DEPENDS += "${@bb.utils.contains("BOOTDEV_TYPE", "nand", "nandapi", "", d)} libhardware libavb"
+
+EXTRA_OEMAKE = "NANDAPIDIR=${TOPDIR}/../src/support/libnandapi"
+
+INHIBIT_PACKAGE_STRIP = "1"
+
+do_configure_prepend() {
+	install -d ${S}/include/hardware
+	install -d ${S}/mediatek/bootctrl/avb/libavb
+	install -m 0755 ${STAGING_DIR_HOST}/${includedir}/hardware.h ${S}/include/hardware
+	install -m 0755 ${STAGING_DIR_HOST}/${includedir}/boot_control.h ${S}/include/hardware
+	install -m 0755 ${STAGING_DIR_HOST}/${includedir}/avb_util.h ${S}/mediatek/bootctrl/avb/libavb
+	install -m 0755 ${STAGING_DIR_HOST}/${datadir}/avb_crc32.c ${S}/mediatek/bootctrl/avb/libavb
+	install -m 0755 ${STAGING_DIR_HOST}/${datadir}/avb_util.c ${S}/mediatek/bootctrl/avb/libavb
+}
diff --git a/meta/meta-mediatek/recipes-support/custom/custom_1.0.0.bb b/meta/meta-mediatek/recipes-support/custom/custom_1.0.0.bb
new file mode 100644
index 0000000..aabf68e
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/custom/custom_1.0.0.bb
@@ -0,0 +1,38 @@
+#Basic Configuration
+DESCRIPTION = "Customization."
+SECTION = "base"
+LICENSE = "MediaTekProprietary"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173fff"
+MTK_SRC = "${TOPDIR}/../src/support/libnvram_custom/CFG"
+
+WORKONSRC = "${MTK_SRC}"
+
+inherit deploy workonsrc
+
+PRJ_FILENAME = "${MTK_PROJECT}"
+
+#Parameters passed to do_compile()
+EXTRA_OEMAKE = "'CROSS=${TARGET_PREFIX}'\
+                'PRJ_FILENAME=${PRJ_FILENAME}'"
+ALLOW_EMPTY_${PN} = "1"
+
+FILES_${PN}-dev = "*"
+FILES_${PN}  = "*"
+do_install () {
+	oe_runmake install ROOT=${D}
+
+	if test -d "${WORKDIR}/${MTK_NVRAM_PROJECT}/cgen"; then
+		mkdir -p ${D}/include/custom/${MTK_PROJECT}
+		cp -rf ${WORKDIR}/${MTK_NVRAM_PROJECT}/cgen ${D}/include/custom/${MTK_PROJECT}
+	fi
+
+	install -d ${D}${includedir}
+	cp -af ${D}/include/* ${D}${includedir}
+	rm -rf ${D}/include
+
+}
+
+addtask nvramclean
+do_nvramclean () {
+	oe_runmake clean
+}
diff --git a/meta/meta-mediatek/recipes-support/db/db/darwin.patch b/meta/meta-mediatek/recipes-support/db/db/darwin.patch
new file mode 100644
index 0000000..5fdccd3
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/db/db/darwin.patch
@@ -0,0 +1,145 @@
+diff --git a/.pc/0001-atomic-Rename-local-__atomic_compare_exchange-to-avo.patch/src/dbinc/atomic.h b/.pc/0001-atomic-Rename-local-__atomic_compare_exchange-to-avo.patch/src/dbinc/atomic.h
+index 6a858f7..a58e152 100644
+--- a/.pc/0001-atomic-Rename-local-__atomic_compare_exchange-to-avo.patch/src/dbinc/atomic.h
++++ b/.pc/0001-atomic-Rename-local-__atomic_compare_exchange-to-avo.patch/src/dbinc/atomic.h
+@@ -70,7 +70,7 @@ typedef struct {
+  * These have no memory barriers; the caller must include them when necessary.
+  */
+ #define	atomic_read(p)		((p)->value)
+-#define	atomic_init(p, val)	((p)->value = (val))
++#define	atomic_init_(p, val)	((p)->value = (val))
+ 
+ #ifdef HAVE_ATOMIC_SUPPORT
+ 
+@@ -206,7 +206,7 @@ static inline int __atomic_compare_exchange(
+ #define	atomic_dec(env, p)	(--(p)->value)
+ #define	atomic_compare_exchange(env, p, oldval, newval)		\
+ 	(DB_ASSERT(env, atomic_read(p) == (oldval)),		\
+-	atomic_init(p, (newval)), 1)
++	atomic_init_(p, (newval)), 1)
+ #else
+ #define atomic_inc(env, p)	__atomic_inc(env, p)
+ #define atomic_dec(env, p)	__atomic_dec(env, p)
+diff --git a/src/dbinc/atomic.h b/src/dbinc/atomic.h
+index 1b49de5..8ddda43 100644
+--- a/src/dbinc/atomic.h
++++ b/src/dbinc/atomic.h
+@@ -70,7 +70,7 @@ typedef struct {
+  * These have no memory barriers; the caller must include them when necessary.
+  */
+ #define	atomic_read(p)		((p)->value)
+-#define	atomic_init(p, val)	((p)->value = (val))
++#define	atomic_init_(p, val)	((p)->value = (val))
+ 
+ #ifdef HAVE_ATOMIC_SUPPORT
+ 
+@@ -206,7 +206,7 @@ static inline int __db_atomic_compare_exchange(
+ #define	atomic_dec(env, p)	(--(p)->value)
+ #define	atomic_compare_exchange(env, p, oldval, newval)		\
+ 	(DB_ASSERT(env, atomic_read(p) == (oldval)),		\
+-	atomic_init(p, (newval)), 1)
++	atomic_init_(p, (newval)), 1)
+ #else
+ #define atomic_inc(env, p)	__atomic_inc(env, p)
+ #define atomic_dec(env, p)	__atomic_dec(env, p)
+diff --git a/src/mp/mp_fget.c b/src/mp/mp_fget.c
+index 16de695..5d553d7 100644
+--- a/src/mp/mp_fget.c
++++ b/src/mp/mp_fget.c
+@@ -649,7 +649,7 @@ alloc:		/* Allocate a new buffer header and data space. */
+ 
+ 		/* Initialize enough so we can call __memp_bhfree. */
+ 		alloc_bhp->flags = 0;
+-		atomic_init(&alloc_bhp->ref, 1);
++		atomic_init_(&alloc_bhp->ref, 1);
+ #ifdef DIAGNOSTIC
+ 		if ((uintptr_t)alloc_bhp->buf & (sizeof(size_t) - 1)) {
+ 			__db_errx(env, DB_STR("3025",
+@@ -955,7 +955,7 @@ alloc:		/* Allocate a new buffer header and data space. */
+ 			MVCC_MPROTECT(bhp->buf, mfp->pagesize,
+ 			    PROT_READ);
+ 
+-		atomic_init(&alloc_bhp->ref, 1);
++		atomic_init_(&alloc_bhp->ref, 1);
+ 		MUTEX_LOCK(env, alloc_bhp->mtx_buf);
+ 		alloc_bhp->priority = bhp->priority;
+ 		alloc_bhp->pgno = bhp->pgno;
+diff --git a/src/mp/mp_mvcc.c b/src/mp/mp_mvcc.c
+index 770bad8..bbf5899 100644
+--- a/src/mp/mp_mvcc.c
++++ b/src/mp/mp_mvcc.c
+@@ -276,7 +276,7 @@ __memp_bh_freeze(dbmp, infop, hp, bhp, need_frozenp)
+ #else
+ 	memcpy(frozen_bhp, bhp, SSZA(BH, buf));
+ #endif
+-	atomic_init(&frozen_bhp->ref, 0);
++	atomic_init_(&frozen_bhp->ref, 0);
+ 	if (mutex != MUTEX_INVALID)
+ 		frozen_bhp->mtx_buf = mutex;
+ 	else if ((ret = __mutex_alloc(env, MTX_MPOOL_BH,
+@@ -428,7 +428,7 @@ __memp_bh_thaw(dbmp, infop, hp, frozen_bhp, alloc_bhp)
+ #endif
+ 		alloc_bhp->mtx_buf = mutex;
+ 		MUTEX_LOCK(env, alloc_bhp->mtx_buf);
+-		atomic_init(&alloc_bhp->ref, 1);
++		atomic_init_(&alloc_bhp->ref, 1);
+ 		F_CLR(alloc_bhp, BH_FROZEN);
+ 	}
+ 
+diff --git a/src/mp/mp_region.c b/src/mp/mp_region.c
+index 4952030..4fbbea5 100644
+--- a/src/mp/mp_region.c
++++ b/src/mp/mp_region.c
+@@ -245,7 +245,7 @@ __memp_init(env, dbmp, reginfo_off, htab_buckets, max_nreg)
+ 			     MTX_MPOOL_FILE_BUCKET, 0, &htab[i].mtx_hash)) != 0)
+ 				return (ret);
+ 			SH_TAILQ_INIT(&htab[i].hash_bucket);
+-			atomic_init(&htab[i].hash_page_dirty, 0);
++			atomic_init_(&htab[i].hash_page_dirty, 0);
+ 		}
+ 
+ 		/*
+@@ -302,7 +302,7 @@ no_prealloc:
+ 		} else
+ 			hp->mtx_hash = mtx_base + (i % dbenv->mp_mtxcount);
+ 		SH_TAILQ_INIT(&hp->hash_bucket);
+-		atomic_init(&hp->hash_page_dirty, 0);
++		atomic_init_(&hp->hash_page_dirty, 0);
+ #ifdef HAVE_STATISTICS
+ 		hp->hash_io_wait = 0;
+ 		hp->hash_frozen = hp->hash_thawed = hp->hash_frozen_freed = 0;
+diff --git a/src/mutex/mut_method.c b/src/mutex/mut_method.c
+index 09353b0..7c17a6f 100644
+--- a/src/mutex/mut_method.c
++++ b/src/mutex/mut_method.c
+@@ -474,7 +474,7 @@ atomic_compare_exchange(env, v, oldval, newval)
+ 	MUTEX_LOCK(env, mtx);
+ 	ret = atomic_read(v) == oldval;
+ 	if (ret)
+-		atomic_init(v, newval);
++		atomic_init_(v, newval);
+ 	MUTEX_UNLOCK(env, mtx);
+ 
+ 	return (ret);
+diff --git a/src/mutex/mut_tas.c b/src/mutex/mut_tas.c
+index 106b161..4d662b0 100644
+--- a/src/mutex/mut_tas.c
++++ b/src/mutex/mut_tas.c
+@@ -47,7 +47,7 @@ __db_tas_mutex_init(env, mutex, flags)
+ 
+ #ifdef HAVE_SHARED_LATCHES
+ 	if (F_ISSET(mutexp, DB_MUTEX_SHARED))
+-		atomic_init(&mutexp->sharecount, 0);
++		atomic_init_(&mutexp->sharecount, 0);
+ 	else
+ #endif
+ 	if (MUTEX_INIT(&mutexp->tas)) {
+@@ -536,7 +536,7 @@ __db_tas_mutex_unlock(env, mutex)
+ 			F_CLR(mutexp, DB_MUTEX_LOCKED);
+ 			/* Flush flag update before zeroing count */
+ 			MEMBAR_EXIT();
+-			atomic_init(&mutexp->sharecount, 0);
++			atomic_init_(&mutexp->sharecount, 0);
+ 		} else {
+ 			DB_ASSERT(env, sharecount > 0);
+ 			MEMBAR_EXIT();
diff --git a/meta/meta-mediatek/recipes-support/db/db_5.3.28.bbappend b/meta/meta-mediatek/recipes-support/db/db_5.3.28.bbappend
new file mode 100644
index 0000000..11253b1
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/db/db_5.3.28.bbappend
@@ -0,0 +1,3 @@
+FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
+SRC_URI_append_toolchain-clang = " file://darwin.patch"
+
diff --git a/meta/meta-mediatek/recipes-support/dmsetup/dmsetup_2.02.171.bb b/meta/meta-mediatek/recipes-support/dmsetup/dmsetup_2.02.171.bb
new file mode 100644
index 0000000..d406896
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/dmsetup/dmsetup_2.02.171.bb
@@ -0,0 +1,14 @@
+require ../../../meta-openembedded/meta-oe/recipes-support/lvm2/lvm2.inc
+
+SRC_URI[md5sum] = "153b7bb643eb26073274968e9026fa8f"
+SRC_URI[sha256sum] = "b815a711a2fabaa5c3dc1a4a284df0268bf0f325f0fc0f5c9530c9bbb54b9964"
+
+DEPENDS += "autoconf-archive-native"
+
+TARGET_CC_ARCH += "${LDFLAGS}"
+
+do_install() {
+    oe_runmake 'DESTDIR=${D}' -C tools install_dmsetup_dynamic
+}
+
+BBCLASSEXTEND = "native nativesdk"
diff --git a/meta/meta-mediatek/recipes-support/dmsetup/files/0001-Avoid-bashisms-in-init-scripts.patch b/meta/meta-mediatek/recipes-support/dmsetup/files/0001-Avoid-bashisms-in-init-scripts.patch
new file mode 100644
index 0000000..e86ab25
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/dmsetup/files/0001-Avoid-bashisms-in-init-scripts.patch
@@ -0,0 +1,182 @@
+From 916ea0c70fd063ab7b81f16fd917a75dc02edf4f Mon Sep 17 00:00:00 2001
+From: Peter Kjellerstedt <pkj@axis.com>
+Date: Fri, 17 Mar 2017 03:18:28 +0100
+Subject: [PATCH] Avoid bashisms in init scripts
+
+Upstream-Status: Inappropriate
+
+Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
+---
+ scripts/blk_availability_init_red_hat.in      | 4 ++--
+ scripts/clvmd_init_red_hat.in                 | 6 +++---
+ scripts/cmirrord_init_red_hat.in              | 4 ++--
+ scripts/lvm2_cluster_activation_red_hat.sh.in | 4 ++--
+ scripts/lvm2_lvmetad_init_red_hat.in          | 4 ++--
+ scripts/lvm2_lvmpolld_init_red_hat.in         | 4 ++--
+ scripts/lvm2_monitoring_init_red_hat.in       | 4 ++--
+ scripts/lvm2_monitoring_init_rhel4            | 4 ++--
+ 8 files changed, 17 insertions(+), 17 deletions(-)
+
+diff --git a/scripts/blk_availability_init_red_hat.in b/scripts/blk_availability_init_red_hat.in
+index a84ffe7..6b855b7 100644
+--- a/scripts/blk_availability_init_red_hat.in
++++ b/scripts/blk_availability_init_red_hat.in
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ #
+ # Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+ #
+@@ -53,6 +53,6 @@ case "$1" in
+   status)
+ 	;;
+   *)
+-	echo $"Usage: $0 {start|stop|status}"
++	echo "Usage: $0 {start|stop|status}"
+ 	;;
+ esac
+diff --git a/scripts/clvmd_init_red_hat.in b/scripts/clvmd_init_red_hat.in
+index d7f3392..abc8011 100644
+--- a/scripts/clvmd_init_red_hat.in
++++ b/scripts/clvmd_init_red_hat.in
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ #
+ # clvmd - Clustered LVM Daemon init script
+ #
+@@ -161,7 +161,7 @@ restart() {
+ 	fi
+ }
+ 
+-[ "$EUID" != "0" ] && {
++[ "$(id -u)" != "0" ] && {
+ 	echo "clvmd init script can only be executed as root user"
+ 	exit 4
+ }
+@@ -206,7 +206,7 @@ case "$1" in
+ 	;;
+ 
+   *)
+-	echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
++	echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+ 	rtrn=2
+ 	;;
+ esac
+diff --git a/scripts/cmirrord_init_red_hat.in b/scripts/cmirrord_init_red_hat.in
+index d4b7e37..d442cbc 100755
+--- a/scripts/cmirrord_init_red_hat.in
++++ b/scripts/cmirrord_init_red_hat.in
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ #
+ # chkconfig: - 22 78
+ # description: Starts and stops cmirrord
+@@ -101,7 +101,7 @@ case "$1" in
+ 		;;
+ 
+ 	*)
+-		echo $"Usage: $0 {start|stop|restart|status}"
++		echo "Usage: $0 {start|stop|restart|status}"
+ 		;;
+ esac
+ 
+diff --git a/scripts/lvm2_cluster_activation_red_hat.sh.in b/scripts/lvm2_cluster_activation_red_hat.sh.in
+index abea026..d8cba2e 100644
+--- a/scripts/lvm2_cluster_activation_red_hat.sh.in
++++ b/scripts/lvm2_cluster_activation_red_hat.sh.in
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ 
+ sbindir=@sbindir@
+ 
+@@ -54,7 +54,7 @@ case "$1" in
+ 	rtrn=$?
+ 	;;
+   *)
+-	echo $"Usage: $0 {activate|deactivate}"
++	echo "Usage: $0 {activate|deactivate}"
+ 	rtrn=3
+ 	;;
+ esac
+diff --git a/scripts/lvm2_lvmetad_init_red_hat.in b/scripts/lvm2_lvmetad_init_red_hat.in
+index b2f5d50..96269a9 100644
+--- a/scripts/lvm2_lvmetad_init_red_hat.in
++++ b/scripts/lvm2_lvmetad_init_red_hat.in
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ #
+ # Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+ #
+@@ -105,7 +105,7 @@ case "$1" in
+ 	;;
+ 
+   *)
+-	echo $"Usage: $0 {start|stop|force-stop|restart|condrestart|try-restart|status}"
++	echo "Usage: $0 {start|stop|force-stop|restart|condrestart|try-restart|status}"
+ 	;;
+ esac
+ 
+diff --git a/scripts/lvm2_lvmpolld_init_red_hat.in b/scripts/lvm2_lvmpolld_init_red_hat.in
+index c521955..cdbaece 100644
+--- a/scripts/lvm2_lvmpolld_init_red_hat.in
++++ b/scripts/lvm2_lvmpolld_init_red_hat.in
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ #
+ # Copyright (C) 2015 Red Hat, Inc. All rights reserved.
+ #
+@@ -107,7 +107,7 @@ case "$1" in
+ 	;;
+ 
+   *)
+-	echo $"Usage: $0 {start|stop|force-stop|restart|condrestart|try-restart|status}"
++	echo "Usage: $0 {start|stop|force-stop|restart|condrestart|try-restart|status}"
+ 	;;
+ esac
+ 
+diff --git a/scripts/lvm2_monitoring_init_red_hat.in b/scripts/lvm2_monitoring_init_red_hat.in
+index de7ff0d..9ff6bb7 100644
+--- a/scripts/lvm2_monitoring_init_red_hat.in
++++ b/scripts/lvm2_monitoring_init_red_hat.in
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ #
+ # Copyright (C) 2007-2009 Red Hat, Inc. All rights reserved.
+ #
+@@ -128,7 +128,7 @@ case "$1" in
+ 	;;
+ 
+   *)
+-	echo $"Usage: $0 {start|stop|restart|status|force-stop}"
++	echo "Usage: $0 {start|stop|restart|status|force-stop}"
+ 	;;
+ esac
+ 
+diff --git a/scripts/lvm2_monitoring_init_rhel4 b/scripts/lvm2_monitoring_init_rhel4
+index 8eb06c5..2e8d0f7 100644
+--- a/scripts/lvm2_monitoring_init_rhel4
++++ b/scripts/lvm2_monitoring_init_rhel4
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ #
+ # Copyright (C) 2007 Red Hat, Inc. All rights reserved.
+ #
+@@ -93,7 +93,7 @@ case "$1" in
+ 	;;
+ 
+   *)
+-	echo $"Usage: $0 {start|stop|restart|status|force-stop}"
++	echo "Usage: $0 {start|stop|restart|status|force-stop}"
+ 	;;
+ esac
+ 
+-- 
+2.12.0
+
diff --git a/meta/meta-mediatek/recipes-support/dmsetup/files/0001-implement-libc-specific-reopen_stream.patch b/meta/meta-mediatek/recipes-support/dmsetup/files/0001-implement-libc-specific-reopen_stream.patch
new file mode 100644
index 0000000..5d72402
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/dmsetup/files/0001-implement-libc-specific-reopen_stream.patch
@@ -0,0 +1,79 @@
+From e3103459416616d3b8508e7176e897b0ae6c90f2 Mon Sep 17 00:00:00 2001
+From: Dengke Du <dengke.du@windriver.com>
+Date: Tue, 25 Oct 2016 11:49:40 +0000
+Subject: [PATCH] implement libc specific reopen_stream
+
+musl defines stdin/stdio/stderr as constant types which means
+we can not assign to them as we are doing here but works ok with glibc
+therefore abstract out the _reopen_stream definition depending upon if
+we are using glibc or otherwise
+
+Origin:
+http://git.alpinelinux.org/cgit/aports/tree/main/lvm2/fix-stdio-usage.patch
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Dengke Du <dengke.du@windriver.com>
+
+---
+ lib/log/log.c      | 6 ++++++
+ tools/lvmcmdline.c | 6 +++---
+ 2 files changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/lib/log/log.c b/lib/log/log.c
+index c933154..3581084 100644
+--- a/lib/log/log.c
++++ b/lib/log/log.c
+@@ -161,6 +161,7 @@ static void _check_and_replace_standard_log_streams(FILE *old_stream, FILE *new_
+  * Close and reopen standard stream on file descriptor fd.
+  */
+ int reopen_standard_stream(FILE **stream, const char *mode)
++#ifdef __GLIBC__
+ {
+ 	int fd, fd_copy, new_fd;
+ 	const char *name;
+@@ -207,6 +208,11 @@ int reopen_standard_stream(FILE **stream, const char *mode)
+ 	*stream = new_stream;
+ 	return 1;
+ }
++#else
++{
++	return (freopen(NULL, mode, *stream) != NULL);
++}
++#endif
+ 
+ void init_log_fn(lvm2_log_fn_t log_fn)
+ {
+diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
+index 9a4deb7..f1f18e6 100644
+--- a/tools/lvmcmdline.c
++++ b/tools/lvmcmdline.c
+@@ -1818,7 +1818,7 @@ static int _check_standard_fds(void)
+ 	int err = is_valid_fd(STDERR_FILENO);
+ 
+ 	if (!is_valid_fd(STDIN_FILENO) &&
+-	    !(stdin = fopen(_PATH_DEVNULL, "r"))) {
++	    !freopen(_PATH_DEVNULL, "r", stdin)) {
+ 		if (err)
+ 			perror("stdin stream open");
+ 		else
+@@ -1828,7 +1828,7 @@ static int _check_standard_fds(void)
+ 	}
+ 
+ 	if (!is_valid_fd(STDOUT_FILENO) &&
+-	    !(stdout = fopen(_PATH_DEVNULL, "w"))) {
++	    !freopen(_PATH_DEVNULL, "w", stdout)) {
+ 		if (err)
+ 			perror("stdout stream open");
+ 		/* else no stdout */
+@@ -1836,7 +1836,7 @@ static int _check_standard_fds(void)
+ 	}
+ 
+ 	if (!is_valid_fd(STDERR_FILENO) &&
+-	    !(stderr = fopen(_PATH_DEVNULL, "w"))) {
++	    !freopen(_PATH_DEVNULL, "w", stderr)) {
+ 		printf("stderr stream open: %s\n",
+ 		       strerror(errno));
+ 		return 0;
+-- 
+2.12.0
+
diff --git a/meta/meta-mediatek/recipes-support/dmsetup/files/0002-Guard-use-of-mallinfo-with-__GLIBC__.patch b/meta/meta-mediatek/recipes-support/dmsetup/files/0002-Guard-use-of-mallinfo-with-__GLIBC__.patch
new file mode 100644
index 0000000..95dcede
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/dmsetup/files/0002-Guard-use-of-mallinfo-with-__GLIBC__.patch
@@ -0,0 +1,30 @@
+From 3ae9c0b607ec33fb07f32a41e9d28cc9068dd39a Mon Sep 17 00:00:00 2001
+From: Dengke Du <dengke.du@windriver.com>
+Date: Tue, 25 Oct 2016 11:52:44 +0000
+Subject: [PATCH] Guard use of mallinfo() with __GLIBC__
+
+This API is glibc-only
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Dengke Du <dengke.du@windriver.com>
+
+---
+ lib/mm/memlock.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
+index da90144..f34f890 100644
+--- a/lib/mm/memlock.c
++++ b/lib/mm/memlock.c
+@@ -150,7 +150,7 @@ static void _touch_memory(void *mem, size_t size)
+ 
+ static void _allocate_memory(void)
+ {
+-#ifndef VALGRIND_POOL
++#if !defined(VALGRIND_POOL) && defined(__GLIBC__)
+ 	void *stack_mem;
+ 	struct rlimit limit;
+ 	int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks;
+-- 
+2.12.0
+
diff --git a/meta/meta-mediatek/recipes-support/dmsetup/files/0003-include-fcntl.h-for-O_-defines-and-fcntl-signature.patch b/meta/meta-mediatek/recipes-support/dmsetup/files/0003-include-fcntl.h-for-O_-defines-and-fcntl-signature.patch
new file mode 100644
index 0000000..9ab1c06
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/dmsetup/files/0003-include-fcntl.h-for-O_-defines-and-fcntl-signature.patch
@@ -0,0 +1,30 @@
+From b1ad91a059d99afd1ce25823b7c0a8d3ac63d2fd Mon Sep 17 00:00:00 2001
+From: Dengke Du <dengke.du@windriver.com>
+Date: Tue, 25 Oct 2016 11:55:49 +0000
+Subject: [PATCH 3/4] include fcntl.h for O_* defines and fcntl() signature
+
+On glibc _somehow_ this header gets pulled in indirectly
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Dengke Du <dengke.du@windriver.com>
+---
+Upstream-Status: Pending
+---
+ libdaemon/server/daemon-server.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
+index 6af6de9..a9590e7 100644
+--- a/libdaemon/server/daemon-server.c
++++ b/libdaemon/server/daemon-server.c
+@@ -18,6 +18,7 @@
+ #include "daemon-server.h"
+ #include "daemon-log.h"
+ 
++#include <fcntl.h>
+ #include <dlfcn.h>
+ #include <errno.h>
+ #include <pthread.h>
+-- 
+2.9.3
+
diff --git a/meta/meta-mediatek/recipes-support/dmsetup/files/0004-tweak-MODPROBE_CMD-for-cross-compile.patch b/meta/meta-mediatek/recipes-support/dmsetup/files/0004-tweak-MODPROBE_CMD-for-cross-compile.patch
new file mode 100644
index 0000000..aaeaa72
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/dmsetup/files/0004-tweak-MODPROBE_CMD-for-cross-compile.patch
@@ -0,0 +1,38 @@
+From 0012ea63f6070a5d41fa380970f9c30b953237d2 Mon Sep 17 00:00:00 2001
+From: Dengke Du <dengke.du@windriver.com>
+Date: Tue, 25 Oct 2016 11:59:40 +0000
+Subject: [PATCH 4/4] tweak MODPROBE_CMD for cross compile
+
+Lvm uses variable MODPROBE_CMD at runtime, so build time detection of modprobe
+is incorrect.
+------
+|lvm lvcreate --thinpool wrl/pool00 --size 5556m --config  devices
+{ preferred_names=["^/dev/mapper/", "^/dev/md/", "^/dev/sd"]
+filter=["r|/loop1$|","r|/loop2$|","r|/loop3$|","r|/loop4$|","r|/loop5$|","r|/loop6$|","r|/loop7$|"] }
+|tmp/sysroots/x86_64-linux/usr/bin/modprobe: execvp failed: No such file or directory
+|tmp/sysroots/x86_64-linux/usr/bin/modprobe failed: 2
+------
+
+Upstream-Status: Inappropriate [oe specific]
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+Signed-off-by: Dengke Du <dengke.du@windriver.com>
+---
+ configure.in | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/configure.in b/configure.in
+index cc77aab..a3579f2 100644
+--- a/configure.in
++++ b/configure.in
+@@ -1853,7 +1853,6 @@ if test "$UDEV_SYNC" = yes; then
+ fi
+ 
+ ################################################################################
+-AC_PATH_TOOL(MODPROBE_CMD, modprobe)
+ 
+ if test -n "$MODPROBE_CMD"; then
+ 	AC_DEFINE_UNQUOTED([MODPROBE_CMD], ["$MODPROBE_CMD"], [The path to 'modprobe', if available.])
+-- 
+2.9.3
+
diff --git a/meta/meta-mediatek/recipes-support/dmsetup/files/0005-do-not-build-manual.patch b/meta/meta-mediatek/recipes-support/dmsetup/files/0005-do-not-build-manual.patch
new file mode 100644
index 0000000..15aa9f5
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/dmsetup/files/0005-do-not-build-manual.patch
@@ -0,0 +1,58 @@
+From d8bb25e34d6533ba78eaae697771ee499a66706f Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Wed, 2 Aug 2017 03:41:37 -0400
+Subject: [PATCH] do not build manual
+
+On some host (ubuntu 1404), build manual failed.
+...
+./tools/man-generator --primary lvscan lvscan.8_des
+Failed to stat description file lvscan.8_des.
+...
+
+Do not build man to workaround the issue.
+
+Upstream-Status: Pending
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ Makefile.in  | 4 ++--
+ configure.in | 1 -
+ 2 files changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/Makefile.in b/Makefile.in
+index 31d428d..24f89a2 100644
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -18,7 +18,7 @@ top_builddir = @top_builddir@
+ abs_top_builddir = @abs_top_builddir@
+ abs_top_srcdir = @abs_top_srcdir@
+ 
+-SUBDIRS = conf daemons include lib libdaemon libdm man scripts tools
++SUBDIRS = conf daemons include lib libdaemon libdm scripts tools
+ 
+ ifeq ("@UDEV_RULES@", "yes")
+   SUBDIRS += udev
+@@ -69,7 +69,7 @@ liblvm.device-mapper: include.device-mapper
+ daemons.device-mapper: libdm.device-mapper
+ tools.device-mapper: libdm.device-mapper
+ scripts.device-mapper: include.device-mapper
+-device-mapper: tools.device-mapper daemons.device-mapper man.device-mapper
++device-mapper: tools.device-mapper daemons.device-mapper
+ 
+ ifeq ("@INTL@", "yes")
+ lib.pofile: include.pofile
+diff --git a/configure.in b/configure.in
+index 1dc8819..108ace4 100644
+--- a/configure.in
++++ b/configure.in
+@@ -2213,7 +2213,6 @@ libdm/Makefile
+ libdm/libdevmapper.pc
+ liblvm/Makefile
+ liblvm/liblvm2app.pc
+-man/Makefile
+ po/Makefile
+ python/Makefile
+ python/setup.py
+-- 
+2.8.1
+
diff --git a/meta/meta-mediatek/recipes-support/dmsetup/files/0006-start-lvm2-monitor.service-after-tmp.mount.patch b/meta/meta-mediatek/recipes-support/dmsetup/files/0006-start-lvm2-monitor.service-after-tmp.mount.patch
new file mode 100644
index 0000000..0e68d62
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/dmsetup/files/0006-start-lvm2-monitor.service-after-tmp.mount.patch
@@ -0,0 +1,32 @@
+From 24a2c47fd01dde1710f1fa66f5c30ce7010c5956 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Thu, 21 Sep 2017 15:28:10 +0800
+Subject: [PATCH] start lvm2-monitor.service after tmp.mount
+
+The lvm2-monitor.service reqires the existence of locking_dir
+("/tmp/lock/lvm"), and unit tmp.mount is to mount /tmp.
+So start lvm2-monitor.service after tmp.mount
+
+Upstream-Status: Inappropriate [oe specific]
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ scripts/lvm2_monitoring_systemd_red_hat.service.in | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/scripts/lvm2_monitoring_systemd_red_hat.service.in b/scripts/lvm2_monitoring_systemd_red_hat.service.in
+index 22238b7..93b2bee 100644
+--- a/scripts/lvm2_monitoring_systemd_red_hat.service.in
++++ b/scripts/lvm2_monitoring_systemd_red_hat.service.in
+@@ -2,7 +2,7 @@
+ Description=Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
+ Documentation=man:dmeventd(8) man:lvcreate(8) man:lvchange(8) man:vgchange(8)
+ Requires=dm-event.socket lvm2-lvmetad.socket
+-After=dm-event.socket dm-event.service lvm2-lvmetad.socket lvm2-activation.service lvm2-lvmetad.service
++After=dm-event.socket dm-event.service lvm2-lvmetad.socket lvm2-activation.service lvm2-lvmetad.service tmp.mount
+ Before=local-fs-pre.target
+ DefaultDependencies=no
+ Conflicts=shutdown.target
+-- 
+1.8.3.1
+
diff --git a/meta/meta-mediatek/recipes-support/dmsetup/files/lvm.conf b/meta/meta-mediatek/recipes-support/dmsetup/files/lvm.conf
new file mode 100644
index 0000000..c2bb85d
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/dmsetup/files/lvm.conf
@@ -0,0 +1,326 @@
+# This is an example configuration file for the LVM2 system.
+# It contains the default settings that would be used if there was no
+# /etc/lvm/lvm.conf file.
+#
+# Refer to 'man lvm.conf' for further information including the file layout.
+#
+# To put this file in a different directory and override /etc/lvm set
+# the environment variable LVM_SYSTEM_DIR before running the tools.
+
+
+# This section allows you to configure which block devices should
+# be used by the LVM system.
+devices {
+
+    # Where do you want your volume groups to appear ?
+    dir = "/dev"
+
+    # An array of directories that contain the device nodes you wish
+    # to use with LVM2.
+    scan = [ "/dev" ]
+
+    # A filter that tells LVM2 to only use a restricted set of devices.
+    # The filter consists of an array of regular expressions.  These
+    # expressions can be delimited by a character of your choice, and
+    # prefixed with either an 'a' (for accept) or 'r' (for reject).
+    # The first expression found to match a device name determines if
+    # the device will be accepted or rejected (ignored).  Devices that
+    # don't match any patterns are accepted.
+
+    # Be careful if there there are symbolic links or multiple filesystem 
+    # entries for the same device as each name is checked separately against
+    # the list of patterns.  The effect is that if any name matches any 'a'
+    # pattern, the device is accepted; otherwise if any name matches any 'r'
+    # pattern it is rejected; otherwise it is accepted.
+
+    # Don't have more than one filter line active at once: only one gets used.
+
+    # Run vgscan after you change this parameter to ensure that
+    # the cache file gets regenerated (see below).
+    # If it doesn't do what you expect, check the output of 'vgscan -vvvv'.
+
+
+    # By default we accept every block device:
+    filter = [ "a/.*/" ]
+
+    # Exclude the cdrom drive
+    # filter = [ "r|/dev/cdrom|" ]
+
+    # When testing I like to work with just loopback devices:
+    # filter = [ "a/loop/", "r/.*/" ]
+
+    # Or maybe all loops and ide drives except hdc:
+    # filter =[ "a|loop|", "r|/dev/hdc|", "a|/dev/ide|", "r|.*|" ]
+
+    # Use anchors if you want to be really specific
+    # filter = [ "a|^/dev/hda8$|", "r/.*/" ]
+
+    # The results of the filtering are cached on disk to avoid
+    # rescanning dud devices (which can take a very long time).  By
+    # default this cache file is hidden in the /etc/lvm directory.
+    # It is safe to delete this file: the tools regenerate it.
+    cache = "/etc/lvm/.cache"
+
+    # You can turn off writing this cache file by setting this to 0.
+    write_cache_state = 1
+
+    # Advanced settings.
+
+    # List of pairs of additional acceptable block device types found 
+    # in /proc/devices with maximum (non-zero) number of partitions.
+    # types = [ "fd", 16 ]
+
+    # If sysfs is mounted (2.6 kernels) restrict device scanning to 
+    # the block devices it believes are valid.
+    # 1 enables; 0 disables.
+    sysfs_scan = 1	
+
+    # By default, LVM2 will ignore devices used as components of
+    # software RAID (md) devices by looking for md superblocks.
+    # 1 enables; 0 disables.
+    md_component_detection = 1
+}
+
+# This section that allows you to configure the nature of the
+# information that LVM2 reports.
+log {
+
+    # Controls the messages sent to stdout or stderr.
+    # There are three levels of verbosity, 3 being the most verbose.
+    verbose = 0
+
+    # Should we send log messages through syslog?
+    # 1 is yes; 0 is no.
+    syslog = 1
+
+    # Should we log error and debug messages to a file?
+    # By default there is no log file.
+    #file = "/var/log/lvm2.log"
+
+    # Should we overwrite the log file each time the program is run?
+    # By default we append.
+    overwrite = 0
+
+    # What level of log messages should we send to the log file and/or syslog?
+    # There are 6 syslog-like log levels currently in use - 2 to 7 inclusive.
+    # 7 is the most verbose (LOG_DEBUG).
+    level = 0
+    
+    # Format of output messages
+    # Whether or not (1 or 0) to indent messages according to their severity
+    indent = 1
+
+    # Whether or not (1 or 0) to display the command name on each line output
+    command_names = 0
+
+    # A prefix to use before the message text (but after the command name,
+    # if selected).  Default is two spaces, so you can see/grep the severity
+    # of each message.
+    prefix = "  "
+
+    # To make the messages look similar to the original LVM tools use:
+    #   indent = 0
+    #   command_names = 1
+    #   prefix = " -- "
+
+    # Set this if you want log messages during activation.
+    # Don't use this in low memory situations (can deadlock).
+    # activation = 0
+}
+
+# Configuration of metadata backups and archiving.  In LVM2 when we
+# talk about a 'backup' we mean making a copy of the metadata for the
+# *current* system.  The 'archive' contains old metadata configurations.
+# Backups are stored in a human readeable text format.
+backup {
+
+    # Should we maintain a backup of the current metadata configuration ?
+    # Use 1 for Yes; 0 for No.
+    # Think very hard before turning this off!
+    backup = 1
+
+    # Where shall we keep it ?
+    # Remember to back up this directory regularly!
+    backup_dir = "/etc/lvm/backup"
+
+    # Should we maintain an archive of old metadata configurations.
+    # Use 1 for Yes; 0 for No.
+    # On by default.  Think very hard before turning this off.
+    archive = 1
+
+    # Where should archived files go ?
+    # Remember to back up this directory regularly!
+    archive_dir = "/etc/lvm/archive"
+    
+    # What is the minimum number of archive files you wish to keep ?
+    retain_min = 10
+
+    # What is the minimum time you wish to keep an archive file for ?
+    retain_days = 30
+}
+
+# Settings for the running LVM2 in shell (readline) mode.
+shell {
+
+    # Number of lines of history to store in ~/.lvm_history
+    history_size = 100
+}
+
+
+# Miscellaneous global LVM2 settings
+global {
+    
+    # The file creation mask for any files and directories created.
+    # Interpreted as octal if the first digit is zero.
+    umask = 077
+
+    # Allow other users to read the files
+    #umask = 022
+
+    # Enabling test mode means that no changes to the on disk metadata
+    # will be made.  Equivalent to having the -t option on every
+    # command.  Defaults to off.
+    test = 0
+
+    # Whether or not to communicate with the kernel device-mapper.
+    # Set to 0 if you want to use the tools to manipulate LVM metadata 
+    # without activating any logical volumes.
+    # If the device-mapper kernel driver is not present in your kernel
+    # setting this to 0 should suppress the error messages.
+    activation = 1
+
+    # If we can't communicate with device-mapper, should we try running 
+    # the LVM1 tools?
+    # This option only applies to 2.4 kernels and is provided to help you
+    # switch between device-mapper kernels and LVM1 kernels.
+    # The LVM1 tools need to be installed with .lvm1 suffices
+    # e.g. vgscan.lvm1 and they will stop working after you start using
+    # the new lvm2 on-disk metadata format.
+    # The default value is set when the tools are built.
+    # fallback_to_lvm1 = 0
+
+    # The default metadata format that commands should use - "lvm1" or "lvm2".
+    # The command line override is -M1 or -M2.
+    # Defaults to "lvm1" if compiled in, else "lvm2".
+    # format = "lvm1"
+
+    # Location of proc filesystem
+    proc = "/proc"
+
+    # Type of locking to use. Defaults to file-based locking (1).
+    # Turn locking off by setting to 0 (dangerous: risks metadata corruption
+    # if LVM2 commands get run concurrently).
+    locking_type = 1
+
+    # Local non-LV directory that holds file-based locks while commands are
+    # in progress.  A directory like /tmp that may get wiped on reboot is OK.
+    locking_dir = "/tmp/lock/lvm"
+
+    # Other entries can go here to allow you to load shared libraries
+    # e.g. if support for LVM1 metadata was compiled as a shared library use
+    #   format_libraries = "liblvm2format1.so" 
+    # Full pathnames can be given.
+
+    # Search this directory first for shared libraries.
+    #   library_dir = "/lib"
+}
+
+activation {
+    # Device used in place of missing stripes if activating incomplete volume.
+    # For now, you need to set this up yourself first (e.g. with 'dmsetup')
+    # For example, you could make it return I/O errors using the 'error' 
+    # target or make it return zeros.
+    missing_stripe_filler = "/dev/ioerror"
+
+    # Size (in KB) of each copy operation when mirroring
+    mirror_region_size = 512
+
+    # How much stack (in KB) to reserve for use while devices suspended
+    reserved_stack = 256
+
+    # How much memory (in KB) to reserve for use while devices suspended
+    reserved_memory = 8192
+
+    # Nice value used while devices suspended
+    process_priority = -18
+
+    # If volume_list is defined, each LV is only activated if there is a
+    # match against the list.
+    #   "vgname" and "vgname/lvname" are matched exactly.
+    #   "@tag" matches any tag set in the LV or VG.
+    #   "@*" matches if any tag defined on the host is also set in the LV or VG
+    #
+    # volume_list = [ "vg1", "vg2/lvol1", "@tag1", "@*" ]
+}
+
+
+####################
+# Advanced section #
+####################
+
+# Metadata settings
+#
+# metadata {
+    # Default number of copies of metadata to hold on each PV.  0, 1 or 2.
+    # You might want to override it from the command line with 0 
+    # when running pvcreate on new PVs which are to be added to large VGs.
+
+    # pvmetadatacopies = 1
+
+    # Approximate default size of on-disk metadata areas in sectors.
+    # You should increase this if you have large volume groups or
+    # you want to retain a large on-disk history of your metadata changes.
+
+    # pvmetadatasize = 255
+
+    # List of directories holding live copies of text format metadata.
+    # These directories must not be on logical volumes!
+    # It's possible to use LVM2 with a couple of directories here,
+    # preferably on different (non-LV) filesystems, and with no other 
+    # on-disk metadata (pvmetadatacopies = 0). Or this can be in
+    # addition to on-disk metadata areas.
+    # The feature was originally added to simplify testing and is not
+    # supported under low memory situations - the machine could lock up.
+    #
+    # Never edit any files in these directories by hand unless you
+    # you are absolutely sure you know what you are doing! Use
+    # the supplied toolset to make changes (e.g. vgcfgrestore).
+
+    # dirs = [ "/etc/lvm/metadata", "/mnt/disk2/lvm/metadata2" ]
+#}
+
+# Event daemon
+#
+dmeventd {
+    # mirror_library is the library used when monitoring a mirror device.
+    #
+    # "libdevmapper-event-lvm2mirror.so" attempts to recover from
+    # failures.  It removes failed devices from a volume group and
+    # reconfigures a mirror as necessary. If no mirror library is
+    # provided, mirrors are not monitored through dmeventd.
+
+    mirror_library = "@libdir@/device-mapper/libdevmapper-event-lvm2mirror.so"
+
+    # snapshot_library is the library used when monitoring a snapshot device.
+    #
+    # "libdevmapper-event-lvm2snapshot.so" monitors the filling of
+    # snapshots and emits a warning through syslog when the use of
+    # the snapshot exceeds 80%. The warning is repeated when 85%, 90% and
+    # 95% of the snapshot is filled.
+
+    snapshot_library = "@libdir@/device-mapper/libdevmapper-event-lvm2snapshot.so"
+
+    # thin_library is the library used when monitoring a thin device.
+    #
+    # "libdevmapper-event-lvm2thin.so" monitors the filling of
+    # pool and emits a warning through syslog when the use of
+    # the pool exceeds 80%. The warning is repeated when 85%, 90% and
+    # 95% of the pool is filled.
+
+    thin_library = "@libdir@/device-mapper/libdevmapper-event-lvm2thin.so"
+
+    # Full path of the dmeventd binary.
+    #
+    # executable = "@DMEVENTD_PATH@"
+}
+
diff --git a/meta/meta-mediatek/recipes-support/encrwpart-init/encrwpart-init.bb b/meta/meta-mediatek/recipes-support/encrwpart-init/encrwpart-init.bb
new file mode 100644
index 0000000..aee10f3
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/encrwpart-init/encrwpart-init.bb
@@ -0,0 +1,37 @@
+inherit workonsrc

+inherit pkgconfig

+inherit systemd

+

+DESCRIPTION = "Encrypted RW Partition Init"

+LICENSE = "MediaTekProprietary"

+LIC_FILES_CHKSUM = "file://COPYING;md5=d7810fab7487fb0aad327b76f1be7cd7"

+APPS_SRC = "${TOPDIR}/../meta/meta-mediatek/recipes-support/encrwpart-init"

+WORKONSRC = "${APPS_SRC}"

+

+#####Customization Start#####

+RWPART_DEVNAME = "/dev/mmcblk0p10"

+RWPART_MOUNT_DIR = "/data"

+RWPART_FILESYSTEM_SIZE = "100"

+RWPART_KEYSTR = "rwpart@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"

+#####Customization End#####

+

+SYSTEMD_PACKAGES = "${PN}"

+SYSTEMD_SERVICE_${PN} = "encrwpart-init.service"

+FILES_${PN} += "${systemd_unitdir}/system/encrwpart-init.service"

+FILES_${PN} += "etc/encrwpart-init.sh"

+

+do_install() {

+        install -d ${D}/etc

+        install -m 755 ${S}files/encrwpart-init.sh ${D}/etc/encrwpart-init.sh

+

+        install -d ${D}${systemd_system_unitdir}

+        install -m 0644 ${S}files/encrwpart-init.service ${D}${systemd_system_unitdir}

+

+        sed -e 's%#RWPART_DEVNAME#%${RWPART_DEVNAME}%g' \

+        	-e 's%#RWPART_MOUNT_DIR#%${RWPART_MOUNT_DIR}%g' \

+        	-e 's%#RWPART_FILESYSTEM_SIZE#%${RWPART_FILESYSTEM_SIZE}%g' \

+        	-e 's%#RWPART_KEYSTR#%${RWPART_KEYSTR}%g' \

+        	-i ${D}/etc/encrwpart-init.sh

+}

+

+

diff --git a/meta/meta-mediatek/recipes-support/encrwpart-init/files/encrwpart-init.service b/meta/meta-mediatek/recipes-support/encrwpart-init/files/encrwpart-init.service
new file mode 100644
index 0000000..929a1bc
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/encrwpart-init/files/encrwpart-init.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=EncrwpartInitScript
+
+[Service]
+ExecStart=/etc/encrwpart-init.sh
+Type=oneshot
+
+[Install]
+Alias=EncrwpartInitScript
+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/encrwpart-init/files/encrwpart-init.sh b/meta/meta-mediatek/recipes-support/encrwpart-init/files/encrwpart-init.sh
new file mode 100644
index 0000000..da43b45
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/encrwpart-init/files/encrwpart-init.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+#       @author
+#       @brief  generate the top index for each module doc
+
+umount #RWPART_MOUNT_DIR#
+
+mount -t ext4 #RWPART_DEVNAME# #RWPART_MOUNT_DIR#
+
+if [ $? -eq 0 ]; then
+	umount #RWPART_MOUNT_DIR#
+	resize2fs -M #RWPART_DEVNAME#
+	dmsetup create $(basename #RWPART_DEVNAME#)_dmcd --table "0 $(blockdev --getsz #RWPART_DEVNAME#) crypt aes-cbc-plain #RWPART_KEYSTR# 0 #RWPART_DEVNAME# 0"
+	if [ $? -eq 0 ]; then
+		dd if=#RWPART_DEVNAME# of=/dev/mapper/$(basename #RWPART_DEVNAME#)_dmcd bs=1M count=#RWPART_FILESYSTEM_SIZE#
+		resize2fs /dev/mapper/$(basename #RWPART_DEVNAME#)_dmcd
+		mount -t ext4 /dev/mapper/$(basename #RWPART_DEVNAME#)_dmcd #RWPART_MOUNT_DIR#
+	else
+		resize2fs #RWPART_DEVNAME#
+		mount -t ext4 #RWPART_DEVNAME# #RWPART_MOUNT_DIR#
+		exit 0
+	fi
+else
+	dmsetup create $(basename #RWPART_DEVNAME#)_dmcd --table "0 $(blockdev --getsz #RWPART_DEVNAME#) crypt aes-cbc-plain #RWPART_KEYSTR# 0 #RWPART_DEVNAME# 0"
+	if [ $? -ne 0 ]; then
+		exit 0
+	fi
+	mount -t ext4 /dev/mapper/$(basename #RWPART_DEVNAME#)_dmcd #RWPART_MOUNT_DIR#
+fi
diff --git a/meta/meta-mediatek/recipes-support/encryptlibrary-init/HOWTO b/meta/meta-mediatek/recipes-support/encryptlibrary-init/HOWTO
new file mode 100644
index 0000000..d0982a1
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/encryptlibrary-init/HOWTO
@@ -0,0 +1,10 @@
+MTK side:
+1.encrypt library on platform with command "secure_program enc [path/to/library] [path/to/encryptedlibrary]
+2.put encryptedlibrary in folder "files"
+
+Customer side:
+1.put encryptedlibrary in folder "files" after receiving encryptedlibrary
+2.make sure or modify "EncryptedLibraryName" value to library name in encryptlibrary-init.bb
+4.add encryptlibrary-init in image:
+eg: add encryptlibrary-init in section "IMAGE_INSTALL_append" of meta/meta-mediatek-mt8516/recipes-audio/images/mtk-image-aud-8516.bb
+5.at bootup time, the encryptedlibrary will be decrypted and put in /tmp
diff --git a/meta/meta-mediatek/recipes-support/encryptlibrary-init/encryptlibrary-init.bb b/meta/meta-mediatek/recipes-support/encryptlibrary-init/encryptlibrary-init.bb
new file mode 100644
index 0000000..c187b4c
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/encryptlibrary-init/encryptlibrary-init.bb
@@ -0,0 +1,35 @@
+inherit workonsrc

+inherit pkgconfig

+inherit systemd

+

+DESCRIPTION = "Encrypted Library Decryption Helper"

+LICENSE = "MediaTekProprietary"

+LIC_FILES_CHKSUM = "file://COPYING;md5=d7810fab7487fb0aad327b76f1be7cd7"

+APPS_SRC = "${TOPDIR}/../meta/meta-mediatek/recipes-support/encryptlibrary-init"

+SECURE_PROGRAM = "secure_program"

+WORKONSRC = "${APPS_SRC}"

+

+#####Customization Start#####

+EncryptedLibraryName = "libMtkOmxEac3Dec.so"

+#####Customization End#####

+

+SYSTEMD_PACKAGES = "${PN}"

+SYSTEMD_SERVICE_${PN} = "encryptlibrary-init.service"

+FILES_${PN} += "${systemd_unitdir}/system/encryptlibrary-init.service"

+FILES_${PN} += "etc/encryptlibrary-init.sh"

+FILES_${PN} += "${libdir}/encrypted/${EncryptedLibraryName}"

+

+do_install() {

+        install -d ${D}${systemd_system_unitdir}

+        install -m 0755 ${S}files/encryptlibrary-init.service ${D}${systemd_system_unitdir}

+

+        install -d ${D}/etc

+        install -m 755 ${S}files/encryptlibrary-init.sh ${D}/etc/encryptlibrary-init.sh

+

+        install -d ${D}${libdir}/encrypted

+        install -m 644 ${S}files/${EncryptedLibraryName} ${D}${libdir}/encrypted

+		

+        echo "${SECURE_PROGRAM} dec /usr/lib/encrypted/${EncryptedLibraryName} /tmp/${EncryptedLibraryName}" >> ${D}/etc/encryptlibrary-init.sh

+}

+

+

diff --git a/meta/meta-mediatek/recipes-support/encryptlibrary-init/files/encryptlibrary-init.service b/meta/meta-mediatek/recipes-support/encryptlibrary-init/files/encryptlibrary-init.service
new file mode 100644
index 0000000..678f1e8
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/encryptlibrary-init/files/encryptlibrary-init.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=EncryptedFileDecryptedHelperScript
+
+[Service]
+ExecStart=/etc/encryptlibrary-init.sh
+Type=simple
+
+[Install]
+Alias=DecryptionHelperScript
+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/encryptlibrary-init/files/encryptlibrary-init.sh b/meta/meta-mediatek/recipes-support/encryptlibrary-init/files/encryptlibrary-init.sh
new file mode 100644
index 0000000..cf14349
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/encryptlibrary-init/files/encryptlibrary-init.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+#
+#       @author
+#       @brief  generate the top index for each module doc
diff --git a/meta/meta-mediatek/recipes-support/ewriter/ewriter.bb b/meta/meta-mediatek/recipes-support/ewriter/ewriter.bb
new file mode 100644
index 0000000..78090cf
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/ewriter/ewriter.bb
@@ -0,0 +1,24 @@
+DESCRIPTION = "MTK eFuse Writer"
+LICENSE = "MediaTekProprietary"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173fff"
+
+inherit workonsrc
+WORKONSRC = "${TOPDIR}/../src/support/efuse_writer"
+
+DEPENDS += "${@bb.utils.contains('TEE_SUPPORT', 'mtee', 'tzapp', '' ,d)}"
+RDEPENDS_${PN} += "${@bb.utils.contains('TEE_SUPPORT', 'mtee', 'tzapp', '' ,d)}"
+DEPENDS += "${@bb.utils.contains('TEE_SUPPORT', 'optee', 'optee-services', '' ,d)}"
+RDEPENDS_${PN} += "${@bb.utils.contains('TEE_SUPPORT', 'optee', 'optee-services', '' ,d)}"
+
+do_compile() {
+	if test "${TEE_SUPPORT}" = "optee" ;then
+		oe_runmake LDFLAGS='${LDFLAGS} -ltz_efuse'
+	else
+		oe_runmake LDFLAGS='${LDFLAGS} -ltz_efuse -ltz_uree'
+	fi
+}
+
+do_install() {
+	install -d ${D}${bindir}
+	install -m 0755 ewriter ${D}${bindir}/
+}
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/fsck-msdos/files/makefile.patch b/meta/meta-mediatek/recipes-support/fsck-msdos/files/makefile.patch
new file mode 100755
index 0000000..e4be6f1
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/fsck-msdos/files/makefile.patch
@@ -0,0 +1,19 @@
+diff --git a/Makefile b/Makefile

+new file mode 100644

+index 0000000..e0cce70

+--- /dev/null

++++ b/Makefile

+@@ -0,0 +1,13 @@

++TARGET  := fsck_msdos

++SOURCES := boot.c check.c dir.c fat.c main.c

++OBJECTS := $(SOURCES:.c=.o)

++

++.PHONY: all clean install

++

++all: $(TARGET)

++

++$(TARGET): $(OBJECTS)

++	$(LINK.o) $^ -o $@

++

++clean: 

++	$(RM) $(OBJECTS) $(TARGET)

diff --git a/meta/meta-mediatek/recipes-support/libavb/files/libavb.patch b/meta/meta-mediatek/recipes-support/libavb/files/libavb.patch
new file mode 100644
index 0000000..92fe61f
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/libavb/files/libavb.patch
@@ -0,0 +1,680 @@
+diff --git a/libavb/avb_crc32.c b/libavb/avb_crc32.c
+index 9abed54..491fb36 100644
+--- a/libavb/avb_crc32.c
++++ b/libavb/avb_crc32.c
+@@ -42,11 +42,12 @@
+  * CRC32 code derived from work by Gary S. Brown.
+  */
+ 
+-#include "avb_sysdeps.h"
++//#include "avb_sysdeps.h"
++#include "avb_util.h"
+ 
+ /* Code taken from FreeBSD 8 */
+ 
+-static uint32_t crc32_tab[] = {
++static uint32_t iavb_crc32_tab[] = {
+     0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+     0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+     0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+@@ -98,16 +99,16 @@ static uint32_t crc32_tab[] = {
+  * in sys/libkern.h, where it can be inlined.
+  */
+ 
+-static uint32_t crc32(uint32_t crc_in, const uint8_t* buf, int size) {
++static uint32_t iavb_crc32(uint32_t crc_in, const uint8_t* buf, int size) {
+   const uint8_t* p = buf;
+   uint32_t crc;
+ 
+   crc = crc_in ^ ~0U;
+   while (size--)
+-    crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
++    crc = iavb_crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
+   return crc ^ ~0U;
+ }
+ 
+ uint32_t avb_crc32(const uint8_t* buf, size_t size) {
+-  return crc32(0, buf, size);
++  return iavb_crc32(0, buf, size);
+ }
+diff --git a/libavb/avb_util.c b/libavb/avb_util.c
+index 43662b4..4105d38 100644
+--- a/libavb/avb_util.c
++++ b/libavb/avb_util.c
+@@ -24,31 +24,7 @@
+ 
+ #include "avb_util.h"
+ 
+-#include <stdarg.h>
+-
+-uint32_t avb_be32toh(uint32_t in) {
+-  uint8_t* d = (uint8_t*)&in;
+-  uint32_t ret;
+-  ret = ((uint32_t)d[0]) << 24;
+-  ret |= ((uint32_t)d[1]) << 16;
+-  ret |= ((uint32_t)d[2]) << 8;
+-  ret |= ((uint32_t)d[3]);
+-  return ret;
+-}
+-
+-uint64_t avb_be64toh(uint64_t in) {
+-  uint8_t* d = (uint8_t*)&in;
+-  uint64_t ret;
+-  ret = ((uint64_t)d[0]) << 56;
+-  ret |= ((uint64_t)d[1]) << 48;
+-  ret |= ((uint64_t)d[2]) << 40;
+-  ret |= ((uint64_t)d[3]) << 32;
+-  ret |= ((uint64_t)d[4]) << 24;
+-  ret |= ((uint64_t)d[5]) << 16;
+-  ret |= ((uint64_t)d[6]) << 8;
+-  ret |= ((uint64_t)d[7]);
+-  return ret;
+-}
++//#include <stdarg.h>
+ 
+ /* Converts a 32-bit unsigned integer from host to big-endian byte order. */
+ uint32_t avb_htobe32(uint32_t in) {
+@@ -63,341 +39,3 @@ uint32_t avb_htobe32(uint32_t in) {
+   return ret.word;
+ }
+ 
+-/* Converts a 64-bit unsigned integer from host to big-endian byte order. */
+-uint64_t avb_htobe64(uint64_t in) {
+-  union {
+-    uint64_t word;
+-    uint8_t bytes[8];
+-  } ret;
+-  ret.bytes[0] = (in >> 56) & 0xff;
+-  ret.bytes[1] = (in >> 48) & 0xff;
+-  ret.bytes[2] = (in >> 40) & 0xff;
+-  ret.bytes[3] = (in >> 32) & 0xff;
+-  ret.bytes[4] = (in >> 24) & 0xff;
+-  ret.bytes[5] = (in >> 16) & 0xff;
+-  ret.bytes[6] = (in >> 8) & 0xff;
+-  ret.bytes[7] = in & 0xff;
+-  return ret.word;
+-}
+-
+-int avb_safe_memcmp(const void* s1, const void* s2, size_t n) {
+-  const unsigned char* us1 = s1;
+-  const unsigned char* us2 = s2;
+-  int result = 0;
+-
+-  if (0 == n) {
+-    return 0;
+-  }
+-
+-  /*
+-   * Code snippet without data-dependent branch due to Nate Lawson
+-   * (nate@root.org) of Root Labs.
+-   */
+-  while (n--) {
+-    result |= *us1++ ^ *us2++;
+-  }
+-
+-  return result != 0;
+-}
+-
+-bool avb_safe_add_to(uint64_t* value, uint64_t value_to_add) {
+-  uint64_t original_value;
+-
+-  avb_assert(value != NULL);
+-
+-  original_value = *value;
+-
+-  *value += value_to_add;
+-  if (*value < original_value) {
+-    avb_error("Overflow when adding values.\n");
+-    return false;
+-  }
+-
+-  return true;
+-}
+-
+-bool avb_safe_add(uint64_t* out_result, uint64_t a, uint64_t b) {
+-  uint64_t dummy;
+-  if (out_result == NULL) {
+-    out_result = &dummy;
+-  }
+-  *out_result = a;
+-  return avb_safe_add_to(out_result, b);
+-}
+-
+-bool avb_validate_utf8(const uint8_t* data, size_t num_bytes) {
+-  size_t n;
+-  unsigned int num_cc;
+-
+-  for (n = 0, num_cc = 0; n < num_bytes; n++) {
+-    uint8_t c = data[n];
+-
+-    if (num_cc > 0) {
+-      if ((c & (0x80 | 0x40)) == 0x80) {
+-        /* 10xx xxxx */
+-      } else {
+-        goto fail;
+-      }
+-      num_cc--;
+-    } else {
+-      if (c < 0x80) {
+-        num_cc = 0;
+-      } else if ((c & (0x80 | 0x40 | 0x20)) == (0x80 | 0x40)) {
+-        /* 110x xxxx */
+-        num_cc = 1;
+-      } else if ((c & (0x80 | 0x40 | 0x20 | 0x10)) == (0x80 | 0x40 | 0x20)) {
+-        /* 1110 xxxx */
+-        num_cc = 2;
+-      } else if ((c & (0x80 | 0x40 | 0x20 | 0x10 | 0x08)) ==
+-                 (0x80 | 0x40 | 0x20 | 0x10)) {
+-        /* 1111 0xxx */
+-        num_cc = 3;
+-      } else {
+-        goto fail;
+-      }
+-    }
+-  }
+-
+-  if (num_cc != 0) {
+-    goto fail;
+-  }
+-
+-  return true;
+-
+-fail:
+-  return false;
+-}
+-
+-bool avb_str_concat(char* buf,
+-                    size_t buf_size,
+-                    const char* str1,
+-                    size_t str1_len,
+-                    const char* str2,
+-                    size_t str2_len) {
+-  uint64_t combined_len;
+-
+-  if (!avb_safe_add(&combined_len, str1_len, str2_len)) {
+-    avb_error("Overflow when adding string sizes.\n");
+-    return false;
+-  }
+-
+-  if (combined_len > buf_size - 1) {
+-    avb_error("Insufficient buffer space.\n");
+-    return false;
+-  }
+-
+-  avb_memcpy(buf, str1, str1_len);
+-  avb_memcpy(buf + str1_len, str2, str2_len);
+-  buf[combined_len] = '\0';
+-
+-  return true;
+-}
+-
+-void* avb_malloc(size_t size) {
+-  void* ret = avb_malloc_(size);
+-  if (ret == NULL) {
+-    avb_error("Failed to allocate memory.\n");
+-    return NULL;
+-  }
+-  return ret;
+-}
+-
+-void* avb_calloc(size_t size) {
+-  void* ret = avb_malloc(size);
+-  if (ret == NULL) {
+-    return NULL;
+-  }
+-
+-  avb_memset(ret, '\0', size);
+-  return ret;
+-}
+-
+-char* avb_strdup(const char* str) {
+-  size_t len = avb_strlen(str);
+-  char* ret = avb_malloc(len + 1);
+-  if (ret == NULL) {
+-    return NULL;
+-  }
+-
+-  avb_memcpy(ret, str, len);
+-  ret[len] = '\0';
+-
+-  return ret;
+-}
+-
+-const char* avb_strstr(const char* haystack, const char* needle) {
+-  size_t n, m;
+-
+-  /* Look through |haystack| and check if the first character of
+-   * |needle| matches. If so, check the rest of |needle|.
+-   */
+-  for (n = 0; haystack[n] != '\0'; n++) {
+-    if (haystack[n] != needle[0]) {
+-      continue;
+-    }
+-
+-    for (m = 1;; m++) {
+-      if (needle[m] == '\0') {
+-        return haystack + n;
+-      }
+-
+-      if (haystack[n + m] != needle[m]) {
+-        break;
+-      }
+-    }
+-  }
+-
+-  return NULL;
+-}
+-
+-const char* avb_strv_find_str(const char* const* strings,
+-                              const char* str,
+-                              size_t str_size) {
+-  size_t n;
+-  for (n = 0; strings[n] != NULL; n++) {
+-    if (avb_strlen(strings[n]) == str_size &&
+-        avb_memcmp(strings[n], str, str_size) == 0) {
+-      return strings[n];
+-    }
+-  }
+-  return NULL;
+-}
+-
+-char* avb_replace(const char* str, const char* search, const char* replace) {
+-  char* ret = NULL;
+-  size_t ret_len = 0;
+-  size_t search_len, replace_len;
+-  const char* str_after_last_replace;
+-
+-  search_len = avb_strlen(search);
+-  replace_len = avb_strlen(replace);
+-
+-  str_after_last_replace = str;
+-  while (*str != '\0') {
+-    const char* s;
+-    size_t num_before;
+-    size_t num_new;
+-
+-    s = avb_strstr(str, search);
+-    if (s == NULL) {
+-      break;
+-    }
+-
+-    num_before = s - str;
+-
+-    if (ret == NULL) {
+-      num_new = num_before + replace_len + 1;
+-      ret = avb_malloc(num_new);
+-      if (ret == NULL) {
+-        goto out;
+-      }
+-      avb_memcpy(ret, str, num_before);
+-      avb_memcpy(ret + num_before, replace, replace_len);
+-      ret[num_new - 1] = '\0';
+-      ret_len = num_new - 1;
+-    } else {
+-      char* new_str;
+-      num_new = ret_len + num_before + replace_len + 1;
+-      new_str = avb_malloc(num_new);
+-      if (ret == NULL) {
+-        goto out;
+-      }
+-      avb_memcpy(new_str, ret, ret_len);
+-      avb_memcpy(new_str + ret_len, str, num_before);
+-      avb_memcpy(new_str + ret_len + num_before, replace, replace_len);
+-      new_str[num_new - 1] = '\0';
+-      avb_free(ret);
+-      ret = new_str;
+-      ret_len = num_new - 1;
+-    }
+-
+-    str = s + search_len;
+-    str_after_last_replace = str;
+-  }
+-
+-  if (ret == NULL) {
+-    ret = avb_strdup(str_after_last_replace);
+-    if (ret == NULL) {
+-      goto out;
+-    }
+-  } else {
+-    size_t num_remaining = avb_strlen(str_after_last_replace);
+-    size_t num_new = ret_len + num_remaining + 1;
+-    char* new_str = avb_malloc(num_new);
+-    if (ret == NULL) {
+-      goto out;
+-    }
+-    avb_memcpy(new_str, ret, ret_len);
+-    avb_memcpy(new_str + ret_len, str_after_last_replace, num_remaining);
+-    new_str[num_new - 1] = '\0';
+-    avb_free(ret);
+-    ret = new_str;
+-    ret_len = num_new - 1;
+-  }
+-
+-out:
+-  return ret;
+-}
+-
+-/* We only support a limited amount of strings in avb_strdupv(). */
+-#define AVB_STRDUPV_MAX_NUM_STRINGS 32
+-
+-char* avb_strdupv(const char* str, ...) {
+-  va_list ap;
+-  const char* strings[AVB_STRDUPV_MAX_NUM_STRINGS];
+-  size_t lengths[AVB_STRDUPV_MAX_NUM_STRINGS];
+-  size_t num_strings, n;
+-  uint64_t total_length;
+-  char *ret = NULL, *dest;
+-
+-  num_strings = 0;
+-  total_length = 0;
+-  va_start(ap, str);
+-  do {
+-    size_t str_len = avb_strlen(str);
+-    strings[num_strings] = str;
+-    lengths[num_strings] = str_len;
+-    if (!avb_safe_add_to(&total_length, str_len)) {
+-      avb_fatal("Overflow while determining total length.\n");
+-      break;
+-    }
+-    num_strings++;
+-    if (num_strings == AVB_STRDUPV_MAX_NUM_STRINGS) {
+-      avb_fatal("Too many strings passed.\n");
+-      break;
+-    }
+-    str = va_arg(ap, const char*);
+-  } while (str != NULL);
+-  va_end(ap);
+-
+-  ret = avb_malloc(total_length + 1);
+-  if (ret == NULL) {
+-    goto out;
+-  }
+-
+-  dest = ret;
+-  for (n = 0; n < num_strings; n++) {
+-    avb_memcpy(dest, strings[n], lengths[n]);
+-    dest += lengths[n];
+-  }
+-  *dest = '\0';
+-  avb_assert(dest == ret + total_length);
+-
+-out:
+-  return ret;
+-}
+-
+-const char* avb_basename(const char* str) {
+-  int64_t n;
+-  size_t len;
+-
+-  len = avb_strlen(str);
+-  if (len >= 2) {
+-    for (n = len - 2; n >= 0; n--) {
+-      if (str[n] == '/') {
+-        return str + n + 1;
+-      }
+-    }
+-  }
+-  return str;
+-}
+diff --git a/libavb/avb_util.h b/libavb/avb_util.h
+index 07c3258..589e64c 100644
+--- a/libavb/avb_util.h
++++ b/libavb/avb_util.h
+@@ -22,254 +22,20 @@
+  * SOFTWARE.
+  */
+ 
+-#if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
+-#error "Never include this file directly, include libavb.h instead."
+-#endif
+-
+ #ifndef AVB_UTIL_H_
+ #define AVB_UTIL_H_
+ 
+-#include "avb_sysdeps.h"
+-
++#include <stdint.h>
++#include <sys/types.h>
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+-
+-#define AVB_STRINGIFY(x) #x
+-#define AVB_TO_STRING(x) AVB_STRINGIFY(x)
+-
+-#ifdef AVB_ENABLE_DEBUG
+-/* Aborts the program if |expr| is false.
+- *
+- * This has no effect unless AVB_ENABLE_DEBUG is defined.
+- */
+-#define avb_assert(expr)                     \
+-  do {                                       \
+-    if (!(expr)) {                           \
+-      avb_fatal("assert fail: " #expr "\n"); \
+-    }                                        \
+-  } while (0)
+-#else
+-#define avb_assert(expr)
+-#endif
+-
+-/* Aborts the program if reached.
+- *
+- * This has no effect unless AVB_ENABLE_DEBUG is defined.
+- */
+-#ifdef AVB_ENABLE_DEBUG
+-#define avb_assert_not_reached()         \
+-  do {                                   \
+-    avb_fatal("assert_not_reached()\n"); \
+-  } while (0)
+-#else
+-#define avb_assert_not_reached()
+-#endif
+-
+-/* Aborts the program if |addr| is not word-aligned.
+- *
+- * This has no effect unless AVB_ENABLE_DEBUG is defined.
+- */
+-#define avb_assert_aligned(addr) \
+-  avb_assert((((uintptr_t)addr) & (AVB_ALIGNMENT_SIZE - 1)) == 0)
+-
+-#ifdef AVB_ENABLE_DEBUG
+-/* Print functions, used for diagnostics.
+- *
+- * These have no effect unless AVB_ENABLE_DEBUG is defined.
+- */
+-#define avb_debug(message)              \
+-  do {                                  \
+-    avb_printv(avb_basename(__FILE__),  \
+-               ":",                     \
+-               AVB_TO_STRING(__LINE__), \
+-               ": DEBUG: ",             \
+-               message,                 \
+-               NULL);                   \
+-  } while (0)
+-#define avb_debugv(message, ...)        \
+-  do {                                  \
+-    avb_printv(avb_basename(__FILE__),  \
+-               ":",                     \
+-               AVB_TO_STRING(__LINE__), \
+-               ": DEBUG: ",             \
+-               message,                 \
+-               ##__VA_ARGS__);          \
+-  } while (0)
+-#else
+-#define avb_debug(message)
+-#define avb_debugv(message, ...)
+-#endif
+-
+-/* Prints out a message. This is typically used if a runtime-error
+- * occurs.
+- */
+-#define avb_error(message)              \
+-  do {                                  \
+-    avb_printv(avb_basename(__FILE__),  \
+-               ":",                     \
+-               AVB_TO_STRING(__LINE__), \
+-               ": ERROR: ",             \
+-               message,                 \
+-               NULL);                   \
+-  } while (0)
+-#define avb_errorv(message, ...)        \
+-  do {                                  \
+-    avb_printv(avb_basename(__FILE__),  \
+-               ":",                     \
+-               AVB_TO_STRING(__LINE__), \
+-               ": ERROR: ",             \
+-               message,                 \
+-               ##__VA_ARGS__);          \
+-  } while (0)
+-
+-/* Prints out a message and calls avb_abort().
+- */
+-#define avb_fatal(message)              \
+-  do {                                  \
+-    avb_printv(avb_basename(__FILE__),  \
+-               ":",                     \
+-               AVB_TO_STRING(__LINE__), \
+-               ": FATAL: ",             \
+-               message,                 \
+-               NULL);                   \
+-    avb_abort();                        \
+-  } while (0)
+-#define avb_fatalv(message, ...)        \
+-  do {                                  \
+-    avb_printv(avb_basename(__FILE__),  \
+-               ":",                     \
+-               AVB_TO_STRING(__LINE__), \
+-               ": FATAL: ",             \
+-               message,                 \
+-               ##__VA_ARGS__);          \
+-    avb_abort();                        \
+-  } while (0)
+-
+-/* Converts a 32-bit unsigned integer from big-endian to host byte order. */
+-uint32_t avb_be32toh(uint32_t in) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Converts a 64-bit unsigned integer from big-endian to host byte order. */
+-uint64_t avb_be64toh(uint64_t in) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+ /* Converts a 32-bit unsigned integer from host to big-endian byte order. */
+-uint32_t avb_htobe32(uint32_t in) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Converts a 64-bit unsigned integer from host to big-endian byte order. */
+-uint64_t avb_htobe64(uint64_t in) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Compare |n| bytes starting at |s1| with |s2| and return 0 if they
+- * match, 1 if they don't.  Returns 0 if |n|==0, since no bytes
+- * mismatched.
+- *
+- * Time taken to perform the comparison is only dependent on |n| and
+- * not on the relationship of the match between |s1| and |s2|.
+- *
+- * Note that unlike avb_memcmp(), this only indicates inequality, not
+- * whether |s1| is less than or greater than |s2|.
+- */
+-int avb_safe_memcmp(const void* s1,
+-                    const void* s2,
+-                    size_t n) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Adds |value_to_add| to |value| with overflow protection.
+- *
+- * Returns false if the addition overflows, true otherwise. In either
+- * case, |value| is always modified.
+- */
+-bool avb_safe_add_to(uint64_t* value,
+-                     uint64_t value_to_add) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Adds |a| and |b| with overflow protection, returning the value in
+- * |out_result|.
+- *
+- * It's permissible to pass NULL for |out_result| if you just want to
+- * check that the addition would not overflow.
+- *
+- * Returns false if the addition overflows, true otherwise.
+- */
+-bool avb_safe_add(uint64_t* out_result,
+-                  uint64_t a,
+-                  uint64_t b) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Checks if |num_bytes| data at |data| is a valid UTF-8
+- * string. Returns true if valid UTF-8, false otherwise.
+- */
+-bool avb_validate_utf8(const uint8_t* data,
+-                       size_t num_bytes) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Concatenates |str1| (of |str1_len| bytes) and |str2| (of |str2_len|
+- * bytes) and puts the result in |buf| which holds |buf_size|
+- * bytes. The result is also guaranteed to be NUL terminated. Fail if
+- * there is not enough room in |buf| for the resulting string plus
+- * terminating NUL byte.
+- *
+- * Returns true if the operation succeeds, false otherwise.
+- */
+-bool avb_str_concat(char* buf,
+-                    size_t buf_size,
+-                    const char* str1,
+-                    size_t str1_len,
+-                    const char* str2,
+-                    size_t str2_len);
+-
+-/* Like avb_malloc_() but prints a error using avb_error() if memory
+- * allocation fails.
+- */
+-void* avb_malloc(size_t size) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Like avb_malloc() but sets the memory with zeroes. */
+-void* avb_calloc(size_t size) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Duplicates a NUL-terminated string. Returns NULL on OOM. */
+-char* avb_strdup(const char* str) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Duplicates a NULL-terminated array of NUL-terminated strings by
+- * concatenating them. The returned string will be
+- * NUL-terminated. Returns NULL on OOM.
+- */
+-char* avb_strdupv(const char* str,
+-                  ...) AVB_ATTR_WARN_UNUSED_RESULT AVB_ATTR_SENTINEL;
+-
+-/* Finds the first occurrence of |needle| in the string |haystack|
+- * where both strings are NUL-terminated strings. The terminating NUL
+- * bytes are not compared.
+- *
+- * Returns NULL if not found, otherwise points into |haystack| for the
+- * first occurrence of |needle|.
+- */
+-const char* avb_strstr(const char* haystack,
+-                       const char* needle) AVB_ATTR_WARN_UNUSED_RESULT;
+-
+-/* Finds the first occurrence of |str| in the NULL-terminated string
+- * array |strings|. Each element in |strings| must be
+- * NUL-terminated. The string given by |str| need not be
+- * NUL-terminated but its size must be given in |str_size|.
+- *
+- * Returns NULL if not found, otherwise points into |strings| for the
+- * first occurrence of |str|.
+- */
+-const char* avb_strv_find_str(const char* const* strings,
+-                              const char* str,
+-                              size_t str_size);
+-
+-/* Replaces all occurrences of |search| with |replace| in |str|.
+- *
+- * Returns a newly allocated string or NULL if out of memory.
+- */
+-char* avb_replace(const char* str,
+-                  const char* search,
+-                  const char* replace) AVB_ATTR_WARN_UNUSED_RESULT;
++uint32_t avb_htobe32(uint32_t in);
+ 
+ /* Calculates the CRC-32 for data in |buf| of size |buf_size|. */
+ uint32_t avb_crc32(const uint8_t* buf, size_t buf_size);
+ 
+-/* Returns the basename of |str|. This is defined as the last path
+- * component, assuming the normal POSIX separator '/'. If there are no
+- * separators, returns |str|.
+- */
+-const char* avb_basename(const char* str);
+-
+ #ifdef __cplusplus
+ }
+ #endif
diff --git a/meta/meta-mediatek/recipes-support/libavb/libavb.bb b/meta/meta-mediatek/recipes-support/libavb/libavb.bb
new file mode 100644
index 0000000..63e979b
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/libavb/libavb.bb
@@ -0,0 +1,25 @@
+inherit deploy
+
+DESCRIPTION = "Android Verify Boot"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+SRC_URI = " \
+        git://android.googlesource.com/platform/external/avb;name=platform/external/avb;destsuffix=platform/external/avb/;protocol=https \
+        file://libavb.patch \
+"
+SRCREV = "c68f082d910b674f9e5ecf05ebe77432dbbfe0b6"
+
+SRC_URI[sha256sum] = "833893127582352d05d925e36a2ba82d7837105ec8915cd82c7ba9abdddcf680"
+SRC_URI[md5sum] = "1935b6e637d9413cc48115e7602dec4f"
+
+S = "${WORKDIR}/platform/external/avb"
+
+INSANE_SKIP_${PN} += "installed-vs-shipped"
+
+do_install() {
+	install -d ${D}${includedir}
+	install -d ${D}${datadir}
+	install -m 0644 ${S}/libavb/avb_util.h  ${D}${includedir}
+	install -m 0644 ${S}/libavb/avb_crc32.c  ${D}${datadir}
+	install -m 0644 ${S}/libavb/avb_util.c  ${D}${datadir}
+}
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/libhardware/files/hardware.patch b/meta/meta-mediatek/recipes-support/libhardware/files/hardware.patch
new file mode 100644
index 0000000..338f369
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/libhardware/files/hardware.patch
@@ -0,0 +1,15 @@
+diff --git a/include/hardware/hardware.h b/include/hardware/hardware.h
+index bf076f6c..ecc12cb1 100644
+--- a/include/hardware/hardware.h
++++ b/include/hardware/hardware.h
+@@ -20,8 +20,8 @@
+ #include <stdint.h>
+ #include <sys/cdefs.h>
+ 
+-#include <cutils/native_handle.h>
+-#include <system/graphics.h>
++//#include <cutils/native_handle.h>
++//#include <system/graphics.h>
+ 
+ __BEGIN_DECLS
+ 
diff --git a/meta/meta-mediatek/recipes-support/libhardware/libhardware.bb b/meta/meta-mediatek/recipes-support/libhardware/libhardware.bb
new file mode 100644
index 0000000..988c940
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/libhardware/libhardware.bb
@@ -0,0 +1,18 @@
+DESCRIPTION = "Android libhardware"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://NOTICE;md5=9645f39e9db895a4aa6e02cb57294595"
+
+SRC_URI = " \
+	git://android.googlesource.com/platform/hardware/libhardware;name=platform/hardware/libhardware;destsuffix=platform/hardware/libhardware/ \
+	file://hardware.patch \
+"
+
+SRCREV_platform/hardware/libhardware = "51d03179c9ddeeb71f36bfac40e445263b5e76e2"
+
+S = "${WORKDIR}/platform/hardware/libhardware"
+
+do_install(){
+	install -d ${D}${includedir}
+	install -m 0644 ${S}/include/hardware/hardware.h  ${D}${includedir}
+	install -m 0644 ${S}/include/hardware/boot_control.h  ${D}${includedir}
+}
diff --git a/meta/meta-mediatek/recipes-support/libnvram_custom/libnvramcustom_1.0.0.bb b/meta/meta-mediatek/recipes-support/libnvram_custom/libnvramcustom_1.0.0.bb
new file mode 100644
index 0000000..37cd529
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/libnvram_custom/libnvramcustom_1.0.0.bb
@@ -0,0 +1,75 @@
+#Basic Configuration
+DESCRIPTION = "Customization."
+SECTION = "base"
+LICENSE = "MediaTekProprietary"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173fff"
+DEPENDS = "custom"
+MTK_SRC = "${TOPDIR}/../src/support/libnvram_custom"
+NVRAM_PREFIX = "${STAGING_DIR}/${MACHINE}${includedir}/install"
+
+WORKONSRC = "${MTK_SRC}"
+BB_INCLUDE_ADD = "--sysroot=${STAGING_DIR_HOST} -I${TOPDIR}/../src/support/nvram/libnvram"
+BB_LDFLAGS_ADD = "--sysroot=${STAGING_DIR_HOST}"
+
+inherit deploy workonsrc
+PRJ_FILENAME = "${MTK_PROJECT}"
+#Parameters passed to do_compile()
+EXTRA_OEMAKE = "'CROSS=${TARGET_PREFIX}'\
+		'PREFIX=${NVRAM_PREFIX}'\
+		'PACKAGE_ARCH=${PACKAGE_ARCH}'\
+		'BB_INCLUDE_ADD=${BB_INCLUDE_ADD}'\
+		'BB_LDFLAGS_ADD=${BB_LDFLAGS_ADD}'\
+		'PRJ_FILENAME=${PRJ_FILENAME}'\
+		'NVRAM_COMBO_CHIP_ID=${COMBO_CHIP_ID}'"
+
+FILES_${PN} = "${base_libdir}/*.so\
+		${base_bindir}\
+		${base_sbindir}\
+		/mnt\
+		/tmp\
+		/etc\
+		/test"
+
+FILES_${PN}-dev = "${includedir}"
+
+FILES_${PN}-staticdev = "${base_libdir}/*.a"
+
+FILES_${PN}-doc = "/doc"
+
+FILES_${PN}-dbg = "/usr/src/debug \
+		   ${base_bindir}/.debug \
+		   ${base_libdir}/.debug \
+		   ${base_sbindir}/.debug"
+
+
+#Skip strip check in QA test.
+INSANE_SKIP_${PN} += "already-stripped"
+
+
+do_compile () {
+	unset LDFLAGS
+	oe_runmake all ROOT=${STAGING_DIR_HOST}${exec_prefix} BOOTDEV_TYPE=${BOOTDEV_TYPE}
+}
+
+do_install () {
+    oe_runmake install ROOT=${D}
+
+	if [ -d "${S}/CFG/${PRJ_FILENAME}/cgen/" ]; then
+		install -d ${D}${includedir}
+		cp -af ${S}/CFG/${PRJ_FILENAME}/cgen/* ${D}${includedir}
+	else
+		if [ -d "${D}/include" ]; then
+			install -d ${D}${includedir}
+			cp -af ${D}/include/* ${D}${includedir}
+			rm -rf ${D}/include
+		fi
+	fi
+}
+
+addtask nvramclean
+do_nvramclean () {
+	oe_runmake clean
+}
+
+INSANE_SKIP_${PN} += "ldflags"
+INSANE_SKIP_${PN} += "installed-vs-shipped"
diff --git a/meta/meta-mediatek/recipes-support/nvram/files/nvram_daemon-service b/meta/meta-mediatek/recipes-support/nvram/files/nvram_daemon-service
new file mode 100644
index 0000000..4fdcab7
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/nvram/files/nvram_daemon-service
@@ -0,0 +1,64 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: nvram_daemon
+# Required-Start:	$syslog $local_fs 
+# Required-Stop:	$syslog $local_fs 
+# Default-Start:	2 3 4 5
+# Default-Stop:		0 1 6
+# Short-Description: nvram_daemon
+### END INIT INFO
+
+. /etc/init.d/init-functions
+prog=nvram_daemon
+PIDFILE=/var/run/$prog.pid
+DESC="nvram_daemon"
+start() {
+	log_daemon_msg "Starting $DESC" "$prog"
+	start_daemon_background -p $PIDFILE /sbin/nvram_daemon
+	if [ $? -ne 0 ]; then
+		log_end_msg 1
+		exit 1
+	fi
+	if [ $? -eq 0 ]; then
+		log_end_msg 0
+	fi
+	exit 0
+}
+
+stop() {
+	log_daemon_msg "Stopping $DESC" "$prog"
+	killproc -p $PIDFILE /sbin/nvram_daemon
+	if [ $? -ne 0 ]; then
+		log_end_msg 1
+		exit 1
+	fi
+	if [ $? -eq 0 ]; then
+		log_end_msg 0
+	fi
+}
+
+force_reload() {
+	stop
+	start
+
+}
+
+case "$1" in
+	start)
+		start
+		;;
+	stop)
+		stop
+		;;
+	force-reload)
+		force_reload
+		;;
+	restart)
+		stop
+		start
+		;;
+
+	*)
+		echo "$Usage: $prog {start|stop|force-reload|restart}"
+		exit 2
+esac
diff --git a/meta/meta-mediatek/recipes-support/nvram/files/nvram_daemon.service b/meta/meta-mediatek/recipes-support/nvram/files/nvram_daemon.service
new file mode 100644
index 0000000..19cfada
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/nvram/files/nvram_daemon.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=nvram_daemon
+
+[Service]
+ExecStart=/sbin/nvram_daemon
+Type=simple
+
+[Install]
+Alias=nvramdaemon
+WantedBy=multi-user.target
diff --git a/meta/meta-mediatek/recipes-support/nvram/nvram_1.0.0.bb b/meta/meta-mediatek/recipes-support/nvram/nvram_1.0.0.bb
new file mode 100644
index 0000000..5520ebf
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/nvram/nvram_1.0.0.bb
@@ -0,0 +1,94 @@
+#Basic Configuration
+DESCRIPTION = "NVRAM."
+SECTION = "base"
+LICENSE = "MediaTekProprietary"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173fff"
+DEPENDS = "libnvramcustom"
+MTK_SRC = "${TOPDIR}/../src/support/nvram"
+NVRAM_PREFIX = "${STAGING_DIR}/${MACHINE}${includedir}/install"
+SRC_URI += "file://nvram_daemon.service"
+
+WORKONSRC = "${MTK_SRC}"
+BB_INCLUDE_ADD = "--sysroot=${STAGING_DIR_HOST}"
+BB_LDFLAGS_ADD = "--sysroot=${STAGING_DIR_HOST}"
+
+inherit deploy workonsrc systemd
+PRJ_FILENAME = "${MTK_PROJECT}"
+#Parameters passed to do_compile()
+EXTRA_OEMAKE = "'CROSS=${TARGET_PREFIX}'\
+		'PREFIX=${NVRAM_PREFIX}'\
+		'PACKAGE_ARCH=${PACKAGE_ARCH}'\
+		'BB_INCLUDE_ADD=${BB_INCLUDE_ADD}'\
+		'BB_LDFLAGS_ADD=${BB_LDFLAGS_ADD}'\
+		'PRJ_FILENAME=${PRJ_FILENAME}'"
+
+FILES_${PN} = "${base_libdir}/*.so\
+		${base_bindir}\
+		${base_sbindir}\
+		/mnt\
+		/tmp\
+		/etc\
+		/usr/out\
+		/test"
+
+FILES_${PN}-dev = "${includedir} \
+		   /out"
+
+FILES_${PN}-staticdev = "${base_libdir}/*.a"
+
+FILES_${PN}-doc = "/doc"
+
+FILES_${PN}-dbg = "/usr/src/debug \
+		   ${base_sbindir}/.debug \
+		   ${base_libdir}/.debug"
+
+#Skip strip check in QA test.
+INSANE_SKIP_${PN} += "already-stripped"
+
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE_${PN} = "nvram_daemon.service"
+FILES_${PN} += "${systemd_unitdir}/system/nvram_daemon.service"
+
+do_compile () {
+	unset LDFLAGS
+	oe_runmake all ROOT=${STAGING_DIR_HOST}${exec_prefix} VA_SUPPORT_GVA_SDK=${VA_SUPPORT_GVA_SDK} AUDIO_SUPPORT_C4A_SDK=${AUDIO_SUPPORT_C4A_SDK} VA_SUPPORT_ALEXA_SDK=${VA_SUPPORT_ALEXA} VA_SUPPORT_ALEXA_SDK_FFS=${VA_SUPPORT_ALEXA_FFS}
+}
+
+do_install () {
+    oe_runmake install ROOT=${D}
+
+	if [ -d "${D}/include" ]; then
+		install -d ${D}${includedir}
+		cp -af ${D}/include/* ${D}${includedir}
+		rm -rf ${D}/include
+	fi
+}
+
+do_install_append() {
+	if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
+		install -d ${D}${systemd_unitdir}/system
+		install -m 644 ${WORKDIR}/nvram_daemon.service ${D}${systemd_unitdir}/system
+	fi
+}
+
+addtask nvramclean
+do_nvramclean () {
+	oe_runmake clean
+}
+
+INSANE_SKIP_${PN} += "ldflags"
+
+
+# Install Sysvinit Scripts #
+DEPENDS_append = " update-rc.d-native"
+INITSCRIPT_NAME_nvram_daemon-service = "nvram_daemon-service"
+INITSCRIPT_PARAMS_nvram_daemon-service = "start 11 3 ."
+FILES_${PN} += "${sysconfdir}/init.d/nvram_daemon-service"
+
+do_install_append() {
+	if ${@bb.utils.contains('DISTRO_FEATURES','sysvinit','true','false',d)}; then
+		install -d ${D}${sysconfdir}/init.d
+		install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/nvram/files/nvram_daemon-service ${D}${sysconfdir}/init.d/nvram_daemon-service
+		update-rc.d -r ${D} ${INITSCRIPT_NAME_nvram_daemon-service} ${INITSCRIPT_PARAMS_nvram_daemon-service}
+	fi
+}
diff --git a/meta/meta-mediatek/recipes-support/nvram/rw-nvram.bb b/meta/meta-mediatek/recipes-support/nvram/rw-nvram.bb
new file mode 100644
index 0000000..c345ec3
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/nvram/rw-nvram.bb
@@ -0,0 +1,22 @@
+DESCRIPTION = "rw_nvram"
+LICENSE = "MPLV2"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173ff"
+DEPENDS = "libnvramcustom nvram"
+WORKING_SRC = "${TOPDIR}/../src/support/nvram/tests"
+
+inherit workonsrc
+
+WORKONSRC = "${WORKING_SRC}"
+
+do_compile() {
+	oe_runmake
+}
+
+do_install() {
+	install -d ${D}/${bindir}
+	install -m 755 ${S}/rw_nvram ${D}/${bindir}
+}
+
+FILES_${PN} += "${bindir}"
+FILES_${PN}-dev = ""
+INSANE_SKIP_${PN} += "already-stripped"
diff --git a/meta/meta-mediatek/recipes-support/pdct/pdct.bb b/meta/meta-mediatek/recipes-support/pdct/pdct.bb
new file mode 100644
index 0000000..96f3cfb
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/pdct/pdct.bb
@@ -0,0 +1,41 @@
+DESCRIPTION = "MTK PDCT"
+LICENSE = "MediaTekProprietary"
+
+inherit get_toolchain_name
+inherit workonsrc
+WORKONSRC = "${TOPDIR}/../src/support/pdct/asf/"
+
+DEPENDS += "${@bb.utils.contains('TEE_SUPPORT', 'mtee', 'tzapp', '' ,d)}"
+RDEPENDS_${PN} += "${@bb.utils.contains('TEE_SUPPORT', 'mtee', 'tzapp', '' ,d)}"
+DEPENDS += "${@bb.utils.contains('TEE_SUPPORT', 'optee', 'optee-services', '' ,d)}"
+RDEPENDS_${PN} += "${@bb.utils.contains('TEE_SUPPORT', 'optee', 'optee-services', '' ,d)}"
+
+BASE_TARGET_PLATFORM ?= "${TARGET_PLATFORM}"
+
+do_compile() {
+    if test -e ${WORKONSRC} ; then
+        if test "${TEE_SUPPORT}" = "optee" ;then
+            oe_runmake LDFLAGS='${LDFLAGS} -shared -ltz_efuse' CONFIG_MTK_PLATFORM="${BASE_TARGET_PLATFORM}"
+        else
+            oe_runmake LDFLAGS='${LDFLAGS} -shared -ltz_efuse -ltz_uree' CONFIG_MTK_PLATFORM="${BASE_TARGET_PLATFORM}"
+        fi
+    fi
+}
+
+do_install() {
+    if ! test -e ${WORKONSRC} ; then
+        if test "${DEFAULTTUNE}" = "aarch64" ; then
+            make install -C "${TOPDIR}/../prebuilt/support/pdct/${BASE_TARGET_PLATFORM}" DESTDIR="${D}" TOOL_CHAIN=${TOOLCHAIN_NAME} AARCH="arm64"
+        else
+            make install -C "${TOPDIR}/../prebuilt/support/pdct/${BASE_TARGET_PLATFORM}" DESTDIR="${D}" TOOL_CHAIN=${TOOLCHAIN_NAME} AARCH="arm"
+        fi
+    else
+        install -d ${D}${libdir}
+        install -m 644 libpdct.so ${D}${libdir}
+    fi
+}
+
+FILES_${PN}-dev = ""
+FILES_${PN} += "${libdir}/libpdct.so"
+INSANE_SKIP_${PN} = "already-stripped ldflags"
+INHIBIT_PACKAGE_STRIP = "1"
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/base.patch b/meta/meta-mediatek/recipes-support/platform-libs-common/files/base.patch
new file mode 100644
index 0000000..4f70bf5
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/base.patch
@@ -0,0 +1,42 @@
+diff --git a/system/core/base/errors_unix.cpp b/system/core/base/errors_unix.cpp
+old mode 100644
+new mode 100755
+index 296995e..48269b6
+--- a/system/core/base/errors_unix.cpp
++++ b/system/core/base/errors_unix.cpp
+@@ -17,6 +17,7 @@
+ #include "android-base/errors.h"
+ 
+ #include <errno.h>
++#include <string.h>
+ 
+ namespace android {
+ namespace base {
+diff --git a/system/core/base/file.cpp b/system/core/base/file.cpp
+old mode 100644
+new mode 100755
+index da1adba..91a3901
+--- a/system/core/base/file.cpp
++++ b/system/core/base/file.cpp
+@@ -20,6 +20,7 @@
+ #include <fcntl.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
++#include <string.h>
+ 
+ #include <string>
+ 
+diff --git a/system/core/base/logging.cpp b/system/core/base/logging.cpp
+old mode 100644
+new mode 100755
+index 1741871..e5a98e3
+--- a/system/core/base/logging.cpp
++++ b/system/core/base/logging.cpp
+@@ -18,6 +18,7 @@
+ #include <windows.h>
+ #endif
+ 
++#include <string.h>
+ #include "android-base/logging.h"
+ 
+ #include <libgen.h>
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/include.patch b/meta/meta-mediatek/recipes-support/platform-libs-common/files/include.patch
new file mode 100644
index 0000000..b13bff7
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/include.patch
@@ -0,0 +1,218 @@
+diff --git a/system/core/include/cutils/atomic.h b/system/core/include/cutils/atomic.h
+index ded972a..fb83e77 100644
+--- a/system/core/include/cutils/atomic.h
++++ b/system/core/include/cutils/atomic.h
+@@ -19,7 +19,12 @@
+ 
+ #include <stdint.h>
+ #include <sys/types.h>
++#ifdef __cplusplus
++#include <atomic>
++using namespace std;
++#else
+ #include <stdatomic.h>
++#endif
+ 
+ #ifndef ANDROID_ATOMIC_INLINE
+ #define ANDROID_ATOMIC_INLINE static inline
+diff --git a/system/core/include/cutils/properties.h b/system/core/include/cutils/properties.h
+index 24aa224..2957e2c 100644
+--- a/system/core/include/cutils/properties.h
++++ b/system/core/include/cutils/properties.h
+@@ -33,8 +33,8 @@ extern "C" {
+ ** WARNING: system/bionic/include/sys/system_properties.h also defines
+ **          these, but with different names.  (TODO: fix that)
+ */
+-#define PROPERTY_KEY_MAX   PROP_NAME_MAX
+-#define PROPERTY_VALUE_MAX  PROP_VALUE_MAX
++#define PROPERTY_KEY_MAX   64
++#define PROPERTY_VALUE_MAX  96
+ 
+ /* property_get: returns the length of the value which will never be
+ ** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated.
+diff --git a/system/core/include/private/android_filesystem_config.h b/system/core/include/private/android_filesystem_config.h
+index e540de2..dac5eb5 100644
+--- a/system/core/include/private/android_filesystem_config.h
++++ b/system/core/include/private/android_filesystem_config.h
+@@ -40,7 +40,7 @@
+ 
+ #define AID_ROOT             0  /* traditional unix root user */
+ 
+-#define AID_SYSTEM        1000  /* system server */
++#define AID_SYSTEM        0  /* system server */
+ 
+ #define AID_RADIO         1001  /* telephony subsystem, RIL */
+ #define AID_BLUETOOTH     1002  /* bluetooth subsystem */
+diff --git a/system/core/include/sysutils/FrameworkListener.h b/system/core/include/sysutils/FrameworkListener.h
+index 18049cd..2137069 100644
+--- a/system/core/include/sysutils/FrameworkListener.h
++++ b/system/core/include/sysutils/FrameworkListener.h
+@@ -32,6 +32,7 @@ private:
+     int mCommandCount;
+     bool mWithSeq;
+     FrameworkCommandCollection *mCommands;
++    bool mSkipToNextNullByte;
+ 
+ public:
+     FrameworkListener(const char *socketName);
+diff --git a/system/core/include/sysutils/NetlinkEvent.h b/system/core/include/sysutils/NetlinkEvent.h
+index b80f3ea..fd9cab4 100644
+--- a/system/core/include/sysutils/NetlinkEvent.h
++++ b/system/core/include/sysutils/NetlinkEvent.h
+@@ -34,6 +34,9 @@ public:
+         kRdnss = 8,
+         kRouteUpdated = 9,
+         kRouteRemoved = 10,
++        kIPv6Enable = 100,
++        kIPv6Disable = 101,
++        kNoRA = 108,
+     };
+ 
+ private:
+@@ -64,6 +67,8 @@ public:
+     bool parseNfPacketMessage(struct nlmsghdr *nh);
+     bool parseRtMessage(const struct nlmsghdr *nh);
+     bool parseNdUserOptMessage(const struct nlmsghdr *nh);
++    bool parseNewPrefixMessage(const struct nlmsghdr *nh);    
++    bool parseNoRAMessage(const struct nlmsghdr *nh);   
+ };
+ 
+ #endif
+diff --git a/system/core/include/utils/CallStack.h b/system/core/include/utils/CallStack.h
+index 27e89f4..ee986b7 100644
+--- a/system/core/include/utils/CallStack.h
++++ b/system/core/include/utils/CallStack.h
+@@ -18,7 +18,12 @@
+ #define ANDROID_CALLSTACK_H
+ 
+ #include <android/log.h>
++#ifdef __ANDROID__
+ #include <backtrace/backtrace_constants.h>
++#else
++#define BACKTRACE_CURRENT_THREAD -1
++#endif
++
+ #include <utils/String8.h>
+ #include <utils/Vector.h>
+ 
+diff --git a/system/core/include/utils/Printer.h b/system/core/include/utils/Printer.h
+index bb66287..5371afb 100644
+--- a/system/core/include/utils/Printer.h
++++ b/system/core/include/utils/Printer.h
+@@ -17,7 +17,11 @@
+ #ifndef ANDROID_PRINTER_H
+ #define ANDROID_PRINTER_H
+ 
++#if defined(__ANDROID__)
+ #include <android/log.h>
++#else
++#include <cutils/log.h>
++#endif
+ 
+ namespace android {
+ 
+diff --git a/system/core/include/utils/ThreadDefs.h b/system/core/include/utils/ThreadDefs.h
+index ae091e4..7f73c4e 100644
+--- a/system/core/include/utils/ThreadDefs.h
++++ b/system/core/include/utils/ThreadDefs.h
+@@ -19,8 +19,66 @@
+ 
+ #include <stdint.h>
+ #include <sys/types.h>
++#if defined(__ANDROID__)
+ #include <system/graphics.h>
+ #include <system/thread_defs.h>
++#else
++
++#if defined(__cplusplus)
++extern "C" {
++#endif
++
++enum {
++    /*
++     * ***********************************************
++     * ** Keep in sync with android.os.Process.java **
++     * ***********************************************
++     *
++     * This maps directly to the "nice" priorities we use in Android.
++     * A thread priority should be chosen inverse-proportionally to
++     * the amount of work the thread is expected to do. The more work
++     * a thread will do, the less favorable priority it should get so that
++     * it doesn't starve the system. Threads not behaving properly might
++     * be "punished" by the kernel.
++     * Use the levels below when appropriate. Intermediate values are
++     * acceptable, preferably use the {MORE|LESS}_FAVORABLE constants below.
++     */
++    ANDROID_PRIORITY_LOWEST         =  19,
++
++    /* use for background tasks */
++    ANDROID_PRIORITY_BACKGROUND     =  10,
++
++    /* most threads run at normal priority */
++    ANDROID_PRIORITY_NORMAL         =   0,
++
++    /* threads currently running a UI that the user is interacting with */
++    ANDROID_PRIORITY_FOREGROUND     =  -2,
++
++    /* the main UI thread has a slightly more favorable priority */
++    ANDROID_PRIORITY_DISPLAY        =  -4,
++
++    /* ui service treads might want to run at a urgent display (uncommon) */
++    ANDROID_PRIORITY_URGENT_DISPLAY =  -8,
++
++    /* all normal audio threads */
++    ANDROID_PRIORITY_AUDIO          = -16,
++
++    /* service audio threads (uncommon) */
++    ANDROID_PRIORITY_URGENT_AUDIO   = -18,
++
++    /* should never be used in practice. regular process might not
++     * be allowed to use this level */
++    ANDROID_PRIORITY_HIGHEST        = -20,
++
++    ANDROID_PRIORITY_DEFAULT        = ANDROID_PRIORITY_NORMAL,
++    ANDROID_PRIORITY_MORE_FAVORABLE = -1,
++    ANDROID_PRIORITY_LESS_FAVORABLE = +1,
++};
++
++#if defined(__cplusplus)
++}
++#endif
++#endif
+ 
+ // ---------------------------------------------------------------------------
+ // C API
+diff --git a/system/core/include/utils/Vector.h b/system/core/include/utils/Vector.h
+index ed7b725..239b33f 100644
+--- a/system/core/include/utils/Vector.h
++++ b/system/core/include/utils/Vector.h
+@@ -242,13 +242,13 @@ Vector<TYPE>::~Vector() {
+ 
+ template<class TYPE> inline
+ Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) {
+-    VectorImpl::operator = (rhs);
++    VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
+     return *this; 
+ }
+ 
+ template<class TYPE> inline
+ const Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) const {
+-    VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
++    VectorImpl::operator = (rhs);
+     return *this;
+ }
+
+diff --git a/system/core/base/include/android-base/strings.h b/system/core/base/include/android-base/strings.h
+index 69781cd..82f7897 100644
+--- a/system/core/base/include/android-base/strings.h
++++ b/system/core/base/include/android-base/strings.h
+@@ -62,6 +62,9 @@ bool StartsWith(const std::string& s, const char* prefix);
+ // Tests whether 's' ends with 'suffix'.
+ bool EndsWith(const std::string& s, const char* suffix);
+ 
++// Tests whether 'lhs' equals 'rhs', ignoring case.
++bool EqualsIgnoreCase(const std::string& lhs, const std::string& rhs);
++
+ }  // namespace base
+ }  // namespace android
+ 
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/liblog.patch b/meta/meta-mediatek/recipes-support/platform-libs-common/files/liblog.patch
new file mode 100644
index 0000000..bac8222
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/liblog.patch
@@ -0,0 +1,252 @@
+diff --git a/system/core/liblog/logger_write.c b/system/core/liblog/logger_write.c
+index b802ed7..3061862 100644
+--- a/system/core/liblog/logger_write.c
++++ b/system/core/liblog/logger_write.c
+@@ -31,6 +31,14 @@
+ #include <private/android_filesystem_config.h>
+ #include <private/android_logger.h>
+ 
++#define __REDIRECT_TO_SYSLOGD__
++
++#if defined(__REDIRECT_TO_SYSLOGD__)
++#include <syslog.h>
++#include <sys/syscall.h>
++#include <unistd.h>
++#endif
++
+ #include "config_write.h"
+ #include "log_portability.h"
+ #include "logger.h"
+@@ -186,8 +194,187 @@ static inline uint32_t get4LE(const uint8_t* src)
+     return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
+ }
+ 
++#if defined(__REDIRECT_TO_SYSLOGD__)
++static int filterPriAndSysPri (android_LogPriority pri, int *sys_pri)
++{
++    switch (pri) {
++    case ANDROID_LOG_DEBUG:
++        *sys_pri = LOG_DEBUG;
++        return 3;
++    case ANDROID_LOG_INFO:
++        *sys_pri = LOG_INFO;
++        return 4;
++    case ANDROID_LOG_WARN:
++        *sys_pri = LOG_WARNING;
++         return 5;
++    case ANDROID_LOG_ERROR:
++        *sys_pri = LOG_ERR;
++        return 6;
++    case ANDROID_LOG_FATAL:
++        *sys_pri = LOG_CRIT;
++        return 7;
++    case ANDROID_LOG_SILENT:
++        *sys_pri = LOG_EMERG;
++        return 8;
++
++    case ANDROID_LOG_DEFAULT:
++    case ANDROID_LOG_UNKNOWN:
++    default:
++        *sys_pri = LOG_INFO;
++        return 1;
++    }
++}
++
++static char *filterLogId(log_id_t log_id)
++{
++    switch (log_id) {
++    case LOG_ID_MAIN:
++        return "MAIN";
++    case LOG_ID_RADIO :
++        return "RADIO";
++    case LOG_ID_EVENTS:
++        return "EVENT";
++    case LOG_ID_SYSTEM:
++        return "SYSTEM";
++    default:
++        return "UNKOWN";
++    }
++}
++
++/*
++ * Extract an 8-byte value from a byte stream.
++ */
++static inline uint64_t get8LE(const uint8_t* src)
++{
++    uint32_t low, high;
++
++    low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
++    high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24);
++    return ((long long) high << 32) | (long long) low;
++}
++
++static char filterEvtType(char type, char *buf, void *payload, ssize_t len)
++{
++    switch(type) {
++    case EVENT_TYPE_INT:
++        sprintf(buf, "%d", get4LE(payload));
++        return 'I';
++    case EVENT_TYPE_LONG:
++        sprintf(buf, "%lld", get8LE(payload));
++        return 'L';
++    case EVENT_TYPE_STRING:
++        snprintf(buf, len, "%s", payload);
++        buf[len] = '\0';
++        return 'S';
++    default: /* not support */
++        sprintf(buf, "?");
++        return '?';
++    }
++}
++#endif
++
++
+ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr)
+ {
++#if defined(__REDIRECT_TO_SYSLOGD__)
++    int ret;
++    size_t totalLen = 0, defaultLen = 512, prefixLen;
++    int write_allocate = 0;
++    int sys_pri = LOG_INFO;
++    char *writeBuf = NULL;
++    char defaultBuf[512];
++    char prefixBuf[128];
++    char *idChar;
++    int priChar;
++
++    // for main, system, radio
++    ssize_t msg_len = 0;
++    int  priority = ANDROID_LOG_INFO;
++    char *tag, *msg;
++
++    // for event
++    int32_t etag;
++    char type;
++    void *payload;
++
++    // ------------------------------------------------------------------
++    // get log id
++    idChar  = filterLogId(log_id);
++
++#if 0 //disable event logid
++    if(log_id == LOG_ID_EVENTS) { /* event type */
++        if(nr == 2) { // __android_log_bwrite
++            etag    = *((int32_t *)vec[0].iov_base);
++            type    = EVENT_TYPE_INT;
++            payload = (void *)vec[1].iov_base;
++            msg_len = vec[1].iov_len;
++        } else { // __android_log_btwrite
++            etag    = *((int32_t *)vec[0].iov_base);
++            type    = *((char *)vec[1].iov_base);
++
++            if(!strcmp(&type, ""))
++                type = EVENT_TYPE_STRING;
++
++            payload = (void *)vec[2].iov_base;
++            msg_len = vec[2].iov_len;
++        }
++
++        // get type char
++        priChar = filterEvtType(type, prefixBuf, payload, msg_len);
++
++        // format prefix (brief format)
++        snprintf(defaultBuf, sizeof(defaultBuf),
++                 "<%c>/%c/%d(%5d): %s\n",
++                 idChar, priChar, etag, getpid(), prefixBuf);
++        // log to syslog
++        syslog(sys_pri, "%s", defaultBuf);
++        ret = strlen(defaultBuf);
++    }
++    else
++#endif
++    {   /* radio, system, main */
++        // get messages and tag from io vector
++        msg_len  = vec[2].iov_len;
++        priority = *((int *)vec[0].iov_base);
++        tag      = (char *)vec[1].iov_base;
++        msg      = (char *)vec[2].iov_base;
++
++        /* disable Android VERBOSE log */
++        if (priority == ANDROID_LOG_VERBOSE) {
++            return -EINVAL;
++        }
++
++        // get priority and logid char
++        priChar = filterPriAndSysPri(priority, &sys_pri);
++
++        // format prefix (brief format)
++        prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
++                    "(%5d, %5d),[%s],[%d],[Tag]%s[TAG]: ", getpid(), syscall(SYS_gettid), idChar, priChar, tag);
++
++        // compute size
++        totalLen = prefixLen + msg_len + 1 + 1;
++        if(totalLen <= defaultLen) {
++            writeBuf = defaultBuf;
++        } else {
++            write_allocate = 1;
++            writeBuf = (char *)malloc(totalLen);
++            if(writeBuf == NULL)
++                return 0;
++        }
++
++        // combine final string
++        writeBuf[0] = '\0';
++        strncat(writeBuf, prefixBuf, prefixLen);
++        strncat(writeBuf, msg, msg_len);
++        strcat(writeBuf, "\n");
++
++        // log to syslog
++        syslog(sys_pri, "%s", writeBuf);
++        ret = strlen(writeBuf);
++
++        if(write_allocate) free(writeBuf);
++    }
++#else
+     struct android_log_transport_write *node;
+     int ret;
+     struct timespec ts;
+@@ -316,6 +503,7 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr)
+             (void)(*node->write)(log_id, &ts, vec, nr);
+         }
+     }
++#endif
+ 
+     return ret;
+ }
+@@ -327,6 +515,27 @@ static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
+     if (write_to_log == __write_to_log_init) {
+         int ret;
+ 
++#if defined(__REDIRECT_TO_SYSLOGD__)
++        // open syslogd
++        if (access("/etc/configs/syslog_split", F_OK) == 0) {
++            switch (log_id) {
++            case LOG_ID_MAIN:
++                openlog("ALOG", 0, LOG_LOCAL0);
++                break;
++            case LOG_ID_SYSTEM:
++                openlog("SLOG", 0, LOG_LOCAL1);
++                break;
++            case LOG_ID_RADIO:
++                openlog("RLOG", 0, LOG_LOCAL2);
++                break;
++            default:
++                openlog("ALOG", 0, LOG_LOCAL0);
++                break;
++            }
++        } else {
++            openlog("ALOG", 0, LOG_USER);
++        }
++#else
+         ret = __write_to_log_initialize();
+         if (ret < 0) {
+             __android_log_unlock();
+@@ -335,7 +544,7 @@ static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
+             }
+             return ret;
+         }
+-
++#endif
+         write_to_log = __write_to_log_daemon;
+     }
+ 
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/Makefile.am
new file mode 100644
index 0000000..26eb2d2
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/Makefile.am
@@ -0,0 +1,5 @@
+SUBDIRS = \
+	system/core/base/include \
+	system/core/include \
+	system/core/liblog \
+	system/core/base
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/configure.ac b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/configure.ac
new file mode 100644
index 0000000..1b9a96d
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/configure.ac
@@ -0,0 +1,13 @@
+AC_INIT([platform-libs-updateengine], [1.0])
+AM_INIT_AUTOMAKE([foreign subdir-objects])
+AC_PROG_CXX
+AM_PROG_AS
+LT_INIT
+AC_CONFIG_FILES([
+	Makefile
+	system/core/base/include/Makefile
+	system/core/include/Makefile
+	system/core/liblog/Makefile
+	system/core/base/Makefile
+])
+AC_OUTPUT
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/base/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/base/Makefile.am
new file mode 100644
index 0000000..53de4aa
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/base/Makefile.am
@@ -0,0 +1,19 @@
+lib_LTLIBRARIES = libbase.la
+
+libbase_la_SOURCES = \
+	file.cpp \
+	logging.cpp \
+	parsenetaddress.cpp \
+	stringprintf.cpp \
+	strings.cpp \
+	test_utils.cpp \
+	errors_unix.cpp
+	
+libbase_la_CPPFLAGS = -Werror -Wall -Wextra  -std=c++14
+
+libbase_la_CPPFLAGS += \
+	-I$(top_srcdir)/system/core/base/include \
+	-I$(top_srcdir)/system/core/include
+
+libbase_la_LIBADD = \
+	$(top_builddir)/system/core/liblog/liblog.la
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/base/include/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/base/include/Makefile.am
new file mode 100644
index 0000000..6d83983
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/base/include/Makefile.am
@@ -0,0 +1,8 @@
+nobase_include_HEADERS = \
+	android-base/unique_fd.h \
+        android-base/file.h \
+        android-base/logging.h \
+        android-base/macros.h \
+        android-base/stringprintf.h \
+        android-base/strings.h  \
+        android-base/parseint.h
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/include/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/include/Makefile.am
new file mode 100644
index 0000000..ec0f4eb
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/include/Makefile.am
@@ -0,0 +1,27 @@
+nobase_include_HEADERS = \
+	utils/Compat.h \
+	utils/Errors.h \
+	utils/KeyedVector.h \
+	utils/RefBase.h \
+	utils/SortedVector.h \
+	utils/String8.h \
+	utils/String16.h \
+	utils/SystemClock.h \
+	utils/Timers.h \
+	utils/TypeHelpers.h \
+	utils/Unicode.h \
+	utils/Vector.h \
+	utils/VectorImpl.h \
+	utils/threads.h \
+	utils/StrongPointer.h \
+	utils/CallStack.h \
+	utils/Printer.h \
+	utils/Looper.h \
+	utils/ThreadDefs.h \
+	utils/AndroidThreads.h \
+	utils/Condition.h \
+	utils/Mutex.h \
+	utils/Thread.h \
+	utils/RWLock.h \
+	utils/List.h
+
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/liblog/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/liblog/Makefile.am
new file mode 100644
index 0000000..1c3443c
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/liblog/Makefile.am
@@ -0,0 +1,20 @@
+lib_LTLIBRARIES = liblog.la
+
+liblog_la_SOURCES = \
+	config_write.c \
+	event_tag_map.c \
+	fake_log_device.c \
+	fake_writer.c \
+	log_event_list.c \
+	log_event_write.c \
+	logger_lock.c \
+	logger_name.c \
+	logger_write.c
+
+liblog_la_CFLAGS = -Werror -fvisibility=hidden
+
+liblog_la_CPPFLAGS = \
+	-DFAKE_LOG_DEVICE=1 \
+	-DLIBLOG_LOG_TAG=1005 \
+	-DSNET_EVENT_LOG_TAG=1397638484 \
+	-I$(top_srcdir)/system/core/include
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/parseint.patch b/meta/meta-mediatek/recipes-support/platform-libs-common/files/parseint.patch
new file mode 100644
index 0000000..136fcc4
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/parseint.patch
@@ -0,0 +1,57 @@
+diff --git a/system/core/base/include/android-base/parseint.h b/system/core/base/include/android-base/parseint.h
+index ed75e2d..e3ebce6 100644
+--- a/system/core/base/include/android-base/parseint.h
++++ b/system/core/base/include/android-base/parseint.h
+@@ -21,6 +21,7 @@
+ #include <stdlib.h>
+ 
+ #include <limits>
++#include <string>
+ 
+ namespace android {
+ namespace base {
+@@ -31,7 +32,7 @@ namespace base {
+ template <typename T>
+ bool ParseUint(const char* s, T* out,
+                T max = std::numeric_limits<T>::max()) {
+-  int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10;
++  int base = (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? 16 : 10;
+   errno = 0;
+   char* end;
+   unsigned long long int result = strtoull(s, &end, base);
+@@ -45,6 +46,12 @@ bool ParseUint(const char* s, T* out,
+   return true;
+ }
+ 
++// TODO: string_view
++template <typename T>
++bool ParseUint(const std::string& s, T* out,
++               T max = std::numeric_limits<T>::max()) {
++  return ParseUint(s.c_str(), out, max);
++}
+ // Parses the signed decimal integer in the string 's' and sets 'out' to
+ // that value. Optionally allows the caller to define a 'min' and 'max
+ // beyond which otherwise valid values will be rejected. Returns boolean
+@@ -53,7 +60,7 @@ template <typename T>
+ bool ParseInt(const char* s, T* out,
+               T min = std::numeric_limits<T>::min(),
+               T max = std::numeric_limits<T>::max()) {
+-  int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10;
++  int base = (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? 16 : 10;
+   errno = 0;
+   char* end;
+   long long int result = strtoll(s, &end, base);
+@@ -67,6 +74,13 @@ bool ParseInt(const char* s, T* out,
+   return true;
+ }
+ 
++// TODO: string_view
++template <typename T>
++bool ParseInt(const std::string& s, T* out,
++              T min = std::numeric_limits<T>::min(),
++              T max = std::numeric_limits<T>::max()) {
++  return ParseInt(s.c_str(), out, min, max);
++}
+ }  // namespace base
+ }  // namespace android
+ 
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/files/string.patch b/meta/meta-mediatek/recipes-support/platform-libs-common/files/string.patch
new file mode 100644
index 0000000..aeb0438
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/files/string.patch
@@ -0,0 +1,14 @@
+diff --git a/system/core/base/strings.cpp b/system/core/base/strings.cpp
+index b8775df..eceb844 100644
+--- a/system/core/base/strings.cpp
++++ b/system/core/base/strings.cpp
+@@ -100,5 +100,9 @@ bool EndsWith(const std::string& s, const char* suffix) {
+   return s.compare(offset, suffix_length, suffix) == 0;
+ }
+ 
++bool EqualsIgnoreCase(const std::string& lhs, const std::string& rhs) {
++  return strcasecmp(lhs.c_str(), rhs.c_str()) == 0;
++}
++
+ }  // namespace base
+ }  // namespace android
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-common/platform-libs-common.bb b/meta/meta-mediatek/recipes-support/platform-libs-common/platform-libs-common.bb
new file mode 100644
index 0000000..aff39ac
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-common/platform-libs-common.bb
@@ -0,0 +1,44 @@
+inherit autotools
+DESCRIPTION = "Android platform libraries"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = " \
+	file://system/core/NOTICE;md5=c1a3ff0b97f199c7ebcfdd4d3fed238e \
+	"
+
+SRC_URI = " \
+	git://android.googlesource.com/platform/system/core;name=platform/system/core;destsuffix=platform/system/core/ \
+	file://base.patch \
+	file://parseint.patch \
+	file://include.patch \
+	file://liblog.patch \
+	file://string.patch \
+"
+
+SRCREV_platform/system/core = "c6160d2a0ef648ccb3d217c589c60b5c00b80387"
+
+FILESEXTRAPATHS_prepend := "${THISDIR}:"
+
+DEPENDS += "openssl glog "
+
+S = "${WORKDIR}/platform"
+
+LDFLAGS += "-lcrypto -lpthread -lglog"
+
+SECURITY_CFLAGS=""
+
+do_configure_prepend() {
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/Makefile.am ${WORKDIR}/platform/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/configure.ac ${WORKDIR}/platform/configure.ac
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/base/Makefile.am ${WORKDIR}/platform/system/core/base/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/base/include/Makefile.am ${WORKDIR}/platform/system/core/base/include/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/include/Makefile.am ${WORKDIR}/platform/system/core/include/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-common/files/makefiles/platform/system/core/liblog/Makefile.am ${WORKDIR}/platform/system/core/liblog/Makefile.am
+}
+
+do_install_append() {
+	install -d ${D}${includedir}
+	install -d ${D}${includedir}/log
+	install -d ${D}${includedir}/android
+	install -m 644 ${S}/system/core/include/log/* ${D}/${includedir}/log
+	install -m 644 ${S}/system/core/include/android/* ${D}/${includedir}/android
+}
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/base.patch b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/base.patch
new file mode 100644
index 0000000..48540dc
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/base.patch
@@ -0,0 +1,36 @@
+diff --git a/system/core/base/errors_unix.cpp b/system/core/base/errors_unix.cpp
+index 296995e..48269b6 100644
+--- a/system/core/base/errors_unix.cpp
++++ b/system/core/base/errors_unix.cpp
+@@ -17,6 +17,7 @@
+ #include "android-base/errors.h"
+ 
+ #include <errno.h>
++#include <string.h>
+ 
+ namespace android {
+ namespace base {
+diff --git a/system/core/base/file.cpp b/system/core/base/file.cpp
+index 2f697a1..b86d1a2 100644
+--- a/system/core/base/file.cpp
++++ b/system/core/base/file.cpp
+@@ -27,6 +27,7 @@
+ #include <mutex>
+ #include <string>
+ #include <vector>
++#include <string.h>
+ 
+ #include "android-base/logging.h"
+ #include "android-base/macros.h"  // For TEMP_FAILURE_RETRY on Darwin.
+diff --git a/system/core/base/logging.cpp b/system/core/base/logging.cpp
+index a31feef..7fd74dc 100644
+--- a/system/core/base/logging.cpp
++++ b/system/core/base/logging.cpp
+@@ -22,6 +22,7 @@
+ 
+ #include <fcntl.h>
+ #include <libgen.h>
++#include <string.h>
+ #include <time.h>
+ 
+ // For getprogname(3) or program_invocation_short_name.
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/file_stream.patch b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/file_stream.patch
new file mode 100644
index 0000000..b5e417c
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/file_stream.patch
@@ -0,0 +1,117 @@
+diff --git a/external/libbrillo/brillo/streams/file_stream.cc b/brillo/streams/file_stream.cc
+index 7b28a5a..81dff4c 100644
+--- a/external/libbrillo/brillo/streams/file_stream.cc
++++ b/external/libbrillo/brillo/streams/file_stream.cc
+@@ -17,6 +17,16 @@
+ #include <brillo/streams/stream_errors.h>
+ #include <brillo/streams/stream_utils.h>
+
++#define BOOTDEV_TYPE_NAND 1
++#define BOOTDEV_TYPE_EMMC 2
++
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  extern "C"{
++    #include "mtk_device_wrap.h"
++}
++static int is_partition = 0;
++#endif
++
+ namespace brillo {
+
+ // FileDescriptor is a helper class that serves two purposes:
+@@ -39,14 +49,50 @@ class FileDescriptor : public FileStream::FileDescriptorInterface {
+   bool IsOpen() const override { return fd_ >= 0; }
+
+   ssize_t Read(void* buf, size_t nbyte) override {
++  #if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++    if(is_partition == 1)
++    {
++      //LOG(INFO) << "read partition device";
++      return HANDLE_EINTR(mtk_device_wrap_read(fd_, buf, nbyte));
++    }
++    else
++    {
++      //LOG(INFO) << "read ordinary file";
++      return HANDLE_EINTR(read(fd_, buf, nbyte));
++    }
++  #endif
+     return HANDLE_EINTR(read(fd_, buf, nbyte));
+   }
+
+   ssize_t Write(const void* buf, size_t nbyte) override {
++  #if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  if(is_partition == 1)
++  {
++    //LOG(INFO) << "write partition device";
++    return HANDLE_EINTR(mtk_device_wrap_write_force(fd_, (void*)buf, nbyte));
++  }
++  else
++  {
++    //LOG(INFO) << "write ordinary file";
++    return HANDLE_EINTR(write(fd_, (void*)buf, nbyte));
++  }
++  #endif
+     return HANDLE_EINTR(write(fd_, buf, nbyte));
+   }
+
+   off64_t Seek(off64_t offset, int whence) override {
++  #if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  if(is_partition == 1)
++  {
++    //LOG(INFO) << "seek partition device";
++    return mtk_device_wrap_seek64(fd_, offset, whence);
++  }
++  else
++  {
++    //LOG(INFO) << "seek ordinary file";
++    return lseek64(fd_, offset, whence);
++  }
++  #endif
+     return lseek64(fd_, offset, whence);
+   }
+
+@@ -76,6 +122,19 @@ class FileDescriptor : public FileStream::FileDescriptorInterface {
+     // it before exiting.
+     std::swap(fd, fd_);
+     CancelPendingAsyncOperations();
++  #if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++   if(is_partition == 1)
++   {
++      LOG(INFO) << "close partition device";
++      is_partition = 0;
++      return own_ ? IGNORE_EINTR(mtk_device_wrap_close(fd)) : 0;
++   }
++   else
++   {
++      LOG(INFO) << "close ordinary file";
++      return own_ ? IGNORE_EINTR(close(fd)) : 0;
++   }
++  #endif
+     return own_ ? IGNORE_EINTR(close(fd)) : 0;
+   }
+
+@@ -239,7 +298,23 @@ StreamPtr FileStream::Open(const base::FilePath& path,
+   }
+
+   mode_t creation_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+-  int fd = HANDLE_EINTR(open(path.value().c_str(), open_flags, creation_mode));
++  int fd = -1;
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  /* because mtk_device_wrap_m_open() can not distinguish between ordinary files and devices files*/
++  if(!memcmp(path.value().c_str(), "/dev/disk/by-partlabel", 22))
++  {
++    LOG(INFO) << "open partition device: " << path.value().c_str();
++    is_partition = 1;
++    fd = HANDLE_EINTR(mtk_device_wrap_m_open(path.value().c_str(), open_flags, creation_mode));
++  }
++  else
++  {
++    LOG(INFO) << "open ordinary file: " << path.value().c_str();
++    fd = HANDLE_EINTR(open(path.value().c_str(), open_flags, creation_mode));
++  }
++#else
++  fd = HANDLE_EINTR(open(path.value().c_str(), open_flags, creation_mode));
++#endif
+   if (fd < 0) {
+     brillo::errors::system::AddSystemError(error, FROM_HERE, errno);
+     return stream;
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/fstab.patch b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/fstab.patch
new file mode 100644
index 0000000..fc52654
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/fstab.patch
@@ -0,0 +1,98 @@
+diff --git a/system/core/fs_mgr/fs_mgr_boot_config.cpp b/system/core/fs_mgr/fs_mgr_boot_config.cpp
+index 9c5d3f3..b7e4b81 100644
+--- a/system/core/fs_mgr/fs_mgr_boot_config.cpp
++++ b/system/core/fs_mgr/fs_mgr_boot_config.cpp
+@@ -19,7 +19,7 @@
+ #include <android-base/file.h>
+ #include <android-base/stringprintf.h>
+ #include <android-base/strings.h>
+-#include <android-base/properties.h>
++//#include <android-base/properties.h>
+ 
+ #include "fs_mgr_priv.h"
+ 
+@@ -51,12 +51,13 @@ bool fs_mgr_get_boot_config_from_kernel_cmdline(const std::string& key, std::str
+ bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) {
+     FS_MGR_CHECK(out_val != nullptr);
+ 
++   #if 0
+     // first check if we have "ro.boot" property already
+     *out_val = android::base::GetProperty("ro.boot." + key, "");
+     if (!out_val->empty()) {
+         return true;
+     }
+-
++   #endif
+     // fallback to kernel cmdline, properties may not be ready yet
+     if (fs_mgr_get_boot_config_from_kernel_cmdline(key, out_val)) {
+         return true;
+diff --git a/system/core/fs_mgr/fs_mgr_fstab.cpp b/system/core/fs_mgr/fs_mgr_fstab.cpp
+index 9b7405a..27fed5e 100644
+--- a/system/core/fs_mgr/fs_mgr_fstab.cpp
++++ b/system/core/fs_mgr/fs_mgr_fstab.cpp
+@@ -115,6 +115,33 @@ static struct flag_list fs_mgr_flags[] = {
+ #define EM_AES_256_CTS  3
+ #define EM_AES_256_HEH  4
+ 
++size_t
++strlcat(char *dst, const char *src, size_t dsize)
++{
++        const char *odst = dst;
++        const char *osrc = src;
++        size_t n = dsize;
++        size_t dlen;
++
++        /* Find the end of dst and adjust bytes left but don't go past end. */
++        while (n-- != 0 && *dst != '\0')
++                dst++;
++        dlen = dst - odst;
++        n = dsize - dlen;
++
++        if (n-- == 0)
++                return(dlen + strlen(src));
++        while (*src != '\0') {
++                if (n != 0) {
++                        *dst++ = *src;
++                        n--;
++                }
++                src++;
++        }
++        *dst = '\0';
++
++        return(dlen + (src - osrc));    /* count does not include NUL */
++}
+ static const struct flag_list file_contents_encryption_modes[] = {
+     {"aes-256-xts", EM_AES_256_XTS},
+     {"software", EM_AES_256_XTS}, /* alias for backwards compatibility */
+@@ -362,7 +389,7 @@ static int parse_flags(char *flags, struct flag_list *fl,
+                 /* fs_options was not passed in, so if the flag is unknown
+                  * it's an error.
+                  */
+-                LERROR << "Warning: unknown flag " << p;
++                //LERROR << "Warning: unknown flag " << p;
+             }
+         }
+         p = strtok_r(NULL, ",", &savep);
+@@ -704,7 +731,7 @@ struct fstab *fs_mgr_read_fstab_dt()
+ {
+     std::string fstab_buf = read_fstab_from_dt();
+     if (fstab_buf.empty()) {
+-        LINFO << __FUNCTION__ << "(): failed to read fstab from dt";
++        //LINFO << __FUNCTION__ << "(): failed to read fstab from dt";
+         return nullptr;
+     }
+ 
+@@ -744,7 +771,12 @@ static std::string get_fstab_path()
+             }
+         }
+     }
+-
++    for (const char* prefix : {"/odm/etc/fstab", "/vendor/etc/fstab", "/etc/fstab"}) {
++        std::string fstab_path = prefix;
++        if (access(fstab_path.c_str(), F_OK) == 0) {
++            return fstab_path;
++        }
++    }
+     return std::string();
+ }
+ 
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/libbrillo.patch b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/libbrillo.patch
new file mode 100644
index 0000000..853a792
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/libbrillo.patch
@@ -0,0 +1,166 @@
+From 4aaf7bc45cfc0db6de494a1a8dedb114915a261f Mon Sep 17 00:00:00 2001
+From: mtk16536 <Dufre.Wu@mediatek.com>
+Date: Wed, 6 May 2020 10:07:22 +0800
+Subject: [PATCH] brillo_stream
+
+Signed-off-by: mtk16536 <Dufre.Wu@mediatek.com>
+---
+ external/libbrillo/brillo/streams/openssl_stream_bio.cc | 74 +++++++++++++++++++++++++++++-------
+ external/libbrillo/brillo/streams/tls_stream.cc         |  6 ++-
+ 2 files changed, 66 insertions(+), 14 deletions(-)
+
+diff --git a/external/libbrillo/brillo/streams/openssl_stream_bio.cc b/brillo/streams/openssl_stream_bio.cc
+index a63d9c0..a2f4b50 100644
+--- a/external/libbrillo/brillo/streams/openssl_stream_bio.cc
++++ b/external/libbrillo/brillo/streams/openssl_stream_bio.cc
+@@ -13,9 +13,31 @@ namespace brillo {
+
+ namespace {
+
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
++static void BIO_set_data(BIO* a, void* ptr) {
++    a->ptr = ptr;
++}
++
++static void* BIO_get_data(BIO* a) {
++    return a->ptr;
++}
++
++static void BIO_set_init(BIO* a, int init) {
++    a->init = init;
++}
++
++static int BIO_get_init(BIO* a) {
++    return a->init;
++}
++
++static void BIO_set_shutdown(BIO* a, int shut) {
++    a->shutdown = shut;
++}
++#endif
++
+ // Internal functions for implementing OpenSSL BIO on brillo::Stream.
+ int stream_write(BIO* bio, const char* buf, int size) {
+-  brillo::Stream* stream = static_cast<brillo::Stream*>(bio->ptr);
++  brillo::Stream* stream = static_cast<brillo::Stream*>(BIO_get_data(bio));
+   size_t written = 0;
+   BIO_clear_retry_flags(bio);
+   if (!stream->WriteNonBlocking(buf, size, &written, nullptr))
+@@ -30,7 +52,7 @@ int stream_write(BIO* bio, const char* buf, int size) {
+ }
+
+ int stream_read(BIO* bio, char* buf, int size) {
+-  brillo::Stream* stream = static_cast<brillo::Stream*>(bio->ptr);
++  brillo::Stream* stream = static_cast<brillo::Stream*>(BIO_get_data(bio));
+   size_t read = 0;
+   BIO_clear_retry_flags(bio);
+   bool eos = false;
+@@ -49,16 +71,16 @@ int stream_read(BIO* bio, char* buf, int size) {
+ // NOLINTNEXTLINE(runtime/int)
+ long stream_ctrl(BIO* bio, int cmd, long /* num */, void* /* ptr */) {
+   if (cmd == BIO_CTRL_FLUSH) {
+-    brillo::Stream* stream = static_cast<brillo::Stream*>(bio->ptr);
++    brillo::Stream* stream = static_cast<brillo::Stream*>(BIO_get_data(bio));
+     return stream->FlushBlocking(nullptr) ? 1 : 0;
+   }
+   return 0;
+ }
+
+ int stream_new(BIO* bio) {
+-  bio->shutdown = 0;  // By default do not close underlying stream on shutdown.
+-  bio->init = 0;
+-  bio->num = -1;  // not used.
++  // By default do not close underlying stream on shutdown.
++  BIO_set_shutdown(bio, 0);
++  BIO_set_init(bio, 0);
+   return 1;
+ }
+
+@@ -66,13 +88,15 @@ int stream_free(BIO* bio) {
+   if (!bio)
+     return 0;
+
+-  if (bio->init) {
+-    bio->ptr = nullptr;
+-    bio->init = 0;
++  if (BIO_get_init(bio)) {
++    BIO_set_data(bio, nullptr);
++    BIO_set_init(bio, 0);
+   }
+   return 1;
+ }
+
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
++
+ // BIO_METHOD structure describing the BIO built on top of brillo::Stream.
+ BIO_METHOD stream_method = {
+     0x7F | BIO_TYPE_SOURCE_SINK,  // type: 0x7F is an arbitrary unused type ID.
+@@ -87,13 +111,37 @@ BIO_METHOD stream_method = {
+     nullptr,       // callback function, not used
+ };
+
+-}  // anonymous namespace
++BIO_NETHOD* stream_get_method() {
++    return &stream_method;
++}
++
++#else
++
++BIO_METHOD* stream_get_method() {
++    static BIO_METHOD* stream_method;
++
++    if (!stream_method) {
++        stream_method = BIO_meth_new(BIO_get_new_index() | BIO_TYPE_SOURCE_SINK, "stream");
++
++        BIO_meth_set_write(stream_method, stream_write);
++        BIO_meth_set_read(stream_method, stream_read);
++        BIO_meth_set_ctrl(stream_method, stream_ctrl);
++        BIO_meth_set_create(stream_method, stream_new);
++        BIO_meth_set_destroy(stream_method, stream_free);
++    }
++
++    return stream_method;
++}
++
++#endif
++
++}  // anonymous namespaces
+
+ BIO* BIO_new_stream(brillo::Stream* stream) {
+-  BIO* bio = BIO_new(&stream_method);
++  BIO* bio = BIO_new(stream_get_method());
+   if (bio) {
+-    bio->ptr = stream;
+-    bio->init = 1;
++    BIO_set_data(bio, stream);
++    BIO_set_init(bio, 1);
+   }
+   return bio;
+ }
+diff --git a/external/libbrillo/brillo/streams/tls_stream.cc b/brillo/streams/tls_stream.cc
+index ac116a4..0403035 100644
+--- a/external/libbrillo/brillo/streams/tls_stream.cc
++++ b/external/libbrillo/brillo/streams/tls_stream.cc
+@@ -67,6 +67,10 @@ const char kCACertificatePath[] =
+
+ namespace brillo {
+
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
++#define TLS_client_method() TLSv1_2_client_method()
++#endif
++
+ // Helper implementation of TLS stream used to hide most of OpenSSL inner
+ // workings from the users of brillo::TlsStream.
+ class TlsStream::TlsStreamImpl {
+@@ -341,7 +345,7 @@ bool TlsStream::TlsStreamImpl::Init(StreamPtr socket,
+                                     const base::Closure& success_callback,
+                                     const Stream::ErrorCallback& error_callback,
+                                     ErrorPtr* error) {
+-  ctx_.reset(SSL_CTX_new(TLSv1_2_client_method()));
++  ctx_.reset(SSL_CTX_new(TLS_client_method()));
+   if (!ctx_)
+     return ReportError(error, FROM_HERE, "Cannot create SSL_CTX");
+
+--
+2.6.4
+
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/libchrome.patch b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/libchrome.patch
new file mode 100644
index 0000000..d34da7e
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/libchrome.patch
@@ -0,0 +1,48 @@
+diff --git a/external/libchrome/base/allocator/features.h b/external/libchrome/base/allocator/features.h
+index ea479cd..c4ddf5c 100644
+--- a/external/libchrome/base/allocator/features.h
++++ b/external/libchrome/base/allocator/features.h
+@@ -9,7 +9,7 @@
+ #if defined(__APPLE__) || defined(ANDROID)
+ #define BUILDFLAG_INTERNAL_USE_EXPERIMENTAL_ALLOCATOR_SHIM() (0)
+ #else
+-#define BUILDFLAG_INTERNAL_USE_EXPERIMENTAL_ALLOCATOR_SHIM() (1)
++#define BUILDFLAG_INTERNAL_USE_EXPERIMENTAL_ALLOCATOR_SHIM() (0)
+ #endif
+ 
+ #endif  // BASE_ALLOCATOR_FEATURES_H_
+diff --git a/external/libchrome/build/build_config.h b/external/libchrome/build/build_config.h
+index 80a93d3..d07274e 100644
+--- a/external/libchrome/build/build_config.h
++++ b/external/libchrome/build/build_config.h
+@@ -27,14 +27,14 @@
+ //   within the NDK.
+ 
+ // Android targets and hosts don't use tcmalloc.
+-#if defined(__ANDROID__) || defined(__ANDROID_HOST__)
++//#if defined(__ANDROID__) || defined(__ANDROID_HOST__)
+ #define NO_TCMALLOC
+-#endif  // defined(__ANDROID__) || defined(__ANDROID_HOST__)
++//#endif  // defined(__ANDROID__) || defined(__ANDROID_HOST__)
+ 
+ // Use the Chrome OS version of the code for both Android targets and Chrome OS builds.
+-#if !defined(__ANDROID_HOST__)
+-#define OS_CHROMEOS 1
+-#endif  // !defined(__ANDROID_HOST__)
++//#if !defined(__ANDROID_HOST__)
++//#define OS_CHROMEOS 0
++//#endif  // !defined(__ANDROID_HOST__)
+ 
+ #if defined(__ANDROID__)  // Android targets
+ 
+@@ -47,8 +47,8 @@
+ 
+ // TODO: Remove these once the GLib MessageLoopForUI isn't being used:
+ // https://crbug.com/361635
+-#define USE_GLIB 1
+-#define USE_OZONE 1
++//#define USE_GLIB 1
++//#define USE_OZONE 1
+ 
+ #endif  // defined(__ANDROID__)
+ 
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/libevent.patch b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/libevent.patch
new file mode 100644
index 0000000..99595f2
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/libevent.patch
@@ -0,0 +1,13 @@
+diff --git a/external/libevent/buffer.c b/external/libevent/buffer.c
+index b7e3a69..a945211 100644
+--- a/external/libevent/buffer.c
++++ b/external/libevent/buffer.c
+@@ -2484,7 +2484,7 @@ evbuffer_write_sendfile(struct evbuffer *buffer, evutil_socket_t dest_fd,
+ 	return (len);
+ #elif defined(SENDFILE_IS_LINUX)
+ 	/* TODO(niels): implement splice */
+-	res = sendfile(dest_fd, source_fd, &offset, chain->off);
++	res = sendfile(dest_fd, source_fd, (off_t *)(&offset), chain->off);
+ 	if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) {
+ 		/* if this is EAGAIN or EINTR return 0; otherwise, -1 */
+ 		return (0);
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/Makefile.am
new file mode 100644
index 0000000..642ae6d
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/Makefile.am
@@ -0,0 +1,16 @@
+SUBDIRS = \
+  external/cros/system_api/dbus \
+  external/modp_b64 \
+  external/libchrome \
+  external/libbrillo \
+  external/xz-embedded/linux/include/linux \
+  external/xz-embedded \
+  system/core/fs_mgr/include_fstab \
+  system/core/fs_mgr \
+  external/libdivsufsort \
+  external/brotli \
+  external/bsdiff/include \
+  external/bsdiff \
+  external/puffin/src/include \
+  external/puffin \
+  external/libevent
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/configure.ac b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/configure.ac
new file mode 100644
index 0000000..4d65be1
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/configure.ac
@@ -0,0 +1,24 @@
+AC_INIT([platform-libs-updateengine], [1.0])
+AM_INIT_AUTOMAKE([foreign subdir-objects])
+AC_PROG_CXX
+AM_PROG_AS
+LT_INIT
+AC_CONFIG_FILES([
+  Makefile
+  external/cros/system_api/dbus/Makefile
+  external/modp_b64/Makefile
+  external/libchrome/Makefile
+  external/libbrillo/Makefile
+  external/xz-embedded/linux/include/linux/Makefile
+  external/xz-embedded/Makefile
+  system/core/fs_mgr/include_fstab/Makefile
+  system/core/fs_mgr/Makefile
+  external/libdivsufsort/Makefile
+  external/brotli/Makefile
+  external/bsdiff/include/Makefile
+  external/bsdiff/Makefile
+  external/puffin/src/include/Makefile
+  external/puffin/Makefile
+  external/libevent/Makefile
+])
+AC_OUTPUT
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/brotli/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/brotli/Makefile.am
new file mode 100644
index 0000000..4792f09
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/brotli/Makefile.am
@@ -0,0 +1,30 @@
+lib_LTLIBRARIES = libbrotli.la
+libbrotli_la_SOURCES = \
+   c/common/dictionary.c \
+   c/dec/bit_reader.c \
+   c/dec/decode.c \
+   c/dec/huffman.c \
+   c/dec/state.c \
+   c/enc/backward_references.c \
+   c/enc/backward_references_hq.c \
+   c/enc/bit_cost.c \
+   c/enc/block_splitter.c \
+   c/enc/brotli_bit_stream.c \
+   c/enc/cluster.c \
+   c/enc/compress_fragment.c \
+   c/enc/compress_fragment_two_pass.c \
+   c/enc/dictionary_hash.c \
+   c/enc/encode.c \
+   c/enc/entropy_encode.c \
+   c/enc/histogram.c \
+   c/enc/literal_cost.c \
+   c/enc/memory.c \
+   c/enc/metablock.c \
+   c/enc/static_dict.c \
+   c/enc/utf8_util.c 
+
+libbrotli_la_CPPFLAGS = -Werror -O2
+
+libbrotli_la_CPPFLAGS += \
+	-I$(top_srcdir)/external/brotli/c/include
+	
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/bsdiff/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/bsdiff/Makefile.am
new file mode 100644
index 0000000..fcac3cc
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/bsdiff/Makefile.am
@@ -0,0 +1,26 @@
+lib_LIBRARIES = libbspatch.a
+
+libbspatch_a_SOURCES = \
+        brotli_decompressor.cc \
+        bspatch.cc \
+        bz2_decompressor.cc \
+        buffer_file.cc \
+        decompressor_interface.cc \
+        extents.cc \
+        extents_file.cc \
+        file.cc \
+        logging.cc \
+        memory_file.cc \
+        patch_reader.cc \
+        sink_file.cc \
+        utils.cc
+		
+libbspatch_a_CPPFLAGS = -Werror -Wall -Wextra -Wno-unused-parameter -D_FILE_OFFSET_BITS=64
+
+libbspatch_a_CPPFLAGS += \
+	-I$(top_srcdir)/external/bsdiff/include \
+        -I$(top_srcdir)/external \
+        -I$(top_srcdir)/external/brotli/c/include
+	
+libbspatch_a_LIBADD = $(top_builddir)/../recipe-sysroot$(libdir)/libbz2.so \
+	$(top_builddir)/external/brotli/libbrotli.la
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/bsdiff/include/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/bsdiff/include/Makefile.am
new file mode 100644
index 0000000..26c5919
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/bsdiff/include/Makefile.am
@@ -0,0 +1,11 @@
+nobase_include_HEADERS = \
+	bsdiff/bsdiff.h \
+	bsdiff/bspatch.h \
+	bsdiff/common.h \
+	bsdiff/constants.h \
+	bsdiff/control_entry.h \
+	bsdiff/extents_file.h \
+	bsdiff/file_interface.h \
+	bsdiff/patch_writer_factory.h \
+	bsdiff/patch_writer_interface.h \
+	bsdiff/suffix_array_index_interface.h
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/cros/system_api/dbus/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/cros/system_api/dbus/Makefile.am
new file mode 100644
index 0000000..180ba8c
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/cros/system_api/dbus/Makefile.am
@@ -0,0 +1,2 @@
+nobase_include_HEADERS = \
+	update_engine/dbus-constants.h
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libbrillo/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libbrillo/Makefile.am
new file mode 100644
index 0000000..4690f82
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libbrillo/Makefile.am
@@ -0,0 +1,164 @@
+libbrillo_core_sources = \
+    brillo/backoff_entry.cc \
+    brillo/data_encoding.cc \
+    brillo/errors/error.cc \
+    brillo/errors/error_codes.cc \
+    brillo/flag_helper.cc \
+    brillo/key_value_store.cc \
+    brillo/message_loops/base_message_loop.cc \
+    brillo/message_loops/message_loop.cc \
+    brillo/message_loops/message_loop_utils.cc \
+    brillo/mime_utils.cc \
+    brillo/osrelease_reader.cc \
+    brillo/process.cc \
+    brillo/process_information.cc \
+    brillo/secure_blob.cc \
+    brillo/strings/string_utils.cc \
+    brillo/syslog_logging.cc \
+    brillo/url_utils.cc \
+    brillo/userdb_utils.cc \
+    brillo/value_conversion.cc
+
+libbrillo_linux_sources = \
+    brillo/asynchronous_signal_handler.cc \
+    brillo/daemons/daemon.cc \
+    brillo/file_utils.cc \
+    brillo/process_reaper.cc
+
+libbrillo_stream_sources = \
+    brillo/streams/file_stream.cc \
+    brillo/streams/input_stream_set.cc \
+    brillo/streams/memory_containers.cc \
+    brillo/streams/memory_stream.cc \
+    brillo/streams/openssl_stream_bio.cc \
+    brillo/streams/stream.cc \
+    brillo/streams/stream_errors.cc \
+    brillo/streams/stream_utils.cc \
+    brillo/streams/tls_stream.cc
+
+lib_LTLIBRARIES = libbrillo.la libbrillo_stream.la
+libbrillo_la_SOURCES = $(libbrillo_core_sources) \
+                       $(libbrillo_linux_sources)
+
+libbrillo_la_LIBADD = \
+    $(top_builddir)/external/modp_b64/libmodpb64.a \
+    $(top_builddir)/external/libchrome/libchrome.la
+
+libbrillo_la_CFLAGS = -Wall -Werror
+
+libbrillo_la_CPPFLAGS = \
+    -I$(top_srcdir)/external/libchrome \
+    -I$(top_srcdir)/external/libbrillo \
+    -I$(top_srcdir)/external/modp_b64
+
+libbrillo_stream_la_SOURCES = $(libbrillo_stream_sources)
+libbrillo_stream_la_CFLAGS = -Wall -Werror
+
+libbrillo_stream_la_LIBADD = \
+    libbrillo.la \
+    -lcrypto -lssl -lgtest
+
+libbrillo_stream_la_CPPFLAGS = \
+    -I$(top_srcdir)/external/libchrome \
+    -I$(top_srcdir)/external/libbrillo
+
+nobase_include_HEADERS = \
+  brillo/any.h                                  \
+  brillo/any_internal_impl.h                    \
+  brillo/asynchronous_signal_handler.h          \
+  brillo/asynchronous_signal_handler_interface.h\
+  brillo/backoff_entry.h                        \
+  brillo/bind_lambda.h                          \
+  brillo/binder_watcher.h                       \
+  brillo/brillo_export.h                        \
+  brillo/cryptohome.h                           \
+  brillo/data_encoding.h                        \
+  brillo/enum_flags.h                           \
+  brillo/file_utils.h                           \
+  brillo/flag_helper.h                          \
+  brillo/key_value_store.h                      \
+  brillo/location_logging.h                     \
+  brillo/make_unique_ptr.h                      \
+  brillo/map_utils.h                            \
+  brillo/mime_utils.h                           \
+  brillo/osrelease_reader.h                     \
+  brillo/pointer_utils.h                        \
+  brillo/process.h                              \
+  brillo/process_information.h                  \
+  brillo/process_mock.h                         \
+  brillo/process_reaper.h                       \
+  brillo/secure_blob.h                          \
+  brillo/syslog_logging.h                       \
+  brillo/test_helpers.h                         \
+  brillo/type_name_undecorate.h                 \
+  brillo/unittest_utils.h                       \
+  brillo/url_utils.h                            \
+  brillo/userdb_utils.h                         \
+  brillo/value_conversion.h                     \
+  brillo/variant_dictionary.h                   \
+  brillo/daemons/daemon.h                       \
+  brillo/daemons/dbus_daemon.h                  \
+  brillo/dbus/async_event_sequencer.h           \
+  brillo/dbus/data_serialization.h              \
+  brillo/dbus/dbus_connection.h                 \
+  brillo/dbus/dbus_method_invoker.h             \
+  brillo/dbus/dbus_method_response.h            \
+  brillo/dbus/dbus_object.h                     \
+  brillo/dbus/dbus_object_internal_impl.h       \
+  brillo/dbus/dbus_object_test_helpers.h        \
+  brillo/dbus/dbus_param_reader.h               \
+  brillo/dbus/dbus_param_writer.h               \
+  brillo/dbus/dbus_property.h                   \
+  brillo/dbus/dbus_service_watcher.h            \
+  brillo/dbus/dbus_signal.h                     \
+  brillo/dbus/dbus_signal_handler.h             \
+  brillo/dbus/exported_object_manager.h         \
+  brillo/dbus/exported_property_set.h           \
+  brillo/dbus/mock_dbus_object.h                \
+  brillo/dbus/mock_exported_object_manager.h    \
+  brillo/dbus/utils.h                           \
+  brillo/errors/error.h                         \
+  brillo/errors/error_codes.h                   \
+  brillo/glib/abstract_dbus_service.h           \
+  brillo/glib/dbus.h                            \
+  brillo/glib/object.h                          \
+  brillo/http/curl_api.h                        \
+  brillo/http/http_connection.h                 \
+  brillo/http/http_connection_curl.h            \
+  brillo/http/http_connection_fake.h            \
+  brillo/http/http_form_data.h                  \
+  brillo/http/http_request.h                    \
+  brillo/http/http_transport.h                  \
+  brillo/http/http_transport_curl.h             \
+  brillo/http/http_transport_fake.h             \
+  brillo/http/http_utils.h                      \
+  brillo/http/mock_connection.h                 \
+  brillo/http/mock_curl_api.h                   \
+  brillo/http/mock_transport.h                  \
+  brillo/message_loops/base_message_loop.h      \
+  brillo/message_loops/fake_message_loop.h      \
+  brillo/message_loops/glib_message_loop.h      \
+  brillo/message_loops/message_loop.h           \
+  brillo/message_loops/message_loop_utils.h     \
+  brillo/message_loops/mock_message_loop.h      \
+  brillo/minijail/minijail.h                    \
+  brillo/minijail/mock_minijail.h               \
+  brillo/streams/fake_stream.h                  \
+  brillo/streams/file_stream.h                  \
+  brillo/streams/input_stream_set.h             \
+  brillo/streams/memory_containers.h            \
+  brillo/streams/memory_stream.h                \
+  brillo/streams/mock_stream.h                  \
+  brillo/streams/openssl_stream_bio.h           \
+  brillo/streams/stream.h                       \
+  brillo/streams/stream_errors.h                \
+  brillo/streams/stream_utils.h                 \
+  brillo/streams/tls_stream.h                   \
+  brillo/strings/string_utils.h                 \
+  policy/device_policy.h                        \
+  policy/device_policy_impl.h                   \
+  policy/libpolicy.h                            \
+  policy/mock_device_policy.h                   \
+  policy/mock_libpolicy.h                       \
+  policy/policy_util.h                          \
+  policy/resilient_policy_util.h
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libchrome/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libchrome/Makefile.am
new file mode 100644
index 0000000..151c645
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libchrome/Makefile.am
@@ -0,0 +1,356 @@
+libchromeCommonSrc = \
+    base/at_exit.cc \
+    base/base64.cc \
+    base/base64url.cc \
+    base/base_switches.cc \
+    base/bind_helpers.cc \
+    base/build_time.cc \
+    base/callback_helpers.cc \
+    base/callback_internal.cc \
+    base/command_line.cc \
+    base/cpu.cc \
+    base/debug/activity_tracker.cc \
+    base/debug/alias.cc \
+    base/debug/debugger.cc \
+    base/debug/debugger_posix.cc \
+    base/debug/dump_without_crashing.cc \
+    base/debug/profiler.cc \
+    base/debug/stack_trace.cc \
+    base/debug/stack_trace_posix.cc \
+    base/debug/task_annotator.cc \
+    base/environment.cc \
+    base/feature_list.cc \
+    base/files/file.cc \
+    base/files/file_descriptor_watcher_posix.cc \
+    base/files/file_enumerator.cc \
+    base/files/file_enumerator_posix.cc \
+    base/files/file_path.cc \
+    base/files/file_path_constants.cc \
+    base/files/file_path_watcher.cc \
+    base/files/file_posix.cc \
+    base/files/file_tracing.cc \
+    base/files/file_util.cc \
+    base/files/file_util_posix.cc \
+    base/files/important_file_writer.cc \
+    base/files/memory_mapped_file.cc \
+    base/files/memory_mapped_file_posix.cc \
+    base/files/scoped_file.cc \
+    base/files/scoped_temp_dir.cc \
+    base/guid.cc \
+    base/hash.cc \
+    base/json/json_file_value_serializer.cc \
+    base/json/json_parser.cc \
+    base/json/json_reader.cc \
+    base/json/json_string_value_serializer.cc \
+    base/json/json_value_converter.cc \
+    base/json/json_writer.cc \
+    base/json/string_escape.cc \
+    base/lazy_instance.cc \
+    base/location.cc \
+    base/logging.cc \
+    base/md5.cc \
+    base/memory/aligned_memory.cc \
+    base/memory/ref_counted.cc \
+    base/memory/ref_counted_memory.cc \
+    base/memory/shared_memory_helper.cc \
+    base/memory/singleton.cc \
+    base/memory/weak_ptr.cc \
+    base/message_loop/incoming_task_queue.cc \
+    base/message_loop/message_loop.cc \
+    base/message_loop/message_loop_task_runner.cc \
+    base/message_loop/message_pump.cc \
+    base/message_loop/message_pump_default.cc \
+    base/message_loop/message_pump_libevent.cc \
+    base/metrics/bucket_ranges.cc \
+    base/metrics/field_trial.cc \
+    base/metrics/field_trial_param_associator.cc \
+    base/metrics/metrics_hashes.cc \
+    base/metrics/histogram_base.cc \
+    base/metrics/histogram.cc \
+    base/metrics/histogram_samples.cc \
+    base/metrics/histogram_snapshot_manager.cc \
+    base/metrics/persistent_histogram_allocator.cc \
+    base/metrics/persistent_memory_allocator.cc \
+    base/metrics/persistent_sample_map.cc \
+    base/metrics/sample_map.cc \
+    base/metrics/sample_vector.cc \
+    base/metrics/sparse_histogram.cc \
+    base/metrics/statistics_recorder.cc \
+    base/pending_task.cc \
+    base/pickle.cc \
+    base/posix/global_descriptors.cc \
+    base/posix/file_descriptor_shuffle.cc \
+    base/posix/safe_strerror.cc \
+    base/process/kill.cc \
+    base/process/kill_posix.cc \
+    base/process/launch.cc \
+    base/process/launch_posix.cc \
+    base/process/memory.cc \
+    base/process/process_handle.cc \
+    base/process/process_handle_posix.cc \
+    base/process/process_iterator.cc \
+    base/process/process_metrics.cc \
+    base/process/process_metrics_posix.cc \
+    base/process/process_posix.cc \
+    base/profiler/scoped_profile.cc \
+    base/profiler/scoped_tracker.cc \
+    base/profiler/tracked_time.cc \
+    base/rand_util.cc \
+    base/rand_util_posix.cc \
+    base/run_loop.cc \
+    base/sequence_checker_impl.cc \
+    base/sequence_token.cc \
+    base/sequenced_task_runner.cc \
+    base/sha1.cc \
+    base/strings/pattern.cc \
+    base/strings/safe_sprintf.cc \
+    base/strings/string16.cc \
+    base/strings/string_number_conversions.cc \
+    base/strings/string_piece.cc \
+    base/strings/stringprintf.cc \
+    base/strings/string_split.cc \
+    base/strings/string_util.cc \
+    base/strings/string_util_constants.cc \
+    base/strings/utf_string_conversions.cc \
+    base/strings/utf_string_conversion_utils.cc \
+    base/synchronization/atomic_flag.cc \
+    base/synchronization/condition_variable_posix.cc \
+    base/synchronization/lock.cc \
+    base/synchronization/lock_impl_posix.cc \
+    base/synchronization/read_write_lock_posix.cc \
+    base/synchronization/waitable_event_posix.cc \
+    base/sync_socket_posix.cc \
+    base/sys_info.cc \
+    base/sys_info_posix.cc \
+    base/task/cancelable_task_tracker.cc \
+    base/task_runner.cc \
+    base/task_scheduler/scheduler_lock_impl.cc \
+    base/task_scheduler/scoped_set_task_priority_for_current_thread.cc \
+    base/task_scheduler/sequence.cc \
+    base/task_scheduler/sequence_sort_key.cc \
+    base/task_scheduler/task.cc \
+    base/task_scheduler/task_traits.cc \
+    base/third_party/dynamic_annotations/dynamic_annotations.c \
+    base/third_party/icu/icu_utf.cc \
+    base/third_party/nspr/prtime.cc \
+    base/threading/non_thread_safe_impl.cc \
+    base/threading/platform_thread_posix.cc \
+    base/threading/post_task_and_reply_impl.cc \
+    base/threading/sequenced_task_runner_handle.cc \
+    base/threading/sequenced_worker_pool.cc \
+    base/threading/simple_thread.cc \
+    base/threading/thread.cc \
+    base/threading/thread_checker_impl.cc \
+    base/threading/thread_collision_warner.cc \
+    base/threading/thread_id_name_manager.cc \
+    base/threading/thread_local_storage.cc \
+    base/threading/thread_local_storage_posix.cc \
+    base/threading/thread_restrictions.cc \
+    base/threading/thread_task_runner_handle.cc \
+    base/threading/worker_pool.cc \
+    base/threading/worker_pool_posix.cc \
+    base/time/clock.cc \
+    base/time/default_clock.cc \
+    base/time/default_tick_clock.cc \
+    base/time/tick_clock.cc \
+    base/time/time.cc \
+    base/time/time_posix.cc \
+    base/timer/elapsed_timer.cc \
+    base/timer/timer.cc \
+    base/trace_event/category_registry.cc \
+    base/trace_event/event_name_filter.cc \
+    base/trace_event/heap_profiler_allocation_context.cc \
+    base/trace_event/heap_profiler_allocation_context_tracker.cc \
+    base/trace_event/heap_profiler_allocation_register.cc \
+    base/trace_event/heap_profiler_allocation_register_posix.cc \
+    base/trace_event/heap_profiler_event_filter.cc \
+    base/trace_event/heap_profiler_heap_dump_writer.cc \
+    base/trace_event/heap_profiler_stack_frame_deduplicator.cc \
+    base/trace_event/heap_profiler_type_name_deduplicator.cc \
+    base/trace_event/malloc_dump_provider.cc \
+    base/trace_event/memory_allocator_dump.cc \
+    base/trace_event/memory_allocator_dump_guid.cc \
+    base/trace_event/memory_dump_manager.cc \
+    base/trace_event/memory_dump_provider_info.cc \
+    base/trace_event/memory_dump_request_args.cc \
+    base/trace_event/memory_dump_scheduler.cc \
+    base/trace_event/memory_dump_session_state.cc \
+    base/trace_event/memory_infra_background_whitelist.cc \
+    base/trace_event/memory_usage_estimator.cc \
+    base/trace_event/process_memory_dump.cc \
+    base/trace_event/process_memory_maps.cc \
+    base/trace_event/process_memory_totals.cc \
+    base/trace_event/trace_buffer.cc \
+    base/trace_event/trace_config.cc \
+    base/trace_event/trace_config_category_filter.cc \
+    base/trace_event/trace_event_argument.cc \
+    base/trace_event/trace_event_filter.cc \
+    base/trace_event/trace_event_impl.cc \
+    base/trace_event/trace_event_memory_overhead.cc \
+    base/trace_event/trace_event_synthetic_delay.cc \
+    base/trace_event/trace_log.cc \
+    base/trace_event/trace_log_constants.cc \
+    base/tracked_objects.cc \
+    base/tracking_info.cc \
+    base/values.cc \
+    base/version.cc \
+    base/vlog.cc 
+
+libchromeLinuxSrc = \
+    base/files/file_path_watcher_linux.cc \
+    base/files/file_util_linux.cc \
+    base/memory/shared_memory_posix.cc \
+    base/memory/shared_memory_tracker.cc \
+    base/posix/unix_domain_socket_linux.cc \
+    base/process/internal_linux.cc \
+    base/process/memory_linux.cc \
+    base/process/process_handle_linux.cc \
+    base/process/process_info_linux.cc \
+    base/process/process_iterator_linux.cc \
+    base/process/process_metrics_linux.cc \
+    base/strings/sys_string_conversions_posix.cc \
+    base/sys_info_linux.cc \
+    base/threading/platform_thread_internal_posix.cc \
+    base/threading/platform_thread_linux.cc \
+    components/timers/alarm_timer_chromeos.cc
+
+libchromeLinuxGlibcSrc = \
+    base/allocator/allocator_shim.cc \
+    base/allocator/allocator_shim_default_dispatch_to_glibc.cc
+
+lib_LTLIBRARIES = libchrome.la
+libchrome_la_SOURCES = $(libchromeCommonSrc) \
+		       $(libchromeLinuxSrc)
+                       
+libchrome_la_LIBADD = \
+	$(top_builddir)/external/modp_b64/libmodpb64.a
+	
+libchrome_la_CFLAGS = -Wall \
+					-Werror \
+					-Wno-deprecated-declarations \
+					-Wno-missing-field-initializers \
+   			-DOS_LINUX 
+#         			-Wno-unused-parameter 
+
+libchrome_la_CPPFLAGS = \
+	-I$(top_srcdir)/external/libchrome \
+	-I$(top_srcdir)/external/valgrind/include \
+	-I$(top_srcdir)/external/valgrind \
+	-I$(top_srcdir)/external/modp_b64 \
+        -I$(top_srcdir)/external/libevent/include
+
+nobase_include_HEADERS = \
+    base/at_exit.h \
+    base/atomic_ref_count.h \
+    base/atomicops_internals_portable.h \
+    base/atomicops.h \
+    base/allocator/features.h \
+    base/bind.h \
+    base/bind_internal.h \
+    base/bind_helpers.h \
+    base/macros.h \
+    base/time/time.h \
+    base/logging.h \
+    base/location.h \
+    base/lazy_instance.h \
+    base/callback.h \
+    base/callback_forward.h \
+    base/callback_internal.h \
+    base/containers/hash_tables.h \
+    base/format_macros.h \
+    base/debug/debugger.h \
+    base/debug/debugging_flags.h \
+    base/debug/thread_heap_usage_tracker.h \
+    base/debug/task_annotator.h \
+    base/debug/leak_annotations.h \
+    base/hash.h \
+		base/memory/aligned_memory.h \
+		base/memory/free_deleter.h \
+		base/memory/linked_ptr.h \
+		base/memory/manual_constructor.h \
+		base/memory/ptr_util.h \
+		base/memory/raw_scoped_refptr_mismatch_checker.h \
+		base/memory/ref_counted.h \
+		base/memory/ref_counted_memory.h \
+		base/memory/scoped_policy.h \
+		base/memory/scoped_vector.h \
+		base/memory/shared_memory.h \
+		base/memory/shared_memory_handle.h \
+    base/memory/shared_memory_helper.h \
+		base/memory/shared_memory_tracker.h \
+		base/memory/singleton.h \
+    base/memory/weak_ptr.h \
+    base/message_loop/message_loop.h \
+    base/message_loop/incoming_task_queue.h \
+    base/message_loop/message_loop_task_runner.h \
+    base/message_loop/message_pump.h \
+    base/message_loop/timer_slack.h \
+    base/message_loop/message_pump_libevent.h \
+    base/metrics/histogram_macros.h \
+    base/metrics/statistics_recorder.h \
+    base/metrics/histogram.h \
+    base/metrics/histogram_base.h \
+    base/metrics/bucket_ranges.h \
+    base/metrics/histogram_samples.h \
+    base/metrics/histogram_macros_internal.h \
+    base/metrics/histogram_macros_local.h \
+    base/metrics/sparse_histogram.h \
+    base/numerics/safe_math.h \
+    base/numerics/safe_math_impl.h \
+    base/numerics/safe_conversions.h \
+    base/numerics/safe_conversions_impl.h \
+    base/file_descriptor_posix.h \
+    base/files/file.h \
+    base/files/file_util.h \
+    base/files/file_path.h \
+    base/files/scoped_temp_dir.h \
+    base/files/scoped_file.h \
+    base/files/dir_reader_posix.h \
+    base/files/file_enumerator.h \
+    base/files/file_tracing.h \
+    base/gtest_prod_util.h \
+    base/command_line.h \
+    base/base_export.h \
+    base/compiler_specific.h \
+    base/stl_util.h \
+    base/single_thread_task_runner.h \
+    base/strings/string16.h \
+    base/strings/string_util.h \
+    base/strings/string_split.h \
+    base/strings/string_number_conversions.h \
+    base/strings/stringprintf.h \
+    base/strings/string_piece.h \
+    base/strings/string_util_posix.h \
+    base/sequence_checker.h \
+    base/sequence_checker_impl.h \
+    base/scoped_generic.h \
+    base/scoped_observer.h \
+    base/sequence_token.h \
+    base/sequenced_task_runner.h \
+    base/sequenced_task_runner_helpers.h \
+    base/synchronization/lock.h \
+    base/synchronization/lock_impl.h \
+    base/synchronization/read_write_lock.h \
+    base/pending_task.h \
+    base/posix/eintr_wrapper.h \
+    base/process/process_handle.h \
+    base/profiler/tracked_time.h \
+    base/tuple.h \
+    base/task_runner.h \
+    base/template_util.h \
+    base/tracked_objects.h \
+    base/tracking_info.h \
+    base/threading/platform_thread.h \
+    base/threading/thread_checker.h \
+    base/threading/thread_checker_impl.h \
+    base/threading/thread_collision_warner.h \
+    base/threading/thread_restrictions.h \
+    base/threading/thread_local_storage.h \
+    base/threading/non_thread_safe.h \    
+    base/threading/non_thread_safe_impl.h \
+    base/observer_list.h \
+    base/rand_util.h \
+    build/build_config.h   \
+    build/buildflag.h \
+    testing/gtest/include/gtest/gtest.h \
+    testing/gtest/include/gtest/gtest_prod.h
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libdivsufsort/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libdivsufsort/Makefile.am
new file mode 100644
index 0000000..b8df2da
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libdivsufsort/Makefile.am
@@ -0,0 +1,21 @@
+lib_LTLIBRARIES = libdivsufsort.la libdivsufsort64.la
+divsufsort_source = lib/divsufsort.c \
+                    lib/sssort.c \
+                    lib/trsort.c \
+                    lib/utils.c
+divsufsort_cflag = -Wall \
+                   -Werror \
+                   -Wextra \
+                   -DHAVE_CONFIG_H=1 
+libdivsufsort_la_SOURCES = $(divsufsort_source)
+libdivsufsort64_la_SOURCES = $(divsufsort_source)
+                       
+libdivsufsort_la_CFLAGS = $(divsufsort_cflag)
+libdivsufsort64_la_CFLAGS = $(divsufsort_cflag) \
+		           -DBUILD_DIVSUFSORT64
+
+libdivsufsort_la_CPPFLAGS = -I$(top_srcdir)/external/libdivsufsort/include \
+                           -I$(top_srcdir)/external/libdivsufsort/android_include
+
+libdivsufsort64_la_CPPFLAGS = -I$(top_srcdir)/external/libdivsufsort/include \
+                           -I$(top_srcdir)/external/libdivsufsort/android_include
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libevent/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libevent/Makefile.am
new file mode 100644
index 0000000..f05ce51
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libevent/Makefile.am
@@ -0,0 +1,37 @@
+lib_LTLIBRARIES = libevent.la
+libevent_la_SOURCES = \
+        buffer.c \
+        bufferevent.c \
+        bufferevent_filter.c \
+        bufferevent_pair.c \
+        bufferevent_ratelim.c \
+        bufferevent_sock.c \
+        event.c \
+        evmap.c \
+        evthread.c \
+        evutil.c \
+        evutil_rand.c \
+        evutil_time.c \
+        listener.c \
+        log.c \
+        signal.c \
+        strlcpy.c \
+        evdns.c \
+        event_tagging.c \
+        evrpc.c \
+        http.c \
+        poll.c \
+        select.c \
+        epoll.c
+
+libevent_la_CPPFLAGS = \
+        -O3 \
+        -Wno-implicit-function-declaration \
+        -Wno-strict-aliasing \
+        -Wno-unused-parameter \
+        -Werror
+
+libevent_la_CPPFLAGS += \
+	-I$(top_srcdir)/external/libevent/include \
+	-I$(top_srcdir)/external/libevent/compat
+	
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/modp_b64/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/modp_b64/Makefile.am
new file mode 100644
index 0000000..0ad27d2
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/modp_b64/Makefile.am
@@ -0,0 +1,15 @@
+lib_LIBRARIES = libmodpb64.a
+
+libmodpb64_a_SOURCES = \
+	modp_b64.cc
+
+
+libmodpb64_a_CPPFLAGS = -Werror -Wall -Wextra  -std=c++14 -fPIC
+
+libmodpb64_a_CPPFLAGS += \
+	-I$(top_srcdir)/external/modp_b64 \
+	-I$(top_srcdir)/external/modp_b64/modp_b64
+
+nobase_include_HEADERS = \
+  modp_b64_data.h \
+	modp_b64/modp_b64.h
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/puffin/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/puffin/Makefile.am
new file mode 100644
index 0000000..fdaab81
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/puffin/Makefile.am
@@ -0,0 +1,23 @@
+lib_LTLIBRARIES = libpuffpatch.la
+
+libpuffpatch_la_SOURCES = \
+        puffin/src/puffin.pb.cc \
+        src/bit_reader.cc \
+        src/bit_writer.cc \
+        src/huffer.cc \
+        src/huffman_table.cc \
+        src/puff_reader.cc \
+        src/puff_writer.cc \
+        src/puffer.cc \
+        src/puffin_stream.cc \
+        src/puffpatch.cc
+
+libpuffpatch_la_CPPFLAGS = -Werror -Wall -Wextra  -std=c++14 -DZLIB_CONST -D_FILE_OFFSET_BITS=64 -Werror=implicit-fallthrough=0
+
+#libpuffpatch_la_LIBADD = $(top_builddir)/system/core/liblog/liblog.la
+libpuffpatch_a_LIBADD = -lgflags -lglog -lprotobuf-lite -lgtest -lpthread
+
+libpuffpatch_la_CPPFLAGS += \
+        -I$(top_srcdir)/external/puffin \
+        -I$(top_srcdir)/external/puffin/src/include \
+        -I$(top_srcdir)/external/bsdiff/include
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/puffin/src/include/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/puffin/src/include/Makefile.am
new file mode 100644
index 0000000..0cdb040
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/puffin/src/include/Makefile.am
@@ -0,0 +1,9 @@
+nobase_include_HEADERS = \
+	puffin/common.h \
+	puffin/errors.h \
+	puffin/huffer.h \
+	puffin/puffdiff.h \
+	puffin/puffer.h \
+	puffin/puffpatch.h \
+	puffin/stream.h \
+	puffin/utils.h
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/xz-embedded/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/xz-embedded/Makefile.am
new file mode 100644
index 0000000..8369af8
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/xz-embedded/Makefile.am
@@ -0,0 +1,14 @@
+lib_LIBRARIES = libxz.a
+libxz_a_SOURCES = linux/lib/xz/xz_crc32.c \
+				  linux/lib/xz/xz_dec_bcj.c \
+                  linux/lib/xz/xz_dec_lzma2.c \
+                  linux/lib/xz/xz_dec_stream.c
+                       
+libxz_a_CFLAGS = -Wall \
+					  -Werror \
+					  -DXZ_DEC_X86 \
+					  -DXZ_DEC_ARM \
+					  -DXZ_DEC_ARMTHUMB
+
+libxz_a_CPPFLAGS = -I$(top_srcdir)/external/xz-embedded/userspace \
+                   -I$(top_srcdir)/external/xz-embedded/linux/include/linux
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/xz-embedded/linux/include/linux/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/xz-embedded/linux/include/linux/Makefile.am
new file mode 100644
index 0000000..7b062f9
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/xz-embedded/linux/include/linux/Makefile.am
@@ -0,0 +1,3 @@
+nobase_include_HEADERS = \
+	xz.h \
+	decompress/unxz.h
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/base/.clang-format b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/base/.clang-format
new file mode 100644
index 0000000..2b83a1f
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/base/.clang-format
@@ -0,0 +1,11 @@
+BasedOnStyle: Google
+AllowShortBlocksOnASingleLine: false
+AllowShortFunctionsOnASingleLine: false
+
+CommentPragmas: NOLINT:.*
+DerivePointerAlignment: false
+IndentWidth: 2
+PointerAlignment: Left
+TabWidth: 2
+UseTab: Never
+PenaltyExcessCharacter: 32
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/base/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/base/Makefile.am
new file mode 100644
index 0000000..9134b45
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/base/Makefile.am
@@ -0,0 +1,20 @@
+lib_LTLIBRARIES = libbase.la
+
+libbase_la_SOURCES = \
+  chrono_utils.cpp \
+	file.cpp \
+	logging.cpp \
+	parsenetaddress.cpp \
+	stringprintf.cpp \
+	strings.cpp \
+	test_utils.cpp \
+	errors_unix.cpp
+	
+libbase_la_CPPFLAGS = -Werror -Wall -Wextra  -std=c++14
+
+libbase_la_CPPFLAGS += \
+	-I$(top_srcdir)/system/core/base/include \
+	-I$(top_srcdir)/system/core/include
+
+libbase_la_LIBADD = \
+	$(top_builddir)/system/core/liblog/liblog.la 
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/base/include/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/base/include/Makefile.am
new file mode 100644
index 0000000..355ce20
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/base/include/Makefile.am
@@ -0,0 +1,3 @@
+nobase_include_HEADERS = \
+	android-base/unique_fd.h \
+	android-base/properties.h
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/fs_mgr/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/fs_mgr/Makefile.am
new file mode 100644
index 0000000..7381adf
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/fs_mgr/Makefile.am
@@ -0,0 +1,14 @@
+lib_LTLIBRARIES = libfstab.la
+
+libfstab_la_SOURCES = \
+  fs_mgr_boot_config.cpp \
+	fs_mgr_fstab.cpp \
+	fs_mgr_slotselect.cpp
+	
+libfstab_la_CFLAGS = -Wall \
+		    -Werror \
+		    -Wno-unused-variable
+					  
+libfstab_la_CPPFLAGS =  \
+	-I$(top_srcdir)/system/core/fs_mgr/include \
+	-I$(top_srcdir)/system/core/fs_mgr/include_fstab
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/fs_mgr/include_fstab/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/fs_mgr/include_fstab/Makefile.am
new file mode 100644
index 0000000..59f16b0
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/fs_mgr/include_fstab/Makefile.am
@@ -0,0 +1,3 @@
+nobase_include_HEADERS = \
+    fstab/fstab.h
+
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/include/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/include/Makefile.am
new file mode 100644
index 0000000..ec0f4eb
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/include/Makefile.am
@@ -0,0 +1,27 @@
+nobase_include_HEADERS = \
+	utils/Compat.h \
+	utils/Errors.h \
+	utils/KeyedVector.h \
+	utils/RefBase.h \
+	utils/SortedVector.h \
+	utils/String8.h \
+	utils/String16.h \
+	utils/SystemClock.h \
+	utils/Timers.h \
+	utils/TypeHelpers.h \
+	utils/Unicode.h \
+	utils/Vector.h \
+	utils/VectorImpl.h \
+	utils/threads.h \
+	utils/StrongPointer.h \
+	utils/CallStack.h \
+	utils/Printer.h \
+	utils/Looper.h \
+	utils/ThreadDefs.h \
+	utils/AndroidThreads.h \
+	utils/Condition.h \
+	utils/Mutex.h \
+	utils/Thread.h \
+	utils/RWLock.h \
+	utils/List.h
+
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/liblog/Makefile.am b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/liblog/Makefile.am
new file mode 100644
index 0000000..5804679
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/liblog/Makefile.am
@@ -0,0 +1,22 @@
+lib_LTLIBRARIES = liblog.la
+
+liblog_la_SOURCES = \
+	config_write.c \
+	config_read.c \
+	local_logger.c \
+	fake_log_device.c \
+	fake_writer.c \
+	log_event_list.c \
+	log_event_write.c \
+	logger_lock.c \
+	logger_name.c \
+	logger_write.c \
+	logprint.c \
+	stderr_write.c
+
+liblog_la_CFLAGS = -Werror -fvisibility=hidden
+liblog_la_CPPFLAGS = \
+	-DFAKE_LOG_DEVICE=1 \
+	-DLIBLOG_LOG_TAG=1005 \
+	-DSNET_EVENT_LOG_TAG=1397638484 \
+	-I$(top_srcdir)/system/core/include
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/puffin.patch b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/puffin.patch
new file mode 100644
index 0000000..c199cb4
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/puffin.patch
@@ -0,0 +1,1590 @@
+From 75e24f2bc2c004d3b16490d34149d258128ca5d3 Mon Sep 17 00:00:00 2001
+From: mtk16536 <Dufre.Wu@mediatek.com>
+Date: Wed, 6 May 2020 12:11:14 +0800
+Subject: [PATCH] puffin
+
+Signed-off-by: mtk16536 <Dufre.Wu@mediatek.com>
+---
+ external/puffin/src/puffin.pb.cc | 854 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ external/puffin/src/puffin.pb.h  | 689 ++++++++++++++++++++++++++++++++++++++++++++
+ external/puffin/src/puffpatch.cc |   4 +-
+ 3 files changed, 1545 insertions(+), 2 deletions(-)
+ create mode 100644 external/puffin/src/puffin.pb.cc
+ create mode 100644 external/puffin/src/puffin.pb.h
+
+diff --git a/external/puffin/src/puffin.pb.cc b/external/puffin/src/puffin.pb.cc
+new file mode 100644
+index 0000000..46f050d
+--- /dev/null
++++ b/external/puffin/src/puffin.pb.cc
+@@ -0,0 +1,854 @@
++// Generated by the protocol buffer compiler.  DO NOT EDIT!
++// source: puffin.proto
++
++#include "puffin.pb.h"
++
++#include <algorithm>
++
++#include <google/protobuf/stubs/common.h>
++#include <google/protobuf/stubs/port.h>
++#include <google/protobuf/io/coded_stream.h>
++#include <google/protobuf/wire_format_lite_inl.h>
++#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
++// This is a temporary google only hack
++#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
++#include "third_party/protobuf/version.h"
++#endif
++// @@protoc_insertion_point(includes)
++
++namespace protobuf_puffin_2eproto {
++extern PROTOBUF_INTERNAL_EXPORT_protobuf_puffin_2eproto ::google::protobuf::internal::SCCInfo<0> scc_info_BitExtent;
++extern PROTOBUF_INTERNAL_EXPORT_protobuf_puffin_2eproto ::google::protobuf::internal::SCCInfo<1> scc_info_StreamInfo;
++}  // namespace protobuf_puffin_2eproto
++namespace puffin {
++namespace metadata {
++class BitExtentDefaultTypeInternal {
++ public:
++  ::google::protobuf::internal::ExplicitlyConstructed<BitExtent>
++      _instance;
++} _BitExtent_default_instance_;
++class StreamInfoDefaultTypeInternal {
++ public:
++  ::google::protobuf::internal::ExplicitlyConstructed<StreamInfo>
++      _instance;
++} _StreamInfo_default_instance_;
++class PatchHeaderDefaultTypeInternal {
++ public:
++  ::google::protobuf::internal::ExplicitlyConstructed<PatchHeader>
++      _instance;
++} _PatchHeader_default_instance_;
++}  // namespace metadata
++}  // namespace puffin
++namespace protobuf_puffin_2eproto {
++static void InitDefaultsBitExtent() {
++  GOOGLE_PROTOBUF_VERIFY_VERSION;
++
++  {
++    void* ptr = &::puffin::metadata::_BitExtent_default_instance_;
++    new (ptr) ::puffin::metadata::BitExtent();
++    ::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
++  }
++  ::puffin::metadata::BitExtent::InitAsDefaultInstance();
++}
++
++::google::protobuf::internal::SCCInfo<0> scc_info_BitExtent =
++    {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsBitExtent}, {}};
++
++static void InitDefaultsStreamInfo() {
++  GOOGLE_PROTOBUF_VERIFY_VERSION;
++
++  {
++    void* ptr = &::puffin::metadata::_StreamInfo_default_instance_;
++    new (ptr) ::puffin::metadata::StreamInfo();
++    ::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
++  }
++  ::puffin::metadata::StreamInfo::InitAsDefaultInstance();
++}
++
++::google::protobuf::internal::SCCInfo<1> scc_info_StreamInfo =
++    {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsStreamInfo}, {
++      &protobuf_puffin_2eproto::scc_info_BitExtent.base,}};
++
++static void InitDefaultsPatchHeader() {
++  GOOGLE_PROTOBUF_VERIFY_VERSION;
++
++  {
++    void* ptr = &::puffin::metadata::_PatchHeader_default_instance_;
++    new (ptr) ::puffin::metadata::PatchHeader();
++    ::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
++  }
++  ::puffin::metadata::PatchHeader::InitAsDefaultInstance();
++}
++
++::google::protobuf::internal::SCCInfo<1> scc_info_PatchHeader =
++    {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsPatchHeader}, {
++      &protobuf_puffin_2eproto::scc_info_StreamInfo.base,}};
++
++void InitDefaults() {
++  ::google::protobuf::internal::InitSCC(&scc_info_BitExtent.base);
++  ::google::protobuf::internal::InitSCC(&scc_info_StreamInfo.base);
++  ::google::protobuf::internal::InitSCC(&scc_info_PatchHeader.base);
++}
++
++}  // namespace protobuf_puffin_2eproto
++namespace puffin {
++namespace metadata {
++
++// ===================================================================
++
++void BitExtent::InitAsDefaultInstance() {
++}
++#if !defined(_MSC_VER) || _MSC_VER >= 1900
++const int BitExtent::kOffsetFieldNumber;
++const int BitExtent::kLengthFieldNumber;
++#endif  // !defined(_MSC_VER) || _MSC_VER >= 1900
++
++BitExtent::BitExtent()
++  : ::google::protobuf::MessageLite(), _internal_metadata_(NULL) {
++  ::google::protobuf::internal::InitSCC(
++      &protobuf_puffin_2eproto::scc_info_BitExtent.base);
++  SharedCtor();
++  // @@protoc_insertion_point(constructor:puffin.metadata.BitExtent)
++}
++BitExtent::BitExtent(const BitExtent& from)
++  : ::google::protobuf::MessageLite(),
++      _internal_metadata_(NULL) {
++  _internal_metadata_.MergeFrom(from._internal_metadata_);
++  ::memcpy(&offset_, &from.offset_,
++    static_cast<size_t>(reinterpret_cast<char*>(&length_) -
++    reinterpret_cast<char*>(&offset_)) + sizeof(length_));
++  // @@protoc_insertion_point(copy_constructor:puffin.metadata.BitExtent)
++}
++
++void BitExtent::SharedCtor() {
++  ::memset(&offset_, 0, static_cast<size_t>(
++      reinterpret_cast<char*>(&length_) -
++      reinterpret_cast<char*>(&offset_)) + sizeof(length_));
++}
++
++BitExtent::~BitExtent() {
++  // @@protoc_insertion_point(destructor:puffin.metadata.BitExtent)
++  SharedDtor();
++}
++
++void BitExtent::SharedDtor() {
++}
++
++void BitExtent::SetCachedSize(int size) const {
++  _cached_size_.Set(size);
++}
++const BitExtent& BitExtent::default_instance() {
++  ::google::protobuf::internal::InitSCC(&protobuf_puffin_2eproto::scc_info_BitExtent.base);
++  return *internal_default_instance();
++}
++
++
++void BitExtent::Clear() {
++// @@protoc_insertion_point(message_clear_start:puffin.metadata.BitExtent)
++  ::google::protobuf::uint32 cached_has_bits = 0;
++  // Prevent compiler warnings about cached_has_bits being unused
++  (void) cached_has_bits;
++
++  ::memset(&offset_, 0, static_cast<size_t>(
++      reinterpret_cast<char*>(&length_) -
++      reinterpret_cast<char*>(&offset_)) + sizeof(length_));
++  _internal_metadata_.Clear();
++}
++
++bool BitExtent::MergePartialFromCodedStream(
++    ::google::protobuf::io::CodedInputStream* input) {
++#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
++  ::google::protobuf::uint32 tag;
++  ::google::protobuf::internal::LiteUnknownFieldSetter unknown_fields_setter(
++      &_internal_metadata_);
++  ::google::protobuf::io::StringOutputStream unknown_fields_output(
++      unknown_fields_setter.buffer());
++  ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
++      &unknown_fields_output, false);
++  // @@protoc_insertion_point(parse_start:puffin.metadata.BitExtent)
++  for (;;) {
++    ::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
++    tag = p.first;
++    if (!p.second) goto handle_unusual;
++    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
++      // uint64 offset = 1;
++      case 1: {
++        if (static_cast< ::google::protobuf::uint8>(tag) ==
++            static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) {
++
++          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
++                   ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
++                 input, &offset_)));
++        } else {
++          goto handle_unusual;
++        }
++        break;
++      }
++
++      // uint64 length = 2;
++      case 2: {
++        if (static_cast< ::google::protobuf::uint8>(tag) ==
++            static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) {
++
++          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
++                   ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
++                 input, &length_)));
++        } else {
++          goto handle_unusual;
++        }
++        break;
++      }
++
++      default: {
++      handle_unusual:
++        if (tag == 0) {
++          goto success;
++        }
++        DO_(::google::protobuf::internal::WireFormatLite::SkipField(
++            input, tag, &unknown_fields_stream));
++        break;
++      }
++    }
++  }
++success:
++  // @@protoc_insertion_point(parse_success:puffin.metadata.BitExtent)
++  return true;
++failure:
++  // @@protoc_insertion_point(parse_failure:puffin.metadata.BitExtent)
++  return false;
++#undef DO_
++}
++
++void BitExtent::SerializeWithCachedSizes(
++    ::google::protobuf::io::CodedOutputStream* output) const {
++  // @@protoc_insertion_point(serialize_start:puffin.metadata.BitExtent)
++  ::google::protobuf::uint32 cached_has_bits = 0;
++  (void) cached_has_bits;
++
++  // uint64 offset = 1;
++  if (this->offset() != 0) {
++    ::google::protobuf::internal::WireFormatLite::WriteUInt64(1, this->offset(), output);
++  }
++
++  // uint64 length = 2;
++  if (this->length() != 0) {
++    ::google::protobuf::internal::WireFormatLite::WriteUInt64(2, this->length(), output);
++  }
++
++  output->WriteRaw((::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()).data(),
++                   static_cast<int>((::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()).size()));
++  // @@protoc_insertion_point(serialize_end:puffin.metadata.BitExtent)
++}
++
++size_t BitExtent::ByteSizeLong() const {
++// @@protoc_insertion_point(message_byte_size_start:puffin.metadata.BitExtent)
++  size_t total_size = 0;
++
++  total_size += (::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()).size();
++
++  // uint64 offset = 1;
++  if (this->offset() != 0) {
++    total_size += 1 +
++      ::google::protobuf::internal::WireFormatLite::UInt64Size(
++        this->offset());
++  }
++
++  // uint64 length = 2;
++  if (this->length() != 0) {
++    total_size += 1 +
++      ::google::protobuf::internal::WireFormatLite::UInt64Size(
++        this->length());
++  }
++
++  int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
++  SetCachedSize(cached_size);
++  return total_size;
++}
++
++void BitExtent::CheckTypeAndMergeFrom(
++    const ::google::protobuf::MessageLite& from) {
++  MergeFrom(*::google::protobuf::down_cast<const BitExtent*>(&from));
++}
++
++void BitExtent::MergeFrom(const BitExtent& from) {
++// @@protoc_insertion_point(class_specific_merge_from_start:puffin.metadata.BitExtent)
++  GOOGLE_DCHECK_NE(&from, this);
++  _internal_metadata_.MergeFrom(from._internal_metadata_);
++  ::google::protobuf::uint32 cached_has_bits = 0;
++  (void) cached_has_bits;
++
++  if (from.offset() != 0) {
++    set_offset(from.offset());
++  }
++  if (from.length() != 0) {
++    set_length(from.length());
++  }
++}
++
++void BitExtent::CopyFrom(const BitExtent& from) {
++// @@protoc_insertion_point(class_specific_copy_from_start:puffin.metadata.BitExtent)
++  if (&from == this) return;
++  Clear();
++  MergeFrom(from);
++}
++
++bool BitExtent::IsInitialized() const {
++  return true;
++}
++
++void BitExtent::Swap(BitExtent* other) {
++  if (other == this) return;
++  InternalSwap(other);
++}
++void BitExtent::InternalSwap(BitExtent* other) {
++  using std::swap;
++  swap(offset_, other->offset_);
++  swap(length_, other->length_);
++  _internal_metadata_.Swap(&other->_internal_metadata_);
++}
++
++::std::string BitExtent::GetTypeName() const {
++  return "puffin.metadata.BitExtent";
++}
++
++
++// ===================================================================
++
++void StreamInfo::InitAsDefaultInstance() {
++}
++#if !defined(_MSC_VER) || _MSC_VER >= 1900
++const int StreamInfo::kDeflatesFieldNumber;
++const int StreamInfo::kPuffsFieldNumber;
++const int StreamInfo::kPuffLengthFieldNumber;
++#endif  // !defined(_MSC_VER) || _MSC_VER >= 1900
++
++StreamInfo::StreamInfo()
++  : ::google::protobuf::MessageLite(), _internal_metadata_(NULL) {
++  ::google::protobuf::internal::InitSCC(
++      &protobuf_puffin_2eproto::scc_info_StreamInfo.base);
++  SharedCtor();
++  // @@protoc_insertion_point(constructor:puffin.metadata.StreamInfo)
++}
++StreamInfo::StreamInfo(const StreamInfo& from)
++  : ::google::protobuf::MessageLite(),
++      _internal_metadata_(NULL),
++      deflates_(from.deflates_),
++      puffs_(from.puffs_) {
++  _internal_metadata_.MergeFrom(from._internal_metadata_);
++  puff_length_ = from.puff_length_;
++  // @@protoc_insertion_point(copy_constructor:puffin.metadata.StreamInfo)
++}
++
++void StreamInfo::SharedCtor() {
++  puff_length_ = GOOGLE_ULONGLONG(0);
++}
++
++StreamInfo::~StreamInfo() {
++  // @@protoc_insertion_point(destructor:puffin.metadata.StreamInfo)
++  SharedDtor();
++}
++
++void StreamInfo::SharedDtor() {
++}
++
++void StreamInfo::SetCachedSize(int size) const {
++  _cached_size_.Set(size);
++}
++const StreamInfo& StreamInfo::default_instance() {
++  ::google::protobuf::internal::InitSCC(&protobuf_puffin_2eproto::scc_info_StreamInfo.base);
++  return *internal_default_instance();
++}
++
++
++void StreamInfo::Clear() {
++// @@protoc_insertion_point(message_clear_start:puffin.metadata.StreamInfo)
++  ::google::protobuf::uint32 cached_has_bits = 0;
++  // Prevent compiler warnings about cached_has_bits being unused
++  (void) cached_has_bits;
++
++  deflates_.Clear();
++  puffs_.Clear();
++  puff_length_ = GOOGLE_ULONGLONG(0);
++  _internal_metadata_.Clear();
++}
++
++bool StreamInfo::MergePartialFromCodedStream(
++    ::google::protobuf::io::CodedInputStream* input) {
++#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
++  ::google::protobuf::uint32 tag;
++  ::google::protobuf::internal::LiteUnknownFieldSetter unknown_fields_setter(
++      &_internal_metadata_);
++  ::google::protobuf::io::StringOutputStream unknown_fields_output(
++      unknown_fields_setter.buffer());
++  ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
++      &unknown_fields_output, false);
++  // @@protoc_insertion_point(parse_start:puffin.metadata.StreamInfo)
++  for (;;) {
++    ::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
++    tag = p.first;
++    if (!p.second) goto handle_unusual;
++    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
++      // repeated .puffin.metadata.BitExtent deflates = 1;
++      case 1: {
++        if (static_cast< ::google::protobuf::uint8>(tag) ==
++            static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
++          DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(
++                input, add_deflates()));
++        } else {
++          goto handle_unusual;
++        }
++        break;
++      }
++
++      // repeated .puffin.metadata.BitExtent puffs = 2;
++      case 2: {
++        if (static_cast< ::google::protobuf::uint8>(tag) ==
++            static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) {
++          DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(
++                input, add_puffs()));
++        } else {
++          goto handle_unusual;
++        }
++        break;
++      }
++
++      // uint64 puff_length = 3;
++      case 3: {
++        if (static_cast< ::google::protobuf::uint8>(tag) ==
++            static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) {
++
++          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
++                   ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
++                 input, &puff_length_)));
++        } else {
++          goto handle_unusual;
++        }
++        break;
++      }
++
++      default: {
++      handle_unusual:
++        if (tag == 0) {
++          goto success;
++        }
++        DO_(::google::protobuf::internal::WireFormatLite::SkipField(
++            input, tag, &unknown_fields_stream));
++        break;
++      }
++    }
++  }
++success:
++  // @@protoc_insertion_point(parse_success:puffin.metadata.StreamInfo)
++  return true;
++failure:
++  // @@protoc_insertion_point(parse_failure:puffin.metadata.StreamInfo)
++  return false;
++#undef DO_
++}
++
++void StreamInfo::SerializeWithCachedSizes(
++    ::google::protobuf::io::CodedOutputStream* output) const {
++  // @@protoc_insertion_point(serialize_start:puffin.metadata.StreamInfo)
++  ::google::protobuf::uint32 cached_has_bits = 0;
++  (void) cached_has_bits;
++
++  // repeated .puffin.metadata.BitExtent deflates = 1;
++  for (unsigned int i = 0,
++      n = static_cast<unsigned int>(this->deflates_size()); i < n; i++) {
++    ::google::protobuf::internal::WireFormatLite::WriteMessage(
++      1,
++      this->deflates(static_cast<int>(i)),
++      output);
++  }
++
++  // repeated .puffin.metadata.BitExtent puffs = 2;
++  for (unsigned int i = 0,
++      n = static_cast<unsigned int>(this->puffs_size()); i < n; i++) {
++    ::google::protobuf::internal::WireFormatLite::WriteMessage(
++      2,
++      this->puffs(static_cast<int>(i)),
++      output);
++  }
++
++  // uint64 puff_length = 3;
++  if (this->puff_length() != 0) {
++    ::google::protobuf::internal::WireFormatLite::WriteUInt64(3, this->puff_length(), output);
++  }
++
++  output->WriteRaw((::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()).data(),
++                   static_cast<int>((::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()).size()));
++  // @@protoc_insertion_point(serialize_end:puffin.metadata.StreamInfo)
++}
++
++size_t StreamInfo::ByteSizeLong() const {
++// @@protoc_insertion_point(message_byte_size_start:puffin.metadata.StreamInfo)
++  size_t total_size = 0;
++
++  total_size += (::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()).size();
++
++  // repeated .puffin.metadata.BitExtent deflates = 1;
++  {
++    unsigned int count = static_cast<unsigned int>(this->deflates_size());
++    total_size += 1UL * count;
++    for (unsigned int i = 0; i < count; i++) {
++      total_size +=
++        ::google::protobuf::internal::WireFormatLite::MessageSize(
++          this->deflates(static_cast<int>(i)));
++    }
++  }
++
++  // repeated .puffin.metadata.BitExtent puffs = 2;
++  {
++    unsigned int count = static_cast<unsigned int>(this->puffs_size());
++    total_size += 1UL * count;
++    for (unsigned int i = 0; i < count; i++) {
++      total_size +=
++        ::google::protobuf::internal::WireFormatLite::MessageSize(
++          this->puffs(static_cast<int>(i)));
++    }
++  }
++
++  // uint64 puff_length = 3;
++  if (this->puff_length() != 0) {
++    total_size += 1 +
++      ::google::protobuf::internal::WireFormatLite::UInt64Size(
++        this->puff_length());
++  }
++
++  int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
++  SetCachedSize(cached_size);
++  return total_size;
++}
++
++void StreamInfo::CheckTypeAndMergeFrom(
++    const ::google::protobuf::MessageLite& from) {
++  MergeFrom(*::google::protobuf::down_cast<const StreamInfo*>(&from));
++}
++
++void StreamInfo::MergeFrom(const StreamInfo& from) {
++// @@protoc_insertion_point(class_specific_merge_from_start:puffin.metadata.StreamInfo)
++  GOOGLE_DCHECK_NE(&from, this);
++  _internal_metadata_.MergeFrom(from._internal_metadata_);
++  ::google::protobuf::uint32 cached_has_bits = 0;
++  (void) cached_has_bits;
++
++  deflates_.MergeFrom(from.deflates_);
++  puffs_.MergeFrom(from.puffs_);
++  if (from.puff_length() != 0) {
++    set_puff_length(from.puff_length());
++  }
++}
++
++void StreamInfo::CopyFrom(const StreamInfo& from) {
++// @@protoc_insertion_point(class_specific_copy_from_start:puffin.metadata.StreamInfo)
++  if (&from == this) return;
++  Clear();
++  MergeFrom(from);
++}
++
++bool StreamInfo::IsInitialized() const {
++  return true;
++}
++
++void StreamInfo::Swap(StreamInfo* other) {
++  if (other == this) return;
++  InternalSwap(other);
++}
++void StreamInfo::InternalSwap(StreamInfo* other) {
++  using std::swap;
++  CastToBase(&deflates_)->InternalSwap(CastToBase(&other->deflates_));
++  CastToBase(&puffs_)->InternalSwap(CastToBase(&other->puffs_));
++  swap(puff_length_, other->puff_length_);
++  _internal_metadata_.Swap(&other->_internal_metadata_);
++}
++
++::std::string StreamInfo::GetTypeName() const {
++  return "puffin.metadata.StreamInfo";
++}
++
++
++// ===================================================================
++
++void PatchHeader::InitAsDefaultInstance() {
++  ::puffin::metadata::_PatchHeader_default_instance_._instance.get_mutable()->src_ = const_cast< ::puffin::metadata::StreamInfo*>(
++      ::puffin::metadata::StreamInfo::internal_default_instance());
++  ::puffin::metadata::_PatchHeader_default_instance_._instance.get_mutable()->dst_ = const_cast< ::puffin::metadata::StreamInfo*>(
++      ::puffin::metadata::StreamInfo::internal_default_instance());
++}
++#if !defined(_MSC_VER) || _MSC_VER >= 1900
++const int PatchHeader::kVersionFieldNumber;
++const int PatchHeader::kSrcFieldNumber;
++const int PatchHeader::kDstFieldNumber;
++#endif  // !defined(_MSC_VER) || _MSC_VER >= 1900
++
++PatchHeader::PatchHeader()
++  : ::google::protobuf::MessageLite(), _internal_metadata_(NULL) {
++  ::google::protobuf::internal::InitSCC(
++      &protobuf_puffin_2eproto::scc_info_PatchHeader.base);
++  SharedCtor();
++  // @@protoc_insertion_point(constructor:puffin.metadata.PatchHeader)
++}
++PatchHeader::PatchHeader(const PatchHeader& from)
++  : ::google::protobuf::MessageLite(),
++      _internal_metadata_(NULL) {
++  _internal_metadata_.MergeFrom(from._internal_metadata_);
++  if (from.has_src()) {
++    src_ = new ::puffin::metadata::StreamInfo(*from.src_);
++  } else {
++    src_ = NULL;
++  }
++  if (from.has_dst()) {
++    dst_ = new ::puffin::metadata::StreamInfo(*from.dst_);
++  } else {
++    dst_ = NULL;
++  }
++  version_ = from.version_;
++  // @@protoc_insertion_point(copy_constructor:puffin.metadata.PatchHeader)
++}
++
++void PatchHeader::SharedCtor() {
++  ::memset(&src_, 0, static_cast<size_t>(
++      reinterpret_cast<char*>(&version_) -
++      reinterpret_cast<char*>(&src_)) + sizeof(version_));
++}
++
++PatchHeader::~PatchHeader() {
++  // @@protoc_insertion_point(destructor:puffin.metadata.PatchHeader)
++  SharedDtor();
++}
++
++void PatchHeader::SharedDtor() {
++  if (this != internal_default_instance()) delete src_;
++  if (this != internal_default_instance()) delete dst_;
++}
++
++void PatchHeader::SetCachedSize(int size) const {
++  _cached_size_.Set(size);
++}
++const PatchHeader& PatchHeader::default_instance() {
++  ::google::protobuf::internal::InitSCC(&protobuf_puffin_2eproto::scc_info_PatchHeader.base);
++  return *internal_default_instance();
++}
++
++
++void PatchHeader::Clear() {
++// @@protoc_insertion_point(message_clear_start:puffin.metadata.PatchHeader)
++  ::google::protobuf::uint32 cached_has_bits = 0;
++  // Prevent compiler warnings about cached_has_bits being unused
++  (void) cached_has_bits;
++
++  if (GetArenaNoVirtual() == NULL && src_ != NULL) {
++    delete src_;
++  }
++  src_ = NULL;
++  if (GetArenaNoVirtual() == NULL && dst_ != NULL) {
++    delete dst_;
++  }
++  dst_ = NULL;
++  version_ = 0;
++  _internal_metadata_.Clear();
++}
++
++bool PatchHeader::MergePartialFromCodedStream(
++    ::google::protobuf::io::CodedInputStream* input) {
++#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
++  ::google::protobuf::uint32 tag;
++  ::google::protobuf::internal::LiteUnknownFieldSetter unknown_fields_setter(
++      &_internal_metadata_);
++  ::google::protobuf::io::StringOutputStream unknown_fields_output(
++      unknown_fields_setter.buffer());
++  ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
++      &unknown_fields_output, false);
++  // @@protoc_insertion_point(parse_start:puffin.metadata.PatchHeader)
++  for (;;) {
++    ::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
++    tag = p.first;
++    if (!p.second) goto handle_unusual;
++    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
++      // int32 version = 1;
++      case 1: {
++        if (static_cast< ::google::protobuf::uint8>(tag) ==
++            static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) {
++
++          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
++                   ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
++                 input, &version_)));
++        } else {
++          goto handle_unusual;
++        }
++        break;
++      }
++
++      // .puffin.metadata.StreamInfo src = 2;
++      case 2: {
++        if (static_cast< ::google::protobuf::uint8>(tag) ==
++            static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) {
++          DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(
++               input, mutable_src()));
++        } else {
++          goto handle_unusual;
++        }
++        break;
++      }
++
++      // .puffin.metadata.StreamInfo dst = 3;
++      case 3: {
++        if (static_cast< ::google::protobuf::uint8>(tag) ==
++            static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) {
++          DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(
++               input, mutable_dst()));
++        } else {
++          goto handle_unusual;
++        }
++        break;
++      }
++
++      default: {
++      handle_unusual:
++        if (tag == 0) {
++          goto success;
++        }
++        DO_(::google::protobuf::internal::WireFormatLite::SkipField(
++            input, tag, &unknown_fields_stream));
++        break;
++      }
++    }
++  }
++success:
++  // @@protoc_insertion_point(parse_success:puffin.metadata.PatchHeader)
++  return true;
++failure:
++  // @@protoc_insertion_point(parse_failure:puffin.metadata.PatchHeader)
++  return false;
++#undef DO_
++}
++
++void PatchHeader::SerializeWithCachedSizes(
++    ::google::protobuf::io::CodedOutputStream* output) const {
++  // @@protoc_insertion_point(serialize_start:puffin.metadata.PatchHeader)
++  ::google::protobuf::uint32 cached_has_bits = 0;
++  (void) cached_has_bits;
++
++  // int32 version = 1;
++  if (this->version() != 0) {
++    ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->version(), output);
++  }
++
++  // .puffin.metadata.StreamInfo src = 2;
++  if (this->has_src()) {
++    ::google::protobuf::internal::WireFormatLite::WriteMessage(
++      2, this->_internal_src(), output);
++  }
++
++  // .puffin.metadata.StreamInfo dst = 3;
++  if (this->has_dst()) {
++    ::google::protobuf::internal::WireFormatLite::WriteMessage(
++      3, this->_internal_dst(), output);
++  }
++
++  output->WriteRaw((::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()).data(),
++                   static_cast<int>((::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()).size()));
++  // @@protoc_insertion_point(serialize_end:puffin.metadata.PatchHeader)
++}
++
++size_t PatchHeader::ByteSizeLong() const {
++// @@protoc_insertion_point(message_byte_size_start:puffin.metadata.PatchHeader)
++  size_t total_size = 0;
++
++  total_size += (::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()).size();
++
++  // .puffin.metadata.StreamInfo src = 2;
++  if (this->has_src()) {
++    total_size += 1 +
++      ::google::protobuf::internal::WireFormatLite::MessageSize(
++        *src_);
++  }
++
++  // .puffin.metadata.StreamInfo dst = 3;
++  if (this->has_dst()) {
++    total_size += 1 +
++      ::google::protobuf::internal::WireFormatLite::MessageSize(
++        *dst_);
++  }
++
++  // int32 version = 1;
++  if (this->version() != 0) {
++    total_size += 1 +
++      ::google::protobuf::internal::WireFormatLite::Int32Size(
++        this->version());
++  }
++
++  int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
++  SetCachedSize(cached_size);
++  return total_size;
++}
++
++void PatchHeader::CheckTypeAndMergeFrom(
++    const ::google::protobuf::MessageLite& from) {
++  MergeFrom(*::google::protobuf::down_cast<const PatchHeader*>(&from));
++}
++
++void PatchHeader::MergeFrom(const PatchHeader& from) {
++// @@protoc_insertion_point(class_specific_merge_from_start:puffin.metadata.PatchHeader)
++  GOOGLE_DCHECK_NE(&from, this);
++  _internal_metadata_.MergeFrom(from._internal_metadata_);
++  ::google::protobuf::uint32 cached_has_bits = 0;
++  (void) cached_has_bits;
++
++  if (from.has_src()) {
++    mutable_src()->::puffin::metadata::StreamInfo::MergeFrom(from.src());
++  }
++  if (from.has_dst()) {
++    mutable_dst()->::puffin::metadata::StreamInfo::MergeFrom(from.dst());
++  }
++  if (from.version() != 0) {
++    set_version(from.version());
++  }
++}
++
++void PatchHeader::CopyFrom(const PatchHeader& from) {
++// @@protoc_insertion_point(class_specific_copy_from_start:puffin.metadata.PatchHeader)
++  if (&from == this) return;
++  Clear();
++  MergeFrom(from);
++}
++
++bool PatchHeader::IsInitialized() const {
++  return true;
++}
++
++void PatchHeader::Swap(PatchHeader* other) {
++  if (other == this) return;
++  InternalSwap(other);
++}
++void PatchHeader::InternalSwap(PatchHeader* other) {
++  using std::swap;
++  swap(src_, other->src_);
++  swap(dst_, other->dst_);
++  swap(version_, other->version_);
++  _internal_metadata_.Swap(&other->_internal_metadata_);
++}
++
++::std::string PatchHeader::GetTypeName() const {
++  return "puffin.metadata.PatchHeader";
++}
++
++
++// @@protoc_insertion_point(namespace_scope)
++}  // namespace metadata
++}  // namespace puffin
++namespace google {
++namespace protobuf {
++template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::puffin::metadata::BitExtent* Arena::CreateMaybeMessage< ::puffin::metadata::BitExtent >(Arena* arena) {
++  return Arena::CreateInternal< ::puffin::metadata::BitExtent >(arena);
++}
++template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::puffin::metadata::StreamInfo* Arena::CreateMaybeMessage< ::puffin::metadata::StreamInfo >(Arena* arena) {
++  return Arena::CreateInternal< ::puffin::metadata::StreamInfo >(arena);
++}
++template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::puffin::metadata::PatchHeader* Arena::CreateMaybeMessage< ::puffin::metadata::PatchHeader >(Arena* arena) {
++  return Arena::CreateInternal< ::puffin::metadata::PatchHeader >(arena);
++}
++}  // namespace protobuf
++}  // namespace google
++
++// @@protoc_insertion_point(global_scope)
+diff --git a/external/puffin/src/puffin.pb.h b/external/puffin/src/puffin.pb.h
+new file mode 100644
+index 0000000..074c4b6
+--- /dev/null
++++ b/src/puffin.pb.h
+@@ -0,0 +1,689 @@
++// Generated by the protocol buffer compiler.  DO NOT EDIT!
++// source: puffin.proto
++
++#ifndef PROTOBUF_INCLUDED_puffin_2eproto
++#define PROTOBUF_INCLUDED_puffin_2eproto
++
++#include <string>
++
++#include <google/protobuf/stubs/common.h>
++
++#if GOOGLE_PROTOBUF_VERSION < 3006001
++#error This file was generated by a newer version of protoc which is
++#error incompatible with your Protocol Buffer headers.  Please update
++#error your headers.
++#endif
++#if 3006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
++#error This file was generated by an older version of protoc which is
++#error incompatible with your Protocol Buffer headers.  Please
++#error regenerate this file with a newer version of protoc.
++#endif
++
++#include <google/protobuf/io/coded_stream.h>
++#include <google/protobuf/arena.h>
++#include <google/protobuf/arenastring.h>
++#include <google/protobuf/generated_message_table_driven.h>
++#include <google/protobuf/generated_message_util.h>
++#include <google/protobuf/inlined_string_field.h>
++#include <google/protobuf/metadata_lite.h>
++#include <google/protobuf/message_lite.h>
++#include <google/protobuf/repeated_field.h>  // IWYU pragma: export
++#include <google/protobuf/extension_set.h>  // IWYU pragma: export
++// @@protoc_insertion_point(includes)
++#define PROTOBUF_INTERNAL_EXPORT_protobuf_puffin_2eproto 
++
++namespace protobuf_puffin_2eproto {
++// Internal implementation detail -- do not use these members.
++struct TableStruct {
++  static const ::google::protobuf::internal::ParseTableField entries[];
++  static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
++  static const ::google::protobuf::internal::ParseTable schema[3];
++  static const ::google::protobuf::internal::FieldMetadata field_metadata[];
++  static const ::google::protobuf::internal::SerializationTable serialization_table[];
++  static const ::google::protobuf::uint32 offsets[];
++};
++}  // namespace protobuf_puffin_2eproto
++namespace puffin {
++namespace metadata {
++class BitExtent;
++class BitExtentDefaultTypeInternal;
++extern BitExtentDefaultTypeInternal _BitExtent_default_instance_;
++class PatchHeader;
++class PatchHeaderDefaultTypeInternal;
++extern PatchHeaderDefaultTypeInternal _PatchHeader_default_instance_;
++class StreamInfo;
++class StreamInfoDefaultTypeInternal;
++extern StreamInfoDefaultTypeInternal _StreamInfo_default_instance_;
++}  // namespace metadata
++}  // namespace puffin
++namespace google {
++namespace protobuf {
++template<> ::puffin::metadata::BitExtent* Arena::CreateMaybeMessage<::puffin::metadata::BitExtent>(Arena*);
++template<> ::puffin::metadata::PatchHeader* Arena::CreateMaybeMessage<::puffin::metadata::PatchHeader>(Arena*);
++template<> ::puffin::metadata::StreamInfo* Arena::CreateMaybeMessage<::puffin::metadata::StreamInfo>(Arena*);
++}  // namespace protobuf
++}  // namespace google
++namespace puffin {
++namespace metadata {
++
++// ===================================================================
++
++class BitExtent : public ::google::protobuf::MessageLite /* @@protoc_insertion_point(class_definition:puffin.metadata.BitExtent) */ {
++ public:
++  BitExtent();
++  virtual ~BitExtent();
++
++  BitExtent(const BitExtent& from);
++
++  inline BitExtent& operator=(const BitExtent& from) {
++    CopyFrom(from);
++    return *this;
++  }
++  #if LANG_CXX11
++  BitExtent(BitExtent&& from) noexcept
++    : BitExtent() {
++    *this = ::std::move(from);
++  }
++
++  inline BitExtent& operator=(BitExtent&& from) noexcept {
++    if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
++      if (this != &from) InternalSwap(&from);
++    } else {
++      CopyFrom(from);
++    }
++    return *this;
++  }
++  #endif
++  static const BitExtent& default_instance();
++
++  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
++  static inline const BitExtent* internal_default_instance() {
++    return reinterpret_cast<const BitExtent*>(
++               &_BitExtent_default_instance_);
++  }
++  static constexpr int kIndexInFileMessages =
++    0;
++
++  void Swap(BitExtent* other);
++  friend void swap(BitExtent& a, BitExtent& b) {
++    a.Swap(&b);
++  }
++
++  // implements Message ----------------------------------------------
++
++  inline BitExtent* New() const final {
++    return CreateMaybeMessage<BitExtent>(NULL);
++  }
++
++  BitExtent* New(::google::protobuf::Arena* arena) const final {
++    return CreateMaybeMessage<BitExtent>(arena);
++  }
++  void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from)
++    final;
++  void CopyFrom(const BitExtent& from);
++  void MergeFrom(const BitExtent& from);
++  void Clear() final;
++  bool IsInitialized() const final;
++
++  size_t ByteSizeLong() const final;
++  bool MergePartialFromCodedStream(
++      ::google::protobuf::io::CodedInputStream* input) final;
++  void SerializeWithCachedSizes(
++      ::google::protobuf::io::CodedOutputStream* output) const final;
++  void DiscardUnknownFields();
++  int GetCachedSize() const final { return _cached_size_.Get(); }
++
++  private:
++  void SharedCtor();
++  void SharedDtor();
++  void SetCachedSize(int size) const;
++  void InternalSwap(BitExtent* other);
++  private:
++  inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
++    return NULL;
++  }
++  inline void* MaybeArenaPtr() const {
++    return NULL;
++  }
++  public:
++
++  ::std::string GetTypeName() const final;
++
++  // nested types ----------------------------------------------------
++
++  // accessors -------------------------------------------------------
++
++  // uint64 offset = 1;
++  void clear_offset();
++  static const int kOffsetFieldNumber = 1;
++  ::google::protobuf::uint64 offset() const;
++  void set_offset(::google::protobuf::uint64 value);
++
++  // uint64 length = 2;
++  void clear_length();
++  static const int kLengthFieldNumber = 2;
++  ::google::protobuf::uint64 length() const;
++  void set_length(::google::protobuf::uint64 value);
++
++  // @@protoc_insertion_point(class_scope:puffin.metadata.BitExtent)
++ private:
++
++  ::google::protobuf::internal::InternalMetadataWithArenaLite _internal_metadata_;
++  ::google::protobuf::uint64 offset_;
++  ::google::protobuf::uint64 length_;
++  mutable ::google::protobuf::internal::CachedSize _cached_size_;
++  friend struct ::protobuf_puffin_2eproto::TableStruct;
++};
++// -------------------------------------------------------------------
++
++class StreamInfo : public ::google::protobuf::MessageLite /* @@protoc_insertion_point(class_definition:puffin.metadata.StreamInfo) */ {
++ public:
++  StreamInfo();
++  virtual ~StreamInfo();
++
++  StreamInfo(const StreamInfo& from);
++
++  inline StreamInfo& operator=(const StreamInfo& from) {
++    CopyFrom(from);
++    return *this;
++  }
++  #if LANG_CXX11
++  StreamInfo(StreamInfo&& from) noexcept
++    : StreamInfo() {
++    *this = ::std::move(from);
++  }
++
++  inline StreamInfo& operator=(StreamInfo&& from) noexcept {
++    if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
++      if (this != &from) InternalSwap(&from);
++    } else {
++      CopyFrom(from);
++    }
++    return *this;
++  }
++  #endif
++  static const StreamInfo& default_instance();
++
++  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
++  static inline const StreamInfo* internal_default_instance() {
++    return reinterpret_cast<const StreamInfo*>(
++               &_StreamInfo_default_instance_);
++  }
++  static constexpr int kIndexInFileMessages =
++    1;
++
++  void Swap(StreamInfo* other);
++  friend void swap(StreamInfo& a, StreamInfo& b) {
++    a.Swap(&b);
++  }
++
++  // implements Message ----------------------------------------------
++
++  inline StreamInfo* New() const final {
++    return CreateMaybeMessage<StreamInfo>(NULL);
++  }
++
++  StreamInfo* New(::google::protobuf::Arena* arena) const final {
++    return CreateMaybeMessage<StreamInfo>(arena);
++  }
++  void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from)
++    final;
++  void CopyFrom(const StreamInfo& from);
++  void MergeFrom(const StreamInfo& from);
++  void Clear() final;
++  bool IsInitialized() const final;
++
++  size_t ByteSizeLong() const final;
++  bool MergePartialFromCodedStream(
++      ::google::protobuf::io::CodedInputStream* input) final;
++  void SerializeWithCachedSizes(
++      ::google::protobuf::io::CodedOutputStream* output) const final;
++  void DiscardUnknownFields();
++  int GetCachedSize() const final { return _cached_size_.Get(); }
++
++  private:
++  void SharedCtor();
++  void SharedDtor();
++  void SetCachedSize(int size) const;
++  void InternalSwap(StreamInfo* other);
++  private:
++  inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
++    return NULL;
++  }
++  inline void* MaybeArenaPtr() const {
++    return NULL;
++  }
++  public:
++
++  ::std::string GetTypeName() const final;
++
++  // nested types ----------------------------------------------------
++
++  // accessors -------------------------------------------------------
++
++  // repeated .puffin.metadata.BitExtent deflates = 1;
++  int deflates_size() const;
++  void clear_deflates();
++  static const int kDeflatesFieldNumber = 1;
++  ::puffin::metadata::BitExtent* mutable_deflates(int index);
++  ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent >*
++      mutable_deflates();
++  const ::puffin::metadata::BitExtent& deflates(int index) const;
++  ::puffin::metadata::BitExtent* add_deflates();
++  const ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent >&
++      deflates() const;
++
++  // repeated .puffin.metadata.BitExtent puffs = 2;
++  int puffs_size() const;
++  void clear_puffs();
++  static const int kPuffsFieldNumber = 2;
++  ::puffin::metadata::BitExtent* mutable_puffs(int index);
++  ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent >*
++      mutable_puffs();
++  const ::puffin::metadata::BitExtent& puffs(int index) const;
++  ::puffin::metadata::BitExtent* add_puffs();
++  const ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent >&
++      puffs() const;
++
++  // uint64 puff_length = 3;
++  void clear_puff_length();
++  static const int kPuffLengthFieldNumber = 3;
++  ::google::protobuf::uint64 puff_length() const;
++  void set_puff_length(::google::protobuf::uint64 value);
++
++  // @@protoc_insertion_point(class_scope:puffin.metadata.StreamInfo)
++ private:
++
++  ::google::protobuf::internal::InternalMetadataWithArenaLite _internal_metadata_;
++  ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent > deflates_;
++  ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent > puffs_;
++  ::google::protobuf::uint64 puff_length_;
++  mutable ::google::protobuf::internal::CachedSize _cached_size_;
++  friend struct ::protobuf_puffin_2eproto::TableStruct;
++};
++// -------------------------------------------------------------------
++
++class PatchHeader : public ::google::protobuf::MessageLite /* @@protoc_insertion_point(class_definition:puffin.metadata.PatchHeader) */ {
++ public:
++  PatchHeader();
++  virtual ~PatchHeader();
++
++  PatchHeader(const PatchHeader& from);
++
++  inline PatchHeader& operator=(const PatchHeader& from) {
++    CopyFrom(from);
++    return *this;
++  }
++  #if LANG_CXX11
++  PatchHeader(PatchHeader&& from) noexcept
++    : PatchHeader() {
++    *this = ::std::move(from);
++  }
++
++  inline PatchHeader& operator=(PatchHeader&& from) noexcept {
++    if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
++      if (this != &from) InternalSwap(&from);
++    } else {
++      CopyFrom(from);
++    }
++    return *this;
++  }
++  #endif
++  static const PatchHeader& default_instance();
++
++  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
++  static inline const PatchHeader* internal_default_instance() {
++    return reinterpret_cast<const PatchHeader*>(
++               &_PatchHeader_default_instance_);
++  }
++  static constexpr int kIndexInFileMessages =
++    2;
++
++  void Swap(PatchHeader* other);
++  friend void swap(PatchHeader& a, PatchHeader& b) {
++    a.Swap(&b);
++  }
++
++  // implements Message ----------------------------------------------
++
++  inline PatchHeader* New() const final {
++    return CreateMaybeMessage<PatchHeader>(NULL);
++  }
++
++  PatchHeader* New(::google::protobuf::Arena* arena) const final {
++    return CreateMaybeMessage<PatchHeader>(arena);
++  }
++  void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from)
++    final;
++  void CopyFrom(const PatchHeader& from);
++  void MergeFrom(const PatchHeader& from);
++  void Clear() final;
++  bool IsInitialized() const final;
++
++  size_t ByteSizeLong() const final;
++  bool MergePartialFromCodedStream(
++      ::google::protobuf::io::CodedInputStream* input) final;
++  void SerializeWithCachedSizes(
++      ::google::protobuf::io::CodedOutputStream* output) const final;
++  void DiscardUnknownFields();
++  int GetCachedSize() const final { return _cached_size_.Get(); }
++
++  private:
++  void SharedCtor();
++  void SharedDtor();
++  void SetCachedSize(int size) const;
++  void InternalSwap(PatchHeader* other);
++  private:
++  inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
++    return NULL;
++  }
++  inline void* MaybeArenaPtr() const {
++    return NULL;
++  }
++  public:
++
++  ::std::string GetTypeName() const final;
++
++  // nested types ----------------------------------------------------
++
++  // accessors -------------------------------------------------------
++
++  // .puffin.metadata.StreamInfo src = 2;
++  bool has_src() const;
++  void clear_src();
++  static const int kSrcFieldNumber = 2;
++  private:
++  const ::puffin::metadata::StreamInfo& _internal_src() const;
++  public:
++  const ::puffin::metadata::StreamInfo& src() const;
++  ::puffin::metadata::StreamInfo* release_src();
++  ::puffin::metadata::StreamInfo* mutable_src();
++  void set_allocated_src(::puffin::metadata::StreamInfo* src);
++
++  // .puffin.metadata.StreamInfo dst = 3;
++  bool has_dst() const;
++  void clear_dst();
++  static const int kDstFieldNumber = 3;
++  private:
++  const ::puffin::metadata::StreamInfo& _internal_dst() const;
++  public:
++  const ::puffin::metadata::StreamInfo& dst() const;
++  ::puffin::metadata::StreamInfo* release_dst();
++  ::puffin::metadata::StreamInfo* mutable_dst();
++  void set_allocated_dst(::puffin::metadata::StreamInfo* dst);
++
++  // int32 version = 1;
++  void clear_version();
++  static const int kVersionFieldNumber = 1;
++  ::google::protobuf::int32 version() const;
++  void set_version(::google::protobuf::int32 value);
++
++  // @@protoc_insertion_point(class_scope:puffin.metadata.PatchHeader)
++ private:
++
++  ::google::protobuf::internal::InternalMetadataWithArenaLite _internal_metadata_;
++  ::puffin::metadata::StreamInfo* src_;
++  ::puffin::metadata::StreamInfo* dst_;
++  ::google::protobuf::int32 version_;
++  mutable ::google::protobuf::internal::CachedSize _cached_size_;
++  friend struct ::protobuf_puffin_2eproto::TableStruct;
++};
++// ===================================================================
++
++
++// ===================================================================
++
++#ifdef __GNUC__
++  #pragma GCC diagnostic push
++  #pragma GCC diagnostic ignored "-Wstrict-aliasing"
++#endif  // __GNUC__
++// BitExtent
++
++// uint64 offset = 1;
++inline void BitExtent::clear_offset() {
++  offset_ = GOOGLE_ULONGLONG(0);
++}
++inline ::google::protobuf::uint64 BitExtent::offset() const {
++  // @@protoc_insertion_point(field_get:puffin.metadata.BitExtent.offset)
++  return offset_;
++}
++inline void BitExtent::set_offset(::google::protobuf::uint64 value) {
++  
++  offset_ = value;
++  // @@protoc_insertion_point(field_set:puffin.metadata.BitExtent.offset)
++}
++
++// uint64 length = 2;
++inline void BitExtent::clear_length() {
++  length_ = GOOGLE_ULONGLONG(0);
++}
++inline ::google::protobuf::uint64 BitExtent::length() const {
++  // @@protoc_insertion_point(field_get:puffin.metadata.BitExtent.length)
++  return length_;
++}
++inline void BitExtent::set_length(::google::protobuf::uint64 value) {
++  
++  length_ = value;
++  // @@protoc_insertion_point(field_set:puffin.metadata.BitExtent.length)
++}
++
++// -------------------------------------------------------------------
++
++// StreamInfo
++
++// repeated .puffin.metadata.BitExtent deflates = 1;
++inline int StreamInfo::deflates_size() const {
++  return deflates_.size();
++}
++inline void StreamInfo::clear_deflates() {
++  deflates_.Clear();
++}
++inline ::puffin::metadata::BitExtent* StreamInfo::mutable_deflates(int index) {
++  // @@protoc_insertion_point(field_mutable:puffin.metadata.StreamInfo.deflates)
++  return deflates_.Mutable(index);
++}
++inline ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent >*
++StreamInfo::mutable_deflates() {
++  // @@protoc_insertion_point(field_mutable_list:puffin.metadata.StreamInfo.deflates)
++  return &deflates_;
++}
++inline const ::puffin::metadata::BitExtent& StreamInfo::deflates(int index) const {
++  // @@protoc_insertion_point(field_get:puffin.metadata.StreamInfo.deflates)
++  return deflates_.Get(index);
++}
++inline ::puffin::metadata::BitExtent* StreamInfo::add_deflates() {
++  // @@protoc_insertion_point(field_add:puffin.metadata.StreamInfo.deflates)
++  return deflates_.Add();
++}
++inline const ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent >&
++StreamInfo::deflates() const {
++  // @@protoc_insertion_point(field_list:puffin.metadata.StreamInfo.deflates)
++  return deflates_;
++}
++
++// repeated .puffin.metadata.BitExtent puffs = 2;
++inline int StreamInfo::puffs_size() const {
++  return puffs_.size();
++}
++inline void StreamInfo::clear_puffs() {
++  puffs_.Clear();
++}
++inline ::puffin::metadata::BitExtent* StreamInfo::mutable_puffs(int index) {
++  // @@protoc_insertion_point(field_mutable:puffin.metadata.StreamInfo.puffs)
++  return puffs_.Mutable(index);
++}
++inline ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent >*
++StreamInfo::mutable_puffs() {
++  // @@protoc_insertion_point(field_mutable_list:puffin.metadata.StreamInfo.puffs)
++  return &puffs_;
++}
++inline const ::puffin::metadata::BitExtent& StreamInfo::puffs(int index) const {
++  // @@protoc_insertion_point(field_get:puffin.metadata.StreamInfo.puffs)
++  return puffs_.Get(index);
++}
++inline ::puffin::metadata::BitExtent* StreamInfo::add_puffs() {
++  // @@protoc_insertion_point(field_add:puffin.metadata.StreamInfo.puffs)
++  return puffs_.Add();
++}
++inline const ::google::protobuf::RepeatedPtrField< ::puffin::metadata::BitExtent >&
++StreamInfo::puffs() const {
++  // @@protoc_insertion_point(field_list:puffin.metadata.StreamInfo.puffs)
++  return puffs_;
++}
++
++// uint64 puff_length = 3;
++inline void StreamInfo::clear_puff_length() {
++  puff_length_ = GOOGLE_ULONGLONG(0);
++}
++inline ::google::protobuf::uint64 StreamInfo::puff_length() const {
++  // @@protoc_insertion_point(field_get:puffin.metadata.StreamInfo.puff_length)
++  return puff_length_;
++}
++inline void StreamInfo::set_puff_length(::google::protobuf::uint64 value) {
++  
++  puff_length_ = value;
++  // @@protoc_insertion_point(field_set:puffin.metadata.StreamInfo.puff_length)
++}
++
++// -------------------------------------------------------------------
++
++// PatchHeader
++
++// int32 version = 1;
++inline void PatchHeader::clear_version() {
++  version_ = 0;
++}
++inline ::google::protobuf::int32 PatchHeader::version() const {
++  // @@protoc_insertion_point(field_get:puffin.metadata.PatchHeader.version)
++  return version_;
++}
++inline void PatchHeader::set_version(::google::protobuf::int32 value) {
++  
++  version_ = value;
++  // @@protoc_insertion_point(field_set:puffin.metadata.PatchHeader.version)
++}
++
++// .puffin.metadata.StreamInfo src = 2;
++inline bool PatchHeader::has_src() const {
++  return this != internal_default_instance() && src_ != NULL;
++}
++inline void PatchHeader::clear_src() {
++  if (GetArenaNoVirtual() == NULL && src_ != NULL) {
++    delete src_;
++  }
++  src_ = NULL;
++}
++inline const ::puffin::metadata::StreamInfo& PatchHeader::_internal_src() const {
++  return *src_;
++}
++inline const ::puffin::metadata::StreamInfo& PatchHeader::src() const {
++  const ::puffin::metadata::StreamInfo* p = src_;
++  // @@protoc_insertion_point(field_get:puffin.metadata.PatchHeader.src)
++  return p != NULL ? *p : *reinterpret_cast<const ::puffin::metadata::StreamInfo*>(
++      &::puffin::metadata::_StreamInfo_default_instance_);
++}
++inline ::puffin::metadata::StreamInfo* PatchHeader::release_src() {
++  // @@protoc_insertion_point(field_release:puffin.metadata.PatchHeader.src)
++  
++  ::puffin::metadata::StreamInfo* temp = src_;
++  src_ = NULL;
++  return temp;
++}
++inline ::puffin::metadata::StreamInfo* PatchHeader::mutable_src() {
++  
++  if (src_ == NULL) {
++    auto* p = CreateMaybeMessage<::puffin::metadata::StreamInfo>(GetArenaNoVirtual());
++    src_ = p;
++  }
++  // @@protoc_insertion_point(field_mutable:puffin.metadata.PatchHeader.src)
++  return src_;
++}
++inline void PatchHeader::set_allocated_src(::puffin::metadata::StreamInfo* src) {
++  ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
++  if (message_arena == NULL) {
++    delete src_;
++  }
++  if (src) {
++    ::google::protobuf::Arena* submessage_arena = NULL;
++    if (message_arena != submessage_arena) {
++      src = ::google::protobuf::internal::GetOwnedMessage(
++          message_arena, src, submessage_arena);
++    }
++    
++  } else {
++    
++  }
++  src_ = src;
++  // @@protoc_insertion_point(field_set_allocated:puffin.metadata.PatchHeader.src)
++}
++
++// .puffin.metadata.StreamInfo dst = 3;
++inline bool PatchHeader::has_dst() const {
++  return this != internal_default_instance() && dst_ != NULL;
++}
++inline void PatchHeader::clear_dst() {
++  if (GetArenaNoVirtual() == NULL && dst_ != NULL) {
++    delete dst_;
++  }
++  dst_ = NULL;
++}
++inline const ::puffin::metadata::StreamInfo& PatchHeader::_internal_dst() const {
++  return *dst_;
++}
++inline const ::puffin::metadata::StreamInfo& PatchHeader::dst() const {
++  const ::puffin::metadata::StreamInfo* p = dst_;
++  // @@protoc_insertion_point(field_get:puffin.metadata.PatchHeader.dst)
++  return p != NULL ? *p : *reinterpret_cast<const ::puffin::metadata::StreamInfo*>(
++      &::puffin::metadata::_StreamInfo_default_instance_);
++}
++inline ::puffin::metadata::StreamInfo* PatchHeader::release_dst() {
++  // @@protoc_insertion_point(field_release:puffin.metadata.PatchHeader.dst)
++  
++  ::puffin::metadata::StreamInfo* temp = dst_;
++  dst_ = NULL;
++  return temp;
++}
++inline ::puffin::metadata::StreamInfo* PatchHeader::mutable_dst() {
++  
++  if (dst_ == NULL) {
++    auto* p = CreateMaybeMessage<::puffin::metadata::StreamInfo>(GetArenaNoVirtual());
++    dst_ = p;
++  }
++  // @@protoc_insertion_point(field_mutable:puffin.metadata.PatchHeader.dst)
++  return dst_;
++}
++inline void PatchHeader::set_allocated_dst(::puffin::metadata::StreamInfo* dst) {
++  ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
++  if (message_arena == NULL) {
++    delete dst_;
++  }
++  if (dst) {
++    ::google::protobuf::Arena* submessage_arena = NULL;
++    if (message_arena != submessage_arena) {
++      dst = ::google::protobuf::internal::GetOwnedMessage(
++          message_arena, dst, submessage_arena);
++    }
++    
++  } else {
++    
++  }
++  dst_ = dst;
++  // @@protoc_insertion_point(field_set_allocated:puffin.metadata.PatchHeader.dst)
++}
++
++#ifdef __GNUC__
++  #pragma GCC diagnostic pop
++#endif  // __GNUC__
++// -------------------------------------------------------------------
++
++// -------------------------------------------------------------------
++
++
++// @@protoc_insertion_point(namespace_scope)
++
++}  // namespace metadata
++}  // namespace puffin
++
++// @@protoc_insertion_point(global_scope)
++
++#endif  // PROTOBUF_INCLUDED_puffin_2eproto
+diff --git a/external/puffin/src/puffpatch.cc b/external/puffin/src/puffpatch.cc
+index 185b1dd..a9114fd 100644
+--- a/external/puffin/src/puffpatch.cc
++++ b/external/puffin/src/puffpatch.cc
+@@ -135,11 +135,11 @@ bool PuffPatch(UniqueStreamPtr src,
+                const uint8_t* patch,
+                size_t patch_length,
+                size_t max_cache_size) {
+-  size_t bsdiff_patch_offset;  // bsdiff offset in |patch|.
++  size_t bsdiff_patch_offset = 0;  // bsdiff offset in |patch|.
+   size_t bsdiff_patch_size = 0;
+   vector<BitExtent> src_deflates, dst_deflates;
+   vector<ByteExtent> src_puffs, dst_puffs;
+-  uint64_t src_puff_size, dst_puff_size;
++  uint64_t src_puff_size, dst_puff_size = 0;
+ 
+   // Decode the patch and get the bsdiff_patch.
+   TEST_AND_RETURN_FALSE(DecodePatch(patch, patch_length, &bsdiff_patch_offset,
+-- 
+2.6.4
+
diff --git a/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/platform-libs-updateengine.bb b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/platform-libs-updateengine.bb
new file mode 100644
index 0000000..562b94a
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/platform-libs-updateengine.bb
@@ -0,0 +1,70 @@
+inherit autotools
+DESCRIPTION = "Android platform libraries"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = " \
+	file://system/core/NOTICE;md5=c1a3ff0b97f199c7ebcfdd4d3fed238e \
+	"
+
+SRC_URI = " \
+	git://android.googlesource.com/platform/external/brotli;name=platform/external/brotli;destsuffix=platform/external/brotli/ \
+	git://android.googlesource.com/platform/external/bsdiff;name=platform/external/bsdiff;destsuffix=platform/external/bsdiff/ \
+	git://android.googlesource.com/platform/external/puffin;name=platform/external/puffin;destsuffix=platform/external/puffin/ \
+	git://android.googlesource.com/platform/external/libevent;name=platform/external/libevent;destsuffix=platform/external/libevent/ \
+	git://android.googlesource.com/platform/external/libdivsufsort;name=platform/external/libdivsufsort;destsuffix=platform/external/libdivsufsort/ \
+	git://android.googlesource.com/platform/external/libbrillo;name=platform/external/libbrillo;destsuffix=platform/external/libbrillo/ \
+	git://android.googlesource.com/platform/external/libchrome;name=platform/external/libchrome;destsuffix=platform/external/libchrome/ \
+	git://android.googlesource.com/platform/external/modp_b64;name=platform/external/modp_b64;destsuffix=platform/external/modp_b64/ \
+	git://android.googlesource.com/platform/external/xz-embedded;name=platform/external/xz-embedded;destsuffix=platform/external/xz-embedded/ \
+	git://android.googlesource.com/platform/external/cros/system_api;name=platform/external/cros/system_api;destsuffix=platform/external/cros/system_api/ \
+	git://android.googlesource.com/platform/system/core;name=platform/system/core;destsuffix=platform/system/core/ \
+	file://base.patch \
+	file://libchrome.patch \
+	file://fstab.patch \
+	file://puffin.patch \
+	file://libevent.patch \
+	file://libbrillo.patch \
+	file://file_stream.patch \
+"
+
+SRCREV_platform/external/brotli = "5ccabc48199cb108fd914222cd6bdbe12c7e15e6"
+SRCREV_platform/external/bsdiff = "f0c8211af44d092cf6cc816b1e9af72f14fe80f6"
+SRCREV_platform/external/puffin = "7c492ae6e97dadf21d9282e26711d318ccddfc9b"
+SRCREV_platform/external/libevent = "becbc79be28cd4f92d14c3f395d562995fc73bf9"
+SRCREV_platform/external/libdivsufsort = "fcee868119b5eac60a8cd9fc9ddebb9627ffd172"
+SRCREV_platform/external/libbrillo = "11469312f6dce4ee8a4b98d33a36a0814b7f77c2"
+SRCREV_platform/external/libchrome = "b6fcee758cbc64842e10cb155780818aaad02420"
+SRCREV_platform/external/modp_b64 = "6f11b5c9b4ffb38dc9375f3cf344da4300a2741a"
+SRCREV_platform/external/xz-embedded = "180f9115008b00e7c1a2b35317f2bca709fce8a1"
+SRCREV_platform/external/cros/system_api = "b48922224f13c7323a389cc8b2585d43dc1ba724"
+SRCREV_platform/system/core = "f0c6e2494ebb7fdbb95494fc4e461542e02bdfeb"
+
+FILESEXTRAPATHS_prepend := "${THISDIR}:"
+
+DEPENDS += "openssl-native openssl gtest bzip2 glog protobuf platform-libs-common ${@bb.utils.contains("BOOTDEV_TYPE", "nand", "nandapi", "", d)}"
+
+S = "${WORKDIR}/platform"
+
+LDFLAGS += "-lcrypto -lpthread -lglog -lbase"
+
+SECURITY_CFLAGS=""
+
+do_configure_prepend() {
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/Makefile.am ${WORKDIR}/platform/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/configure.ac ${WORKDIR}/platform/configure.ac
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/fs_mgr/Makefile.am ${WORKDIR}/platform/system/core/fs_mgr/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/system/core/fs_mgr/include_fstab/Makefile.am ${WORKDIR}/platform/system/core/fs_mgr/include_fstab/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/modp_b64/Makefile.am ${WORKDIR}/platform/external/modp_b64/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libbrillo/Makefile.am ${WORKDIR}/platform/external/libbrillo/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libchrome/Makefile.am ${WORKDIR}/platform/external/libchrome/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libevent/Makefile.am ${WORKDIR}/platform/external/libevent/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/cros/system_api/dbus/Makefile.am ${WORKDIR}/platform/external/cros/system_api/dbus/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/xz-embedded/Makefile.am ${WORKDIR}/platform/external/xz-embedded/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/xz-embedded/linux/include/linux/Makefile.am ${WORKDIR}/platform/external/xz-embedded/linux/include/linux/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/bsdiff/Makefile.am ${WORKDIR}/platform/external/bsdiff/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/bsdiff/include/Makefile.am ${WORKDIR}/platform/external/bsdiff/include/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/brotli/Makefile.am ${WORKDIR}/platform/external/brotli/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/puffin/src/include/Makefile.am ${WORKDIR}/platform/external/puffin/src/include/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/puffin/Makefile.am ${WORKDIR}/platform/external/puffin/Makefile.am
+	install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/platform-libs-for-updateengine/files/makefiles/platform/external/libdivsufsort/Makefile.am ${WORKDIR}/platform/external/libdivsufsort/Makefile.am
+}
+
diff --git a/meta/meta-mediatek/recipes-support/softhsm-init/files/softhsm-init.service b/meta/meta-mediatek/recipes-support/softhsm-init/files/softhsm-init.service
new file mode 100644
index 0000000..53d693e
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/softhsm-init/files/softhsm-init.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=SofthsmInitScript
+RequiresMountsFor=#SOFTHSM_DATA_MOUNT_POINT#
+
+[Service]
+ExecStart=/etc/softhsm-init.sh
+Type=simple
+
+[Install]
+Alias=SofthsmInitScript
+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/softhsm-init/files/softhsm-init.sh b/meta/meta-mediatek/recipes-support/softhsm-init/files/softhsm-init.sh
new file mode 100644
index 0000000..4fdf411
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/softhsm-init/files/softhsm-init.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+#       @author
+#       @brief  generate the top index for each module doc
+
+if [ -d "#SOFTHSM_DATA_TOKEN_DIR#" ]; then
+    exit 0
+fi
+
+mkdir -p #SOFTHSM_DATA_TOKEN_DIR#
+
+softhsm2-util --init-token --free --label \"#SOFTHSM_DEFAULT_TOKEN_LABEL#\" --pin #SOFTHSM_DEFAULT_TOKEN_PIN# --so-pin #SOFTHSM_DEFAULT_TOKEN_SO_PIN#
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/softhsm-init/softhsm-init.bb b/meta/meta-mediatek/recipes-support/softhsm-init/softhsm-init.bb
new file mode 100644
index 0000000..d83a056
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/softhsm-init/softhsm-init.bb
@@ -0,0 +1,45 @@
+inherit workonsrc

+inherit pkgconfig

+inherit systemd

+

+DESCRIPTION = "SoftHSM Init"

+LICENSE = "MediaTekProprietary"

+LIC_FILES_CHKSUM = "file://COPYING;md5=d7810fab7487fb0aad327b76f1be7cd7"

+APPS_SRC = "${TOPDIR}/../meta/meta-mediatek/recipes-support/softhsm-init"

+WORKONSRC = "${APPS_SRC}"

+

+#####Customization Start#####

+SOFTHSM_DATA_MOUNT_POINT = "/data"

+SOFTHSM_DATA_TOKEN_DIR = "/data/softhsm"

+SOFTHSM_DEFAULT_TOKEN_LABEL = "8516softhsm"

+SOFTHSM_DEFAULT_TOKEN_PIN = "85168516"

+SOFTHSM_DEFAULT_TOKEN_SO_PIN = "85168516"

+#####Customization End#####

+

+SYSTEMD_PACKAGES = "${PN}"

+SYSTEMD_SERVICE_${PN} = "softhsm-init.service"

+FILES_${PN} += "${systemd_unitdir}/system/softhsm-init.service"

+FILES_${PN} += "etc/softhsm-init.sh"

+FILES_${PN} += "etc/softhsm2.conf"

+

+do_install() {

+        install -d ${D}/etc

+        install -m 755 ${S}files/softhsm-init.sh ${D}/etc/softhsm-init.sh

+

+        install -d ${D}${systemd_system_unitdir}

+        install -m 0755 ${S}files/softhsm-init.service ${D}${systemd_system_unitdir}

+

+        sed -e 's%#SOFTHSM_DATA_MOUNT_POINT#%${SOFTHSM_DATA_MOUNT_POINT}%g' \

+        -i ${D}${systemd_system_unitdir}/softhsm-init.service

+

+        sed -e 's%#SOFTHSM_DATA_TOKEN_DIR#%${SOFTHSM_DATA_TOKEN_DIR}%g' \

+        	-e 's%#SOFTHSM_DEFAULT_TOKEN_LABEL#%${SOFTHSM_DEFAULT_TOKEN_LABEL}%g' \

+        	-e 's%#SOFTHSM_DEFAULT_TOKEN_PIN#%${SOFTHSM_DEFAULT_TOKEN_PIN}%g' \

+        	-e 's%#SOFTHSM_DEFAULT_TOKEN_SO_PIN#%${SOFTHSM_DEFAULT_TOKEN_SO_PIN}%g' \

+        	-i ${D}/etc/softhsm-init.sh

+

+        echo "objectstore.backend = file" > ${D}/etc/softhsm2.conf

+        echo "directories.tokendir = ${SOFTHSM_DATA_TOKEN_DIR}" >> ${D}/etc/softhsm2.conf

+}

+

+

diff --git a/meta/meta-mediatek/recipes-support/update-engine-sideload/files/buildinfo.sh b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/buildinfo.sh
new file mode 100644
index 0000000..76f91a2
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/buildinfo.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+echo "ro.build.version.sdk=28"
+echo "ro.build.version.security_patch=2019-01-05"
+echo "ro.build.version.incremental=eng.mtk941.20190311.151249"
+echo "ro.product.device=mt2712"
+echo "ro.build.fingerprint=mediatek/car_mt2712/mt2712:9/PPR1.181005.003/mtk9412903120944:userdebug/test-keys"
+echo "ro.build.date=`date`"
+echo "ro.build.date.utc=`date +%s`"
diff --git a/meta/meta-mediatek/recipes-support/update-engine-sideload/files/erase_partition.patch b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/erase_partition.patch
new file mode 100644
index 0000000..02a4a23
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/erase_partition.patch
@@ -0,0 +1,22 @@
+diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
+index a619d1d9..2abc3baa 100644
+--- a/payload_consumer/delta_performer.cc
++++ b/payload_consumer/delta_performer.cc
+@@ -367,6 +367,17 @@ bool DeltaPerformer::OpenCurrentPartition() {
+   target_path_ = install_part.target_path;
+   int err;
+
++  if (install_plan_->is_resume == false)
++  {
++      string cmd = "flash_eraseall ";
++      string p_cmd;
++
++      p_cmd = cmd + target_path_;
++      LOG(INFO) << "Erase partition, erase cmd=" << p_cmd;
++
++      system(p_cmd.c_str());
++  }
++
+   int flags = O_RDWR;
+   if (!is_interactive_)
+     flags |= O_DSYNC;
diff --git a/meta/meta-mediatek/recipes-support/update-engine-sideload/files/file_descriptor.patch b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/file_descriptor.patch
new file mode 100644
index 0000000..3f63f57
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/file_descriptor.patch
@@ -0,0 +1,92 @@
+diff --git a/payload_consumer/file_descriptor.cc b/payload_consumer/file_descriptor.cc
+index 4eabb8f..1dc03d6 100644
+--- a/payload_consumer/file_descriptor.cc
++++ b/payload_consumer/file_descriptor.cc
+@@ -24,22 +24,40 @@
+
+ #include <base/posix/eintr_wrapper.h>
+
++#define BOOTDEV_TYPE_NAND 1
++#define BOOTDEV_TYPE_EMMC 2
++
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  extern "C"{
++    #include "mtk_device_wrap.h"
++}
++#endif
++
+ #include "update_engine/common/utils.h"
+
+ namespace chromeos_update_engine {
+
+ bool EintrSafeFileDescriptor::Open(const char* path, int flags, mode_t mode) {
+   CHECK_EQ(fd_, -1);
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  return ((fd_ = HANDLE_EINTR(mtk_device_wrap_m_open(path, flags, mode))) >= 0);
++#endif
+   return ((fd_ = HANDLE_EINTR(open(path, flags, mode))) >= 0);
+ }
+
+ bool EintrSafeFileDescriptor::Open(const char* path, int flags) {
+   CHECK_EQ(fd_, -1);
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  return ((fd_ = HANDLE_EINTR(mtk_device_wrap_open(path, flags))) >= 0);
++#endif
+   return ((fd_ = HANDLE_EINTR(open(path, flags))) >= 0);
+ }
+
+ ssize_t EintrSafeFileDescriptor::Read(void* buf, size_t count) {
+   CHECK_GE(fd_, 0);
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  return HANDLE_EINTR(mtk_device_wrap_read(fd_, buf, count));
++#endif
+   return HANDLE_EINTR(read(fd_, buf, count));
+ }
+
+@@ -50,7 +68,11 @@ ssize_t EintrSafeFileDescriptor::Write(const void* buf, size_t count) {
+   char* char_buf = const_cast<char*>(reinterpret_cast<const char*>(buf));
+   ssize_t written = 0;
+   while (count > 0) {
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++    ssize_t ret = HANDLE_EINTR(mtk_device_wrap_write_force(fd_, char_buf, count));
++#else
+     ssize_t ret = HANDLE_EINTR(write(fd_, char_buf, count));
++#endif
+
+     // Fail on either an error or no progress.
+     if (ret <= 0)
+@@ -64,6 +86,9 @@ ssize_t EintrSafeFileDescriptor::Write(const void* buf, size_t count) {
+
+ off64_t EintrSafeFileDescriptor::Seek(off64_t offset, int whence) {
+   CHECK_GE(fd_, 0);
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  return mtk_device_wrap_seek64(fd_, offset, whence);
++#endif
+   return lseek64(fd_, offset, whence);
+ }
+
+@@ -87,6 +112,10 @@ bool EintrSafeFileDescriptor::BlkIoctl(int request,
+                                        int* result) {
+   // If the ioctl BLKZEROOUT is not defined, just fail to perform any of these
+   // operations.
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  return false;
++#endif
++
+ #ifndef BLKZEROOUT
+   return false;
+ #else  // defined(BLKZEROOUT)
+@@ -130,8 +159,13 @@ bool EintrSafeFileDescriptor::Flush() {
+
+ bool EintrSafeFileDescriptor::Close() {
+   CHECK_GE(fd_, 0);
++#if MTK_BOOTDEV_TYPE == BOOTDEV_TYPE_NAND
++  if (IGNORE_EINTR(mtk_device_wrap_close(fd_)))
++    return false;
++#else
+   if (IGNORE_EINTR(close(fd_)))
+     return false;
++#endif
+   fd_ = -1;
+   return true;
+ }
diff --git a/meta/meta-mediatek/recipes-support/update-engine-sideload/files/makefiles/Makefile.am b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/makefiles/Makefile.am
new file mode 100644
index 0000000..f2b3184
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/makefiles/Makefile.am
@@ -0,0 +1,120 @@
+local_use_binder = 0
+local_use_hwid_override = 0
+local_use_libcros = 0
+local_use_mtd = 0
+
+BUILT_SOURCES = 
+EXTRA_DIST =
+
+AM_CPPFLAGS = $(GTEST_CPPFLAGS) $(GMOCK_CPPFLAGS)
+AM_CFLAGS = -fno-exceptions \
+    -fno-strict-aliasing \
+    -Wclobbered \
+    -Wempty-body \
+    -Wignored-qualifiers \
+    -Wmissing-field-initializers \
+    -Wsign-compare \
+    -Wtype-limits \
+    -Wuninitialized \
+    -Wa,--noexecstack \
+    -Wall \
+    -Wextra \
+    -Wformat=2 \
+    -Wno-psabi \
+    -Wno-unused-parameter \
+    -ffunction-sections \
+    -fstack-protector-strong \
+    -fvisibility=hidden \
+    -D__STDC_FORMAT_MACROS=1 \
+    $(GLIB_CFLAGS) $(DEPS_CFLAGS) \
+    -DUSE_BINDER=$(local_use_binder) \
+    -DUSE_HWID_OVERRIDE=$(local_use_hwid_override) \
+    -DUSE_LIBCROS=$(local_use_libcros) \
+    -DUSE_MTD=$(local_use_mtd) \
+    -DUSE_OMAHA=0 \
+    -D_FILE_OFFSET_BITS=64 \
+    -D_POSIX_C_SOURCE=199309L \
+    -D_UE_SIDELOAD=1 \
+    -DUSE_DBUS=0
+
+AM_CXXFLAGS = $(AM_CFLAGS)
+
+EXTRA_DIST += update_metadata.proto
+BUILT_SOURCES += update_metadata.pb.cc \
+		 update_metadata.pb.h
+%.pb.cc %.pb.h: %.proto
+	$(AM_V_GEN) $(PROTOC) --proto_path=$(top_srcdir) --cpp_out=$(top_srcdir) $<
+
+noinst_LIBRARIES = libpayload_consumer.a
+
+sbin_PROGRAMS = update_engine_sideload
+
+libpayload_consumer_a_SOURCES = \
+    common/action_processor.cc \
+    common/boot_control_stub.cc \
+    common/clock.cc \
+    common/constants.cc \
+    common/cpu_limiter.cc \
+    common/error_code_utils.cc \
+    common/file_fetcher.cc \
+    common/hash_calculator.cc \
+    common/http_common.cc \
+    common/http_fetcher.cc \
+    common/hwid_override.cc \
+    common/multi_range_http_fetcher.cc \
+    common/platform_constants_android.cc \
+    common/prefs.cc \
+    common/subprocess.cc \
+    common/terminator.cc \
+    common/utils.cc \
+    payload_consumer/bzip_extent_writer.cc \
+    payload_consumer/cached_file_descriptor.cc \
+    payload_consumer/delta_performer.cc \
+    payload_consumer/download_action.cc \
+    payload_consumer/extent_reader.cc \
+    payload_consumer/extent_writer.cc \
+    payload_consumer/file_descriptor.cc \
+    payload_consumer/file_descriptor_utils.cc \
+    payload_consumer/file_writer.cc \
+    payload_consumer/filesystem_verifier_action.cc \
+    payload_consumer/install_plan.cc \
+    payload_consumer/mount_history.cc \
+    payload_consumer/payload_constants.cc \
+    payload_consumer/payload_metadata.cc \
+    payload_consumer/payload_verifier.cc \
+    payload_consumer/postinstall_runner_action.cc \
+    payload_consumer/xz_extent_writer.cc
+
+if NAND
+update_engine_sideload_LDADD = libpayload_consumer.a -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lcrypto \
+     -lcurl -llog -lssl -lprotobuf-lite -lpthread -lbz2 -lgflags -lbase -lchrome -lbrillo -lbrillo_stream \
+     -levent -lbspatch -lfstab -lbootctrl -lxz -lpuffpatch -lbrotli -lnandapi
+else
+update_engine_sideload_LDADD = libpayload_consumer.a -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lcrypto \
+     -lcurl -llog -lssl -lprotobuf-lite -lpthread -lbz2 -lgflags -lbase -lchrome -lbrillo -lbrillo_stream \
+     -levent -lbspatch -lfstab -lbootctrl -lxz -lpuffpatch -lbrotli
+endif
+
+
+update_engine_sideload_SOURCES = \
+    update_metadata.pb.cc \
+    certificate_checker.cc \
+    daemon.cc \
+    daemon_state_android.cc \
+    boot_control_recovery.cc \
+    hardware_android.cc \
+    libcurl_http_fetcher.cc \
+    metrics_reporter_stub.cc \
+    metrics_utils.cc \
+    network_selector_stub.cc \
+    proxy_resolver.cc \
+    sideload_main.cc \
+    update_attempter_android.cc \
+    update_status_utils.cc \
+    utils_android.cc
+
+update_engine_sideload_CFLAGS = -std=c++14 -g -fPIC -c
+
+
+
+
diff --git a/meta/meta-mediatek/recipes-support/update-engine-sideload/files/makefiles/configure.ac b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/makefiles/configure.ac
new file mode 100644
index 0000000..04fbf65
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/makefiles/configure.ac
@@ -0,0 +1,46 @@
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.69])
+AC_INIT([update_engine],[0.4.7],[https://github.com/coreos/bugs/issues])
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_SRCDIR([main.cc])
+AC_USE_SYSTEM_EXTENSIONS
+AC_SYS_LARGEFILE
+
+AM_INIT_AUTOMAKE([foreign 1.13 -Wall -Wno-portability
+                  serial-tests silent-rules subdir-objects])
+AM_SILENT_RULES([yes])
+
+# check boot type
+AC_ARG_ENABLE(nand, AC_HELP_STRING([--enable-nand],
+                                [enable nand support]),
+                                        [enable_nand=${enableval}])
+
+AM_CONDITIONAL(NAND, test "$enable_nand" = "yes")
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_MKDIR_P
+AC_PROG_RANLIB
+AM_PROG_AR
+
+AC_PATH_PROG([PROTOC], [protoc])
+AS_IF([test "x${PROTOC}" = "x"],
+      [AC_MSG_ERROR([*** protoc not found])])
+	  
+AC_CHECK_LIB([bz2], [BZ2_bzDecompressInit], [],
+             [AC_MSG_ERROR([*** libbz2 not found])])
+AC_CHECK_HEADERS([bzlib.h], [],
+                 [AC_MSG_ERROR([*** bzlib.h not found])])
+
+PKG_CHECK_MODULES([DEPS],
+	[dbus-1
+	dbus-glib-1
+	libcrypto
+	libcurl
+	libssl])
+#	protobuf])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/meta/meta-mediatek/recipes-support/update-engine-sideload/files/update-payload-key.pub.pem b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/update-payload-key.pub.pem
new file mode 100644
index 0000000..47e6e4d
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/update-payload-key.pub.pem
@@ -0,0 +1,9 @@
+-----BEGIN PUBLIC KEY-----
+MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEA1pMZBN7GCySx7cdi4NnY
+JT4+zWzrHeL/Boyo6LyozWvTeG6nCqds5g67D5k1Wf/ZPnepQ+foPUtkuOT+otPm
+VvHiZ6gbv7IwtXjCBEO+THIYuEb1IRWG8DihTonCvjh/jr7Pj8rD2h7jMMnqk9Cn
+w9xK81AiDVAIBzLggJcX7moFM1nmppTsLLPyhKCkZsh6lNg7MQk6ZzcuL2QSwG5t
+QvFYGN/+A4HMDNRE2mzdw7gkWBlIAbMlZBNPv96YySh3SNv1Z2pUDYFUyLvKB7ni
+R1UzEcRrmvdv3uzMjmnnyKLQjngmIJQ/mXJ9PAT+cpkdmd+brjigshd/ox1bav7p
+HwIBAw==
+-----END PUBLIC KEY-----
diff --git a/meta/meta-mediatek/recipes-support/update-engine-sideload/files/update_engine.patch b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/update_engine.patch
new file mode 100644
index 0000000..af502f6
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-engine-sideload/files/update_engine.patch
@@ -0,0 +1,312 @@
+diff --git a/common/platform_constants_android.cc b/common/platform_constants_android.cc
+index 371fe26..ef13058 100644
+--- a/common/platform_constants_android.cc
++++ b/common/platform_constants_android.cc
+@@ -30,7 +30,7 @@ const char kUpdatePayloadPublicKeyPath[] =
+ const char kCACertificatesPath[] = "/system/etc/security/cacerts_google";
+ // No deadline file API support on Android.
+ const char kOmahaResponseDeadlineFile[] = "";
+-const char kNonVolatileDirectory[] = "/data/misc/update_engine";
++const char kNonVolatileDirectory[] = "/var/lib/update_engine";
+ const char kPostinstallMountOptions[] =
+   "context=u:object_r:postinstall_file:s0";
+ 
+diff --git a/hardware_android.cc b/hardware_android.cc
+index 947b13a..0ccb161 100644
+--- a/hardware_android.cc
++++ b/hardware_android.cc
+@@ -22,10 +22,11 @@
+ 
+ #include <algorithm>
+ #include <memory>
+-
++#if 0
+ #include <bootloader.h>
+ 
+ #include <android-base/properties.h>
++#endif
+ #include <base/files/file_util.h>
+ #include <base/strings/stringprintf.h>
+ 
+@@ -34,9 +35,11 @@
+ #include "update_engine/common/utils.h"
+ #include "update_engine/utils_android.h"
+ 
++#if 0
+ using android::base::GetBoolProperty;
+ using android::base::GetIntProperty;
+ using android::base::GetProperty;
++#endif
+ using std::string;
+ 
+ namespace chromeos_update_engine {
+@@ -58,7 +61,7 @@ const char kPropProductManufacturer[] = "ro.product.manufacturer";
+ const char kPropBootHardwareSKU[] = "ro.boot.hardware.sku";
+ const char kPropBootRevision[] = "ro.boot.revision";
+ const char kPropBuildDateUTC[] = "ro.build.date.utc";
+-
++#if 0
+ // Write a recovery command line |message| to the BCB. The arguments to recovery
+ // must be separated by '\n'. An empty string will erase the BCB.
+ bool WriteBootloaderRecoveryMessage(const string& message) {
+@@ -91,7 +94,7 @@ bool WriteBootloaderRecoveryMessage(const string& message) {
+   }
+   return true;
+ }
+-
++#endif
+ }  // namespace
+ 
+ namespace hardware {
+@@ -124,7 +127,7 @@ bool HardwareAndroid::IsOfficialBuild() const {
+   //
+   // In case of a non-bool value, we take the most restrictive option and
+   // assume we are in an official-build.
+-  return GetBoolProperty("ro.secure", true);
++  return true;//GetBoolProperty("ro.secure", true);
+ }
+ 
+ bool HardwareAndroid::IsNormalBootMode() const {
+@@ -132,11 +135,11 @@ bool HardwareAndroid::IsNormalBootMode() const {
+   // update_engine will allow extra developers options, such as providing a
+   // different update URL. In case of error, we assume the build is in
+   // normal-mode.
+-  return !GetBoolProperty("ro.debuggable", false);
++  return true;//!GetBoolProperty("ro.debuggable", false);
+ }
+ 
+ bool HardwareAndroid::AreDevFeaturesEnabled() const {
+-  return !IsNormalBootMode();
++  return false;//!IsNormalBootMode();
+ }
+ 
+ bool HardwareAndroid::IsOOBEEnabled() const {
+@@ -152,19 +155,22 @@ bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const {
+ }
+ 
+ string HardwareAndroid::GetHardwareClass() const {
+-  auto manufacturer = GetProperty(kPropProductManufacturer, "");
+-  auto sku = GetProperty(kPropBootHardwareSKU, "");
+-  auto revision = GetProperty(kPropBootRevision, "");
++  //auto manufacturer = GetProperty(kPropProductManufacturer, "");
++  //auto sku = GetProperty(kPropBootHardwareSKU, "");
++  //auto revision = GetProperty(kPropBootRevision, "");
+ 
+-  return manufacturer + ":" + sku + ":" + revision;
++  //return manufacturer + ":" + sku + ":" + revision;
++  return "manufacturer:sku:revision";
+ }
+ 
+ string HardwareAndroid::GetFirmwareVersion() const {
+-  return GetProperty(kPropBootBootloader, "");
++  //return GetProperty(kPropBootBootloader, "");
++  return "1.0";
+ }
+ 
+ string HardwareAndroid::GetECVersion() const {
+-  return GetProperty(kPropBootBaseband, "");
++  //return GetProperty(kPropBootBaseband, "");
++  return "1.0";
+ }
+ 
+ int HardwareAndroid::GetPowerwashCount() const {
+@@ -174,11 +180,11 @@ int HardwareAndroid::GetPowerwashCount() const {
+ 
+ bool HardwareAndroid::SchedulePowerwash() {
+   LOG(INFO) << "Scheduling a powerwash to BCB.";
+-  return WriteBootloaderRecoveryMessage(kAndroidRecoveryPowerwashCommand);
++  return false;//WriteBootloaderRecoveryMessage(kAndroidRecoveryPowerwashCommand);
+ }
+ 
+ bool HardwareAndroid::CancelPowerwash() {
+-  return WriteBootloaderRecoveryMessage("");
++  return true;//WriteBootloaderRecoveryMessage("");
+ }
+ 
+ bool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const {
+@@ -197,7 +203,8 @@ bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const {
+ }
+ 
+ int64_t HardwareAndroid::GetBuildTimestamp() const {
+-  return GetIntProperty<int64_t>(kPropBuildDateUTC, 0);
++  //return GetIntProperty<int64_t>(kPropBuildDateUTC, 0);
++  return utils::GetIntProperty(kPropBuildDateUTC, 0);
+ }
+ 
+ bool HardwareAndroid::GetFirstActiveOmahaPingSent() const {
+diff --git a/sideload_main.cc b/sideload_main.cc
+index ddb312e..b983534 100644
+--- a/sideload_main.cc
++++ b/sideload_main.cc
+@@ -155,7 +155,7 @@ bool ApplyUpdatePayload(const string& payload,
+ 
+   // During the sideload we don't access the prefs persisted on disk but instead
+   // use a temporary memory storage.
+-  MemoryPrefs prefs;
++  //MemoryPrefs prefs;
+ 
+   std::unique_ptr<BootControlInterface> boot_control =
+       boot_control::CreateBootControl();
+@@ -169,9 +169,21 @@ bool ApplyUpdatePayload(const string& payload,
+     LOG(ERROR) << "Error initializing the HardwareInterface.";
+     return false;
+   }
++  base::FilePath non_volatile_path;
++  if (!hardware->GetNonVolatileDirectory(&non_volatile_path)) {
++    LOG(ERROR) << "Failed to get a non-volatile directory.";
++    return false;
++  }
++  std::unique_ptr<PrefsInterface> prefsIf;
++  Prefs* prefs = new Prefs();
++  if (!prefs->Init(non_volatile_path.Append(kPrefsSubDirectory))) {
++    LOG(ERROR) << "Failed to initialize preferences.";
++    return false;
++  }
++  prefsIf.reset(prefs);
+ 
+   UpdateAttempterAndroid update_attempter(
+-      &sideload_daemon_state, &prefs, boot_control.get(), hardware.get());
++      &sideload_daemon_state, prefsIf.get(), boot_control.get(), hardware.get());
+   update_attempter.Init();
+ 
+   TEST_AND_RETURN_FALSE(update_attempter.ApplyPayload(
+diff --git a/update_attempter_android.cc b/update_attempter_android.cc
+index 04ccb18..60e96ff 100644
+--- a/update_attempter_android.cc
++++ b/update_attempter_android.cc
+@@ -21,7 +21,7 @@
+ #include <memory>
+ #include <utility>
+ 
+-#include <android-base/properties.h>
++//#include <android-base/properties.h>
+ #include <base/bind.h>
+ #include <base/logging.h>
+ #include <base/strings/string_number_conversions.h>
+@@ -29,7 +29,7 @@
+ #include <brillo/data_encoding.h>
+ #include <brillo/message_loops/message_loop.h>
+ #include <brillo/strings/string_utils.h>
+-#include <log/log_safetynet.h>
++//#include <log/log_safetynet.h>
+ 
+ #include "update_engine/common/constants.h"
+ #include "update_engine/common/error_code_utils.h"
+@@ -449,7 +449,7 @@ void UpdateAttempterAndroid::ProcessingDone(const ActionProcessor* processor,
+ 
+     case ErrorCode::kPayloadTimestampError:
+       // SafetyNet logging, b/36232423
+-      android_errorWriteLog(0x534e4554, "36232423");
++      //android_errorWriteLog(0x534e4554, "36232423");
+       break;
+ 
+     default:
+@@ -599,7 +599,10 @@ void UpdateAttempterAndroid::SetStatusAndNotify(UpdateStatus status) {
+   status_ = status;
+   size_t payload_size =
+       install_plan_.payloads.empty() ? 0 : install_plan_.payloads[0].size;
+-  UpdateEngineStatus status_to_send = {.status = status_,
++  UpdateEngineStatus status_to_send = {.last_checked_time = 0,
++				       .status = status_,
++                                       .current_version = "n",
++				       .current_system_version = "n",
+                                        .progress = download_progress_,
+                                        .new_size_bytes = payload_size};
+ 
+@@ -764,8 +767,8 @@ void UpdateAttempterAndroid::UpdatePrefsAndReportUpdateMetricsOnReboot() {
+   string current_boot_id;
+   TEST_AND_RETURN(utils::GetBootId(&current_boot_id));
+   // Example: [ro.build.version.incremental]: [4292972]
+-  string current_version =
+-      android::base::GetProperty("ro.build.version.incremental", "");
++  string current_version = "4292972";
++      //android::base::GetProperty("ro.build.version.incremental", "");
+   TEST_AND_RETURN(!current_version.empty());
+ 
+   // If there's no record of previous version (e.g. due to a data wipe), we
+diff --git a/update_manager/policy.h b/update_manager/policy.h
+index b60c4da..a57cfa6 100644
+--- a/update_manager/policy.h
++++ b/update_manager/policy.h
+@@ -202,7 +202,7 @@ class Policy {
+                                           std::string*, R*,
+                                           Args...) const) const {
+     std::string class_name = PolicyName() + "::";
+-
++#if 0
+     if (reinterpret_cast<typeof(&Policy::UpdateCheckAllowed)>(
+             policy_method) == &Policy::UpdateCheckAllowed)
+       return class_name + "UpdateCheckAllowed";
+@@ -223,6 +223,7 @@ class Policy {
+       return class_name + "P2PEnabledChanged";
+ 
+     NOTREACHED();
++#endif
+     return class_name + "(unknown)";
+   }
+ 
+diff --git a/utils_android.cc b/utils_android.cc
+index 393e65a..40c06b7 100644
+--- a/utils_android.cc
++++ b/utils_android.cc
+@@ -15,8 +15,10 @@
+ //
+ 
+ #include "update_engine/utils_android.h"
++#include <base/strings/string_number_conversions.h>
++#include <brillo/key_value_store.h>
+ 
+-#include <fs_mgr.h>
++#include <fstab/fstab.h>
+ 
+ using std::string;
+ 
+@@ -40,6 +42,9 @@ static struct fstab* OpenFSTab() {
+ namespace utils {
+ 
+ bool DeviceForMountPoint(const string& mount_point, base::FilePath* device) {
++ //*device = base::FilePath("/dev/disk/by-partlabel/misc");
++ // return true;
++#if 1
+   struct fstab* fstab;
+   struct fstab_rec* record;
+ 
+@@ -58,8 +63,26 @@ bool DeviceForMountPoint(const string& mount_point, base::FilePath* device) {
+   *device = base::FilePath(record->blk_device);
+   fs_mgr_free_fstab(fstab);
+   return true;
++#endif
+ }
+ 
++int64_t GetIntProperty(const string& key, int64_t default_value){
++    brillo::KeyValueStore store;
++    if(store.Load(base::FilePath("/etc/update_engine/build.prop"))){
++        std::string result;
++        int64_t result_value;
++        if(!store.GetString(key, &result)){
++            LOG(ERROR) << "Error get key" << key;
++            return default_value;
++        }
++        if(base::StringToInt64(result,&result_value)){
++            return result_value;
++        }
++    }else{
++         LOG(ERROR) << "Error opening property file.";
++    }
++    return default_value;
++}
+ }  // namespace utils
+ 
+ }  // namespace chromeos_update_engine
+diff --git a/utils_android.h b/utils_android.h
+index 18dd8ab..9692610 100644
+--- a/utils_android.h
++++ b/utils_android.h
+@@ -30,6 +30,7 @@ namespace utils {
+ bool DeviceForMountPoint(const std::string& mount_point,
+                          base::FilePath* device);
+ 
++int64_t GetIntProperty(const std::string& key, int64_t default_value);
+ }  // namespace utils
+ 
+ }  // namespace chromeos_update_engine
diff --git a/meta/meta-mediatek/recipes-support/update-engine-sideload/update-engine-sideload.bb b/meta/meta-mediatek/recipes-support/update-engine-sideload/update-engine-sideload.bb
new file mode 100644
index 0000000..2dcd158
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-engine-sideload/update-engine-sideload.bb
@@ -0,0 +1,53 @@
+DESCRIPTION = "update engine sideload"
+
+HOMEPAGE = "https://github.com/coreos/update_engine"
+
+LICENSE = "BSD-3-Clause"
+LIC_FILES_CHKSUM = "file://MODULE_LICENSE_APACHE2;md5=d41d8cd98f00b204e9800998ecf8427e"
+
+
+FILESEXTRAPATHS_prepend := "${THISDIR}:"
+SRC_URI = "git://android.googlesource.com/platform/system/update_engine;protocol=https;name=platform/system/update_engine;destsuffix=platform/system/update_engine/ \
+           file://update_engine.patch \
+           file://file_descriptor.patch \
+           file://erase_partition.patch \
+"
+
+SRCREV_platform/system/update_engine = "e5d1deba6185ba59da0345cb970d2d60c312ab76"
+
+S = "${WORKDIR}/platform/system/update_engine"
+
+CPPFLAGS += "-I${WORKDIR}/platform/system/"
+
+
+DEPENDS += "bzip2 glog gtest openssl curl gflags protobuf dbus-glib bootctrl platform-libs-updateengine protobuf-native ${@bb.utils.contains("BOOTDEV_TYPE", "nand", "nandapi", "", d)}"
+
+
+inherit autotools pkgconfig
+
+# Avoid QA Issue: 'Files/directories were installed but not shipped'
+INSANE_SKIP_${PN} += "installed-vs-shipped dev-deps"
+
+EXTRA_OEMAKE = "PACKAGE_ARCH=${PACKAGE_ARCH} LIBDIR=${WORKDIR}/recipe-sysroot/usr/lib64 BOOTDEV_TYPE=${BOOTDEV_TYPE}"
+
+FILES_${PN} += "/etc/update_engine"
+FILES_${PN} += "/etc/update_engine/update-payload-key.pub.pem"
+FILES_${PN} += "/var/lib/update_engine"
+
+EXTRA_OECONF = "${@bb.utils.contains("BOOTDEV_TYPE", "nand", "--enable-nand=yes", "", d)}"
+
+do_configure_prepend() {
+    install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/update-engine-sideload/files/makefiles/Makefile.am ${S}/Makefile.am
+    install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/update-engine-sideload/files/makefiles/configure.ac ${S}/configure.ac
+    install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/update-engine-sideload/files/update-payload-key.pub.pem ${S}/update-payload-key.pub.pem
+    install -m 0755 ${TOPDIR}/../meta/meta-mediatek/recipes-support/update-engine-sideload/files/buildinfo.sh ${S}/buildinfo.sh
+}
+
+do_install_append() {
+    install -d ${D}${libdir}
+    install -d ${D}/etc/update_engine
+    install -d ${D}/var/lib/update_engine
+    install -m 0644 ${S}/update-payload-key.pub.pem ${D}/etc/update_engine/update-payload-key.pub.pem
+    sh ${S}/buildinfo.sh > ${D}/etc/update_engine/build.prop
+    cp ${S}/update_engine.conf ${D}/etc/update_engine/
+}
diff --git a/meta/meta-mediatek/recipes-support/update-verifier/files/Makefile.am b/meta/meta-mediatek/recipes-support/update-verifier/files/Makefile.am
new file mode 100644
index 0000000..b26b317
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-verifier/files/Makefile.am
@@ -0,0 +1,31 @@
+# update_verifier.bin
+bin_PROGRAMS = update_verifier
+
+
+update_verifier_SOURCES = \
+	otautil/rangeset.cpp \
+	update_verifier/update_verifier_main.cpp \
+	update_verifier/update_verifier.cpp
+
+update_verifier_CFLAGS = \
+   -Wall \
+   -Werror \
+   -std=c++11
+
+INCLUDES = \
+	-I$(top_srcdir)/otautil/include \
+	-I$(top_srcdir)/update_verifier/include
+
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/otautil \
+	-I$(top_srcdir)/update_verifier
+
+update_verifier_CPPFLAGS = \
+	-Ibootctrl \
+	-I$(top_srcdir)
+
+if NAND
+update_verifier_LDADD = -llog -lpthread -lbase -lbootctrl -lnandapi
+else
+update_verifier_LDADD = -llog -lpthread -lbase -lbootctrl
+endif
diff --git a/meta/meta-mediatek/recipes-support/update-verifier/files/configure.ac b/meta/meta-mediatek/recipes-support/update-verifier/files/configure.ac
new file mode 100644
index 0000000..ca5e7e1
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-verifier/files/configure.ac
@@ -0,0 +1,14 @@
+AC_INIT(update-verifier, 1.0)
+AM_INIT_AUTOMAKE(foreign)
+
+# check boot type
+AC_ARG_ENABLE(nand, AC_HELP_STRING([--enable-nand],
+                                [enable nand support]),
+                                        [enable_nand=${enableval}])
+
+AM_CONDITIONAL(NAND, test "$enable_nand" = "yes")
+
+AM_MAINTAINER_MODE
+AC_PROG_CXX
+LT_INIT
+AC_OUTPUT([Makefile])
diff --git a/meta/meta-mediatek/recipes-support/update-verifier/files/update-verifier.patch b/meta/meta-mediatek/recipes-support/update-verifier/files/update-verifier.patch
new file mode 100644
index 0000000..3150c93
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-verifier/files/update-verifier.patch
@@ -0,0 +1,317 @@
+diff --git a/update_verifier/include/update_verifier/update_verifier.h b/update_verifier/include/update_verifier/update_verifier.h
+index 16b394e98..c700a170b 100644
+--- a/update_verifier/include/update_verifier/update_verifier.h
++++ b/update_verifier/include/update_verifier/update_verifier.h
+@@ -22,3 +22,4 @@ int update_verifier(int argc, char** argv);
+ 
+ // Exposed for testing purpose.
+ bool verify_image(const std::string& care_map_name);
++std::string GetProperty(const char* strProperity);
+diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp
+index 92d931371..45b12cb9f 100644
+--- a/update_verifier/update_verifier.cpp
++++ b/update_verifier/update_verifier.cpp
+@@ -34,9 +34,6 @@
+  * The current slot will be marked as having booted successfully if the
+  * verifier reaches the end after the verification.
+  */
+-
+-#include "update_verifier/update_verifier.h"
+-
+ #include <dirent.h>
+ #include <errno.h>
+ #include <fcntl.h>
+@@ -52,20 +49,22 @@
+ #include <android-base/file.h>
+ #include <android-base/logging.h>
+ #include <android-base/parseint.h>
+-#include <android-base/properties.h>
+ #include <android-base/strings.h>
+ #include <android-base/unique_fd.h>
+-#include <android/hardware/boot/1.0/IBootControl.h>
+-#include <cutils/android_reboot.h>
++#include <hardware/boot_control.h>
++#include <hardware/hardware.h>
++#include <sys/reboot.h>
+ 
+ #include "otautil/rangeset.h"
++#include "update_verifier/update_verifier.h"
+ 
+-using android::sp;
+-using android::hardware::boot::V1_0::IBootControl;
+-using android::hardware::boot::V1_0::BoolResult;
+-using android::hardware::boot::V1_0::CommandResult;
++using std::string;
+ 
+ // Find directories in format of "/sys/block/dm-X".
++
++extern const hw_module_t HAL_MODULE_INFO_SYM;
++boot_control_module_t* module;
++
+ static int dm_name_filter(const dirent* de) {
+   if (android::base::StartsWith(de->d_name, "dm-")) {
+     return 1;
+@@ -73,6 +72,72 @@ static int dm_name_filter(const dirent* de) {
+   return 0;
+ }
+ 
++#define COMMAND_LINE_PATH "/proc/cmdline"
++#define COMMAND_LINE_SIZE 2048
++
++std::string GetProperty(const char* strProperity)
++{
++    int fd, err, slot;
++    ssize_t size = COMMAND_LINE_SIZE, sz;
++    char *buf, *ptr;
++    char *str;
++    std::string res;
++
++    fd = open(COMMAND_LINE_PATH, O_RDONLY);
++    if (fd < 0) {
++        err = -errno;
++        LOG(ERROR) << "error reading commandline\n";
++        return NULL;
++    }
++    ptr = buf = (char *)malloc(size);
++    if (!buf) {
++        err = -errno;
++        LOG(ERROR) << "Error allocating memory";
++        close(fd);
++        return NULL;
++    }
++    do {
++        sz = read(fd, buf, size);
++        if (sz == 0) {
++            break;
++        } else if (sz < 0) {
++            if (errno == EINTR) {
++                continue;
++            }
++            err = -errno;
++			      LOG(ERROR) << "Error reading file";
++            free(ptr);
++            close(fd);
++            return NULL;
++        }
++        size -= sz;
++        buf += sz;
++    } while(size > 0);
++    
++    str = strstr((char *)ptr, strProperity);
++    if (!str) {
++        err = -EIO;
++        LOG(ERROR) << "Cannot find %s in kernel commandline" <<  strProperity;
++        free(ptr);
++        close(fd);
++        return NULL;
++    }
++    str += strlen(strProperity);
++    while(1){
++        str++;
++        if(((*str == ' ') || (*str == '\0' ) || (*str == '\n'))){
++            break;
++		    }else{
++			      res.push_back(*str);
++		    }
++    }
++    LOG(INFO) << "Find kernel commandline" << res;
++    
++    free(ptr);
++    close(fd);
++    return res;
++}
++
+ static bool read_blocks(const std::string& partition, const std::string& range_str) {
+   if (partition != "system" && partition != "vendor" && partition != "product") {
+     LOG(ERROR) << "Invalid partition name \"" << partition << "\"";
+@@ -103,6 +168,7 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
+       PLOG(WARNING) << "Failed to read " << path;
+     } else {
+       std::string dm_block_name = android::base::Trim(content);
++      	LOG(ERROR) << "dm_block_name namelist[n]->d_name " << dm_block_name << namelist[n]->d_name;
+ #ifdef BOARD_AVB_ENABLE
+       // AVB is using 'vroot' for the root block device but we're expecting 'system'.
+       if (dm_block_name == "vroot") {
+@@ -135,7 +201,7 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
+     LOG(ERROR) << "Error parsing RangeSet string " << range_str;
+     return false;
+   }
+-
++  
+   // RangeSet::Split() splits the ranges into multiple groups with same number of blocks (except for
+   // the last group).
+   size_t thread_num = std::thread::hardware_concurrency() ?: 4;
+@@ -147,13 +213,27 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
+       android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(dm_block_device.c_str(), O_RDONLY)));
+       if (fd.get() == -1) {
+         PLOG(ERROR) << "Error reading " << dm_block_device << " for partition " << partition;
+-        return false;
++        //return false;
++        std::string path = "/sys/class/block/dm-0/dev";
++        std::string content;
++        if (!android::base::ReadFileToString(path, &content)) {
++             PLOG(WARNING) << "Failed to read " << path;
++        } else {
++            std::string dev_name = android::base::Trim(content);
++            	dm_block_device = DEV_PATH + dev_name;
++        }
+       }
+-
++      fd.reset(open(dm_block_device.c_str(), O_RDONLY));
++      if (fd.get() == -1) {
++      	  PLOG(ERROR) << "Error reading " << dm_block_device << " for partition " << partition;
++          return false;
++      }
++      
+       static constexpr size_t kBlockSize = 4096;
+       std::vector<uint8_t> buf(1024 * kBlockSize);
+ 
+       size_t block_count = 0;
++
+       for (const auto& range : group) {
+         size_t range_start = range.first;
+         size_t range_end = range.second;
+@@ -161,7 +241,7 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
+           PLOG(ERROR) << "lseek to " << range_start << " failed";
+           return false;
+         }
+-
++        PLOG(ERROR) << "range start " << range_start << " range_end " << range_end;
+         size_t remain = (range_end - range_start) * kBlockSize;
+         while (remain > 0) {
+           size_t to_read = std::min(remain, 1024 * kBlockSize);
+@@ -173,7 +253,7 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
+         }
+         block_count += (range_end - range_start);
+       }
+-      LOG(INFO) << "Finished reading " << block_count << " blocks on " << dm_block_device;
++      LOG(ERROR) << "Finished reading " << block_count << " blocks on " << dm_block_device ;
+       return true;
+     };
+ 
+@@ -238,10 +318,13 @@ bool verify_image(const std::string& care_map_name) {
+ }
+ 
+ static int reboot_device() {
+-  if (android_reboot(ANDROID_RB_RESTART2, 0, nullptr) == -1) {
+-    LOG(ERROR) << "Failed to reboot.";
+-    return -1;
+-  }
++  //if (android_reboot(ANDROID_RB_RESTART2, 0, nullptr) == -1) {
++  //  LOG(ERROR) << "Failed to reboot.";
++  //  return -1;
++  //}
++  //system("reboot");
++  reboot(RB_AUTOBOOT);
++  
+   while (true) pause();
+ }
+ 
+@@ -250,23 +333,45 @@ int update_verifier(int argc, char** argv) {
+     LOG(INFO) << "Started with arg " << i << ": " << argv[i];
+   }
+ 
+-  sp<IBootControl> module = IBootControl::getService();
++  /*************    Bootctrl Init  Start  *************/
++  //sp<IBootControl> module = IBootControl::getService();
++  const hw_module_t* hw_module;
++  int ret;
++
++  // For update_engine_sideload, we simulate the hw_get_module() by accessing it
++  // from the current process directly.
++  hw_module = &HAL_MODULE_INFO_SYM;
++  ret = 0;
++  if (!hw_module ||
++      strcmp(BOOT_CONTROL_HARDWARE_MODULE_ID, hw_module->id) != 0) {
++    ret = -EINVAL;
++  }
++  if (ret != 0) {
++    LOG(ERROR) << "Error loading boot_control HAL implementation.";
++    return false;
++  }
++
++  module = reinterpret_cast<boot_control_module_t*>(
++      const_cast<hw_module_t*>(hw_module));
++  module->init(module);
++
+   if (module == nullptr) {
+     LOG(ERROR) << "Error getting bootctrl module.";
+     return reboot_device();
+   }
++  /*************    Bootctrl Init  End  *************/
+ 
+-  uint32_t current_slot = module->getCurrentSlot();
+-  BoolResult is_successful = module->isSlotMarkedSuccessful(current_slot);
++  uint32_t current_slot = module->getCurrentSlot(module);
++  //bool is_successful = module->isSlotMarkedSuccessful(current_slot);
++  bool is_successful = module->isSlotMarkedSuccessful(module, current_slot);
+   LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful="
+-            << static_cast<int32_t>(is_successful);
++            << is_successful;
+ 
+-  if (is_successful == BoolResult::FALSE) {
++  if (is_successful == false) {
+     // The current slot has not booted successfully.
+-
+ #if defined(PRODUCT_SUPPORTS_VERITY) || defined(BOARD_AVB_ENABLE)
+     bool skip_verification = false;
+-    std::string verity_mode = android::base::GetProperty("ro.boot.veritymode", "");
++    std::string verity_mode = GetProperty("androidboot.veritymode");
+     if (verity_mode.empty()) {
+       // With AVB it's possible to disable verification entirely and
+       // in this case ro.boot.veritymode is empty.
+@@ -290,7 +395,7 @@ int update_verifier(int argc, char** argv) {
+     }
+ 
+     if (!skip_verification) {
+-      static constexpr auto CARE_MAP_FILE = "/data/ota_package/care_map.txt";
++	    static constexpr auto CARE_MAP_FILE = "/var/lib/update_engine/care_map.txt";
+       if (!verify_image(CARE_MAP_FILE)) {
+         LOG(ERROR) << "Failed to verify all blocks in care map file.";
+         return reboot_device();
+@@ -300,10 +405,10 @@ int update_verifier(int argc, char** argv) {
+     LOG(WARNING) << "dm-verity not enabled; marking without verification.";
+ #endif
+ 
+-    CommandResult cr;
+-    module->markBootSuccessful([&cr](CommandResult result) { cr = result; });
+-    if (!cr.success) {
+-      LOG(ERROR) << "Error marking booted successfully: " << cr.errMsg;
++    //bool cr = module->markBootSuccessful([&cr](CommandResult result) { cr = result; });
++    int cr = module->markBootSuccessful(module);
++    if (cr < 0) {
++      LOG(ERROR) << "Error marking booted successfully: " << cr;
+       return reboot_device();
+     }
+     LOG(INFO) << "Marked slot " << current_slot << " as booted successfully.";
+diff --git a/update_verifier/update_verifier_main.cpp b/update_verifier/update_verifier_main.cpp
+index a86203bfb..c22582341 100644
+--- a/update_verifier/update_verifier_main.cpp
++++ b/update_verifier/update_verifier_main.cpp
+@@ -19,12 +19,15 @@
+ #include <string>
+ 
+ #include <android-base/logging.h>
+-#include <android-base/properties.h>
++//#include <android-base/properties.h>
+ 
+ #include "update_verifier/update_verifier.h"
+ 
+ int main(int argc, char** argv) {
+-  std::string s = android::base::GetProperty("ro.boot.slot_suffix", "");
++  //std::string s = android::base::GetProperty("ro.boot.slot_suffix", "");
++  
++  
++  std::string s = GetProperty("androidboot.slot");
+ 
+   if (s.empty()) {
+     return 0;  // non-A/B update device, so we quit
+@@ -32,7 +35,7 @@ int main(int argc, char** argv) {
+ 
+   // Set up update_verifier logging to be written to kmsg; because we may not have Logd during
+   // boot time.
+-  android::base::InitLogging(argv, &android::base::KernelLogger);
++  android::base::InitLogging(argv, android::base::StderrLogger);
+ 
+   return update_verifier(argc, argv);
+ }
diff --git a/meta/meta-mediatek/recipes-support/update-verifier/files/update_verifier.service b/meta/meta-mediatek/recipes-support/update-verifier/files/update_verifier.service
new file mode 100644
index 0000000..732bc33
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-verifier/files/update_verifier.service
@@ -0,0 +1,10 @@
+[Unit]

+Description=update_verifier

+

+[Service]

+ExecStart=/usr/bin/update_verifier

+Type=simple

+

+[Install]

+Alias=upgrade

+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/meta/meta-mediatek/recipes-support/update-verifier/update-verifier.bb b/meta/meta-mediatek/recipes-support/update-verifier/update-verifier.bb
new file mode 100644
index 0000000..7f6751e
--- /dev/null
+++ b/meta/meta-mediatek/recipes-support/update-verifier/update-verifier.bb
@@ -0,0 +1,42 @@
+inherit pkgconfig autotools
+DESCRIPTION = "ab update verifier"
+
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://NOTICE;md5=9645f39e9db895a4aa6e02cb57294595"
+
+DEPENDS += "bootctrl platform-libs-common ${@bb.utils.contains("BOOTDEV_TYPE", "nand", "nandapi", "", d)}"
+
+INHIBIT_PACKAGE_STRIP = "1"
+inherit systemd
+
+FILESEXTRAPATHS_prepend := "${THISDIR}:"
+SRC_URI = " \
+	git://android.googlesource.com/platform/bootable/recovery;name=platform/bootable/recovery;destsuffix=platform/bootable/recovery \
+	file://update-verifier.patch \
+	file://Makefile.am \
+	file://configure.ac \
+	file://update_verifier.service \
+"
+
+SRCREV_platform/bootable/recovery = "896de5423db1ec3824797e11199a08be20b02d1d"
+
+S = "${WORKDIR}/platform/bootable/recovery"
+
+CPPFLAGS += "${@bb.utils.contains("BOARD_AVB_ENABLE","true", "-DBOARD_AVB_ENABLE","",d)}"
+
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE_${PN} = "update_verifier.service"
+FILES_${PN} += "${systemd_unitdir}/system/update_verifier.service"
+
+EXTRA_OECONF = "${@bb.utils.contains("BOOTDEV_TYPE", "nand", "--enable-nand=yes", "", d)}"
+
+do_configure_prepend() {
+	install -m 0755 ${WORKDIR}/Makefile.am ${S}/Makefile.am
+	install -m 0755 ${WORKDIR}/configure.ac ${S}/configure.ac
+	install -m 0755 ${WORKDIR}/update_verifier.service ${S}/update_verifier.service
+}
+
+do_install_append() {
+	install -d ${D}${systemd_unitdir}/system
+	install -m 0755 ${S}/update_verifier.service ${D}${systemd_unitdir}/system
+}