From e5eaa824202a3760d508012b13b9df45c43e670c Mon Sep 17 00:00:00 2001 From: Preetam Das Date: Tue, 13 Jan 2026 23:59:46 +0530 Subject: [PATCH] bsps/aarch64/raspberrypi5: Add initial Raspberry Pi 5 BSP This is initial mvp implementation for the Pi5 BSP. The initial support has the following features: - PL011 debug uart (full termios console driver) - Arm Generic Timer (virtual interface) - GIC-V2 interrupts This will be extended in follow-up work. Should Close rtems/programs/gsoc#85 --- bsps/aarch64/raspberrypi5/console/console.c | 88 +++++++++++++++++++ bsps/aarch64/raspberrypi5/include/bsp.h | 79 +++++++++++++++++ bsps/aarch64/raspberrypi5/include/bsp/irq.h | 66 ++++++++++++++ .../raspberrypi5/include/bsp/raspberrypi5.h | 63 +++++++++++++ bsps/aarch64/raspberrypi5/include/tm27.h | 45 ++++++++++ bsps/aarch64/raspberrypi5/start/bspstart.c | 49 +++++++++++ .../raspberrypi5/start/bspstarthooks.c | 53 +++++++++++ bsps/aarch64/raspberrypi5/start/bspstartmmu.c | 60 +++++++++++++ bsps/aarch64/raspberrypi5/start/mmu-config.c | 60 +++++++++++++ spec/build/bsps/aarch64/raspberrypi5/abi.yml | 20 +++++ .../aarch64/raspberrypi5/bspraspberrypi5.yml | 73 +++++++++++++++ .../bsps/aarch64/raspberrypi5/linkercmds.yml | 84 ++++++++++++++++++ .../bsps/aarch64/raspberrypi5/objclock.yml | 29 ++++++ .../bsps/aarch64/raspberrypi5/objconsole.yml | 21 +++++ .../raspberrypi5/optclockpl011freq.yml | 17 ++++ .../aarch64/raspberrypi5/optsystemtimer.yml | 25 ++++++ spec/build/bsps/optarmpl011fifodepth.yml | 1 + 17 files changed, 833 insertions(+) create mode 100644 bsps/aarch64/raspberrypi5/console/console.c create mode 100644 bsps/aarch64/raspberrypi5/include/bsp.h create mode 100644 bsps/aarch64/raspberrypi5/include/bsp/irq.h create mode 100644 bsps/aarch64/raspberrypi5/include/bsp/raspberrypi5.h create mode 100644 bsps/aarch64/raspberrypi5/include/tm27.h create mode 100644 bsps/aarch64/raspberrypi5/start/bspstart.c create mode 100644 bsps/aarch64/raspberrypi5/start/bspstarthooks.c create mode 100644 bsps/aarch64/raspberrypi5/start/bspstartmmu.c create mode 100644 bsps/aarch64/raspberrypi5/start/mmu-config.c create mode 100644 spec/build/bsps/aarch64/raspberrypi5/abi.yml create mode 100644 spec/build/bsps/aarch64/raspberrypi5/bspraspberrypi5.yml create mode 100644 spec/build/bsps/aarch64/raspberrypi5/linkercmds.yml create mode 100644 spec/build/bsps/aarch64/raspberrypi5/objclock.yml create mode 100644 spec/build/bsps/aarch64/raspberrypi5/objconsole.yml create mode 100644 spec/build/bsps/aarch64/raspberrypi5/optclockpl011freq.yml create mode 100644 spec/build/bsps/aarch64/raspberrypi5/optsystemtimer.yml diff --git a/bsps/aarch64/raspberrypi5/console/console.c b/bsps/aarch64/raspberrypi5/console/console.c new file mode 100644 index 0000000000..71d8d6e1cc --- /dev/null +++ b/bsps/aarch64/raspberrypi5/console/console.c @@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RaspberryPi5 + * + * @brief Console driver configuration + */ + +/* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 +#include +#include +#include +#include + +#include +#include +#include + +static arm_pl011_context rpi5_uart_debug_context = { + .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART DEBUG"), + .regs = (volatile arm_pl011_uart*) BCM2712_UART_DEBUG_BASE, + .irq = BCM2712_IRQ_PL011_UART, + .initial_baud = BCM2712_UART_DEBUG_BAUD, + .clock = BSP_PL011_CLOCK_FREQ +}; + +static void output_char (char c) { + arm_pl011_write_polled(&rpi5_uart_debug_context.base, c); +} + +static int poll_char (void) { + return arm_pl011_read_polled(&rpi5_uart_debug_context.base); +} + +rtems_device_driver console_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *arg +) +{ + (void) major; + (void) minor; + (void) arg; + + const rtems_termios_device_handler *handler; + rtems_status_code sc; + + handler = &arm_pl011_fns; + + rtems_termios_initialize(); + + sc = rtems_termios_device_install( "/dev/console", handler, NULL, &rpi5_uart_debug_context.base ); + if ( sc != RTEMS_SUCCESSFUL ) { + bsp_fatal( BSP_FATAL_CONSOLE_INSTALL_1 ); + } + + return RTEMS_SUCCESSFUL; +} + +BSP_output_char_function_type BSP_output_char = output_char; +BSP_polling_getchar_function_type BSP_poll_char = poll_char; diff --git a/bsps/aarch64/raspberrypi5/include/bsp.h b/bsps/aarch64/raspberrypi5/include/bsp.h new file mode 100644 index 0000000000..67a717247f --- /dev/null +++ b/bsps/aarch64/raspberrypi5/include/bsp.h @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RaspberryPi5 + * + * @brief BSP Core definitions + */ + +/* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + */ + + +#ifndef LIBBSP_AARCH64_RASPBERRYPI5_BSP_H +#define LIBBSP_AARCH64_RASPBERRYPI5_BSP_H + +/** + * @defgroup RTEMSBSPsAArch64RaspberryPi5 Raspberry Pi 5 - BCM2712 + * + * @ingroup RTEMSBSPsAArch64 + * + * @brief This group contains the BSP for the Raspberry Pi 5 + * + * @{ + */ + +#include + +#ifndef ASM + +#include +#include + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Raspberry Pi 5 MMU initialization */ +BSP_START_TEXT_SECTION void raspberrypi5_setup_mmu_and_cache(void); + +#define BSP_ARM_GIC_CPUIF_BASE (BCM2712_GIC_CPUIF_BASE) +#define BSP_ARM_GIC_DIST_BASE (BCM2712_GIC_DIST_BASE) + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* ASM */ + +/** @} */ /* RTEMSBSPsAArch64RaspberryPi5 */ + +#endif /* LIBBSP_AARCH64_RASPBERRYPI5_BSP_H */ diff --git a/bsps/aarch64/raspberrypi5/include/bsp/irq.h b/bsps/aarch64/raspberrypi5/include/bsp/irq.h new file mode 100644 index 0000000000..5e3c892715 --- /dev/null +++ b/bsps/aarch64/raspberrypi5/include/bsp/irq.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RaspberryPi5 + * + * @brief IRQ Definitions + */ + +/* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + */ + +#ifndef LIBBSP_AARCH64_RASPBERRYPI5_IRQ_H +#define LIBBSP_AARCH64_RASPBERRYPI5_IRQ_H + +#ifndef ASM + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Debug UART */ +#define BCM2712_IRQ_PL011_UART (121 + 32) + +/* Arm Generic Timer */ +#define BSP_TIMER_VIRT_PPI 27 +#define BSP_TIMER_PHYS_NS_PPI 30 + +#define BCM2712_INTC_TOTAL_IRQ 306 +#define BSP_INTERRUPT_VECTOR_COUNT BCM2712_INTC_TOTAL_IRQ +#define BSP_INTERRUPT_VECTOR_INVALID (UINT32_MAX) +#define BSP_IRQ_COUNT (BCM2712_INTC_TOTAL_IRQ) + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* ASM */ + +#endif /* LIBBSP_AARCH64_RASPBERRYPI5_IRQ_H */ diff --git a/bsps/aarch64/raspberrypi5/include/bsp/raspberrypi5.h b/bsps/aarch64/raspberrypi5/include/bsp/raspberrypi5.h new file mode 100644 index 0000000000..a1a8364df8 --- /dev/null +++ b/bsps/aarch64/raspberrypi5/include/bsp/raspberrypi5.h @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RaspberryPi5 + * + * @brief Peripheral and Register definitions + */ + +/* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + */ + +#ifndef LIBBSP_AARCH64_RASPBERRYPI5_H +#define LIBBSP_AARCH64_RASPBERRYPI5_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define RPI_PERIPHERAL_BASE 0x107C000000UL +#define RPI_PERIPHERAL_SIZE 0x04000000UL + +#define BCM2712_GIC_BASE (RPI_PERIPHERAL_BASE + 0x03FF9000) +#define BCM2712_GIC_DIST_BASE (BCM2712_GIC_BASE + 0x0000) +#define BCM2712_GIC_CPUIF_BASE (BCM2712_GIC_BASE + 0x1000) + +#define BCM2712_PL011_DEVICE_SIZE 0x200 +#define BCM2712_UART_DEBUG_BASE (RPI_PERIPHERAL_BASE + 0x1001000) +#define BCM2712_UART_DEBUG_SIZE BCM2712_PL011_DEVICE_SIZE +#define BCM2712_UART_DEBUG_BAUD 115200 + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LIBBSP_AARCH64_RASPBERRYPI5_H */ diff --git a/bsps/aarch64/raspberrypi5/include/tm27.h b/bsps/aarch64/raspberrypi5/include/tm27.h new file mode 100644 index 0000000000..32d345e9fe --- /dev/null +++ b/bsps/aarch64/raspberrypi5/include/tm27.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RaspberryPi5 + * + * @brief BSP tm27 header + */ + +/* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + */ + +#ifndef _RTEMS_TMTEST27 +#error "This is an RTEMS internal file you must not include directly." +#endif + +#ifndef __tm27_h +#define __tm27_h + +#include + +#endif /* __tm27_h */ diff --git a/bsps/aarch64/raspberrypi5/start/bspstart.c b/bsps/aarch64/raspberrypi5/start/bspstart.c new file mode 100644 index 0000000000..77f2482118 --- /dev/null +++ b/bsps/aarch64/raspberrypi5/start/bspstart.c @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RaspberryPi5 + * + * @brief Low Level Startup Code + */ + +/* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 +#include +#include +#include + +void bsp_start( void ) +{ + bsp_interrupt_initialize(); + + rtems_cache_coherent_add_area( + bsp_section_nocacheheap_begin, + (uintptr_t) bsp_section_nocacheheap_size + ); +} diff --git a/bsps/aarch64/raspberrypi5/start/bspstarthooks.c b/bsps/aarch64/raspberrypi5/start/bspstarthooks.c new file mode 100644 index 0000000000..83f1932e44 --- /dev/null +++ b/bsps/aarch64/raspberrypi5/start/bspstarthooks.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RaspberryPi5 + * + * @brief BSP Startup Hooks + */ + +/* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 +#include + +#ifdef BSP_START_ENABLE_EL3_START_SUPPORT +BSP_START_TEXT_SECTION void bsp_start_hook_0(void) +{ + /* Do nothing */ +} +#endif + +BSP_START_TEXT_SECTION void bsp_start_hook_1(void) +{ + AArch64_start_set_vector_base(); + bsp_start_copy_sections(); + + raspberrypi5_setup_mmu_and_cache(); + bsp_start_clear_bss(); +} diff --git a/bsps/aarch64/raspberrypi5/start/bspstartmmu.c b/bsps/aarch64/raspberrypi5/start/bspstartmmu.c new file mode 100644 index 0000000000..7300bc971c --- /dev/null +++ b/bsps/aarch64/raspberrypi5/start/bspstartmmu.c @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RaspberryPi5 + * + * @brief Default MMU configuration + */ + +/* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 +#include +#include + +/* + * Make weak and let the user override. + */ +BSP_START_TEXT_SECTION void +raspberrypi5_setup_mmu_and_cache( void ) __attribute__ ((weak)); + +BSP_START_TEXT_SECTION void +raspberrypi5_setup_mmu_and_cache( void ) +{ + aarch64_mmu_control *control = &aarch64_mmu_instance; + + aarch64_mmu_setup(); + + aarch64_mmu_setup_translation_table( + control, + &aarch64_mmu_config_table[ 0 ], + aarch64_mmu_config_table_size + ); + + aarch64_mmu_enable( control ); +} diff --git a/bsps/aarch64/raspberrypi5/start/mmu-config.c b/bsps/aarch64/raspberrypi5/start/mmu-config.c new file mode 100644 index 0000000000..8ea56adc97 --- /dev/null +++ b/bsps/aarch64/raspberrypi5/start/mmu-config.c @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RaspberryPi5 + * + * @brief MMU Config Table + */ + +/* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 +#include +#include +#include + +BSP_START_DATA_SECTION const aarch64_mmu_config_entry +aarch64_mmu_config_table[] = { + AARCH64_MMU_DEFAULT_SECTIONS, + + { /* RPI peripheral address */ + .begin = (uintptr_t)RPI_PERIPHERAL_BASE, + .end = (uintptr_t)RPI_PERIPHERAL_BASE + (uintptr_t)RPI_PERIPHERAL_SIZE, + .flags = AARCH64_MMU_DEVICE + }, + + { /* RPI firmware-owned addresses including spintables */ + .begin = (uintptr_t)0x0, + .end = (uintptr_t)0x1000, + .flags = AARCH64_MMU_DEVICE + }, + +}; + +BSP_START_DATA_SECTION const size_t aarch64_mmu_config_table_size = + RTEMS_ARRAY_SIZE(aarch64_mmu_config_table); diff --git a/spec/build/bsps/aarch64/raspberrypi5/abi.yml b/spec/build/bsps/aarch64/raspberrypi5/abi.yml new file mode 100644 index 0000000000..a9a22020a7 --- /dev/null +++ b/spec/build/bsps/aarch64/raspberrypi5/abi.yml @@ -0,0 +1,20 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-string: null +- split: null +- env-append: null +build-type: option +copyrights: +- Copyright (C) 2026 Preetam Das +default: +- enabled-by: true + value: + - -mcpu=cortex-a76 + - -march=armv8.2-a + - -mno-outline-atomics +description: | + ABI flags +enabled-by: true +links: [] +name: ABI_FLAGS +type: build diff --git a/spec/build/bsps/aarch64/raspberrypi5/bspraspberrypi5.yml b/spec/build/bsps/aarch64/raspberrypi5/bspraspberrypi5.yml new file mode 100644 index 0000000000..ba261bf258 --- /dev/null +++ b/spec/build/bsps/aarch64/raspberrypi5/bspraspberrypi5.yml @@ -0,0 +1,73 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +arch: aarch64 +bsp: raspberrypi5 +build-type: bsp +cflags: [] +copyrights: +- Copyright (C) 2026 Preetam Das +cppflags: [] +enabled-by: true +family: raspberrypi5 +includes: [] +install: +- destination: ${BSP_INCLUDEDIR} + source: + - bsps/aarch64/raspberrypi5/include/bsp.h + - bsps/aarch64/raspberrypi5/include/tm27.h +- destination: ${BSP_INCLUDEDIR}/bsp + source: + - bsps/aarch64/raspberrypi5/include/bsp/irq.h + - bsps/aarch64/raspberrypi5/include/bsp/raspberrypi5.h +links: +- role: build-dependency + uid: ../grp +- role: build-dependency + uid: ../start +- role: build-dependency + uid: ../optmmupages +- role: build-dependency + uid: ../optgtusevirt +- role: build-dependency + uid: ../optgtuseps +- role: build-dependency + uid: abi +- role: build-dependency + uid: ../../optcachedata +- role: build-dependency + uid: ../../optcacheinst +- role: build-dependency + uid: ../../opto2 +- role: build-dependency + uid: ../../bspopts +- role: build-dependency + uid: linkercmds +- role: build-dependency + uid: ../../dev/irq/objarmgicv2 +- role: build-dependency + uid: ../../obj +- role: build-dependency + uid: ../../objirq +- role: build-dependency + uid: objclock +- role: build-dependency + uid: objconsole +source: +- bsps/aarch64/raspberrypi5/start/bspstart.c +- bsps/aarch64/raspberrypi5/start/bspstarthooks.c +- bsps/aarch64/raspberrypi5/start/bspstartmmu.c +- bsps/aarch64/raspberrypi5/start/mmu-config.c +- bsps/aarch64/shared/cache/cache.c +- bsps/aarch64/shared/mmu/mmu-setup.c +- bsps/aarch64/shared/mmu/vmsav8-64.c +- bsps/aarch64/shared/start/start-cpu-mpidr.S +- bsps/shared/dev/irq/arm-gicv2-get-attributes.c +- bsps/shared/dev/getentropy/getentropy-cpucounter.c +- bsps/shared/dev/btimer/btimer-cpucounter.c +- bsps/shared/irq/irq-default-handler.c +- bsps/shared/start/gettargethash-default.c +- bsps/shared/start/sbrk.c +- bsps/shared/start/wkspaceinitone.c +- bsps/shared/start/mallocinitmulti.c +- bsps/shared/start/bspgetworkarea-default.c +- bsps/shared/start/bspreset-loop.c +type: build diff --git a/spec/build/bsps/aarch64/raspberrypi5/linkercmds.yml b/spec/build/bsps/aarch64/raspberrypi5/linkercmds.yml new file mode 100644 index 0000000000..7e641f96bc --- /dev/null +++ b/spec/build/bsps/aarch64/raspberrypi5/linkercmds.yml @@ -0,0 +1,84 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: config-file +content: | + /* SPDX-License-Identifier: BSD-2-Clause */ + + /* + * Copyright (C) 2026 Preetam Das + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + */ + + MMU_TTB_LEN = (0x1000 * ${AARCH64_MMU_TRANSLATION_TABLE_PAGES}); + NOCACHE_LEN = 16M; + LOAD_OFFSET = 0x80000; + + GPU_RAM_LEN = 64M; + RAM_TOP = 0x40000000 - GPU_RAM_LEN; + + MEMORY { + RAM : ORIGIN = LOAD_OFFSET, LENGTH = RAM_TOP - LOAD_OFFSET - NOCACHE_LEN - MMU_TTB_LEN + RAM_NOCACHE : ORIGIN = RAM_TOP - NOCACHE_LEN - MMU_TTB_LEN, LENGTH = NOCACHE_LEN + RAM_MMU : ORIGIN = RAM_TOP - MMU_TTB_LEN, LENGTH = MMU_TTB_LEN + } + + REGION_ALIAS ("REGION_START", RAM); + REGION_ALIAS ("REGION_VECTOR", RAM); + REGION_ALIAS ("REGION_TEXT", RAM); + REGION_ALIAS ("REGION_TEXT_LOAD", RAM); + REGION_ALIAS ("REGION_RODATA", RAM); + REGION_ALIAS ("REGION_RODATA_LOAD", RAM); + REGION_ALIAS ("REGION_DATA", RAM); + REGION_ALIAS ("REGION_DATA_LOAD", RAM); + REGION_ALIAS ("REGION_FAST_TEXT", RAM); + REGION_ALIAS ("REGION_FAST_TEXT_LOAD", RAM); + REGION_ALIAS ("REGION_FAST_DATA", RAM); + REGION_ALIAS ("REGION_FAST_DATA_LOAD", RAM); + REGION_ALIAS ("REGION_BSS", RAM); + REGION_ALIAS ("REGION_WORK", RAM); + REGION_ALIAS ("REGION_STACK", RAM); + REGION_ALIAS ("REGION_NOCACHE", RAM_NOCACHE); + REGION_ALIAS ("REGION_NOCACHE_LOAD", RAM_NOCACHE); + + bsp_stack_abt_size = DEFINED (bsp_stack_abt_size) ? bsp_stack_abt_size : 1024; + + bsp_section_rwbarrier_align = DEFINED (bsp_section_rwbarrier_align) ? bsp_section_rwbarrier_align : 1M; + + bsp_stack_exception_size = DEFINED (bsp_stack_exception_size) ? bsp_stack_exception_size : 1024; + + bsp_section_rwbarrier_align = DEFINED (bsp_section_rwbarrier_align) ? bsp_section_rwbarrier_align : 1M; + + bsp_vector_table_in_start_section = 1; + bsp_translation_table_base = ORIGIN (RAM_MMU); + bsp_translation_table_end = ORIGIN (RAM_MMU) + LENGTH (RAM_MMU); + + OUTPUT_FORMAT ("elf64-littleaarch64") + OUTPUT_ARCH (aarch64) + + INCLUDE linkcmds.base +copyrights: +- Copyright (C) 2026 Preetam Das +enabled-by: true +install-path: ${BSP_LIBDIR} +links: [] +target: linkcmds +type: build diff --git a/spec/build/bsps/aarch64/raspberrypi5/objclock.yml b/spec/build/bsps/aarch64/raspberrypi5/objclock.yml new file mode 100644 index 0000000000..abaeed9357 --- /dev/null +++ b/spec/build/bsps/aarch64/raspberrypi5/objclock.yml @@ -0,0 +1,29 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +copyrights: +- Copyright (C) 2026 Preetam Das +type: build +enabled-by: + not: BSP_CLOCK_USE_SYSTEMTIMER + +build-type: objects +cflags: [] +cppflags: +- -DAARCH64_GENERIC_TIMER_USE_VIRTUAL +cxxflags: [] +includes: [] +install: +- destination: ${BSP_INCLUDEDIR}/dev/clock + source: + - bsps/include/dev/clock/arm-generic-timer.h + +source: +- bsps/aarch64/shared/clock/arm-generic-timer-aarch64.c +- bsps/shared/dev/clock/arm-generic-timer.c + +links: +- role: build-dependency + uid: ../optgtusevirt +- role: build-dependency + uid: ../optgtuseps +- role: build-dependency + uid: optsystemtimer diff --git a/spec/build/bsps/aarch64/raspberrypi5/objconsole.yml b/spec/build/bsps/aarch64/raspberrypi5/objconsole.yml new file mode 100644 index 0000000000..25c2be2dc0 --- /dev/null +++ b/spec/build/bsps/aarch64/raspberrypi5/objconsole.yml @@ -0,0 +1,21 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: objects +cflags: [] +copyrights: +- Copyright (C) 2026 Preetam Das +cppflags: [] +cxxflags: [] +enabled-by: true +includes: [] +install: [] +links: +- role: build-dependency + uid: ../../optconsoleirq +- role: build-dependency + uid: ../../objdevserialarmpl011 +- role: build-dependency + uid: optclockpl011freq +source: +- bsps/aarch64/raspberrypi5/console/console.c +- bsps/shared/dev/serial/console-termios.c +type: build diff --git a/spec/build/bsps/aarch64/raspberrypi5/optclockpl011freq.yml b/spec/build/bsps/aarch64/raspberrypi5/optclockpl011freq.yml new file mode 100644 index 0000000000..313f3224ba --- /dev/null +++ b/spec/build/bsps/aarch64/raspberrypi5/optclockpl011freq.yml @@ -0,0 +1,17 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-integer: null +- define: null +build-type: option +copyrights: +- Copyright (C) 2026 Preetam Das +default: +- enabled-by: + - aarch64/raspberrypi5 + value: 44236800 +description: PL011 UART clock frequency in Hz. +enabled-by: true +format: '{}' +links: [] +name: BSP_PL011_CLOCK_FREQ +type: build diff --git a/spec/build/bsps/aarch64/raspberrypi5/optsystemtimer.yml b/spec/build/bsps/aarch64/raspberrypi5/optsystemtimer.yml new file mode 100644 index 0000000000..057a07b25d --- /dev/null +++ b/spec/build/bsps/aarch64/raspberrypi5/optsystemtimer.yml @@ -0,0 +1,25 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +copyrights: +- Copyright (C) 2026 Preetam Das + +type: build +build-type: option + +enabled-by: true +name: BSP_CLOCK_USE_SYSTEMTIMER +description: | + The clock from the ARM timer is derived from the system clock. This clock can + change dynamically e.g. if the system goes into reduced power or in low power + mode. Thus the clock speed adapts to the overall system performance + capabilities. For accurate timing it is recommended to use the system timers. + +actions: +- get-boolean: null +- define-condition: null +- env-enable: null +default: +- enabled-by: + - aarch64/raspberrypi5 + value: false + +links: [] diff --git a/spec/build/bsps/optarmpl011fifodepth.yml b/spec/build/bsps/optarmpl011fifodepth.yml index dcc42f3901..dfa4b14854 100644 --- a/spec/build/bsps/optarmpl011fifodepth.yml +++ b/spec/build/bsps/optarmpl011fifodepth.yml @@ -15,6 +15,7 @@ default: value: 64 - enabled-by: - aarch64/raspberrypi4b + - aarch64/raspberrypi5 value: 32 description: | Set the size of UART FIFO