Merge pull request #1517 from satheesbalya-arm/sb1_2607_mcd_reg

Console: Use callee-saved registers
diff --git a/Makefile b/Makefile
index 533cb8a..18c4873 100644
--- a/Makefile
+++ b/Makefile
@@ -45,7 +45,7 @@
 # Do not check the coding style on imported library files or documentation files
 INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
 					include/lib/libfdt		\
-					include/lib/stdlib,		\
+					include/lib/libc,		\
 					$(wildcard include/lib/*)))
 INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
 					include/lib,			\
@@ -53,7 +53,7 @@
 LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
 					lib/compiler-rt			\
 					lib/libfdt%			\
-					lib/stdlib,			\
+					lib/libc,			\
 					$(wildcard lib/*)))
 ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
 					lib				\
@@ -172,7 +172,7 @@
 ASFLAGS_aarch32		=	$(march32-directive)
 ASFLAGS_aarch64		=	-march=armv8-a
 
-CPPFLAGS		=	${DEFINES} ${INCLUDES} -nostdinc		\
+CPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc		\
 				-Wmissing-include-dirs -Werror
 ASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
 				-D__ASSEMBLY__ -ffreestanding 			\
@@ -198,7 +198,7 @@
 # Common sources and include directories
 ################################################################################
 include lib/compiler-rt/compiler-rt.mk
-include lib/stdlib/stdlib.mk
+include lib/libc/libc.mk
 
 BL_COMMON_SOURCES	+=	common/bl_common.c			\
 				common/tf_log.c				\
@@ -211,8 +211,7 @@
 				plat/common/plat_log_common.c		\
 				plat/common/${ARCH}/plat_common.c	\
 				plat/common/${ARCH}/platform_helpers.S	\
-				${COMPILER_RT_SRCS}			\
-				${STDLIB_SRCS}
+				${COMPILER_RT_SRCS}
 
 INCLUDES		+=	-Iinclude				\
 				-Iinclude/bl1				\
@@ -506,6 +505,9 @@
 FIPTOOLPATH		?=	tools/fiptool
 FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
 
+# Variables for use with ROMLIB
+ROMLIBPATH		?=	lib/romlib
+
 ################################################################################
 # Include BL specific makefiles
 ################################################################################
@@ -574,6 +576,7 @@
 $(eval $(call assert_boolean,SPIN_ON_BL1_EXIT))
 $(eval $(call assert_boolean,TRUSTED_BOARD_BOOT))
 $(eval $(call assert_boolean,USE_COHERENT_MEM))
+$(eval $(call assert_boolean,USE_ROMLIB))
 $(eval $(call assert_boolean,USE_TBBR_DEFS))
 $(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY))
 $(eval $(call assert_boolean,BL2_AT_EL3))
@@ -626,6 +629,7 @@
 $(eval $(call add_define,SPIN_ON_BL1_EXIT))
 $(eval $(call add_define,TRUSTED_BOARD_BOOT))
 $(eval $(call add_define,USE_COHERENT_MEM))
+$(eval $(call add_define,USE_ROMLIB))
 $(eval $(call add_define,USE_TBBR_DEFS))
 $(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY))
 $(eval $(call add_define,BL2_AT_EL3))
@@ -670,6 +674,9 @@
     CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
 endif
 
+$(eval $(call MAKE_LIB_DIRS))
+$(eval $(call MAKE_LIB,c))
+
 # Expand build macros for the different images
 ifeq (${NEED_BL1},yes)
 $(eval $(call MAKE_BL,1))
@@ -734,6 +741,7 @@
 	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
 	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
 	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
+	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
 
 realclean distclean:
 	@echo "  REALCLEAN"
@@ -741,11 +749,12 @@
 	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
 	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
 	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
+	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
 
 checkcodebase:		locate-checkpatch
 	@echo "  CHECKING STYLE"
 	@if test -d .git ; then						\
-		git ls-files | grep -E -v 'libfdt|stdlib|docs|\.md' |	\
+		git ls-files | grep -E -v 'libfdt|libc|docs|\.md' |	\
 		while read GIT_FILE ;					\
 		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
 		done ;							\
@@ -753,7 +762,7 @@
 		 find . -type f -not -iwholename "*.git*"		\
 		 -not -iwholename "*build*"				\
 		 -not -iwholename "*libfdt*"				\
-		 -not -iwholename "*stdlib*"				\
+		 -not -iwholename "*libc*"				\
 		 -not -iwholename "*docs*"				\
 		 -not -iwholename "*.md"				\
 		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
@@ -819,6 +828,10 @@
 ${FIPTOOL}:
 	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH}
 
+.PHONY: libraries
+romlib.bin: libraries
+	${Q}${MAKE} BUILD_PLAT=${BUILD_PLAT} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all
+
 cscope:
 	@echo "  CSCOPE"
 	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
diff --git a/bl1/aarch32/bl1_exceptions.S b/bl1/aarch32/bl1_exceptions.S
index 1540542..9b001a9 100644
--- a/bl1/aarch32/bl1_exceptions.S
+++ b/bl1/aarch32/bl1_exceptions.S
@@ -116,7 +116,7 @@
 
 	/* Turn on the MMU */
 	mov	r0, #DISABLE_DCACHE
-	bl	enable_mmu_secure
+	bl	enable_mmu_svc_mon
 
 	/* Enable the data cache. */
 	ldcopr	r9, SCTLR
diff --git a/bl1/bl1.mk b/bl1/bl1.mk
index 41ee1a7..9a46a34 100644
--- a/bl1/bl1.mk
+++ b/bl1/bl1.mk
@@ -14,9 +14,7 @@
 				lib/el3_runtime/${ARCH}/context_mgmt.c	\
 				plat/common/plat_bl1_common.c		\
 				plat/common/${ARCH}/platform_up_stack.S \
-				${MBEDTLS_COMMON_SOURCES}		\
-				${MBEDTLS_CRYPTO_SOURCES}		\
-				${MBEDTLS_X509_SOURCES}
+				${MBEDTLS_SOURCES}
 
 ifeq (${ARCH},aarch64)
 BL1_SOURCES		+=	lib/el3_runtime/aarch64/context.S
diff --git a/bl2/bl2.mk b/bl2/bl2.mk
index a856fb7..7e33703 100644
--- a/bl2/bl2.mk
+++ b/bl2/bl2.mk
@@ -8,9 +8,7 @@
 				bl2/${ARCH}/bl2_arch_setup.c		\
 				lib/locks/exclusive/${ARCH}/spinlock.S	\
 				plat/common/${ARCH}/platform_up_stack.S	\
-				${MBEDTLS_COMMON_SOURCES}               \
-				${MBEDTLS_CRYPTO_SOURCES}		\
-				${MBEDTLS_X509_SOURCES}
+				${MBEDTLS_SOURCES}
 
 ifeq (${ARCH},aarch64)
 BL2_SOURCES		+=	common/aarch64/early_exceptions.S
diff --git a/bl2u/bl2u_main.c b/bl2u/bl2u_main.c
index a7e3fb9..b29d57e 100644
--- a/bl2u/bl2u_main.c
+++ b/bl2u/bl2u_main.c
@@ -17,6 +17,7 @@
 #include <platform_def.h>
 #include <stdint.h>
 
+
 /*******************************************************************************
  * This function is responsible to:
  * Load SCP_BL2U if platform has defined SCP_BL2U_BASE
diff --git a/common/tf_snprintf.c b/common/tf_snprintf.c
index a99ab7a..6df1377 100644
--- a/common/tf_snprintf.c
+++ b/common/tf_snprintf.c
@@ -8,6 +8,17 @@
 #include <platform.h>
 #include <stdarg.h>
 
+static void string_print(char **s, size_t n, size_t *chars_printed,
+			 const char *str)
+{
+	while (*str) {
+		if (*chars_printed < n)
+			*(*s)++ = *str;
+		(*chars_printed)++;
+		str++;
+	}
+}
+
 static void unsigned_dec_print(char **s, size_t n, size_t *chars_printed,
 			       unsigned int unum)
 {
@@ -32,6 +43,7 @@
  * The following type specifiers are supported:
  *
  * %d or %i - signed decimal format
+ * %s - string format
  * %u - unsigned decimal format
  *
  * The function panics on all other formats specifiers.
@@ -45,6 +57,7 @@
 	va_list args;
 	int num;
 	unsigned int unum;
+	char *str;
 	size_t chars_printed = 0;
 
 	if (n == 1) {
@@ -79,6 +92,10 @@
 
 				unsigned_dec_print(&s, n, &chars_printed, unum);
 				break;
+			case 's':
+				str = va_arg(args, char *);
+				string_print(&s, n, &chars_printed, str);
+				break;
 			case 'u':
 				unum = va_arg(args, unsigned int);
 				unsigned_dec_print(&s, n, &chars_printed, unum);
diff --git a/drivers/arm/cci/cci.c b/drivers/arm/cci/cci.c
index 71b65f4..a6ee77a 100644
--- a/drivers/arm/cci/cci.c
+++ b/drivers/arm/cci/cci.c
@@ -147,7 +147,7 @@
 	 * Wait for the completion of the write to the Snoop Control Register
 	 * before testing the change_pending bit
 	 */
-	dmbish();
+	dsbish();
 
 	/* Wait for the dust to settle down */
 	while (mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT)
@@ -174,7 +174,7 @@
 	 * Wait for the completion of the write to the Snoop Control Register
 	 * before testing the change_pending bit
 	 */
-	dmbish();
+	dsbish();
 
 	/* Wait for the dust to settle down */
 	while (mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT)
diff --git a/drivers/auth/mbedtls/mbedtls_common.c b/drivers/auth/mbedtls/mbedtls_common.c
index c048d00..64dc196 100644
--- a/drivers/auth/mbedtls/mbedtls_common.c
+++ b/drivers/auth/mbedtls/mbedtls_common.c
@@ -5,6 +5,7 @@
  */
 
 #include <debug.h>
+#include <stdlib.h>
 
 /* mbed TLS headers */
 #include <mbedtls/memory_buffer_alloc.h>
@@ -23,6 +24,12 @@
 #endif
 static unsigned char heap[MBEDTLS_HEAP_SIZE];
 
+static void cleanup(void)
+{
+	ERROR("EXIT from BL2\n");
+	panic();
+}
+
 /*
  * mbed TLS initialization function
  */
@@ -31,6 +38,9 @@
 	static int ready;
 
 	if (!ready) {
+		if (atexit(cleanup))
+			panic();
+
 		/* Initialize the mbed TLS heap */
 		mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
 
diff --git a/drivers/auth/mbedtls/mbedtls_common.mk b/drivers/auth/mbedtls/mbedtls_common.mk
index a5d19e6..71c496e 100644
--- a/drivers/auth/mbedtls/mbedtls_common.mk
+++ b/drivers/auth/mbedtls/mbedtls_common.mk
@@ -13,22 +13,86 @@
   $(error Error: MBEDTLS_DIR not set)
 endif
 
-INCLUDES		+=	-I${MBEDTLS_DIR}/include		\
-				-Iinclude/drivers/auth/mbedtls
+MBEDTLS_INC		=	-I${MBEDTLS_DIR}/include
+INCLUDES		+=     -Iinclude/drivers/auth/mbedtls
 
 # Specify mbed TLS configuration file
 MBEDTLS_CONFIG_FILE	:=	"<mbedtls_config.h>"
 $(eval $(call add_define,MBEDTLS_CONFIG_FILE))
 
-MBEDTLS_COMMON_SOURCES	:=	drivers/auth/mbedtls/mbedtls_common.c	\
-				$(addprefix ${MBEDTLS_DIR}/library/,	\
-				asn1parse.c 				\
-				asn1write.c 				\
-				memory_buffer_alloc.c			\
-				oid.c 					\
-				platform.c 				\
-				platform_util.c				\
-				rsa_internal.c				\
-				)
+MBEDTLS_SOURCES	+=		drivers/auth/mbedtls/mbedtls_common.c
+
+
+LIBMBEDTLS_SRCS		:= $(addprefix ${MBEDTLS_DIR}/library/,	\
+					asn1parse.c 				\
+					asn1write.c 				\
+					memory_buffer_alloc.c			\
+					oid.c 					\
+					platform.c 				\
+					platform_util.c				\
+					bignum.c				\
+					md.c					\
+					md_wrap.c				\
+					pk.c 					\
+					pk_wrap.c 				\
+					pkparse.c 				\
+					pkwrite.c 				\
+					sha256.c            			\
+					sha512.c            			\
+					ecdsa.c					\
+					ecp_curves.c				\
+					ecp.c					\
+					rsa.c					\
+					rsa_internal.c				\
+					x509.c 					\
+					x509_crt.c 				\
+					)
+
+# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
+# algorithm to use. If the variable is not defined, select it based on algorithm
+# used for key generation `KEY_ALG`. If `KEY_ALG` is not defined or is
+# defined to `rsa`/`rsa_1_5`, then set the variable to `rsa`.
+ifeq (${TF_MBEDTLS_KEY_ALG},)
+    ifeq (${KEY_ALG}, ecdsa)
+        TF_MBEDTLS_KEY_ALG		:=	ecdsa
+    else
+        TF_MBEDTLS_KEY_ALG		:=	rsa
+    endif
+endif
+
+# If MBEDTLS_KEY_ALG build flag is defined use it to set TF_MBEDTLS_KEY_ALG for
+# backward compatibility
+ifdef MBEDTLS_KEY_ALG
+    ifeq (${ERROR_DEPRECATED},1)
+        $(error "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG")
+    endif
+    $(warning "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG")
+    TF_MBEDTLS_KEY_ALG	:= ${MBEDTLS_KEY_ALG}
+endif
+
+ifeq (${HASH_ALG}, sha384)
+    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA384
+else ifeq (${HASH_ALG}, sha512)
+   TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA512
+else
+    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA256
+endif
+
+ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
+    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_ECDSA
+else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
+    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_RSA
+else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
+    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_RSA_AND_ECDSA
+else
+    $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
+endif
+
+# Needs to be set to drive mbed TLS configuration correctly
+$(eval $(call add_define,TF_MBEDTLS_KEY_ALG_ID))
+$(eval $(call add_define,TF_MBEDTLS_HASH_ALG_ID))
+
+
+$(eval $(call MAKE_LIB,mbedtls))
 
 endif
diff --git a/drivers/auth/mbedtls/mbedtls_crypto.mk b/drivers/auth/mbedtls/mbedtls_crypto.mk
index 6b15e71..2a9fbbf 100644
--- a/drivers/auth/mbedtls/mbedtls_crypto.mk
+++ b/drivers/auth/mbedtls/mbedtls_crypto.mk
@@ -6,86 +6,6 @@
 
 include drivers/auth/mbedtls/mbedtls_common.mk
 
-# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
-# algorithm to use. If the variable is not defined, select it based on algorithm
-# used for key generation `KEY_ALG`. If `KEY_ALG` is not defined or is
-# defined to `rsa`/`rsa_1_5`, then set the variable to `rsa`.
-ifeq (${TF_MBEDTLS_KEY_ALG},)
-    ifeq (${KEY_ALG}, ecdsa)
-        TF_MBEDTLS_KEY_ALG		:=	ecdsa
-    else
-        TF_MBEDTLS_KEY_ALG		:=	rsa
-    endif
-endif
+MBEDTLS_SOURCES	+=		drivers/auth/mbedtls/mbedtls_crypto.c
 
-# If MBEDTLS_KEY_ALG build flag is defined use it to set TF_MBEDTLS_KEY_ALG for
-# backward compatibility
-ifdef MBEDTLS_KEY_ALG
-    ifeq (${ERROR_DEPRECATED},1)
-        $(error "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG")
-    endif
-    $(warning "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG")
-    TF_MBEDTLS_KEY_ALG	:= ${MBEDTLS_KEY_ALG}
-endif
-
-MBEDTLS_CRYPTO_SOURCES		:=	drivers/auth/mbedtls/mbedtls_crypto.c	\
-					$(addprefix ${MBEDTLS_DIR}/library/,	\
-					bignum.c				\
-					md.c					\
-					md_wrap.c				\
-					pk.c 					\
-					pk_wrap.c 				\
-					pkparse.c 				\
-					pkwrite.c 				\
-					)
-
-ifeq (${HASH_ALG}, sha384)
-    MBEDTLS_CRYPTO_SOURCES  += \
-					$(addprefix ${MBEDTLS_DIR}/library/,	\
-						sha256.c            \
-						sha512.c            \
-					)
-    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA384
-else ifeq (${HASH_ALG}, sha512)
-    MBEDTLS_CRYPTO_SOURCES  += \
-					$(addprefix ${MBEDTLS_DIR}/library/,	\
-						sha256.c            \
-						sha512.c            \
-					)
-    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA512
-else
-    MBEDTLS_CRYPTO_SOURCES  += \
-					$(addprefix ${MBEDTLS_DIR}/library/,	\
-						sha256.c            \
-					)
-    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA256
-endif
-
-# Key algorithm specific files
-MBEDTLS_ECDSA_CRYPTO_SOURCES	+=	$(addprefix ${MBEDTLS_DIR}/library/,	\
-					ecdsa.c					\
-					ecp_curves.c				\
-					ecp.c					\
-					)
-
-MBEDTLS_RSA_CRYPTO_SOURCES	+=	$(addprefix ${MBEDTLS_DIR}/library/,	\
-					rsa.c					\
-					)
-
-ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
-    MBEDTLS_CRYPTO_SOURCES	+=	$(MBEDTLS_ECDSA_CRYPTO_SOURCES)
-    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_ECDSA
-else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
-    MBEDTLS_CRYPTO_SOURCES	+=	$(MBEDTLS_RSA_CRYPTO_SOURCES)
-    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_RSA
-else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
-    MBEDTLS_CRYPTO_SOURCES	+=	$(MBEDTLS_ECDSA_CRYPTO_SOURCES)
-    MBEDTLS_CRYPTO_SOURCES	+=	$(MBEDTLS_RSA_CRYPTO_SOURCES)
-    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_RSA_AND_ECDSA
-else
-    $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
-endif
 
-# Needs to be set to drive mbed TLS configuration correctly
-$(eval $(call add_define,TF_MBEDTLS_KEY_ALG_ID))
-$(eval $(call add_define,TF_MBEDTLS_HASH_ALG_ID))
diff --git a/drivers/auth/mbedtls/mbedtls_x509.mk b/drivers/auth/mbedtls/mbedtls_x509.mk
index a6f72e6..a0557e2 100644
--- a/drivers/auth/mbedtls/mbedtls_x509.mk
+++ b/drivers/auth/mbedtls/mbedtls_x509.mk
@@ -6,8 +6,4 @@
 
 include drivers/auth/mbedtls/mbedtls_common.mk
 
-MBEDTLS_X509_SOURCES	:=	drivers/auth/mbedtls/mbedtls_x509_parser.c	\
-				$(addprefix ${MBEDTLS_DIR}/library/,		\
-				x509.c 						\
-				x509_crt.c 					\
-				)
+MBEDTLS_SOURCES	+=	drivers/auth/mbedtls/mbedtls_x509_parser.c
diff --git a/drivers/emmc/emmc.c b/drivers/emmc/emmc.c
deleted file mode 100644
index 92d1e87..0000000
--- a/drivers/emmc/emmc.c
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Defines a simple and generic interface to access eMMC device.
- */
-
-#include <arch_helpers.h>
-#include <assert.h>
-#include <debug.h>
-#include <emmc.h>
-#include <errno.h>
-#include <string.h>
-#include <utils.h>
-
-static const emmc_ops_t *ops;
-static unsigned int emmc_ocr_value;
-static emmc_csd_t emmc_csd;
-static unsigned int emmc_flags;
-
-static int is_cmd23_enabled(void)
-{
-	return (!!(emmc_flags & EMMC_FLAG_CMD23));
-}
-
-static int emmc_device_state(void)
-{
-	emmc_cmd_t cmd;
-	int ret;
-
-	do {
-		zeromem(&cmd, sizeof(emmc_cmd_t));
-		cmd.cmd_idx = EMMC_CMD13;
-		cmd.cmd_arg = EMMC_FIX_RCA << RCA_SHIFT_OFFSET;
-		cmd.resp_type = EMMC_RESPONSE_R1;
-		ret = ops->send_cmd(&cmd);
-		assert(ret == 0);
-		assert((cmd.resp_data[0] & STATUS_SWITCH_ERROR) == 0);
-		/* Ignore improbable errors in release builds */
-		(void)ret;
-	} while ((cmd.resp_data[0] & STATUS_READY_FOR_DATA) == 0);
-	return EMMC_GET_STATE(cmd.resp_data[0]);
-}
-
-static void emmc_set_ext_csd(unsigned int ext_cmd, unsigned int value)
-{
-	emmc_cmd_t cmd;
-	int ret, state;
-
-	zeromem(&cmd, sizeof(emmc_cmd_t));
-	cmd.cmd_idx = EMMC_CMD6;
-	cmd.cmd_arg = EXTCSD_WRITE_BYTES | EXTCSD_CMD(ext_cmd) |
-		      EXTCSD_VALUE(value) | 1;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-
-	/* wait to exit PRG state */
-	do {
-		state = emmc_device_state();
-	} while (state == EMMC_STATE_PRG);
-	/* Ignore improbable errors in release builds */
-	(void)ret;
-}
-
-static void emmc_set_ios(int clk, int bus_width)
-{
-	int ret;
-
-	/* set IO speed & IO bus width */
-	if (emmc_csd.spec_vers == 4)
-		emmc_set_ext_csd(CMD_EXTCSD_BUS_WIDTH, bus_width);
-	ret = ops->set_ios(clk, bus_width);
-	assert(ret == 0);
-	/* Ignore improbable errors in release builds */
-	(void)ret;
-}
-
-static int emmc_enumerate(int clk, int bus_width)
-{
-	emmc_cmd_t cmd;
-	int ret, state;
-
-	ops->init();
-
-	/* CMD0: reset to IDLE */
-	zeromem(&cmd, sizeof(emmc_cmd_t));
-	cmd.cmd_idx = EMMC_CMD0;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-
-	while (1) {
-		/* CMD1: get OCR register */
-		zeromem(&cmd, sizeof(emmc_cmd_t));
-		cmd.cmd_idx = EMMC_CMD1;
-		cmd.cmd_arg = OCR_SECTOR_MODE | OCR_VDD_MIN_2V7 |
-			      OCR_VDD_MIN_1V7;
-		cmd.resp_type = EMMC_RESPONSE_R3;
-		ret = ops->send_cmd(&cmd);
-		assert(ret == 0);
-		emmc_ocr_value = cmd.resp_data[0];
-		if (emmc_ocr_value & OCR_POWERUP)
-			break;
-	}
-
-	/* CMD2: Card Identification */
-	zeromem(&cmd, sizeof(emmc_cmd_t));
-	cmd.cmd_idx = EMMC_CMD2;
-	cmd.resp_type = EMMC_RESPONSE_R2;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-
-	/* CMD3: Set Relative Address */
-	zeromem(&cmd, sizeof(emmc_cmd_t));
-	cmd.cmd_idx = EMMC_CMD3;
-	cmd.cmd_arg = EMMC_FIX_RCA << RCA_SHIFT_OFFSET;
-	cmd.resp_type = EMMC_RESPONSE_R1;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-
-	/* CMD9: CSD Register */
-	zeromem(&cmd, sizeof(emmc_cmd_t));
-	cmd.cmd_idx = EMMC_CMD9;
-	cmd.cmd_arg = EMMC_FIX_RCA << RCA_SHIFT_OFFSET;
-	cmd.resp_type = EMMC_RESPONSE_R2;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-	memcpy(&emmc_csd, &cmd.resp_data, sizeof(cmd.resp_data));
-
-	/* CMD7: Select Card */
-	zeromem(&cmd, sizeof(emmc_cmd_t));
-	cmd.cmd_idx = EMMC_CMD7;
-	cmd.cmd_arg = EMMC_FIX_RCA << RCA_SHIFT_OFFSET;
-	cmd.resp_type = EMMC_RESPONSE_R1;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-	/* wait to TRAN state */
-	do {
-		state = emmc_device_state();
-	} while (state != EMMC_STATE_TRAN);
-
-	emmc_set_ios(clk, bus_width);
-	return ret;
-}
-
-size_t emmc_read_blocks(int lba, uintptr_t buf, size_t size)
-{
-	emmc_cmd_t cmd;
-	int ret;
-
-	assert((ops != 0) &&
-	       (ops->read != 0) &&
-	       ((buf & EMMC_BLOCK_MASK) == 0) &&
-	       ((size & EMMC_BLOCK_MASK) == 0));
-
-	inv_dcache_range(buf, size);
-	ret = ops->prepare(lba, buf, size);
-	assert(ret == 0);
-
-	if (is_cmd23_enabled()) {
-		zeromem(&cmd, sizeof(emmc_cmd_t));
-		/* set block count */
-		cmd.cmd_idx = EMMC_CMD23;
-		cmd.cmd_arg = size / EMMC_BLOCK_SIZE;
-		cmd.resp_type = EMMC_RESPONSE_R1;
-		ret = ops->send_cmd(&cmd);
-		assert(ret == 0);
-
-		zeromem(&cmd, sizeof(emmc_cmd_t));
-		cmd.cmd_idx = EMMC_CMD18;
-	} else {
-		if (size > EMMC_BLOCK_SIZE)
-			cmd.cmd_idx = EMMC_CMD18;
-		else
-			cmd.cmd_idx = EMMC_CMD17;
-	}
-	if ((emmc_ocr_value & OCR_ACCESS_MODE_MASK) == OCR_BYTE_MODE)
-		cmd.cmd_arg = lba * EMMC_BLOCK_SIZE;
-	else
-		cmd.cmd_arg = lba;
-	cmd.resp_type = EMMC_RESPONSE_R1;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-
-	ret = ops->read(lba, buf, size);
-	assert(ret == 0);
-
-	/* wait buffer empty */
-	emmc_device_state();
-
-	if (is_cmd23_enabled() == 0) {
-		if (size > EMMC_BLOCK_SIZE) {
-			zeromem(&cmd, sizeof(emmc_cmd_t));
-			cmd.cmd_idx = EMMC_CMD12;
-			ret = ops->send_cmd(&cmd);
-			assert(ret == 0);
-		}
-	}
-	/* Ignore improbable errors in release builds */
-	(void)ret;
-	return size;
-}
-
-size_t emmc_write_blocks(int lba, const uintptr_t buf, size_t size)
-{
-	emmc_cmd_t cmd;
-	int ret;
-
-	assert((ops != 0) &&
-	       (ops->write != 0) &&
-	       ((buf & EMMC_BLOCK_MASK) == 0) &&
-	       ((size & EMMC_BLOCK_MASK) == 0));
-
-	clean_dcache_range(buf, size);
-	ret = ops->prepare(lba, buf, size);
-	assert(ret == 0);
-
-	if (is_cmd23_enabled()) {
-		/* set block count */
-		zeromem(&cmd, sizeof(emmc_cmd_t));
-		cmd.cmd_idx = EMMC_CMD23;
-		cmd.cmd_arg = size / EMMC_BLOCK_SIZE;
-		cmd.resp_type = EMMC_RESPONSE_R1;
-		ret = ops->send_cmd(&cmd);
-		assert(ret == 0);
-
-		zeromem(&cmd, sizeof(emmc_cmd_t));
-		cmd.cmd_idx = EMMC_CMD25;
-	} else {
-		zeromem(&cmd, sizeof(emmc_cmd_t));
-		if (size > EMMC_BLOCK_SIZE)
-			cmd.cmd_idx = EMMC_CMD25;
-		else
-			cmd.cmd_idx = EMMC_CMD24;
-	}
-	if ((emmc_ocr_value & OCR_ACCESS_MODE_MASK) == OCR_BYTE_MODE)
-		cmd.cmd_arg = lba * EMMC_BLOCK_SIZE;
-	else
-		cmd.cmd_arg = lba;
-	cmd.resp_type = EMMC_RESPONSE_R1;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-
-	ret = ops->write(lba, buf, size);
-	assert(ret == 0);
-
-	/* wait buffer empty */
-	emmc_device_state();
-
-	if (is_cmd23_enabled() == 0) {
-		if (size > EMMC_BLOCK_SIZE) {
-			zeromem(&cmd, sizeof(emmc_cmd_t));
-			cmd.cmd_idx = EMMC_CMD12;
-			ret = ops->send_cmd(&cmd);
-			assert(ret == 0);
-		}
-	}
-	/* Ignore improbable errors in release builds */
-	(void)ret;
-	return size;
-}
-
-size_t emmc_erase_blocks(int lba, size_t size)
-{
-	emmc_cmd_t cmd;
-	int ret, state;
-
-	assert(ops != 0);
-	assert((size != 0) && ((size % EMMC_BLOCK_SIZE) == 0));
-
-	zeromem(&cmd, sizeof(emmc_cmd_t));
-	cmd.cmd_idx = EMMC_CMD35;
-	cmd.cmd_arg = lba;
-	cmd.resp_type = EMMC_RESPONSE_R1;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-
-	zeromem(&cmd, sizeof(emmc_cmd_t));
-	cmd.cmd_idx = EMMC_CMD36;
-	cmd.cmd_arg = lba + (size / EMMC_BLOCK_SIZE) - 1;
-	cmd.resp_type = EMMC_RESPONSE_R1;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-
-	zeromem(&cmd, sizeof(emmc_cmd_t));
-	cmd.cmd_idx = EMMC_CMD38;
-	cmd.resp_type = EMMC_RESPONSE_R1B;
-	ret = ops->send_cmd(&cmd);
-	assert(ret == 0);
-
-	/* wait to TRAN state */
-	do {
-		state = emmc_device_state();
-	} while (state != EMMC_STATE_TRAN);
-	/* Ignore improbable errors in release builds */
-	(void)ret;
-	return size;
-}
-
-static inline void emmc_rpmb_enable(void)
-{
-	emmc_set_ext_csd(CMD_EXTCSD_PARTITION_CONFIG,
-			PART_CFG_BOOT_PARTITION1_ENABLE |
-			PART_CFG_PARTITION1_ACCESS);
-}
-
-static inline void emmc_rpmb_disable(void)
-{
-	emmc_set_ext_csd(CMD_EXTCSD_PARTITION_CONFIG,
-			PART_CFG_BOOT_PARTITION1_ENABLE);
-}
-
-size_t emmc_rpmb_read_blocks(int lba, uintptr_t buf, size_t size)
-{
-	size_t size_read;
-
-	emmc_rpmb_enable();
-	size_read = emmc_read_blocks(lba, buf, size);
-	emmc_rpmb_disable();
-	return size_read;
-}
-
-size_t emmc_rpmb_write_blocks(int lba, const uintptr_t buf, size_t size)
-{
-	size_t size_written;
-
-	emmc_rpmb_enable();
-	size_written = emmc_write_blocks(lba, buf, size);
-	emmc_rpmb_disable();
-	return size_written;
-}
-
-size_t emmc_rpmb_erase_blocks(int lba, size_t size)
-{
-	size_t size_erased;
-
-	emmc_rpmb_enable();
-	size_erased = emmc_erase_blocks(lba, size);
-	emmc_rpmb_disable();
-	return size_erased;
-}
-
-void emmc_init(const emmc_ops_t *ops_ptr, int clk, int width,
-	       unsigned int flags)
-{
-	assert((ops_ptr != 0) &&
-	       (ops_ptr->init != 0) &&
-	       (ops_ptr->send_cmd != 0) &&
-	       (ops_ptr->set_ios != 0) &&
-	       (ops_ptr->prepare != 0) &&
-	       (ops_ptr->read != 0) &&
-	       (ops_ptr->write != 0) &&
-	       (clk != 0) &&
-	       ((width == EMMC_BUS_WIDTH_1) ||
-		(width == EMMC_BUS_WIDTH_4) ||
-		(width == EMMC_BUS_WIDTH_8) ||
-		(width == EMMC_BUS_WIDTH_DDR_4) ||
-		(width == EMMC_BUS_WIDTH_DDR_8)));
-	ops = ops_ptr;
-	emmc_flags = flags;
-
-	emmc_enumerate(clk, width);
-}
diff --git a/drivers/marvell/comphy/phy-comphy-cp110.c b/drivers/marvell/comphy/phy-comphy-cp110.c
index 8b78280..2b1770f 100644
--- a/drivers/marvell/comphy/phy-comphy-cp110.c
+++ b/drivers/marvell/comphy/phy-comphy-cp110.c
@@ -18,7 +18,7 @@
 
 /* #define DEBUG_COMPHY */
 #ifdef DEBUG_COMPHY
-#define debug(format...) printf(format)
+#define debug(format...) tf_printf(format)
 #else
 #define debug(format, arg...)
 #endif
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 0c9ec10..bf87612 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -24,7 +24,7 @@
 static const struct mmc_ops *ops;
 static unsigned int mmc_ocr_value;
 static struct mmc_csd_emmc mmc_csd;
-static unsigned char mmc_ext_csd[512] __aligned(4);
+static unsigned char mmc_ext_csd[512] __aligned(16);
 static unsigned int mmc_flags;
 static struct mmc_device_info *mmc_dev_info;
 static unsigned int rca;
@@ -221,7 +221,7 @@
 	unsigned int speed_idx;
 	unsigned int nb_blocks;
 	unsigned int freq_unit;
-	int ret;
+	int ret = 0;
 	struct mmc_csd_sd_v2 *csd_sd_v2;
 
 	switch (mmc_dev_info->mmc_dev_type) {
@@ -363,8 +363,6 @@
 {
 	int ret;
 
-	mdelay(1);
-
 	/* CMD0: reset to IDLE */
 	ret = mmc_send_cmd(MMC_CMD(0), 0, 0, NULL);
 	if (ret != 0) {
@@ -413,14 +411,16 @@
 
 	mmc_reset_to_idle();
 
-	/* CMD8: Send Interface Condition Command */
-	ret = mmc_send_cmd(MMC_CMD(8), VHS_2_7_3_6_V | CMD8_CHECK_PATTERN,
-			   MMC_RESPONSE_R(7), &resp_data[0]);
-
-	if ((ret == 0) && ((resp_data[0] & 0xffU) == CMD8_CHECK_PATTERN)) {
-		ret = sd_send_op_cond();
-	} else {
+	if (mmc_dev_info->mmc_dev_type == MMC_IS_EMMC) {
 		ret = mmc_send_op_cond();
+	} else {
+		/* CMD8: Send Interface Condition Command */
+		ret = mmc_send_cmd(MMC_CMD(8), VHS_2_7_3_6_V | CMD8_CHECK_PATTERN,
+				   MMC_RESPONSE_R(7), &resp_data[0]);
+
+		if ((ret == 0) && ((resp_data[0] & 0xffU) == CMD8_CHECK_PATTERN)) {
+			ret = sd_send_op_cond();
+		}
 	}
 	if (ret != 0) {
 		return ret;
@@ -473,15 +473,15 @@
 		}
 	} while (ret != MMC_STATE_TRAN);
 
-	ret = mmc_fill_device_info();
+	ret = mmc_set_ios(clk, bus_width);
 	if (ret != 0) {
 		return ret;
 	}
 
-	return mmc_set_ios(clk, bus_width);
+	return mmc_fill_device_info();
 }
 
-size_t mmc_read_blocks(unsigned int lba, uintptr_t buf, size_t size)
+size_t mmc_read_blocks(int lba, uintptr_t buf, size_t size)
 {
 	int ret;
 	unsigned int cmd_idx, cmd_arg;
@@ -548,7 +548,7 @@
 	return size;
 }
 
-size_t mmc_write_blocks(unsigned int lba, const uintptr_t buf, size_t size)
+size_t mmc_write_blocks(int lba, const uintptr_t buf, size_t size)
 {
 	int ret;
 	unsigned int cmd_idx, cmd_arg;
@@ -615,7 +615,7 @@
 	return size;
 }
 
-size_t mmc_erase_blocks(unsigned int lba, size_t size)
+size_t mmc_erase_blocks(int lba, size_t size)
 {
 	int ret;
 
@@ -661,7 +661,7 @@
 			PART_CFG_BOOT_PARTITION1_ENABLE);
 }
 
-size_t mmc_rpmb_read_blocks(unsigned int lba, uintptr_t buf, size_t size)
+size_t mmc_rpmb_read_blocks(int lba, uintptr_t buf, size_t size)
 {
 	size_t size_read;
 
@@ -672,7 +672,7 @@
 	return size_read;
 }
 
-size_t mmc_rpmb_write_blocks(unsigned int lba, const uintptr_t buf, size_t size)
+size_t mmc_rpmb_write_blocks(int lba, const uintptr_t buf, size_t size)
 {
 	size_t size_written;
 
@@ -683,7 +683,7 @@
 	return size_written;
 }
 
-size_t mmc_rpmb_erase_blocks(unsigned int lba, size_t size)
+size_t mmc_rpmb_erase_blocks(int lba, size_t size)
 {
 	size_t size_erased;
 
diff --git a/drivers/partition/partition.c b/drivers/partition/partition.c
index e2b4683..5a338b8 100644
--- a/drivers/partition/partition.c
+++ b/drivers/partition/partition.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -24,7 +24,7 @@
 
 	VERBOSE("Partition table with %d entries:\n", num);
 	for (i = 0; i < num; i++) {
-		len = snprintf(name, EFI_NAMELEN, "%s", list.list[i].name);
+		len = tf_snprintf(name, EFI_NAMELEN, "%s", list.list[i].name);
 		for (j = 0; j < EFI_NAMELEN - len - 1; j++) {
 			name[len + j] = ' ';
 		}
diff --git a/drivers/st/clk/stm32mp1_clk.c b/drivers/st/clk/stm32mp1_clk.c
index 7dff98b..1dc08d8 100644
--- a/drivers/st/clk/stm32mp1_clk.c
+++ b/drivers/st/clk/stm32mp1_clk.c
@@ -1344,7 +1344,7 @@
 	for (i = (enum stm32mp1_pll_id)0; i < _PLL_NB; i++) {
 		char name[12];
 
-		sprintf(name, "st,pll@%d", i);
+		tf_snprintf(name, sizeof(name), "st,pll@%d", i);
 		plloff[i] = fdt_rcc_subnode_offset(name);
 
 		if (!fdt_check_node(plloff[i])) {
diff --git a/drivers/synopsys/emmc/dw_mmc.c b/drivers/synopsys/emmc/dw_mmc.c
index 156c2b4..b0b0a3f 100644
--- a/drivers/synopsys/emmc/dw_mmc.c
+++ b/drivers/synopsys/emmc/dw_mmc.c
@@ -10,8 +10,8 @@
 #include <debug.h>
 #include <delay_timer.h>
 #include <dw_mmc.h>
-#include <emmc.h>
 #include <errno.h>
+#include <mmc.h>
 #include <mmio.h>
 #include <string.h>
 
@@ -107,6 +107,8 @@
 
 #define DWMMC_8BIT_MODE			(1 << 6)
 
+#define DWMMC_ADDRESS_MASK		U(0x0f)
+
 #define TIMEOUT				100000
 
 struct dw_idmac_desc {
@@ -117,13 +119,13 @@
 };
 
 static void dw_init(void);
-static int dw_send_cmd(emmc_cmd_t *cmd);
-static int dw_set_ios(int clk, int width);
+static int dw_send_cmd(struct mmc_cmd *cmd);
+static int dw_set_ios(unsigned int clk, unsigned int width);
 static int dw_prepare(int lba, uintptr_t buf, size_t size);
 static int dw_read(int lba, uintptr_t buf, size_t size);
 static int dw_write(int lba, uintptr_t buf, size_t size);
 
-static const emmc_ops_t dw_mmc_ops = {
+static const struct mmc_ops dw_mmc_ops = {
 	.init		= dw_init,
 	.send_cmd	= dw_send_cmd,
 	.set_ios	= dw_set_ios,
@@ -187,7 +189,7 @@
 	unsigned int data;
 	uintptr_t base;
 
-	assert((dw_params.reg_base & EMMC_BLOCK_MASK) == 0);
+	assert((dw_params.reg_base & MMC_BLOCK_MASK) == 0);
 
 	base = dw_params.reg_base;
 	mmio_write_32(base + DWMMC_PWREN, 1);
@@ -203,7 +205,7 @@
 	mmio_write_32(base + DWMMC_INTMASK, 0);
 	mmio_write_32(base + DWMMC_TMOUT, ~0);
 	mmio_write_32(base + DWMMC_IDINTEN, ~0);
-	mmio_write_32(base + DWMMC_BLKSIZ, EMMC_BLOCK_SIZE);
+	mmio_write_32(base + DWMMC_BLKSIZ, MMC_BLOCK_SIZE);
 	mmio_write_32(base + DWMMC_BYTCNT, 256 * 1024);
 	mmio_write_32(base + DWMMC_DEBNCE, 0x00ffffff);
 	mmio_write_32(base + DWMMC_BMOD, BMOD_SWRESET);
@@ -215,11 +217,11 @@
 	mmio_write_32(base + DWMMC_BMOD, data);
 
 	udelay(100);
-	dw_set_clk(EMMC_BOOT_CLK_RATE);
+	dw_set_clk(MMC_BOOT_CLK_RATE);
 	udelay(100);
 }
 
-static int dw_send_cmd(emmc_cmd_t *cmd)
+static int dw_send_cmd(struct mmc_cmd *cmd)
 {
 	unsigned int op, data, err_mask;
 	uintptr_t base;
@@ -230,22 +232,22 @@
 	base = dw_params.reg_base;
 
 	switch (cmd->cmd_idx) {
-	case EMMC_CMD0:
+	case 0:
 		op = CMD_SEND_INIT;
 		break;
-	case EMMC_CMD12:
+	case 12:
 		op = CMD_STOP_ABORT_CMD;
 		break;
-	case EMMC_CMD13:
+	case 13:
 		op = CMD_WAIT_PRVDATA_COMPLETE;
 		break;
-	case EMMC_CMD8:
-	case EMMC_CMD17:
-	case EMMC_CMD18:
+	case 8:
+	case 17:
+	case 18:
 		op = CMD_DATA_TRANS_EXPECT | CMD_WAIT_PRVDATA_COMPLETE;
 		break;
-	case EMMC_CMD24:
-	case EMMC_CMD25:
+	case 24:
+	case 25:
 		op = CMD_WRITE | CMD_DATA_TRANS_EXPECT |
 		     CMD_WAIT_PRVDATA_COMPLETE;
 		break;
@@ -257,11 +259,11 @@
 	switch (cmd->resp_type) {
 	case 0:
 		break;
-	case EMMC_RESPONSE_R2:
+	case MMC_RESPONSE_R(2):
 		op |= CMD_RESP_EXPECT | CMD_CHECK_RESP_CRC |
 		      CMD_RESP_LEN;
 		break;
-	case EMMC_RESPONSE_R3:
+	case MMC_RESPONSE_R(3):
 		op |= CMD_RESP_EXPECT;
 		break;
 	default:
@@ -307,16 +309,16 @@
 	return 0;
 }
 
-static int dw_set_ios(int clk, int width)
+static int dw_set_ios(unsigned int clk, unsigned int width)
 {
 	switch (width) {
-	case EMMC_BUS_WIDTH_1:
+	case MMC_BUS_WIDTH_1:
 		mmio_write_32(dw_params.reg_base + DWMMC_CTYPE, CTYPE_1BIT);
 		break;
-	case EMMC_BUS_WIDTH_4:
+	case MMC_BUS_WIDTH_4:
 		mmio_write_32(dw_params.reg_base + DWMMC_CTYPE, CTYPE_4BIT);
 		break;
-	case EMMC_BUS_WIDTH_8:
+	case MMC_BUS_WIDTH_8:
 		mmio_write_32(dw_params.reg_base + DWMMC_CTYPE, CTYPE_8BIT);
 		break;
 	default:
@@ -333,12 +335,14 @@
 	int desc_cnt, i, last;
 	uintptr_t base;
 
-	assert(((buf & EMMC_BLOCK_MASK) == 0) &&
-	       ((size % EMMC_BLOCK_SIZE) == 0) &&
+	assert(((buf & DWMMC_ADDRESS_MASK) == 0) &&
+	       ((size % MMC_BLOCK_SIZE) == 0) &&
 	       (dw_params.desc_size > 0) &&
-	       ((dw_params.reg_base & EMMC_BLOCK_MASK) == 0) &&
-	       ((dw_params.desc_base & EMMC_BLOCK_MASK) == 0) &&
-	       ((dw_params.desc_size & EMMC_BLOCK_MASK) == 0));
+	       ((dw_params.reg_base & MMC_BLOCK_MASK) == 0) &&
+	       ((dw_params.desc_base & MMC_BLOCK_MASK) == 0) &&
+	       ((dw_params.desc_size & MMC_BLOCK_MASK) == 0));
+
+	flush_dcache_range(buf, size);
 
 	desc_cnt = (size + DWMMC_DMA_MAX_BUFFER_SIZE - 1) /
 		   DWMMC_DMA_MAX_BUFFER_SIZE;
@@ -367,7 +371,7 @@
 	(desc + last)->des3 = 0;
 
 	mmio_write_32(base + DWMMC_DBADDR, dw_params.desc_base);
-	clean_dcache_range(dw_params.desc_base,
+	flush_dcache_range(dw_params.desc_base,
 			   desc_cnt * DWMMC_DMA_MAX_BUFFER_SIZE);
 
 	return 0;
@@ -383,19 +387,19 @@
 	return 0;
 }
 
-void dw_mmc_init(dw_mmc_params_t *params)
+void dw_mmc_init(dw_mmc_params_t *params, struct mmc_device_info *info)
 {
 	assert((params != 0) &&
-	       ((params->reg_base & EMMC_BLOCK_MASK) == 0) &&
-	       ((params->desc_base & EMMC_BLOCK_MASK) == 0) &&
-	       ((params->desc_size & EMMC_BLOCK_MASK) == 0) &&
+	       ((params->reg_base & MMC_BLOCK_MASK) == 0) &&
+	       ((params->desc_base & MMC_BLOCK_MASK) == 0) &&
+	       ((params->desc_size & MMC_BLOCK_MASK) == 0) &&
 	       (params->desc_size > 0) &&
 	       (params->clk_rate > 0) &&
-	       ((params->bus_width == EMMC_BUS_WIDTH_1) ||
-		(params->bus_width == EMMC_BUS_WIDTH_4) ||
-		(params->bus_width == EMMC_BUS_WIDTH_8)));
+	       ((params->bus_width == MMC_BUS_WIDTH_1) ||
+		(params->bus_width == MMC_BUS_WIDTH_4) ||
+		(params->bus_width == MMC_BUS_WIDTH_8)));
 
 	memcpy(&dw_params, params, sizeof(dw_mmc_params_t));
-	emmc_init(&dw_mmc_ops, params->clk_rate, params->bus_width,
-		  params->flags);
+	mmc_init(&dw_mmc_ops, params->clk_rate, params->bus_width,
+		 params->flags, info);
 }
diff --git a/include/common/romlib.h b/include/common/romlib.h
new file mode 100644
index 0000000..81a6f5c
--- /dev/null
+++ b/include/common/romlib.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef ROMLIB_H_
+
+#define ROMLIB_MAJOR   0
+#define ROMLIB_MINOR   1
+#define ROMLIB_VERSION ((ROMLIB_MAJOR << 8) | ROMLIB_MINOR)
+
+int rom_lib_init(int version);
+
+#endif
diff --git a/include/drivers/emmc.h b/include/drivers/emmc.h
deleted file mode 100644
index 286c014..0000000
--- a/include/drivers/emmc.h
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef __EMMC_H__
-#define __EMMC_H__
-
-#include <stdint.h>
-
-#define EMMC_BLOCK_SIZE			512
-#define EMMC_BLOCK_MASK			(EMMC_BLOCK_SIZE - 1)
-#define EMMC_BOOT_CLK_RATE		(400 * 1000)
-
-#define EMMC_CMD0			0
-#define EMMC_CMD1			1
-#define EMMC_CMD2			2
-#define EMMC_CMD3			3
-#define EMMC_CMD6			6
-#define EMMC_CMD7			7
-#define EMMC_CMD8			8
-#define EMMC_CMD9			9
-#define EMMC_CMD12			12
-#define EMMC_CMD13			13
-#define EMMC_CMD17			17
-#define EMMC_CMD18			18
-#define EMMC_CMD21			21
-#define EMMC_CMD23			23
-#define EMMC_CMD24			24
-#define EMMC_CMD25			25
-#define EMMC_CMD35			35
-#define EMMC_CMD36			36
-#define EMMC_CMD38			38
-
-#define OCR_POWERUP			(1 << 31)
-#define OCR_BYTE_MODE			(0 << 29)
-#define OCR_SECTOR_MODE			(2 << 29)
-#define OCR_ACCESS_MODE_MASK		(3 << 29)
-#define OCR_VDD_MIN_2V7			(0x1ff << 15)
-#define OCR_VDD_MIN_2V0			(0x7f << 8)
-#define OCR_VDD_MIN_1V7			(1 << 7)
-
-#define EMMC_RESPONSE_R1		1
-#define EMMC_RESPONSE_R1B		1
-#define EMMC_RESPONSE_R2		4
-#define EMMC_RESPONSE_R3		1
-#define EMMC_RESPONSE_R4		1
-#define EMMC_RESPONSE_R5		1
-
-#define EMMC_FIX_RCA			6	/* > 1 */
-#define RCA_SHIFT_OFFSET		16
-
-#define CMD_EXTCSD_PARTITION_CONFIG	179
-#define CMD_EXTCSD_BUS_WIDTH		183
-#define CMD_EXTCSD_HS_TIMING		185
-
-#define PART_CFG_BOOT_PARTITION1_ENABLE	(1 << 3)
-#define PART_CFG_PARTITION1_ACCESS	(1 << 0)
-
-/* values in EXT CSD register */
-#define EMMC_BUS_WIDTH_1		0
-#define EMMC_BUS_WIDTH_4		1
-#define EMMC_BUS_WIDTH_8		2
-#define EMMC_BUS_WIDTH_DDR_4		5
-#define EMMC_BUS_WIDTH_DDR_8		6
-#define EMMC_BOOT_MODE_BACKWARD		(0 << 3)
-#define EMMC_BOOT_MODE_HS_TIMING	(1 << 3)
-#define EMMC_BOOT_MODE_DDR		(2 << 3)
-
-#define EXTCSD_SET_CMD			(0 << 24)
-#define EXTCSD_SET_BITS			(1 << 24)
-#define EXTCSD_CLR_BITS			(2 << 24)
-#define EXTCSD_WRITE_BYTES		(3 << 24)
-#define EXTCSD_CMD(x)			(((x) & 0xff) << 16)
-#define EXTCSD_VALUE(x)			(((x) & 0xff) << 8)
-
-#define STATUS_CURRENT_STATE(x)		(((x) & 0xf) << 9)
-#define STATUS_READY_FOR_DATA		(1 << 8)
-#define STATUS_SWITCH_ERROR		(1 << 7)
-#define EMMC_GET_STATE(x)		(((x) >> 9) & 0xf)
-#define EMMC_STATE_IDLE			0
-#define EMMC_STATE_READY		1
-#define EMMC_STATE_IDENT		2
-#define EMMC_STATE_STBY			3
-#define EMMC_STATE_TRAN			4
-#define EMMC_STATE_DATA			5
-#define EMMC_STATE_RCV			6
-#define EMMC_STATE_PRG			7
-#define EMMC_STATE_DIS			8
-#define EMMC_STATE_BTST			9
-#define EMMC_STATE_SLP			10
-
-#define EMMC_FLAG_CMD23			(1 << 0)
-
-typedef struct emmc_cmd {
-	unsigned int	cmd_idx;
-	unsigned int	cmd_arg;
-	unsigned int	resp_type;
-	unsigned int	resp_data[4];
-} emmc_cmd_t;
-
-typedef struct emmc_ops {
-	void (*init)(void);
-	int (*send_cmd)(emmc_cmd_t *cmd);
-	int (*set_ios)(int clk, int width);
-	int (*prepare)(int lba, uintptr_t buf, size_t size);
-	int (*read)(int lba, uintptr_t buf, size_t size);
-	int (*write)(int lba, const uintptr_t buf, size_t size);
-} emmc_ops_t;
-
-typedef struct emmc_csd {
-	unsigned int 	    not_used:		1;
-	unsigned int   	    crc:			7;
-	unsigned int   	    ecc:			2;
-	unsigned int   	    file_format:		2;
-	unsigned int   	    tmp_write_protect:	1;
-	unsigned int   	    perm_write_protect:	1;
-	unsigned int   	    copy:			1;
-	unsigned int   	    file_format_grp:	1;
-
-	unsigned int 		reserved_1:		5;
-	unsigned int 		write_bl_partial:	1;
-	unsigned int 		write_bl_len:		4;
-	unsigned int 		r2w_factor:		3;
-	unsigned int 		default_ecc:		2;
-	unsigned int 		wp_grp_enable:		1;
-
-	unsigned int		wp_grp_size:		5;
-	unsigned int		erase_grp_mult:		5;
-	unsigned int		erase_grp_size:		5;
-	unsigned int		c_size_mult:		3;
-	unsigned int		vdd_w_curr_max:		3;
-	unsigned int		vdd_w_curr_min:		3;
-	unsigned int		vdd_r_curr_max:		3;
-	unsigned int		vdd_r_curr_min:		3;
-	unsigned int		c_size_low:		2;
-
-	unsigned int		c_size_high:		10;
-	unsigned int		reserved_2:		2;
-	unsigned int		dsr_imp:		1;
-	unsigned int		read_blk_misalign:	1;
-	unsigned int		write_blk_misalign:	1;
-	unsigned int		read_bl_partial:	1;
-	unsigned int		read_bl_len:		4;
-	unsigned int		ccc:			12;
-
-	unsigned int		tran_speed:		8;
-	unsigned int		nsac:			8;
-	unsigned int		taac:			8;
-	unsigned int		reserved_3:		2;
-	unsigned int		spec_vers:		4;
-	unsigned int		csd_structure:		2;
-} emmc_csd_t;
-
-size_t emmc_read_blocks(int lba, uintptr_t buf, size_t size);
-size_t emmc_write_blocks(int lba, const uintptr_t buf, size_t size);
-size_t emmc_erase_blocks(int lba, size_t size);
-size_t emmc_rpmb_read_blocks(int lba, uintptr_t buf, size_t size);
-size_t emmc_rpmb_write_blocks(int lba, const uintptr_t buf, size_t size);
-size_t emmc_rpmb_erase_blocks(int lba, size_t size);
-void emmc_init(const emmc_ops_t *ops, int clk, int bus_width,
-	       unsigned int flags);
-
-#endif	/* __EMMC_H__ */
diff --git a/include/drivers/mmc.h b/include/drivers/mmc.h
index 65f4bbd..0a513bd 100644
--- a/include/drivers/mmc.h
+++ b/include/drivers/mmc.h
@@ -208,13 +208,12 @@
 	enum mmc_device_type	mmc_dev_type;	/* Type of MMC */
 };
 
-size_t mmc_read_blocks(unsigned int lba, uintptr_t buf, size_t size);
-size_t mmc_write_blocks(unsigned int lba, const uintptr_t buf, size_t size);
-size_t mmc_erase_blocks(unsigned int lba, size_t size);
-size_t mmc_rpmb_read_blocks(unsigned int lba, uintptr_t buf, size_t size);
-size_t mmc_rpmb_write_blocks(unsigned int lba, const uintptr_t buf,
-			     size_t size);
-size_t mmc_rpmb_erase_blocks(unsigned int lba, size_t size);
+size_t mmc_read_blocks(int lba, uintptr_t buf, size_t size);
+size_t mmc_write_blocks(int lba, const uintptr_t buf, size_t size);
+size_t mmc_erase_blocks(int lba, size_t size);
+size_t mmc_rpmb_read_blocks(int lba, uintptr_t buf, size_t size);
+size_t mmc_rpmb_write_blocks(int lba, const uintptr_t buf, size_t size);
+size_t mmc_rpmb_erase_blocks(int lba, size_t size);
 int mmc_init(const struct mmc_ops *ops_ptr, unsigned int clk,
 	     unsigned int width, unsigned int flags,
 	     struct mmc_device_info *device_info);
diff --git a/include/drivers/synopsys/dw_mmc.h b/include/drivers/synopsys/dw_mmc.h
index 4e6b348..1ec8d1d 100644
--- a/include/drivers/synopsys/dw_mmc.h
+++ b/include/drivers/synopsys/dw_mmc.h
@@ -7,6 +7,8 @@
 #ifndef __DW_MMC_H__
 #define __DW_MMC_H__
 
+#include <mmc.h>
+
 typedef struct dw_mmc_params {
 	uintptr_t	reg_base;
 	uintptr_t	desc_base;
@@ -16,6 +18,6 @@
 	unsigned int	flags;
 } dw_mmc_params_t;
 
-void dw_mmc_init(dw_mmc_params_t *params);
+void dw_mmc_init(dw_mmc_params_t *params, struct mmc_device_info *info);
 
 #endif	/* __DW_MMC_H__ */
diff --git a/include/lib/aarch32/arch.h b/include/lib/aarch32/arch.h
index a536649..6f0949b 100644
--- a/include/lib/aarch32/arch.h
+++ b/include/lib/aarch32/arch.h
@@ -313,6 +313,28 @@
 #define TTBCR_T0SZ_SHIFT	U(0)
 #define TTBCR_T0SZ_MASK		U(0x7)
 
+/*
+ * HTCR definitions
+ */
+#define HTCR_RES1			((U(1) << 31) | (U(1) << 23))
+
+#define HTCR_SH0_NON_SHAREABLE		(U(0x0) << 12)
+#define HTCR_SH0_OUTER_SHAREABLE	(U(0x2) << 12)
+#define HTCR_SH0_INNER_SHAREABLE	(U(0x3) << 12)
+
+#define HTCR_RGN0_OUTER_NC	(U(0x0) << 10)
+#define HTCR_RGN0_OUTER_WBA	(U(0x1) << 10)
+#define HTCR_RGN0_OUTER_WT	(U(0x2) << 10)
+#define HTCR_RGN0_OUTER_WBNA	(U(0x3) << 10)
+
+#define HTCR_RGN0_INNER_NC	(U(0x0) << 8)
+#define HTCR_RGN0_INNER_WBA	(U(0x1) << 8)
+#define HTCR_RGN0_INNER_WT	(U(0x2) << 8)
+#define HTCR_RGN0_INNER_WBNA	(U(0x3) << 8)
+
+#define HTCR_T0SZ_SHIFT		U(0)
+#define HTCR_T0SZ_MASK		U(0x7)
+
 #define MODE_RW_SHIFT		U(0x4)
 #define MODE_RW_MASK		U(0x1)
 #define MODE_RW_32		U(0x1)
@@ -433,6 +455,7 @@
 #define TLBIMVA		p15, 0, c8, c7, 1
 #define TLBIMVAA	p15, 0, c8, c7, 3
 #define TLBIMVAAIS	p15, 0, c8, c3, 3
+#define TLBIMVAHIS	p15, 4, c8, c3, 1
 #define BPIALLIS	p15, 0, c7, c1, 6
 #define BPIALL		p15, 0, c7, c5, 6
 #define ICIALLU		p15, 0, c7, c5, 0
@@ -448,6 +471,8 @@
 #define CLIDR		p15, 1, c0, c0, 1
 #define CSSELR		p15, 2, c0, c0, 0
 #define CCSIDR		p15, 1, c0, c0, 0
+#define HTCR		p15, 4, c2, c0, 2
+#define HMAIR0		p15, 4, c10, c2, 0
 #define DBGOSDLR	p14, 0, c1, c3, 4
 
 /* Debug register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
@@ -487,6 +512,7 @@
 #define CNTVOFF_64	p15, 4, c14
 #define VTTBR_64	p15, 6, c2
 #define CNTPCT_64	p15, 0, c14
+#define HTTBR_64	p15, 4, c2
 
 /* 64 bit GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRm */
 #define ICC_SGI1R_EL1_64	p15, 0, c12
diff --git a/include/lib/aarch32/arch_helpers.h b/include/lib/aarch32/arch_helpers.h
index beae5d0..aa68bcb 100644
--- a/include/lib/aarch32/arch_helpers.h
+++ b/include/lib/aarch32/arch_helpers.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -300,6 +300,7 @@
 DEFINE_TLBIOP_PARAM_FUNC(mva, TLBIMVA)
 DEFINE_TLBIOP_PARAM_FUNC(mvaa, TLBIMVAA)
 DEFINE_TLBIOP_PARAM_FUNC(mvaais, TLBIMVAAIS)
+DEFINE_TLBIOP_PARAM_FUNC(mvahis, TLBIMVAHIS)
 
 /*
  * BPI operation prototypes.
@@ -320,6 +321,10 @@
 #define IS_IN_SECURE() \
 	(GET_NS_BIT(read_scr()) == 0)
 
+#define IS_IN_HYP()	(GET_M32(read_cpsr()) == MODE32_hyp)
+#define IS_IN_SVC()	(GET_M32(read_cpsr()) == MODE32_svc)
+#define IS_IN_MON()	(GET_M32(read_cpsr()) == MODE32_mon)
+#define IS_IN_EL2()	IS_IN_HYP()
  /*
   * If EL3 is AArch32, then secure PL1 and monitor mode correspond to EL3
   */
diff --git a/include/lib/aarch64/arch.h b/include/lib/aarch64/arch.h
index 397013e..c9619f6 100644
--- a/include/lib/aarch64/arch.h
+++ b/include/lib/aarch64/arch.h
@@ -364,7 +364,9 @@
  * TCR defintions
  */
 #define TCR_EL3_RES1		((U(1) << 31) | (U(1) << 23))
+#define TCR_EL2_RES1		((ULL(1) << 31) | (ULL(1) << 23))
 #define TCR_EL1_IPS_SHIFT	U(32)
+#define TCR_EL2_PS_SHIFT	U(16)
 #define TCR_EL3_PS_SHIFT	U(16)
 
 #define TCR_TxSZ_MIN		ULL(16)
diff --git a/include/lib/stdlib/assert.h b/include/lib/libc/assert.h
similarity index 100%
rename from include/lib/stdlib/assert.h
rename to include/lib/libc/assert.h
diff --git a/include/lib/stdlib/inttypes.h b/include/lib/libc/inttypes.h
similarity index 100%
rename from include/lib/stdlib/inttypes.h
rename to include/lib/libc/inttypes.h
diff --git a/include/lib/stdlib/machine/_inttypes.h b/include/lib/libc/machine/_inttypes.h
similarity index 100%
rename from include/lib/stdlib/machine/_inttypes.h
rename to include/lib/libc/machine/_inttypes.h
diff --git a/include/lib/stdlib/machine/_limits.h b/include/lib/libc/machine/_limits.h
similarity index 100%
rename from include/lib/stdlib/machine/_limits.h
rename to include/lib/libc/machine/_limits.h
diff --git a/include/lib/stdlib/machine/_stdint.h b/include/lib/libc/machine/_stdint.h
similarity index 100%
rename from include/lib/stdlib/machine/_stdint.h
rename to include/lib/libc/machine/_stdint.h
diff --git a/include/lib/stdlib/machine/_types.h b/include/lib/libc/machine/_types.h
similarity index 100%
rename from include/lib/stdlib/machine/_types.h
rename to include/lib/libc/machine/_types.h
diff --git a/include/lib/stdlib/machine/endian.h b/include/lib/libc/machine/endian.h
similarity index 100%
rename from include/lib/stdlib/machine/endian.h
rename to include/lib/libc/machine/endian.h
diff --git a/include/lib/stdlib/stdbool.h b/include/lib/libc/stdbool.h
similarity index 100%
rename from include/lib/stdlib/stdbool.h
rename to include/lib/libc/stdbool.h
diff --git a/include/lib/stdlib/stddef.h b/include/lib/libc/stddef.h
similarity index 100%
rename from include/lib/stdlib/stddef.h
rename to include/lib/libc/stddef.h
diff --git a/include/lib/stdlib/stdio.h b/include/lib/libc/stdio.h
similarity index 100%
rename from include/lib/stdlib/stdio.h
rename to include/lib/libc/stdio.h
diff --git a/include/lib/stdlib/stdlib.h b/include/lib/libc/stdlib.h
similarity index 100%
rename from include/lib/stdlib/stdlib.h
rename to include/lib/libc/stdlib.h
diff --git a/include/lib/stdlib/string.h b/include/lib/libc/string.h
similarity index 100%
rename from include/lib/stdlib/string.h
rename to include/lib/libc/string.h
diff --git a/include/lib/stdlib/strings.h b/include/lib/libc/strings.h
similarity index 100%
rename from include/lib/stdlib/strings.h
rename to include/lib/libc/strings.h
diff --git a/include/lib/stdlib/sys/_null.h b/include/lib/libc/sys/_null.h
similarity index 100%
rename from include/lib/stdlib/sys/_null.h
rename to include/lib/libc/sys/_null.h
diff --git a/include/lib/stdlib/sys/_stdint.h b/include/lib/libc/sys/_stdint.h
similarity index 100%
rename from include/lib/stdlib/sys/_stdint.h
rename to include/lib/libc/sys/_stdint.h
diff --git a/include/lib/stdlib/sys/_timespec.h b/include/lib/libc/sys/_timespec.h
similarity index 100%
rename from include/lib/stdlib/sys/_timespec.h
rename to include/lib/libc/sys/_timespec.h
diff --git a/include/lib/stdlib/sys/_types.h b/include/lib/libc/sys/_types.h
similarity index 100%
rename from include/lib/stdlib/sys/_types.h
rename to include/lib/libc/sys/_types.h
diff --git a/include/lib/stdlib/sys/cdefs.h b/include/lib/libc/sys/cdefs.h
similarity index 100%
rename from include/lib/stdlib/sys/cdefs.h
rename to include/lib/libc/sys/cdefs.h
diff --git a/include/lib/stdlib/sys/ctype.h b/include/lib/libc/sys/ctype.h
similarity index 100%
rename from include/lib/stdlib/sys/ctype.h
rename to include/lib/libc/sys/ctype.h
diff --git a/include/lib/stdlib/sys/endian.h b/include/lib/libc/sys/endian.h
similarity index 100%
rename from include/lib/stdlib/sys/endian.h
rename to include/lib/libc/sys/endian.h
diff --git a/include/lib/stdlib/sys/errno.h b/include/lib/libc/sys/errno.h
similarity index 100%
rename from include/lib/stdlib/sys/errno.h
rename to include/lib/libc/sys/errno.h
diff --git a/include/lib/stdlib/sys/limits.h b/include/lib/libc/sys/limits.h
similarity index 100%
rename from include/lib/stdlib/sys/limits.h
rename to include/lib/libc/sys/limits.h
diff --git a/include/lib/stdlib/sys/stdarg.h b/include/lib/libc/sys/stdarg.h
similarity index 100%
rename from include/lib/stdlib/sys/stdarg.h
rename to include/lib/libc/sys/stdarg.h
diff --git a/include/lib/stdlib/sys/stdint.h b/include/lib/libc/sys/stdint.h
similarity index 100%
rename from include/lib/stdlib/sys/stdint.h
rename to include/lib/libc/sys/stdint.h
diff --git a/include/lib/stdlib/sys/timespec.h b/include/lib/libc/sys/timespec.h
similarity index 100%
rename from include/lib/stdlib/sys/timespec.h
rename to include/lib/libc/sys/timespec.h
diff --git a/include/lib/stdlib/sys/types.h b/include/lib/libc/sys/types.h
similarity index 100%
rename from include/lib/stdlib/sys/types.h
rename to include/lib/libc/sys/types.h
diff --git a/include/lib/stdlib/time.h b/include/lib/libc/time.h
similarity index 100%
rename from include/lib/stdlib/time.h
rename to include/lib/libc/time.h
diff --git a/include/lib/stdlib/xlocale/_strings.h b/include/lib/libc/xlocale/_strings.h
similarity index 100%
rename from include/lib/stdlib/xlocale/_strings.h
rename to include/lib/libc/xlocale/_strings.h
diff --git a/include/lib/stdlib/xlocale/_time.h b/include/lib/libc/xlocale/_time.h
similarity index 100%
rename from include/lib/stdlib/xlocale/_time.h
rename to include/lib/libc/xlocale/_time.h
diff --git a/include/lib/xlat_tables/xlat_mmu_helpers.h b/include/lib/xlat_tables/xlat_mmu_helpers.h
index cd42c33..e1d0227 100644
--- a/include/lib/xlat_tables/xlat_mmu_helpers.h
+++ b/include/lib/xlat_tables/xlat_mmu_helpers.h
@@ -67,15 +67,24 @@
 
 #ifdef AARCH32
 /* AArch32 specific translation table API */
+#if !ERROR_DEPRECATED
 void enable_mmu_secure(unsigned int flags);
-
 void enable_mmu_direct(unsigned int flags);
+#endif
+
+void enable_mmu_svc_mon(unsigned int flags);
+void enable_mmu_hyp(unsigned int flags);
+
+void enable_mmu_direct_svc_mon(unsigned int flags);
+void enable_mmu_direct_hyp(unsigned int flags);
 #else
 /* AArch64 specific translation table APIs */
 void enable_mmu_el1(unsigned int flags);
+void enable_mmu_el2(unsigned int flags);
 void enable_mmu_el3(unsigned int flags);
 
 void enable_mmu_direct_el1(unsigned int flags);
+void enable_mmu_direct_el2(unsigned int flags);
 void enable_mmu_direct_el3(unsigned int flags);
 #endif /* AARCH32 */
 
diff --git a/include/lib/xlat_tables/xlat_tables_v2.h b/include/lib/xlat_tables/xlat_tables_v2.h
index 022acce..52c4dc6 100644
--- a/include/lib/xlat_tables/xlat_tables_v2.h
+++ b/include/lib/xlat_tables/xlat_tables_v2.h
@@ -125,6 +125,7 @@
  * library to detect it at runtime.
  */
 #define EL1_EL0_REGIME		1
+#define EL2_REGIME		2
 #define EL3_REGIME		3
 #define EL_REGIME_INVALID	-1
 
diff --git a/include/plat/arm/board/common/board_arm_def.h b/include/plat/arm/board/common/board_arm_def.h
index c3ae564..a388ed9 100644
--- a/include/plat/arm/board/common/board_arm_def.h
+++ b/include/plat/arm/board/common/board_arm_def.h
@@ -71,9 +71,12 @@
 #elif defined(IMAGE_BL32)
 # define PLAT_ARM_MMAP_ENTRIES		8
 # define MAX_XLAT_TABLES		5
-#else
+#elif !USE_ROMLIB
 # define PLAT_ARM_MMAP_ENTRIES		11
 # define MAX_XLAT_TABLES		5
+#else
+# define PLAT_ARM_MMAP_ENTRIES		12
+# define MAX_XLAT_TABLES		6
 #endif
 
 /*
@@ -83,6 +86,18 @@
 #define PLAT_ARM_MAX_BL1_RW_SIZE	0xB000
 
 /*
+ * PLAT_ARM_MAX_ROMLIB_RW_SIZE is define to use a full page
+ */
+
+#if USE_ROMLIB
+#define PLAT_ARM_MAX_ROMLIB_RW_SIZE	0x1000
+#define PLAT_ARM_MAX_ROMLIB_RO_SIZE	0xe000
+#else
+#define PLAT_ARM_MAX_ROMLIB_RW_SIZE	0
+#define PLAT_ARM_MAX_ROMLIB_RO_SIZE	0
+#endif
+
+/*
  * PLAT_ARM_MAX_BL2_SIZE is calculated using the current BL2 debug size plus a
  * little space for growth.
  */
diff --git a/include/plat/arm/common/arm_def.h b/include/plat/arm/common/arm_def.h
index 47f2ac2..5da8cdb 100644
--- a/include/plat/arm/common/arm_def.h
+++ b/include/plat/arm/common/arm_def.h
@@ -268,6 +268,17 @@
 							- BL_COHERENT_RAM_BASE, \
 						MT_DEVICE | MT_RW | MT_SECURE)
 #endif
+#if USE_ROMLIB
+#define ARM_MAP_ROMLIB_CODE		MAP_REGION_FLAT(			\
+						ROMLIB_RO_BASE,			\
+						ROMLIB_RO_LIMIT	- ROMLIB_RO_BASE,\
+						MT_CODE | MT_SECURE)
+
+#define ARM_MAP_ROMLIB_DATA		MAP_REGION_FLAT(			\
+						ROMLIB_RW_BASE,			\
+						ROMLIB_RW_END	- ROMLIB_RW_BASE,\
+						MT_MEMORY | MT_RW | MT_SECURE)
+#endif
 
 /*
  * The max number of regions like RO(code), coherent and data required by
@@ -346,14 +357,23 @@
  ******************************************************************************/
 #define BL1_RO_BASE			PLAT_ARM_TRUSTED_ROM_BASE
 #define BL1_RO_LIMIT			(PLAT_ARM_TRUSTED_ROM_BASE	\
-					 + PLAT_ARM_TRUSTED_ROM_SIZE)
+					 + (PLAT_ARM_TRUSTED_ROM_SIZE - \
+					    PLAT_ARM_MAX_ROMLIB_RO_SIZE))
 /*
  * Put BL1 RW at the top of the Trusted SRAM.
  */
 #define BL1_RW_BASE			(ARM_BL_RAM_BASE +		\
 						ARM_BL_RAM_SIZE -	\
-						PLAT_ARM_MAX_BL1_RW_SIZE)
-#define BL1_RW_LIMIT			(ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)
+						(PLAT_ARM_MAX_BL1_RW_SIZE +\
+						 PLAT_ARM_MAX_ROMLIB_RW_SIZE))
+#define BL1_RW_LIMIT			(ARM_BL_RAM_BASE + 		\
+					    (ARM_BL_RAM_SIZE - PLAT_ARM_MAX_ROMLIB_RW_SIZE))
+
+#define ROMLIB_RO_BASE			BL1_RO_LIMIT
+#define ROMLIB_RO_LIMIT			(PLAT_ARM_TRUSTED_ROM_BASE + PLAT_ARM_TRUSTED_ROM_SIZE)
+
+#define ROMLIB_RW_BASE			(BL1_RW_BASE + PLAT_ARM_MAX_BL1_RW_SIZE)
+#define ROMLIB_RW_END			(ROMLIB_RW_BASE + PLAT_ARM_MAX_ROMLIB_RW_SIZE)
 
 /*******************************************************************************
  * BL2 specific defines.
diff --git a/include/plat/arm/common/plat_arm.h b/include/plat/arm/common/plat_arm.h
index 506bed3..1af4dd1 100644
--- a/include/plat/arm/common/plat_arm.h
+++ b/include/plat/arm/common/plat_arm.h
@@ -72,6 +72,8 @@
 void arm_setup_page_tables(const mmap_region_t bl_regions[],
 			   const mmap_region_t plat_regions[]);
 
+void arm_setup_romlib(void);
+
 #if defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32))
 /*
  * Use this macro to instantiate lock before it is used in below
diff --git a/lib/stdlib/abort.c b/lib/libc/abort.c
similarity index 100%
rename from lib/stdlib/abort.c
rename to lib/libc/abort.c
diff --git a/lib/stdlib/assert.c b/lib/libc/assert.c
similarity index 100%
rename from lib/stdlib/assert.c
rename to lib/libc/assert.c
diff --git a/lib/libc/exit.c b/lib/libc/exit.c
new file mode 100644
index 0000000..b2fde9c
--- /dev/null
+++ b/lib/libc/exit.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stdlib.h>
+
+static void (*exitfun)(void);
+
+void exit(int status)
+{
+	if (exitfun)
+		(*exitfun)();
+	for (;;)
+		;
+}
+
+int atexit(void (*fun)(void))
+{
+	if (exitfun)
+		return -1;
+	exitfun = fun;
+
+	return 0;
+}
diff --git a/lib/stdlib/stdlib.mk b/lib/libc/libc.mk
similarity index 77%
rename from lib/stdlib/stdlib.mk
rename to lib/libc/libc.mk
index 8211623..ded3d74 100644
--- a/lib/stdlib/stdlib.mk
+++ b/lib/libc/libc.mk
@@ -4,7 +4,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
-STDLIB_SRCS	:=	$(addprefix lib/stdlib/,	\
+LIBC_SRCS	:=	$(addprefix lib/libc/,	\
 			abort.c				\
 			assert.c			\
 			exit.c				\
@@ -21,5 +21,5 @@
 			subr_prf.c			\
 			timingsafe_bcmp.c)
 
-INCLUDES	+=	-Iinclude/lib/stdlib		\
-			-Iinclude/lib/stdlib/sys
+INCLUDES	+=	-Iinclude/lib/libc		\
+			-Iinclude/lib/libc/sys
diff --git a/lib/stdlib/mem.c b/lib/libc/mem.c
similarity index 100%
rename from lib/stdlib/mem.c
rename to lib/libc/mem.c
diff --git a/lib/stdlib/printf.c b/lib/libc/printf.c
similarity index 100%
rename from lib/stdlib/printf.c
rename to lib/libc/printf.c
diff --git a/lib/stdlib/putchar.c b/lib/libc/putchar.c
similarity index 100%
rename from lib/stdlib/putchar.c
rename to lib/libc/putchar.c
diff --git a/lib/stdlib/puts.c b/lib/libc/puts.c
similarity index 100%
rename from lib/stdlib/puts.c
rename to lib/libc/puts.c
diff --git a/lib/stdlib/sscanf.c b/lib/libc/sscanf.c
similarity index 100%
rename from lib/stdlib/sscanf.c
rename to lib/libc/sscanf.c
diff --git a/lib/stdlib/strchr.c b/lib/libc/strchr.c
similarity index 100%
rename from lib/stdlib/strchr.c
rename to lib/libc/strchr.c
diff --git a/lib/stdlib/strcmp.c b/lib/libc/strcmp.c
similarity index 100%
rename from lib/stdlib/strcmp.c
rename to lib/libc/strcmp.c
diff --git a/lib/stdlib/strlen.c b/lib/libc/strlen.c
similarity index 100%
rename from lib/stdlib/strlen.c
rename to lib/libc/strlen.c
diff --git a/lib/stdlib/strncmp.c b/lib/libc/strncmp.c
similarity index 100%
rename from lib/stdlib/strncmp.c
rename to lib/libc/strncmp.c
diff --git a/lib/stdlib/strnlen.c b/lib/libc/strnlen.c
similarity index 100%
rename from lib/stdlib/strnlen.c
rename to lib/libc/strnlen.c
diff --git a/lib/stdlib/subr_prf.c b/lib/libc/subr_prf.c
similarity index 100%
rename from lib/stdlib/subr_prf.c
rename to lib/libc/subr_prf.c
diff --git a/lib/stdlib/timingsafe_bcmp.c b/lib/libc/timingsafe_bcmp.c
similarity index 100%
rename from lib/stdlib/timingsafe_bcmp.c
rename to lib/libc/timingsafe_bcmp.c
diff --git a/lib/libfdt/libfdt.mk b/lib/libfdt/libfdt.mk
index d03dde2..1cbbd78 100644
--- a/lib/libfdt/libfdt.mk
+++ b/lib/libfdt/libfdt.mk
@@ -15,3 +15,5 @@
 			fdt_wip.c)			\
 
 INCLUDES	+=	-Iinclude/lib/libfdt
+
+$(eval $(call MAKE_LIB,fdt))
diff --git a/lib/romlib/Makefile b/lib/romlib/Makefile
new file mode 100644
index 0000000..46b9206
--- /dev/null
+++ b/lib/romlib/Makefile
@@ -0,0 +1,71 @@
+#
+# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+AS          = $(CROSS_COMPILE)as
+LD          = $(CROSS_COMPILE)ld
+OC          = $(CROSS_COMPILE)objcopy
+CPP         = $(CROSS_COMPILE)cpp
+BUILD_DIR   = ../../$(BUILD_PLAT)/romlib
+LIB_DIR     = ../../$(BUILD_PLAT)/lib
+WRAPPER_DIR = ../../$(BUILD_PLAT)/libwrapper
+LIBS        = -lmbedtls -lfdt -lc
+INC         = $(INCLUDES:-I%=-I../../%)
+PPFLAGS     = $(INC) $(DEFINES) -P -D__ASSEMBLY__ -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld
+OBJS        = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o
+
+V ?= 0
+ifeq ($(V),0)
+  Q := @
+else
+  Q :=
+endif
+
+ifeq ($(DEBUG),1)
+   CFLAGS  := -g
+   LDFLAGS := -g
+endif
+
+
+.PHONY: all clean distclean
+
+all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a
+
+%.o: %.s
+	@echo "  AS      $@"
+	$(Q)$(AS) $(ASFLAGS) -o $@ $<
+
+$(BUILD_DIR)/%.o: %.s
+	@echo "  AS      $@"
+	$(Q)$(AS) $(ASFLAGS) -o $@ $<
+
+$(BUILD_DIR)/romlib.ld: romlib.ld.S
+	@echo "  PP      $@"
+	$(Q)$(CPP) $(PPFLAGS) -o $@ romlib.ld.S
+
+$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld
+	@echo "  LD      $@"
+	$(Q)$(LD) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
+
+$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf
+	@echo "  BIN     $@"
+	$(Q)$(OC) -O binary $(BUILD_DIR)/romlib.elf $@
+
+$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf
+	@echo "  VAR     $@"
+	$(Q)./genvar.sh -o $@ $(BUILD_DIR)/romlib.elf
+
+$(LIB_DIR)/libwrappers.a: jmptbl.i $(WRAPPER_DIR)/jmpvar.o
+	@echo "  AR      $@"
+	$(Q)./genwrappers.sh -b $(WRAPPER_DIR) -o $@ jmptbl.i
+
+$(BUILD_DIR)/jmptbl.s: jmptbl.i
+	@echo "  TBL     $@"
+	$(Q)./gentbl.sh -o $@ jmptbl.i
+
+clean:
+	@rm -f $(BUILD_DIR)/*
+
+-include $(BUILD_DIR)/romlib.d
diff --git a/lib/romlib/gentbl.sh b/lib/romlib/gentbl.sh
new file mode 100755
index 0000000..0695f6e
--- /dev/null
+++ b/lib/romlib/gentbl.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+set -e
+
+output=jmptbl.s
+
+for i
+do
+	case $i in
+	-o)
+		output=$2
+		shift 2
+		;;
+	--)
+		shift
+		break
+		;;
+	-*)
+		echo usage: gentbl.sh [-o output]  file ... >&2
+		exit 1
+		;;
+	esac
+done
+
+tmp=`mktemp`
+trap "rm -f $tmp" EXIT INT QUIT
+
+rm -f $output
+
+awk -v OFS="\n" '
+BEGIN {print "\t.text",
+             "\t.globl\tjmptbl",
+             "jmptbl:"}
+      {sub(/[:blank:]*#.*/,"")}
+!/^$/ {print "\tb\t" $3}' "$@" > $tmp
+
+mv $tmp $output
diff --git a/lib/romlib/genvar.sh b/lib/romlib/genvar.sh
new file mode 100755
index 0000000..a3e2cdf
--- /dev/null
+++ b/lib/romlib/genvar.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+set -e
+
+output=jmpvar.s
+for i
+do
+	case $i in
+	-o)
+		output=$2
+		shift 2
+		;;
+	--)
+		shift
+		break
+		;;
+	-*)
+		echo usage: genvar.sh [-o output] file... >&2
+		;;
+	esac
+done
+
+tmp=`mktemp`
+trap "rm -f $tmp" EXIT INT QUIT
+
+nm -a "$@" |
+awk -v OFS="\n" '
+$3 == ".text" {print "\t.data",
+                     "\t.globl\tjmptbl",
+                     "\t.align\t4",
+                     "jmptbl:\t.quad\t0x" $1}' > $tmp
+
+mv $tmp $output
diff --git a/lib/romlib/genwrappers.sh b/lib/romlib/genwrappers.sh
new file mode 100755
index 0000000..bcf670b
--- /dev/null
+++ b/lib/romlib/genwrappers.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+set -e
+
+build=.
+out=output.a
+
+for i
+do
+	case $i in
+	-o)
+		out=$2
+		shift 2
+		;;
+	-b)
+		build=$2
+		shift 2
+		;;
+	--)
+		shift
+		break
+		;;
+	-*)
+		echo usage: genwrappers.sh [-o output] [-b dir] file ... >&2
+		exit 1
+		;;
+	esac
+done
+
+awk  '{sub(/[:blank:]*#.*/,"")}
+!/^$/ {print $1*4, $2, $3}' "$@" |
+while read idx lib sym
+do
+	file=$build/${lib}_$sym
+
+	cat <<EOF > $file.s
+	.globl	$sym
+$sym:
+	ldr	x17, =jmptbl
+	ldr	x17, [x17]
+	mov	x16, $idx
+	add	x16, x16, x17
+	br	x16
+EOF
+
+	${CROSS_COMPILE}as -o $file.o $file.s
+done
+
+${CROSS_COMPILE}ar -rc $out $build/*.o
diff --git a/lib/romlib/init.s b/lib/romlib/init.s
new file mode 100644
index 0000000..5cf2aca
--- /dev/null
+++ b/lib/romlib/init.s
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+	.globl	rom_lib_init
+	.extern	__DATA_RAM_START__, __DATA_ROM_START__, __DATA_SIZE__
+	.extern	memset, memcpy
+
+rom_lib_init:
+	cmp	w0, #1
+	mov	w0, #0
+	b.le	1f
+	ret
+
+1:	stp	x29, x30, [sp, #-16]!
+	adrp	x0, __DATA_RAM_START__
+	ldr	x1,= __DATA_ROM_START__
+	ldr	x2, =__DATA_SIZE__
+	bl	memcpy
+
+	ldr	x0, =__BSS_START__
+	mov	x1, #0
+	ldr	x2, =__BSS_SIZE__
+	bl	memset
+	ldp	x29, x30, [sp], #16
+
+	mov	w0, #1
+	ret
diff --git a/lib/romlib/jmptbl.i b/lib/romlib/jmptbl.i
new file mode 100644
index 0000000..338cd8a
--- /dev/null
+++ b/lib/romlib/jmptbl.i
@@ -0,0 +1,35 @@
+#
+# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+0	rom	rom_lib_init
+1	fdt	fdt_getprop_namelen
+2	fdt	fdt_setprop_inplace
+3	fdt	fdt_check_header
+4	fdt	fdt_node_offset_by_compatible
+5	mbedtls	mbedtls_asn1_get_alg
+6	mbedtls	mbedtls_asn1_get_alg_null
+7	mbedtls	mbedtls_asn1_get_bitstring_null
+8	mbedtls	mbedtls_asn1_get_bool
+9	mbedtls	mbedtls_asn1_get_int
+10	mbedtls	mbedtls_asn1_get_tag
+11	mbedtls	mbedtls_free
+12	mbedtls	mbedtls_md
+13	mbedtls	mbedtls_md_get_size
+14	mbedtls	mbedtls_memory_buffer_alloc_init
+15	mbedtls	mbedtls_oid_get_md_alg
+16	mbedtls	mbedtls_oid_get_numeric_string
+17	mbedtls	mbedtls_oid_get_pk_alg
+18	mbedtls	mbedtls_oid_get_sig_alg
+19	mbedtls	mbedtls_pk_free
+20	mbedtls	mbedtls_pk_init
+21	mbedtls	mbedtls_pk_parse_subpubkey
+22	mbedtls	mbedtls_pk_verify_ext
+23	mbedtls	mbedtls_platform_set_snprintf
+24	mbedtls	mbedtls_x509_get_rsassa_pss_params
+25	mbedtls	mbedtls_x509_get_sig_alg
+26	mbedtls	mbedtls_md_info_from_type
+27	c	exit
+28	c	atexit
diff --git a/lib/romlib/romlib.ld.S b/lib/romlib/romlib.ld.S
new file mode 100644
index 0000000..8f0bc62
--- /dev/null
+++ b/lib/romlib/romlib.ld.S
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <platform_def.h>
+#include <xlat_tables_defs.h>
+
+MEMORY {
+	ROM (rx): ORIGIN = ROMLIB_RO_BASE, LENGTH = ROMLIB_RO_LIMIT - ROMLIB_RO_BASE
+	RAM (rwx): ORIGIN = ROMLIB_RW_BASE, LENGTH = ROMLIB_RW_END - ROMLIB_RW_BASE
+}
+
+OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
+OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
+ENTRY(jmptbl)
+
+SECTIONS
+{
+	. = ROMLIB_RO_BASE;
+	.text : {
+		*jmptbl.o(.text)
+		*(.text*)
+		*(.rodata*)
+	} >ROM
+
+	__DATA_ROM_START__ = LOADADDR(.data);
+
+	.data : {
+		__DATA_RAM_START__ = .;
+		*(.data*)
+		__DATA_RAM_END__ = .;
+	} >RAM AT>ROM
+
+	__DATA_SIZE__ = SIZEOF(.data);
+
+	.bss : {
+		__BSS_START__ = .;
+		*(.bss*)
+		__BSS_END__ = .;
+	 } >RAM
+	__BSS_SIZE__ = SIZEOF(.bss);
+}
diff --git a/lib/stdlib/exit.c b/lib/stdlib/exit.c
deleted file mode 100644
index afc3f93..0000000
--- a/lib/stdlib/exit.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <debug.h>
-#include <stdlib.h>
-
-void exit(int v)
-{
-	ERROR("EXIT\n");
-	panic();
-}
diff --git a/lib/xlat_tables/aarch32/xlat_tables.c b/lib/xlat_tables/aarch32/xlat_tables.c
index 87b15b8..033e237 100644
--- a/lib/xlat_tables/aarch32/xlat_tables.c
+++ b/lib/xlat_tables/aarch32/xlat_tables.c
@@ -65,8 +65,20 @@
  * Function for enabling the MMU in Secure PL1, assuming that the
  * page-tables have already been created.
  ******************************************************************************/
