Re: [PATCH] bsp/raspberry: Enabled FDT support for console.

2020-01-03 Thread Niteesh
On Fri, Jan 3, 2020 at 1:51 PM Christian Mauderer 
wrote:

> On 03/01/2020 04:50, Niteesh wrote:
> > On Fri, Jan 3, 2020 at 2:26 AM Christian Mauderer  > > wrote:
> >
> > Sorry, it seems I missed some parts in the last mail. Beneath that I
> > caused a misunderstanding again.
> >
> > On 02/01/2020 20:08, G S Niteesh wrote:
> > > Replaced the older console api with newer FDT based
> > > console driver.
> > > Replaces the custom pl011 driver with RTEMS arm-pl011
> > > driver.
> > > ---
> > >  bsps/arm/raspberrypi/console/console-config.c | 156
> 
> > >  bsps/arm/raspberrypi/console/console_select.c | 114 
> > >  bsps/arm/raspberrypi/console/fbcons.c |  78 
> > >  bsps/arm/raspberrypi/console/usart.c  | 167
> > --
> > >  bsps/arm/raspberrypi/include/bsp.h|   6 +
> > >  bsps/arm/raspberrypi/include/bsp/fbcons.h |  17 +-
> > >  .../arm/raspberrypi/include/bsp/raspberrypi.h |  53 ++
> > >  bsps/arm/raspberrypi/include/bsp/usart.h  |   5 +-
> > >  bsps/arm/raspberrypi/start/bspstart.c |  15 ++
> > >  c/src/lib/libbsp/arm/raspberrypi/Makefile.am  |   7 +-
> > >  c/src/lib/libbsp/arm/raspberrypi/configure.ac
> >  |  13 ++
> > >  11 files changed, 225 insertions(+), 406 deletions(-)
> > >  delete mode 100644 bsps/arm/raspberrypi/console/console_select.c
> > >  delete mode 100644 bsps/arm/raspberrypi/console/usart.c
> > >
> > > diff --git a/bsps/arm/raspberrypi/console/console-config.c
> > b/bsps/arm/raspberrypi/console/console-config.c
> > > index d2186c918b..c306db439b 100644
> > > --- a/bsps/arm/raspberrypi/console/console-config.c
> > > +++ b/bsps/arm/raspberrypi/console/console-config.c
> > > @@ -19,50 +19,140 @@
> > >   */
> > >
> > >  #include 
> > > -
> > > -#include 
> > > +#include 
> > > +#include 
> > >
> > >  #include 
> > > -#include 
> > > -#include 
> > > +#include 
> > >  #include 
> > > +#include 
> > > +#include 
> > >  #include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +#include 
> > > +#include 
> > > +
> > > +arm_pl011_context pl011_context;
> > > +
> > > +rpi_fb_context fb_context;
> > > +
> > > +static void output_char_serial(char c)
> > > +{
> > > +  arm_pl011_write_polled(_context.base, c);
> > > +}
> > > +
> > > +void output_char_fb(char c)
> > > +{
> > > +  fbcons_write_polled(_context.base, c);
> > > +}
> > > +
> > > +static void init_ctx_arm_pl011(
> > > +  const void *fdt,
> > > +  int node
> > > +)
> > > +{
> > > +  arm_pl011_context *ctx = _context;
> > > +  rtems_termios_device_context_initialize(>base, "UART");
> > > +  ctx->regs = raspberrypi_get_reg_of_node(fdt, node);
> > > +}
> > > +
> > > +static void register_fb( void )
> > > +{
> > > +  if (fbcons_probe(_context.base) == true) {
> > > +rtems_termios_device_install(
> > > +  "/dev/fbcons",
> > > +  _fns,
> > > +  NULL,
> > > +  _context.base);
> > > +  }
> > > +}
> > >
> > > -console_tbl Console_Configuration_Ports [] = {
> > > -{
> > > -  .sDeviceName = "/dev/ttyS0",
> > > -  .deviceType = SERIAL_CUSTOM,
> > > -  .pDeviceFns = _usart_fns,
> > > -  .deviceProbe = NULL,
> > > -  .pDeviceFlow = NULL,
> > > -  .ulCtrlPort1 = BCM2835_UART0_BASE,
> > > -  .ulCtrlPort2 = 0,
> > > -  .ulClock = USART0_DEFAULT_BAUD,
> > > -  .ulIntVector = BCM2835_IRQ_ID_UART
> > > -},
> > > -{
> > > -  .sDeviceName ="/dev/fbcons",
> > > -  .deviceType = SERIAL_CUSTOM,
> > > -  .pDeviceFns = _fns,
> > > -  .deviceProbe = fbcons_probe,
> > > -  .pDeviceFlow = NULL,
> > > -},
> > > -};
> > > -
> > > -#define PORT_COUNT \
> > > -  (sizeof(Console_Configuration_Ports) \
> > > -/ sizeof(Console_Configuration_Ports [0]))
> > > -
> > > -unsigned long Console_Configuration_Count = PORT_COUNT;
> > > +static void console_select( void )
> > > +{
> > > +  const char *opt;
> > > +  const void *fdt;
> > > +  const char *console;
> > > +  int node;
> > > +
> > > +  fdt = bsp_fdt_get();
> > > +  node = fdt_path_offset(fdt, "/chosen");
> > > +
> > > +  console = fdt_getprop(fdt, node, "stdout-path", NULL);
> >
> > Sorry that I missed that on your earlier patch:
> >
> > I had a look at all the "chosen" nodes in the dtb files here:
> >
> >
> https://github.com/raspberrypi/firmware/tree/0c01dbefba45a08c47f8538d5a071a0fba6b7e83/boot
> >
> >
> > I was using the dtb file from freeBSD, that one had the chosen 

Re: [PATCH] bsp/raspberry: Enabled FDT support for console.

2020-01-03 Thread Christian Mauderer
On 03/01/2020 04:50, Niteesh wrote:
> On Fri, Jan 3, 2020 at 2:26 AM Christian Mauderer  > wrote:
> 
> Sorry, it seems I missed some parts in the last mail. Beneath that I
> caused a misunderstanding again.
> 
> On 02/01/2020 20:08, G S Niteesh wrote:
> > Replaced the older console api with newer FDT based
> > console driver.
> > Replaces the custom pl011 driver with RTEMS arm-pl011
> > driver.
> > ---
> >  bsps/arm/raspberrypi/console/console-config.c | 156 
> >  bsps/arm/raspberrypi/console/console_select.c | 114 
> >  bsps/arm/raspberrypi/console/fbcons.c         |  78 
> >  bsps/arm/raspberrypi/console/usart.c          | 167
> --
> >  bsps/arm/raspberrypi/include/bsp.h            |   6 +
> >  bsps/arm/raspberrypi/include/bsp/fbcons.h     |  17 +-
> >  .../arm/raspberrypi/include/bsp/raspberrypi.h |  53 ++
> >  bsps/arm/raspberrypi/include/bsp/usart.h      |   5 +-
> >  bsps/arm/raspberrypi/start/bspstart.c         |  15 ++
> >  c/src/lib/libbsp/arm/raspberrypi/Makefile.am  |   7 +-
> >  c/src/lib/libbsp/arm/raspberrypi/configure.ac
>  |  13 ++
> >  11 files changed, 225 insertions(+), 406 deletions(-)
> >  delete mode 100644 bsps/arm/raspberrypi/console/console_select.c
> >  delete mode 100644 bsps/arm/raspberrypi/console/usart.c
> >
> > diff --git a/bsps/arm/raspberrypi/console/console-config.c
> b/bsps/arm/raspberrypi/console/console-config.c
> > index d2186c918b..c306db439b 100644
> > --- a/bsps/arm/raspberrypi/console/console-config.c
> > +++ b/bsps/arm/raspberrypi/console/console-config.c
> > @@ -19,50 +19,140 @@
> >   */
> > 
> >  #include 
> > -
> > -#include 
> > +#include 
> > +#include 
> > 
> >  #include 
> > -#include 
> > -#include 
> > +#include 
> >  #include 
> > +#include 
> > +#include 
> >  #include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +
> > +arm_pl011_context pl011_context;
> > +
> > +rpi_fb_context fb_context;
> > +
> > +static void output_char_serial(char c)
> > +{
> > +  arm_pl011_write_polled(_context.base, c);
> > +}
> > +
> > +void output_char_fb(char c)
> > +{
> > +  fbcons_write_polled(_context.base, c);
> > +}
> > +
> > +static void init_ctx_arm_pl011(
> > +  const void *fdt,
> > +  int node
> > +)
> > +{
> > +  arm_pl011_context *ctx = _context;
> > +  rtems_termios_device_context_initialize(>base, "UART");
> > +  ctx->regs = raspberrypi_get_reg_of_node(fdt, node);
> > +}
> > +
> > +static void register_fb( void )
> > +{
> > +  if (fbcons_probe(_context.base) == true) {
> > +    rtems_termios_device_install(
> > +      "/dev/fbcons",
> > +      _fns,
> > +      NULL,
> > +      _context.base);
> > +  }
> > +}
> > 
> > -console_tbl Console_Configuration_Ports [] = {
> > -    {
> > -      .sDeviceName = "/dev/ttyS0",
> > -      .deviceType = SERIAL_CUSTOM,
> > -      .pDeviceFns = _usart_fns,
> > -      .deviceProbe = NULL,
> > -      .pDeviceFlow = NULL,
> > -      .ulCtrlPort1 = BCM2835_UART0_BASE,
> > -      .ulCtrlPort2 = 0,
> > -      .ulClock = USART0_DEFAULT_BAUD,
> > -      .ulIntVector = BCM2835_IRQ_ID_UART
> > -    },
> > -    {
> > -      .sDeviceName ="/dev/fbcons",
> > -      .deviceType = SERIAL_CUSTOM,
> > -      .pDeviceFns = _fns,
> > -      .deviceProbe = fbcons_probe,
> > -      .pDeviceFlow = NULL,
> > -    },
> > -};
> > -
> > -#define PORT_COUNT \
> > -  (sizeof(Console_Configuration_Ports) \
> > -    / sizeof(Console_Configuration_Ports [0]))
> > -
> > -unsigned long Console_Configuration_Count = PORT_COUNT;
> > +static void console_select( void )
> > +{
> > +  const char *opt;
> > +  const void *fdt;
> > +  const char *console;
> > +  int node;
> > +
> > +  fdt = bsp_fdt_get();
> > +  node = fdt_path_offset(fdt, "/chosen");
> > +
> > +  console = fdt_getprop(fdt, node, "stdout-path", NULL);
> 
> Sorry that I missed that on your earlier patch:
> 
> I had a look at all the "chosen" nodes in the dtb files here:
> 
> 
> https://github.com/raspberrypi/firmware/tree/0c01dbefba45a08c47f8538d5a071a0fba6b7e83/boot
> 
> 
> I was using the dtb file from freeBSD, that one had the chosen node.
> https://github.com/freebsd/freebsd/blob/41655e1cf1451b788f6437c91ec74bcecd2192b7/sys/gnu/dts/arm/bcm283x.dtsi#L31
> But there is no standalone DTB file from freeBSD, we have to build it so
> I'll move to the DTB
> that you mentioned, since it's more commonly used. 

OK. How did you change that? Did you remove it 

Re: [PATCH] bsp/raspberry: Enabled FDT support for console.

2020-01-02 Thread Niteesh
On Fri, Jan 3, 2020 at 2:26 AM Christian Mauderer 
wrote:

> Sorry, it seems I missed some parts in the last mail. Beneath that I
> caused a misunderstanding again.
>
> On 02/01/2020 20:08, G S Niteesh wrote:
> > Replaced the older console api with newer FDT based
> > console driver.
> > Replaces the custom pl011 driver with RTEMS arm-pl011
> > driver.
> > ---
> >  bsps/arm/raspberrypi/console/console-config.c | 156 
> >  bsps/arm/raspberrypi/console/console_select.c | 114 
> >  bsps/arm/raspberrypi/console/fbcons.c |  78 
> >  bsps/arm/raspberrypi/console/usart.c  | 167 --
> >  bsps/arm/raspberrypi/include/bsp.h|   6 +
> >  bsps/arm/raspberrypi/include/bsp/fbcons.h |  17 +-
> >  .../arm/raspberrypi/include/bsp/raspberrypi.h |  53 ++
> >  bsps/arm/raspberrypi/include/bsp/usart.h  |   5 +-
> >  bsps/arm/raspberrypi/start/bspstart.c |  15 ++
> >  c/src/lib/libbsp/arm/raspberrypi/Makefile.am  |   7 +-
> >  c/src/lib/libbsp/arm/raspberrypi/configure.ac |  13 ++
> >  11 files changed, 225 insertions(+), 406 deletions(-)
> >  delete mode 100644 bsps/arm/raspberrypi/console/console_select.c
> >  delete mode 100644 bsps/arm/raspberrypi/console/usart.c
> >
> > diff --git a/bsps/arm/raspberrypi/console/console-config.c
> b/bsps/arm/raspberrypi/console/console-config.c
> > index d2186c918b..c306db439b 100644
> > --- a/bsps/arm/raspberrypi/console/console-config.c
> > +++ b/bsps/arm/raspberrypi/console/console-config.c
> > @@ -19,50 +19,140 @@
> >   */
> >
> >  #include 
> > -
> > -#include 
> > +#include 
> > +#include 
> >
> >  #include 
> > -#include 
> > -#include 
> > +#include 
> >  #include 
> > +#include 
> > +#include 
> >  #include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +
> > +arm_pl011_context pl011_context;
> > +
> > +rpi_fb_context fb_context;
> > +
> > +static void output_char_serial(char c)
> > +{
> > +  arm_pl011_write_polled(_context.base, c);
> > +}
> > +
> > +void output_char_fb(char c)
> > +{
> > +  fbcons_write_polled(_context.base, c);
> > +}
> > +
> > +static void init_ctx_arm_pl011(
> > +  const void *fdt,
> > +  int node
> > +)
> > +{
> > +  arm_pl011_context *ctx = _context;
> > +  rtems_termios_device_context_initialize(>base, "UART");
> > +  ctx->regs = raspberrypi_get_reg_of_node(fdt, node);
> > +}
> > +
> > +static void register_fb( void )
> > +{
> > +  if (fbcons_probe(_context.base) == true) {
> > +rtems_termios_device_install(
> > +  "/dev/fbcons",
> > +  _fns,
> > +  NULL,
> > +  _context.base);
> > +  }
> > +}
> >
> > -console_tbl Console_Configuration_Ports [] = {
> > -{
> > -  .sDeviceName = "/dev/ttyS0",
> > -  .deviceType = SERIAL_CUSTOM,
> > -  .pDeviceFns = _usart_fns,
> > -  .deviceProbe = NULL,
> > -  .pDeviceFlow = NULL,
> > -  .ulCtrlPort1 = BCM2835_UART0_BASE,
> > -  .ulCtrlPort2 = 0,
> > -  .ulClock = USART0_DEFAULT_BAUD,
> > -  .ulIntVector = BCM2835_IRQ_ID_UART
> > -},
> > -{
> > -  .sDeviceName ="/dev/fbcons",
> > -  .deviceType = SERIAL_CUSTOM,
> > -  .pDeviceFns = _fns,
> > -  .deviceProbe = fbcons_probe,
> > -  .pDeviceFlow = NULL,
> > -},
> > -};
> > -
> > -#define PORT_COUNT \
> > -  (sizeof(Console_Configuration_Ports) \
> > -/ sizeof(Console_Configuration_Ports [0]))
> > -
> > -unsigned long Console_Configuration_Count = PORT_COUNT;
> > +static void console_select( void )
> > +{
> > +  const char *opt;
> > +  const void *fdt;
> > +  const char *console;
> > +  int node;
> > +
> > +  fdt = bsp_fdt_get();
> > +  node = fdt_path_offset(fdt, "/chosen");
> > +
> > +  console = fdt_getprop(fdt, node, "stdout-path", NULL);
>
> Sorry that I missed that on your earlier patch:
>
> I had a look at all the "chosen" nodes in the dtb files here:
>
>
> https://github.com/raspberrypi/firmware/tree/0c01dbefba45a08c47f8538d5a071a0fba6b7e83/boot


I was using the dtb file from freeBSD, that one had the chosen node.
https://github.com/freebsd/freebsd/blob/41655e1cf1451b788f6437c91ec74bcecd2192b7/sys/gnu/dts/arm/bcm283x.dtsi#L31
But there is no standalone DTB file from freeBSD, we have to build it so
I'll move to the DTB
that you mentioned, since it's more commonly used.

>
> None of these had a property called stdout-path. Where did you find it?
> Beneath that: It seems that you just check whether the property is there
> without checking the value a few lines further down. Why?
>
> If there is no special reason, I would suggest to just completely remove
> the fdt from here and only parse the cmdline. If it is not "fbcons" just
> default to the /dev/ttyS0.
>
> > +
> > +  opt = rpi_cmdline_get_arg("--console=");
> > +
> > +  if ( opt ) {
> > +if ( strncmp( opt, "fbcons", sizeof( "fbcons" ) - 1 ) == 0 ) {
> > +  if ( rpi_video_is_initialized() > 0 ) {
> > +BSP_output_char = output_char_fb;
> > +link("/dev/fbcons", 

Re: [PATCH] bsp/raspberry: Enabled FDT support for console.

2020-01-02 Thread Christian Mauderer
Sorry, it seems I missed some parts in the last mail. Beneath that I
caused a misunderstanding again.

On 02/01/2020 20:08, G S Niteesh wrote:
> Replaced the older console api with newer FDT based
> console driver.
> Replaces the custom pl011 driver with RTEMS arm-pl011
> driver.
> ---
>  bsps/arm/raspberrypi/console/console-config.c | 156 
>  bsps/arm/raspberrypi/console/console_select.c | 114 
>  bsps/arm/raspberrypi/console/fbcons.c |  78 
>  bsps/arm/raspberrypi/console/usart.c  | 167 --
>  bsps/arm/raspberrypi/include/bsp.h|   6 +
>  bsps/arm/raspberrypi/include/bsp/fbcons.h |  17 +-
>  .../arm/raspberrypi/include/bsp/raspberrypi.h |  53 ++
>  bsps/arm/raspberrypi/include/bsp/usart.h  |   5 +-
>  bsps/arm/raspberrypi/start/bspstart.c |  15 ++
>  c/src/lib/libbsp/arm/raspberrypi/Makefile.am  |   7 +-
>  c/src/lib/libbsp/arm/raspberrypi/configure.ac |  13 ++
>  11 files changed, 225 insertions(+), 406 deletions(-)
>  delete mode 100644 bsps/arm/raspberrypi/console/console_select.c
>  delete mode 100644 bsps/arm/raspberrypi/console/usart.c
> 
> diff --git a/bsps/arm/raspberrypi/console/console-config.c 
> b/bsps/arm/raspberrypi/console/console-config.c
> index d2186c918b..c306db439b 100644
> --- a/bsps/arm/raspberrypi/console/console-config.c
> +++ b/bsps/arm/raspberrypi/console/console-config.c
> @@ -19,50 +19,140 @@
>   */
>  
>  #include 
> -
> -#include 
> +#include 
> +#include 
>  
>  #include 
> -#include 
> -#include 
> +#include 
>  #include 
> +#include 
> +#include 
>  #include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +
> +arm_pl011_context pl011_context;
> +
> +rpi_fb_context fb_context;
> +
> +static void output_char_serial(char c)
> +{
> +  arm_pl011_write_polled(_context.base, c);
> +}
> +
> +void output_char_fb(char c)
> +{
> +  fbcons_write_polled(_context.base, c);
> +}
> +
> +static void init_ctx_arm_pl011(
> +  const void *fdt,
> +  int node
> +)
> +{
> +  arm_pl011_context *ctx = _context;
> +  rtems_termios_device_context_initialize(>base, "UART");
> +  ctx->regs = raspberrypi_get_reg_of_node(fdt, node);
> +}
> +
> +static void register_fb( void )
> +{
> +  if (fbcons_probe(_context.base) == true) {
> +rtems_termios_device_install(
> +  "/dev/fbcons",
> +  _fns,
> +  NULL,
> +  _context.base);
> +  }
> +}
>  
> -console_tbl Console_Configuration_Ports [] = {
> -{
> -  .sDeviceName = "/dev/ttyS0",
> -  .deviceType = SERIAL_CUSTOM,
> -  .pDeviceFns = _usart_fns,
> -  .deviceProbe = NULL,
> -  .pDeviceFlow = NULL,
> -  .ulCtrlPort1 = BCM2835_UART0_BASE,
> -  .ulCtrlPort2 = 0,
> -  .ulClock = USART0_DEFAULT_BAUD,
> -  .ulIntVector = BCM2835_IRQ_ID_UART
> -},
> -{
> -  .sDeviceName ="/dev/fbcons",
> -  .deviceType = SERIAL_CUSTOM,
> -  .pDeviceFns = _fns,
> -  .deviceProbe = fbcons_probe,
> -  .pDeviceFlow = NULL,
> -},
> -};
> -
> -#define PORT_COUNT \
> -  (sizeof(Console_Configuration_Ports) \
> -/ sizeof(Console_Configuration_Ports [0]))
> -
> -unsigned long Console_Configuration_Count = PORT_COUNT;
> +static void console_select( void )
> +{
> +  const char *opt;
> +  const void *fdt;
> +  const char *console;
> +  int node;
> +
> +  fdt = bsp_fdt_get();
> +  node = fdt_path_offset(fdt, "/chosen");
> +
> +  console = fdt_getprop(fdt, node, "stdout-path", NULL);

Sorry that I missed that on your earlier patch:

I had a look at all the "chosen" nodes in the dtb files here:

https://github.com/raspberrypi/firmware/tree/0c01dbefba45a08c47f8538d5a071a0fba6b7e83/boot

None of these had a property called stdout-path. Where did you find it?
Beneath that: It seems that you just check whether the property is there
without checking the value a few lines further down. Why?

If there is no special reason, I would suggest to just completely remove
the fdt from here and only parse the cmdline. If it is not "fbcons" just
default to the /dev/ttyS0.

> +
> +  opt = rpi_cmdline_get_arg("--console=");
> +
> +  if ( opt ) {
> +if ( strncmp( opt, "fbcons", sizeof( "fbcons" ) - 1 ) == 0 ) {
> +  if ( rpi_video_is_initialized() > 0 ) {
> +BSP_output_char = output_char_fb;
> +link("/dev/fbcons", CONSOLE_DEVICE_NAME);
> +return ;
> +  }
> +}else{
> +  if ( console == NULL ){
> +bsp_fatal( BSP_FATAL_CONSOLE_NO_DEV );
> +  }
> +  link("/dev/S0", CONSOLE_DEVICE_NAME);

Typo: That should be "/dev/ttyS0". Maybe use a #define for that. You are
using the same string twice. Same could be true for "/dev/fbcons".

> +}
> +  }
> +  BSP_output_char = output_char_serial;
> +}
> +
> +static void uart_probe(void)
> +{
> +  static bool initialized = false;
> +  const void *fdt;
> +  int node;
> +
> +  if ( initialized ) {
> +return ;
> +  }
> +
> +  fdt = bsp_fdt_get();
> +  node = fdt_node_offset_by_compatible(fdt, -1, 

[PATCH] bsp/raspberry: Enabled FDT support for console.

2020-01-02 Thread G S Niteesh
Replaced the older console api with newer FDT based
console driver.
Replaces the custom pl011 driver with RTEMS arm-pl011
driver.
---
 bsps/arm/raspberrypi/console/console-config.c | 156 
 bsps/arm/raspberrypi/console/console_select.c | 114 
 bsps/arm/raspberrypi/console/fbcons.c |  78 
 bsps/arm/raspberrypi/console/usart.c  | 167 --
 bsps/arm/raspberrypi/include/bsp.h|   6 +
 bsps/arm/raspberrypi/include/bsp/fbcons.h |  17 +-
 .../arm/raspberrypi/include/bsp/raspberrypi.h |  53 ++
 bsps/arm/raspberrypi/include/bsp/usart.h  |   5 +-
 bsps/arm/raspberrypi/start/bspstart.c |  15 ++
 c/src/lib/libbsp/arm/raspberrypi/Makefile.am  |   7 +-
 c/src/lib/libbsp/arm/raspberrypi/configure.ac |  13 ++
 11 files changed, 225 insertions(+), 406 deletions(-)
 delete mode 100644 bsps/arm/raspberrypi/console/console_select.c
 delete mode 100644 bsps/arm/raspberrypi/console/usart.c

diff --git a/bsps/arm/raspberrypi/console/console-config.c 
b/bsps/arm/raspberrypi/console/console-config.c
index d2186c918b..c306db439b 100644
--- a/bsps/arm/raspberrypi/console/console-config.c
+++ b/bsps/arm/raspberrypi/console/console-config.c
@@ -19,50 +19,140 @@
  */
 
 #include 
-
-#include 
+#include 
+#include 
 
 #include 
-#include 
-#include 
+#include 
 #include 
+#include 
+#include 
 #include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+arm_pl011_context pl011_context;
+
+rpi_fb_context fb_context;
+
+static void output_char_serial(char c)
+{
+  arm_pl011_write_polled(_context.base, c);
+}
+
+void output_char_fb(char c)
+{
+  fbcons_write_polled(_context.base, c);
+}
+
+static void init_ctx_arm_pl011(
+  const void *fdt,
+  int node
+)
+{
+  arm_pl011_context *ctx = _context;
+  rtems_termios_device_context_initialize(>base, "UART");
+  ctx->regs = raspberrypi_get_reg_of_node(fdt, node);
+}
+
+static void register_fb( void )
+{
+  if (fbcons_probe(_context.base) == true) {
+rtems_termios_device_install(
+  "/dev/fbcons",
+  _fns,
+  NULL,
+  _context.base);
+  }
+}
 
-console_tbl Console_Configuration_Ports [] = {
-{
-  .sDeviceName = "/dev/ttyS0",
-  .deviceType = SERIAL_CUSTOM,
-  .pDeviceFns = _usart_fns,
-  .deviceProbe = NULL,
-  .pDeviceFlow = NULL,
-  .ulCtrlPort1 = BCM2835_UART0_BASE,
-  .ulCtrlPort2 = 0,
-  .ulClock = USART0_DEFAULT_BAUD,
-  .ulIntVector = BCM2835_IRQ_ID_UART
-},
-{
-  .sDeviceName ="/dev/fbcons",
-  .deviceType = SERIAL_CUSTOM,
-  .pDeviceFns = _fns,
-  .deviceProbe = fbcons_probe,
-  .pDeviceFlow = NULL,
-},
-};
-
-#define PORT_COUNT \
-  (sizeof(Console_Configuration_Ports) \
-/ sizeof(Console_Configuration_Ports [0]))
-
-unsigned long Console_Configuration_Count = PORT_COUNT;
+static void console_select( void )
+{
+  const char *opt;
+  const void *fdt;
+  const char *console;
+  int node;
+
+  fdt = bsp_fdt_get();
+  node = fdt_path_offset(fdt, "/chosen");
+
+  console = fdt_getprop(fdt, node, "stdout-path", NULL);
+
+  opt = rpi_cmdline_get_arg("--console=");
+
+  if ( opt ) {
+if ( strncmp( opt, "fbcons", sizeof( "fbcons" ) - 1 ) == 0 ) {
+  if ( rpi_video_is_initialized() > 0 ) {
+BSP_output_char = output_char_fb;
+link("/dev/fbcons", CONSOLE_DEVICE_NAME);
+return ;
+  }
+}else{
+  if ( console == NULL ){
+bsp_fatal( BSP_FATAL_CONSOLE_NO_DEV );
+  }
+  link("/dev/S0", CONSOLE_DEVICE_NAME);
+}
+  }
+  BSP_output_char = output_char_serial;
+}
+
+static void uart_probe(void)
+{
+  static bool initialized = false;
+  const void *fdt;
+  int node;
+
+  if ( initialized ) {
+return ;
+  }
+
+  fdt = bsp_fdt_get();
+  node = fdt_node_offset_by_compatible(fdt, -1, "brcm,bcm2835-pl011");
+
+  init_ctx_arm_pl011(fdt, node);
+
+  initialized = true;
+}
 
 static void output_char(char c)
 {
-  const console_fns *con =
-Console_Configuration_Ports [Console_Port_Minor].pDeviceFns;
+  uart_probe();
+  output_char_serial(c);
+}
+
+rtems_status_code console_initialize(
+  rtems_device_major_number major,
+  rtems_device_minor_number minor,
+  void *arg
+)
+{
+  rtems_termios_initialize();
+
+  uart_probe();
+
+  rtems_termios_device_install( "/dev/ttyS0",
+_pl011_fns,
+NULL,
+_context.base
+  );
+  register_fb();
 
-  con->deviceWritePolled((int) Console_Port_Minor, c);
+  console_select();
+
+  return RTEMS_SUCCESSFUL;
 }
 
 BSP_output_char_function_type BSP_output_char = output_char;
 
 BSP_polling_getchar_function_type BSP_poll_char = NULL;
+
+RTEMS_SYSINIT_ITEM(
+  uart_probe,
+  RTEMS_SYSINIT_BSP_START,
+  RTEMS_SYSINIT_ORDER_LAST
+);
\ No newline at end of file
diff --git a/bsps/arm/raspberrypi/console/console_select.c 
b/bsps/arm/raspberrypi/console/console_select.c
deleted file mode 100644
index bd246ca868..00
--- a/bsps/arm/raspberrypi/console/console_select.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * @file