From 31e63813353f6bb57e14fdf444edb3db207761bf Mon Sep 17 00:00:00 2001 From: likun17 Date: Thu, 25 Jun 2026 16:13:39 +0800 Subject: [PATCH 1/4] drivers/serial/16550: add u16550_consoledev() accessor Expose a pointer to the console uart_dev_t so board logic can drive the console RX by polling. This is needed on AMP secondary cores where the UART RX interrupt cannot be delivered reliably through a GIC distributor that is shared with another OS (e.g. Linux), so the board polls the LSR and feeds bytes to the upper half via uart_recvchars(). Signed-off-by: likun17 --- drivers/serial/uart_16550.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/serial/uart_16550.c b/drivers/serial/uart_16550.c index 6278cab0728c2..9f7c74c12b58a 100644 --- a/drivers/serial/uart_16550.c +++ b/drivers/serial/uart_16550.c @@ -1748,6 +1748,22 @@ void up_putc(int ch) u16550_putc(priv, ch); } + +/**************************************************************************** + * Name: u16550_consoledev + * + * Description: + * Return a pointer to the console uart_dev_t. Used by board logic that + * needs to drive the console RX via polling (e.g. AMP secondary cores + * where the UART RX interrupt cannot be delivered reliably through a GIC + * distributor shared with another OS). + * + ****************************************************************************/ + +FAR uart_dev_t *u16550_consoledev(void) +{ + return &CONSOLE_DEV; +} #endif /**************************************************************************** From 4a440fa9bf9358eba7b708b1afa73558c78b92c1 Mon Sep 17 00:00:00 2001 From: likun17 Date: Thu, 25 Jun 2026 16:14:06 +0800 Subject: [PATCH 2/4] arch/arm/rk3506: add Rockchip RK3506 (Cortex-A7) chip support Add the RK3506 architecture support for running NuttX as an AMP secondary subsystem on one Cortex-A7 core (CPU2), brought up by U-Boot via PSCI alongside Linux on the other cores. Key points specific to the AMP-shared-GIC environment: - up_irqinitialize() only initializes the GIC CPU interface (GICC) and disables all SPIs, because the GIC distributor (GICD) is owned by Linux. Leftover SPIs targeting CPU2 would otherwise storm the core right after up_irq_enable(). - The generic timer uses the per-CPU PTM path (select ARMV7A_HAVE_PTM), since the per-CPU PPI is private and unaffected by Linux reconfiguring the shared distributor. - Memory map covers DDR (normal) and the 0xff000000 device region; the image runs from the AMP-reserved DRAM window. - rk3506_boot.c includes a raw UART4 breadcrumb for early bring-up debugging, independent of the serial driver. Signed-off-by: likun17 --- arch/arm/Kconfig | 18 ++ arch/arm/include/rk3506/chip.h | 48 +++++ arch/arm/include/rk3506/irq.h | 71 +++++++ arch/arm/src/rk3506/CMakeLists.txt | 37 ++++ arch/arm/src/rk3506/Kconfig | 37 ++++ arch/arm/src/rk3506/Make.defs | 36 ++++ arch/arm/src/rk3506/chip.h | 129 ++++++++++++ .../src/rk3506/hardware/rk3506_memorymap.h | 67 ++++++ arch/arm/src/rk3506/rk3506_boot.c | 165 +++++++++++++++ arch/arm/src/rk3506/rk3506_irq.c | 195 ++++++++++++++++++ arch/arm/src/rk3506/rk3506_irq.h | 53 +++++ arch/arm/src/rk3506/rk3506_memorymap.c | 73 +++++++ arch/arm/src/rk3506/rk3506_memorymap.h | 84 ++++++++ arch/arm/src/rk3506/rk3506_pgalloc.c | 78 +++++++ arch/arm/src/rk3506/rk3506_serial.c | 69 +++++++ arch/arm/src/rk3506/rk3506_timer.c | 38 ++++ 16 files changed, 1198 insertions(+) create mode 100644 arch/arm/include/rk3506/chip.h create mode 100644 arch/arm/include/rk3506/irq.h create mode 100644 arch/arm/src/rk3506/CMakeLists.txt create mode 100644 arch/arm/src/rk3506/Kconfig create mode 100644 arch/arm/src/rk3506/Make.defs create mode 100644 arch/arm/src/rk3506/chip.h create mode 100644 arch/arm/src/rk3506/hardware/rk3506_memorymap.h create mode 100644 arch/arm/src/rk3506/rk3506_boot.c create mode 100644 arch/arm/src/rk3506/rk3506_irq.c create mode 100644 arch/arm/src/rk3506/rk3506_irq.h create mode 100644 arch/arm/src/rk3506/rk3506_memorymap.c create mode 100644 arch/arm/src/rk3506/rk3506_memorymap.h create mode 100644 arch/arm/src/rk3506/rk3506_pgalloc.c create mode 100644 arch/arm/src/rk3506/rk3506_serial.c create mode 100644 arch/arm/src/rk3506/rk3506_timer.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index b107f0ab91d2f..7664cfbd390d8 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -885,6 +885,20 @@ config ARCH_CHIP_QEMU_ARM ---help--- QEMU virt platform (ARMv7a) +config ARCH_CHIP_RK3506 + bool "Rockchip RK3506 (ARMv7a, Cortex-A7)" + select ARCH_CORTEXA7 + select ARCH_HAVE_MULTICPU + select ARMV7A_HAVE_GICv2 + select ARMV7A_HAVE_PTM + select ARCH_HAVE_LOWVECTORS + select ARCH_HAVE_ADDRENV + select ARCH_NEED_ADDRENV_MAPPING + ---help--- + Rockchip RK3506 SoC. NuttX runs as an AMP subsystem on one of the + Cortex-A7 cores (CPU2), alongside Linux on the other cores. Brought + up by U-Boot via PSCI. + config ARCH_CHIP_GOLDFISH_ARM bool "GOLDFISH virt platform (ARMv7a)" select ARCH_HAVE_POWEROFF @@ -1366,6 +1380,7 @@ config ARCH_CHIP default "phy62xx" if ARCH_CHIP_PHY62XX default "tlsr82" if ARCH_CHIP_TLSR82 default "qemu" if ARCH_CHIP_QEMU_ARM + default "rk3506" if ARCH_CHIP_RK3506 default "mps" if ARCH_CHIP_MPS default "rtl8721dx" if ARCH_CHIP_RTL8721DX default "rtl8720f" if ARCH_CHIP_RTL8720F @@ -1935,6 +1950,9 @@ endif if ARCH_CHIP_QEMU_ARM source "arch/arm/src/qemu/Kconfig" endif +if ARCH_CHIP_RK3506 +source "arch/arm/src/rk3506/Kconfig" +endif if ARCH_CHIP_MPS source "arch/arm/src/mps/Kconfig" endif diff --git a/arch/arm/include/rk3506/chip.h b/arch/arm/include/rk3506/chip.h new file mode 100644 index 0000000000000..31cbb8fc8703c --- /dev/null +++ b/arch/arm/include/rk3506/chip.h @@ -0,0 +1,48 @@ +/**************************************************************************** + * arch/arm/include/rk3506/chip.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_INCLUDE_RK3506_CHIP_H +#define __ARCH_ARM_INCLUDE_RK3506_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +#endif /* __ARCH_ARM_INCLUDE_RK3506_CHIP_H */ diff --git a/arch/arm/include/rk3506/irq.h b/arch/arm/include/rk3506/irq.h new file mode 100644 index 0000000000000..18db3d440a5ec --- /dev/null +++ b/arch/arm/include/rk3506/irq.h @@ -0,0 +1,71 @@ +/**************************************************************************** + * arch/arm/include/rk3506/irq.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/* This file should never be included directly but, rather, + * only indirectly through nuttx/irq.h + */ + +#ifndef __ARCH_ARM_INCLUDE_RK3506_IRQ_H +#define __ARCH_ARM_INCLUDE_RK3506_IRQ_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Pre-processor Prototypes + ****************************************************************************/ + +#define NR_IRQS 220 /* Total number of interrupts */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Inline functions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef __ASSEMBLY__ +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +#undef EXTERN +#ifdef __cplusplus +} +#endif +#endif + +#endif /* __ARCH_ARM_INCLUDE_RK3506_IRQ_H */ diff --git a/arch/arm/src/rk3506/CMakeLists.txt b/arch/arm/src/rk3506/CMakeLists.txt new file mode 100644 index 0000000000000..0a3b07cb18cdf --- /dev/null +++ b/arch/arm/src/rk3506/CMakeLists.txt @@ -0,0 +1,37 @@ +# ############################################################################## +# arch/arm/src/qemu/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +set(SRCS rk3506_boot.c rk3506_serial.c rk3506_irq.c rk3506_timer.c) + +if(CONFIG_ARCH_ARMV7A) + list(APPEND SRCS rk3506_pgalloc.c rk3506_memorymap.c) +endif() + +if(CONFIG_BUILD_KERNEL) + list(APPEND SRCS rk3506_pgalloc.c) +endif() + +if(CONFIG_BUILD_PROTECTED) + list(APPEND SRCS qemu_userspace.c qemu_allocateheap.c) +endif() + +target_sources(arch PRIVATE ${SRCS}) diff --git a/arch/arm/src/rk3506/Kconfig b/arch/arm/src/rk3506/Kconfig new file mode 100644 index 0000000000000..3fe578a87d837 --- /dev/null +++ b/arch/arm/src/rk3506/Kconfig @@ -0,0 +1,37 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_CHIP_RK3506 + +menu "RK3506 Chip Selection" + +config RK3506_AMP_SECONDARY + bool "Run as AMP secondary core (do not init GIC distributor)" + default y + ---help--- + When NuttX runs as an AMP subsystem alongside Linux on the same + SoC, the GIC distributor is owned/initialized by the Linux side. + This option makes NuttX initialize only its own GIC CPU interface + (GICC) and skip the distributor (GICD) initialization, so it does + not corrupt the configuration set up by Linux. + +config RK3506_UART4 + bool "UART4 (dw-apb-uart) console" + default y + ---help--- + RK3506 UART4 at 0xff0e0000, used as the NuttX console in the + default AMP configuration. Pins routed to CPU2 by the Linux + device tree. + +config RK3506_UART3 + bool "UART3 (dw-apb-uart)" + default n + ---help--- + RK3506 UART3 at 0xff0d0000, the secondary UART also routed to + CPU2 by the Linux device tree. + +endmenu # "RK3506 Chip Selection" + +endif # ARCH_CHIP_RK3506 diff --git a/arch/arm/src/rk3506/Make.defs b/arch/arm/src/rk3506/Make.defs new file mode 100644 index 0000000000000..8107b89b525a8 --- /dev/null +++ b/arch/arm/src/rk3506/Make.defs @@ -0,0 +1,36 @@ +############################################################################ +# arch/arm/src/qemu/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifeq ($(CONFIG_ARCH_ARMV7A),y) +include armv7-a/Make.defs +endif + +ifeq ($(CONFIG_ARCH_ARMV7R),y) +include armv7-r/Make.defs +endif + +# rk3506-specific C source files +CHIP_CSRCS = rk3506_boot.c rk3506_serial.c rk3506_irq.c rk3506_timer.c + +ifeq ($(CONFIG_ARCH_ARMV7A),y) +CHIP_CSRCS += rk3506_pgalloc.c rk3506_memorymap.c +endif diff --git a/arch/arm/src/rk3506/chip.h b/arch/arm/src/rk3506/chip.h new file mode 100644 index 0000000000000..14e71005cbbd2 --- /dev/null +++ b/arch/arm/src/rk3506/chip.h @@ -0,0 +1,129 @@ +/**************************************************************************** + * arch/arm/src/rk3506/chip.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_RK3506_CHIP_H +#define __ARCH_ARM_SRC_RK3506_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "hardware/rk3506_memorymap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* RK3506 GIC-400 (GICv2): + * GICD (distributor) @ 0xff581000 + * GICC (CPU interface) @ 0xff582000 + * so ICC offset from the distributor base is 0x1000. + */ + +#define RK3506_SPI_IRQ_BASE 32 +#define CHIP_MPCORE_VBASE 0xff581000 +#define MPCORE_ICD_OFFSET 0x00000000 +#define MPCORE_ICC_OFFSET 0x00001000 + +#define PGTABLE_SIZE 0x00004000 +#define PGTABLE_BASE_PADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - PGTABLE_SIZE * CONFIG_SMP_NCPUS) +#define PGTABLE_BASE_VADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - PGTABLE_SIZE * CONFIG_SMP_NCPUS) + +#undef CONFIG_RAM_END +#define CONFIG_RAM_END PGTABLE_BASE_PADDR + +#define NUTTX_TEXT_VADDR (CONFIG_FLASH_VSTART & 0xfff00000) +#define NUTTX_TEXT_PADDR (CONFIG_FLASH_VSTART & 0xfff00000) +#define NUTTX_TEXT_PEND ((CONFIG_FLASH_END + 0x000fffff) & 0xfff00000) +#define NUTTX_TEXT_SIZE (NUTTX_TEXT_PEND - NUTTX_TEXT_PADDR) + +#define NUTTX_RAM_VADDR (CONFIG_RAM_VSTART & 0xfff00000) +#define NUTTX_RAM_PADDR (CONFIG_RAM_START & 0xfff00000) +#define NUTTX_RAM_PEND ((CONFIG_RAM_END + 0x000fffff) & 0xfff00000) +#define NUTTX_RAM_SIZE (NUTTX_RAM_PEND - NUTTX_RAM_PADDR) + +/**************************************************************************** + * Macro Definitions + ****************************************************************************/ + +#ifdef __ASSEMBLY__ + +/**************************************************************************** + * Name: cpuindex + * + * Description: + * Return an index identifying the current CPU. + * + ****************************************************************************/ + +#if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 + .macro cpuindex, index + mrc p15, 0, \index, c0, c0, 5 /* Read the MPIDR */ + and \index, \index, #3 /* Bits 0-1=CPU ID */ + .endm +#endif + +/**************************************************************************** + * Name: setirqstack + * + * Description: + * Set the current stack pointer to the -"top" of the IRQ interrupt + * stack for the current CPU. + * + ****************************************************************************/ + +#if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 + .macro setirqstack, tmp1, tmp2 + mrc p15, 0, \tmp1, c0, c0, 5 /* tmp1=MPIDR */ + and \tmp1, \tmp1, #3 /* Bits 0-1=CPU ID */ + ldr \tmp2, =g_irqstack_top /* tmp2=Array of IRQ stack pointers */ + lsls \tmp1, \tmp1, #2 /* tmp1=Array byte offset */ + add \tmp2, \tmp2, \tmp1 /* tmp2=Offset address into array */ + ldr sp, [\tmp2, #0] /* sp=Address in stack allocation */ + .endm +#endif + +/**************************************************************************** + * Name: setfiqstack + * + * Description: + * Set the current stack pointer to the -"top" of the FIQ interrupt + * stack for the current CPU. + * + ****************************************************************************/ + +#if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 + .macro setfiqstack, tmp1, tmp2 + mrc p15, 0, \tmp1, c0, c0, 5 /* tmp1=MPIDR */ + and \tmp1, \tmp1, #3 /* Bits 0-1=CPU ID */ + ldr \tmp2, =g_fiqstack_top /* tmp2=Array of FIQ stack pointers */ + lsls \tmp1, \tmp1, #2 /* tmp1=Array byte offset */ + add \tmp2, \tmp2, \tmp1 /* tmp2=Offset address into array */ + ldr sp, [\tmp2, #0] /* sp=Address in stack allocation */ + .endm +#endif + +#endif /* __ASSEMBLY__ */ + +#endif /* __ARCH_ARM_SRC_RK3506_CHIP_H */ diff --git a/arch/arm/src/rk3506/hardware/rk3506_memorymap.h b/arch/arm/src/rk3506/hardware/rk3506_memorymap.h new file mode 100644 index 0000000000000..6b56b3e48aeb1 --- /dev/null +++ b/arch/arm/src/rk3506/hardware/rk3506_memorymap.h @@ -0,0 +1,67 @@ +/**************************************************************************** + * arch/arm/src/rk3506/hardware/rk3506_memorymap.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_QEMU_HARDWARE_QEMU_MEMORYMAP_H +#define __ARCH_ARM_SRC_QEMU_HARDWARE_QEMU_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#undef ARMV7A_PGTABLE_MAPPING /* We do not remap the page table */ + +/* Check if the user has configured the page table address */ + +#if !defined(PGTABLE_BASE_PADDR) || !defined(PGTABLE_BASE_VADDR) + +/* Sanity check.. if one is undefined, both should be undefined */ + +# if defined(PGTABLE_BASE_PADDR) || defined(PGTABLE_BASE_VADDR) +# error "Only one of PGTABLE_BASE_PADDR or PGTABLE_BASE_VADDR is defined" +# endif + +/* A sanity check, if the configuration says that the page table is read-only + * and pre-initialized (maybe ROM), then it should have also defined both of + * the page table base addresses. + */ + +# ifdef CONFIG_ARCH_ROMPGTABLE +# error "CONFIG_ARCH_ROMPGTABLE defined; PGTABLE_BASE_P/VADDR not defined" +# endif + +#define ARMV7A_PGTABLE_MAPPING 1 + +#else /* !PGTABLE_BASE_PADDR || !PGTABLE_BASE_VADDR */ + +/* Sanity check.. if one is defined, both should be defined */ + +# if !defined(PGTABLE_BASE_PADDR) || !defined(PGTABLE_BASE_VADDR) +# error "One of PGTABLE_BASE_PADDR or PGTABLE_BASE_VADDR is undefined" +# endif + +#endif /* !PGTABLE_BASE_PADDR || !PGTABLE_BASE_VADDR */ + +#endif /* __ARCH_ARM_SRC_QEMU_HARDWARE_QEMU_MEMORYMAP_H */ diff --git a/arch/arm/src/rk3506/rk3506_boot.c b/arch/arm/src/rk3506/rk3506_boot.c new file mode 100644 index 0000000000000..ea5565b15fa36 --- /dev/null +++ b/arch/arm/src/rk3506/rk3506_boot.c @@ -0,0 +1,165 @@ +/**************************************************************************** + * arch/arm/src/rk3506/rk3506_boot.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "arm_internal.h" + +#include "rk3506_irq.h" +#include "rk3506_memorymap.h" +#include "gic.h" + +#ifdef CONFIG_SCHED_INSTRUMENTATION +# include +# include +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* RK3506 CRU: force UART4 source clock to the 24MHz crystal (XIN_OSC0). + * + * This mirrors what the Rockchip HAL does for RT-Thread, which is the proven + * configuration that yields a working 1.5Mbaud console on UART4. NuttX does + * not otherwise touch the CRU, so without this the UART4 source clock would + * stay at the (lower) reset/U-Boot value and the 16550 divisor would produce + * the wrong baud rate. + * + * CRU base = 0xff9a0000 + * SCLK_UART4_SEL/_DIV = CLKSEL_CON31 (offset 0x37c) + * - mux bits[15:13]: 0 = XIN_OSC0 (24MHz) + * - div bits[12:8] : 0 = divide by 1 + * Rockchip CRU registers use the upper 16 bits as a write-enable mask for + * the corresponding lower 16 bits. Writing 0xff000000 enables bits[15:8] + * and clears them -> mux=0, div=0 -> UART4 source = 24MHz. + */ + +#define RK3506_CRU_BASE 0xff9a0000 +#define RK3506_CRU_CLKSEL_CON31 (RK3506_CRU_BASE + 0x37c) +#define RK3506_UART4_CLK_24M 0xff000000 + +/* Raw UART4 (dw-apb 16550, reg-shift=2) breadcrumb for early boot. + * Proves arm_boot() runs and the UART hardware works, independent of + * the NuttX serial driver / OS init. Register index << 2 (reg-shift=2). + */ + +#define RK3506_UART4_BASE 0xff0e0000 +#define UART4_REG(idx) \ + (*(volatile uint32_t *)(RK3506_UART4_BASE + ((idx) << 2))) +#define UART4_RBR_THR_DLL UART4_REG(0) /* THR(w) / DLL(DLAB=1) */ +#define UART4_IER_DLM UART4_REG(1) /* IER / DLM(DLAB=1) */ +#define UART4_FCR UART4_REG(2) /* FIFO control */ +#define UART4_LCR UART4_REG(3) /* Line control */ +#define UART4_LSR UART4_REG(5) /* Line status */ +#define UART4_LSR_THRE (1 << 5) /* TX holding empty */ + +static void rk3506_rawuart_init(void) +{ + /* 24MHz / (16 * 1) = 1.5Mbaud, matching the working RT-Thread config. */ + + UART4_LCR = 0x80; /* DLAB=1 */ + UART4_RBR_THR_DLL = 0x01; /* DLL = 1 */ + UART4_IER_DLM = 0x00; /* DLM = 0 */ + UART4_LCR = 0x03; /* DLAB=0, 8N1 */ + UART4_FCR = 0x07; /* enable+clear FIFOs */ +} + +void rk3506_rawuart_puts(const char *s) +{ + while (*s) + { + while ((UART4_LSR & UART4_LSR_THRE) == 0); + UART4_RBR_THR_DLL = (uint32_t)*s++; + } +} + +/* Debug marker: print a tag repeatedly so it survives the board-powered + * CH340 USB-serial re-enumeration window (2-3s) on every board reset. + */ + +void rk3506_dbgmark(const char *tag) +{ + int i; + + /* Re-assert the known-good 1.5Mbaud divisor before printing. By the time + * the OS reaches later init stages, the u16550 serial driver may have + * reconfigured UART4's divisor, which would garble these raw markers. + */ + + rk3506_rawuart_init(); + + for (i = 0; i < 30; i++) + { + rk3506_rawuart_puts(tag); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: arm_boot + * + * Description: + * Complete boot operations started in arm_head.S + * + ****************************************************************************/ + +void arm_boot(void) +{ +#ifdef CONFIG_ARCH_PERF_EVENTS + /* Perf init */ + + up_perf_init(0); +#endif + +#ifdef CONFIG_ARCH_ARMV7A + /* Set the page table for section */ + + rk3506_setupmappings(); +#endif + + arm_fpuconfig(); + + /* Force UART4 source clock to 24MHz before bringing up the console. */ + + putreg32(RK3506_UART4_CLK_24M, RK3506_CRU_CLKSEL_CON31); + + /* Early boot breadcrumb (single line) before the serial driver comes up. */ + + rk3506_rawuart_init(); + rk3506_rawuart_puts("\r\n[RK3506] NuttX arm_boot reached\r\n"); + +#ifdef USE_EARLYSERIALINIT + /* Perform early serial initialization if we are going to use the serial + * driver. + */ + + arm_earlyserialinit(); +#endif +} diff --git a/arch/arm/src/rk3506/rk3506_irq.c b/arch/arm/src/rk3506/rk3506_irq.c new file mode 100644 index 0000000000000..5706a71a11a6d --- /dev/null +++ b/arch/arm/src/rk3506/rk3506_irq.c @@ -0,0 +1,195 @@ +/**************************************************************************** + * arch/arm/src/rk3506/rk3506_irq.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include "arm_internal.h" +#include "sctlr.h" +#include "gic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Size of the interrupt stack allocation */ + +#define INTSTACK_ALLOC (CONFIG_SMP_NCPUS * INTSTACK_SIZE) + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 +/* In the SMP configuration, we will need custom IRQ and FIQ stacks. + * These definitions provide the aligned stack allocations. + */ + +static uint64_t g_irqstack_alloc[INTSTACK_ALLOC >> 3]; +static uint64_t g_fiqstack_alloc[INTSTACK_ALLOC >> 3]; + +/* These are arrays that point to the top of each interrupt stack */ + +uintptr_t g_irqstack_top[CONFIG_SMP_NCPUS] = +{ + (uintptr_t)g_irqstack_alloc + INTSTACK_SIZE, +#if CONFIG_SMP_NCPUS > 1 + (uintptr_t)g_irqstack_alloc + (2 * INTSTACK_SIZE), +#endif +#if CONFIG_SMP_NCPUS > 2 + (uintptr_t)g_irqstack_alloc + (3 * INTSTACK_SIZE), +#endif +#if CONFIG_SMP_NCPUS > 3 + (uintptr_t)g_irqstack_alloc + (4 * INTSTACK_SIZE) +#endif +}; + +uintptr_t g_fiqstack_top[CONFIG_SMP_NCPUS] = +{ + (uintptr_t)g_fiqstack_alloc + INTSTACK_SIZE, +#if CONFIG_SMP_NCPUS > 1 + (uintptr_t)g_fiqstack_alloc + 2 * INTSTACK_SIZE, +#endif +#if CONFIG_SMP_NCPUS > 2 + (uintptr_t)g_fiqstack_alloc + 3 * INTSTACK_SIZE, +#endif +#if CONFIG_SMP_NCPUS > 3 + (uintptr_t)g_fiqstack_alloc + 4 * INTSTACK_SIZE +#endif +}; + +#endif + +/* Symbols defined via the linker script */ + +extern uint8_t _vector_start[]; /* Beginning of vector block */ +extern uint8_t _vector_end[]; /* End+1 of vector block */ + +/* Raw UART4 debug breadcrumb helpers (defined in rk3506_boot.c). Used to + * localize where boot hangs, independent of the OS/serial driver. The + * marker prints repeatedly so it survives the CH340 USB re-enumeration + * window (board-powered adapter re-enumerates 2-3s on every reset). + */ + +void rk3506_rawuart_puts(const char *s); +void rk3506_dbgmark(const char *tag); + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_irqinitialize + * + * Description: + * This function is called by up_initialize() during the bring-up of the + * system. It is the responsibility of this function to but the interrupt + * subsystem into the working and ready state. + * + ****************************************************************************/ + +void up_irqinitialize(void) +{ +#ifdef CONFIG_RK3506_AMP_SECONDARY + int i; +#endif + +#ifdef CONFIG_ARCH_LOWVECTORS + /* Set the VBAR register to the address of the vector table */ + + DEBUGASSERT((((uintptr_t)_vector_start) & ~VBAR_MASK) == 0); + cp15_wrvbar((uint32_t)_vector_start); +#endif + + /* The following operations need to be atomic, but since this function is + * called early in the initialization sequence, we expect to have exclusive + * access to the GIC. + */ + +#ifdef CONFIG_RK3506_AMP_SECONDARY + /* AMP secondary core: the GIC distributor (GICD) is owned and already + * initialized by the Linux side running on the other cores. We must NOT + * call arm_gic0_initialize() here, otherwise we would reset the global + * distributor configuration and break Linux. Only initialize our own + * GIC CPU interface (GICC). + */ + + arm_gic_initialize(); /* CPU interface (GICC) only */ + + /* AMP coexistence fix (root cause of the early IRQ-storm crash): + * + * arm_gic_initialize() only disables this core's banked SGIs/PPIs + * (IRQ 0-31). Any SPI (IRQ >= 32) left enabled, pending, and targeting + * CPU2 in the shared distributor would be taken the instant we run + * up_irq_enable() below, vectoring into irq_unexpected_isr() (no handler) + * and producing a crash/garbage loop on UART4 (observed symptom). + * + * NuttX on CPU2 is brought up by U-Boot BEFORE Linux configures the GIC, + * so it is safe to clear the SPI enable bits here: Linux re-enables the + * SPIs it needs during its own GIC init later. This mirrors RT-Thread's + * arm_gic_dist_init(), proven to coexist with Linux on this SoC. + */ + + for (i = 32; i < NR_IRQS; i += 32) + { + putreg32(0xffffffff, GIC_ICDICER(i)); /* Clear-Enable: disable SPIs */ + } +#else + /* Initialize the Generic Interrupt Controller (GIC) for CPU0. + * In AMP mode, we want arm_gic0_initialize to be called only once. + */ + + if (sched_getcpu() == 0) + { + arm_gic0_initialize(); /* Initialization unique to CPU0 */ + } + + arm_gic_initialize(); /* Initialization common to all CPUs */ +#endif + +#ifndef CONFIG_SUPPRESS_INTERRUPTS + /* And finally, enable interrupts */ + + arm_color_intstack(); + up_irq_enable(); +#endif +} + +/**************************************************************************** + * Name: up_get_intstackbase + * + * Description: + * Return a pointer to the "alloc" the correct interrupt stack allocation + * for the current CPU. + * + ****************************************************************************/ + +#if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 +uintptr_t up_get_intstackbase(int cpu) +{ + return g_irqstack_top[cpu] - INTSTACK_SIZE; +} +#endif diff --git a/arch/arm/src/rk3506/rk3506_irq.h b/arch/arm/src/rk3506/rk3506_irq.h new file mode 100644 index 0000000000000..1350176262d68 --- /dev/null +++ b/arch/arm/src/rk3506/rk3506_irq.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * arch/arm/src/rk3506/rk3506_irq.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_RK3506_RK3506_IRQ_H +#define __ARCH_ARM_SRC_RK3506_RK3506_IRQ_H + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: arm_earlyirqinit + ****************************************************************************/ + +void arm_earlyirqinit(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM_SRC_RK3506_RK3506_IRQ_H */ diff --git a/arch/arm/src/rk3506/rk3506_memorymap.c b/arch/arm/src/rk3506/rk3506_memorymap.c new file mode 100644 index 0000000000000..9638b368ae4ea --- /dev/null +++ b/arch/arm/src/rk3506/rk3506_memorymap.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * arch/arm/src/rk3506/rk3506_memorymap.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "mmu.h" + +#include "hardware/rk3506_memorymap.h" +#include "rk3506_memorymap.h" + +/**************************************************************************** + * Macro Definitions + ****************************************************************************/ + +#define _NSECTIONS(b) (((b) + 0x000fffff) >> 20) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct section_mapping_s g_section_mapping[] = +{ + { + RK3506_DDR_PSECTION, RK3506_DDR_VSECTION, + MMU_MEMFLAGS, _NSECTIONS(RK3506_DDR_SECSIZE) + }, + { + RK3506_DEVICE_PSECTION, RK3506_DEVICE_VSECTION, + MMU_IOFLAGS, _NSECTIONS(RK3506_DEVICE_SECSIZE) + }, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rk3506_setupmappings + * + * Description: + * Initializes the non-code area page table + * + ****************************************************************************/ + +int rk3506_setupmappings(void) +{ + mmu_l1_map_regions(g_section_mapping, nitems(g_section_mapping)); + + return 0; +} diff --git a/arch/arm/src/rk3506/rk3506_memorymap.h b/arch/arm/src/rk3506/rk3506_memorymap.h new file mode 100644 index 0000000000000..b65a9bcaa8ff4 --- /dev/null +++ b/arch/arm/src/rk3506/rk3506_memorymap.h @@ -0,0 +1,84 @@ +/**************************************************************************** + * arch/arm/src/rk3506/rk3506_memorymap.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_RK3506_RK3506_MEMORYMAP_H +#define __ARCH_ARM_SRC_RK3506_RK3506_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* RK3506 Physical Memory Map (for the NuttX AMP subsystem on CPU2) ********* + * + * DDR: 0x00000000 - 0x10000000 (256MB window, normal memory) + * - NuttX firmware loaded at 0x03e00000 (see amp_linux_mcu.its) + * - rpmsg shared memory at 0x03c00000 + * Device: 0xff000000 - 0xfff00000 (peripherals: UART 0xff0e0000, + * GIC 0xff581000, etc, device memory) + */ + +#define RK3506_DDR_PSECTION 0x00000000 /* 0x00000000-0x10000000 */ +#define RK3506_DEVICE_PSECTION 0xff000000 /* 0xff000000-0xfff00000 */ + +#define RK3506_DDR_VSECTION RK3506_DDR_PSECTION +#define RK3506_DEVICE_VSECTION RK3506_DEVICE_PSECTION + +/* Sizes of memory regions in bytes. */ + +#define RK3506_DDR_SECSIZE (256 * 1024 * 1024) +#define RK3506_DEVICE_SECSIZE (15 * 1024 * 1024) + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +int rk3506_setupmappings(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM_SRC_RK3506_RK3506_MEMORYMAP_H */ diff --git a/arch/arm/src/rk3506/rk3506_pgalloc.c b/arch/arm/src/rk3506/rk3506_pgalloc.c new file mode 100644 index 0000000000000..9d6c7b855a83b --- /dev/null +++ b/arch/arm/src/rk3506/rk3506_pgalloc.c @@ -0,0 +1,78 @@ +/**************************************************************************** + * arch/arm/src/rk3506/rk3506_pgalloc.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include + +#ifdef CONFIG_MM_PGALLOC + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Currently, page cache memory must be allocated in DRAM. There are other + * possibilities, but the logic in this file will have to extended in order + * handle any other possibility. + */ + +#ifndef CONFIG_ARCH_PGPOOL_MAPPING +# error CONFIG_ARCH_PGPOOL_MAPPING must be selected +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_allocate_pgheap + * + * Description: + * If there is a page allocator in the configuration, then this function + * must be provided by the platform-specific code. The OS initialization + * logic will call this function early in the initialization sequence to + * get the page heap information needed to configure the page allocator. + * + * Input parameters: + * heap_start - A double pointer to the start address of the pgheap + * heap_size - A pointer to the size of the pgheap + * + * Returned Value: + * None + * + ****************************************************************************/ + +void up_allocate_pgheap(void **heap_start, size_t *heap_size) +{ + DEBUGASSERT(heap_start && heap_size); + + *heap_start = (void *)CONFIG_ARCH_PGPOOL_PBASE; + *heap_size = (size_t)CONFIG_ARCH_PGPOOL_SIZE; +} + +#endif /* CONFIG_MM_PGALLOC */ diff --git a/arch/arm/src/rk3506/rk3506_serial.c b/arch/arm/src/rk3506/rk3506_serial.c new file mode 100644 index 0000000000000..69eb27fb1621c --- /dev/null +++ b/arch/arm/src/rk3506/rk3506_serial.c @@ -0,0 +1,69 @@ +/*************************************************************************** + * arch/arm/src/rk3506/rk3506_serial.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ***************************************************************************/ + +/*************************************************************************** + * Included Files + ***************************************************************************/ + +#include + +#include + +#include "arm_internal.h" + +#ifdef CONFIG_16550_UART + +/*************************************************************************** + * Public Functions + ***************************************************************************/ + +/*************************************************************************** + * Name: arm_earlyserialinit + * + * Description: + * see arm_internal.h + * + ***************************************************************************/ + +void arm_earlyserialinit(void) +{ + /* Enable the console UART. The other UARTs will be initialized if and + * when they are first opened. + */ + + u16550_earlyserialinit(); +} + +/*************************************************************************** + * Name: arm_serialinit + * + * Description: + * see arm_internal.h + * + ***************************************************************************/ + +void arm_serialinit(void) +{ + u16550_serialinit(); +} + +#endif /* CONFIG_16550_UART */ diff --git a/arch/arm/src/rk3506/rk3506_timer.c b/arch/arm/src/rk3506/rk3506_timer.c new file mode 100644 index 0000000000000..3453fc3da3d21 --- /dev/null +++ b/arch/arm/src/rk3506/rk3506_timer.c @@ -0,0 +1,38 @@ +/**************************************************************************** + * arch/arm/src/rk3506/rk3506_timer.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "arm_timer.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void up_timer_initialize(void) +{ + up_alarm_set_lowerhalf(arm_timer_initialize(0)); +} From d419c7db1d5233c8442e6d3445505e74c5541992 Mon Sep 17 00:00:00 2001 From: likun17 Date: Thu, 25 Jun 2026 16:14:29 +0800 Subject: [PATCH 3/4] boards/arm/rk3506: add Luckfox Lyra AMP subsystem board Add the Luckfox Lyra (RK3506) board running NuttX as an AMP subsystem on Cortex-A7 CPU2. Boot flow: U-Boot psci_cpu_on() jumps to the image in the AMP-reserved DRAM window, arm_boot() sets up the MMU, and NSH comes up on UART4 (1.5Mbaud). The nsh defconfig enables: - Console on UART4 (16550, MMIO32, REGINCR=1) with the TX driver and a board-side poll thread for RX (the RX interrupt is unreliable on the GIC distributor shared with Linux). - uORB + sensor framework with a CSV-backed fake accelerometer demo on /dev/uorb/sensor_accel0, plus uorb_listener/generator/unit_test. - NSH tab-completion and command history. - RAM disk tooling (mkrd + FAT + mkfatfs) and the ramtest / memtester / fstest utilities. rk3506_bringup.c writes a small CSV to tmpfs and registers the fake sensor, and spawns the console RX poll thread. Signed-off-by: likun17 --- boards/Kconfig | 12 + .../rk3506/luckfox-lyra-amp/CMakeLists.txt | 25 ++ boards/arm/rk3506/luckfox-lyra-amp/Kconfig | 7 + .../luckfox-lyra-amp/configs/nsh/defconfig | 77 +++++++ .../rk3506/luckfox-lyra-amp/include/board.h | 61 +++++ .../rk3506/luckfox-lyra-amp/scripts/Make.defs | 42 ++++ .../luckfox-lyra-amp/scripts/dramboot.ld | 138 ++++++++++++ .../luckfox-lyra-amp/src/CMakeLists.txt | 29 +++ .../arm/rk3506/luckfox-lyra-amp/src/Makefile | 31 +++ .../arm/rk3506/luckfox-lyra-amp/src/rk3506.h | 61 +++++ .../luckfox-lyra-amp/src/rk3506_boardinit.c | 126 +++++++++++ .../luckfox-lyra-amp/src/rk3506_bringup.c | 213 ++++++++++++++++++ 12 files changed, 822 insertions(+) create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/CMakeLists.txt create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/Kconfig create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/include/board.h create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/scripts/Make.defs create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/scripts/dramboot.ld create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/src/CMakeLists.txt create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/src/Makefile create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/src/rk3506.h create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_boardinit.c create mode 100644 boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_bringup.c diff --git a/boards/Kconfig b/boards/Kconfig index c9be61afe4416..7272790029bfc 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -2511,6 +2511,14 @@ config ARCH_BOARD_QEMU_ARMV7A This options selects support for NuttX on the QEMU ARMv7a + virt board featuring the qemu ARMv7a CPUs. +config ARCH_BOARD_LUCKFOX_LYRA_AMP + bool "Luckfox Lyra RK3506 AMP subsystem board" + depends on ARCH_CHIP_RK3506 + ---help--- + This option selects support for NuttX running as an AMP subsystem + on the Cortex-A7 CPU2 of the Rockchip RK3506 (Luckfox Lyra), brought + up by U-Boot via PSCI, alongside Linux on the other cores. + config ARCH_BOARD_QEMU_ARMV8A bool "Qemu ARMv8a CPUs board" depends on ARCH_CHIP_QEMU @@ -3940,6 +3948,7 @@ config ARCH_BOARD default "a2g-tc397-5v-tft" if ARCH_BOARD_A2G_TC397_5V_TFT default "triboard_tc4x9_com" if ARCH_BOARD_TRIBOARD_TC4X9_COM default "qemu-armv7a" if ARCH_BOARD_QEMU_ARMV7A + default "luckfox-lyra-amp" if ARCH_BOARD_LUCKFOX_LYRA_AMP default "qemu-armv7r" if ARCH_BOARD_QEMU_ARMV7R default "qemu-armv8a" if ARCH_BOARD_QEMU_ARMV8A default "pinephone" if ARCH_BOARD_PINEPHONE @@ -4182,6 +4191,9 @@ endif if ARCH_BOARD_QEMU_ARMV7A source "boards/arm/qemu/qemu-armv7a/Kconfig" endif +if ARCH_BOARD_LUCKFOX_LYRA_AMP +source "boards/arm/rk3506/luckfox-lyra-amp/Kconfig" +endif if ARCH_BOARD_QEMU_ARMV8A source "boards/arm64/qemu/qemu-armv8a/Kconfig" endif diff --git a/boards/arm/rk3506/luckfox-lyra-amp/CMakeLists.txt b/boards/arm/rk3506/luckfox-lyra-amp/CMakeLists.txt new file mode 100644 index 0000000000000..aea7eee46a4ff --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/CMakeLists.txt @@ -0,0 +1,25 @@ +# ############################################################################## +# boards/arm/qemu/qemu-armv7a/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/dramboot.ld") + +add_subdirectory(src) diff --git a/boards/arm/rk3506/luckfox-lyra-amp/Kconfig b/boards/arm/rk3506/luckfox-lyra-amp/Kconfig new file mode 100644 index 0000000000000..793b1e671720c --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/Kconfig @@ -0,0 +1,7 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_BOARD_LUCKFOX_LYRA_AMP +endif diff --git a/boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig b/boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig new file mode 100644 index 0000000000000..7466f256c6eff --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig @@ -0,0 +1,77 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +CONFIG_16550_ADDRWIDTH=0 +CONFIG_16550_POLLING=y +CONFIG_16550_REGWIDTH=32 +CONFIG_16550_UART0=y +CONFIG_16550_UART0_BASE=0xff0e0000 +CONFIG_16550_UART0_BAUD=1500000 +CONFIG_16550_UART0_CLOCK=24000000 +CONFIG_16550_UART0_IRQ=70 +CONFIG_16550_UART0_SERIAL_CONSOLE=y +CONFIG_16550_UART=y +CONFIG_ALARM_ARCH=y +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="luckfox-lyra-amp" +CONFIG_ARCH_BOARD_LUCKFOX_LYRA_AMP=y +CONFIG_ARCH_CHIP="rk3506" +CONFIG_ARCH_CHIP_RK3506=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_LOWVECTORS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LOOPSPERMSEC=393693 +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEFAULT_TASK_STACKSIZE=4096 +CONFIG_EXAMPLES_HELLO=y +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FLASH_SIZE=1048576 +CONFIG_FLASH_START=0x03e00000 +CONFIG_FLASH_VSTART=0x03e00000 +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_FS_TMPFS=y +CONFIG_IDLETHREAD_STACKSIZE=4096 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_LIBM=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_RAM_SIZE=15728640 +CONFIG_RAM_START=0x03f00000 +CONFIG_RAM_VSTART=0x03f00000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HAVE_PARENT=y +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_SENSORS=y +CONFIG_SENSORS_FAKESENSOR=y +CONFIG_SERIAL_UART_ARCH_MMIO=y +CONFIG_SIG_DEFAULT=y +CONFIG_START_DAY=23 +CONFIG_START_MONTH=6 +CONFIG_START_YEAR=2026 +CONFIG_SYSTEM_NSH=y +CONFIG_TESTING_FSTEST=y +CONFIG_TESTING_RAMTEST=y +CONFIG_TTY_SIGINT=y +CONFIG_UORB=y +CONFIG_UORB_GENERATOR=y +CONFIG_UORB_LISTENER=y +CONFIG_UORB_STORAGE_DIR="/tmp" +CONFIG_UORB_TESTS=y +CONFIG_USEC_PER_TICK=1000 +CONFIG_USENSOR=y +CONFIG_UTILS_MEMTESTER=y diff --git a/boards/arm/rk3506/luckfox-lyra-amp/include/board.h b/boards/arm/rk3506/luckfox-lyra-amp/include/board.h new file mode 100644 index 0000000000000..1563558d5ad17 --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/include/board.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * boards/arm/rk3506/luckfox-lyra-amp/include/board.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_RK3506_LUCKFOX_LYRA_AMP_INCLUDE_BOARD_H +#define __BOARDS_ARM_RK3506_LUCKFOX_LYRA_AMP_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_QEMU_QEMU_ARMV7A_INCLUDE_BOARD_H */ diff --git a/boards/arm/rk3506/luckfox-lyra-amp/scripts/Make.defs b/boards/arm/rk3506/luckfox-lyra-amp/scripts/Make.defs new file mode 100644 index 0000000000000..a49e02016e253 --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/scripts/Make.defs @@ -0,0 +1,42 @@ +############################################################################ +# boards/arm/qemu/qemu-armv7a/scripts/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/.config +include $(TOPDIR)/tools/Config.mk +include $(TOPDIR)/arch/arm/src/armv7-a/Toolchain.defs + +LDSCRIPT = dramboot.ld + +ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT) + +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ + +# NXFLAT module definitions + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)$(DELIM)binfmt$(DELIM)libnxflat$(DELIM)gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 diff --git a/boards/arm/rk3506/luckfox-lyra-amp/scripts/dramboot.ld b/boards/arm/rk3506/luckfox-lyra-amp/scripts/dramboot.ld new file mode 100644 index 0000000000000..19e481ecd6de1 --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/scripts/dramboot.ld @@ -0,0 +1,138 @@ +/**************************************************************************** + * boards/arm/qemu/qemu-armv7a/scripts/dramboot.ld + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#include + +OUTPUT_ARCH(arm) +ENTRY(__start) + +MEMORY +{ + ROM (rx) : ORIGIN = CONFIG_FLASH_START, LENGTH = CONFIG_FLASH_SIZE + RAM (rwx): ORIGIN = CONFIG_RAM_START, LENGTH = CONFIG_RAM_SIZE +} + +SECTIONS +{ + + /* where the global variable out-of-bounds detection information located */ + +#ifdef CONFIG_MM_KASAN_GLOBAL + .kasan.unused : { + *(.data..LASANLOC*) + } + .kasan.global : { + KEEP (*(.data..LASAN0)) + KEEP (*(.data.rel.local..LASAN0)) + } + .kasan.shadows : { + *(.kasan.shadows) + } +#endif + + .text : { + _stext = .; /* Text section */ + __text_start = .; + *(.vectors) + *(.text*) + *(.fixup) + *(.gnu.warning) + } > ROM + + . = ALIGN(4096); + + .init_section : { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .ctors)) + _einit = ABSOLUTE(.); + . = ALIGN(4096); + _etext = .; /* End_1 of .text */ + _sztext = _etext - _stext; + } > ROM + + .ARM.extab : + { + *(.ARM.extab*) + } > ROM + + /* .ARM.exidx is sorted, so has to go in its own output section. */ + + PROVIDE_HIDDEN (__exidx_start = .); + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > ROM + PROVIDE_HIDDEN (__exidx_end = .); + + .rodata : { + _srodata = .; /* Read-only data */ + *(.rodata*) + *(.data.rel.ro*) + KEEP(*(SORT(.scattered_array*))); + . = ALIGN(4096); + _erodata = .; + } > ROM + + _eronly = LOADADDR(.data); + .data : { /* Data */ + _sdata = .; + *(.data*) + . = ALIGN(8); + __start_impls = .; + *(.impls) + KEEP(*(.impls)) + . = ALIGN(4); + __stop_impls = .; + _edata = .; + } > RAM AT > ROM + + .noinit : { + _snoinit = ABSOLUTE(.); + *(.noinit*) + _enoinit = ABSOLUTE(.); + } > RAM + + .bss : { /* BSS */ + _sbss = .; + *(.bss*) + . = ALIGN(4096); + _ebss = .; + } > RAM + + /* Sections to be discarded */ + /DISCARD/ : { + *(.exit.text) + *(.exit.data) + *(.exitcall.exit) + } + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } +} + diff --git a/boards/arm/rk3506/luckfox-lyra-amp/src/CMakeLists.txt b/boards/arm/rk3506/luckfox-lyra-amp/src/CMakeLists.txt new file mode 100644 index 0000000000000..198bf94e5eadb --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/src/CMakeLists.txt @@ -0,0 +1,29 @@ +# ############################################################################## +# boards/arm/qemu/qemu-armv7a/src/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## +set(SRCS rk3506_boardinit.c rk3506_bringup.c) + +if(CONFIG_LIBC_FDT) + target_include_directories(board + PRIVATE ${NUTTX_DIR}/libs/libc/fdt/dtc/libfdt) +endif() + +target_sources(board PRIVATE ${SRCS}) diff --git a/boards/arm/rk3506/luckfox-lyra-amp/src/Makefile b/boards/arm/rk3506/luckfox-lyra-amp/src/Makefile new file mode 100644 index 0000000000000..651b017a0efe2 --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/src/Makefile @@ -0,0 +1,31 @@ +############################################################################ +# boards/arm/qemu/qemu-armv7a/src/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/Make.defs + +CSRCS = rk3506_boardinit.c rk3506_bringup.c + +ifeq ($(CONFIG_LIBC_FDT),y) +CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)fdt$(DELIM)dtc$(DELIM)libfdt +endif + +include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/rk3506/luckfox-lyra-amp/src/rk3506.h b/boards/arm/rk3506/luckfox-lyra-amp/src/rk3506.h new file mode 100644 index 0000000000000..c6ba037e323af --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/src/rk3506.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * boards/arm/rk3506/luckfox-lyra-amp/src/rk3506.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_RK3506_LUCKFOX_LYRA_AMP_SRC_RK3506_H +#define __BOARDS_ARM_RK3506_LUCKFOX_LYRA_AMP_SRC_RK3506_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Functions Definitions + ****************************************************************************/ + +/**************************************************************************** + * Name: rk3506_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +#if defined(CONFIG_BOARDCTL) || defined(CONFIG_BOARD_LATE_INITIALIZE) +int rk3506_bringup(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_RK3506_LUCKFOX_LYRA_AMP_SRC_RK3506_H */ diff --git a/boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_boardinit.c b/boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_boardinit.c new file mode 100644 index 0000000000000..bb58af5b3349f --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_boardinit.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_boardinit.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include "rk3506.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rk3506_memory_initialize + * + * Description: + * All qemu architectures must provide the following entry point. This + * entry point is called early in the initialization before memory has + * been configured. This board-specific function is responsible for + * configuring any on-board memories. + * + * Logic in rk3506_memory_initialize must be careful to avoid using any + * global variables because those will be uninitialized at the time this + * function is called. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void rk3506_memory_initialize(void) +{ + /* SDRAM was initialized by a bootloader in the supported configurations. */ +} + +/**************************************************************************** + * Name: rk3506_board_initialize + * + * Description: + * All qemu architectures must provide the following entry point. This + * entry point is called in the initialization phase -- after + * rk3506_memory_initialize and after all memory has been configured and + * mapped but before any devices have been initialized. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void rk3506_board_initialize(void) +{ +#ifdef CONFIG_ARCH_LEDS + /* Configure on-board LEDs if LED support has been selected. */ + +#endif +} + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will be + * called immediately after up_intitialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + /* Perform board initialization */ + + rk3506_bringup(); +} +#endif /* CONFIG_BOARD_LATE_INITIALIZE */ + +#if defined(CONFIG_BOARDCTL_POWEROFF) && defined(CONFIG_ARM_PSCI) +int board_power_off(int status) +{ + UNUSED(status); + + up_systempoweroff(); + return 0; +} +#endif \ No newline at end of file diff --git a/boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_bringup.c b/boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_bringup.c new file mode 100644 index 0000000000000..4fc40d9dca8d8 --- /dev/null +++ b/boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_bringup.c @@ -0,0 +1,213 @@ +/**************************************************************************** + * boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_bringup.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifdef CONFIG_SENSORS_FAKESENSOR +# include +# include +#endif + +#include "chip.h" +#include "rk3506.h" + +/* Console uart_dev_t accessor exported by drivers/serial/uart_16550.c. */ + +FAR uart_dev_t *u16550_consoledev(void); + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Poll-driven console RX worker. + * + * UART4 RX is wired to GIC SPI IRQ70. On this AMP SoC the GIC distributor is + * shared with Linux, so IRQ70 cannot be delivered to CPU2 reliably (Linux + * owns/reconfigures the distributor and the SPI enable/target for IRQ70 does + * not stick). Polling the UART bypasses the GIC entirely and is reliable; + * TX and the per-CPU PPI timer are unaffected. + */ + +static int rk3506_rxpoll(int argc, char *argv[]) +{ + FAR uart_dev_t *con = u16550_consoledev(); + + /* Disable IRQ70 so the (unreliable) RX interrupt never races this poller + * for the same RBR byte. Give NSH a moment to open the console first. + */ + + usleep(200000); + up_disable_irq(70); + + /* Poll the Line Status Register; when data is ready, push it up through + * the normal serial upper-half via uart_recvchars() - exactly what the RX + * ISR would have done. + * + * LSR @ 0xff0e0000 + (5 << 2), Data-Ready = bit0 + */ + + for (; ; ) + { + uint32_t lsr = *(volatile uint32_t *)(0xff0e0000 + (5 << 2)); + + if (lsr & 0x01) + { + uart_recvchars(con); + } + else + { + usleep(2000); + } + } + + return 0; +} + +#ifdef CONFIG_SENSORS_FAKESENSOR +/* Register a demo accelerometer backed by a small CSV that fakesensor + * replays in a loop. This brings up a live sensor node at + * /dev/uorb/sensor_accel0 with no real hardware, so the full uORB pipeline + * (sensor framework -> uORB -> read/poll) can be exercised on the board: + * + * uorb_listener sensor_accel # watch the live stream + * cat /dev/uorb/sensor_accel0 # raw binary samples + * + * The CSV format is fakesensor's own: first line "interval:", second + * line the header, then rows of samples. EOF wraps back to the top, so a + * handful of rows produces an endless stream. + */ + +static void rk3506_fakesensor_setup(void) +{ + static const char csv[] = + "interval:100\n" /* 10 Hz */ + "x,y,z\n" + "0.10,0.00,9.81\n" + "0.20,0.05,9.79\n" + "0.05,-0.05,9.82\n" + "-0.10,0.10,9.80\n"; + + const char *path = CONFIG_LIBC_TMPDIR "/accel0.csv"; + struct file f; + int ret; + + ret = file_open(&f, path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: fakesensor CSV open %s: %d\n", path, ret); + return; + } + + file_write(&f, csv, sizeof(csv) - 1); + file_close(&f); + + /* type, csv path, devno=0, batch buffer = 8 samples */ + + ret = fakesensor_init(SENSOR_TYPE_ACCELEROMETER, path, 0, 8); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: fakesensor_init: %d\n", ret); + return; + } + + syslog(LOG_INFO, "fakesensor accel0 -> /dev/uorb/sensor_accel0\n"); +} +#endif /* CONFIG_SENSORS_FAKESENSOR */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rk3506_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +int rk3506_bringup(void) +{ + int ret; + + UNUSED(ret); + + /* Defer the rest of bring-up (and the subsequent one-shot NSH banner) a + * few seconds. The console UART4 is observed through a board-powered CH340 + * USB-serial adapter that re-enumerates on the host for ~2-3s after every + * board reset. Without this delay the NSH banner is emitted while the host + * port is still gone and is lost. This also exercises the timer tick. + */ + + sleep(3); + + /* Spawn the poll-driven console RX worker (see rk3506_rxpoll above: + * interrupt-driven RX is unreliable on the AMP-shared GIC). + */ + + kthread_create("rxpoll", 100, 2048, rk3506_rxpoll, NULL); + +#ifdef CONFIG_FS_TMPFS + /* Mount the tmpfs file system */ + + ret = nx_mount(NULL, CONFIG_LIBC_TMPDIR, "tmpfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount tmpfs at %s: %d\n", + CONFIG_LIBC_TMPDIR, ret); + } +#endif + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, "/proc", "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_FAKESENSOR + /* Register a demo accelerometer (CSV-backed) on /dev/uorb/sensor_accel0. */ + + rk3506_fakesensor_setup(); +#endif + + return OK; +} From a14e6451d43c79bbbb5de93c0e49df0f00293d5f Mon Sep 17 00:00:00 2001 From: likun17 Date: Mon, 13 Jul 2026 16:49:15 +0800 Subject: [PATCH 4/4] boards/arm/rk3506: set Luckfox Lyra AMP NuttX RAM to 32MB CONFIG_RAM_SIZE 0x02000000 (32MB), RAM_START 0x03f00000. Total NuttX footprint 0x03e00000-0x05f00000 (33MB); the Linux kernel dts amp_reserved node reserves this whole range (no-map). Hard ceiling is 193MB, bounded by the 256MB DDR window mapped in the rk3506 MMU setup. Signed-off-by: likun17 --- boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig b/boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig index 7466f256c6eff..369f9792ad586 100644 --- a/boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig +++ b/boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig @@ -46,7 +46,7 @@ CONFIG_LIBM=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_READLINE=y -CONFIG_RAM_SIZE=15728640 +CONFIG_RAM_SIZE=33554432 CONFIG_RAM_START=0x03f00000 CONFIG_RAM_VSTART=0x03f00000 CONFIG_RAW_BINARY=y