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
32 changes: 19 additions & 13 deletions bsp/allwinner/d1/.config
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ CONFIG_RT_USING_DEVICE_OPS=y
# CONFIG_RT_USING_THREADSAFE_PRINTF is not set
CONFIG_RT_USING_CONSOLE=y
CONFIG_RT_CONSOLEBUF_SIZE=256
CONFIG_RT_CONSOLE_DEVICE_NAME="uart"
CONFIG_RT_CONSOLE_DEVICE_NAME="uart0"
CONFIG_RT_USING_CONSOLE_OUTPUT_CTL=y
CONFIG_RT_VER_NUM=0x50300
CONFIG_RT_USING_STDC_ATOMIC=y
Expand All @@ -201,7 +201,7 @@ CONFIG_RT_BACKTRACE_LEVEL_MAX_NR=32
CONFIG_ARCH_CPU_64BIT=y
CONFIG_RT_USING_CACHE=y
CONFIG_ARCH_MM_MMU=y
CONFIG_KERNEL_VADDR_START=0x150000000
CONFIG_KERNEL_VADDR_START=0x45000000
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_RISCV_FPU=y
CONFIG_ARCH_RISCV_FPU_D=y
Expand Down Expand Up @@ -290,12 +290,7 @@ CONFIG_RT_PAGECACHE_GC_STOP_LEVEL=70
# end of page cache config
# end of DFS: device virtual file system

CONFIG_RT_USING_FAL=y
CONFIG_FAL_USING_DEBUG=y
CONFIG_FAL_PART_HAS_TABLE_CFG=y
# CONFIG_FAL_USING_SFUD_PORT is not set
CONFIG_FAL_DEV_NAME_MAX=24
CONFIG_FAL_DEV_BLK_MAX=6
# CONFIG_RT_USING_FAL is not set

#
# Device Drivers
Expand All @@ -308,10 +303,11 @@ CONFIG_RT_USING_SYSTEM_WORKQUEUE=y
CONFIG_RT_SYSTEM_WORKQUEUE_STACKSIZE=8192
CONFIG_RT_SYSTEM_WORKQUEUE_PRIORITY=23
CONFIG_RT_USING_SERIAL=y
CONFIG_RT_USING_SERIAL_V1=y
# CONFIG_RT_USING_SERIAL_V2 is not set
CONFIG_RT_SERIAL_USING_DMA=y
CONFIG_RT_SERIAL_RB_BUFSZ=64
# CONFIG_RT_USING_SERIAL_V1 is not set
CONFIG_RT_USING_SERIAL_V2=y
# CONFIG_RT_SERIAL_BUF_STRATEGY_DROP is not set
CONFIG_RT_SERIAL_BUF_STRATEGY_OVERWRITE=y
# CONFIG_RT_SERIAL_USING_DMA is not set
CONFIG_RT_USING_SERIAL_BYPASS=y
# CONFIG_RT_USING_CAN is not set
CONFIG_RT_USING_CLOCK_TIME=y
Expand Down Expand Up @@ -1641,6 +1637,7 @@ CONFIG_BOARD_allwinnerd1=y
CONFIG_ENABLE_FPU=y
# CONFIG_RT_USING_USERSPACE_32BIT_LIMIT is not set
CONFIG___STACKSIZE__=16384
CONFIG_BSP_UART_DEFAULT_BAUDRATE=115200

#
# General Drivers Configuration
Expand Down Expand Up @@ -1728,7 +1725,16 @@ CONFIG_DRIVERS_GPIO=y
#
# SDMMC Devices
#
# CONFIG_DRIVERS_SDMMC is not set
CONFIG_DRIVERS_SDMMC=y
CONFIG_USE_SD=y
CONFIG_USE_SDIO=y
# CONFIG_USE_MMC is not set
CONFIG_DETECT_CARD=y
CONFIG_SDC_DMA_USED=y
CONFIG_SDIO_IRQ_SUPPORT=y
# CONFIG_SD_TEST is not set
CONFIG_SDC_DMA_BUF_SIZE=64
CONFIG_DRIVERS_SDC_CDPIN_PRESENT_VAL=0
# end of SDMMC Devices

