Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
722 changes: 364 additions & 358 deletions bsp/k230/.config

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion bsp/k230/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@ source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
rsource "board/Kconfig"

choice
prompt "SoC variant"
default SOC_K230

config SOC_K230
bool "K230"

config SOC_K230D
bool "K230D (128MB DDR)"
endchoice

config BOARD_C908
bool
select ARCH_RISCV64
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select RT_USING_CACHE
select ARCH_MM_MMU
select ARCH_MM_MMU
select ARCH_RISCV_FPU
select ARCH_RISCV_XUANTIE
select ARCH_REMAP_KERNEL if RT_USING_SMART
default y

Expand All @@ -33,6 +45,10 @@ choice BSP_ROOTFS_TYPE
bool "Use Elm-chan FAT File-System"
select RT_USING_DFS_ELMFAT

config BSP_ROOTFS_TYPE_EXT4
bool "Use Ext4 File-System"
select PKG_USING_LWEXT4

config BSP_ROOTFS_TYPE_CROMFS
bool "Use Compressed ROM File-System (ReadOnly)"
select RT_USING_DFS_CROMFS
Expand Down
6 changes: 2 additions & 4 deletions bsp/k230/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ TARGET = 'rtthread.' + rtconfig.TARGET_EXT
options = LocalOptions("rtconfig.h")
soft_fpu = GetLocalDepend(options, 'BSP_RISCV_FPU_SOFT')
if soft_fpu:
rtconfig.DEVICE = rtconfig.DEVICE.replace('-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64')
rtconfig.CFLAGS = rtconfig.CFLAGS.replace('-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64')
rtconfig.LFLAGS = rtconfig.LFLAGS.replace('-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64')
rtconfig.AFLAGS = rtconfig.AFLAGS.replace('-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64')
for name in ('DEVICE', 'CFLAGS', 'LFLAGS', 'AFLAGS'):
setattr(rtconfig, name, getattr(rtconfig, name).replace('-march=rv64imafdcv', '-march=rv64imafdc'))

DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
Expand Down
67 changes: 52 additions & 15 deletions bsp/k230/applications/mnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,51 @@ static int mnt_cromfs(void)
}
#endif

#ifdef RT_USING_DFS_PTYFS
static int mnt_ptyfs(void)
{
mkdir("/dev/pts", 0755);

if (dfs_mount(RT_NULL, "/dev/pts", "ptyfs", 0, RT_NULL) != RT_EOK)
{
rt_kprintf("ptyfs mounted on /dev/pts failed!\n");
return -RT_ERROR;
}

rt_kprintf("ptyfs mounted on /dev/pts success!\n");
return RT_EOK;
}
#endif

int mnt_init(void)
{
#if defined(BSP_USING_SDIO) && defined(BSP_ROOTFS_TYPE_ELMFAT)
int timeout = 50; // Timeout after 50 iterations (5 seconds if each iteration waits 100ms)
#if defined(BSP_USING_SDIO) && \
(defined(BSP_ROOTFS_TYPE_ELMFAT) || defined(BSP_ROOTFS_TYPE_EXT4))
int timeout = 50;
const char *filesystem;

#ifdef BSP_ROOTFS_TYPE_EXT4
filesystem = "ext";
#else
filesystem = "elm";
#endif

while (mmcsd_wait_cd_changed(100) != MMCSD_HOST_PLUGED)
{
if (--timeout <= 0)
{
rt_kprintf("Timeout waiting for MMCSD host to be plugged!\n");
return -1; // Return an error code to indicate failure
return -1;
}
rt_thread_mdelay(100); // Yield to the scheduler
rt_thread_mdelay(100);
}

if (dfs_mount(BSP_SD_MNT_DEVNAME, "/", "elm", 0, 0) != 0)
if (dfs_mount(BSP_SD_MNT_DEVNAME, "/", filesystem, 0, 0) != 0)
{
rt_kprintf("%s mounted on / failed!\n", BSP_SD_MNT_DEVNAME);
}
else {
else
{
rt_kprintf("%s mounted on / success!\n", BSP_SD_MNT_DEVNAME);
}
#endif
Expand All @@ -62,20 +88,31 @@ int mnt_init(void)
}
#endif

mkdir("/dev/shm", 0x777);

if (dfs_mount(RT_NULL, "/dev/shm", "tmp", 0, 0) != 0)
{
rt_kprintf("tmpfs mounted on /dev/shm failed!\n");
}
else {
rt_kprintf("tmpfs mounted on /dev/shm success!\n");
}
#ifdef RT_USING_DFS_PTYFS
(void)mnt_ptyfs();
#endif

rt_kprintf("file system initialization done!\n");

return 0;
}
INIT_ENV_EXPORT(mnt_init);

#if defined(RT_USING_DFS_PROCFS) && !defined(RT_USING_DM)
static int mnt_procfs(void)
{
mkdir("/proc", 0755);

if (dfs_mount(RT_NULL, "/proc", "procfs", 0, RT_NULL) != RT_EOK)
{
rt_kprintf("procfs mounted on /proc failed!\n");
return -RT_ERROR;
}

rt_kprintf("procfs mounted on /proc success!\n");
return RT_EOK;
}
INIT_FS_EXPORT(mnt_procfs);
#endif