+#if !ERROR_DEPRECATED
 void enable_mmu_secure(unsigned int flags)
 {
+	enable_mmu_svc_mon(flags);
+}
+
+void enable_mmu_direct(unsigned int flags)
+{
+	enable_mmu_direct_svc_mon(flags);
+}
+#endif
+
+void enable_mmu_svc_mon(unsigned int flags)
+{
 	unsigned int mair0, ttbcr, sctlr;
 	uint64_t ttbr0;
 
@@ -131,7 +143,7 @@
 	isb();
 }
 
-void enable_mmu_direct(unsigned int flags)
+void enable_mmu_direct_svc_mon(unsigned int flags)
 {
-	enable_mmu_secure(flags);
+	enable_mmu_svc_mon(flags);
 }
diff --git a/lib/xlat_tables_v2/aarch32/enable_mmu.S b/lib/xlat_tables_v2/aarch32/enable_mmu.S
index 99cf088..4a4ac30 100644
--- a/lib/xlat_tables_v2/aarch32/enable_mmu.S
+++ b/lib/xlat_tables_v2/aarch32/enable_mmu.S
@@ -8,9 +8,11 @@
 #include <assert_macros.S>
 #include <xlat_tables_v2.h>
 
-	.global	enable_mmu_direct
+	.global	enable_mmu_direct_svc_mon
+	.global	enable_mmu_direct_hyp
 
