Index: bsps/riscv/riscv/console/console-config.c
===================================================================
--- bsps/riscv/riscv/console/console-config.c	(revision 1232cd46905cc5a59dae2195c39eb5dd5742a754)
+++ bsps/riscv/riscv/console/console-config.c	(revision 1232cd46905cc5a59dae2195c39eb5dd5742a754)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <info@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <rtems/bspIo.h>
+#include <rtems/console.h>
+#include <rtems/sysinit.h>
+#include <rtems/termiostypes.h>
+
+#include <bsp.h>
+#include <bsp/fdt.h>
+#include <bsp/irq.h>
+
+#include <dev/serial/htif.h>
+
+#include <libfdt.h>
+
+#if RISCV_ENABLE_HTIF_SUPPORT > 0
+static htif_console_context htif_console_instance;
+#endif
+
+static struct {
+  rtems_termios_device_context *context;
+  void (*write_polled)(
+    rtems_termios_device_context *base,
+    const char *buf,
+    size_t len
+  );
+  int (*poll_char)(rtems_termios_device_context *base);
+} riscv_console;
+
+static void riscv_output_char(char c)
+{
+  (*riscv_console.write_polled)(riscv_console.context, &c, 1);
+}
+
+static int riscv_get_console_node(const void *fdt)
+{
+  const char *stdout_path;
+  int node;
+
+  node = fdt_path_offset(fdt, "/chosen");
+
+  stdout_path = fdt_getprop(fdt, node, "stdout-path", NULL);
+  if (stdout_path == NULL) {
+    stdout_path = "";
+  }
+
+  return fdt_path_offset(fdt, stdout_path);
+}
+
+static void riscv_console_probe(void)
+{
+  const void *fdt;
+  int node;
+  int console_node;
+
+  fdt = bsp_fdt_get();
+  console_node = riscv_get_console_node(fdt);
+
+  node = fdt_next_node(fdt, -1, NULL);
+
+  while (node >= 0) {
+#if RISCV_ENABLE_HTIF_SUPPORT
+    if (fdt_node_check_compatible(fdt, node, "ucb,htif0") == 0) {
+      htif_console_context_init(&htif_console_instance.base, node);
+
+      riscv_console.context = &htif_console_instance.base;
+      riscv_console.write_polled = htif_console_write_polled;
+      riscv_console.poll_char = htif_console_poll_char;
+    };
+#endif
+
+    node = fdt_next_node(fdt, node, NULL);
+  }
+
+  BSP_output_char = riscv_output_char;
+}
+
+static void riscv_output_char_init(char c)
+{
+  riscv_console_probe();
+  riscv_output_char(c);
+}
+
+BSP_output_char_function_type BSP_output_char = riscv_output_char_init;
+
+BSP_polling_getchar_function_type BSP_poll_char = NULL;
+
+rtems_status_code console_initialize(
+  rtems_device_major_number major,
+  rtems_device_minor_number minor,
+  void *arg
+)
+{
+  rtems_termios_device_context *base;
+  char htif_path[] = "/dev/ttyShtif";
+
+  rtems_termios_initialize();
+
+#if RISCV_ENABLE_HTIF_SUPPORT
+  base = &htif_console_instance.base;
+  rtems_termios_device_install(htif_path, &htif_console_handler, NULL, base);
+
+  if (base == riscv_console.context) {
+    link(htif_path, CONSOLE_DEVICE_NAME);
+  }
+#endif
+
+  return RTEMS_SUCCESSFUL;
+}
+
+RTEMS_SYSINIT_ITEM(
+  riscv_console_probe,
+  RTEMS_SYSINIT_BSP_START,
+  RTEMS_SYSINIT_ORDER_LAST
+);
Index: ps/riscv/riscv/console/console-io.c
===================================================================
--- bsps/riscv/riscv/console/console-io.c	(revision c558cc4b00f00b6746eec3a249a7a79995cea7cf)
+++ 	(revision )
@@ -1,162 +1,0 @@
-/*
- * Copyright (c) 2015 University of York.
- * Hesham Almatary <hesham@alumni.york.ac.uk>
- *
- * Copyright (c) 2013, The Regents of the University of California (Regents).
- * All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <bsp.h>
-#include <bsp/console-polled.h>
-#include <rtems/libio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <stdio.h>
-
-/* Most of the code below is copied from riscv-pk project */
-# define TOHOST_CMD(dev, cmd, payload) \
-  (((uint64_t)(dev) << 56) | ((uint64_t)(cmd) << 48) | (uint64_t)(payload))
-
-#define FROMHOST_DEV(fromhost_value) ((uint64_t)(fromhost_value) >> 56)
-#define FROMHOST_CMD(fromhost_value) ((uint64_t)(fromhost_value) << 8 >> 56)
-#define FROMHOST_DATA(fromhost_value) ((uint64_t)(fromhost_value) << 16 >> 16)
-
-volatile uint64_t tohost __attribute__((section(".htif")));
-volatile uint64_t fromhost __attribute__((section(".htif")));
-volatile uint64_t riscv_fill_up_htif_section[510] __attribute__((section(".htif")));
-volatile int htif_console_buf;
-
-static void __check_fromhost(void)
-{
-  uint64_t fh = fromhost;
-  if (!fh) {
-    return;
-  }
-  fromhost = 0;
-
-  // this should be from the console
-  assert(FROMHOST_DEV(fh) == 1);
-  switch (FROMHOST_CMD(fh)) {
-  case 0:
-    htif_console_buf = 1 + (uint8_t)FROMHOST_DATA(fh);
-    break;
-  case 1:
-    break;
-  default:
-    assert(0);
-  }
-}
-
-static void __set_tohost(uintptr_t dev, uintptr_t cmd, uintptr_t data)
-{
-  while (tohost) {
-    __check_fromhost();
-  }
-  tohost = TOHOST_CMD(dev, cmd, data);
-}
-
-static int htif_console_getchar(void)
-{
-  __check_fromhost();
-  int ch = htif_console_buf;
-  if (ch >= 0) {
-    htif_console_buf = -1;
-    __set_tohost(1, 0, 0);
-  }
-
-  return ch - 1;
-}
-
-static void htif_console_putchar(uint8_t ch)
-{
-  __set_tohost(1, 1, ch);
-}
-
-void htif_poweroff(void)
-{
-  while (1) {
-    fromhost = 0;
-    tohost = 1;
-  }
-}
-
-void console_initialize_hardware(void)
-{
-  /* Do nothing */
-}
-
-static void outbyte_console(char ch)
-{
-  htif_console_putchar(ch);
-}
-
-static char inbyte_console(void)
-{
-  return htif_console_getchar();
-}
-
-/*
- *  console_outbyte_polled
- *
- *  This routine transmits a character using polling.
- */
-void console_outbyte_polled(
-  int  port,
-  char ch
-)
-{
-  outbyte_console( ch );
-}
-
-/*
- *  console_inbyte_nonblocking
- *
- *  This routine polls for a character.
- */
-
-int console_inbyte_nonblocking(int port)
-{
-  char c;
-
-  c = inbyte_console();
-  if (!c) {
-    return -1;
-  }
-  return (int) c;
-}
-
-/*
- *  To support printk
- */
-
-#include <rtems/bspIo.h>
-
-static void RISCV_output_char(char c)
-{
-  console_outbyte_polled( 0, c );
-}
-
-BSP_output_char_function_type BSP_output_char = RISCV_output_char;
-BSP_polling_getchar_function_type BSP_poll_char =
-  (void *)console_inbyte_nonblocking;
Index: bsps/riscv/riscv/console/htif.c
===================================================================
--- bsps/riscv/riscv/console/htif.c	(revision 1232cd46905cc5a59dae2195c39eb5dd5742a754)
+++ bsps/riscv/riscv/console/htif.c	(revision 1232cd46905cc5a59dae2195c39eb5dd5742a754)
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2015 University of York.
+ * Hesham Almatary <hesham@alumni.york.ac.uk>
+ *
+ * Copyright (c) 2013, The Regents of the University of California (Regents).
+ * All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <dev/serial/htif.h>
+
+#include <assert.h>
+
+/* Most of the code below is copied from riscv-pk project */
+# define TOHOST_CMD(dev, cmd, payload) \
+  (((uint64_t)(dev) << 56) | ((uint64_t)(cmd) << 48) | (uint64_t)(payload))
+
+#define FROMHOST_DEV(fromhost_value) ((uint64_t)(fromhost_value) >> 56)
+#define FROMHOST_CMD(fromhost_value) ((uint64_t)(fromhost_value) << 8 >> 56)
+#define FROMHOST_DATA(fromhost_value) ((uint64_t)(fromhost_value) << 16 >> 16)
+
+volatile uint64_t tohost __attribute__((section(".htif")));
+volatile uint64_t fromhost __attribute__((section(".htif")));
+volatile uint64_t riscv_fill_up_htif_section[510] __attribute__((section(".htif")));
+volatile int htif_console_buf;
+
+static void __check_fromhost(void)
+{
+  uint64_t fh = fromhost;
+  if (!fh) {
+    return;
+  }
+  fromhost = 0;
+
+  // this should be from the console
+  assert(FROMHOST_DEV(fh) == 1);
+  switch (FROMHOST_CMD(fh)) {
+  case 0:
+    htif_console_buf = 1 + (uint8_t)FROMHOST_DATA(fh);
+    break;
+  case 1:
+    break;
+  default:
+    assert(0);
+  }
+}
+
+static void __set_tohost(uintptr_t dev, uintptr_t cmd, uintptr_t data)
+{
+  while (tohost) {
+    __check_fromhost();
+  }
+  tohost = TOHOST_CMD(dev, cmd, data);
+}
+
+int htif_console_poll_char(rtems_termios_device_context *base)
+{
+  __check_fromhost();
+  int ch = htif_console_buf;
+  if (ch >= 0) {
+    htif_console_buf = -1;
+    __set_tohost(1, 0, 0);
+  }
+
+  return ch - 1;
+}
+
+void htif_console_write_polled(
+  rtems_termios_device_context *base,
+  const char *buf,
+  size_t len
+)
+{
+  size_t i;
+
+  for (i = 0; i < len; ++i) {
+    __set_tohost(1, 1, buf[i]);
+  }
+}
+
+void htif_poweroff(void)
+{
+  while (1) {
+    fromhost = 0;
+    tohost = 1;
+  }
+}
+
+void htif_console_context_init(
+  rtems_termios_device_context *base,
+  int device_tree_node
+)
+{
+  rtems_termios_device_context_initialize(base, "HTIF");
+}
+
+static bool htif_console_first_open(
+  struct rtems_termios_tty *tty,
+  rtems_termios_device_context *base,
+  struct termios *term,
+  rtems_libio_open_close_args_t *args
+)
+{
+  return true;
+}
+
+const rtems_termios_device_handler htif_console_handler = {
+  .first_open = htif_console_first_open,
+  .write = htif_console_write_polled,
+  .poll_read = htif_console_poll_char,
+  .mode = TERMIOS_POLLED
+};
Index: bsps/riscv/riscv/include/dev/serial/htif.h
===================================================================
--- bsps/riscv/riscv/include/dev/serial/htif.h	(revision 1232cd46905cc5a59dae2195c39eb5dd5742a754)
+++ bsps/riscv/riscv/include/dev/serial/htif.h	(revision 1232cd46905cc5a59dae2195c39eb5dd5742a754)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <rtems/termiostypes.h>
+
+#ifndef DEV_SERIAL_HTIF_H
+#define DEV_SERIAL_HTIF_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef struct {
+  rtems_termios_device_context base;
+} htif_console_context;
+
+void htif_console_context_init(
+  rtems_termios_device_context *base,
+  int device_tree_node
+);
+
+void htif_console_write_polled(
+  rtems_termios_device_context *base,
+  const char *buf,
+  size_t len
+);
+
+int htif_console_poll_char(rtems_termios_device_context *base);
+
+const rtems_termios_device_handler htif_console_handler;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* DEV_SERIAL_HTIF_H */
Index: c/src/lib/libbsp/riscv/riscv/Makefile.am
===================================================================
--- c/src/lib/libbsp/riscv/riscv/Makefile.am	(revision c558cc4b00f00b6746eec3a249a7a79995cea7cf)
+++ c/src/lib/libbsp/riscv/riscv/Makefile.am	(revision 1232cd46905cc5a59dae2195c39eb5dd5742a754)
@@ -50,7 +50,4 @@
 librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/btimer/btimer.c
 