#
Expand Down
4 changes: 4 additions & 0 deletions bsp/allwinner/d1/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ config __STACKSIZE__
int "stack size for interrupt"
default 4096

config BSP_UART_DEFAULT_BAUDRATE
int "Default UART baud rate"
default 115200

rsource "../libraries/drivers/Kconfig"
rsource "../libraries/Kconfig"
27 changes: 23 additions & 4 deletions bsp/allwinner/d1/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# RT-Thread全志D1移植

全志 d1-allwinner-nezha 属于 riscv64 平台
全志 D1 是采用玄铁 C906 RV64 处理器的 RISC-V SoC。本 BSP 已在
Sipeed Lichee RV 86 Panel 类 D1 硬件上验证 RT-Smart 启动和交互式
`msh />` shell。

## 编译环境搭建
## 硬件配置

- SoC:Allwinner D1
- CPU:T-Head/XuanTie C906 RV64
- 验证板卡:Sipeed Lichee RV 86 Panel 类 D1 板卡
- 控制台:UART0,115200 8N1
- 内核加载地址:`0x45000000`

## 编译环境

- 拉取 RT-Thread Smart的代码仓库 `git clone https://gitee.com/guozhanxin/rtthread-smart.git`

Expand Down Expand Up @@ -36,10 +46,19 @@

## 开发与编译

- windows 下使用RT-Thread ENV 工具, `menuconfig` 配置工程,`scons` 编译工程
- windows 下使用 RT-Thread ENV 工具,`menuconfig` 配置工程,`scons` 编译工程

- ubuntu 下 使用shell 终端: `scons --menuconfig` 配置工程, `scons` 编译工程
- Linux 下进入本 BSP 目录,设置包含
`riscv64-unknown-linux-musl-` 工具链的目录后编译:

```sh
cd bsp/allwinner/d1
RTT_EXEC_PATH=/path/to/riscv64-musl-toolchain/bin scons -j
sh generateimg.sh
```

生成的 `rtthread.img` 是加载地址和入口地址均为 `0x45000000` 的
U-Boot legacy kernel image。

## 下载验证

Expand Down
12 changes: 5 additions & 7 deletions bsp/allwinner/d1/applications/mnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

int mnt_init(void)
{

rt_thread_mdelay(200);

if (dfs_mount("boot", "/", "elm", 0, 0) != 0)
if (dfs_mount(RT_NULL, "/", "rom", 0, &romfs_root) != 0)
{
rt_kprintf("Dir /boot mount failed!\n");
rt_kprintf("Mount ROMFS on \"/\" failed!\n");
return -RT_ERROR;
}

rt_kprintf("file system initialization done!\n");
return 0;
rt_kprintf("Mount ROMFS on \"/\" success.\n");
return RT_EOK;
}
INIT_ENV_EXPORT(mnt_init);
#endif
58 changes: 44 additions & 14 deletions bsp/allwinner/d1/board/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <rtdevice.h>

#include "board.h"
#include "mm_aspace.h"
#include "tick.h"

#include "drv_uart.h"
Expand Down Expand Up @@ -41,11 +42,39 @@
};

//内核页表
volatile rt_size_t MMUTable[__SIZE(VPN2_BIT)] __attribute__((aligned(4 * 1024)));
rt_mmu_info mmu_info;
extern volatile rt_size_t MMUTable[__SIZE(VPN2_BIT)] __attribute__((aligned(4 * 1024)));

struct mem_desc platform_mem_desc[] =
{
{KERNEL_VADDR_START,
KERNEL_VADDR_START + 0x8000000 - 1,
(rt_size_t)ARCH_MAP_FAILED,
NORMAL_MEM},
{0x1000,
0x3ffff000 - 1,
(rt_size_t)ARCH_MAP_FAILED,
DEVICE_MEM},
};

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