-func enable_mmu_direct
+	/* void enable_mmu_direct_svc_mon(unsigned int flags) */
+func enable_mmu_direct_svc_mon
 	/* Assert that MMU is turned off */
 #if ENABLE_ASSERTIONS
 	ldcopr  r1, SCTLR
@@ -63,4 +65,56 @@
 	isb
 
 	bx	lr
-endfunc enable_mmu_direct
+endfunc enable_mmu_direct_svc_mon
+
+
+	/* void enable_mmu_direct_hyp(unsigned int flags) */
+func enable_mmu_direct_hyp
+	/* Assert that MMU is turned off */
+#if ENABLE_ASSERTIONS
+	ldcopr  r1, HSCTLR
+	tst	r1, #HSCTLR_M_BIT
+	ASM_ASSERT(eq)
+#endif
+
+	/* Invalidate TLB entries */
+	TLB_INVALIDATE(r0, TLBIALL)
+
+	mov	r3, r0
+	ldr	r0, =mmu_cfg_params
+
+	/* HMAIR0 */
+	ldr	r1, [r0, #(MMU_CFG_MAIR << 3)]
+	stcopr	r1, HMAIR0
+
+	/* HTCR */
+	ldr	r2, [r0, #(MMU_CFG_TCR << 3)]
+	stcopr	r2, HTCR
+
+	/* HTTBR */
+	ldr	r1, [r0, #(MMU_CFG_TTBR0 << 3)]
+	ldr	r2, [r0, #((MMU_CFG_TTBR0 << 3) + 4)]
+	stcopr16	r1, r2, HTTBR_64
+
+	/*
+	 * Ensure all translation table writes have drained into memory, the TLB
+	 * invalidation is complete, and translation register writes are
+	 * committed before enabling the MMU
+	 */
+	dsb	ish
+	isb
+
+	/* Enable enable MMU by honoring flags */
+	ldcopr  r1, HSCTLR
+	ldr	r2, =(HSCTLR_WXN_BIT | HSCTLR_C_BIT | HSCTLR_M_BIT)
+	orr	r1, r1, r2
+
+	/* Clear C bit if requested */
+	tst	r3, #DISABLE_DCACHE
+	bicne	r1, r1, #HSCTLR_C_BIT
+
+	stcopr	r1, HSCTLR
+	isb
+
+	bx	lr
+endfunc enable_mmu_direct_hyp
diff --git a/lib/xlat_tables_v2/aarch32/xlat_tables_arch.c b/lib/xlat_tables_v2/aarch32/xlat_tables_arch.c
index 2482840..66938e5 100644
--- a/lib/xlat_tables_v2/aarch32/xlat_tables_arch.c
+++ b/lib/xlat_tables_v2/aarch32/xlat_tables_arch.c
@@ -43,22 +43,38 @@
 }
 #endif /* ENABLE_ASSERTIONS*/
 
-bool is_mmu_enabled_ctx(const xlat_ctx_t *ctx __unused)
+bool is_mmu_enabled_ctx(const xlat_ctx_t *ctx)
 {
-	return (read_sctlr() & SCTLR_M_BIT) != 0;
+	if (ctx->xlat_regime == EL1_EL0_REGIME) {
+		assert(xlat_arch_current_el() == 1U);
+		return (read_sctlr() & SCTLR_M_BIT) != 0U;
+	} else {
+		assert(ctx->xlat_regime == EL2_REGIME);
+		assert(xlat_arch_current_el() == 2U);
+		return (read_hsctlr() & HSCTLR_M_BIT) != 0U;
+	}
 }
 
 bool is_dcache_enabled(void)
 {
-	return (read_sctlr() & SCTLR_C_BIT) != 0;
+	if (IS_IN_EL2()) {
+		return (read_hsctlr() & HSCTLR_C_BIT) != 0U;
+	} else {
+		return (read_sctlr() & SCTLR_C_BIT) != 0U;
+	}
 }
 
-uint64_t xlat_arch_regime_get_xn_desc(int xlat_regime __unused)
+uint64_t xlat_arch_regime_get_xn_desc(int xlat_regime)
 {
-	return UPPER_ATTRS(XN);
+	if (xlat_regime == EL1_EL0_REGIME) {
+		return UPPER_ATTRS(XN) | UPPER_ATTRS(PXN);
+	} else {
+		assert(xlat_regime == EL2_REGIME);
+		return UPPER_ATTRS(XN);
+	}
 }
 
-void xlat_arch_tlbi_va(uintptr_t va, int xlat_regime __unused)
+void xlat_arch_tlbi_va(uintptr_t va, int xlat_regime)
 {
 	/*
 	 * Ensure the translation table write has drained into memory before
@@ -66,7 +82,12 @@
 	 */
 	dsbishst();
 
-	tlbimvaais(TLBI_ADDR(va));
+	if (xlat_regime == EL1_EL0_REGIME) {
+		tlbimvaais(TLBI_ADDR(va));
+	} else {
+		assert(xlat_regime == EL2_REGIME);
+		tlbimvahis(TLBI_ADDR(va));
+	}
 }
 
 void xlat_arch_tlbi_va_sync(void)
@@ -97,19 +118,25 @@
 
 unsigned int xlat_arch_current_el(void)
 {
-	/*
-	 * If EL3 is in AArch32 mode, all secure PL1 modes (Monitor, System,
-	 * SVC, Abort, UND, IRQ and FIQ modes) execute at EL3.
-	 *
-	 * The PL1&0 translation regime in AArch32 behaves like the EL1&0 regime
-	 * in AArch64 except for the XN bits, but we set and unset them at the
-	 * same time, so there's no difference in practice.
-	 */
-	return 1U;
+	if (IS_IN_HYP()) {
+		return 2U;
+	} else {
+		assert(IS_IN_SVC() || IS_IN_MON());
+		/*
+		 * If EL3 is in AArch32 mode, all secure PL1 modes (Monitor,
+		 * System, SVC, Abort, UND, IRQ and FIQ modes) execute at EL3.
+		 *
+		 * The PL1&0 translation regime in AArch32 behaves like the
+		 * EL1&0 regime in AArch64 except for the XN bits, but we set
+		 * and unset them at the same time, so there's no difference in
+		 * practice.
+		 */
+		return 1U;
+	}
 }
 
 /*******************************************************************************
- * Function for enabling the MMU in Secure PL1, assuming that the page tables
+ * Function for enabling the MMU in PL1 or PL2, assuming that the page tables
  * have already been created.
  ******************************************************************************/
 void setup_mmu_cfg(uint64_t *params, unsigned int flags,
@@ -119,8 +146,6 @@
 	uint64_t mair, ttbr0;
 	uint32_t ttbcr;
 
-	assert(IS_IN_SECURE());
-
 	/* Set attributes in the right indices of the MAIR */
 	mair = MAIR0_ATTR_SET(ATTR_DEVICE, ATTR_DEVICE_INDEX);
 	mair |= MAIR0_ATTR_SET(ATTR_IWBWA_OWBWA_NTR,
@@ -129,18 +154,32 @@
 			ATTR_NON_CACHEABLE_INDEX);
 
 	/*
-	 * Configure the control register for stage 1 of the PL1&0 translation
-	 * regime.
+	 * Configure the control register for stage 1 of the PL1&0 or EL2
+	 * translation regimes.
 	 */
 
 	/* Use the Long-descriptor translation table format. */
 	ttbcr = TTBCR_EAE_BIT;
 
-	/*
-	 * Disable translation table walk for addresses that are translated
-	 * using TTBR1. Therefore, only TTBR0 is used.
-	 */
-	ttbcr |= TTBCR_EPD1_BIT;
+	if (xlat_regime == EL1_EL0_REGIME) {
+		assert(IS_IN_SVC() || IS_IN_MON());
+		/*
+		 * Disable translation table walk for addresses that are
+		 * translated using TTBR1. Therefore, only TTBR0 is used.
+		 */
+		ttbcr |= TTBCR_EPD1_BIT;
+	} else {
+		assert(xlat_regime == EL2_REGIME);
+		assert(IS_IN_HYP());
+
+		/*
+		 * Set HTCR bits as well. Set HTTBR table properties
+		 * as Inner & outer WBWA & shareable.
+		 */
+		ttbcr |= HTCR_RES1 |
+			 HTCR_SH0_INNER_SHAREABLE | HTCR_RGN0_OUTER_WBA |
+			 HTCR_RGN0_INNER_WBA;
+	}
 
 	/*
 	 * Limit the input address ranges and memory region sizes translated
diff --git a/lib/xlat_tables_v2/aarch64/enable_mmu.S b/lib/xlat_tables_v2/aarch64/enable_mmu.S
index 5c5a2a9..21717d2 100644
--- a/lib/xlat_tables_v2/aarch64/enable_mmu.S
+++ b/lib/xlat_tables_v2/aarch64/enable_mmu.S
@@ -9,6 +9,7 @@
 #include <xlat_tables_v2.h>
 
 	.global	enable_mmu_direct_el1
+	.global	enable_mmu_direct_el2
 	.global	enable_mmu_direct_el3
 
 	/* Macros to read and write to system register for a given EL. */
@@ -20,6 +21,19 @@
 	mrs	\gp_reg, \reg_name\()_el\()\el
 	.endm
 
+	.macro tlbi_invalidate_all el
+	.if \el == 1
+		TLB_INVALIDATE(vmalle1)
+	.elseif \el == 2
+		TLB_INVALIDATE(alle2)
+	.elseif \el == 3
+		TLB_INVALIDATE(alle3)
+	.else
+		.error "EL must be 1, 2 or 3"
+	.endif
+	.endm
+
+	/* void enable_mmu_direct_el<x>(unsigned int flags) */
 	.macro define_mmu_enable_func el
 	func enable_mmu_direct_\()el\el
 #if ENABLE_ASSERTIONS
@@ -27,17 +41,8 @@
 		tst	x1, #SCTLR_M_BIT
 		ASM_ASSERT(eq)
 #endif
-
-		/* Invalidate TLB entries */
-		.if \el == 1
-		TLB_INVALIDATE(vmalle1)
-		.else
-		.if \el == 3
-		TLB_INVALIDATE(alle3)
-		.else
-		.error "EL must be 1 or 3"
-		.endif
-		.endif
+		/* Invalidate all TLB entries */
+		tlbi_invalidate_all \el
 
 		mov	x7, x0
 		ldr	x0, =mmu_cfg_params
@@ -86,4 +91,5 @@
 	 *  enable_mmu_direct_el3
 	 */
 	define_mmu_enable_func 1
+	define_mmu_enable_func 2
 	define_mmu_enable_func 3
diff --git a/lib/xlat_tables_v2/aarch64/xlat_tables_arch.c b/lib/xlat_tables_v2/aarch64/xlat_tables_arch.c
index cf8070a..d1555bf 100644
--- a/lib/xlat_tables_v2/aarch64/xlat_tables_arch.c
+++ b/lib/xlat_tables_v2/aarch64/xlat_tables_arch.c
@@ -105,6 +105,9 @@
 	if (ctx->xlat_regime == EL1_EL0_REGIME) {
 		assert(xlat_arch_current_el() >= 1U);
 		return (read_sctlr_el1() & SCTLR_M_BIT) != 0U;
+	} else if (ctx->xlat_regime == EL2_REGIME) {
+		assert(xlat_arch_current_el() >= 2U);
+		return (read_sctlr_el2() & SCTLR_M_BIT) != 0U;
 	} else {
 		assert(ctx->xlat_regime == EL3_REGIME);
 		assert(xlat_arch_current_el() >= 3U);
@@ -118,6 +121,8 @@
 
 	if (el == 1U) {
 		return (read_sctlr_el1() & SCTLR_C_BIT) != 0U;
+	} else if (el == 2U) {
+		return (read_sctlr_el2() & SCTLR_C_BIT) != 0U;
 	} else {
 		return (read_sctlr_el3() & SCTLR_C_BIT) != 0U;
 	}
@@ -128,7 +133,8 @@
 	if (xlat_regime == EL1_EL0_REGIME) {
 		return UPPER_ATTRS(UXN) | UPPER_ATTRS(PXN);
 	} else {
-		assert(xlat_regime == EL3_REGIME);
+		assert((xlat_regime == EL2_REGIME) ||
+		       (xlat_regime == EL3_REGIME));
 		return UPPER_ATTRS(XN);
 	}
 }
@@ -151,6 +157,9 @@
 	if (xlat_regime == EL1_EL0_REGIME) {
 		assert(xlat_arch_current_el() >= 1U);
 		tlbivaae1is(TLBI_ADDR(va));
+	} else if (xlat_regime == EL2_REGIME) {
+		assert(xlat_arch_current_el() >= 2U);
+		tlbivae2is(TLBI_ADDR(va));
 	} else {
 		assert(xlat_regime == EL3_REGIME);
 		assert(xlat_arch_current_el() >= 3U);
@@ -245,6 +254,8 @@
 		 * that are translated using TTBR1_EL1.
 		 */
 		tcr |= TCR_EPD1_BIT | (tcr_ps_bits << TCR_EL1_IPS_SHIFT);
+	} else if (xlat_regime == EL2_REGIME) {
+		tcr |= TCR_EL2_RES1 | (tcr_ps_bits << TCR_EL2_PS_SHIFT);
 	} else {
 		assert(xlat_regime == EL3_REGIME);
 		tcr |= TCR_EL3_RES1 | (tcr_ps_bits << TCR_EL3_PS_SHIFT);
diff --git a/lib/xlat_tables_v2/xlat_tables_context.c b/lib/xlat_tables_v2/xlat_tables_context.c
index 143f08a..bf0cc9f 100644
--- a/lib/xlat_tables_v2/xlat_tables_context.c
+++ b/lib/xlat_tables_v2/xlat_tables_context.c
@@ -82,6 +82,8 @@
 
 	if (current_el == 1U) {
 		tf_xlat_ctx.xlat_regime = EL1_EL0_REGIME;
+	} else if (current_el == 2U) {
+		tf_xlat_ctx.xlat_regime = EL2_REGIME;
 	} else {
 		assert(current_el == 3U);
 		tf_xlat_ctx.xlat_regime = EL3_REGIME;
@@ -119,14 +121,34 @@
 
 #ifdef AARCH32
 
+#if !ERROR_DEPRECATED
 void enable_mmu_secure(unsigned int flags)
 {
+	enable_mmu_svc_mon(flags);
+}
+
+void enable_mmu_direct(unsigned int flags)
+{
+	enable_mmu_direct_svc_mon(flags);
+}
+#endif
+
+void enable_mmu_svc_mon(unsigned int flags)
+{
 	setup_mmu_cfg((uint64_t *)&mmu_cfg_params, flags,
 		      tf_xlat_ctx.base_table, MAX_PHYS_ADDR,
 		      tf_xlat_ctx.va_max_address, EL1_EL0_REGIME);
-	enable_mmu_direct(flags);
+	enable_mmu_direct_svc_mon(flags);
 }
 
+void enable_mmu_hyp(unsigned int flags)
+{
+	setup_mmu_cfg((uint64_t *)&mmu_cfg_params, flags,
+		      tf_xlat_ctx.base_table, MAX_PHYS_ADDR,
+		      tf_xlat_ctx.va_max_address, EL2_REGIME);
+	enable_mmu_direct_hyp(flags);
+}
+
 #else
 
 void enable_mmu_el1(unsigned int flags)
@@ -137,6 +159,14 @@
 	enable_mmu_direct_el1(flags);
 }
 
+void enable_mmu_el2(unsigned int flags)
+{
+	setup_mmu_cfg((uint64_t *)&mmu_cfg_params, flags,
+		      tf_xlat_ctx.base_table, MAX_PHYS_ADDR,
+		      tf_xlat_ctx.va_max_address, EL2_REGIME);
+	enable_mmu_direct_el2(flags);
+}
+
 void enable_mmu_el3(unsigned int flags)
 {
 	setup_mmu_cfg((uint64_t *)&mmu_cfg_params, flags,
diff --git a/lib/xlat_tables_v2/xlat_tables_core.c b/lib/xlat_tables_v2/xlat_tables_core.c
index 56b9514..0340bf6 100644
--- a/lib/xlat_tables_v2/xlat_tables_core.c
+++ b/lib/xlat_tables_v2/xlat_tables_core.c
@@ -142,7 +142,8 @@
 			desc |= LOWER_ATTRS(AP_NO_ACCESS_UNPRIVILEGED);
 		}
 	} else {
-		assert(ctx->xlat_regime == EL3_REGIME);
+		assert((ctx->xlat_regime == EL2_REGIME) ||
+		       (ctx->xlat_regime == EL3_REGIME));
 		desc |= LOWER_ATTRS(AP_ONE_VA_RANGE_RES1);
 	}
 
@@ -1016,6 +1017,7 @@
 	assert(ctx != NULL);
 	assert(!ctx->initialized);
 	assert((ctx->xlat_regime == EL3_REGIME) ||
+	       (ctx->xlat_regime == EL2_REGIME) ||
 	       (ctx->xlat_regime == EL1_EL0_REGIME));
 	assert(!is_mmu_enabled_ctx(ctx));
 
diff --git a/lib/xlat_tables_v2/xlat_tables_utils.c b/lib/xlat_tables_v2/xlat_tables_utils.c
index 8cad348..05533c6 100644
--- a/lib/xlat_tables_v2/xlat_tables_utils.c
+++ b/lib/xlat_tables_v2/xlat_tables_utils.c
@@ -60,8 +60,8 @@
 		tf_printf("DEV");
 	}
 
-	if (xlat_regime == EL3_REGIME) {
-		/* For EL3 only check the AP[2] and XN bits. */
+	if ((xlat_regime == EL3_REGIME) || (xlat_regime == EL2_REGIME)) {
+		/* For EL3 and EL2 only check the AP[2] and XN bits. */
 		tf_printf(((desc & LOWER_ATTRS(AP_RO)) != 0ULL) ? "-RO" : "-RW");
 		tf_printf(((desc & UPPER_ATTRS(XN)) != 0ULL) ? "-XN" : "-EXEC");
 	} else {
@@ -200,6 +200,8 @@
 
 	if (ctx->xlat_regime == EL1_EL0_REGIME) {
 		xlat_regime_str = "1&0";
+	} else if (ctx->xlat_regime == EL2_REGIME) {
+		xlat_regime_str = "2";
 	} else {
 		assert(ctx->xlat_regime == EL3_REGIME);
 		xlat_regime_str = "3";
@@ -329,6 +331,7 @@
 	assert(ctx != NULL);
 	assert(ctx->initialized);
 	assert((ctx->xlat_regime == EL1_EL0_REGIME) ||
+	       (ctx->xlat_regime == EL2_REGIME) ||
 	       (ctx->xlat_regime == EL3_REGIME));
 
 	virt_addr_space_size = (unsigned long long)ctx->va_max_address + 1ULL;
diff --git a/maintainers.rst b/maintainers.rst
index 28127f8..1424f85 100644
--- a/maintainers.rst
+++ b/maintainers.rst
@@ -34,13 +34,11 @@
 ----------------
 :M: Haojian Zhuang <haojian.zhuang@linaro.org>
 :G: `hzhuang1`_
-:F: drivers/emmc/
 :F: drivers/partition/
 :F: drivers/synopsys/emmc/
 :F: drivers/synopsys/ufs/
 :F: drivers/ufs/
 :F: include/drivers/dw_ufs.h
-:F: include/drivers/emmc.h
 :F: include/drivers/ufs.h
 :F: include/drivers/synopsys/dw_mmc.h
 
diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk
index 1184b7a..92a0f6e 100644
--- a/make_helpers/build_macros.mk
+++ b/make_helpers/build_macros.mk
@@ -189,6 +189,24 @@
 
 MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP
 
+
+# MAKE_C_LIB builds a C source file and generates the dependency file
+#   $(1) = output directory
+#   $(2) = source file (%.c)
+#   $(3) = library name
+define MAKE_C_LIB
+$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
+$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
+
+$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
+	@echo "  CC      $$<"
+	$$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@
+
+-include $(DEP)
+
+endef
+
+
 # MAKE_C builds a C source file and generates the dependency file
 #   $(1) = output directory
 #   $(2) = source file (%.c)
@@ -241,6 +259,18 @@
 
 -include $(DEP)
 
+endef
+
+# MAKE_LIB_OBJS builds both C source files
+#   $(1) = output directory
+#   $(2) = list of source files
+#   $(3) = name of the library
+define MAKE_LIB_OBJS
+        $(eval C_OBJS := $(filter %.c,$(2)))
+        $(eval REMAIN := $(filter-out %.c,$(2)))
+        $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3))))
+
+        $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
 endef
 
 
@@ -274,6 +304,49 @@
 # This must be set to a C string (including quotes where applicable).
 BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
 
+.PHONY: libraries
+
+# MAKE_LIB_DIRS macro defines the target for the directory where
+# libraries are created
+define MAKE_LIB_DIRS
+        $(eval LIB_DIR    := ${BUILD_PLAT}/lib)
+        $(eval ROMLIB_DIR    := ${BUILD_PLAT}/romlib)
+        $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper)
+        $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT}))
+        $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT}))
+        $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT}))
+endef
+
+# MAKE_LIB macro defines the targets and options to build each BL image.
+# Arguments:
+#   $(1) = Library name
+define MAKE_LIB
+        $(eval BUILD_DIR  := ${BUILD_PLAT}/lib$(1))
+        $(eval LIB_DIR    := ${BUILD_PLAT}/lib)
+        $(eval ROMLIB_DIR    := ${BUILD_PLAT}/romlib)
+        $(eval SOURCES    := $(LIB$(call uppercase,$(1))_SRCS))
+        $(eval OBJS       := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
+
+$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
+$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
+
+.PHONY : lib${1}_dirs
+lib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR}  ${ROMLIB_DIR} ${LIBWRAPPER_DIR}
+libraries: ${LIB_DIR}/lib$(1).a
+LDPATHS = -L${LIB_DIR}
+LDLIBS += -l$(1)
+
+ifeq ($(USE_ROMLIB),1)
+LDLIBS := -lwrappers -lc
+endif
+
+all: ${LIB_DIR}/lib$(1).a
+
+${LIB_DIR}/lib$(1).a: $(OBJS)
+	@echo "  AR      $$@"
+	$$(Q)$$(AR) cr $$@ $$?
+endef
+
 # MAKE_BL macro defines the targets and options to build each BL image.
 # Arguments:
 #   $(1) = BL stage (2, 2u, 30, 31, 32, 33)