#endif /* RT_USING_DFS */
7 changes: 6 additions & 1 deletion bsp/k230/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ menu "Drivers Configuration"
bool "Enable KPU and AI2D"
default n

config BSP_USING_GPIO
bool "Enable GPIO"
select RT_USING_PIN
default n

menuconfig BSP_USING_SPI
bool "Enable SPI"
select RT_USING_SPI
Expand Down Expand Up @@ -160,7 +165,7 @@ menu "Drivers Configuration"

config BSP_SD_MNT_DEVNAME
string "The name of the SD-BlkDev to be mounted"
default "sd0p1"
default "sd0p0"
endif

menuconfig BSP_USING_TIMERS
Expand Down
22 changes: 10 additions & 12 deletions bsp/k230/board/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ extern unsigned int __bss_end;
#define RT_HW_PAGE_END ((void *)(RAM_END))

#ifdef RT_USING_SMART

rt_region_t init_page_region = {(rt_size_t)RT_HW_PAGE_START, (rt_size_t)RT_HW_PAGE_END};

extern size_t MMUTable[];

struct mem_desc platform_mem_desc[] = {
{KERNEL_VADDR_START, (rt_size_t)(KERNEL_VADDR_START + CONFIG_MEM_MMZ_BASE + CONFIG_MEM_MMZ_SIZE - 1), (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM},
};

#define NUM_MEM_DESC (sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]))

#endif /* RT_USING_SMART */

#ifndef ARCH_REMAP_KERNEL
Expand All @@ -76,34 +73,35 @@ static void __rt_assert_handler(const char *ex_string, const char *func, rt_size
asm volatile("ebreak":::"memory");
}

//BSP的C入口
/* C entry point, this gets called on primary CPU after stack setup. */
void primary_cpu_entry(void)
{
//关中断
rt_hw_interrupt_disable();

#ifdef RT_DEBUGING_ASSERT
rt_assert_set_hook(__rt_assert_handler);
//启动RT-Thread Smart内核
#endif

entry();
}

#define IOREMAP_SIZE (1ul << 30)

//这个初始化程序由内核主动调用,此时调度器还未启动,因此在此不能使用依赖线程上下文的函数
/*
* This function is called by the kernel during initialization. At this point,
* the scheduler has not started, so functions that depend on thread context
* cannot be used.
*/
void rt_hw_board_init(void)
{
#ifdef RT_USING_SMART
/* init data structure */
rt_hw_mmu_map_init(&rt_kernel_space, (void *)(IOREMAP_VEND - IOREMAP_SIZE), IOREMAP_SIZE, (rt_size_t *)MMUTable, PV_OFFSET);

/* init page allocator */
rt_page_init(init_page_region);

/* setup region, and enable MMU */
rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, NUM_MEM_DESC);
#endif

#ifdef RT_USING_HEAP
/* initialize memory system */
rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
#endif
/* initalize interrupt */
Expand Down
65 changes: 0 additions & 65 deletions bsp/k230/board/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
*
* See K230 Technical Reference Manual, chapter 1.5 Address Space mapping
*/
#define SRAM_BASE_ADDR (0x80200000UL)
#define SRAM_IO_SIZE (0x00200000UL)

#define KPU_BASE_ADDR (0x80400000UL)
#define KPU_IO_SIZE (0x00000800UL)

Expand All @@ -32,43 +29,15 @@
#define AI2D_BASE_ADDR (0x80400C00UL)
#define AI2D_IO_SIZE (0x00000400UL)

#define GSDMA_BASE_ADDR (0x80800000UL)
#define GSDMA_IO_SIZE (0x00004000UL)

#define DMA_BASE_ADDR (0x80804000UL)
#define DMA_IO_SIZE (0x00004000UL)

#define DECOMP_BASE_ADDR (0x80808000UL)
#define DECOMP_IO_SIZE (0x00004000UL)

#define NON_AI2D_BASE_ADDR (0x8080C000UL)
#define NON_AI2D_IO_SIZE (0x00004000UL)

#define ISP_BASE_ADDR (0x90000000UL)
#define ISP_IO_SIZE (0x00008000UL)

#define DEWARP_BASE_ADDR (0x90008000UL)
#define DEWARP_IO_SIZE (0x00001000UL)

#define CSI_BASE_ADDR (0x90009000UL)
#define CSI_IO_SIZE (0x00002000UL)

#define VPU_BASE_ADDR (0x90400000UL)
#define VPU_IO_SIZE (0x00010000UL)

/*2.5D*/
#define TAAH_GPU_BASE_ADDR (0x90800000UL)
#define TAAH_GPU_IO_SIZE (0x00040000UL)

#define VO_BASE_ADDR (0x90840000UL)
#define VO_IO_SIZE (0x00010000UL)

#define DSI_BASE_ADDR (0x90850000UL)
#define DSI_IO_SIZE (0x00001000UL)

#define GPU_ENGINE_BASE_ADDR (0x90A00000UL)
#define GPU_ENGINE_IO_SIZE (0x00000800UL)

#define PMU_BASE_ADDR (0x91000000UL)
#define PMU_IO_SIZE (0x00000C00UL)

Expand Down Expand Up @@ -105,18 +74,9 @@
#define TS_BASE_ADDR (0x91107000UL)
#define TS_IO_SIZE (0x00000800UL)

#define HDI_BASE_ADDR (0x91107800UL)
#define HDI_IO_SIZE (0x00000800UL)

#define STC_BASE_ADDR (0x91108000UL)
#define STC_IO_SIZE (0x00001000UL)

#define BOOTROM_BASE_ADDR (0x91200000UL)
#define BOOTROM_IO_SIZE (0x00010000UL)

#define SECURITY_BASE_ADDR (0x91210000UL)
#define SECURITY_IO_SIZE (0x00008000UL)

#define UART0_BASE_ADDR (0x91400000UL)
#define UART0_IO_SIZE (0x00001000UL)

Expand Down Expand Up @@ -159,35 +119,10 @@
#define ADC_BASE_ADDR (0x9140D000UL)
#define ADC_IO_SIZE (0x00001000UL)

#define CODEC_BASE_ADDR (0x9140E000UL)
#define CODEC_IO_SIZE (0x00001000UL)

#define AUDIO_BASE_ADDR (0x9140F000UL)
#define AUDIO_IO_SIZE (0x00001000UL)

#define USB2_BASE_ADDR (0x91500000UL)
#define USB2_IO_SIZE (0x00080000UL)

#define SD_HC_BASE_ADDR (0x91580000UL)
#define SD_HC_IO_SIZE (0x00002000UL)

#define SPI_QOPI_BASE_ADDR (0x91582000UL)
#define SPI_QOPI_IO_SIZE (0x00002000UL)

#define SPI_OPI_BASE_ADDR (0x91584000UL)
#define SPI_OPI_IO_SIZE (0x00001000UL)

#define HI_SYS_CONFIG_BASE_ADDR (0x91585000UL)
#define HI_SYS_CONFIG_IO_SIZE (0x00000400UL)

#define DDRC_CONF_BASE_ADDR (0x98000000UL)
#define DDRC_CONF_IO_SIZE (0x02000000UL)

#define SPI_XIP_FLASH_BASE_ADDR (0xC0000000UL)
#define SPI_XIP_FLASH_IO_SIZE (0x08000000UL)

#define IO_SPACE_BASE_ADDR (KPU_BASE_ADDR)

#define TIMER_CLK_FREQ (27000000)

#endif // BOARD_H__
25 changes: 15 additions & 10 deletions bsp/k230/board/mem_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* | ...... | maybe zero
* +---------+ <- CONFIG_MEM_RTSMART_SIZE
* | guard | MEM_GUARD_SIZE
* +---------+ <- End of Kerenl
* +---------+ <- End of Kernel
* | |
* | |
* +---------+
Expand All @@ -47,30 +47,35 @@
* the SDK configuration.
*
* If CONFIG_XXX is defined, it means that the value comes from the SDK
* configuration, otherwise the default configuration of bsp/k230 in RT-Thead
* is used. The default configuration of bsp/k230 is for the 01Studio CanMV
* development board that supports 512MB of memory.
* configuration, otherwise the default configuration defined in this file
* is used.
*/

#if !defined(SOC_K230) && !defined(SOC_K230D)
#error "Either SOC_K230 or SOC_K230D must be defined"
#endif

/* Standalone defaults for K230 and K230D boards with 128MB DDR. */
#ifndef CONFIG_MEM_TOTAL_SIZE
#define CONFIG_MEM_TOTAL_SIZE 0x20000000 // 512M
#define CONFIG_MEM_TOTAL_SIZE 0x8000000 // 128M
#endif

#ifndef CONFIG_MEM_RTSMART_SIZE
#define CONFIG_MEM_RTSMART_SIZE 0x10000000 // 256M
#define CONFIG_MEM_RTSMART_SIZE 0x3A00000 // 58M
#endif

#ifndef CONFIG_MEM_RTSMART_HEAP_SIZE
#define CONFIG_MEM_RTSMART_HEAP_SIZE 0x2000000 // 32M
#define CONFIG_MEM_RTSMART_HEAP_SIZE 0x800000 // 8M
#endif

#ifndef CONFIG_MEM_MMZ_BASE
#define CONFIG_MEM_MMZ_BASE 0x10000000 // 512M
#define CONFIG_MEM_MMZ_BASE 0x3A00000 // 58M
#endif

#ifndef CONFIG_MEM_MMZ_SIZE
#define CONFIG_MEM_MMZ_SIZE 0x10000000 // 256M
#define CONFIG_MEM_MMZ_SIZE 0x4600000 // 70M
#endif

#define MEM_KERNEL_SIZE (CONFIG_MEM_RTSMART_SIZE - MEM_OPENSBI_SIZE - MEM_GUARD_SIZE)

#endif // MEMORY_LAYOUT_H__
#endif // MEMORY_LAYOUT_H__
Loading
Loading