risc-v/k230: add NUTTSBI based kernel build support
Previously k230 kernel build needs OpenSBI wrapping for use on target, thus leading to larger program and memory overheads. This patch adds alternative small overhead kernel build support. Changes: - in arch/risc-v/src/k230: - k230_head.S entrance renamed for sake of NUTTSBI - k230_irq.c add M-mode handling for NUTTSBI case - k230_mm_init.c add L3 table for smaller RAM case - hardware/k230_plic.h add PLIC_CTRL definition - Make.defs use CHIP_ASRCS to fix entrance selection - in boards/risc-v/canmv230/scripts: - Make.defs add support for NUTTSBI case Additions: - in boards/riscv/canmv230/: - scripts/ld-nuttsbi.script link script for NUTTSBI case - configs/nsbi/defconfig config for NUTTSBI case The artifact nuttx.bin from this configuration can be used directly on target as OpenSBI wrapping is not needed. Signed-off-by: Yanfeng Liu <yfliu2008@qq.com> fix typo
This commit is contained in:
parent
6a0eeb1b3e
commit
87c9a0ee76
@ -20,9 +20,7 @@
|
||||
|
||||
include common/Make.defs
|
||||
|
||||
# Specify our HEAD assembly file. This will be linked as
|
||||
# the first object file, so it will appear at address 0
|
||||
HEAD_ASRC = k230_head.S
|
||||
CHIP_ASRCS += k230_head.S
|
||||
|
||||
# Specify our C code within this directory to be included
|
||||
CHIP_CSRCS = k230_start.c k230_irq_dispatch.c k230_irq.c
|
||||
|
@ -46,4 +46,8 @@
|
||||
# define K230_PLIC_CLAIM (K230_PLIC_BASE + 0x200004)
|
||||
#endif
|
||||
|
||||
/* use in M-mode to enable PLIC delegation to S-mode */
|
||||
|
||||
#define K230_PLIC_CTRL (K230_PLIC_BASE + 0x01ffffc)
|
||||
|
||||
#endif /* __ARCH_RISCV_SRC_K230_HARDWARE_K230_PLIC_H */
|
||||
|
@ -41,10 +41,21 @@
|
||||
/* Exported Symbols */
|
||||
|
||||
.section .text
|
||||
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
|
||||
.global __start_s
|
||||
|
||||
__start_s:
|
||||
|
||||
#else
|
||||
|
||||
.global __start
|
||||
|
||||
__start:
|
||||
|
||||
#endif
|
||||
|
||||
/* Preserve a1 by not using it here as it contains DTB */
|
||||
|
||||
#ifndef CONFIG_BUILD_KERNEL
|
||||
|
@ -41,6 +41,19 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
/****************************************************************************
|
||||
* Name: sbi_late_initialize runs in M-mode
|
||||
****************************************************************************/
|
||||
|
||||
void sbi_late_initialize(void)
|
||||
{
|
||||
/* delegate K230 plic enable to S-mode */
|
||||
|
||||
*((volatile uint32_t *)K230_PLIC_CTRL) = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_irqinitialize
|
||||
****************************************************************************/
|
||||
@ -72,7 +85,7 @@ void up_irqinitialize(void)
|
||||
putreg32(1, (uintptr_t)(K230_PLIC_PRIORITY + 4 * id));
|
||||
}
|
||||
|
||||
sinfo("prioritized %d plic irqs\n", NR_IRQS);
|
||||
sinfo("prioritized %d irqs\n", NR_IRQS);
|
||||
|
||||
/* Set irq threshold to 0 (permits all global interrupts) */
|
||||
|
||||
@ -197,7 +210,7 @@ irqstate_t up_irq_enable(void)
|
||||
/* Read and enable global interrupts (M/SIE) in m/sstatus */
|
||||
|
||||
oldstat = READ_AND_SET_CSR(CSR_STATUS, STATUS_IE);
|
||||
sinfo("ie=%lx sts=%lx xcs=%d\n", READ_CSR(CSR_IE), STATUS_LOW,
|
||||
sinfo("ie=%lx sts=%lx ctx=%d\n", READ_CSR(CSR_IE), STATUS_LOW,
|
||||
XCPTCONTEXT_SIZE);
|
||||
|
||||
return oldstat;
|
||||
|
@ -40,15 +40,6 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* T-Head C908 MMU flags for I/O Memory, just in case standard Risc-V
|
||||
* PTE format is not working.
|
||||
*/
|
||||
|
||||
#define MMU_THEAD_SHAREABLE (1ul << 60)
|
||||
#define MMU_THEAD_STRONG_ORDER (1ul << 63)
|
||||
#define MMU_THEAD_IO_FLAGS (MMU_IO_FLAGS | MMU_THEAD_SHAREABLE | \
|
||||
MMU_THEAD_STRONG_ORDER)
|
||||
|
||||
/* Map the whole I/O & PLIC memory with vaddr = paddr mappings */
|
||||
|
||||
#define MMU_IO_BASE (0x80000000) /* KPU-Cache */
|
||||
@ -61,18 +52,27 @@
|
||||
#error "No valid MMU type defined"
|
||||
#endif
|
||||
|
||||
/* Physical and virtual addresses to page tables (vaddr = paddr mapping) */
|
||||
/* Physical and virtual addresses to page tables (vaddr = paddr mapping)
|
||||
* Note NUTTSBI kernel can live in small flash+ram regions thus needs L3
|
||||
* entries
|
||||
*/
|
||||
|
||||
#define PGT_L1_PBASE (uintptr_t)&m_l1_pgtable
|
||||
#define PGT_L2_PBDDR (uintptr_t)&m_l2_pgt_ddr
|
||||
#define PGT_L2_PBINT (uintptr_t)&m_l2_pgt_int
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
#define PGT_L3_PBDDR (uintptr_t)&m_l3_pgt_ddr
|
||||
#endif
|
||||
#define PGT_L1_VBASE PGT_L1_PBASE
|
||||
#define PGT_L2_VBDDR PGT_L2_PBDDR
|
||||
#define PGT_L2_VBINT PGT_L2_PBINT
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
#define PGT_L3_VBDDR PGT_L3_PBDDR
|
||||
#endif
|
||||
|
||||
#define PGT_L1_SIZE (512) /* Enough to map 512 GiB */
|
||||
#define PGT_L2_SIZE (512) /* Enough to map 1 GiB */
|
||||
#define PGT_L3_SIZE (1024) /* Enough to map 4 MiB (2MiB x 2) */
|
||||
#define PGT_L3_SIZE (512) /* Enough to map 2 MiB */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
@ -87,6 +87,9 @@
|
||||
static size_t m_l1_pgtable[PGT_L1_SIZE] locate_data(".pgtables");
|
||||
static size_t m_l2_pgt_ddr[PGT_L2_SIZE] locate_data(".pgtables");
|
||||
static size_t m_l2_pgt_int[PGT_L2_SIZE] locate_data(".pgtables");
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
static size_t m_l3_pgt_ddr[PGT_L3_SIZE] locate_data(".pgtables");
|
||||
#endif
|
||||
|
||||
/* Kernel mappings (L1 base) required by riscv_addrenv */
|
||||
|
||||
@ -155,13 +158,23 @@ void k230_kernel_mappings(void)
|
||||
|
||||
/* Map kernel text and data using L2 pages */
|
||||
|
||||
minfo("map L2 kernel text(%ldMB)\n", KFLASH_SIZE >> 20);
|
||||
minfo("map kernel text(%ldMB)\n", KFLASH_SIZE >> 20);
|
||||
mmu_ln_map_region(2, PGT_L2_VBDDR, KFLASH_START, KFLASH_START,
|
||||
KFLASH_SIZE, MMU_KTEXT_FLAGS);
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
mmu_ln_map_region(3, PGT_L3_VBDDR, KFLASH_START, KFLASH_START,
|
||||
KFLASH_SIZE, MMU_KTEXT_FLAGS);
|
||||
mmu_ln_setentry(2, PGT_L2_VBDDR, PGT_L3_PBDDR, KFLASH_START, 0);
|
||||
#endif
|
||||
|
||||
minfo("map L2 kernel data(%ldMB)\n", KSRAM_SIZE >> 20);
|
||||
minfo("map kernel data(%ldMB)\n", KSRAM_SIZE >> 20);
|
||||
mmu_ln_map_region(2, PGT_L2_VBDDR, KSRAM_START, KSRAM_START,
|
||||
KSRAM_SIZE, MMU_KDATA_FLAGS);
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
mmu_ln_map_region(3, PGT_L3_VBDDR, KSRAM_START, KSRAM_START,
|
||||
KSRAM_SIZE, MMU_KDATA_FLAGS);
|
||||
mmu_ln_setentry(2, PGT_L2_VBDDR, PGT_L3_PBDDR, KSRAM_START, 0);
|
||||
#endif
|
||||
|
||||
/* Map the page pool */
|
||||
|
||||
@ -184,6 +197,9 @@ void k230_kernel_mappings(void)
|
||||
dump_pgtable(m_l1_pgtable, PGT_L1_SIZE, "L1");
|
||||
dump_pgtable(m_l2_pgt_ddr, PGT_L2_SIZE, "L2_DDR");
|
||||
dump_pgtable(m_l2_pgt_int, PGT_L2_SIZE, "L2_INT");
|
||||
#ifdef CONFIG_NUTTSBI
|
||||
dump_pgtable(m_l3_pgt_ddr, PGT_L3_SIZE, "L3_DDR");
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
95
boards/risc-v/k230/canmv230/configs/nsbi/defconfig
Normal file
95
boards/risc-v/k230/canmv230/configs/nsbi/defconfig
Normal file
@ -0,0 +1,95 @@
|
||||
#
|
||||
# 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_DISABLE_OS_API is not set
|
||||
# CONFIG_NSH_DISABLE_LOSMART is not set
|
||||
CONFIG_16550_ADDRWIDTH=0
|
||||
CONFIG_16550_REGWIDTH=32
|
||||
CONFIG_16550_SERIAL_DISABLE_REORDERING=y
|
||||
CONFIG_16550_SUPRESS_CONFIG=y
|
||||
CONFIG_16550_UART0=y
|
||||
CONFIG_16550_UART0_BASE=0x91400000
|
||||
CONFIG_16550_UART0_CLOCK=50000000
|
||||
CONFIG_16550_UART0_IRQ=41
|
||||
CONFIG_16550_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_16550_UART=y
|
||||
CONFIG_16550_WAIT_LCR=y
|
||||
CONFIG_ARCH="risc-v"
|
||||
CONFIG_ARCH_ADDRENV=y
|
||||
CONFIG_ARCH_BOARD="canmv230"
|
||||
CONFIG_ARCH_BOARD_K230_CANMV=y
|
||||
CONFIG_ARCH_CHIP="k230"
|
||||
CONFIG_ARCH_CHIP_K230=y
|
||||
CONFIG_ARCH_DATA_NPAGES=128
|
||||
CONFIG_ARCH_DATA_VBASE=0xC0100000
|
||||
CONFIG_ARCH_HEAP_NPAGES=128
|
||||
CONFIG_ARCH_HEAP_VBASE=0xC0200000
|
||||
CONFIG_ARCH_INTERRUPTSTACK=3072
|
||||
CONFIG_ARCH_KERNEL_STACKSIZE=3072
|
||||
CONFIG_ARCH_LAZYFPU=y
|
||||
CONFIG_ARCH_PGPOOL_MAPPING=y
|
||||
CONFIG_ARCH_PGPOOL_PBASE=0x8600000
|
||||
CONFIG_ARCH_PGPOOL_SIZE=10485760
|
||||
CONFIG_ARCH_PGPOOL_VBASE=0x8600000
|
||||
CONFIG_ARCH_RISCV=y
|
||||
CONFIG_ARCH_TEXT_NPAGES=128
|
||||
CONFIG_ARCH_TEXT_VBASE=0xC0000000
|
||||
CONFIG_ARCH_USE_MMU=y
|
||||
CONFIG_ARCH_USE_MPU=y
|
||||
CONFIG_ARCH_USE_S_MODE=y
|
||||
CONFIG_BINFMT_ELF_EXECUTABLE=y
|
||||
CONFIG_BOARD_LATE_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=6366
|
||||
CONFIG_BUILD_KERNEL=y
|
||||
CONFIG_DEBUG_ASSERTIONS=y
|
||||
CONFIG_DEBUG_FEATURES=y
|
||||
CONFIG_DEV_ZERO=y
|
||||
CONFIG_ELF=y
|
||||
CONFIG_EXAMPLES_HELLO=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_FS_ROMFS=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INIT_FILEPATH="/system/bin/init"
|
||||
CONFIG_INIT_MOUNT=y
|
||||
CONFIG_INIT_MOUNT_FLAGS=0x1
|
||||
CONFIG_INIT_MOUNT_TARGET="/system/bin"
|
||||
CONFIG_INIT_STACKSIZE=3072
|
||||
CONFIG_LIBC_ENVPATH=y
|
||||
CONFIG_LIBC_EXECFUNCS=y
|
||||
CONFIG_LIBC_PERROR_STDOUT=y
|
||||
CONFIG_LIBC_STRERROR=y
|
||||
CONFIG_LIBM=y
|
||||
CONFIG_MEMSET_64BIT=y
|
||||
CONFIG_MEMSET_OPTSPEED=y
|
||||
CONFIG_MM_PGALLOC=y
|
||||
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_FILE_APPS=y
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_NUTTSBI=y
|
||||
CONFIG_NUTTSBI_MTIMECMP_BASE=0xf04004000
|
||||
CONFIG_NUTTSBI_MTIME_BASE=0xf0400bff8
|
||||
CONFIG_PATH_INITIAL="/system/bin"
|
||||
CONFIG_RAM_SIZE=132116480
|
||||
CONFIG_RAM_START=0x8080000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_READLINE_CMD_HISTORY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SERIAL_UART_ARCH_MMIO=y
|
||||
CONFIG_STACK_COLORATION=y
|
||||
CONFIG_STANDARD_SERIAL=y
|
||||
CONFIG_START_DAY=15
|
||||
CONFIG_START_YEAR=2024
|
||||
CONFIG_SYMTAB_ORDEREDBYNAME=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_SYSTEM_NSH_PROGNAME="init"
|
||||
CONFIG_TESTING_GETPRIME=y
|
||||
CONFIG_TESTING_OSTEST=y
|
||||
CONFIG_USEC_PER_TICK=1000
|
@ -24,7 +24,11 @@ include $(TOPDIR)/arch/risc-v/src/common/Toolchain.defs
|
||||
|
||||
ifeq ($(CONFIG_ARCH_CHIP_K230),y)
|
||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||
ifeq ($(CONFIG_NUTTSBI),y)
|
||||
LDSCRIPT = ld-nuttsbi.script
|
||||
else
|
||||
LDSCRIPT = ld-kernel.script
|
||||
endif
|
||||
else ifeq ($(CONFIG_BUILD_PROTECTED),y)
|
||||
LDSCRIPT = ld-protected.script
|
||||
else
|
||||
@ -54,17 +58,21 @@ endif
|
||||
|
||||
# POSTBUILD management
|
||||
|
||||
# KERNEL build needs real ROMFS and SBI wrapping
|
||||
# KERNEL builds need real ROMFS and even OpenSBI wrapping
|
||||
|
||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||
ifeq ($(wildcard $(BOARD_DIR)$(DELIM)src$(DELIM)romfs_boot.c),)
|
||||
define POSTBUILD
|
||||
$(Q) echo "Please replace stub ROMFS w/ real one."
|
||||
$(Q) echo "Please replace stub ROMFS with real one."
|
||||
$(Q) rm $(BOARD_DIR)$(DELIM)src$(DELIM)libboard.a
|
||||
endef
|
||||
else ifneq ($(CONFIG_NUTTSBI),y)
|
||||
define POSTBUILD
|
||||
$(Q) echo "Please wrap nuttx.bin with OpenSBI to run on target."
|
||||
endef
|
||||
else
|
||||
define POSTBUILD
|
||||
$(Q) echo "wrap nuttx.bin w/ SBI to run on target."
|
||||
$(Q) echo "Please try nuttx.bin on target."
|
||||
endef
|
||||
endif
|
||||
endif
|
||||
|
143
boards/risc-v/k230/canmv230/scripts/ld-nuttsbi.script
Normal file
143
boards/risc-v/k230/canmv230/scripts/ld-nuttsbi.script
Normal file
@ -0,0 +1,143 @@
|
||||
/****************************************************************************
|
||||
* boards/risc-v/k230/canmv230/scripts/ld-nuttsbi.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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
MEMORY
|
||||
{
|
||||
kflash (rx) : ORIGIN = 0x8000000, LENGTH = 384K /* w/ cache */
|
||||
ksram (rwx) : ORIGIN = 0x8080000, LENGTH = 128K /* w/ cache */
|
||||
pgram (rwx) : ORIGIN = 0x8600000, LENGTH = 10M /* w/ cache */
|
||||
}
|
||||
|
||||
OUTPUT_ARCH("riscv")
|
||||
|
||||
/* Provide the kernel boundaries */
|
||||
|
||||
__kflash_start = ORIGIN(kflash);
|
||||
__kflash_size = LENGTH(kflash);
|
||||
__ksram_start = ORIGIN(ksram);
|
||||
__ksram_size = LENGTH(ksram);
|
||||
__ksram_end = ORIGIN(ksram) + LENGTH(ksram);
|
||||
|
||||
/* Page heap */
|
||||
|
||||
__pgheap_start = ORIGIN(pgram);
|
||||
__pgheap_size = LENGTH(pgram);
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x8000000;
|
||||
|
||||
.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 = . ;
|
||||
}
|
||||
|
||||
.tdata : {
|
||||
_stdata = ABSOLUTE(.);
|
||||
*(.tdata .tdata.* .gnu.linkonce.td.*);
|
||||
_etdata = ABSOLUTE(.);
|
||||
}
|
||||
|
||||
.tbss : {
|
||||
_stbss = ABSOLUTE(.);
|
||||
*(.tbss .tbss.* .gnu.linkonce.tb.* .tcommon);
|
||||
_etbss = ABSOLUTE(.);
|
||||
}
|
||||
|
||||
_eronly = ABSOLUTE(.);
|
||||
|
||||
.data :
|
||||
{
|
||||
_sdata = . ;
|
||||
*(.data)
|
||||
*(.data1)
|
||||
*(.data.*)
|
||||
*(.gnu.linkonce.d*)
|
||||
. = ALIGN(4);
|
||||
_edata = . ;
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
_sbss = . ;
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.sbss)
|
||||
*(.sbss.*)
|
||||
*(.gnu.linkonce.b*)
|
||||
*(COMMON)
|
||||
_ebss = . ;
|
||||
} > ksram
|
||||
|
||||
/* Page tables here, align to 4K boundary */
|
||||
|
||||
.pgtables (NOLOAD) : ALIGN(0x1000) {
|
||||
*(.pgtables)
|
||||
. = ALIGN(4);
|
||||
} > ksram
|
||||
|
||||
/* Stack top */
|
||||
|
||||
.stack_top : {
|
||||
. = ALIGN(32);
|
||||
_ebss = ABSOLUTE(.);
|
||||
} > ksram
|
||||
|
||||
/* 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) }
|
||||
}
|
Loading…
Reference in New Issue
Block a user