@@ -313,7 +386,11 @@
 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
 $(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1)))
 
-$(ELF): $(OBJS) $(LINKERFILE) | bl$(1)_dirs $(BL_LIBS)
+ifeq ($(USE_ROMLIB),1)
+$(ELF): romlib.bin
+endif
+
+$(ELF): $(OBJS) $(LINKERFILE) | bl$(1)_dirs libraries $(BL_LIBS)
 	@echo "  LD      $$@"
 ifdef MAKE_BUILD_STRINGS
 	$(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o)
@@ -323,7 +400,8 @@
 		$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o
 endif
 	$$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Map=$(MAPFILE) \
-		--script $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS) $(LDLIBS) $(BL_LIBS)
+		--script $(LINKERFILE) $(BUILD_DIR)/build_message.o \
+		$(OBJS) $(LDPATHS) $(LDLIBS) $(BL_LIBS)
 
 $(DUMP): $(ELF)
 	@echo "  OD      $$@"
diff --git a/make_helpers/defaults.mk b/make_helpers/defaults.mk
index cea8533..e4b5bdc 100644
--- a/make_helpers/defaults.mk
+++ b/make_helpers/defaults.mk
@@ -166,6 +166,9 @@
 # Build option to choose whether Trusted firmware uses Coherent memory or not.
 USE_COHERENT_MEM		:= 1
 
