Skip to content

Commit

Permalink
[bsp] add k230
Browse files Browse the repository at this point in the history
  • Loading branch information
heyuanjie87 authored Sep 26, 2024
1 parent 633d203 commit caac564
Show file tree
Hide file tree
Showing 26 changed files with 4,495 additions and 0 deletions.
1,360 changes: 1,360 additions & 0 deletions bsp/k230/.config

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions bsp/k230/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Build & install directories
build/
packages/
install/

rtthread.*

__pycache__
.config.old
46 changes: 46 additions & 0 deletions bsp/k230/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
mainmenu "RT-Thread Project Configuration"

config BSP_DIR
string
option env="BSP_ROOT"
default "."

config RTT_DIR
string
option env="RTT_ROOT"
default "../../rt-thread"

config PKGS_DIR
string
option env="PKGS_ROOT"
default "packages"

source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
rsource "board/Kconfig"

config BOARD_fpgac908
bool
select ARCH_RISCV64
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select RT_USING_CACHE
select ARCH_MM_MMU
select ARCH_RISCV_FPU_D
select ARCH_REMAP_KERNEL if RT_USING_SMART
default y

config __STACKSIZE__
int "stack size for interrupt"
default 4096

config C908_PLIC_PHY_ADDR
int "PLIC base address"
default 0xF00000000

config BSP_ROOTFS_TYPE_CROMFS
bool "Use CROMFS as ROOTFS"
select RT_USING_DFS_CROMFS
select PKG_USING_ZLIB
select PKG_USING_ZLIB_LATEST_VERSION
default y
38 changes: 38 additions & 0 deletions bsp/k230/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# rt-smart canaan porting

## 下载依赖的软件包

在软件包无需变更的情况下只须执行一次
```
source ~/.env/env.sh
pkgs --update
```

## 将根文件系统编译进内核

为了方便测试,这里将根文件系统制作成CROMFS格式转换成C代码编译进内核。

1.https://github.com/RT-Thread/userapps 页面下载riscv64预编译镜像
2. 解压后将其中的ext4.img挂载到一个目录中
```
sudo mount ext4.img dir
```
3. 删除其中一些不必要的文件以减小内核体积
```
du -ha # 查看文件大小
sudo rm -rf dir/www dir/usr/share/fonts dir/tc
```
4. 生成cromfs文件
工具位于 https://github.com/RT-Thread/userapps/tree/main/tools/cromfs
```
sudo ./cromfs-tool-x64 dir crom.img ./ # 将生成的cromfs_data.c放入applications目录
```

## 编译

```
export RTT_EXEC_PATH=/mnt/e/tools/riscv64gc/bin # 你自己的编译器路径
scons -j8
```
14 changes: 14 additions & 0 deletions bsp/k230/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# for module compiling
import os
from building import *

cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)

for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))

Return('objs')
37 changes: 37 additions & 0 deletions bsp/k230/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import sys
import rtconfig

from rtconfig import RTT_ROOT
import sys

sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *

TARGET = 'rtthread.' + rtconfig.TARGET_EXT

DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
env['ASCOM'] = env['ASPPCOM']

Export('RTT_ROOT')
Export('rtconfig')

# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)

stack_size = 4096

stack_lds = open('link_stacksize.lds', 'w')
if GetDepend('__STACKSIZE__'): stack_size = GetDepend('__STACKSIZE__')
stack_lds.write('__STACKSIZE__ = %d;' % stack_size)
stack_lds.close()

# make a building
DoBuilding(TARGET, objs)
9 changes: 9 additions & 0 deletions bsp/k230/applications/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from building import *

cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]

group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)

Return('group')
20 changes: 20 additions & 0 deletions bsp/k230/applications/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/

#include <rtthread.h>
#include <rthw.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
printf("Hello RISC-V\n");

return 0;
}
58 changes: 58 additions & 0 deletions bsp/k230/applications/mnt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <rtthread.h>

#ifdef RT_USING_DFS
#include <dfs_fs.h>

rt_weak uint8_t *cromfs_get_partition_data(uint32_t *len)
{
return RT_NULL;
}

static int mnt_cromfs(void)
{
uint32_t length = 0;
uint8_t *data = cromfs_get_partition_data(&length);
int ret = -1;

if (data && length)
{
ret = dfs_mount(NULL, "/", "crom", 0, data);
}

return ret;
}

int mnt_init(void)
{
rt_err_t ret;

ret = mnt_cromfs();
if (ret != RT_EOK)
{
rt_kprintf("CromFS mount failed!\n");
return ret;
}

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

if (dfs_mount(RT_NULL, "/dev/shm", "tmp", 0, 0) != 0)
{
rt_kprintf("Dir /dev/shm mount failed!\n");
}

#ifdef BSP_SD_SDIO_DEV
while (mmcsd_wait_cd_changed(100) != MMCSD_HOST_PLUGED)
;

if (dfs_mount(BSP_SD_MNT_DEVNAME, "/mnt", "elm", 0, 0) != 0)
{
rt_kprintf("Dir /mnt mount failed!\n");
}
#endif

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

return 0;
}
INIT_ENV_EXPORT(mnt_init);
#endif
38 changes: 38 additions & 0 deletions bsp/k230/board/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
menu "Drivers Configuration"

menuconfig BSP_USING_SDIO
bool "Enable SDIO"
select RT_USING_SDIO
default n

if BSP_USING_SDIO
config BSP_USING_SDIO0
bool "Enable SDIO0"
default n

if BSP_USING_SDIO0
config BSP_SDIO0_EMMC
bool "Enable eMMC"
default y

config BSP_SDIO0_1V8
bool "Enable 1.8V"
default y
endif

config BSP_USING_SDIO1
bool "Enable SDIO1"
default y

config BSP_SD_SDIO_DEV
int "SDIO device SdCard on"
range 0 1
default 1

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


endmenu
19 changes: 19 additions & 0 deletions bsp/k230/board/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# RT-Thread building script for component

from building import *

cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]

group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)

objs = [group]

list = os.listdir(cwd)

for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
objs = objs + SConscript(os.path.join(item, 'SConscript'))

Return('objs')
Loading

0 comments on commit caac564

Please sign in to comment.