diff --git a/Documentation/platforms/risc-v/k230/boards/canmv230/index.rst b/Documentation/platforms/risc-v/k230/boards/canmv230/index.rst index 7f5cdd67d51..673287db090 100644 --- a/Documentation/platforms/risc-v/k230/boards/canmv230/index.rst +++ b/Documentation/platforms/risc-v/k230/boards/canmv230/index.rst @@ -10,27 +10,25 @@ The `K230 SDK `_ contains source code, lib K230 boots from CPU0 and loads U-Boot into DRAM first, then U-Boot kicks off OpenSBI wrapped Linux/RTT OS images on respective CPU cores accordingly. -The K230 U-Boot operates in machine mode, thus provides an ideal environment for NuttX. allowing one to run flat or kernel builds in theory. - +The K230 U-Boot runs in machine mode, thus it can run flat or kernel NuttX builds. The kernel build shall run with or without SBI layer. Preparations ============ -Please follow the K230 SDK to prepare a booting SD card for the board, or use prebuilt boot image from `here `_. +Take the prebuilt CanMV-k230 boot image from `here ` as the v1.2 K230 SDK doesn't provide RiscV standard PTE format support needed by NuttX. This package also contains extract of OpenSBI from K230 SDK v1.2 release, which is needed to wrap kernel build NuttX binary. Make sure that before trying NuttX: -- The board can boot default SDK image normally. -- U-Boot console can be accessed from host(e.g. `minicom -D /dev/ttyACM0`). -- U-Boot has access to a TFTP service is available. -- You can drop files to the TFTP service folder. +- The board can boot K230 SDK image normally. +- Device console access available (e.g. `minicom -D /dev/ttyACM0`). +- U-Boot connectivity to TFTP service available. -Note for below NuttX tests, the SD image is only used to enter U-Boot console. +For NuttX tests, the microSD card is only used to enter U-Boot console, NuttX isn't using any persistent storage on the target now. -RISC-V Toolchain -================ +Toolchains +========== -Before building NuttX for Star64, download the **RISC-V Toolchain riscv64-unknown-elf** from `XPack `_ or use "gcc-riscv64-unknown-elf" on Ubuntu. +Before building NuttX, download the **RISC-V Toolchain riscv64-unknown-elf** from `XPack `_ or use the stock "gcc-riscv64-unknown-elf" on Ubuntu. Building @@ -46,18 +44,50 @@ Configure the NuttX project and build the project: $ tools/configure.sh canmv230:nsh $ make -j4 -There should have `nuttx.bin` generated. +This should have `nuttx.bin` generated, it can be used without OpenSBI wrapping on the board. + +The kernel build requires two build passes: first pass to build kernel and apps, second pass to build the kernel with a ROMFS image that includes some built apps. + +.. code:: console + + $ cd nuttx + $ tools/configure.sh canmv230:knsh + $ make -j4 # first pass for apps build preparations + $ (make export; cd ../apps; tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.gz; make import) + $ (cd ../apps/; tools/mkromfsimg.sh ../nuttx/boards/risc-v/k230/canmv230/src/romfs_boot.c) + $ make -j4 # second pass to pick up ROMFS + +The built `nuttx.bin` can be then wrapped with K230 OpenSBI like below: + +.. code:: console + + $ cd $HOME + $ tar xvf canmv230-opensbi-dtb.tar.xz + $ export OSBI=$HOME/opensbi + $ cd /tmp/aaa # use a temporary work folder + $ make -C $OSBI O=$(pwd) PLATFORM=generic\ + CROSS_COMPILE=riscv64-unknown-elf- FW_PIC=n K230_LIITLE_CORE=1\ + FW_FDT_PATH=$OSBI/k230.dtb FW_PAYLOAD_PATH=nuttx.bin -j4 + $ cp platform/generic/firmware/fw_payload.bin tftp-server-path/nuttx.bin + +Note to use actual paths of SBI source tree, device dtb, TFTP folder etc when using above commands. Booting ======= -Copy the `nuttx.bin` to the TFTP service folder and work with the U-Boot console: +Within U-boot console, load `nuttx.bin` from TFTP service and run it: .. code:: console k230# usb start k230# ping $serverip k230# tftp 8000000 nuttx.bin - k230# boot_barememtal 0 8000000 $filesize + k230# go 8000000 + +Then the `nsh> ` console should appear, type `help` to see available commands. + +Issues +====== + + - The `ostest` app only works with flat build. -Then the `nsh> `console should appear, type `help` to see available commands. diff --git a/arch/risc-v/include/k230/irq.h b/arch/risc-v/include/k230/irq.h index 4e527c7c82d..c2676041c7a 100644 --- a/arch/risc-v/include/k230/irq.h +++ b/arch/risc-v/include/k230/irq.h @@ -31,8 +31,16 @@ /* Map RISC-V exception code to NuttX IRQ */ -#define K230_IRQ_UART0 (RISCV_IRQ_MEXT + 16) +#ifndef CONFIG_BUILD_KERNEL +# define K230_IRQ_TIMER (RISCV_IRQ_MTIMER) +# define K230_IRQ_UART0 (RISCV_IRQ_MEXT + 16) +#else +# define K230_IRQ_TIMER (RISCV_IRQ_STIMER) +# define K230_IRQ_UART0 (RISCV_IRQ_SEXT + 16) +#endif -#define NR_IRQS (K230_IRQ_UART0 + 1) +/* NR_IRQS is needed by NuttX */ + +#define NR_IRQS (K230_IRQ_UART0 + 1) #endif /* __ARCH_RISCV_INCLUDE_K230_IRQ_H */ diff --git a/arch/risc-v/src/k230/Make.defs b/arch/risc-v/src/k230/Make.defs index d481c48d3cc..73dab21378f 100644 --- a/arch/risc-v/src/k230/Make.defs +++ b/arch/risc-v/src/k230/Make.defs @@ -30,7 +30,6 @@ CHIP_CSRCS += k230_timerisr.c k230_allocateheap.c ifeq ($(CONFIG_BUILD_KERNEL),y) CHIP_CSRCS += k230_mm_init.c -CMN_ASRCS += k230_exception_m.S endif ifeq ($(CONFIG_MM_PGALLOC),y) diff --git a/arch/risc-v/src/k230/hardware/k230_clint.h b/arch/risc-v/src/k230/hardware/k230_clint.h index 7bf44350072..834984a5c22 100644 --- a/arch/risc-v/src/k230/hardware/k230_clint.h +++ b/arch/risc-v/src/k230/hardware/k230_clint.h @@ -27,14 +27,21 @@ #define K230_CLINT_MSIP (K230_CLINT_BASE + 0x0000) #define K230_CLINT_MTIMECMP (K230_CLINT_BASE + 0x4000) +#define K230_CLINT_SSIP (K230_CLINT_BASE + 0xC000) +#define K230_CLINT_STIMECMP (K230_CLINT_BASE + 0xD000) #define K230_CLINT_MTIME (K230_CLINT_BASE + 0xBFF8) +#define K230_CLINT_STIME (K230_CLINT_BASE + 0xBFF8) -#define RISCV_CLINT_MSIP K230_CLINT_MSIP +#define K230_CLINT_FREQ (27000000) #ifdef CONFIG_ARCH_USE_S_MODE -# define RISCV_IPI +# define K230_IPI K230_CLINT_SSIP +# define K230_TIME K230_CLINT_STIME +# define K230_TIMECMP K230_CLINT_STIMECMP #else -# define RISCV_IPI RISCV_CLINT_MSIP +# define K230_IPI K230_CLINT_MSIP +# define K230_TIME K230_CLINT_MTIME +# define K230_TIMECMP K230_CLINT_MTIMECMP #endif #endif /* __ARCH_RISCV_SRC_K230_HARDWARE_K230_CLINT_H */ diff --git a/arch/risc-v/src/k230/k230_exception_m.S b/arch/risc-v/src/k230/k230_exception_m.S deleted file mode 100644 index a4ca925afc8..00000000000 --- a/arch/risc-v/src/k230/k230_exception_m.S +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * arch/risc-v/src/qemu-rv/k230_exception_m.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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include - -#include "chip.h" - -#include "riscv_macros.S" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Provide a default section for the exeception handler. */ - -#ifndef EXCEPTION_SECTION -# define EXCEPTION_SECTION .text -#endif - -/**************************************************************************** - * Public Symbols - ****************************************************************************/ - -.section .text -.balign 8 -.global __trap_vec_m - -/**************************************************************************** - * Name: __trap_vec_m - * - * Description: - * All M-mode exceptions and interrupts will be handled from here. If - * kernel is in S-mode delegated exceptions and interrupts are handled. - * - ****************************************************************************/ - -__trap_vec_m: - j exception_m - -/**************************************************************************** - * Name: exception_m - * - * Description: - * Handles interrupts for m-mode - * - ****************************************************************************/ - -.section EXCEPTION_SECTION -.global exception_m -.align 8 - -exception_m: - - /* Swap mscratch with sp */ - /* NOTE: mscratch has been set in up_mtimer_initialize() */ - - csrrw sp, mscratch, sp - - /* Save the context */ - - save_ctx sp - - /* Handle the mtimer interrupt */ - /* NOTE: we assume exception/interrupt only happens for mtimer */ - - jal ra, k230_mtimer_interrupt - - /* Restore the context */ - - load_ctx sp - - /* Swap mscratch with sp */ - - csrrw sp, mscratch, sp - - /* Return from exception */ - - mret diff --git a/arch/risc-v/src/k230/k230_head.S b/arch/risc-v/src/k230/k230_head.S index 1509a41b670..56d1bb271cf 100644 --- a/arch/risc-v/src/k230/k230_head.S +++ b/arch/risc-v/src/k230/k230_head.S @@ -26,6 +26,7 @@ #include #include +#include #include "chip.h" #include "riscv_internal.h" @@ -33,6 +34,9 @@ /**************************************************************************** * Public Symbols ****************************************************************************/ + /* Imported symbols */ + + .extern __trap_vec /* Exported Symbols */ @@ -41,10 +45,13 @@ __start: - /* Preserve a1 as it contains the pointer to DTB */ + /* Preserve a1 by not using it here as it contains DTB */ + +#ifndef CONFIG_BUILD_KERNEL /* Load mhartid (cpuid) */ csrr a0, mhartid +#endif /* Set stack pointer to the idle thread stack */ @@ -64,7 +71,7 @@ __start: /* If a0 (mhartid) >= t1 (the number of CPUs), stop here */ blt a0, t1, 3f - csrw mie, zero + csrw CSR_IE, zero wfi 3: @@ -74,11 +81,7 @@ __start: /* Offset = pointer width * hart id */ -#ifdef CONFIG_ARCH_RV32 - slli t1, a0, 2 -#else slli t1, a0, 3 -#endif add t0, t0, t1 /* Load idle stack base to sp */ @@ -97,14 +100,14 @@ __start: 2: - /* Disable all interrupts (i.e. timer, external) in mie */ + /* Disable all interrupts (i.e. timer, external) */ - csrw mie, zero - - la t0, __trap_vec - csrw mtvec, t0 - - /* Jump to k230_start */ + csrw CSR_IE, zero + + la t0, __trap_vec /* __trap_dump */ + csrw CSR_TVEC, t0 + + /* Jump to k230_start, a0=mhartid, a1=dtb */ jal x1, k230_start diff --git a/arch/risc-v/src/k230/k230_irq.c b/arch/risc-v/src/k230/k230_irq.c index 1acfbc98e40..f803f829fd3 100644 --- a/arch/risc-v/src/k230/k230_irq.c +++ b/arch/risc-v/src/k230/k230_irq.c @@ -35,6 +35,8 @@ #include "riscv_internal.h" #include "chip.h" +#define STATUS_LOW (READ_CSR(CSR_STATUS) & 0xffffffff) /* STATUS low part */ + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -70,6 +72,8 @@ void up_irqinitialize(void) putreg32(1, (uintptr_t)(K230_PLIC_PRIORITY + 4 * id)); } + sinfo("prioritized %d plic irqs\n", NR_IRQS); + /* Set irq threshold to 0 (permits all global interrupts) */ putreg32(0, K230_PLIC_THRESHOLD); @@ -114,7 +118,7 @@ void up_disable_irq(int irq) } else if (irq == RISCV_IRQ_TIMER) { - /* Read m/sstatus & clear timer interrupt enable in m/sie */ + /* Disable timer interrupt in m/sie */ CLEAR_CSR(CSR_IE, IE_TIE); } @@ -134,6 +138,8 @@ void up_disable_irq(int irq) PANIC(); } } + + sinfo("ie=%lx sts=%lx irq=%d\n", READ_CSR(CSR_IE), STATUS_LOW, irq); } /**************************************************************************** @@ -156,23 +162,15 @@ void up_enable_irq(int irq) } else if (irq == RISCV_IRQ_TIMER) { - /* Read m/sstatus & set timer interrupt enable in m/sie */ + /* Enable timer interrupt in m/sie */ SET_CSR(CSR_IE, IE_TIE); } -#ifdef CONFIG_BUILD_KERNEL - else if (irq == RISCV_IRQ_MTIMER) - { - /* Read m/sstatus & set timer interrupt enable in m/sie */ - - SET_CSR(mie, MIE_MTIE); - } -#endif else if (irq > RISCV_IRQ_EXT) { extirq = irq - RISCV_IRQ_EXT; - /* Set enable bit for the irq */ + /* Enable the irq in PLIC */ if (0 <= extirq && extirq <= 63) { @@ -184,6 +182,8 @@ void up_enable_irq(int irq) PANIC(); } } + + sinfo("ie=%lx sts=%lx irq=%d\n", READ_CSR(CSR_IE), STATUS_LOW, irq); } irqstate_t up_irq_enable(void) @@ -197,6 +197,8 @@ 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, + XCPTCONTEXT_SIZE); return oldstat; } diff --git a/arch/risc-v/src/k230/k230_mm_init.c b/arch/risc-v/src/k230/k230_mm_init.c index c3bbf154d7c..7a75f8fb103 100644 --- a/arch/risc-v/src/k230/k230_mm_init.c +++ b/arch/risc-v/src/k230/k230_mm_init.c @@ -40,69 +40,44 @@ * Pre-processor Definitions ****************************************************************************/ -/* Map the whole I/O memory with vaddr = paddr mappings */ +/* T-Head C908 MMU flags for I/O Memory, just in case standard Risc-V + * PTE format is not working. + */ -#define MMU_IO_BASE (0x80400000) // KPU config -#define MMU_IO_SIZE (0x19c00000) // DDR config +#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) -#ifdef CONFIG_ARCH_MMU_TYPE_SV32 +/* Map the whole I/O & PLIC memory with vaddr = paddr mappings */ + +#define MMU_IO_BASE (0x80000000) /* KPU-Cache */ +#define MMU_IO_SIZE (0x40000000) /* 1GB, till XIP start */ + +#define MMU_INT_BASE (0xF00000000ul) /* PLIC base */ +#define MMU_INT_SIZE (0x400000ul) /* 4MB */ + +#ifndef CONFIG_ARCH_MMU_TYPE_SV39 +#error "No valid MMU type defined" +#endif /* Physical and virtual addresses to page tables (vaddr = paddr mapping) */ #define PGT_L1_PBASE (uintptr_t)&m_l1_pgtable -#define PGT_L2_PBASE (uintptr_t)&m_l2_pgtable +#define PGT_L2_PBDDR (uintptr_t)&m_l2_pgt_ddr +#define PGT_L2_PBINT (uintptr_t)&m_l2_pgt_int #define PGT_L1_VBASE PGT_L1_PBASE -#define PGT_L2_VBASE PGT_L2_PBASE - -#define PGT_L1_SIZE (1024) /* Enough to map 4 GiB */ -#define PGT_L2_SIZE (3072) /* Enough to map 12 MiB */ - -#define SLAB_COUNT (sizeof(m_l2_pgtable) / RV_MMU_PAGE_SIZE) - -#define KMM_PAGE_SIZE RV_MMU_L2_PAGE_SIZE -#define KMM_PBASE PGT_L2_PBASE -#define KMM_PBASE_IDX 2 -#define KMM_SPBASE PGT_L1_PBASE -#define KMM_SPBASE_IDX 1 - -#elif CONFIG_ARCH_MMU_TYPE_SV39 - -/* Physical and virtual addresses to page tables (vaddr = paddr mapping) */ - -#define PGT_L1_PBASE (uintptr_t)&m_l1_pgtable -#define PGT_L2_PBASE (uintptr_t)&m_l2_pgtable -#define PGT_L3_PBASE (uintptr_t)&m_l3_pgtable -#define PGT_L1_VBASE PGT_L1_PBASE -#define PGT_L2_VBASE PGT_L2_PBASE -#define PGT_L3_VBASE PGT_L3_PBASE +#define PGT_L2_VBDDR PGT_L2_PBDDR +#define PGT_L2_VBINT PGT_L2_PBINT #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 SLAB_COUNT (sizeof(m_l3_pgtable) / RV_MMU_PAGE_SIZE) - -#define KMM_PAGE_SIZE RV_MMU_L3_PAGE_SIZE -#define KMM_PBASE PGT_L3_PBASE -#define KMM_PBASE_IDX 3 -#define KMM_SPBASE PGT_L2_PBASE -#define KMM_SPBASE_IDX 2 - -#else -#error No valid MMU defined. -#endif - /**************************************************************************** * Private Types ****************************************************************************/ -struct pgalloc_slab_s -{ - sq_entry_t *next; - void *memory; -}; -typedef struct pgalloc_slab_s pgalloc_slab_t; - /**************************************************************************** * Private Data ****************************************************************************/ @@ -110,122 +85,37 @@ typedef struct pgalloc_slab_s pgalloc_slab_t; /* Kernel mappings simply here, mapping is vaddr=paddr */ static size_t m_l1_pgtable[PGT_L1_SIZE] locate_data(".pgtables"); -static size_t m_l2_pgtable[PGT_L2_SIZE] locate_data(".pgtables"); -#ifdef CONFIG_ARCH_MMU_TYPE_SV39 -static size_t m_l3_pgtable[PGT_L3_SIZE] locate_data(".pgtables"); -#endif +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"); -/* Kernel mappings (L1 base) */ +/* Kernel mappings (L1 base) required by riscv_addrenv */ uintptr_t g_kernel_mappings = PGT_L1_VBASE; uintptr_t g_kernel_pgt_pbase = PGT_L1_PBASE; -/* L3 page table allocator */ - -static sq_queue_t g_free_slabs; -static pgalloc_slab_t g_slabs[SLAB_COUNT]; - /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: slab_init + * Name: dump_pgtable * * Description: - * Initialize slab allocator for L2 or L3 page table entries - * - * L2 Page table is used for SV32. L3 used for SV39 - * - * Input Parameters: - * start - Beginning of the L2 or L3 page table pool + * Dump page tables to console, mainly for debugging purposes. * ****************************************************************************/ -static void slab_init(uintptr_t start) +static void dump_pgtable(const size_t * pgt, uint32_t len, const char * name) { - int i; - - sq_init(&g_free_slabs); - - for (i = 0; i < SLAB_COUNT; i++) + minfo("%s at %lx\n", name, (size_t)pgt); + for (uint32_t i = 0; i < len ; i++) { - g_slabs[i].memory = (void *)start; - sq_addlast((sq_entry_t *)&g_slabs[i], (sq_queue_t *)&g_free_slabs); - start += RV_MMU_PAGE_SIZE; - } -} - -/**************************************************************************** - * Name: slab_alloc - * - * Description: - * Allocate single slab for L2/L3 page table entry - * - * L2 Page table is used for SV32. L3 used for SV39 - * - ****************************************************************************/ - -static uintptr_t slab_alloc(void) -{ - pgalloc_slab_t *slab = (pgalloc_slab_t *)sq_remfirst(&g_free_slabs); - return slab ? (uintptr_t)slab->memory : 0; -} - -/**************************************************************************** - * Name: map_region - * - * Description: - * Map a region of physical memory to the L3 page table - * - * Input Parameters: - * paddr - Beginning of the physical address mapping - * vaddr - Beginning of the virtual address mapping - * size - Size of the region in bytes - * mmuflags - The MMU flags to use in the mapping - * - ****************************************************************************/ - -static void map_region(uintptr_t paddr, uintptr_t vaddr, size_t size, - uint32_t mmuflags) -{ - uintptr_t endaddr; - uintptr_t pbase; - int npages; - int i; - int j; - - /* How many pages */ - - npages = (size + RV_MMU_PAGE_MASK) >> RV_MMU_PAGE_SHIFT; - endaddr = vaddr + size; - - for (i = 0; i < npages; i += RV_MMU_PAGE_ENTRIES) - { - /* See if a mapping exists ? */ - - pbase = mmu_pte_to_paddr(mmu_ln_getentry( - KMM_SPBASE_IDX, KMM_SPBASE, vaddr)); - if (!pbase) + uintptr_t pte = (uintptr_t)pgt[i]; + if (pte & PTE_VALID) { - /* No, allocate 1 page, this must not fail */ - - pbase = slab_alloc(); - DEBUGASSERT(pbase); - - /* Map it to the new table */ - - mmu_ln_setentry( - KMM_SPBASE_IDX, KMM_SPBASE, pbase, vaddr, MMU_UPGT_FLAGS); - } - - /* Then add the mappings */ - - for (j = 0; j < RV_MMU_PAGE_ENTRIES && vaddr < endaddr; j++) - { - mmu_ln_setentry(KMM_PBASE_IDX, pbase, paddr, vaddr, mmuflags); - paddr += KMM_PAGE_SIZE; - vaddr += KMM_PAGE_SIZE; + minfo("#%03d paddr:%09lx flags:%02x %s\n", i, + mmu_pte_to_paddr(pte), (unsigned)(pte & 0xff), + (pte & PTE_LEAF_MASK)? "" : ">>>"); } } } @@ -245,46 +135,55 @@ static void map_region(uintptr_t paddr, uintptr_t vaddr, size_t size, void k230_kernel_mappings(void) { - /* Initialize slab allocator for the L2/L3 page tables */ - - slab_init(KMM_PBASE); - /* Begin mapping memory to MMU; note that at this point the MMU is not yet * active, so the page table virtual addresses are actually physical * addresses and so forth. M-mode does not perform translations anyhow, so * this mapping is quite simple to do */ - /* Map I/O region, use enough large page tables for the IO region. */ + /* Map I/O region in L1 page table. */ - binfo("map I/O regions\n"); + minfo("map L1 I/O regions(%dGB)\n", MMU_IO_SIZE >> 30); mmu_ln_map_region(1, PGT_L1_VBASE, MMU_IO_BASE, MMU_IO_BASE, MMU_IO_SIZE, MMU_IO_FLAGS); - /* Map the kernel text and data for L2/L3 */ + /* Map INT region using L2 page table */ - binfo("map kernel text\n"); - map_region(KFLASH_START, KFLASH_START, KFLASH_SIZE, MMU_KTEXT_FLAGS); + minfo("map L2 INT regions(%ldMB)\n", MMU_INT_SIZE >> 20); + mmu_ln_map_region(2, PGT_L2_VBINT, MMU_INT_BASE, MMU_INT_BASE, + MMU_INT_SIZE, MMU_IO_FLAGS); - binfo("map kernel data\n"); - map_region(KSRAM_START, KSRAM_START, KSRAM_SIZE, MMU_KDATA_FLAGS); + /* Map kernel text and data using L2 pages */ -#ifdef CONFIG_ARCH_MMU_TYPE_SV39 + minfo("map L2 kernel text(%ldMB)\n", KFLASH_SIZE >> 20); + mmu_ln_map_region(2, PGT_L2_VBDDR, KFLASH_START, KFLASH_START, + KFLASH_SIZE, MMU_KTEXT_FLAGS); - /* Connect the L1 and L2 page tables for the kernel text and data */ - - binfo("connect the L1 and L2 page tables\n"); - mmu_ln_setentry(1, PGT_L1_VBASE, PGT_L2_PBASE, KFLASH_START, PTE_G); + minfo("map L2 kernel data(%ldMB)\n", KSRAM_SIZE >> 20); + mmu_ln_map_region(2, PGT_L2_VBDDR, KSRAM_START, KSRAM_START, + KSRAM_SIZE, MMU_KDATA_FLAGS); /* Map the page pool */ - binfo("map the page pool\n"); - mmu_ln_map_region(2, PGT_L2_VBASE, PGPOOL_START, PGPOOL_START, PGPOOL_SIZE, - MMU_KDATA_FLAGS); -#elif CONFIG_ARCH_MMU_TYPE_SV32 - binfo("map the page pool\n"); - map_region(PGPOOL_START, PGPOOL_START, PGPOOL_SIZE, MMU_KDATA_FLAGS); -#endif + minfo("map L2 pages pool(%ldMB)\n", PGPOOL_SIZE >> 20); + mmu_ln_map_region(2, PGT_L2_VBDDR, PGPOOL_START, PGPOOL_START, + PGPOOL_SIZE, MMU_KDATA_FLAGS); + + /* Connect the L1 and L2 page tables */ + + minfo("connect L1 and L2 DDR pgtables\n"); + mmu_ln_setentry(1, PGT_L1_VBASE, PGT_L2_PBDDR, KFLASH_START, 0); + + /* Connect the L1 and L2 page tables for INT regions */ + + minfo("connect L1 and L2 INT pgtables\n"); + mmu_ln_setentry(1, PGT_L1_VBASE, PGT_L2_PBINT, MMU_INT_BASE, 0); + + /* dump page tables */ + + 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"); } /**************************************************************************** @@ -302,8 +201,8 @@ void k230_mm_init(void) k230_kernel_mappings(); - /* Enable MMU (note: system is still in M-mode) */ + /* Enable MMU (note: system in S-mode) */ - binfo("mmu_enable: satp=%" PRIuPTR "\n", g_kernel_pgt_pbase); + minfo("mmu_enable: satp=%lx\n", g_kernel_pgt_pbase); mmu_enable(g_kernel_pgt_pbase, 0); } diff --git a/arch/risc-v/src/k230/k230_start.c b/arch/risc-v/src/k230/k230_start.c index cf46c685f9c..2bab9c4b7e7 100644 --- a/arch/risc-v/src/k230/k230_start.c +++ b/arch/risc-v/src/k230/k230_start.c @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -54,21 +55,11 @@ # error "Target requires kernel in S-mode, enable CONFIG_ARCH_USE_S_MODE" #endif -/**************************************************************************** - * Extern Function Declarations - ****************************************************************************/ - -#ifdef CONFIG_BUILD_KERNEL -extern void __trap_vec(void); -extern void __trap_vec_m(void); -extern void up_mtimer_initialize(void); -#endif - /**************************************************************************** * Name: k230_clear_bss ****************************************************************************/ -void k230_clear_bss(void) +static void k230_clear_bss(void) { uint32_t *dest; @@ -100,12 +91,23 @@ uintptr_t g_idle_topstack = K230_IDLESTACK_TOP; * Name: k230_start ****************************************************************************/ -#ifdef CONFIG_BUILD_KERNEL -void k230_start_s(int mhartid, const char *dtb) -#else void k230_start(int mhartid, const char *dtb) -#endif { + if (0 == mhartid) + { + k230_clear_bss(); + +#ifdef CONFIG_BUILD_KERNEL + /* Initialize the per CPU areas */ + + riscv_percpu_add_hart(mhartid); +#endif + } + + /* Disable MMU */ + + WRITE_CSR(satp, 0x0); + /* Configure FPU */ riscv_fpuconfig(); @@ -115,10 +117,6 @@ void k230_start(int mhartid, const char *dtb) goto cpux; } -#ifndef CONFIG_BUILD_KERNEL - k230_clear_bss(); -#endif - #ifdef CONFIG_DEVICE_TREE fdt_register(dtb); #endif @@ -157,77 +155,6 @@ cpux: } } -#ifdef CONFIG_BUILD_KERNEL - -/**************************************************************************** - * Name: k230_start - ****************************************************************************/ - -void k230_start(int mhartid, const char *dtb) -{ - /* NOTE: still in M-mode */ - - if (0 == mhartid) - { - k230_clear_bss(); - - /* Initialize the per CPU areas */ - - riscv_percpu_add_hart(mhartid); - } - - /* Disable MMU and enable PMP */ - - WRITE_CSR(satp, 0x0); - WRITE_CSR(pmpaddr0, 0x3fffffffffffffull); - WRITE_CSR(pmpcfg0, 0xf); - - /* Set exception and interrupt delegation for S-mode */ - - WRITE_CSR(medeleg, 0xffff); - WRITE_CSR(mideleg, 0xffff); - - /* Allow to write satp from S-mode */ - - CLEAR_CSR(mstatus, MSTATUS_TVM); - - /* Set mstatus to S-mode and enable SUM */ - - CLEAR_CSR(mstatus, ~MSTATUS_MPP_MASK); - SET_CSR(mstatus, MSTATUS_MPPS | SSTATUS_SUM); - - /* Set the trap vector for S-mode */ - - WRITE_CSR(stvec, (uintptr_t)__trap_vec); - - /* Set the trap vector for M-mode */ - - WRITE_CSR(mtvec, (uintptr_t)__trap_vec_m); - - if (0 == mhartid) - { - /* Only the primary CPU needs to initialize mtimer - * before entering to S-mode - */ - - up_mtimer_initialize(); - } - - /* Set mepc to the entry */ - - WRITE_CSR(mepc, (uintptr_t)k230_start_s); - - /* Set a0 to mhartid and a1 to dtb explicitly and enter to S-mode */ - - asm volatile ( - "mv a0, %0 \n" - "mv a1, %1 \n" - "mret \n" - :: "r" (mhartid), "r" (dtb) - ); -} -#endif - void riscv_earlyserialinit(void) { u16550_earlyserialinit(); diff --git a/arch/risc-v/src/k230/k230_timerisr.c b/arch/risc-v/src/k230/k230_timerisr.c index 1b82f98909e..ff97e1cf3e5 100644 --- a/arch/risc-v/src/k230/k230_timerisr.c +++ b/arch/risc-v/src/k230/k230_timerisr.c @@ -38,7 +38,6 @@ #include "riscv_internal.h" #include "riscv_mtimer.h" -#include "riscv_percpu.h" #include "hardware/k230_memorymap.h" #include "hardware/k230_clint.h" @@ -46,78 +45,14 @@ * Pre-processor Definitions ****************************************************************************/ -#define MTIMER_FREQ 10000000 -#define TICK_COUNT (10000000 / TICK_PER_SEC) - -#ifdef CONFIG_BUILD_KERNEL - /**************************************************************************** * Private Data ****************************************************************************/ -static uint32_t g_mtimer_cnt = 0; -static uint32_t g_stimer_pending = false; - /**************************************************************************** * Private Functions for S-mode ****************************************************************************/ -/**************************************************************************** - * Name: k230_ssoft_interrupt - * - * Description: - * This function is S-mode software interrupt handler to proceed - * the OS timer - * - ****************************************************************************/ - -static int k230_ssoft_interrupt(int irq, void *context, void *arg) -{ - /* Cleaer Supervisor Software Interrupt */ - - CLEAR_CSR(sip, SIP_SSIP); - - if (g_stimer_pending) - { - g_stimer_pending = false; - - /* Proceed the OS timer */ - - nxsched_process_timer(); - } -#ifdef CONFIG_SMP - else - { - /* We assume IPI has been issued */ - - riscv_pause_handler(irq, context, arg); - } -#endif - - return 0; -} - -/**************************************************************************** - * Name: k230_reload_mtimecmp - * - * Description: - * This function is called during start-up to initialize mtimecmp - * for CONFIG_BUILD_KERNEL=y - * - ****************************************************************************/ - -static void k230_reload_mtimecmp(void) -{ - uint64_t current; - uint64_t next; - - current = READ_CSR(time); - next = current + TICK_COUNT; - putreg64(next, K230_CLINT_MTIMECMP); -} - -#endif /* CONFIG_BUILD_KERNEL */ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -126,86 +61,16 @@ static void k230_reload_mtimecmp(void) * Name: up_timer_initialize * * Description: - * This function is called during start-up to initialize - * the timer interrupt. - * + * This function is called during start-up to initialize timer interrupt ****************************************************************************/ void up_timer_initialize(void) { -#ifndef CONFIG_BUILD_KERNEL + /* KERNEL mode ignores CLINT addresses and use SBI timer. */ struct oneshot_lowerhalf_s *lower = riscv_mtimer_initialize( - K230_CLINT_MTIME, K230_CLINT_MTIMECMP, - RISCV_IRQ_MTIMER, MTIMER_FREQ); + K230_TIME, K230_TIMECMP, K230_IRQ_TIMER, K230_CLINT_FREQ); DEBUGASSERT(lower); - up_alarm_set_lowerhalf(lower); -#else - /* NOTE: This function is called in S-mode */ - - irq_attach(RISCV_IRQ_SSOFT, k230_ssoft_interrupt, NULL); - up_enable_irq(RISCV_IRQ_SSOFT); -#endif } - -#ifdef CONFIG_BUILD_KERNEL - -/**************************************************************************** - * Name: up_mtimer_initialize - * - * Description: - * This function is called during start-up to initialize the M-mode timer - * - ****************************************************************************/ - -void up_mtimer_initialize(void) -{ - uintptr_t irqstacktop = riscv_percpu_get_irqstack(); - - /* Set the irq stack base to mscratch */ - - WRITE_CSR(mscratch, - irqstacktop - STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK)); - - /* NOTE: we do not attach a handler for mtimer, - * because it is handled in the exception_m directly - */ - - up_enable_irq(RISCV_IRQ_MTIMER); - k230_reload_mtimecmp(); -} - -/**************************************************************************** - * Name: k230_mtimer_interrupt - * - * Description: - * In RISC-V with S-mode, M-mode timer must be handled in M-mode - * This function is called from exception_m in M-mode directly - * - ****************************************************************************/ - -void k230_mtimer_interrupt(void) -{ - uint64_t current; - uint64_t next; - - /* Update mtimercmp */ - - current = getreg64(K230_CLINT_MTIMECMP); - next = current + TICK_COUNT; - putreg64(next, K230_CLINT_MTIMECMP); - - g_mtimer_cnt++; - g_stimer_pending = true; - - if (OSINIT_HW_READY()) - { - /* Post Supervisor Software Interrupt */ - - SET_CSR(sip, SIP_SSIP); - } -} - -#endif /* CONFIG_BUILD_KERNEL */ diff --git a/boards/risc-v/k230/canmv230/configs/knsh/defconfig b/boards/risc-v/k230/canmv230/configs/knsh/defconfig new file mode 100644 index 00000000000..4679604e3a2 --- /dev/null +++ b/boards/risc-v/k230/canmv230/configs/knsh/defconfig @@ -0,0 +1,92 @@ +# +# 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_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_PATH_INITIAL="/system/bin" +CONFIG_RAM_SIZE=132116480 +CONFIG_RAM_START=0x8200000 +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=17 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2023 +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 diff --git a/boards/risc-v/k230/canmv230/configs/nsh/defconfig b/boards/risc-v/k230/canmv230/configs/nsh/defconfig index abbbd4ce183..4ba26d61b10 100644 --- a/boards/risc-v/k230/canmv230/configs/nsh/defconfig +++ b/boards/risc-v/k230/canmv230/configs/nsh/defconfig @@ -46,7 +46,7 @@ CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_READLINE=y CONFIG_PATH_INITIAL="/system/bin" -CONFIG_RAM_SIZE=134217728 +CONFIG_RAM_SIZE=134213632 CONFIG_RAM_START=0x8000000 CONFIG_RAW_BINARY=y CONFIG_READLINE_CMD_HISTORY=y diff --git a/boards/risc-v/k230/canmv230/include/board_memorymap.h b/boards/risc-v/k230/canmv230/include/board_memorymap.h index d2de8b3261c..4c5a5e09d39 100644 --- a/boards/risc-v/k230/canmv230/include/board_memorymap.h +++ b/boards/risc-v/k230/canmv230/include/board_memorymap.h @@ -31,23 +31,16 @@ * Pre-processor Definitions ****************************************************************************/ -/* DDR start address */ - -#define K230_DDR_BASE (0x8000000) -#define K230_DDR_SIZE (0x8000000) - /* Kernel code memory (RX) */ #define KFLASH_START (uintptr_t)__kflash_start #define KFLASH_SIZE (uintptr_t)__kflash_size -#define KSRAM_START (uintptr_t)__ksram_start -#define KSRAM_SIZE (uintptr_t)__ksram_size -#define KSRAM_END (uintptr_t)__ksram_end /* Kernel RAM (RW) */ -#define PGPOOL_START (uintptr_t)__pgheap_start -#define PGPOOL_SIZE (uintptr_t)__pgheap_size +#define KSRAM_START (uintptr_t)__ksram_start +#define KSRAM_SIZE (uintptr_t)__ksram_size +#define KSRAM_END (uintptr_t)__ksram_end /* Page pool (RWX) */ diff --git a/boards/risc-v/k230/canmv230/scripts/ld-kernel.script b/boards/risc-v/k230/canmv230/scripts/ld-kernel.script new file mode 100644 index 00000000000..745ead8bba5 --- /dev/null +++ b/boards/risc-v/k230/canmv230/scripts/ld-kernel.script @@ -0,0 +1,143 @@ +/**************************************************************************** + * boards/risc-v/k230/canmv230/scripts/ld-kernel.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 = 0x08200000, LENGTH = 2048K /* w/ cache */ + ksram (rwx) : ORIGIN = 0x08400000, LENGTH = 2048K /* w/ cache */ + pgram (rwx) : ORIGIN = 0x08600000, 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 +{ + . = 0x8200000; + + .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) } +} diff --git a/boards/risc-v/k230/canmv230/src/.gitignore b/boards/risc-v/k230/canmv230/src/.gitignore index 1baf09ba3ae..7c0a8cdf91b 100644 --- a/boards/risc-v/k230/canmv230/src/.gitignore +++ b/boards/risc-v/k230/canmv230/src/.gitignore @@ -1 +1,4 @@ -/etctmp* +etctmp/ +etctmp.c +romfs_boot.c + diff --git a/boards/risc-v/k230/canmv230/src/Makefile b/boards/risc-v/k230/canmv230/src/Makefile index b514e41ee0f..d73534315b4 100644 --- a/boards/risc-v/k230/canmv230/src/Makefile +++ b/boards/risc-v/k230/canmv230/src/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# boards/risc-v/k230/canmv-k230/src/Makefile +# boards/risc-v/k230/canmv230/src/Makefile # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -22,6 +22,10 @@ include $(TOPDIR)/Make.defs RCSRCS = etc/init.d/rc.sysinit etc/init.d/rcS -CSRCS = k230_appinit.c +CSRCS = canmv_init.c + +ifeq ($(CONFIG_BUILD_KERNEL),y) +CSRCS += $(wildcard romfs_*.c) +endif include $(TOPDIR)/boards/Board.mk diff --git a/boards/risc-v/k230/canmv230/src/k230_appinit.c b/boards/risc-v/k230/canmv230/src/canmv_init.c similarity index 85% rename from boards/risc-v/k230/canmv230/src/k230_appinit.c rename to boards/risc-v/k230/canmv230/src/canmv_init.c index f1c170db97f..9047d575193 100644 --- a/boards/risc-v/k230/canmv230/src/k230_appinit.c +++ b/boards/risc-v/k230/canmv230/src/canmv_init.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/risc-v/k230/canmv230/src/k230_appinit.c + * boards/risc-v/k230/canmv230/src/canmv_init.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -35,10 +36,19 @@ #include #include +#ifdef CONFIG_BUILD_KERNEL +#include "romfs.h" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#ifdef CONFIG_BUILD_KERNEL +#define SECTORSIZE 512 +#define NSECTORS(b) (((b) + SECTORSIZE - 1) / SECTORSIZE) +#endif /* CONFIG_BUILD_KERNEL */ + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -112,6 +122,25 @@ void board_late_initialize(void) { /* Perform board-specific initialization */ +#ifdef CONFIG_BUILD_KERNEL + /* Create ROM disk for mount in nx_start_application */ + + if (NSECTORS(romfs_img_len) > 5) + { + int ret = OK; + ret = romdisk_register(0, romfs_img, NSECTORS(romfs_img_len), + SECTORSIZE); + if (ret < 0) + { + serr("ERROR: Failed to register romfs: %d\n", -ret); + } + } + else + { + swarn("ROMFS too small: %d\n", NSECTORS(romfs_img_len)); + } +#endif /* CONFIG_BUILD_KERNEL */ + #ifdef CONFIG_NSH_ARCHINIT mount(NULL, "/proc", "procfs", 0, NULL); diff --git a/boards/risc-v/k230/canmv230/src/romfs.h b/boards/risc-v/k230/canmv230/src/romfs.h new file mode 100644 index 00000000000..4578780ffd8 --- /dev/null +++ b/boards/risc-v/k230/canmv230/src/romfs.h @@ -0,0 +1,39 @@ +/**************************************************************************** + * boards/risc-v/k230/canmv230/src/romfs.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_RISC_V_K230_CANMV230_SRC_ROMFS_H +#define __BOARDS_RISC_V_K230_CANMV230_SRC_ROMFS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +extern const unsigned char romfs_img[]; +extern const unsigned int romfs_img_len; + +#endif /* __BOARDS_RISC_V_K230_CANMV230_SRC_ROMFS_H */ diff --git a/boards/risc-v/k230/canmv230/src/romfs_stub.c b/boards/risc-v/k230/canmv230/src/romfs_stub.c new file mode 100644 index 00000000000..3ca1ec783bb --- /dev/null +++ b/boards/risc-v/k230/canmv230/src/romfs_stub.c @@ -0,0 +1,38 @@ +/**************************************************************************** + * boards/risc-v/k230/canmv230/src/romfs_stub.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 +weak_data const unsigned char aligned_data(4) romfs_img[] = +{ + 0x00 +}; +weak_data unsigned int romfs_img_len = 1; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/