+# Build option to choose wheter Trusted firmware uses library at ROM
+USE_ROMLIB				:= 0
+
 # Use tbbr_oid.h instead of platform_oid.h
 USE_TBBR_DEFS			= $(ERROR_DEPRECATED)
 
diff --git a/plat/arm/board/juno/include/platform_def.h b/plat/arm/board/juno/include/platform_def.h
index a781c4f..3f71d73 100644
--- a/plat/arm/board/juno/include/platform_def.h
+++ b/plat/arm/board/juno/include/platform_def.h
@@ -67,6 +67,8 @@
  * in debug mode. We can test TBB on Juno bypassing the ROM and using 128 KB of
  * flash
  */
+#define PLAT_ARM_MAX_ROMLIB_RO_SIZE	0
+
 #if TRUSTED_BOARD_BOOT
 #define PLAT_ARM_TRUSTED_ROM_SIZE	0x00020000
 #else
@@ -123,6 +125,15 @@
 #endif
 
 /*
+ * PLAT_ARM_MAX_ROMLIB_RW_SIZE is define to use a full page
+ */
+#if USE_ROMLIB
+#define PLAT_ARM_MAX_ROMLIB_RW_SIZE	0x1000
+#else
+#define PLAT_ARM_MAX_ROMLIB_RW_SIZE	0
+#endif
+
+/*
  * PLAT_ARM_MAX_BL2_SIZE is calculated using the current BL2 debug size plus a
  * little space for growth.
  */
