Nuclei SDK快速入门指南

欢迎关注“安全有理”微信公众号。

安全有理

概述

**Nuclei Software Development Kit (SDK)**是芯来推出的开源软件平台,用来加速基于芯来处理器的开发。Nuclei SDK设计架构如下所示:

nuclei_sdk_diagram

本文的入门指南均以linux环境进行说明。

工具

安装Nuclei工具链,包括GCC编译器,OpenOCD以及QEMU模拟器。

芯来工具链

创建一个目录比如toolchains,解压上面下载的工具链,注意最终的路径需要类似如下:

${NUCLEI_TOOL_ROOT}
├── gcc
│   ├── bin
│   ├── build.txt
│   ├── gitrepo.txt
│   ├── include
│   ├── lib
│   ├── lib64
│   ├── libexec
│   ├── riscv64-unknown-elf
│   └── share
├── openocd
│   ├── OpenULINK
│   ├── README.md
│   ├── bin
│   ├── contrib
│   ├── distro-info
│   ├── scripts
│   └── share
└── qemu
    ├── bin
    ├── doc
    ├── include
    ├── libexec
    ├── readme.md
    ├── share
    └── var

SDK

下载nuclei-sdk,链接如下:

$ git clone https://github.com/Nuclei-Software/nuclei-sdk

在nuclei-sdk顶级目录下创建一个setup_config.sh脚本,内容为配置工具链的路径:

# This can be path to Nuclei Studio's toolchain folder
NUCLEI_TOOL_ROOT=/path/to/your_tool_root

然后创建nuclei-sdk的编译环境,执行成功会打印工具链跟目录:

$ source setup.sh
Setup Nuclei SDK Tool Environment
NUCLEI_TOOL_ROOT=/path/to/your_tool_root

查看工具链是否准备好:

$ which riscv64-unknown-elf-gcc openocd qemu-system-riscv64
/path/to/your_tool_root/gcc/bin/riscv64-unknown-elf-gcc
/path/to/your_tool_root/openocd/bin/openocd
/path/to/your_tool_root/qemu/bin/qemu-system-riscv64

Hello World

进入nuclei-sdk/application/baremetal/helloworld,可以执行make help查看帮助信息:

$ make help
Nuclei N/NX-series RISC-V Embedded Processor Software Development Kit 
== For detailed user guide, please check https://doc.nucleisys.com/nuclei_sdk/
== Make variables used in Nuclei SDK ==
SOC:         Select SoC built in Nuclei SDK, will select evalsoc by default
BOARD:       Select SoC's Board built in Nuclei SDK, will select nuclei_fpga_eval by default
CORE:        Not required for all SoCs, currently only evalsoc require it, n307fd by default
ARCH_EXT:    Not required for all SoCs, currently only evalsoc require it, such as ARCH_EXT=_zba_zbb_zbc_zbs_xxldspn3x, means B and Nuclei DSP(p v0.5.3) with N1/N2/N3 extension, please use >= gcc 13
DOWNLOAD:    Not required for all SoCs, use ilm by default, optional flashxip/ilm/flash/ddr
V:           V=1 verbose make, will print more information, by default V=0

支持SOCBOARDCORE等变量参数。

n305CORE为例,执行编译:

make CORE=n305 DOWNLOAD=ilm all
# Linking    :  helloworld.elf
#   text    data     bss     dec     hex filename
#   8756    1272    4592   14620    391c helloworld.elf

Qemu模拟

Nuclei QEMU是基于QEMU 8.x版本进行开发, 支持芯来demosocevalsoc的评估用SoC。QEMU分为qemu-system-riscv32qemu-system-riscv64,分别对应32位架构的CPU(如n200,n300,n600等系列),和64位架构的CPU(如nx600,nx900等系列)。

qemu常见的命令如下:

# 查看支持的机器类型
$ qemu-system-riscv64 -M ?
# 查看支持的cpu类型
$ qemu-system-riscv64 -M nuclei_evalsoc -cpu ?

模拟helloworld运行的命令如下:

$ qemu-system-riscv32 -M nuclei_evalsoc,download=ilm -cpu nuclei-n205,ext=_zca_zcb_zcmp_zcmt -smp 1 -icount shift=0 -nodefaults -nographic -serial stdio -kernel helloworld.elf

其中ext表示芯来支持的扩展。

启动成功的话会打印如下:

Nuclei SDK Build Time: Feb 23 2024, 10:42:28
Download Mode: ILM
CPU Frequency 999999078 Hz
CPU HartID: 0
Cluster 0, Hart 0, MISA: 0x40101105
MISA: RV32IMACU
Got rand integer 3278175 using seed 285701249.
0: Hello World From Nuclei RISC-V Processor!
1: Hello World From Nuclei RISC-V Processor!
……

GDB调试

对于qemu的调试,需要加上 -s -S,其含义为:

-S              freeze CPU at startup (use 'c' to start execution)
-s              shorthand for -gdb tcp::1234

调试hello world示例的命令如下:

$ qemu-system-riscv32 -M nuclei_evalsoc,download=ilm -cpu nuclei-n205,ext=_zca_zcb_zcmp_zcmt -smp 1 -icount shift=0 -nodefaults -nographic -serial stdio -kernel helloworld.elf -s -S

重新打开一个终端,连接tcp端口1234即可,通过riscv64-unknown-elf-gdb来进行调试。

$ riscv64-unknown-elf-gdb helloworld.elf

连接目标,开始调试:

(gdb) target remote localhost:1234
(gdb) b main
(gdb) c

gdb调试常用命令

命令功能
set disassemble-next-line on打开汇编显示
si汇编级别单步跳转
nC语言级别单步跳转
b设置断点
info register <register name>查看寄存器
info register all查看所有寄存器
  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值