diff --git a/Documentation/introduction/detailed_support.rst b/Documentation/introduction/detailed_support.rst index 53162a744d9..40e548ff804 100644 --- a/Documentation/introduction/detailed_support.rst +++ b/Documentation/introduction/detailed_support.rst @@ -335,6 +335,16 @@ AM335x are supported by NuttX: `README `__ file for further, up-to-date information. +ARM Cortex-A53 +============== + +Allwinner A64 +------------- + +The basic port has been completed for the following Allwinner A64 board: + +- **PINE64 PinePhone**: Refer to :doc:`PINE64 PinePhone ` for further information. + ARM Cortex-A9 ============= diff --git a/Documentation/introduction/supported_platforms.rst b/Documentation/introduction/supported_platforms.rst index 7f7d24c45c1..5f3e5f7b870 100644 --- a/Documentation/introduction/supported_platforms.rst +++ b/Documentation/introduction/supported_platforms.rst @@ -25,6 +25,7 @@ from board-to-board. Follow the links for the details: - :ref:`introduction/detailed_support:ARM Cortex-A5` (3) - :ref:`introduction/detailed_support:ARM Cortex-A8` (2) - :ref:`introduction/detailed_support:ARM Cortex-A9` (1) + - :ref:`introduction/detailed_support:ARM Cortex-A53` (1) - :ref:`introduction/detailed_support:ARM Cortex-R4` (2) - :ref:`introduction/detailed_support:ARM Cortex-M0/M0+` (13) - :ref:`introduction/detailed_support:ARM Cortex-M3` (39) diff --git a/Documentation/platforms/arm/a64/boards/pinephone/index.rst b/Documentation/platforms/arm/a64/boards/pinephone/index.rst new file mode 100644 index 00000000000..fc3f3435cb7 --- /dev/null +++ b/Documentation/platforms/arm/a64/boards/pinephone/index.rst @@ -0,0 +1,136 @@ +================ +PINE64 PinePhone +================ + +`PinePhone `_ is an ARM64 smartphone created by PINE64. + +Features +======== + +- **System on Chip:** Allwinner A64 + - **CPU:** Quad-Core ARM Cortex-A53 + - **GPU:** ARM Mali400 MP2 + - **Interrupt Controller:** ARM GIC PL400 (Generic Interrupt Controller v2) + - **Display Engine:** Allwinner Display Engine 2.0 (MIPI DSI with DMA) +- **Display:** Xingbangda XBD599 HD IPS Capacitive Touchscreen (5.95 inches, 1440x720 resolution, 16M colors) +- **LCD Controller:** Sitronix ST7703 (MIPI DSI) +- **RAM:** 2GB or 3GB LPDDR3 SDRAM +- **Internal Storage:** 16GB or 32GB eMMC, extendable up to 2TB via microSD +- **Back Camera:** Single 5MP, 1/4", LED Flash +- **Front Camera:** Single 2MP, f/2.8, 1/5" +- **Sound:** Loudspeaker, 3.5mm jack & mic (jack doubles as Hardware UART if Privacy Switch 6 is Off) +- Modem: Quectel EG25-G + - **LTE-FDD, LTE-TDD, WCDMA, GSM** + - **GNSS:** GPS / GLONASS / BeiDou / Galileo / QZSS, with A-GPS +- 2.4 GHz Wireless: Realtek RTL8723CS + - **WLAN:** WiFi 802.11 b/g/n, single-band, hotspot + - **Bluetooth:** 4.0, A2DP +- **Sensors:** Accelerometer, Gyroscope, Proximity, Ambient Light, Compass +- **Privacy Switches:** Modem, WiFi & Bluetooth, Microphone, Cameras, Headphone +- **Battery:** Lithium-ion, rated capacity 2800mAh (10.64Wh), typical capacity 3000mAh (11.40Wh) +- **I/O:** USB Type-C, USB Host, DisplayPort Alternate Mode output, 15W 5V 3A Quick Charge, follows USB PD specification + +Serial Console +============== + +A `PinePhone Serial Debug Cable `_ +is required to run NuttX on PinePhone. + +On PinePhone, set the `Privacy Switch 6 (Headphone) `_ +to **Off**. + +Connect PinePhone to our computer with the Serial Debug Cable. +On our computer, start a Serial Terminal and connect to the USB Serial Port +at **115.2 kbps**. + +NuttX will appear in the Serial Console when it boots on PinePhone. + +ARM64 Toolchain +=============== + +Before building NuttX for PinePhone, download the ARM64 Toolchain for +**AArch64 Bare-Metal Target** ``aarch64-none-elf`` from +`Arm GNU Toolchain Downloads `_. +(Skip the section for Beta Releases) + +Add the downloaded toolchain ``gcc-arm-...-aarch64-none-elf/bin`` +to the ``PATH`` Environment Variable. + +Check the ARM64 Toolchain: + +.. code:: console + + $ aarch64-none-elf-gcc -v + +Building +======== + +To build NuttX for PinePhone, :doc:`install the prerequisites ` and +:doc:`clone the git repositories ` for ``nuttx`` and ``apps``. + +Configure the NuttX project and build the project: + +.. code:: console + + $ cd nuttx + $ tools/configure.sh pinephone:nsh + $ make + $ cp nuttx.bin Image + $ rm -f Image.gz + $ gzip Image + +This produces the file ``Image.gz``, which will be copied to PinePhone in the next step. + +If the build fails with the error ``token "@" is not valid in preprocessor``, +`apply this patch `_ +to ``gcc-arm-none-eabi/arm-none-eabi/include/_newlib_version.h`` +in the ARM64 Toolchain. + +Booting +======= + +NuttX boots on PinePhone via a microSD Card. To prepare the microSD Card, download the +**PinePhone Jumpdrive Image** ``pine64-pinephone.img.xz`` from +`dreemurrs-embedded/Jumpdrive `_. + +Write the downloaded image to a microSD Card with +`Balena Etcher `_. + +Copy the file ``Image.gz`` from the previous section +and overwrite the file on the microSD Card. + +Check that PinePhone is connected to our computer via a +`Serial Debug Cable `_ at 115.2 kbps. +`Privacy Switch 6 (Headphone) `_ +should be set to **Off**. + +Insert the microSD Card into PinePhone and power up PinePhone. +NuttX boots on PinePhone and NuttShell (nsh) appears in the Serial Console. + +To see the available commands in NuttShell: + +.. code:: console + + $ help + +Configurations +============== + +nsh +--- + +Basic configuration that runs NuttShell (nsh). +This configuration is focused on low level, command-line driver testing. +Built-in applications are supported, but none are enabled. +Serial Console is enabled on UART0 at 115.2 kbps. + +Peripheral Support +================== + +NuttX for PinePhone supports these peripherals: + +=========== ======= ===== +Peripheral Support NOTES +=========== ======= ===== +UART Yes Only UART0 is supported +=========== ======= ===== diff --git a/Documentation/platforms/arm/a64/index.rst b/Documentation/platforms/arm/a64/index.rst new file mode 100644 index 00000000000..cc0dd4daa3f --- /dev/null +++ b/Documentation/platforms/arm/a64/index.rst @@ -0,0 +1,19 @@ +============= +Allwinner A64 +============= + +`Allwinner A64 `_ is an ARM64 SoC that features: + +- **CPU:** Quad-Core ARM Cortex-A53 +- **GPU:** ARM Mali400 MP2 +- **Interrupt Controller:** ARM GIC PL400 (Generic Interrupt Controller v2) +- **Display Engine:** Allwinner Display Engine 2.0 (MIPI DSI with DMA) + +Supported Boards +================ + +.. toctree:: + :glob: + :maxdepth: 1 + + boards/*/* diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index cb74385bf4d..2353830cce1 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -10,6 +10,14 @@ choice prompt "ARM64 chip selection" default ARCH_CHIP_QEMU +config ARCH_CHIP_A64 + bool "Allwinner A64" + select ARCH_CORTEX_A53 + select ARCH_HAVE_ADDRENV + select ARCH_NEED_ADDRENV_MAPPING + ---help--- + Allwinner A64 SoC + config ARCH_CHIP_QEMU bool "QEMU virt platform (ARMv8a)" select ARCH_CORTEX_A53 @@ -80,6 +88,7 @@ config ARCH_FAMILY config ARCH_CHIP string + default "a64" if ARCH_CHIP_A64 default "qemu" if ARCH_CHIP_QEMU config ARCH_HAVE_TRUSTZONE @@ -97,12 +106,17 @@ config ARM_HAVE_NEON config ARM_GIC_VERSION int "GIC version" + default 2 if ARCH_CHIP_A64 default 3 range 2 4 ---help--- Version of Generic Interrupt Controller (GIC) supported by the architecture +if ARCH_CHIP_A64 +source "arch/arm64/src/a64/Kconfig" +endif + if ARCH_CHIP_QEMU source "arch/arm64/src/qemu/Kconfig" endif diff --git a/arch/arm64/include/a64/chip.h b/arch/arm64/include/a64/chip.h new file mode 100644 index 00000000000..ef6eb593864 --- /dev/null +++ b/arch/arm64/include/a64/chip.h @@ -0,0 +1,57 @@ +/**************************************************************************** + * arch/arm64/include/a64/chip.h + * + * 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_ARM64_INCLUDE_A64_CHIP_H +#define __ARCH_ARM64_INCLUDE_A64_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Number of bytes in @p x kibibytes/mebibytes/gibibytes */ + +#define KB(x) ((x) << 10) +#define MB(x) (KB(x) << 10) +#define GB(x) (MB(UINT64_C(x)) << 10) + +/* Allwinner A64 Generic Interrupt Controller v2: Distributor and Redist */ + +#define CONFIG_GICD_BASE 0x1C81000 +#define CONFIG_GICR_BASE 0x1C82000 + +/* Allwinner A64 Memory Map: RAM and Device I/O */ + +#define CONFIG_RAMBANK1_ADDR 0x40000000 +#define CONFIG_RAMBANK1_SIZE MB(128) + +#define CONFIG_DEVICEIO_BASEADDR 0x00000000 +#define CONFIG_DEVICEIO_SIZE MB(512) + +/* U-Boot loads NuttX at this address (kernel_addr_r) */ + +#define CONFIG_LOAD_BASE 0x40080000 + +#endif /* __ARCH_ARM64_INCLUDE_A64_CHIP_H */ diff --git a/arch/arm64/include/a64/irq.h b/arch/arm64/include/a64/irq.h new file mode 100644 index 00000000000..84cb88b8bba --- /dev/null +++ b/arch/arm64/include/a64/irq.h @@ -0,0 +1,36 @@ +/**************************************************************************** + * arch/arm64/include/a64/irq.h + * + * 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_ARM64_INCLUDE_A64_IRQ_H +#define __ARCH_ARM64_INCLUDE_A64_IRQ_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Allwinner A64 Interrupts */ + +#define NR_IRQS 220 /* Total number of interrupts */ + +#endif /* __ARCH_ARM64_INCLUDE_QEMU_IRQ_H */ diff --git a/arch/arm64/src/a64/Kconfig b/arch/arm64/src/a64/Kconfig new file mode 100644 index 00000000000..55665849bb4 --- /dev/null +++ b/arch/arm64/src/a64/Kconfig @@ -0,0 +1,15 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_CHIP_A64 + +menu "Allwinner A64 Peripheral Selection" +config A64_UART + bool "UART" + default n + select UART1_SERIALDRIVER +endmenu # Allwinner A64 Peripheral Selection + +endif # ARCH_CHIP_A64 diff --git a/arch/arm64/src/a64/Make.defs b/arch/arm64/src/a64/Make.defs new file mode 100644 index 00000000000..92a1daaaaa1 --- /dev/null +++ b/arch/arm64/src/a64/Make.defs @@ -0,0 +1,26 @@ +############################################################################ +# arch/arm64/src/a64/Make.defs +# +# 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 common/Make.defs + +# Allwinner A64 specific C source files +CHIP_CSRCS = a64_boot.c a64_serial.c + +CHIP_ASRCS = a64_lowputc.S diff --git a/arch/arm64/src/a64/a64_boot.c b/arch/arm64/src/a64/a64_boot.c new file mode 100644 index 00000000000..862d014dc16 --- /dev/null +++ b/arch/arm64/src/a64/a64_boot.c @@ -0,0 +1,112 @@ +/**************************************************************************** + * arch/arm64/src/a64/a64_boot.c + * + * 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 +#ifdef CONFIG_PAGING +# include +#endif + +#include + +#ifdef CONFIG_SMP +#include "arm64_smp.h" +#endif + +#include "arm64_arch.h" +#include "arm64_internal.h" +#include "arm64_mmu.h" +#include "a64_boot.h" +#include "a64_serial.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct arm_mmu_region mmu_regions[] = +{ + MMU_REGION_FLAT_ENTRY("DEVICE_REGION", + CONFIG_DEVICEIO_BASEADDR, CONFIG_DEVICEIO_SIZE, + MT_DEVICE_NGNRNE | MT_RW | MT_SECURE), + + MMU_REGION_FLAT_ENTRY("DRAM0_S0", + CONFIG_RAMBANK1_ADDR, CONFIG_RAMBANK1_SIZE, + MT_NORMAL | MT_RW | MT_SECURE), +}; + +const struct arm_mmu_config mmu_config = +{ + .num_regions = ARRAY_SIZE(mmu_regions), + .mmu_regions = mmu_regions, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: arm64_chip_boot + * + * Description: + * Complete boot operations started in arm64_head.S + * + ****************************************************************************/ + +void arm64_chip_boot(void) +{ + /* MAP IO and DRAM, enable MMU. */ + + arm64_mmu_init(true); + +#ifdef CONFIG_SMP + arm64_psci_init("smc"); + +#endif + + /* Perform board-specific device initialization. This would include + * configuration of board specific resources such as GPIOs, LEDs, etc. + */ + + a64_board_initialize(); + +#ifdef USE_EARLYSERIALINIT + /* Perform early serial initialization if we are going to use the serial + * driver. + */ + + a64_earlyserialinit(); +#endif +} + +#if defined(CONFIG_NET) && !defined(CONFIG_NETDEV_LATEINIT) +void arm64_netinitialize(void) +{ + /* TODO: Support net initialize */ +} +#endif diff --git a/arch/arm64/src/a64/a64_boot.h b/arch/arm64/src/a64/a64_boot.h new file mode 100644 index 00000000000..0e9b28d1059 --- /dev/null +++ b/arch/arm64/src/a64/a64_boot.h @@ -0,0 +1,80 @@ +/**************************************************************************** + * arch/arm64/src/a64/a64_boot.h + * + * 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_ARM64_SRC_A64_A64_BOOT_H +#define __ARCH_ARM64_SRC_A64_A64_BOOT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "arm64_internal.h" +#include "arm64_arch.h" + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: a64_board_initialize + * + * Description: + * All A64 architectures must provide the following entry point. This + * entry point is called in the initialization phase -- after + * a64_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 a64_board_initialize(void); + +void up_lowputc(char c); +void up_low_flush(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM64_SRC_A64_A64_BOOT_H */ diff --git a/arch/arm64/src/a64/a64_lowputc.S b/arch/arm64/src/a64/a64_lowputc.S new file mode 100644 index 00000000000..4b43f394a9b --- /dev/null +++ b/arch/arm64/src/a64/a64_lowputc.S @@ -0,0 +1,91 @@ +/**************************************************************************** + * arch/arm64/src/a64/a64_lowputc.S + * + * 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. + * + **************************************************************************** + * + * DESCRIPTION + * Low-level console output for Allwinner A64 + * + ***************************************************************************/ + +#include + +#include "arm64_macro.inc" + +/**************************************************************************** + * Public Symbols + ****************************************************************************/ + + .file "a64_lowputc.S" + +/**************************************************************************** + * Assembly Macros + ****************************************************************************/ + + /* Allwinner A64 UART0 Base Address */ + + #define UART0_BASE_ADDRESS 0x1C28000 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/* Initialize A64 UART + * xb: Register that contains the UART Base Address + * c: Scratch register number + */ + +GTEXT(up_earlyserialinit) +SECTION_FUNC(text, up_earlyserialinit) + ret /* Do nothing because U-Boot has already initialized UART */ + +/* Wait for A64 UART to be ready to transmit + * xb: Register that contains the UART Base Address + * wt: Scratch register number + */ + +.macro early_uart_ready xb, wt +1: + ldrh \wt, [\xb, #0x14] /* UART_LSR (Line Status Register) */ + tst \wt, #0x20 /* Check THRE (TX Holding Register Empty) */ + b.eq 1b /* Wait for the UART to be ready (THRE=1) */ +.endm + +/* Transmit character to A64 UART + * xb: Register that contains the UART base address + * wt: Register that contains the character to transmit + */ + +.macro early_uart_transmit xb, wt + strb \wt, [\xb] /* UART_THR (Transmit Holding Register) */ +.endm + +/* Print a character on the UART - this function is called by C + * x0: Character to print + */ + +GTEXT(up_lowputc) +SECTION_FUNC(text, up_lowputc) + ldr x15, =UART0_BASE_ADDRESS + early_uart_ready x15, w2 + early_uart_transmit x15, w0 + ret diff --git a/arch/arm64/src/a64/a64_serial.c b/arch/arm64/src/a64/a64_serial.c new file mode 100644 index 00000000000..37f38336e9a --- /dev/null +++ b/arch/arm64/src/a64/a64_serial.c @@ -0,0 +1,716 @@ +/*************************************************************************** + * arch/arm64/src/a64/a64_serial.c + * + * 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 + +#ifdef CONFIG_SERIAL_TERMIOS +# include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include "arm64_arch.h" +#include "arm64_internal.h" +#include "a64_serial.h" +#include "arm64_arch_timer.h" +#include "a64_boot.h" +#include "arm64_gic.h" + +#ifdef USE_SERIALDRIVER + +/*************************************************************************** + * Pre-processor Definitions + ***************************************************************************/ + +/* UART1 is console and ttys0 */ + +#if defined(CONFIG_UART1_SERIAL_CONSOLE) +# define CONSOLE_DEV g_uart1port /* UART1 is console */ +# define TTYS0_DEV g_uart1port /* UART1 is ttyS0 */ +# define UART1_ASSIGNED 1 +#endif + +/* A64 UART Registers */ + +#define UART_THR(uart_addr) (uart_addr + 0x00) /* Tx Holding */ +#define UART_RBR(uart_addr) (uart_addr + 0x00) /* Rx Buffer */ +#define UART_IER(uart_addr) (uart_addr + 0x04) /* Interrupt Enable */ +#define UART_IIR(uart_addr) (uart_addr + 0x08) /* Interrupt Identity */ +#define UART_LSR(uart_addr) (uart_addr + 0x14) /* Line Status */ + +/* A64 UART Register Bit Definitions */ + +#define UART_IER_ERBFI (1 << 0) /* Enable Rx Data Interrupt */ +#define UART_IER_ETBEI (1 << 1) /* Enable Tx Empty Interrupt */ +#define UART_IIR_INTID (0b1111) /* Interrupt ID */ +#define UART_LSR_DR (1 << 0) /* Rx Data Ready */ +#define UART_LSR_THRE (1 << 5) /* Tx Empty */ + +/*************************************************************************** + * Private Types + ***************************************************************************/ + +/* A64 UART Configuration */ + +struct a64_uart_config +{ + unsigned long uart; /* UART Base Address */ +}; + +/* A64 UART Device Data */ + +struct a64_uart_data +{ + uint32_t baud_rate; /* UART Baud Rate */ +}; + +/* A64 UART Port */ + +struct a64_uart_port_s +{ + struct a64_uart_data data; /* UART Device Data */ + struct a64_uart_config config; /* UART Configuration */ + unsigned int irq_num; /* UART IRQ Number */ + bool is_console; /* 1 if this UART is console */ +}; + +/*************************************************************************** + * Private Functions + ***************************************************************************/ + +/*************************************************************************** + * Name: a64_uart_irq_handler + * + * Description: + * This is the common UART interrupt handler. It should call + * uart_xmitchars or uart_recvchars to perform the appropriate data + * transfers. + * + * Input Parameters: + * irq - IRQ Number + * context - Interrupt Context + * arg - UART Device + * + * Returned Value: + * OK is always returned at present. + * + ***************************************************************************/ + +static int a64_uart_irq_handler(int irq, void *context, void *arg) +{ + struct uart_dev_s *dev = (struct uart_dev_s *)arg; + const struct a64_uart_port_s *port = (struct a64_uart_port_s *)dev->priv; + const struct a64_uart_config *config = &port->config; + uint8_t int_id; + + UNUSED(irq); + UNUSED(context); + + /* Read Interrupt ID from Interrupt Identity Register (UART_IIR) */ + + int_id = getreg8(UART_IIR(config->uart)) & UART_IIR_INTID; + + if (int_id == 0b0100) /* If received data is available */ + { + uart_recvchars(dev); /* Receive the data */ + } + else if (int_id == 0b0010) /* If Tx Holding Register is empty */ + { + uart_xmitchars(dev); /* Transmit the data */ + } + + return OK; +} + +/*************************************************************************** + * Name: a64_uart_setup + * + * Description: + * Set up the UART Port. We do nothing because U-Boot has already + * initialized A64 UART0 at 115.2 kbps. + * + * Input Parameters: + * dev - UART Device + * + * Returned Value: + * OK is always returned at present. + * + ***************************************************************************/ + +static int a64_uart_setup(struct uart_dev_s *dev) +{ + /* TODO: Set the Baud Rate if this isn't A64 UART0 */ + + return OK; +} + +/*************************************************************************** + * Name: a64_uart_shutdown + * + * Description: + * Disable the UART Port. This method is called when the serial + * port is closed. + * + * Input Parameters: + * dev - UART Device + * + * Returned Value: + * None + * + ***************************************************************************/ + +static void a64_uart_shutdown(struct uart_dev_s *dev) +{ + /* Should never be called */ + + UNUSED(dev); + sinfo("%s: call unexpected\n", __func__); +} + +/*************************************************************************** + * Name: a64_uart_attach + * + * Description: + * Configure the UART to operation in interrupt driven mode. + * This method is called when the serial port is opened. + * Normally, this is just after the setup() method is called, + * however, the serial console may operate in + * a non-interrupt driven mode during the boot phase. + * + * RX and TX interrupts are not enabled when by the attach method + * (unless the hardware supports multiple levels of interrupt + * enabling). The RX and TX interrupts are not enabled until + * the txint() and rxint() methods are called. + * + * Input Parameters: + * dev - UART Device + * + * Returned Value: + * Zero (OK) on success; a negated errno value is returned on any failure. + * + ***************************************************************************/ + +static int a64_uart_attach(struct uart_dev_s *dev) +{ + int ret; + + /* Attach UART Interrupt Handler */ + + ret = irq_attach(CONFIG_A64_UART_IRQ, a64_uart_irq_handler, dev); + + /* Set Interrupt Priority in Generic Interrupt Controller v2 */ + + arm64_gic_irq_set_priority(CONFIG_A64_UART_IRQ, IRQ_TYPE_LEVEL, 0); + + /* Enable UART Interrupt */ + + if (ret == OK) + { + up_enable_irq(CONFIG_A64_UART_IRQ); + } + else + { + sinfo("error ret=%d\n", ret); + } + + return ret; +} + +/*************************************************************************** + * Name: a64_uart_detach + * + * Description: + * Detach UART interrupts. This method is called when the serial port is + * closed normally just before the shutdown method is called. The + * exception is the serial console which is never shutdown. + * + * Input Parameters: + * dev - UART Device + * + * Returned Value: + * None + * + ***************************************************************************/ + +static void a64_uart_detach(struct uart_dev_s *dev) +{ + /* Disable UART Interrupt */ + + up_disable_irq(CONFIG_A64_UART_IRQ); + + /* Detach UART Interrupt Handler */ + + irq_detach(CONFIG_A64_UART_IRQ); +} + +/*************************************************************************** + * Name: a64_uart_ioctl + * + * Description: + * All ioctl calls will be routed through this method. + * + * Input Parameters: + * filep - File Struct + * cmd - ioctl Command + * arg - ioctl Argument + * + * Returned Value: + * Zero (OK) on success; a negated errno value is returned on any failure. + * + ***************************************************************************/ + +static int a64_uart_ioctl(struct file *filep, int cmd, unsigned long arg) +{ + int ret = OK; + + UNUSED(filep); + UNUSED(arg); + + switch (cmd) + { + case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */ + case TIOCCBRK: /* BSD compatibility: Turn break off, unconditionally */ + default: + { + ret = -ENOTTY; + break; + } + } + + return ret; +} + +/*************************************************************************** + * Name: a64_uart_receive + * + * Description: + * Called (usually) from the interrupt level to receive one + * character from the UART. Error bits associated with the + * receipt are provided in the return 'status'. + * + * Input Parameters: + * dev - UART Device + * status - Return status, zero on success + * + * Returned Value: + * Received character + * + ***************************************************************************/ + +static int a64_uart_receive(struct uart_dev_s *dev, unsigned int *status) +{ + const struct a64_uart_port_s *port = (struct a64_uart_port_s *)dev->priv; + const struct a64_uart_config *config = &port->config; + + /* Status is always OK */ + + *status = 0; + + /* Read received char from Receiver Buffer Register (UART_RBR) */ + + return getreg8(UART_RBR(config->uart)); +} + +/*************************************************************************** + * Name: a64_uart_rxint + * + * Description: + * Call to enable or disable RX interrupts + * + * Input Parameters: + * dev - UART Device + * enable - True to enable RX interrupts; false to disable + * + * Returned Value: + * None + * + ***************************************************************************/ + +static void a64_uart_rxint(struct uart_dev_s *dev, bool enable) +{ + const struct a64_uart_port_s *port = (struct a64_uart_port_s *)dev->priv; + const struct a64_uart_config *config = &port->config; + + /* Write to Interrupt Enable Register (UART_IER) */ + + if (enable) + { + /* Set ERBFI bit (Enable Rx Data Available Interrupt) */ + + modreg8(UART_IER_ERBFI, UART_IER_ERBFI, UART_IER(config->uart)); + } + else + { + /* Clear ERBFI bit (Disable Rx Data Available Interrupt) */ + + modreg8(0, UART_IER_ERBFI, UART_IER(config->uart)); + } +} + +/*************************************************************************** + * Name: a64_uart_rxavailable + * + * Description: + * Return true if the Receive FIFO is not empty + * + * Input Parameters: + * dev - UART Device + * + * Returned Value: + * True if the Receive FIFO is not empty; false otherwise + * + ***************************************************************************/ + +static bool a64_uart_rxavailable(struct uart_dev_s *dev) +{ + const struct a64_uart_port_s *port = (struct a64_uart_port_s *)dev->priv; + const struct a64_uart_config *config = &port->config; + + /* Data Ready Bit (Line Status Register) is 1 if Rx Data is ready */ + + return getreg8(UART_LSR(config->uart)) & UART_LSR_DR; +} + +/*************************************************************************** + * Name: a64_uart_send + * + * Description: + * This method will send one byte on the UART + * + * Input Parameters: + * dev - UART Device + * ch - Character to be sent + * + * Returned Value: + * None + * + ***************************************************************************/ + +static void a64_uart_send(struct uart_dev_s *dev, int ch) +{ + const struct a64_uart_port_s *port = (struct a64_uart_port_s *)dev->priv; + const struct a64_uart_config *config = &port->config; + + /* Write char to Transmit Holding Register (UART_THR) */ + + putreg8(ch, UART_THR(config->uart)); +} + +/*************************************************************************** + * Name: a64_uart_txint + * + * Description: + * Call to enable or disable TX interrupts + * + * Input Parameters: + * dev - UART Device + * enable - True to enable TX interrupts; false to disable + * + * Returned Value: + * None + * + ***************************************************************************/ + +static void a64_uart_txint(struct uart_dev_s *dev, bool enable) +{ + const struct a64_uart_port_s *port = (struct a64_uart_port_s *)dev->priv; + const struct a64_uart_config *config = &port->config; + + /* Write to Interrupt Enable Register (UART_IER) */ + + if (enable) + { + /* Set ETBEI bit (Enable Tx Holding Register Empty Interrupt) */ + + modreg8(UART_IER_ETBEI, UART_IER_ETBEI, UART_IER(config->uart)); + } + else + { + /* Clear ETBEI bit (Disable Tx Holding Register Empty Interrupt) */ + + modreg8(0, UART_IER_ETBEI, UART_IER(config->uart)); + } +} + +/*************************************************************************** + * Name: a64_uart_txready + * + * Description: + * Return true if the Transmit FIFO is not full + * + * Input Parameters: + * dev - UART Device + * + * Returned Value: + * True if the Transmit FIFO is not full; false otherwise + * + ***************************************************************************/ + +static bool a64_uart_txready(struct uart_dev_s *dev) +{ + const struct a64_uart_port_s *port = (struct a64_uart_port_s *)dev->priv; + const struct a64_uart_config *config = &port->config; + + /* Tx FIFO is ready if THRE Bit is 1 (Tx Holding Register Empty) */ + + return (getreg8(UART_LSR(config->uart)) & UART_LSR_THRE) != 0; +} + +/*************************************************************************** + * Name: a64_uart_txempty + * + * Description: + * Return true if the Transmit FIFO is empty + * + * Input Parameters: + * dev - UART Device + * + * Returned Value: + * True if the Transmit FIFO is empty; false otherwise + * + ***************************************************************************/ + +static bool a64_uart_txempty(struct uart_dev_s *dev) +{ + /* Tx FIFO is empty if Tx FIFO is not full (for now) */ + + return a64_uart_txready(dev); +} + +/*************************************************************************** + * Private Data + ***************************************************************************/ + +/* UART Operations for Serial Driver */ + +static const struct uart_ops_s g_uart_ops = +{ + .setup = a64_uart_setup, + .shutdown = a64_uart_shutdown, + .attach = a64_uart_attach, + .detach = a64_uart_detach, + .ioctl = a64_uart_ioctl, + .receive = a64_uart_receive, + .rxint = a64_uart_rxint, + .rxavailable = a64_uart_rxavailable, +#ifdef CONFIG_SERIAL_IFLOWCONTROL + .rxflowcontrol = NULL, +#endif + .send = a64_uart_send, + .txint = a64_uart_txint, + .txready = a64_uart_txready, + .txempty = a64_uart_txempty, +}; + +/* UART1 Port State */ + +static struct a64_uart_port_s g_uart1priv = +{ + .data = + { + .baud_rate = CONFIG_UART1_BAUD, + }, + + .config = + { + .uart = CONFIG_A64_UART_BASE, + }, + + .irq_num = CONFIG_A64_UART_IRQ, + .is_console = 1, +}; + +/* UART1 I/O Buffers */ + +#ifdef CONFIG_A64_UART + +static char g_uart1rxbuffer[CONFIG_UART1_RXBUFSIZE]; +static char g_uart1txbuffer[CONFIG_UART1_TXBUFSIZE]; + +/* UART1 Port Definition */ + +static struct uart_dev_s g_uart1port = +{ + .recv = + { + .size = CONFIG_UART1_RXBUFSIZE, + .buffer = g_uart1rxbuffer, + }, + + .xmit = + { + .size = CONFIG_UART1_TXBUFSIZE, + .buffer = g_uart1txbuffer, + }, + + .ops = &g_uart_ops, + .priv = &g_uart1priv, +}; + +#endif + +/*************************************************************************** + * Public Functions + ***************************************************************************/ + +/*************************************************************************** + * Name: a64_earlyserialinit + * + * Description: + * Performs the low level UART initialization early in + * debug so that the serial console will be available + * during bootup. This must be called before arm64_serialinit. + * + * Returned Value: + * None + * + ***************************************************************************/ + +void a64_earlyserialinit(void) +{ + /* NOTE: This function assumes that low level hardware configuration + * -- including all clocking and pin configuration -- was performed + * earlier in the boot sequence. + */ + + /* Enable the console UART. The other UARTs will be initialized if and + * when they are first opened. + */ +#ifdef CONSOLE_DEV + CONSOLE_DEV.isconsole = true; + a64_uart_setup(&CONSOLE_DEV); +#endif +} + +/*************************************************************************** + * Name: up_putc + * + * Description: + * Provide priority, low-level access to support OS debug + * writes + * + * Input Parameters: + * ch - Character to be transmitted over UART + * + * Returned Value: + * Character that was transmitted + * + ***************************************************************************/ + +int up_putc(int ch) +{ + /* Check for LF */ + + if (ch == '\n') + { + /* Add CR */ + + up_lowputc('\r'); + } + + up_lowputc((uint8_t)ch); + return ch; +} + +/*************************************************************************** + * Name: arm64_serialinit + * + * Description: + * Register serial console and serial ports. This assumes + * that a64_earlyserialinit was called previously. + * + * Returned Value: + * None + * + ***************************************************************************/ + +void arm64_serialinit(void) +{ + int ret; + + ret = uart_register("/dev/console", &CONSOLE_DEV); + if (ret < 0) + { + sinfo("error at register dev/console, ret =%d\n", ret); + } + + ret = uart_register("/dev/ttyS0", &TTYS0_DEV); + + if (ret < 0) + { + sinfo("error at register dev/ttyS0, ret =%d\n", ret); + } +} + +#else /* USE_SERIALDRIVER */ + +/*************************************************************************** + * Public Functions + ***************************************************************************/ + +/*************************************************************************** + * Name: up_putc + * + * Description: + * Provide priority, low-level access to support OS debug + * writes + * + * Input Parameters: + * ch - Character to be transmitted over UART + * + * Returned Value: + * Character that was transmitted + * + ***************************************************************************/ + +int up_putc(int ch) +{ + /* Check for LF */ + + if (ch == '\n') + { + /* Add CR */ + + up_lowputc('\r'); + } + + up_lowputc((uint8_t)ch); + return ch; +} + +#endif /* USE_SERIALDRIVER */ diff --git a/arch/arm64/src/a64/a64_serial.h b/arch/arm64/src/a64/a64_serial.h new file mode 100644 index 00000000000..d5737ca514e --- /dev/null +++ b/arch/arm64/src/a64/a64_serial.h @@ -0,0 +1,75 @@ +/**************************************************************************** + * arch/arm64/src/a64/a64_serial.h + * + * 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_ARM64_SRC_A64_A64_SERIAL_H +#define __ARCH_ARM64_SRC_A64_A64_SERIAL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "arm64_internal.h" +#include "arm64_gic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef CONFIG_ARCH_CHIP_A64 +#define CONFIG_A64_UART_BASE 0x1C28000 /* A64 UART0 Base Address */ +#define CONFIG_A64_UART_IRQ 32 /* A64 UART0 IRQ */ +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: a64_earlyserialinit + * + * Description: + * Performs the low level UART initialization early in debug so that the + * serial console will be available during bootup. This must be called + * before arm64_serialinit. + * + ****************************************************************************/ + +#ifdef USE_EARLYSERIALINIT +void a64_earlyserialinit(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM64_SRC_A64_A64_SERIAL_H */ diff --git a/arch/arm64/src/a64/chip.h b/arch/arm64/src/a64/chip.h new file mode 100644 index 00000000000..33a67606fb9 --- /dev/null +++ b/arch/arm64/src/a64/chip.h @@ -0,0 +1,42 @@ +/**************************************************************************** + * arch/arm64/src/a64/chip.h + * + * 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_ARM64_SRC_A64_CHIP_H +#define __ARCH_ARM64_SRC_A64_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifndef __ASSEMBLY__ +# include +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Macro Definitions + ****************************************************************************/ + +#endif /* __ARCH_ARM64_SRC_A64_CHIP_H */ diff --git a/boards/Kconfig b/boards/Kconfig index 02e5a5a92d9..01584e3fc7c 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -1760,6 +1760,14 @@ config ARCH_BOARD_QEMU_ARMV8A This options selects support for NuttX on the QEMU ARMv8a + virt board featuring the qemu ARMv8a CPUs. +config ARCH_BOARD_PINEPHONE + bool "PINE64 PinePhone" + depends on ARCH_CHIP_A64 + select ARCH_HAVE_IRQBUTTONS + ---help--- + This options selects support for NuttX on PINE64 PinePhone based + on Allwinner A64 SoC with ARM Cortex-A53. + config ARCH_BOARD_SAMA5D2_XULT bool "Atmel SAMA5D2 Xplained Ultra development board" depends on ARCH_CHIP_ATSAMA5D27 @@ -2833,6 +2841,7 @@ config ARCH_BOARD default "rv-virt" if ARCH_BOARD_QEMU_RV_VIRT default "sabre-6quad" if ARCH_BOARD_SABRE_6QUAD default "qemu-armv8a" if ARCH_BOARD_QEMU_ARMV8A + default "pinephone" if ARCH_BOARD_PINEPHONE default "sama5d2-xult" if ARCH_BOARD_SAMA5D2_XULT default "giant-board" if ARCH_BOARD_GIANT_BOARD default "sama5d3x-ek" if ARCH_BOARD_SAMA5D3X_EK @@ -3021,6 +3030,9 @@ endif if ARCH_BOARD_QEMU_ARMV8A source "boards/arm64/qemu/qemu-armv8a/Kconfig" endif +if ARCH_BOARD_PINEPHONE +source "boards/arm64/a64/pinephone/Kconfig" +endif if ARCH_BOARD_IMXRT1020_EVK source "boards/arm/imxrt/imxrt1020-evk/Kconfig" endif diff --git a/boards/arm64/a64/pinephone/Kconfig b/boards/arm64/a64/pinephone/Kconfig new file mode 100644 index 00000000000..16dbc39161f --- /dev/null +++ b/boards/arm64/a64/pinephone/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_PINEPHONE +endif diff --git a/boards/arm64/a64/pinephone/configs/nsh/defconfig b/boards/arm64/a64/pinephone/configs/nsh/defconfig new file mode 100644 index 00000000000..14d5c206e45 --- /dev/null +++ b/boards/arm64/a64/pinephone/configs/nsh/defconfig @@ -0,0 +1,64 @@ +# +# 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_A64_UART=y +CONFIG_ARCH="arm64" +CONFIG_ARCH_ARM64=y +CONFIG_ARCH_BOARD="pinephone" +CONFIG_ARCH_BOARD_PINEPHONE=y +CONFIG_ARCH_CHIP="a64" +CONFIG_ARCH_CHIP_A64=y +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_ERROR=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_SCHED=y +CONFIG_DEBUG_SCHED_ERROR=y +CONFIG_DEBUG_SCHED_INFO=y +CONFIG_DEBUG_SCHED_WARN=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEBUG_WARN=y +CONFIG_DEFAULT_TASK_STACKSIZE=8192 +CONFIG_DEV_ZERO=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXPERIMENTAL=y +CONFIG_FS_PROCFS=y +CONFIG_FS_ROMFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=8192 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_NSH_ROMFSETC=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PTHREAD_STACK_MIN=8192 +CONFIG_RAMLOG=y +CONFIG_RAM_SIZE=134217728 +CONFIG_RAM_START=0x40000000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKPRIORITY=192 +CONFIG_SPINLOCK=y +CONFIG_STACK_COLORATION=y +CONFIG_START_MONTH=11 +CONFIG_START_YEAR=2022 +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_SYSTEM=y +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_UART1_SERIAL_CONSOLE=y +CONFIG_USEC_PER_TICK=1000 diff --git a/boards/arm64/a64/pinephone/include/board_memorymap.h b/boards/arm64/a64/pinephone/include/board_memorymap.h new file mode 100644 index 00000000000..06840ed9677 --- /dev/null +++ b/boards/arm64/a64/pinephone/include/board_memorymap.h @@ -0,0 +1,59 @@ +/**************************************************************************** + * boards/arm64/a64/pinephone/include/board_memorymap.h + * + * 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_ARM64_A64_PINEPHONE_INCLUDE_BOARD_MEMORYMAP_H +#define __BOARDS_ARM64_A64_PINEPHONE_INCLUDE_BOARD_MEMORYMAP_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_ARM64_A64_PINEPHONE_INCLUDE_BOARD_MEMORYMAP_H */ diff --git a/boards/arm64/a64/pinephone/scripts/Make.defs b/boards/arm64/a64/pinephone/scripts/Make.defs new file mode 100644 index 00000000000..6b64a8b34ef --- /dev/null +++ b/boards/arm64/a64/pinephone/scripts/Make.defs @@ -0,0 +1,48 @@ +############################################################################ +# boards/arm64/a64/pinephone/scripts/Make.defs +# +# 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/arm64/src/Toolchain.defs + +LDSCRIPT = dramboot.ld + +ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT) + +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +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 + +# ELF module definitions + +CELFFLAGS = $(CFLAGS) -mlong-calls # --target1-abs +CXXELFFLAGS = $(CXXFLAGS) -mlong-calls # --target1-abs + +LDELFFLAGS = -r -e main +LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/binfmt/libelf/gnu-elf.ld) diff --git a/boards/arm64/a64/pinephone/scripts/dramboot.ld b/boards/arm64/a64/pinephone/scripts/dramboot.ld new file mode 100644 index 00000000000..7d1db6d0fd2 --- /dev/null +++ b/boards/arm64/a64/pinephone/scripts/dramboot.ld @@ -0,0 +1,126 @@ +/**************************************************************************** + * boards/arm64/a64/pinephone/scripts/dramboot.ld + * + * 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. + * + ****************************************************************************/ + +OUTPUT_ARCH(aarch64) + +ENTRY(__start) + +PHDRS +{ + text PT_LOAD ; +} + +SECTIONS +{ + . = 0x40080000; /* U-Boot loads NuttX at this address (kernel_addr_r) */ + _start = .; + .text : { + _stext = .; /* Text section */ + *(.text) + *(.text.cold) + *(.text.unlikely) + *(.fixup) + *(.gnu.warning) + } :text = 0x9090 + + . = ALIGN(4096); + + .init_section : { + _sinit = ABSOLUTE(.); + *(.init_array .init_array.*) + _einit = ABSOLUTE(.); + } + + . = ALIGN(4096); + + .vector : { + _vector_start = .; + KEEP(*(.exc_vector_table)) + KEEP(*(".exc_vector_table.*")) + KEEP(*(.vectors)) + _vector_end = .; + } :text + . = ALIGN(4096); + _etext = .; /* End_1 of .text */ + _sztext = _etext - _stext; + + . = ALIGN(4096); + .rodata : { + _srodata = .; /* Read-only data */ + *(.rodata) + *(.rodata.*) + *(.data.rel.ro) + *(.data.rel.ro.*) + } :text + . = ALIGN(4096); + _erodata = .; /* End of read-only data */ + _szrodata = _erodata - _srodata; + _eronly = .; /* End of read-only data */ + + . = ALIGN(4096); + .data : { /* Data */ + _sdata = .; + *(.data.page_aligned) + *(.data) + . = ALIGN(8); + *(.data.rel) + *(.data.rel.*) + CONSTRUCTORS + } :text + _edata = .; /* End+1 of .data */ + + .bss : { /* BSS */ + _sbss = .; + *(.bss) + . = ALIGN(1 << 3); + } :text + . = ALIGN(4096); + _ebss = .; + _szbss = _ebss - _sbss; + + .initstack : { /* INIT STACK */ + _s_initstack = .; + *(.initstack) + . = ALIGN(16); + } :text + . = ALIGN(4096); + _e_initstack = . ; + g_idle_topstack = . ; + + _szdata = _e_initstack - _sdata; + + /* Sections to be discarded */ + /DISCARD/ : { + *(.exit.text) + *(.exit.data) + *(.exitcall.exit) + *(.eh_frame) + } + + /* 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/arm64/a64/pinephone/src/Makefile b/boards/arm64/a64/pinephone/src/Makefile new file mode 100644 index 00000000000..7a06b9d61a5 --- /dev/null +++ b/boards/arm64/a64/pinephone/src/Makefile @@ -0,0 +1,29 @@ +############################################################################ +# boards/arm64/a64/pinephone/src/Makefile +# +# 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 = pinephone_boardinit.c pinephone_bringup.c + +ifeq ($(CONFIG_BOARDCTL),y) +CSRCS += pinephone_appinit.c +endif + +include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm64/a64/pinephone/src/pinephone.h b/boards/arm64/a64/pinephone/src/pinephone.h new file mode 100644 index 00000000000..5169eec217e --- /dev/null +++ b/boards/arm64/a64/pinephone/src/pinephone.h @@ -0,0 +1,50 @@ +/**************************************************************************** + * boards/arm64/a64/pinephone/src/pinephone.h + * + * 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_ARM64_A64_PINEPHONE_SRC_PINEPHONE_H +#define __BOARDS_ARM64_A64_PINEPHONE_SRC_PINEPHONE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Functions Definitions + ****************************************************************************/ + +/**************************************************************************** + * Name: pinephone_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +#if defined(CONFIG_BOARDCTL) || defined(CONFIG_BOARD_LATE_INITIALIZE) +int pinephone_bringup(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM64_A64_PINEPHONE_SRC_PINEPHONE_H */ diff --git a/boards/arm64/a64/pinephone/src/pinephone_appinit.c b/boards/arm64/a64/pinephone/src/pinephone_appinit.c new file mode 100644 index 00000000000..844bcdffc29 --- /dev/null +++ b/boards/arm64/a64/pinephone/src/pinephone_appinit.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * boards/arm64/a64/pinephone/src/pinephone_appinit.c + * + * 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 "pinephone.h" + +#ifdef CONFIG_BOARDCTL + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform application specific initialization. This function is never + * called directly from application code, but only indirectly via the + * (non-standard) boardctl() interface using the command BOARDIOC_INIT. + * + * Input Parameters: + * arg - The boardctl() argument is passed to the board_app_initialize() + * implementation without modification. The argument has no + * meaning to NuttX; the meaning of the argument is a contract + * between the board-specific initialization logic and the + * matching application logic. The value could be such things as a + * mode enumeration value, a set of DIP switch switch settings, a + * pointer to configuration data read from a file or serial FLASH, + * or whatever you would like to do with it. Every implementation + * should accept zero/NULL as a default configuration. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure to indicate the nature of the failure. + * + ****************************************************************************/ + +int board_app_initialize(uintptr_t arg) +{ + UNUSED(arg); +#ifndef CONFIG_BOARD_LATE_INITIALIZE + /* Perform board initialization */ + + return pinephone_bringup(); +#else + return OK; +#endif +} + +#endif /* CONFIG_BOARDCTL */ diff --git a/boards/arm64/a64/pinephone/src/pinephone_boardinit.c b/boards/arm64/a64/pinephone/src/pinephone_boardinit.c new file mode 100644 index 00000000000..694ce3db79c --- /dev/null +++ b/boards/arm64/a64/pinephone/src/pinephone_boardinit.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * boards/arm64/a64/pinephone/src/pinephone_boardinit.c + * + * 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 "pinephone.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: a64_memory_initialize + * + * Description: + * All A64 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 a64_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 a64_memory_initialize(void) +{ + /* SDRAM was initialized by a bootloader in the supported configurations. */ +} + +/**************************************************************************** + * Name: a64_board_initialize + * + * Description: + * All A64 architectures must provide the following entry point. This + * entry point is called in the initialization phase -- after + * a64_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 a64_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 */ + + pinephone_bringup(); +} +#endif /* CONFIG_BOARD_LATE_INITIALIZE */ diff --git a/boards/arm64/a64/pinephone/src/pinephone_bringup.c b/boards/arm64/a64/pinephone/src/pinephone_bringup.c new file mode 100644 index 00000000000..fb79b626ad8 --- /dev/null +++ b/boards/arm64/a64/pinephone/src/pinephone_bringup.c @@ -0,0 +1,59 @@ +/**************************************************************************** + * boards/arm64/a64/pinephone/src/pinephone_bringup.c + * + * 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 "pinephone.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pinephone_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +int pinephone_bringup(void) +{ + int ret; + +#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 + + UNUSED(ret); + return OK; +}