diff --git a/plat/arm/common/arm_bl1_setup.c b/plat/arm/common/arm_bl1_setup.c
index a192a06..d435553 100644
--- a/plat/arm/common/arm_bl1_setup.c
+++ b/plat/arm/common/arm_bl1_setup.c
@@ -117,15 +117,21 @@
 	const mmap_region_t bl_regions[] = {
 		MAP_BL1_TOTAL,
 		MAP_BL1_RO,
+#if USE_ROMLIB
+		ARM_MAP_ROMLIB_CODE,
+		ARM_MAP_ROMLIB_DATA,
+ #endif
 		{0}
 	};
 
 	arm_setup_page_tables(bl_regions, plat_arm_get_mmap());
 #ifdef AARCH32
-	enable_mmu_secure(0);
+	enable_mmu_svc_mon(0);
 #else
 	enable_mmu_el3(0);
 #endif /* AARCH32 */
+
+	arm_setup_romlib();
 }
 
 void bl1_plat_arch_setup(void)
diff --git a/plat/arm/common/arm_bl2_el3_setup.c b/plat/arm/common/arm_bl2_el3_setup.c
index 1c93214..c67ab49 100644
--- a/plat/arm/common/arm_bl2_el3_setup.c
+++ b/plat/arm/common/arm_bl2_el3_setup.c
@@ -82,7 +82,7 @@
 	arm_setup_page_tables(bl_regions, plat_arm_get_mmap());
 
 #ifdef AARCH32