-# console
-librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-polled.c
-
 # IRQ
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-default-handler.c
@@ -60,6 +57,8 @@
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/cache/nocache.c
 
-# debugio
-librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/console/console-io.c
+# Console
+librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termios.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/console/console-config.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/console/htif.c
 
 if HAS_SMP
Index: c/src/lib/libbsp/riscv/riscv/configure.ac
===================================================================
--- c/src/lib/libbsp/riscv/riscv/configure.ac	(revision c558cc4b00f00b6746eec3a249a7a79995cea7cf)
+++ c/src/lib/libbsp/riscv/riscv/configure.ac	(revision 1232cd46905cc5a59dae2195c39eb5dd5742a754)
@@ -28,4 +28,7 @@
 RTEMS_BSPOPTS_HELP([BSP_FDT_BLOB_COPY_TO_READ_ONLY_LOAD_AREA],[copy the FDT blob into the read-only load area via bsp_fdt_copy()])
 
+RTEMS_BSPOPTS_SET([RISCV_ENABLE_HTIF_SUPPORT],[*],[1])
+RTEMS_BSPOPTS_HELP([RISCV_ENABLE_HTIF_SUPPORT],[enables the HTIF support if defined to a non-zero value, otherwise it is disabled (enabled by default)])
+
 RTEMS_BSP_CLEANUP_OPTIONS
 
