diff --git a/CMakeLists.txt b/CMakeLists.txt
index 383820fd65f3c959a03ea834a119485621be4921..f163d9a6c0cc2bd1ecb4e1fe5e7fb9e299ee01a0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -60,6 +60,7 @@ add_subdirectory(sdr)
add_subdirectory(system)
add_subdirectory(testing)
add_subdirectory(wireless)
+add_subdirectory(phytium_examples)
# add examples and external at the end to allow library dependencies
add_subdirectory(examples)
diff --git a/phytium_examples/.gitignore b/phytium_examples/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..9e1d2593ee8d4c0ff219286bb0a35ef3b7d2c9ba
--- /dev/null
+++ b/phytium_examples/.gitignore
@@ -0,0 +1 @@
+/Kconfig
diff --git a/phytium_examples/CMakeLists.txt b/phytium_examples/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..569b0e492d2815b310643fd8451d3ad103b4774c
--- /dev/null
+++ b/phytium_examples/CMakeLists.txt
@@ -0,0 +1,22 @@
+# ##############################################################################
+# apps/phytium_examples/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+nuttx_add_subdirectory()
+nuttx_generate_kconfig(MENUDESC "Phytium Examples")
diff --git a/phytium_examples/Make.defs b/phytium_examples/Make.defs
new file mode 100644
index 0000000000000000000000000000000000000000..8944e75a3a403b2c2b9128b03199612091e3e0fb
--- /dev/null
+++ b/phytium_examples/Make.defs
@@ -0,0 +1,21 @@
+############################################################################
+# apps/phytium_examples/Make.defs
+#
+# 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.
+#
+############################################################################
+
+include $(wildcard $(APPDIR)/phytium_examples/*/Make.defs)
diff --git a/phytium_examples/Makefile b/phytium_examples/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..d4630d51ae0dea969147727cdc228e7f6824a674
--- /dev/null
+++ b/phytium_examples/Makefile
@@ -0,0 +1,23 @@
+############################################################################
+# apps/phytium_examples/Makefile
+#
+# 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.
+#
+############################################################################
+
+MENUDESC = "Phytium Examples"
+
+include $(APPDIR)/Directory.mk
diff --git a/phytium_examples/README.md b/phytium_examples/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..832d7a6e12b6d629f3d9494fa9c9baf46554894b
--- /dev/null
+++ b/phytium_examples/README.md
@@ -0,0 +1,45 @@
+# Phytium Examples
+
+## 1. 目录介绍
+
+> ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作 `
`
+
+本目录基于apps目录下成熟的应用程序,通过修改完善,实现phytium soc板卡的接口测试。
+
+| 目录 | 例程 |
+| ------- | ---------------------------- |
+| nsh | up nuttx shell演示 |
+| nsh_smp | smp nuttx shell演示 |
+| net | 网络接口测试 |
+| nxffs | spi flash的nxffs文件系统测试 |
+| sd | sd卡的fatfs文件系统测试 |
+| gpio | gpio测试 |
+
+## 2. 如何使用例程
+
+> ``描述开发平台准备,使用例程配置,构建和下载镜像的过程 `
`
+
+本例程需要以下硬件,
+
+- E2000D/Q Demo 板, PhytiumPi开发板
+- 串口线和串口上位机
+
+### 2.1 硬件配置方法
+
+> ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
`
+
+### 2.2 SDK配置方法
+
+> ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
`
+
+### 2.3 构建和下载
+
+> ``描述构建、烧录下载镜像的过程,列出相关的命令 `
`
+
+## 3. 如何解决问题
+
+> ``主要记录使用例程中可能会遇到的问题,给出相应的解决方案 `
`
+
+## 4. 修改历史记录
+
+> ``记录例程的重大修改记录,标明修改发生的版本号 `
`
diff --git a/phytium_examples/gpio/README.md b/phytium_examples/gpio/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..2f8ec9a5c209826e25f9e7a2ca4955c9b5e25dd7
--- /dev/null
+++ b/phytium_examples/gpio/README.md
@@ -0,0 +1,89 @@
+# gpio例程
+
+## 1. 例程介绍
+
+> ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作 `
`
+
+gpio例程基于e2000 demo板,使用apps/examples/gpio例程,实现e2000 demo板的gpio测试。
+将GPIO 4-A-12作为输出脚(J30-PIN10),GPIO 4-A-11作为输入脚(J30-PIN8)进行测试。
+
+## 2. 如何使用例程
+
+> ``描述开发平台准备,使用例程配置,构建和下载镜像的过程 `
`
+
+本例程需要以下硬件,
+
+- E2000D/Q Demo 板
+- 串口线和串口上位机
+- 万用表
+
+### 2.1 硬件配置方法
+
+> ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
`
+
+### 2.2 SDK配置方法
+
+> ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
`
+
+- 本例子已经提供好具体的编译指令,以下进行介绍:
+
+ 1. 进入phytium-nuttx-sdk/nuttx目录
+ 2. `make distclean` 清理当前配置文件
+ 3. `./tools/configure.sh -l e2000d_demo:gpio` 加载e2000d_demo板的gpio配置
+ 4. `make menuconfig` 配置目录下的参数,本步骤可忽略
+ 5. `make -j` 编译nuttx镜像
+- 具体使用方法为:
+
+ - 在当前目录下
+ - 执行以上指令
+
+### 2.3 构建和下载
+
+> ``描述构建、烧录下载镜像的过程,列出相关的命令 `
`
+
+- 参见 `NuttX 系统镜像加载方法`章节
+ [NuttX 系统镜像加载方法](../../../docs/compile_nuttx.md)
+
+### 2.4 输出与实验现象
+
+> ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
`
+
+#### 2.4.1 存在gpio命令
+
+```
+$ help
+```
+
+
+
+#### 2.4.2 存在/dev/gpio设备节点
+
+查看gpio节点,gpio0为输入脚,gpio1为输出脚
+
+```
+$ ls /dev
+```
+
+
+
+#### 2.4.3 执行gpio测试指令
+
+拉低输出脚,使用万用表测量,电压是0V
+
+```
+$ gpio -o 0 /dev/gpio1
+```
+
+拉高输出脚,使用万用表测量,电压是1.8V
+
+```
+$ gpio -o 1 /dev/gpio1
+```
+
+## 3. 如何解决问题
+
+> ``主要记录使用例程中可能会遇到的问题,给出相应的解决方案 `
`
+
+## 4. 修改历史记录
+
+> ``记录例程的重大修改记录,标明修改发生的版本号 `
`
diff --git a/phytium_examples/gpio/figs/dev.png b/phytium_examples/gpio/figs/dev.png
new file mode 100644
index 0000000000000000000000000000000000000000..aea09b2361ef41b239e06ab2d8d3076f60032fe9
Binary files /dev/null and b/phytium_examples/gpio/figs/dev.png differ
diff --git a/phytium_examples/gpio/figs/help.png b/phytium_examples/gpio/figs/help.png
new file mode 100644
index 0000000000000000000000000000000000000000..37f63fe52185635c2990817bd5b28f27f2249fd6
Binary files /dev/null and b/phytium_examples/gpio/figs/help.png differ
diff --git a/phytium_examples/net/README.md b/phytium_examples/net/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..381bf06b4c05d182cd2662d3da0cd317c12ed83d
--- /dev/null
+++ b/phytium_examples/net/README.md
@@ -0,0 +1,91 @@
+# 网络例程
+
+## 1. 例程介绍
+
+> ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作 `
`
+
+网络测试例程基于e2000 demo板,使用apps/system/ping例程增加nsh ping指令,使用apps/netutils/netinit例程进行ip的初始化设置,实现e2000 demo板的网络测试。
+
+## 2. 如何使用例程
+
+> ``描述开发平台准备,使用例程配置,构建和下载镜像的过程 `
`
+
+本例程需要以下硬件,
+
+- E2000D/Q Demo 板
+- 网线、串口线和串口上位机
+
+### 2.1 硬件配置方法
+
+> ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
`
+
+E2000 demo 板网口外接上位机,板卡默认ip配置是 `192.168.4.10`,需要设置上位机ip地址为同一网段,比如 `192.168.4.50`
+
+### 2.2 SDK配置方法
+
+> ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
`
+
+- 本例子已经提供好具体的编译指令,以下进行介绍:
+
+ 1. 进入phytium-nuttx-sdk/nuttx目录
+ 2. `make distclean` 清理当前配置文件
+ 3. `./tools/configure.sh -l e2000d_demo:net` 加载e2000d_demo板的net配置
+ 4. `make menuconfig` 配置目录下的参数,本步骤可忽略
+ 5. `make -j` 编译nuttx镜像
+- 具体使用方法为:
+
+ - 在当前目录下
+ - 执行以上指令
+
+### 2.3 构建和下载
+
+> ``描述构建、烧录下载镜像的过程,列出相关的命令 `
`
+
+- 参见 `NuttX 系统镜像加载方法`章节
+ [NuttX 系统镜像加载方法](../../../docs/compile_nuttx.md)
+
+### 2.4 输出与实验现象
+
+> ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
`
+
+#### 2.4.1 存在ping测试命令
+
+```
+$ help
+```
+
+
+
+#### 2.4.2 ip配置正常
+
+```
+$ ifconfig
+```
+
+
+
+#### 2.4.3 执行ping指令
+
+- 板卡ping上位机
+
+```
+$ ping 192.168.4.50
+```
+
+
+
+- 上位机ping板卡
+
+```
+$ ping 192.168.4.10
+```
+
+
+
+## 3. 如何解决问题
+
+> ``主要记录使用例程中可能会遇到的问题,给出相应的解决方案 `
`
+
+## 4. 修改历史记录
+
+> ``记录例程的重大修改记录,标明修改发生的版本号 `
`
diff --git a/phytium_examples/net/figs/ifconfig.png b/phytium_examples/net/figs/ifconfig.png
new file mode 100644
index 0000000000000000000000000000000000000000..2d635b3d5a073e0ab8f10d59d0bb5b5c57761ecc
Binary files /dev/null and b/phytium_examples/net/figs/ifconfig.png differ
diff --git a/phytium_examples/net/figs/ping.png b/phytium_examples/net/figs/ping.png
new file mode 100644
index 0000000000000000000000000000000000000000..e2cf6141cb7cd3ef33ca18a3a65a977c8e9624ee
Binary files /dev/null and b/phytium_examples/net/figs/ping.png differ
diff --git a/phytium_examples/net/figs/ping1.png b/phytium_examples/net/figs/ping1.png
new file mode 100644
index 0000000000000000000000000000000000000000..157286f5cdb6626dbf313fdcb53b3517ddc214aa
Binary files /dev/null and b/phytium_examples/net/figs/ping1.png differ
diff --git a/phytium_examples/net/figs/ping_cmd.png b/phytium_examples/net/figs/ping_cmd.png
new file mode 100644
index 0000000000000000000000000000000000000000..618ef9340c92441ce9d244ab5ff0fd8b2d45eadb
Binary files /dev/null and b/phytium_examples/net/figs/ping_cmd.png differ
diff --git a/phytium_examples/nsh/README.md b/phytium_examples/nsh/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..86ccb169d37f1520a8d7f2c45f25ec658d8a1ac2
--- /dev/null
+++ b/phytium_examples/nsh/README.md
@@ -0,0 +1,65 @@
+# nsh例程
+
+## 1. 例程介绍
+
+> ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作 `
`
+
+NuttShell (NSH) 是一个非常完整的 shell 系统。[NSH介绍](https://nuttx.apache.org/docs/latest/applications/nsh/index.htmlk)
+例程基于e2000 demo板,演示nsh的使用。
+
+## 2. 如何使用例程
+
+> ``描述开发平台准备,使用例程配置,构建和下载镜像的过程 `
`
+
+本例程需要以下硬件,
+
+- E2000D/Q Demo 板
+- 网线、串口线和串口上位机
+
+### 2.1 硬件配置方法
+
+> ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
`
+
+### 2.2 SDK配置方法
+
+> ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
`
+
+- 本例子已经提供好具体的编译指令,以下进行介绍:
+
+ 1. 进入phytium-nuttx-sdk/nuttx目录
+ 2. `make distclean` 清理当前配置文件
+ 3. `./tools/configure.sh -l e2000d_demo:nsh` 加载e2000d_demo板的nsh配置
+ 4. `make menuconfig` 配置目录下的参数,本步骤可忽略
+ 5. `make -j` 编译nuttx镜像
+- 具体使用方法为:
+
+ - 在当前目录下
+ - 执行以上指令
+
+### 2.3 构建和下载
+
+> ``描述构建、烧录下载镜像的过程,列出相关的命令 `
`
+
+- 参见 `NuttX 系统镜像加载方法`章节
+ [NuttX 系统镜像加载方法](../../../docs/compile_nuttx.md)
+
+### 2.4 输出与实验现象
+
+> ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
`
+
+#### 2.4.1 shell正常运行
+
+```
+$ help
+```
+
+
+
+
+## 3. 如何解决问题
+
+> ``主要记录使用例程中可能会遇到的问题,给出相应的解决方案 `
`
+
+## 4. 修改历史记录
+
+> ``记录例程的重大修改记录,标明修改发生的版本号 `
`
diff --git a/phytium_examples/nsh/figs/help.png b/phytium_examples/nsh/figs/help.png
new file mode 100644
index 0000000000000000000000000000000000000000..0621b2eee676185298e3455645015c243a43ed72
Binary files /dev/null and b/phytium_examples/nsh/figs/help.png differ
diff --git a/phytium_examples/nsh_smp/README.md b/phytium_examples/nsh_smp/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..6131095525020dc600bf83e5ec4469d2fcb6b585
--- /dev/null
+++ b/phytium_examples/nsh_smp/README.md
@@ -0,0 +1,64 @@
+# nsh_smp例程
+
+## 1. 例程介绍
+
+> ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作 `
`
+
+NuttShell (NSH) 是一个非常完整的 shell 系统。[NSH介绍](https://nuttx.apache.org/docs/latest/applications/nsh/index.htmlk)
+例程基于e2000 demo板,演示多核(smp)模式下nsh的使用。
+
+## 2. 如何使用例程
+
+> ``描述开发平台准备,使用例程配置,构建和下载镜像的过程 `
`
+
+本例程需要以下硬件,
+
+- E2000D/Q Demo 板
+- 网线、串口线和串口上位机
+
+### 2.1 硬件配置方法
+
+> ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
`
+
+### 2.2 SDK配置方法
+
+> ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
`
+
+- 本例子已经提供好具体的编译指令,以下进行介绍:
+
+ 1. 进入phytium-nuttx-sdk/nuttx目录
+ 2. `make distclean` 清理当前配置文件
+ 3. `./tools/configure.sh -l e2000d_demo:nsh_smp` 加载e2000d_demo板的nsh_smp配置
+ 4. `make menuconfig` 配置目录下的参数,本步骤可忽略
+ 5. `make -j` 编译nuttx镜像
+- 具体使用方法为:
+
+ - 在当前目录下
+ - 执行以上指令
+
+### 2.3 构建和下载
+
+> ``描述构建、烧录下载镜像的过程,列出相关的命令 `
`
+
+- 参见 `NuttX 系统镜像加载方法`章节
+ [NuttX 系统镜像加载方法](../../../docs/compile_nuttx.md)
+
+### 2.4 输出与实验现象
+
+> ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
`
+
+#### 2.4.1 shell正常运行
+
+```
+$ help
+```
+
+
+
+## 3. 如何解决问题
+
+> ``主要记录使用例程中可能会遇到的问题,给出相应的解决方案 `
`
+
+## 4. 修改历史记录
+
+> ``记录例程的重大修改记录,标明修改发生的版本号 `
`
diff --git a/phytium_examples/nsh_smp/figs/help.png b/phytium_examples/nsh_smp/figs/help.png
new file mode 100644
index 0000000000000000000000000000000000000000..0621b2eee676185298e3455645015c243a43ed72
Binary files /dev/null and b/phytium_examples/nsh_smp/figs/help.png differ
diff --git a/phytium_examples/nxffs/CMakeLists.txt b/phytium_examples/nxffs/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..aa569608d4b771e699174d4f9fc544491e24df48
--- /dev/null
+++ b/phytium_examples/nxffs/CMakeLists.txt
@@ -0,0 +1,23 @@
+# ##############################################################################
+# apps/testing/nxffs/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+if(CONFIG_PHYTIUM_TESTING_NXFFS)
+ nuttx_add_application(NAME phytium_nxffs SRCS nxffs_main.c)
+endif()
diff --git a/phytium_examples/nxffs/Kconfig b/phytium_examples/nxffs/Kconfig
new file mode 100644
index 0000000000000000000000000000000000000000..7654a070bbfeca4e0792e827101ca8d7186cd72f
--- /dev/null
+++ b/phytium_examples/nxffs/Kconfig
@@ -0,0 +1,71 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config PHYTIUM_TESTING_NXFFS
+ tristate "NXFFS file system example"
+ default n
+ ---help---
+ Enable the NXFFS file system example
+
+if PHYTIUM_TESTING_NXFFS
+
+config TESTING_NXFFS_ARCHINIT
+ bool "Architecture-specific initialization"
+ default n
+ ---help---
+ The default is to use the RAM MTD device at drivers/mtd/rammtd.c.
+ But an architecture-specific MTD driver can be used instead by
+ defining TESTING_NXFFS_ARCHINIT. In this case, the
+ initialization logic will call mtdpart_archinitialize() to obtain
+ the MTD driver instance.
+
+config TESTING_NXFFS_NEBLOCKS
+ int "Number of erase blocks (simulated)"
+ default 32
+ depends on !TESTING_NXFFS_ARCHINIT
+ ---help---
+ When TESTING_NXFFS_ARCHINIT is not defined, this test will use
+ the RAM MTD device at drivers/mtd/rammtd.c to simulate FLASH. In
+ this case, this value must be provided to give the number of erase
+ blocks in MTD RAM device.
+
+ The size of the allocated RAM drive will be:
+
+ RAMMTD_ERASESIZE * TESTING_NXFFS_NEBLOCKS
+
+config TESTING_NXFFS_MAXNAME
+ int "Max name size"
+ default 128
+ range 1 255
+ ---help---
+ Determines the maximum size of names used in the filesystem
+
+config TESTING_NXFFS_MAXFILE
+ int "Max file size"
+ default 8192
+ ---help---
+ Determines the maximum size of a file
+
+config TESTING_NXFFS_MAXIO
+ int "Max I/O"
+ default 347
+
+config TESTING_NXFFS_MAXOPEN
+ int "Max open files"
+ default 512
+
+config TESTING_NXFFS_MOUNTPT
+ string "NXFFS mountpoint"
+ default "/mnt/nxffs"
+
+config TESTING_NXFFS_NLOOPS
+ int "Number of test loops"
+ default 100
+
+config TESTING_NXFFS_VERBOSE
+ bool "Verbose output"
+ default n
+
+endif # TESTING_NXFFS
diff --git a/phytium_examples/nxffs/Make.defs b/phytium_examples/nxffs/Make.defs
new file mode 100644
index 0000000000000000000000000000000000000000..d410d82ba6d33c71f32385f0b73cc27595a9a787
--- /dev/null
+++ b/phytium_examples/nxffs/Make.defs
@@ -0,0 +1,23 @@
+############################################################################
+# apps/phytium_examples/nxffs/Make.defs
+#
+# 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.
+#
+############################################################################
+
+ifneq ($(CONFIG_PHYTIUM_TESTING_NXFFS),)
+CONFIGURED_APPS += $(APPDIR)/phytium_examples/nxffs
+endif
diff --git a/phytium_examples/nxffs/Makefile b/phytium_examples/nxffs/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..e7988e0d7212fe2b1408be7c2ed298410d1a7588
--- /dev/null
+++ b/phytium_examples/nxffs/Makefile
@@ -0,0 +1,32 @@
+############################################################################
+# apps/phytium_examples/nxffs/Makefile
+#
+# 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.
+#
+############################################################################
+
+include $(APPDIR)/Make.defs
+
+# NXFFS file system example
+
+PROGNAME = phytium_nxffs
+PRIORITY = SCHED_PRIORITY_DEFAULT
+STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
+MODULE = $(CONFIG_PHYTIUM_TESTING_NXFFS)
+
+MAINSRC = nxffs_main.c
+
+include $(APPDIR)/Application.mk
diff --git a/phytium_examples/nxffs/README.md b/phytium_examples/nxffs/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..42a588678fc3d892ee171e2cdf09adb66641528a
--- /dev/null
+++ b/phytium_examples/nxffs/README.md
@@ -0,0 +1,84 @@
+# NXFFS Example
+
+## 1. 例程介绍
+
+> ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作 `
`
+
+NuttX FLASH File System (NXFFS) 比较适用于 NOR FLASH设备,本例程基于e2000 demo板spi外接的w25 flash挂载nxffs文件系统,对apps/testing/nxffs例程进行了部分修改,实现e2000 demo板的NXFFS测试。
+
+## 2. 如何使用例程
+
+> ``描述开发平台准备,使用例程配置,构建和下载镜像的过程 `
`
+
+本例程需要以下硬件,
+
+- E2000D/Q Demo 板
+- 外接w25 flash芯片
+- 串口线和串口上位机
+
+### 2.1 硬件配置方法
+
+> ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
`
+
+E2000 demo spi2外接flash示例,VCC接P1V8或P3V3,建议从P1V8开始尝试,使用用例测试后,flash没有反应再连接P3V3,J30引脚组内侧第3号到第6号引脚分别为:SPI2_RXD、SPI2_CSN0、SPI2_TXD、SPI2_SCLK
+
+
+
+### 2.2 SDK配置方法
+
+> ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
`
+
+- 本例子已经提供好具体的编译指令,以下进行介绍:
+
+ 1. 进入phytium-nuttx-sdk/nuttx目录
+ 2. `make distclean` 清理当前配置文件
+ 3. `./tools/configure.sh -l e2000d_demo:nxffs` 加载e2000d_demo板的nxffs配置
+ 4. `make menuconfig` 配置目录下的参数,本步骤可忽略
+ 5. `make -j` 编译nuttx镜像
+- 具体使用方法为:
+
+ - 在当前目录下
+ - 执行以上指令
+
+### 2.3 构建和下载
+
+> ``描述构建、烧录下载镜像的过程,列出相关的命令 `
`
+
+- 参见 `NuttX 系统镜像加载方法`章节
+ [NuttX 系统镜像加载方法](../../../docs/compile_nuttx.md)
+
+### 2.4 输出与实验现象
+
+> ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
`
+
+#### 2.4.1 存在phytium_nxffs测试命令
+
+```
+$ help
+```
+
+
+
+#### 2.4.2 存在/mnt/w25a目录
+
+```
+$ ls /mnt
+```
+
+
+
+#### 2.4.3 执行phytium_nxffs指令
+
+```
+$ phytium_nxffs
+```
+
+
+
+## 3. 如何解决问题
+
+> ``主要记录使用例程中可能会遇到的问题,给出相应的解决方案 `
`
+
+## 4. 修改历史记录
+
+> ``记录例程的重大修改记录,标明修改发生的版本号 `
`
diff --git a/phytium_examples/nxffs/figs/e2000demo_flash.jpg b/phytium_examples/nxffs/figs/e2000demo_flash.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..3a52b9ada8568331211adcb835acfde0aed8f2a4
Binary files /dev/null and b/phytium_examples/nxffs/figs/e2000demo_flash.jpg differ
diff --git a/phytium_examples/nxffs/figs/nxffs.png b/phytium_examples/nxffs/figs/nxffs.png
new file mode 100644
index 0000000000000000000000000000000000000000..83c098e9665172a1e263f899e58c8ae1955395cd
Binary files /dev/null and b/phytium_examples/nxffs/figs/nxffs.png differ
diff --git a/phytium_examples/nxffs/figs/nxffs_cmd.png b/phytium_examples/nxffs/figs/nxffs_cmd.png
new file mode 100644
index 0000000000000000000000000000000000000000..d28b5d65672f53babb25d110094deca1090b8206
Binary files /dev/null and b/phytium_examples/nxffs/figs/nxffs_cmd.png differ
diff --git a/phytium_examples/nxffs/figs/phytium_nxffs.png b/phytium_examples/nxffs/figs/phytium_nxffs.png
new file mode 100644
index 0000000000000000000000000000000000000000..aa438378405009bb8942e73c6e3ae2db8b4fe44b
Binary files /dev/null and b/phytium_examples/nxffs/figs/phytium_nxffs.png differ
diff --git a/phytium_examples/nxffs/figs/phytium_nxffs_cmd.png b/phytium_examples/nxffs/figs/phytium_nxffs_cmd.png
new file mode 100644
index 0000000000000000000000000000000000000000..fd3ed3fa9512f0fa74f78c5a66eb6a4ebf4702b8
Binary files /dev/null and b/phytium_examples/nxffs/figs/phytium_nxffs_cmd.png differ
diff --git a/phytium_examples/nxffs/figs/w25a.png b/phytium_examples/nxffs/figs/w25a.png
new file mode 100644
index 0000000000000000000000000000000000000000..ef08643cd8bb96803e798fe9b4624491c18478eb
Binary files /dev/null and b/phytium_examples/nxffs/figs/w25a.png differ
diff --git a/phytium_examples/nxffs/nxffs_main.c b/phytium_examples/nxffs/nxffs_main.c
new file mode 100644
index 0000000000000000000000000000000000000000..0e117f0561d6081fc55e57b0bde0ac0844ca24fc
--- /dev/null
+++ b/phytium_examples/nxffs/nxffs_main.c
@@ -0,0 +1,885 @@
+/****************************************************************************
+ * apps/testing/nxffs/nxffs_main.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
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Configuration ************************************************************/
+
+/* The default is to use the RAM MTD device at drivers/mtd/rammtd.c. But
+ * an architecture-specific MTD driver can be used instead by defining
+ * CONFIG_TESTING_NXFFS_ARCHINIT. In this case, the initialization logic
+ * will call nxffs_archinitialize() to obtain the MTD driver instance.
+ */
+
+#ifndef CONFIG_TESTING_NXFFS_ARCHINIT
+
+/* This must exactly match the default configuration in
+ * drivers/mtd/rammtd.c
+ */
+
+# ifndef CONFIG_RAMMTD_ERASESIZE
+# define CONFIG_RAMMTD_ERASESIZE 4096
+# endif
+
+# ifndef CONFIG_TESTING_NXFFS_NEBLOCKS
+# define CONFIG_TESTING_NXFFS_NEBLOCKS (32)
+# endif
+
+# define TESTING_NXFFS_BUFSIZE \
+ (CONFIG_RAMMTD_ERASESIZE * CONFIG_TESTING_NXFFS_NEBLOCKS)
+#endif
+
+#ifndef CONFIG_TESTING_NXFFS_MAXNAME
+# define CONFIG_TESTING_NXFFS_MAXNAME 128
+#endif
+
+#if CONFIG_TESTING_NXFFS_MAXNAME > 255
+# undef CONFIG_TESTING_NXFFS_MAXNAME
+# define CONFIG_TESTING_NXFFS_MAXNAME 255
+#endif
+
+#ifndef CONFIG_TESTING_NXFFS_MAXFILE
+# define CONFIG_TESTING_NXFFS_MAXFILE 8192
+#endif
+
+#ifndef CONFIG_TESTING_NXFFS_MAXIO
+# define CONFIG_TESTING_NXFFS_MAXIO 347
+#endif
+
+#ifndef CONFIG_TESTING_NXFFS_MAXOPEN
+# define CONFIG_TESTING_NXFFS_MAXOPEN 512
+#endif
+
+#ifndef CONFIG_TESTING_NXFFS_MOUNTPT
+# define CONFIG_TESTING_NXFFS_MOUNTPT "/mnt/nxffs"
+#endif
+
+#ifndef CONFIG_TESTING_NXFFS_NLOOPS
+# define CONFIG_TESTING_NXFFS_NLOOPS 100
+#endif
+
+#ifndef CONFIG_TESTING_NXFFS_VERBOSE
+# define CONFIG_TESTING_NXFFS_VERBOSE 0
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct nxffs_filedesc_s
+{
+ FAR char *name;
+ bool deleted;
+ size_t len;
+ uint32_t crc;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Pre-allocated simulated flash */
+
+#ifndef CONFIG_TESTING_NXFFS_ARCHINIT
+// static uint8_t g_simflash[TESTING_NXFFS_BUFSIZE];
+#endif
+
+static uint8_t g_fileimage[CONFIG_TESTING_NXFFS_MAXFILE];
+static struct nxffs_filedesc_s g_files[CONFIG_TESTING_NXFFS_MAXOPEN];
+static const char g_mountdir[] = CONFIG_TESTING_NXFFS_MOUNTPT "/";
+static int g_nfiles;
+static int g_ndeleted;
+
+static struct mallinfo g_mmbefore;
+static struct mallinfo g_mmprevious;
+static struct mallinfo g_mmafter;
+
+/****************************************************************************
+ * External Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_TESTING_NXFFS_ARCHINIT
+extern FAR struct mtd_dev_s *nxffs_archinitialize(void);
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxffs_memusage
+ ****************************************************************************/
+
+static void nxffs_showmemusage(struct mallinfo *mmbefore,
+ struct mallinfo *mmafter)
+{
+ printf("VARIABLE BEFORE AFTER\n");
+ printf("======== ======== ========\n");
+ printf("arena %8x %8x\n", mmbefore->arena, mmafter->arena);
+ printf("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks);
+ printf("mxordblk %8x %8x\n", mmbefore->mxordblk, mmafter->mxordblk);
+ printf("uordblks %8x %8x\n", mmbefore->uordblks, mmafter->uordblks);
+ printf("fordblks %8x %8x\n", mmbefore->fordblks, mmafter->fordblks);
+}
+
+/****************************************************************************
+ * Name: nxffs_loopmemusage
+ ****************************************************************************/
+
+static void nxffs_loopmemusage(void)
+{
+ /* Get the current memory usage */
+
+ g_mmafter = mallinfo();
+
+ /* Show the change from the previous loop */
+
+ printf("\nEnd of loop memory usage:\n");
+ nxffs_showmemusage(&g_mmprevious, &g_mmafter);
+
+ /* Set up for the next test */
+
+ g_mmprevious = g_mmafter;
+}
+
+/****************************************************************************
+ * Name: nxffs_endmemusage
+ ****************************************************************************/
+
+static void nxffs_endmemusage(void)
+{
+ g_mmafter = mallinfo();
+
+ printf("\nFinal memory usage:\n");
+ nxffs_showmemusage(&g_mmbefore, &g_mmafter);
+}
+
+/****************************************************************************
+ * Name: nxffs_randchar
+ ****************************************************************************/
+
+static inline char nxffs_randchar(void)
+{
+ int value = rand() % 63;
+ if (value == 0)
+ {
+ return '0';
+ }
+ else if (value <= 10)
+ {
+ return value + '0' - 1;
+ }
+ else if (value <= 36)
+ {
+ return value + 'a' - 11;
+ }
+ else /* if (value <= 62) */
+ {
+ return value + 'A' - 37;
+ }
+}
+
+/****************************************************************************
+ * Name: nxffs_randname
+ ****************************************************************************/
+
+static inline void nxffs_randname(FAR struct nxffs_filedesc_s *file)
+{
+ int dirlen;
+ int maxname;
+ int namelen;
+ int alloclen;
+ int i;
+
+ dirlen = strlen(g_mountdir);
+ maxname = CONFIG_TESTING_NXFFS_MAXNAME - dirlen;
+ namelen = (rand() % maxname) + 1;
+ alloclen = namelen + dirlen;
+
+ file->name = (FAR char *)malloc(alloclen + 1);
+ if (!file->name)
+ {
+ printf("ERROR: Failed to allocate name, length=%d\n", namelen);
+ fflush(stdout);
+ exit(5);
+ }
+
+ memcpy(file->name, g_mountdir, dirlen);
+ for (i = dirlen; i < alloclen; i++)
+ {
+ file->name[i] = nxffs_randchar();
+ }
+
+ file->name[alloclen] = '\0';
+}
+
+/****************************************************************************
+ * Name: nxffs_randfile
+ ****************************************************************************/
+
+static inline void nxffs_randfile(FAR struct nxffs_filedesc_s *file)
+{
+ int i;
+
+ file->len = (rand() % CONFIG_TESTING_NXFFS_MAXFILE) + 1;
+ for (i = 0; i < file->len; i++)
+ {
+ g_fileimage[i] = nxffs_randchar();
+ }
+
+ file->crc = crc32(g_fileimage, file->len);
+}
+
+/****************************************************************************
+ * Name: nxffs_freefile
+ ****************************************************************************/
+
+static void nxffs_freefile(FAR struct nxffs_filedesc_s *file)
+{
+ if (file->name)
+ {
+ free(file->name);
+ }
+
+ memset(file, 0, sizeof(struct nxffs_filedesc_s));
+}
+
+/****************************************************************************
+ * Name: nxffs_wrfile
+ ****************************************************************************/
+
+static inline int nxffs_wrfile(FAR struct nxffs_filedesc_s *file)
+{
+ size_t offset;
+ int fd;
+ int ret;
+
+ /* Create a random file */
+
+ nxffs_randname(file);
+ nxffs_randfile(file);
+ fd = open(file->name, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ if (fd < 0)
+ {
+ /* If it failed because there is no space on the device, then don't
+ * complain.
+ */
+
+ if (errno != ENOSPC)
+ {
+ printf("ERROR: Failed to open file for writing: %d\n", errno);
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ }
+
+ nxffs_freefile(file);
+ return ERROR;
+ }
+
+ /* Write a random amount of data to the file */
+
+ for (offset = 0; offset < file->len; )
+ {
+ size_t maxio = (rand() % CONFIG_TESTING_NXFFS_MAXIO) + 1;
+ size_t nbytestowrite = file->len - offset;
+ ssize_t nbyteswritten;
+
+ if (nbytestowrite > maxio)
+ {
+ nbytestowrite = maxio;
+ }
+
+ nbyteswritten = write(fd, &g_fileimage[offset], nbytestowrite);
+ if (nbyteswritten < 0)
+ {
+ int errcode = errno;
+
+ /* If the write failed because there is no space on the device,
+ * then don't complain.
+ */
+
+ if (errcode != ENOSPC)
+ {
+ printf("ERROR: Failed to write file: %d\n", errcode);
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ printf(" Write offset: %ld\n", (long)offset);
+ printf(" Write size: %ld\n", (long)nbytestowrite);
+ ret = ERROR;
+ }
+
+ close(fd);
+
+ /* Remove any garbage file that might have been left behind */
+
+ ret = unlink(file->name);
+ if (ret < 0)
+ {
+ printf(" Failed to remove partial file\n");
+ }
+ else
+ {
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf(" Successfully removed partial file\n");
+#endif
+ }
+
+ nxffs_freefile(file);
+ return ERROR;
+ }
+ else if (nbyteswritten != nbytestowrite)
+ {
+ printf("ERROR: Partial write:\n");
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ printf(" Write offset: %ld\n", (long)offset);
+ printf(" Write size: %ld\n", (long)nbytestowrite);
+ printf(" Written: %ld\n", (long)nbyteswritten);
+ }
+
+ offset += nbyteswritten;
+ }
+
+ close(fd);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: nxffs_fillfs
+ ****************************************************************************/
+
+static int nxffs_fillfs(void)
+{
+ FAR struct nxffs_filedesc_s *file;
+ int ret;
+ int i;
+
+ /* Create a file for each unused file structure */
+
+ for (i = 0; i < CONFIG_TESTING_NXFFS_MAXOPEN; i++)
+ {
+ file = &g_files[i];
+ if (file->name == NULL)
+ {
+ ret = nxffs_wrfile(file);
+ if (ret < 0)
+ {
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf("ERROR: Failed to write file %d\n", i);
+#endif
+ return ERROR;
+ }
+
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf(" Created file %s\n", file->name);
+#endif
+ g_nfiles++;
+ }
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: nxffs_rdblock
+ ****************************************************************************/
+
+static ssize_t nxffs_rdblock(int fd, FAR struct nxffs_filedesc_s *file,
+ size_t offset, size_t len)
+{
+ size_t maxio = (rand() % CONFIG_TESTING_NXFFS_MAXIO) + 1;
+ ssize_t nbytesread;
+
+ if (len > maxio)
+ {
+ len = maxio;
+ }
+
+ nbytesread = read(fd, &g_fileimage[offset], len);
+ if (nbytesread < 0)
+ {
+ printf("ERROR: Failed to read file: %d\n", errno);
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ printf(" Read offset: %ld\n", (long)offset);
+ printf(" Read size: %ld\n", (long)len);
+ return ERROR;
+ }
+ else if (nbytesread == 0)
+ {
+#if 0 /* No... we do this on purpose sometimes */
+ printf("ERROR: Unexpected end-of-file:\n");
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %d\n", file->len);
+ printf(" Read offset: %ld\n", (long)offset);
+ printf(" Read size: %ld\n", (long)len);
+#endif
+ return ERROR;
+ }
+ else if (nbytesread != len)
+ {
+ printf("ERROR: Partial read:\n");
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ printf(" Read offset: %ld\n", (long)offset);
+ printf(" Read size: %ld\n", (long)len);
+ printf(" Bytes read: %ld\n", (long)nbytesread);
+ }
+
+ return nbytesread;
+}
+
+/****************************************************************************
+ * Name: nxffs_rdfile
+ ****************************************************************************/
+
+static inline int nxffs_rdfile(FAR struct nxffs_filedesc_s *file)
+{
+ size_t ntotalread;
+ ssize_t nbytesread;
+ uint32_t crc;
+ int fd;
+
+ /* Open the file for reading */
+
+ fd = open(file->name, O_RDONLY);
+ if (fd < 0)
+ {
+ if (!file->deleted)
+ {
+ printf("ERROR: Failed to open file for reading: %d\n", errno);
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ }
+
+ return ERROR;
+ }
+
+ /* Read all of the data info the fileimage buffer using random read sizes */
+
+ for (ntotalread = 0; ntotalread < file->len; )
+ {
+ nbytesread = nxffs_rdblock(fd, file, ntotalread,
+ file->len - ntotalread);
+ if (nbytesread < 0)
+ {
+ close(fd);
+ return ERROR;
+ }
+
+ ntotalread += nbytesread;
+ }
+
+ /* Verify the file image CRC */
+
+ crc = crc32(g_fileimage, file->len);
+ if (crc != file->crc)
+ {
+ printf("ERROR: Bad CRC: %u vs %u\n",
+ (unsigned int)crc, (unsigned int)file->crc);
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ close(fd);
+ return ERROR;
+ }
+
+ /* Try reading past the end of the file */
+
+ nbytesread = nxffs_rdblock(fd, file, ntotalread, 1024) ;
+ if (nbytesread > 0)
+ {
+ printf("ERROR: Read past the end of file\n");
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ printf(" Bytes read: %ld\n", (long)nbytesread);
+ close(fd);
+ return ERROR;
+ }
+
+ close(fd);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: nxffs_verifyfs
+ ****************************************************************************/
+
+static int nxffs_verifyfs(void)
+{
+ FAR struct nxffs_filedesc_s *file;
+ int ret;
+ int i;
+
+ /* Create a file for each unused file structure */
+
+ for (i = 0; i < CONFIG_TESTING_NXFFS_MAXOPEN; i++)
+ {
+ file = &g_files[i];
+ if (file->name != NULL)
+ {
+ ret = nxffs_rdfile(file);
+ if (ret < 0)
+ {
+ if (file->deleted)
+ {
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf("Deleted file %d OK\n", i);
+#endif
+ nxffs_freefile(file);
+ g_ndeleted--;
+ g_nfiles--;
+ }
+ else
+ {
+ printf("ERROR: Failed to read a file: %d\n", i);
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ return ERROR;
+ }
+ }
+ else
+ {
+ if (file->deleted)
+ {
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf("Succesffully read a deleted file\n");
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %d\n", file->len);
+#endif
+ nxffs_freefile(file);
+ g_ndeleted--;
+ g_nfiles--;
+ return ERROR;
+ }
+ else
+ {
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf(" Verifed file %s\n", file->name);
+#endif
+ }
+ }
+ }
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: nxffs_delfiles
+ ****************************************************************************/
+
+static int nxffs_delfiles(void)
+{
+ FAR struct nxffs_filedesc_s *file;
+ int ndel;
+ int ret;
+ int i;
+ int j;
+
+ /* Are there any files to be deleted? */
+
+ int nfiles = g_nfiles - g_ndeleted;
+ if (nfiles < 1)
+ {
+ return 0;
+ }
+
+ /* Yes... How many files should we delete? */
+
+ ndel = (rand() % nfiles) + 1;
+
+ /* Now pick which files to delete */
+
+ for (i = 0; i < ndel; i++)
+ {
+ /* Guess a file index */
+
+ int ndx = (rand() % (g_nfiles - g_ndeleted));
+
+ /* And delete the next undeleted file after that random index. NOTE
+ * that the entry at ndx is not checked.
+ */
+
+ for (j = ndx + 1; j != ndx; j++)
+ {
+ /* Test for wrap-around */
+
+ if (j >= CONFIG_TESTING_NXFFS_MAXOPEN)
+ {
+ j = 0;
+ }
+
+ file = &g_files[j];
+ if (file->name && !file->deleted)
+ {
+ ret = unlink(file->name);
+ if (ret < 0)
+ {
+ printf("ERROR: Unlink %d failed: %d\n", i + 1, errno);
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ printf(" File index: %d\n", j);
+ }
+ else
+ {
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf(" Deleted file %s\n", file->name);
+#endif
+ file->deleted = true;
+ g_ndeleted++;
+ break;
+ }
+ }
+ }
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: nxffs_delallfiles
+ ****************************************************************************/
+
+static int nxffs_delallfiles(void)
+{
+ FAR struct nxffs_filedesc_s *file;
+ int ret;
+ int i;
+
+ for (i = 0; i < CONFIG_TESTING_NXFFS_MAXOPEN; i++)
+ {
+ file = &g_files[i];
+ if (file->name)
+ {
+ ret = unlink(file->name);
+ if (ret < 0)
+ {
+ printf("ERROR: Unlink %d failed: %d\n", i + 1, errno);
+ printf(" File name: %s\n", file->name);
+ printf(" File size: %lu\n", (unsigned long)file->len);
+ printf(" File index: %d\n", i);
+ }
+ else
+ {
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf(" Deleted file %s\n", file->name);
+#endif
+ nxffs_freefile(file);
+ }
+ }
+ }
+
+ g_nfiles = 0;
+ g_ndeleted = 0;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: nxffs_directory
+ ****************************************************************************/
+
+static int nxffs_directory(void)
+{
+ DIR *dirp;
+ FAR struct dirent *entryp;
+ int number;
+
+ /* Open the directory */
+
+ dirp = opendir(CONFIG_TESTING_NXFFS_MOUNTPT);
+
+ if (!dirp)
+ {
+ /* Failed to open the directory */
+
+ printf("ERROR: Failed to open directory '%s': %d\n",
+ CONFIG_TESTING_NXFFS_MOUNTPT, errno);
+ return ERROR;
+ }
+
+ /* Read each directory entry */
+
+ printf("Directory:\n");
+ number = 1;
+ do
+ {
+ entryp = readdir(dirp);
+ if (entryp)
+ {
+ printf("%2d. Type[%d]: %s Name: %s\n",
+ number, entryp->d_type,
+ entryp->d_type == DTYPE_FILE ? "File " : "Error",
+ entryp->d_name);
+ }
+
+ number++;
+ }
+ while (entryp != NULL);
+
+ closedir(dirp);
+ return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxffs_main
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+ unsigned int i;
+ int ret;
+
+ /* Seed the random number generated */
+
+ srand(0x93846);
+
+ /* Set up memory monitoring */
+
+ g_mmbefore = mallinfo();
+ g_mmprevious = g_mmbefore;
+
+ /* Loop a few times ... file the file system with some random, files,
+ * delete some files randomly, fill the file system with more random file,
+ * delete, etc. This beats the FLASH very hard!
+ */
+
+#if CONFIG_TESTING_NXFFS_NLOOPS == 0
+ for (i = 0; ; i++)
+#else
+ for (i = 1; i <= CONFIG_TESTING_NXFFS_NLOOPS; i++)
+#endif
+ {
+ /* Write a files to the NXFFS file system until either (1) all of the
+ * open file structures are utilized or until (2) NXFFS reports an
+ * error (hopefully that the file system is full)
+ */
+
+ printf("\n=== FILLING %u =============================\n", i);
+ nxffs_fillfs();
+ printf("Filled file system\n");
+ printf(" Number of files: %d\n", g_nfiles);
+ printf(" Number deleted: %d\n", g_ndeleted);
+
+ /* Directory listing */
+
+ nxffs_directory();
+
+ /* Verify all files written to FLASH */
+
+ ret = nxffs_verifyfs();
+ if (ret < 0)
+ {
+ printf("ERROR: Failed to verify files\n");
+ printf(" Number of files: %d\n", g_nfiles);
+ printf(" Number deleted: %d\n", g_ndeleted);
+ exit(ret);
+ }
+ else
+ {
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf("Verified!\n");
+ printf(" Number of files: %d\n", g_nfiles);
+ printf(" Number deleted: %d\n", g_ndeleted);
+#endif
+ }
+
+ /* Delete some files */
+
+ printf("\n=== DELETING %u ============================\n", i);
+ ret = nxffs_delfiles();
+ if (ret < 0)
+ {
+ printf("ERROR: Failed to delete files\n");
+ printf(" Number of files: %d\n", g_nfiles);
+ printf(" Number deleted: %d\n", g_ndeleted);
+ exit(ret);
+ }
+ else
+ {
+ printf("Deleted some files\n");
+ printf(" Number of files: %d\n", g_nfiles);
+ printf(" Number deleted: %d\n", g_ndeleted);
+ }
+
+ /* Directory listing */
+
+ nxffs_directory();
+
+ /* Verify all files written to FLASH */
+
+ ret = nxffs_verifyfs();
+ if (ret < 0)
+ {
+ printf("ERROR: Failed to verify files\n");
+ printf(" Number of files: %d\n", g_nfiles);
+ printf(" Number deleted: %d\n", g_ndeleted);
+ exit(ret);
+ }
+ else
+ {
+#if CONFIG_TESTING_NXFFS_VERBOSE != 0
+ printf("Verified!\n");
+ printf(" Number of files: %d\n", g_nfiles);
+ printf(" Number deleted: %d\n", g_ndeleted);
+#endif
+ }
+
+ /* Show memory usage */
+
+ nxffs_loopmemusage();
+ fflush(stdout);
+ }
+
+ /* Delete all files then show memory usage again */
+
+ nxffs_delallfiles();
+ nxffs_endmemusage();
+ fflush(stdout);
+ return 0;
+}
diff --git a/phytium_examples/sd/README.md b/phytium_examples/sd/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..3f8786aed99cb6fa983e0664c96b9139d18ff883
--- /dev/null
+++ b/phytium_examples/sd/README.md
@@ -0,0 +1,82 @@
+# sd卡例程
+
+## 1. 例程介绍
+
+> ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作 `
`
+
+sd卡例程基于e2000 demo板,使用apps/testing/fstest例程,实现e2000 demo板的sd卡挂载fatfs文件系统测试。
+
+## 2. 如何使用例程
+
+> ``描述开发平台准备,使用例程配置,构建和下载镜像的过程 `
`
+
+本例程需要以下硬件,
+
+- E2000D/Q Demo 板
+- sd卡
+- 串口线和串口上位机
+
+### 2.1 硬件配置方法
+
+> ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
`
+
+E2000 demo 板需要插入sd卡
+
+### 2.2 SDK配置方法
+
+> ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
`
+
+- 本例子已经提供好具体的编译指令,以下进行介绍:
+
+ 1. 进入phytium-nuttx-sdk/nuttx目录
+ 2. `make distclean` 清理当前配置文件
+ 3. `./tools/configure.sh -l e2000d_demo:sd` 加载e2000d_demo板的sd配置
+ 4. `make menuconfig` 配置目录下的参数,本步骤可忽略
+ 5. `make -j` 编译nuttx镜像
+- 具体使用方法为:
+
+ - 在当前目录下
+ - 执行以上指令
+
+### 2.3 构建和下载
+
+> ``描述构建、烧录下载镜像的过程,列出相关的命令 `
`
+
+- 参见 `NuttX 系统镜像加载方法`章节
+ [NuttX 系统镜像加载方法](../../../docs/compile_nuttx.md)
+
+### 2.4 输出与实验现象
+
+> ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
`
+
+#### 2.4.1 存在fstest测试命令
+
+```
+$ help
+```
+
+
+
+#### 2.4.2 存在/mnt/sd目录
+
+```
+$ ls /mnt
+```
+
+
+
+#### 2.4.3 执行fstest指令
+
+```
+$ fstest
+```
+
+
+
+## 3. 如何解决问题
+
+> ``主要记录使用例程中可能会遇到的问题,给出相应的解决方案 `
`
+
+## 4. 修改历史记录
+
+> ``记录例程的重大修改记录,标明修改发生的版本号 `
`
diff --git a/phytium_examples/sd/figs/fstest.png b/phytium_examples/sd/figs/fstest.png
new file mode 100644
index 0000000000000000000000000000000000000000..dda6f6ef841266d65b4d6b950b3fbff5fe2710f6
Binary files /dev/null and b/phytium_examples/sd/figs/fstest.png differ
diff --git a/phytium_examples/sd/figs/fstest_cmd.png b/phytium_examples/sd/figs/fstest_cmd.png
new file mode 100644
index 0000000000000000000000000000000000000000..261a977c71478373b824b2c6ea630fb72bede56d
Binary files /dev/null and b/phytium_examples/sd/figs/fstest_cmd.png differ
diff --git a/phytium_examples/sd/figs/sd.png b/phytium_examples/sd/figs/sd.png
new file mode 100644
index 0000000000000000000000000000000000000000..8197ceee6bac3d9cb91f717e37d7169159eebadb
Binary files /dev/null and b/phytium_examples/sd/figs/sd.png differ
diff --git a/system/argtable3/CMakeLists.txt b/system/argtable3/CMakeLists.txt
index 30ff55c86cc394d7578d155e0a620552844ce572..88f158dfcb0d9cbb0ae1921d8c151c486d87f733 100644
--- a/system/argtable3/CMakeLists.txt
+++ b/system/argtable3/CMakeLists.txt
@@ -25,7 +25,7 @@ if(CONFIG_SYSTEM_ARGTABLE3)
if(NOT CONFIG_SYSTEM_ARGTABLE3_URL)
set(CONFIG_SYSTEM_ARGTABLE3_URL
- "https://github.com/argtable/argtable3/archive")
+ "https://github.com/argtable/argtable3")
endif()
if(NOT CONFIG_SYSTEM_ARGTABLE3_VERSION)
diff --git a/testing/sd_bench/sd_bench_main.c b/testing/sd_bench/sd_bench_main.c
index 7e67fb9dedbde8cb645a02f38ea67190f3bc0311..d48f9ceec7994dda6773f98c9eca43e0901b09d7 100644
--- a/testing/sd_bench/sd_bench_main.c
+++ b/testing/sd_bench/sd_bench_main.c
@@ -175,7 +175,7 @@ void write_test(int fd, sdb_config_t *cfg, uint8_t *block, int block_size)
uint64_t elapsed;
uint64_t total_elapsed = 0.;
size_t total_blocks = 0;
- size_t *blocknumber = (unsigned int *)(void *)&block[0];
+ size_t *blocknumber = (size_t *)(void *)&block[0];
printf("\n");
printf("Testing Sequential Write Speed...\n");
@@ -275,7 +275,7 @@ int read_test(int fd, sdb_config_t *cfg, uint8_t *block, int block_size)
total_elapsed = 0.;
total_blocks = 0;
- size_t *blocknumber = (unsigned int *)(void *) &read_block[0];
+ size_t *blocknumber = (size_t *)(void *) &read_block[0];
for (int run = 0; run < cfg->num_runs; ++run)
{
@@ -304,7 +304,7 @@ int read_test(int fd, sdb_config_t *cfg, uint8_t *block, int block_size)
if (*blocknumber != total_blocks + num_blocks)
{
- printf("Read data error at block: %d wrote:0x%04x read:0x%04x",
+ printf("Read data error at block: %ld wrote:0x%04lx read:0x%04lx",
(total_blocks + num_blocks),
total_blocks + num_blocks, *blocknumber);
}
@@ -314,7 +314,7 @@ int read_test(int fd, sdb_config_t *cfg, uint8_t *block, int block_size)
{
if (block[i] != read_block[i])
{
- printf("Read data error at offset: %d wrote:0x%02x "
+ printf("Read data error at offset: %ld wrote:0x%02x "
"read:0x%02x", total_blocks + num_blocks + i,
block[i], read_block[i]);
}
@@ -351,11 +351,11 @@ static void usage(void)
printf("Test the speed of an SD card or mount point\n");
printf(CONFIG_TESTING_SD_BENCH_PROGNAME
": [-b] [-r] [-d] [-k] [-s] [-a] [-v]\n");
- printf(" -b Block size per write (%u-%u), default %u\n",
+ printf(" -b Block size per write (%lu-%lu), default %lu\n",
min_block, max_block, default_block);
- printf(" -r Number of runs (%u-%u), default %u\n",
+ printf(" -r Number of runs (%lu-%lu), default %lu\n",
min_runs, max_runs, default_runs);
- printf(" -d Max duration of a test (ms) (%u-%u), default %u\n",
+ printf(" -d Max duration of a test (ms) (%lu-%lu), default %lu\n",
min_duration, max_duration, default_duration);
printf(" -k Keep test file when finished, default %s\n",
print_bool(default_keep_test));
@@ -479,7 +479,7 @@ int main(int argc, char *argv[])
block[j] = (uint8_t)j;
}
- printf("Using block size = %u bytes, sync = %s\n", block_size,
+ printf("Using block size = %lu bytes, sync = %s\n", block_size,
print_bool(cfg.synchronized));
write_test(bench_fd, &cfg, block, block_size);