From b3e511c5a8feecb9a3a4a3801b125d49d601cacf Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Thu, 15 Aug 2024 12:50:37 +0300 Subject: [PATCH] arm64/qemu: Add knsh target for armv8a qemu board This adds a qemu test target for testing kernel mode with arm64 --- .../arm64/qemu/boards/qemu-armv8a/README.txt | 10 ++ .../qemu/qemu-armv8a/configs/knsh/defconfig | 110 +++++++++++++ .../arm64/qemu/qemu-armv8a/scripts/Make.defs | 9 +- .../arm64/qemu/qemu-armv8a/scripts/gnu-elf.ld | 131 +++++++++++++++ .../qemu/qemu-armv8a/scripts/ld-kernel.script | 151 ++++++++++++++++++ 5 files changed, 407 insertions(+), 4 deletions(-) create mode 100644 boards/arm64/qemu/qemu-armv8a/configs/knsh/defconfig create mode 100644 boards/arm64/qemu/qemu-armv8a/scripts/gnu-elf.ld create mode 100644 boards/arm64/qemu/qemu-armv8a/scripts/ld-kernel.script diff --git a/Documentation/platforms/arm64/qemu/boards/qemu-armv8a/README.txt b/Documentation/platforms/arm64/qemu/boards/qemu-armv8a/README.txt index 4e82535d6a..e890270d34 100644 --- a/Documentation/platforms/arm64/qemu/boards/qemu-armv8a/README.txt +++ b/Documentation/platforms/arm64/qemu/boards/qemu-armv8a/README.txt @@ -148,6 +148,16 @@ Getting Started -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 \ -mon chardev=con,mode=readline -kernel ./nuttx + 3.5 Single Core /w kernel mode (GICv3) + Configuring NuttX and compile: + $ ./tools/configure.sh -l qemu-armv8a:knsh + $ make + Running with qemu + $ qemu-system-aarch64 -semihosting -cpu cortex-a53 -nographic \ + -machine virt,virtualization=on,gic-version=3 \ + -net none -chardev stdio,id=con,mux=on -serial chardev:con \ + -mon chardev=con,mode=readline -kernel ./nuttx + Status ====== diff --git a/boards/arm64/qemu/qemu-armv8a/configs/knsh/defconfig b/boards/arm64/qemu/qemu-armv8a/configs/knsh/defconfig new file mode 100644 index 0000000000..a4e960524c --- /dev/null +++ b/boards/arm64/qemu/qemu-armv8a/configs/knsh/defconfig @@ -0,0 +1,110 @@ +# +# 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_ARCH="arm64" +CONFIG_ARCH_ADDRENV=y +CONFIG_ARCH_ARM64=y +CONFIG_ARCH_BOARD="qemu-armv8a" +CONFIG_ARCH_BOARD_QEMU_ARMV8A=y +CONFIG_ARCH_CHIP="qemu" +CONFIG_ARCH_CHIP_QEMU=y +CONFIG_ARCH_CHIP_QEMU_A53=y +CONFIG_ARCH_DATA_NPAGES=0 +CONFIG_ARCH_DATA_VBASE=0xC0000000 +CONFIG_ARCH_EARLY_PRINT=y +CONFIG_ARCH_HEAP_NPAGES=0 +CONFIG_ARCH_HEAP_VBASE=0x00000000 +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARCH_KERNEL_STACKSIZE=8192 +CONFIG_ARCH_KMAP_NPAGES=4096 +CONFIG_ARCH_KMAP_VBASE=0x7F000000 +CONFIG_ARCH_PGPOOL_MAPPING=y +CONFIG_ARCH_PGPOOL_PBASE=0x40800000 +CONFIG_ARCH_PGPOOL_SIZE=4194304 +CONFIG_ARCH_PGPOOL_VBASE=0x40800000 +CONFIG_ARCH_SHM_NPAGES=4096 +CONFIG_ARCH_SHM_VBASE=0xFF000000 +CONFIG_ARCH_TEXT_NPAGES=0 +CONFIG_ARCH_TEXT_VBASE=0x00000000 +CONFIG_ARCH_USE_MMU=y +CONFIG_ARM64_SEMIHOSTING_HOSTFS=y +CONFIG_ARM64_SEMIHOSTING_HOSTFS_CACHE_COHERENCE=y +CONFIG_ARM64_STRING_FUNCTION=y +CONFIG_BUILD_KERNEL=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SCHED=y +CONFIG_DEBUG_SCHED_ERROR=y +CONFIG_DEBUG_SCHED_WARN=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEFAULT_TASK_STACKSIZE=8192 +CONFIG_DEVICE_TREE=y +CONFIG_DEV_ZERO=y +CONFIG_ELF=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXPERIMENTAL=y +CONFIG_FS_HOSTFS=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_FS_ROMFS=y +CONFIG_FS_SHMFS=y +CONFIG_HAVE_CXX=y +CONFIG_IDLETHREAD_STACKSIZE=8192 +CONFIG_INIT_FILEPATH="/system/bin/init" +CONFIG_INIT_MOUNT=y +CONFIG_INIT_MOUNT_DATA="fs=../apps" +CONFIG_INIT_MOUNT_FLAGS=0x1 +CONFIG_INIT_MOUNT_FSTYPE="hostfs" +CONFIG_INIT_MOUNT_SOURCE="" +CONFIG_INIT_MOUNT_TARGET="/system" +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBC_ENVPATH=y +CONFIG_LIBC_EXECFUNCS=y +CONFIG_LIBC_MAX_EXITFUNS=16 +CONFIG_LIBC_PERROR_STDOUT=y +CONFIG_LIBC_STRERROR=y +CONFIG_LIBM=y +CONFIG_MM_KMAP=y +CONFIG_MM_PGALLOC=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_FILE_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_PATH_INITIAL="/system/bin" +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PTHREAD_STACK_MIN=8192 +CONFIG_RAMLOG=y +CONFIG_RAM_SIZE=8388608 +CONFIG_RAM_START=0x40000000 +CONFIG_RAM_VSTART=0x40000000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HAVE_PARENT=y +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKPRIORITY=192 +CONFIG_SCHED_LPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_SIG_DEFAULT=y +CONFIG_SPINLOCK=y +CONFIG_STACK_COLORATION=y +CONFIG_START_MONTH=3 +CONFIG_START_YEAR=2022 +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_PROGNAME="init" +CONFIG_SYSTEM_TIME64=y +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_TESTING_OSTEST_FPUTESTDISABLE=y +CONFIG_UART1_BASE=0x9000000 +CONFIG_UART1_IRQ=33 +CONFIG_UART1_PL011=y +CONFIG_UART1_SERIAL_CONSOLE=y +CONFIG_UART_PL011=y +CONFIG_USEC_PER_TICK=1000 diff --git a/boards/arm64/qemu/qemu-armv8a/scripts/Make.defs b/boards/arm64/qemu/qemu-armv8a/scripts/Make.defs index 2b76e1b08d..ca50cf3f79 100644 --- a/boards/arm64/qemu/qemu-armv8a/scripts/Make.defs +++ b/boards/arm64/qemu/qemu-armv8a/scripts/Make.defs @@ -22,7 +22,11 @@ include $(TOPDIR)/.config include $(TOPDIR)/tools/Config.mk include $(TOPDIR)/arch/arm64/src/Toolchain.defs -LDSCRIPT = dramboot.ld +ifeq ($(CONFIG_BUILD_KERNEL),y) + LDSCRIPT = ld-kernel.script +else + LDSCRIPT = dramboot.ld +endif ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT) @@ -50,6 +54,3 @@ SHMODULEFLAGS = -Bsymbolic -G -Bdynamic 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/qemu/qemu-armv8a/scripts/gnu-elf.ld b/boards/arm64/qemu/qemu-armv8a/scripts/gnu-elf.ld new file mode 100644 index 0000000000..7a42b64451 --- /dev/null +++ b/boards/arm64/qemu/qemu-armv8a/scripts/gnu-elf.ld @@ -0,0 +1,131 @@ +/**************************************************************************** + * boards/arm64/qemu/qemu-armv8a/scripts/gnu-elf.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. + * + ****************************************************************************/ + +SECTIONS +{ + .text : + { + _stext = . ; + *(.text) + *(.text.*) + *(.gnu.warning) + *(.stub) + *(.glue_7) + *(.glue_7t) + *(.jcr) + + /* C++ support: The .init and .fini sections contain specific logic + * to manage static constructors and destructors. + */ + + *(.gnu.linkonce.t.*) + *(.init) /* Old ABI */ + *(.fini) /* Old ABI */ + _etext = . ; + } + + .rodata : + { + _srodata = . ; + *(.rodata) + *(.rodata1) + *(.rodata.*) + *(.gnu.linkonce.r*) + _erodata = . ; + } + + .data : + { + _sdata = . ; + *(.data) + *(.data1) + *(.data.*) + *(.gnu.linkonce.d*) + . = ALIGN(4); + _edata = . ; + } + + /* C++ support. For each global and static local C++ object, + * GCC creates a small subroutine to construct the object. Pointers + * to these routines (not the routines themselves) are stored as + * simple, linear arrays in the .ctors section of the object file. + * Similarly, pointers to global/static destructor routines are + * stored in .dtors. + */ + + .ctors : + { + _sctors = . ; + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _ectors = . ; + } + + .dtors : + { + _sdtors = . ; + KEEP (*(.dtors)) /* Old ABI: Unallocated */ + KEEP (*(.fini_array)) /* New ABI: Allocated */ + KEEP (*(SORT(.fini_array.*))) + _edtors = . ; + } + + .bss : + { + _sbss = . ; + *(.bss) + *(.bss.*) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.b*) + *(COMMON) + _ebss = . ; + } + + /* Thread local storage support */ + .tdata : + { + _stdata = ABSOLUTE(.); + KEEP (*(.tdata .tdata.* .gnu.linkonce.td.*)); + _etdata = ABSOLUTE(.); + } + + .tbss : + { + _stbss = ABSOLUTE(.); + KEEP (*(.tbss .tbss.* .gnu.linkonce.tb.* .tcommon)); + _etbss = ABSOLUTE(.); + } + + /* 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) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } +} diff --git a/boards/arm64/qemu/qemu-armv8a/scripts/ld-kernel.script b/boards/arm64/qemu/qemu-armv8a/scripts/ld-kernel.script new file mode 100644 index 0000000000..e6c951f3f6 --- /dev/null +++ b/boards/arm64/qemu/qemu-armv8a/scripts/ld-kernel.script @@ -0,0 +1,151 @@ +/**************************************************************************** + * boards/risc-v/qemu-rv/rv-virt/scripts/ld.script + * + * 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) +EXTERN(__start) + +MEMORY +{ + dram (rwx) : ORIGIN = 0x40280000, LENGTH = 2M + pgram (rwx) : ORIGIN = 0x40800000, LENGTH = 4M /* w/ cache */ +} + +PHDRS +{ + /* R = 100, W = 010, X = 001 */ + + text PT_LOAD FLAGS(5); /* RX */ + rodata PT_LOAD FLAGS(4); /* R */ + data PT_LOAD FLAGS(6); /* RW */ +} + +SECTIONS +{ + .text : + { + _stext = ABSOLUTE(.); /* Text section */ + *(.start .start.*) /* Place __start here */ + *(.text .text.*) + *(.text.cold) + *(.text.unlikely) + *(.fixup) + *(.gnu.warning) + } > dram :text + + .init_section : + { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _einit = ABSOLUTE(.); + } > dram :text + + /* Vector table must be page aligned */ + + .vector : ALIGN(4096) + { + _vector_start = ABSOLUTE(.); + KEEP(*(.exc_vector_table)) + KEEP(*(".exc_vector_table.*")) + KEEP(*(.vectors)) + _vector_end = ABSOLUTE(.); + } > dram :text + + /* End of text data must be aligned to page boundary */ + + . = ALIGN(4096); + _etext = .; + _sztext = _etext - _stext; + + /* Start of RO data must be page aligned (mapped as read only) */ + + .rodata : ALIGN(4096) + { + _srodata = ABSOLUTE(.); /* Read-only data */ + *(.rodata .rodata.*) + *(.data.rel.ro) + *(.data.rel.ro.*) + } > dram :rodata + + /* End of RO data must be page aligned */ + + . = ALIGN(4096); + + _erodata = .; /* End of read-only data */ + _szrodata = _erodata - _srodata; + _eronly = .; /* End of read-only data */ + + .data : ALIGN(4096) + { + _sdata = ABSOLUTE(.); + *(.data.page_aligned) + *(.data .data.*) + . = ALIGN(8); + *(.data.rel) + *(.data.rel.*) + CONSTRUCTORS + . = ALIGN(8); + _edata = ABSOLUTE(.); + } > dram :data + + .bss : + { + . = ALIGN(8); + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + . = ALIGN(8); + _ebss = ABSOLUTE(.); + } > dram :data + + _szbss = _ebss - _sbss; + + .initstack : + { + _s_initstack = ABSOLUTE(.); + *(.initstack) + } > dram :data + + /* End of data must be page aligned */ + . = ALIGN(4096); + + g_idle_topstack = .; + _e_initstack = .; + _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) } +}