#endif

#define D1_RISCV_WDT_MODE ((volatile rt_uint32_t *)0x06011018UL)
#define D1_RISCV_WDT_KEY 0x16aa0000U

static void d1_disable_inherited_watchdog(void)
{
/* Some bootloaders leave the RISC-V subsystem watchdog running. */
*D1_RISCV_WDT_MODE = D1_RISCV_WDT_KEY;
rt_hw_dsb();
}

rt_uint64_t rt_hw_get_clock_timer_freq(void)
{
return 24000000ULL;
}

//初始化BSS节区
void init_bss(void)
{
Expand All @@ -67,39 +96,38 @@ static void __rt_assert_handler(const char *ex_string, const char *func, rt_size
//BSP的C入口
void primary_cpu_entry(void)
{
//初始化BSS
init_bss();
//关中断
rt_hw_interrupt_disable();
rt_assert_set_hook(__rt_assert_handler);
//启动RT-Thread Smart内核
entry();
}

#define IOREMAP_SIZE (1ul << 30)

//这个初始化程序由内核主动调用,此时调度器还未启动,因此在此不能使用依赖线程上下文的函数
void rt_hw_board_init(void)
{
#ifdef RT_USING_SMART
rt_hw_mmu_map_init(&rt_kernel_space,
(void *)(USER_VADDR_START - IOREMAP_SIZE),
IOREMAP_SIZE,
(rt_size_t *)MMUTable,
0);
rt_page_init(init_page_region);
rt_hw_mmu_map_init(&mmu_info,(void *)USER_VADDR_START, USER_VADDR_TOP - USER_VADDR_START, (rt_size_t *)MMUTable, 0);
//将低1GB MMIO区域设置为无Cache与Strong Order访存模式
MMUTable[0] &= ~PTE_CACHE;
MMUTable[0] &= ~PTE_SHARE;
MMUTable[0] |= PTE_SO;
rt_hw_mmu_switch((void *)MMUTable);
rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, NUM_MEM_DESC);
#endif
/* initalize interrupt */
rt_hw_interrupt_init();
d1_disable_inherited_watchdog();
#ifdef RT_USING_HEAP
rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t) RT_HW_HEAP_BEGIN, (rt_ubase_t) RT_HW_HEAP_END);
/* initialize memory system */
rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
#endif
/* initalize interrupt */
rt_hw_interrupt_init();
/* init hal hardware */
hal_clock_init();
hal_gpio_init();
hal_uart_init(0);
hal_dma_init();

/* init rtthread hardware */
Expand All @@ -108,17 +136,19 @@ void rt_hw_board_init(void)

#ifdef RT_USING_CONSOLE
/* set console device */
rt_console_set_device("uart");
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif /* RT_USING_CONSOLE */

#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
}

#if !defined(RT_USING_WDT) || !defined(BSP_USING_WDT)
void rt_hw_cpu_reset(void)
{
sbi_shutdown();
while(1);
}
MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);
#endif
3 changes: 3 additions & 0 deletions bsp/allwinner/d1/link.lds
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SECTIONS
. = 0x45000000 ;

/* __STACKSIZE__ = 4096; */
__text_start = .;

.start :
{
Expand Down Expand Up @@ -82,6 +83,8 @@ SECTIONS
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } > SRAM

. = ALIGN(8);
__text_end = .;
__text_size = __text_end - __text_start;

.data :
{
Expand Down
12 changes: 12 additions & 0 deletions bsp/allwinner/d1/ports/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
from building import *

objs = []
cwd = GetCurrentDir()
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')
11 changes: 11 additions & 0 deletions bsp/allwinner/d1/ports/partition/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from building import *
import rtconfig

cwd = GetCurrentDir()

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

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

Return('group')
Loading
Loading