-	enable_mmu_secure(0);
+	enable_mmu_svc_mon(0);
 #else
 	enable_mmu_el3(0);
 #endif
diff --git a/plat/arm/common/arm_bl2_setup.c b/plat/arm/common/arm_bl2_setup.c
index 39aceb3..01ae8f3 100644
--- a/plat/arm/common/arm_bl2_setup.c
+++ b/plat/arm/common/arm_bl2_setup.c
@@ -246,16 +246,22 @@
 	const mmap_region_t bl_regions[] = {
 		MAP_BL2_TOTAL,
 		ARM_MAP_BL_RO,
+#if USE_ROMLIB
+		ARM_MAP_ROMLIB_CODE,
+		ARM_MAP_ROMLIB_DATA,
+#endif
 		{0}
 	};
 
 	arm_setup_page_tables(bl_regions, plat_arm_get_mmap());
 
 #ifdef AARCH32
-	enable_mmu_secure(0);
+	enable_mmu_svc_mon(0);
 #else
 	enable_mmu_el1(0);
 #endif
+
+	arm_setup_romlib();
 }
 
 void bl2_plat_arch_setup(void)
diff --git a/plat/arm/common/arm_bl2u_setup.c b/plat/arm/common/arm_bl2u_setup.c
index a626830..b518f0f 100644
--- a/plat/arm/common/arm_bl2u_setup.c
+++ b/plat/arm/common/arm_bl2u_setup.c
@@ -73,16 +73,21 @@
 	const mmap_region_t bl_regions[] = {
 		MAP_BL2U_TOTAL,
 		ARM_MAP_BL_RO,
+#if USE_ROMLIB
+		ARM_MAP_ROMLIB_CODE,
+		ARM_MAP_ROMLIB_DATA,
+#endif
 		{0}
 	};
 
 	arm_setup_page_tables(bl_regions, plat_arm_get_mmap());
 
 #ifdef AARCH32
-	enable_mmu_secure(0);
+	enable_mmu_svc_mon(0);
 #else
 	enable_mmu_el1(0);
 #endif
+	arm_setup_romlib();
 }
 
 void bl2u_plat_arch_setup(void)
diff --git a/plat/arm/common/arm_bl31_setup.c b/plat/arm/common/arm_bl31_setup.c
index 0b64804..c7c45b0 100644
--- a/plat/arm/common/arm_bl31_setup.c
+++ b/plat/arm/common/arm_bl31_setup.c
@@ -285,9 +285,18 @@
 void arm_bl31_plat_arch_setup(void)
 {
 
+#define ARM_MAP_BL_ROMLIB	MAP_REGION_FLAT(			\
+					BL31_BASE,			\
+					BL31_END - BL31_BASE,		\
+					MT_MEMORY | MT_RW | MT_SECURE)
+
 	const mmap_region_t bl_regions[] = {
 		MAP_BL31_TOTAL,
 		ARM_MAP_BL_RO,
+#if USE_ROMLIB
+		ARM_MAP_ROMLIB_CODE,
+		ARM_MAP_ROMLIB_DATA,
+#endif
 #if USE_COHERENT_MEM
 		ARM_MAP_BL_COHERENT_RAM,
 #endif
@@ -297,6 +306,8 @@
 	arm_setup_page_tables(bl_regions, plat_arm_get_mmap());
 
 	enable_mmu_el3(0);
+
+	arm_setup_romlib();
 }
 
 void bl31_plat_arch_setup(void)
diff --git a/plat/arm/common/arm_common.c b/plat/arm/common/arm_common.c
index f83005f..ed43c37 100644
--- a/plat/arm/common/arm_common.c
+++ b/plat/arm/common/arm_common.c
@@ -10,8 +10,9 @@
 #include <debug.h>
 #include <mmio.h>
 #include <plat_arm.h>
-#include <platform_def.h>
 #include <platform.h>
+#include <platform_def.h>
+#include <romlib.h>
 #include <secure_partition.h>
 
 /* Weak definitions may be overridden in specific ARM standard platform */
@@ -23,6 +24,15 @@
 #if ERROR_DEPRECATED
 #pragma weak plat_get_syscnt_freq2
 #endif
