From e0f21f625f518b0f1ece8a7cbe96a5206cf8c7f9 Mon Sep 17 00:00:00 2001 From: Antonio Nino Diaz Date: Tue, 27 Mar 2018 09:39:47 +0100 Subject: [PATCH] rpi3: Use new console APIs Switch to the new console APIs enabled by setting MULTI_CONSOLE_API=1. The crash console doesn't use this API, it uses internally the core functions of the 16550 console. `bl31_plat_runtime_setup` is no longer needed. When this platform port was introduced, that function used to disable the console. It was needed to override that behaviour. The new behaviour is to switch to the runtime console. The console is registered for all scopes (boot, crash and runtime) in `rpi3_console_init` so it is not needed to override the default behaviour anymore. Update documentation. Change-Id: If2ee8f91044216183b7ef142e5c05ad6220ae92f Signed-off-by: Antonio Nino Diaz --- docs/plat/rpi3.rst | 7 ++++++- plat/rpi3/aarch64/plat_helpers.S | 10 +++++----- plat/rpi3/platform.mk | 9 ++++++++- plat/rpi3/rpi3_bl1_setup.c | 6 ++---- plat/rpi3/rpi3_bl2_setup.c | 8 +++----- plat/rpi3/rpi3_bl31_setup.c | 13 ++----------- plat/rpi3/rpi3_common.c | 28 +++++++++++++++++++++++++++- plat/rpi3/rpi3_private.h | 3 ++- 8 files changed, 55 insertions(+), 29 deletions(-) diff --git a/docs/plat/rpi3.rst b/docs/plat/rpi3.rst index c30110ed..b7879a85 100644 --- a/docs/plat/rpi3.rst +++ b/docs/plat/rpi3.rst @@ -247,6 +247,11 @@ The following is not currently supported: - ``LOAD_IMAGE_V2=0``: Only version 2 is supported. +- ``MULTI_CONSOLE_API=0``: The multi console API must be enabled. Note that the + crash console uses the internal 16550 driver functions directly in order to be + able to print error messages during early crashes before setting up the + multi console API. + AArch64 kernel build instructions --------------------------------- @@ -300,7 +305,7 @@ Setup SD card The instructions assume that you have an SD card with a fresh install of `Raspbian`_ (or that, at least, the ``boot`` partition is untouched, or nearly -untouched). They have been tested with the image available in 2017-09-07. +untouched). They have been tested with the image available in 2018-03-13. 1. Insert the SD card and open the ``boot`` partition. diff --git a/plat/rpi3/aarch64/plat_helpers.S b/plat/rpi3/aarch64/plat_helpers.S index 76a542f5..65c1bf2d 100644 --- a/plat/rpi3/aarch64/plat_helpers.S +++ b/plat/rpi3/aarch64/plat_helpers.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -137,7 +137,7 @@ func plat_crash_console_init mov_imm x0, PLAT_RPI3_UART_BASE mov_imm x1, PLAT_RPI3_UART_CLK_IN_HZ mov_imm x2, PLAT_RPI3_UART_BAUDRATE - b console_core_init + b console_16550_core_init endfunc plat_crash_console_init /* --------------------------------------------- @@ -149,7 +149,7 @@ endfunc plat_crash_console_init */ func plat_crash_console_putc mov_imm x1, PLAT_RPI3_UART_BASE - b console_core_putc + b console_16550_core_putc endfunc plat_crash_console_putc /* --------------------------------------------- @@ -161,8 +161,8 @@ endfunc plat_crash_console_putc * --------------------------------------------- */ func plat_crash_console_flush - mov_imm x1, PLAT_RPI3_UART_BASE - b console_core_flush + mov_imm x0, PLAT_RPI3_UART_BASE + b console_16550_core_flush endfunc plat_crash_console_flush /* --------------------------------------------- diff --git a/plat/rpi3/platform.mk b/plat/rpi3/platform.mk index e201ceed..2cb7a152 100644 --- a/plat/rpi3/platform.mk +++ b/plat/rpi3/platform.mk @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -81,6 +81,9 @@ USE_COHERENT_MEM := 1 # Enable new version of image loading LOAD_IMAGE_V2 := 1 +# Use multi console API +MULTI_CONSOLE_API := 1 + # Platform build flags # -------------------- @@ -110,6 +113,10 @@ ifneq (${LOAD_IMAGE_V2}, 1) $(error Error: rpi3 needs LOAD_IMAGE_V2=1) endif +ifneq (${MULTI_CONSOLE_API}, 1) + $(error Error: rpi3 needs MULTI_CONSOLE_API=1) +endif + ifeq (${ARCH},aarch32) $(error Error: AArch32 not supported on rpi3) endif diff --git a/plat/rpi3/rpi3_bl1_setup.c b/plat/rpi3/rpi3_bl1_setup.c index 11c0f4af..c98715b9 100644 --- a/plat/rpi3/rpi3_bl1_setup.c +++ b/plat/rpi3/rpi3_bl1_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -29,8 +28,7 @@ meminfo_t *bl1_plat_sec_mem_layout(void) void bl1_early_platform_setup(void) { /* Initialize the console to provide early debug support */ - console_init(PLAT_RPI3_UART_BASE, PLAT_RPI3_UART_CLK_IN_HZ, - PLAT_RPI3_UART_BAUDRATE); + rpi3_console_init(); /* Allow BL1 to see the whole Trusted RAM */ bl1_tzram_layout.total_base = BL_RAM_BASE; diff --git a/plat/rpi3/rpi3_bl2_setup.c b/plat/rpi3/rpi3_bl2_setup.c index 1fd822e9..6d43dcea 100644 --- a/plat/rpi3/rpi3_bl2_setup.c +++ b/plat/rpi3/rpi3_bl2_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -27,8 +26,7 @@ static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE); void bl2_early_platform_setup(meminfo_t *mem_layout) { /* Initialize the console to provide early debug support */ - console_init(PLAT_RPI3_UART_BASE, PLAT_RPI3_UART_CLK_IN_HZ, - PLAT_RPI3_UART_BAUDRATE); + rpi3_console_init(); /* Setup the BL2 memory layout */ bl2_tzram_layout = *mem_layout; @@ -40,7 +38,7 @@ void bl2_platform_setup(void) { /* * This is where a TrustZone address space controller and other - * security related peripherals, would be configured. + * security related peripherals would be configured. */ } diff --git a/plat/rpi3/rpi3_bl31_setup.c b/plat/rpi3/rpi3_bl31_setup.c index 39133564..58344ae9 100644 --- a/plat/rpi3/rpi3_bl31_setup.c +++ b/plat/rpi3/rpi3_bl31_setup.c @@ -1,12 +1,11 @@ /* - * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #include #include -#include #include #include #include @@ -58,8 +57,7 @@ void bl31_early_platform_setup(void *from_bl2, void *plat_params_from_bl2) { /* Initialize the console to provide early debug support */ - console_init(PLAT_RPI3_UART_BASE, PLAT_RPI3_UART_CLK_IN_HZ, - PLAT_RPI3_UART_BAUDRATE); + rpi3_console_init(); #if RESET_TO_BL31 @@ -159,10 +157,3 @@ void bl31_platform_setup(void) return; } - -void bl31_plat_runtime_setup(void) -{ - /* Initialize the runtime console */ - console_init(PLAT_RPI3_UART_BASE, PLAT_RPI3_UART_CLK_IN_HZ, - PLAT_RPI3_UART_BAUDRATE); -} diff --git a/plat/rpi3/rpi3_common.c b/plat/rpi3/rpi3_common.c index 97dce091..03914a6d 100644 --- a/plat/rpi3/rpi3_common.c +++ b/plat/rpi3/rpi3_common.c @@ -1,14 +1,16 @@ /* - * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #include #include +#include #include #include #include +#include #include #include "rpi3_hw.h" @@ -68,6 +70,30 @@ static const mmap_region_t plat_rpi3_mmap[] = { }; #endif +/******************************************************************************* + * Function that sets up the console + ******************************************************************************/ +static console_16550_t rpi3_console; + +void rpi3_console_init(void) +{ + int rc = console_16550_register(PLAT_RPI3_UART_BASE, + PLAT_RPI3_UART_CLK_IN_HZ, + PLAT_RPI3_UART_BAUDRATE, + &rpi3_console); + if (rc == 0) { + /* + * The crash console doesn't use the multi console API, it uses + * the core console functions directly. It is safe to call panic + * and let it print debug information. + */ + panic(); + } + + console_set_scope(&rpi3_console.console, + CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME); +} + /******************************************************************************* * Function that sets up the translation tables. ******************************************************************************/ diff --git a/plat/rpi3/rpi3_private.h b/plat/rpi3/rpi3_private.h index 01c4055f..a9fbfe47 100644 --- a/plat/rpi3/rpi3_private.h +++ b/plat/rpi3/rpi3_private.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -14,6 +14,7 @@ ******************************************************************************/ /* Utility functions */ +void rpi3_console_init(void); void rpi3_setup_page_tables(uintptr_t total_base, size_t total_size, uintptr_t code_start, uintptr_t code_limit, uintptr_t rodata_start, uintptr_t rodata_limit -- 2.30.2