+
+
+void arm_setup_romlib(void)
+{
+#if USE_ROMLIB
+	if (!rom_lib_init(ROMLIB_VERSION))
+		panic();
+#endif
+}
 
 /*
  * Set up the page tables for the generic and platform-specific memory regions.
diff --git a/plat/arm/common/arm_common.mk b/plat/arm/common/arm_common.mk
index 67b574d..d8eda35 100644
--- a/plat/arm/common/arm_common.mk
+++ b/plat/arm/common/arm_common.mk
@@ -185,8 +185,7 @@
 
 DYN_CFG_SOURCES		+=	plat/arm/common/arm_dyn_cfg.c		\
 				plat/arm/common/arm_dyn_cfg_helpers.c	\
-				common/fdt_wrappers.c			\
-				${LIBFDT_SRCS}
+				common/fdt_wrappers.c
 
 BL1_SOURCES		+=	${DYN_CFG_SOURCES}
 BL2_SOURCES		+=	${DYN_CFG_SOURCES}
diff --git a/plat/arm/common/sp_min/arm_sp_min_setup.c b/plat/arm/common/sp_min/arm_sp_min_setup.c
index 935290e..5191d69 100644
--- a/plat/arm/common/sp_min/arm_sp_min_setup.c
+++ b/plat/arm/common/sp_min/arm_sp_min_setup.c
@@ -212,5 +212,5 @@
 
 	arm_setup_page_tables(bl_regions, plat_arm_get_mmap());
 
-	enable_mmu_secure(0);
+	enable_mmu_svc_mon(0);
 }
diff --git a/plat/common/aarch32/plat_common.c b/plat/common/aarch32/plat_common.c
index 4f27149..16c2b5c 100644
--- a/plat/common/aarch32/plat_common.c
+++ b/plat/common/aarch32/plat_common.c
@@ -17,5 +17,5 @@
 
 void bl32_plat_enable_mmu(uint32_t flags)
 {
-	enable_mmu_secure(flags);
+	enable_mmu_svc_mon(flags);
 }
diff --git a/plat/hisilicon/hikey/hikey_bl1_setup.c b/plat/hisilicon/hikey/hikey_bl1_setup.c
index da6f6a5..ec779f4 100644
--- a/plat/hisilicon/hikey/hikey_bl1_setup.c
+++ b/plat/hisilicon/hikey/hikey_bl1_setup.c
@@ -10,11 +10,11 @@
 #include <console.h>
 #include <debug.h>
 #include <dw_mmc.h>
-#include <emmc.h>
 #include <errno.h>
 #include <hi6220.h>
 #include <hikey_def.h>
 #include <hikey_layout.h>
+#include <mmc.h>
 #include <mmio.h>
 #include <platform.h>
 #include <string.h>
@@ -97,6 +97,7 @@
 void bl1_platform_setup(void)
 {
 	dw_mmc_params_t params;
+	struct mmc_device_info info;
 
 	assert((HIKEY_BL1_MMC_DESC_BASE >= SRAM_BASE) &&
 	       ((SRAM_BASE + SRAM_SIZE) >=
@@ -115,9 +116,10 @@
 	params.desc_base = HIKEY_BL1_MMC_DESC_BASE;
 	params.desc_size = 1 << 20;
 	params.clk_rate = 24 * 1000 * 1000;
-	params.bus_width = EMMC_BUS_WIDTH_8;
-	params.flags = EMMC_FLAG_CMD23;
-	dw_mmc_init(&params);
+	params.bus_width = MMC_BUS_WIDTH_8;
+	params.flags = MMC_FLAG_CMD23;
+	info.mmc_dev_type = MMC_IS_EMMC;
+	dw_mmc_init(&params, &info);
 
 	hikey_io_setup();
 }
diff --git a/plat/hisilicon/hikey/hikey_bl2_setup.c b/plat/hisilicon/hikey/hikey_bl2_setup.c
index a3fc607..aad350b 100644
--- a/plat/hisilicon/hikey/hikey_bl2_setup.c
+++ b/plat/hisilicon/hikey/hikey_bl2_setup.c
@@ -11,11 +11,11 @@
 #include <debug.h>
 #include <desc_image_load.h>
 #include <dw_mmc.h>
-#include <emmc.h>
 #include <errno.h>
 #include <hi6220.h>
 #include <hisi_mcu.h>
 #include <hisi_sram_map.h>
+#include <mmc.h>
 #include <mmio.h>
 #ifdef SPD_opteed
 #include <optee_utils.h>
@@ -299,6 +299,7 @@
 void bl2_platform_setup(void)
 {
 	dw_mmc_params_t params;
+	struct mmc_device_info info;
 
 	hikey_sp804_init();
 	hikey_gpio_init();
@@ -328,9 +329,10 @@
 	params.desc_base = HIKEY_MMC_DESC_BASE;
 	params.desc_size = 1 << 20;
 	params.clk_rate = 24 * 1000 * 1000;
-	params.bus_width = EMMC_BUS_WIDTH_8;
-	params.flags = EMMC_FLAG_CMD23;
-	dw_mmc_init(&params);
+	params.bus_width = MMC_BUS_WIDTH_8;
+	params.flags = MMC_FLAG_CMD23;
+	info.mmc_dev_type = MMC_IS_EMMC;
+	dw_mmc_init(&params, &info);
 
 	hikey_io_setup();
 }
diff --git a/plat/hisilicon/hikey/hikey_io_storage.c b/plat/hisilicon/hikey/hikey_io_storage.c
index ef55224..3efbefe 100644
--- a/plat/hisilicon/hikey/hikey_io_storage.c
+++ b/plat/hisilicon/hikey/hikey_io_storage.c
@@ -7,7 +7,6 @@
 #include <arch_helpers.h>
 #include <assert.h>
 #include <debug.h>
-#include <emmc.h>
 #include <errno.h>
 #include <firmware_image_package.h>
 #include <io_block.h>
@@ -15,6 +14,7 @@
 #include <io_fip.h>
 #include <io_memmap.h>
 #include <io_storage.h>
+#include <mmc.h>
 #include <mmio.h>
 #include <platform_def.h>
 #include <semihosting.h>	/* For FOPEN_MODE_... */
@@ -59,10 +59,10 @@
 	},
 #endif
 	.ops		= {
-		.read	= emmc_read_blocks,
-		.write	= emmc_write_blocks,
+		.read	= mmc_read_blocks,
+		.write	= mmc_write_blocks,
 	},
-	.block_size	= EMMC_BLOCK_SIZE,
+	.block_size	= MMC_BLOCK_SIZE,
 };
 
 static const io_uuid_spec_t bl31_uuid_spec = {
diff --git a/plat/hisilicon/hikey/hisi_ipc.c b/plat/hisilicon/hikey/hisi_ipc.c
index 0469a08..4936f83 100644
--- a/plat/hisilicon/hikey/hisi_ipc.c
+++ b/plat/hisilicon/hikey/hisi_ipc.c
@@ -1,16 +1,16 @@
 /*
- * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
 #include <arch_helpers.h>
+#include <debug.h>
 #include <hisi_ipc.h>
 #include <hisi_sram_map.h>
 #include <mmio.h>
 #include <platform_def.h>
 #include <stdarg.h>
-#include <stdio.h>
 #include <string.h>
 
 static int ipc_init;
@@ -63,7 +63,7 @@
 static void hisi_ipc_send(unsigned int ipc_num)
 {
 	if (!ipc_init) {
-		printf("error ipc base is null!!!\n");
+		tf_printf("error ipc base is null!!!\n");
 		return;
 	}
 
diff --git a/plat/hisilicon/hikey/platform.mk b/plat/hisilicon/hikey/platform.mk
index 6a2474e..ccc7296 100644
--- a/plat/hisilicon/hikey/platform.mk
+++ b/plat/hisilicon/hikey/platform.mk
@@ -65,7 +65,7 @@
 				drivers/io/io_block.c			\
 				drivers/io/io_fip.c			\
 				drivers/io/io_storage.c			\
-				drivers/emmc/emmc.c			\
+				drivers/mmc/mmc.c			\
 				drivers/synopsys/emmc/dw_mmc.c		\
 				lib/cpus/aarch64/cortex_a53.S		\
 				plat/hisilicon/hikey/aarch64/hikey_helpers.S \
@@ -81,7 +81,7 @@
 				drivers/io/io_block.c			\
 				drivers/io/io_fip.c			\
 				drivers/io/io_storage.c			\
-				drivers/emmc/emmc.c			\
+				drivers/mmc/mmc.c			\
 				drivers/synopsys/emmc/dw_mmc.c		\
 				lib/cpus/aarch64/cortex_a53.S		\
 				plat/hisilicon/hikey/aarch64/hikey_helpers.S \
diff --git a/plat/hisilicon/poplar/bl1_plat_setup.c b/plat/hisilicon/poplar/bl1_plat_setup.c
index 25eed59..6fc4f33 100644
--- a/plat/hisilicon/poplar/bl1_plat_setup.c
+++ b/plat/hisilicon/poplar/bl1_plat_setup.c
@@ -10,9 +10,9 @@
 #include <console.h>
 #include <debug.h>
 #include <dw_mmc.h>
-#include <emmc.h>
 #include <errno.h>
 #include <generic_delay_timer.h>
+#include <mmc.h>
 #include <mmio.h>
 #include <pl061_gpio.h>
 #include <platform.h>
@@ -92,6 +92,7 @@
 void bl1_platform_setup(void)
 {
 	int i;
+	struct mmc_device_info info;
 #if !POPLAR_RECOVERY
 	dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE);
 #endif
@@ -105,7 +106,8 @@
 #if !POPLAR_RECOVERY
 	/* SoC-specific emmc register are initialized/configured by bootrom */
 	INFO("BL1: initializing emmc\n");
-	dw_mmc_init(&params);
+	info.mmc_dev_type = MMC_IS_EMMC;
+	dw_mmc_init(&params, &info);
 #endif
 
 	plat_io_setup();
diff --git a/plat/hisilicon/poplar/bl2_plat_setup.c b/plat/hisilicon/poplar/bl2_plat_setup.c
index 2671994..041ed4a 100644
--- a/plat/hisilicon/poplar/bl2_plat_setup.c
+++ b/plat/hisilicon/poplar/bl2_plat_setup.c
@@ -11,9 +11,9 @@
 #include <debug.h>
 #include <desc_image_load.h>
 #include <dw_mmc.h>
-#include <emmc.h>
 #include <errno.h>
 #include <generic_delay_timer.h>
+#include <mmc.h>
 #include <mmio.h>
 #include <optee_utils.h>
 #include <partition/partition.h>
@@ -333,6 +333,8 @@
 
 void bl2_early_platform_setup(meminfo_t *mem_layout)
 {
+	struct mmc_device_info info;
+
 #if !POPLAR_RECOVERY
 	dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE);
 #endif
@@ -347,7 +349,8 @@
 #if !POPLAR_RECOVERY
 	/* SoC-specific emmc register are initialized/configured by bootrom */
 	INFO("BL2: initializing emmc\n");
-	dw_mmc_init(&params);
+	info.mmc_dev_type = MMC_IS_EMMC;
+	dw_mmc_init(&params, &info);
 #endif
 
 	plat_io_setup();
diff --git a/plat/hisilicon/poplar/include/hi3798cv200.h b/plat/hisilicon/poplar/include/hi3798cv200.h
index 125b048..254b357 100644
--- a/plat/hisilicon/poplar/include/hi3798cv200.h
+++ b/plat/hisilicon/poplar/include/hi3798cv200.h
@@ -67,11 +67,11 @@
 
 #define EMMC_DESC_SIZE			U(0x00100000) /* 1MB */
 #define EMMC_INIT_PARAMS(base)				\
-	{	.bus_width = EMMC_BUS_WIDTH_8,		\
+	{	.bus_width = MMC_BUS_WIDTH_8,		\
 		.clk_rate = 25 * 1000 * 1000,		\
 		.desc_base = (base),	\
 		.desc_size = EMMC_DESC_SIZE,		\
-		.flags =  EMMC_FLAG_CMD23,		\
+		.flags =  MMC_FLAG_CMD23,		\
 		.reg_base = REG_BASE_MCI,		\
 	}
 
diff --git a/plat/hisilicon/poplar/plat_storage.c b/plat/hisilicon/poplar/plat_storage.c
index db52c67..925274c 100644
--- a/plat/hisilicon/poplar/plat_storage.c
+++ b/plat/hisilicon/poplar/plat_storage.c
@@ -7,13 +7,13 @@
 #include <arch_helpers.h>
 #include <assert.h>
 #include <debug.h>
-#include <emmc.h>
 #include <firmware_image_package.h>
 #include <io_block.h>
 #include <io_driver.h>
 #include <io_fip.h>
 #include <io_memmap.h>
 #include <io_storage.h>
+#include <mmc.h>
 #include <mmio.h>
 #include <partition/partition.h>
 #include <semihosting.h>
@@ -38,10 +38,10 @@
 		.length	= POPLAR_EMMC_DATA_SIZE,
 	},
 	.ops		= {
-		.read	= emmc_read_blocks,
-		.write	= emmc_write_blocks,
+		.read	= mmc_read_blocks,
+		.write	= mmc_write_blocks,
 	},
-	.block_size	= EMMC_BLOCK_SIZE,
+	.block_size	= MMC_BLOCK_SIZE,
 };
 #else
 static const io_dev_connector_t *mmap_dev_con;
diff --git a/plat/hisilicon/poplar/platform.mk b/plat/hisilicon/poplar/platform.mk
index 14ffa99..3cdbe59 100644
--- a/plat/hisilicon/poplar/platform.mk
+++ b/plat/hisilicon/poplar/platform.mk
@@ -82,7 +82,7 @@
 BL1_SOURCES	+=							\
 		lib/cpus/aarch64/cortex_a53.S				\
 		drivers/arm/pl061/pl061_gpio.c				\
-		drivers/emmc/emmc.c					\
+		drivers/mmc/mmc.c					\
 		drivers/synopsys/emmc/dw_mmc.c				\
 		drivers/io/io_storage.c					\
 		drivers/io/io_block.c					\
@@ -94,7 +94,7 @@
 
 BL2_SOURCES	+=      						\
 		drivers/arm/pl061/pl061_gpio.c				\
-		drivers/emmc/emmc.c					\
+		drivers/mmc/mmc.c					\
 		drivers/synopsys/emmc/dw_mmc.c				\
 		drivers/io/io_storage.c					\
 		drivers/io/io_block.c					\
diff --git a/plat/layerscape/common/ls_bl1_setup.c b/plat/layerscape/common/ls_bl1_setup.c
index 43f7450..0642b5e 100644
--- a/plat/layerscape/common/ls_bl1_setup.c
+++ b/plat/layerscape/common/ls_bl1_setup.c
@@ -59,7 +59,7 @@
 			     );
 	VERBOSE("After setup the page tables\n");
 #ifdef AARCH32
-	enable_mmu_secure(0);
+	enable_mmu_svc_mon(0);
 #else
 	enable_mmu_el3(0);
 #endif /* AARCH32 */
diff --git a/plat/layerscape/common/ls_bl2_setup.c b/plat/layerscape/common/ls_bl2_setup.c
index 6e6ad6e..4b2dc72 100644
--- a/plat/layerscape/common/ls_bl2_setup.c
+++ b/plat/layerscape/common/ls_bl2_setup.c
@@ -53,7 +53,7 @@
 			      );
 
 #ifdef AARCH32
-	enable_mmu_secure(0);
+	enable_mmu_svc_mon(0);
 #else
 	enable_mmu_el1(0);
 #endif
diff --git a/plat/marvell/a8k/common/mss/mss_bl2_setup.c b/plat/marvell/a8k/common/mss/mss_bl2_setup.c
index 6688551..2154185 100644
--- a/plat/marvell/a8k/common/mss/mss_bl2_setup.c
+++ b/plat/marvell/a8k/common/mss/mss_bl2_setup.c
@@ -85,7 +85,6 @@
 	int ret;
 
 	INFO("BL2: Initiating SCP_BL2 transfer to SCP\n");
-	printf("BL2: Initiating SCP_BL2 transfer to SCP\n");
 
 	/* initialize time (for delay functionality) */
 	plat_delay_timer_init();
diff --git a/plat/qemu/platform.mk b/plat/qemu/platform.mk
index 379ab3d..1d46eec 100644
--- a/plat/qemu/platform.mk
+++ b/plat/qemu/platform.mk
@@ -132,8 +132,7 @@
 				plat/qemu/qemu_io_storage.c		\
 				plat/qemu/${ARCH}/plat_helpers.S	\
 				plat/qemu/qemu_bl2_setup.c		\
-				plat/qemu/dt.c				\
-				$(LIBFDT_SRCS)
+				plat/qemu/dt.c
 ifeq (${LOAD_IMAGE_V2},1)
 BL2_SOURCES		+=	plat/qemu/qemu_bl2_mem_params_desc.c	\
 				plat/qemu/qemu_image_load.c		\
diff --git a/plat/st/stm32mp1/stm32mp1_common.c b/plat/st/stm32mp1/stm32mp1_common.c
index 68ca7db..7d84da1 100644
--- a/plat/st/stm32mp1/stm32mp1_common.c
+++ b/plat/st/stm32mp1/stm32mp1_common.c
@@ -74,7 +74,7 @@
 	mmap_add(stm32mp1_mmap);
 	init_xlat_tables();
 
-	enable_mmu_secure(0);
+	enable_mmu_svc_mon(0);
 }
 
 uintptr_t plat_get_ns_image_entrypoint(void)
diff --git a/readme.rst b/readme.rst
index a82af64..4897f36 100644
--- a/readme.rst
+++ b/readme.rst
@@ -228,6 +228,13 @@
 project and the `Acknowledgments`_ file for a list of contributors to the
 project.
 
+IRC channel
+~~~~~~~~~~~
+
+Development discussion takes place on the #trusted-firmware-a channel
+on the Freenode IRC network. This is not an official support channel.
+If you have an issue to raise, please use the `GitHub issue tracker`_.
+
 Feedback and support
 ~~~~~~~~~~~~~~~~~~~~
 
diff --git a/services/spd/trusty/generic-arm64-smcall.c b/services/spd/trusty/generic-arm64-smcall.c
index feeecaa..1362c1c 100644
--- a/services/spd/trusty/generic-arm64-smcall.c
+++ b/services/spd/trusty/generic-arm64-smcall.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -29,14 +29,14 @@
 	s->linebuf[s->l++] = ch;
 	if (s->l == sizeof(s->linebuf) || ch == '\n') {
 		if (secure)
-			printf("secure os: ");
+			tf_printf("secure os: ");
 		else
-			printf("non-secure os: ");
+			tf_printf("non-secure os: ");
 		for (i = 0; i < s->l; i++) {
 			putchar(s->linebuf[i]);
 		}
 		if (ch != '\n') {
-			printf(" <...>\n");
+			tf_printf(" <...>\n");
 		}
 		s->l = 0;
 	}