Nuttxporting step
co-work other member
1.Nuttx OS porting 相关的目录介绍.
|- nuttx
| |-- Makefile
| |-- Kconfig
| |-- Documentation
| | `-- (documentation files)/
| |-- arch/
| | |-- Kconfig
| | |-- <arch-name>/
| | | |-- include/
| | | | |--<chip-name>/
| | | | | `-- (chip-specific header files)
| | | | |--<other-chips>/
| | | | `-- (architecture-specificheader files)
| | | `-- src/
| | | |--<chip-name>/
| | | | `-- (chip-specific sourcefiles)
| | | |--<other-chips>/
| | | `-- (architecture-specific source files)
| | `-- <other-architecturedirectories>/
| |-- configs/
| | |-- <board-name>/
| | | |-- include/
| | | | `-- (other board-specific header files)
| | | |-- src/
| | | | `-- (board-specific source files)
| | | |---<config-name>/
| | | | `-- (board configuration-specific source files)
| | | `---(other configuration sub-directories for this board)/
| | `-- <(other board directories)>/
| |-- drivers/
| | |-- Makefile
| | |-- Kconfig
| | |-- (driver-specific sub-directories)/
| | | `-- (driver-specific source files)
| | `-- (common driver source files)
1.1 nuttx/arch
This directory contains severalsub-directories, each containing architecture-specific logic. The task ofporting NuttX to a new processor consists of add a new subdirectory under arch/containing logic specific to the new architecture. The complete board port inis defined by the architecture-specific code in this directory (plus theboard-specific configurations in the config/ subdirectory). Each architecturemust provide a subdirectory, <arch-name> under arch/with the following characteristics:
<arch-name>/
|-- include/
| |--<chip-name>/
| | `-- (chip-specific header files)
| |--<other-chips>/
| |-- arch.h
| |-- irq.h
| |-- types.h
| |-- limits.h
| `-- syscall.h
`-- src/
|--<chip-name>/
| `-- (chip-specific source files)
|--<other-chips>/
|-- Makefile
`-- (architecture-specificsource files)
1.2 nuttx/configs
The configs/
subdirectory contains configuration data for each board. Theseboard-specific configurations plus the architecture-specific configurations inthe arch/
subdirectory complete define a customized port of NuttX.
Subdirectory Structure
The configs directory contains board specific configurationfiles. Each board must provide a subdirectory <board-name> under configs/
with the following characteristics:
<board-name>
|-- Kconfig
|-- include/
| |-- board.h
| `-- (board-specific header files)
|-- src/
| |-- Makefile
| `-- (board-specific source files)
|-- <config1-dir>
| |-- Make.defs
| |-- defconfig
| `-- setenv.sh
|-- <config2-dir>
| |-- Make.defs
| |-- defconfig
| `-- setenv.sh
| ...
`-- (other board-specific configuration sub-directories)
2.NuttX 移植工作
1. 一旦執行過 tools/cofigure.sh,會在指定的configs/<VENDOR>/<CHIP>/<PROJECT> 路徑下,複製 3 個檔案至根目錄。
n defconfig → .config
n Make.defs
n setenv.sh
2. 開始編譯時,會產生幾個新的目錄、檔案:
1. 將configs/<VENDOR>/<BOARD>/src 的檔案複製到arch/<CPU>/src/board
2. 將 arch/<CPU>/src/<CHIP> 的檔案複製到arch/<CPU>/src/chip
3. 將configs/<VENDOR>/<BOARD>/include 的檔案複製到include/arch/board
將arch/<CPU>/include/<CHIP> 的檔案複製到include/arch/chip
4. 將 .config 的內容轉換成 C 語言的引入檔,複製到include/nuttx/config.h
產生一個版本資訊檔案 - include/nuttx/version.h
apps-7.2/ | nuttx-7.2/ | ------ arch/ | | ------ <CPU>/ | | ------ src/ | | ------ board/ | | ------ chip/ | | ------ common/ | | ------ mips32/ | | ------ <CHIP>/ ②-1 | | ------ include | | ------ <CHIP>/ ②-3 | ------ configs/ | | ------ <VENDOR>/ | | ------ <BOARD>/ | | ------ include/ ②-3 | | ------ nsh/ | | ------ src/ ②-2 | ------ include/ | | ------ apps/ | | ------ arch/ | | ------ nuttx/ | | ------ config.h ②-4 | | ------ version.h | ------ .config | ------ Make.defs ① | ------ setenv.sh
|
因此根據以上實驗,要移植 NuttX 到 NT456 的平台上,要做的事情有:
A. 編寫 arch/<CPU>/Kconfig、configs/Kconfig,將 NT72456 相關組態設定加入。
B. 在arch/<CPU>/src 目錄下新增、撰寫 <SOC>相關初始化驅動程式。
C. 在 configs 目錄下新增、撰寫 <BOARD> 相關初始化驅動程式。
也就是上圖中紅色框框,就是我們這次預定移植的範圍。
NEW arch config
Z:\home\xa00010\nuttx7.3\nuttx\arch\mips\src\mips32 这个nuttxos 帮我们做好了
NEW CHIP config
1 Z:\home\xa00010\nuttx7.3\nuttx\arch\mips\src\pic32mx这是一个ic的参考
2同样我们建立了如下文件夹
Z:\home\xa00010\nuttx7.3\nuttx\arch\mips\src\nt7245x
3这些文件的创建过程 MIPS 24KEc 的規格文件
其实就是根据nuttxos 的启动流程来实现和打通最终是要把os_start成功带起来.
mips_head.S mips reset 入口,异常向量,cpu状态,cache
nvt_clock.c pll 设定
nvt_cache.c 缓存配置
nvt_exception.c 异常向量处理
nvt_irq.c 中断处理
nvt_time.c 系统时间
nvt_lowconsole.cUART 配置
nvt_serial.c 标准输入输出
nvt_ehci.cnvt_usb.c USB 相关
nvt_spi.c spidriver
nvt_lowinit.c 将会调用board_init
Adding a New Board Configuration
Okay, so you have created a new board configurationdirectory. Now, how do you hook this board into the configuration system sothat you can select with makemenuconfig
?
You will need modify the file configs/Kconfig
. Let's look at the STM32F4-Discovery configuration in the Kconfig
fileand see how we would add a new board directory to the configuration. For thisconfiguration let's say that you new board resides in the directory configs/myboard
; It uses an MCU selected with CONFIG_ARCH_CHIP_MYMCU
;and you want the board to be selected with CONFIG_ARCH_BOARD_MYBOARD
. Then here is how you can clone the STM32F4-Discovery configurationin configs/Kconfig
to support your new board configuration.
In configs/Kconfig
for the stm32f4-discovery, you will see a configuration definitionlike this:
config ARCH_BOARD_STM32F4_DISCOVERY
bool "STMicro STM32F4-Discovery board"
depends on ARCH_CHIP_STM32F407VG
select ARCH_HAVE_LEDS
select ARCH_HAVE_BUTTONS
select ARCH_HAVE_IRQBUTTONS
---help---
STMicro STM32F4-Discovery board based on the STMicro STM32F407VGT6 MCU.
The above selects the STM32F4-Discovery board. The select
linessay that the board has both LEDs and buttons and that the board can generateinterrupts from the button presses. You can just copy the above configurationdefinition to a new location (notice that they the configurations are inalphabetical order). Then you should edit the configuration to support yourboard. The final configuration definition might look something like:
config ARCH_BOARD_MYBOARD
bool "My very own board configuration"
depends on ARCH_CHIP_MYMCU
select ARCH_HAVE_LEDS
select ARCH_HAVE_BUTTONS
select ARCH_HAVE_IRQBUTTONS
---help---
This options selects the board configuration for my very own board
based on the MYMCU processor.
Later in the configs/Kconfig
file,you will see a long, long string configuration with lots of defaults like this:
config ARCH_BOARD
string
default "amber" if ARCH_BOARD_AMBER
default "avr32dev1" if ARCH_BOARD_AVR32DEV1
default "c5471evm" if ARCH_BOARD_C5471EVM
...
default "stm32f4discovery" if ARCH_BOARD_STM32F4_DISCOVERY
...
This logic will assign string value to a configuration variablecalled CONFIG_ARCH_BOARD
that will name the directory where the board-specific files reside.In our case, these files reside in configs/myboard
and weadd the following to the long list of defaults (again in alphabetical order):
default "myboar" if ARCH_BOARD_MYBOARD
Now the build system knows where to find your boardconfiguration!
And finally, add something like this near the bottom of configs/myboard
:
if ARCH_BOARD_MYBOARD
source "configs/myboard/Kconfig"
endif
This includes additional, board-specific configurationvariable definitions in configs/myboard/Kconfig
.
同样道理我们可以参考.
Z:\home\xa00010\nuttx7.3\nuttx\configs\pic32mx7mmb来建立
Z:\home\xa00010\nuttx7.3\nuttx\configs\nt7245x
最关键的文件是ld.script defconfig
Up_boot.c 我们主要是增加了.
up_sf_initialize MTD块设备 ,vfat 文件系统, 和 spi存储器 的初始化
up_usbhost_initialize usb 设备初始化
ld.script 及 vector 向量配置:
1. 定義:
image 由 boot loader 載入到 DRAM 執行,因此不處理 copydata section to ram 的相關事宜。
2. 記憶體規劃:
/* * REGION START ADDR KSEG SIZE * DESCRIPTION (BYTES) * ------------------------- ----------- ------ -------------- * vector * vector table 0x80000200 KSEG1 256 * virtual vector table 0x80000300 KSEG1 256 * ebase 0x80001000 * utlb_vector 0x80001000 32 * other_vector 0x80001180 32 * debug_vector 0x80001200 32 * reset_vector entry point */
ram : ORIGIN = 0x80000000, LENGTH = 0x4000000 tspu_sram : ORIGIN = 0xbc12c000, LENGTH = 0x4000 imvq_sram : ORIGIN = 0xbc130000, LENGTH = 0x10000
|
l 記憶體起始位址:0x80000000
l 保留一開始的 4KB 空間存放 vectortable
l ebase 設在 0x80001000
任务调度处理:
处理方法:
1. 新的 task 確實有加入ready queue list 裡,等待被執行。
2. 加入的時候也有呼叫up_switchcontext()
3. up_switchcontext() 使用syscall exception 實做,因此這個exception 也有被觸發。
4. 進入 syscall 的處理函式up_swint0()
up_swint0( ... )
{
switch (regs[REG_R4])
{
case SYS_switch_context:
DEBUGASSERT(regs[REG_A1] != 0 && regs[REG_A2] != 0);
up_copystate((uint32_t*)regs[REG_A1], regs);
current_regs =(uint32_t*)regs[REG_A2]; <-- 新的task 沒有被排程,
break; a. 一個原因是這裡的暫存器存錯;
} b. 或是這個current_regs 不足以做context swich
}
完整的排程:
3 Configuring and Building |
3.1 Configuring NuttX
Manual Configuration.Configuring NuttX requires only copying the board-specificconfiguration files into the top level directory which appears in the makefiles as the make variable, ${TOPDIR}
. This could be done manuallyas follows:
- Copy
configs/
<board-name>/[
<config-dir>/]Make.defs
to${TOPDIR}/Make.defs
, - Copy
configs/
<board-name>/[
<config-dir>/]setenv.sh
to${TOPDIR}/setenv.sh
, and - Copy
configs/
<board-name>/[
<config-dir>/]defconfig
to${TOPDIR}/.config
Where <board-name> is the name of one of thesub-directories of the NuttX configs/
directory. This sub-directoryname corresponds to one of the supported boards identified above.<config-dir> is the optional, specific configuration directory for theboard. And <app-dir> is the location of the optional applicationdirectory.
Automated Configuration.There is a script that automates these steps. The following steps willaccomplish the same configuration:
cd tools
./configure.sh <board-name>[/<config-dir>]
There is an alternative Windows batch file, configure.bat
, that can be used instead of configure.sh
in thewindows native environment like:
cd tools
configure.bat <board-name>[\<config-dir>]
See tools/README.txt
for more information about these scripts.
If your application directory is not in the standardlocation (../apps
or ../apps-<version>
), then you should also specify the location of the applicationdirectory on the command line like:
cd tools
./configure.sh -a <app-dir> <board-name>[/<config-dir>]
Version Files. The NuttXbuild expects to find a version file located in the top-level NuttX builddirectory. That version file is called .version
. The correctversion file is installed in each versioned NuttX released. However, if you areworking from an GIT snapshot, then there will be no version file. If there isno version file, the top-level Makefile
will create a dummy .version
file on the first make. This dummy version file will contain all zeroes for versioninformation. If that is not what you want, they you should run the version.sh
script to create a better .version
file.
You can get help information from the version.sh
script using the -h
option. For example:
$ tools/version.sh -h
tools/version.sh is a tool for generation of proper version files for the NuttX build
USAGE: tools/version.sh [-d|-h] [-b build] -v <major.minor> <outfile-path>
Where:
-d
Enable script debug
-h
show this help message and exit
-v <major.minor>
The NuttX version number expressed a major and minor number separated
by a period
<outfile-path>
The full path to the version file to be created
As an example, the following command will generate aversion file for version 6.1 using the current GIT revision number:
tools/version.h -v 6.1 .version
The .version
file is also used during the build process to create a C headerfile at include/nuttx/version.h
that contains the same version information. That version file maybe used by your C applications for, as an example, reporting versioninformation.
Additional Configuration Steps. The remainder of configuration steps will be performed by ${TOPDIR}/Makefile
the first timethe system is built as described below.
3.2 Building NuttX
Building NuttX. Once NuttXhas been configured as described above,it may be built as follows:
cd ${TOPDIR}
source ./setenv.sh
make
The ${TOPDIR}
directory holds:
- The top level
Makefile
that controls the NuttX build.
That directory also holds:
- The makefile fragment
.config
that describes the current configuration. - The makefile fragment
Make.defs
that provides customized build targets, and - The shell script
setenv.sh
that sets up the configuration environment for the build.
The setenv.sh
contains Linux/Cygwinenvironmental settings that are needed for the build. The specificenvironmental definitions are unique for each board but should include, as aminimum, updates to the PATH
variable to include the full path to the architecture-specifictoolchain identified in Make.defs
. The setenv.sh
only needs to be source'edat the beginning of a session. The system can be re-made subsequently by justtyping make
.
First Time Make. Additionalconfiguration actions will be taken the first time that system is built. Theseadditional steps include:
- Auto-generating the file
include/nuttx/config.h
using the${TOPDIR}/.config
file. - Auto-generating the file
${TOPDIR}/.version
with version 0.0 if one does not exist. - Auto-generating the file
include/nuttx/version.h
using the${TOPDIR}/.version
file. - Creating a link to
${TOPDIR}/arch/
<arch-name>/include
at${TOPDIR}/include/arch
. - Creating a link to
${TOPDIR}/configs/
<board-name>/include
at${TOPDIR}/include/arch/board
. - Creating a link to
${TOPDIR}/configs/
<board-name>/src
at${TOPDIR}/arch/
<arch-name>/src/board
- Creating a link to
${APPDIR}/include
at${TOPDIR}/include/apps
- Creating make dependencies.
http://svn.novatek.com.tw/svn/SP_BSP/trunk/453-bsp/nuttx7.3
目前step:
$ cd tools
$ ./configure.sh../configs/nt72456/nsh/
$ cd ..
$ make V=1
使用os test 程序来测试:
Z:\home\xa00010\nuttx7.3\nuttx\configs\nt7245x\ostest 使用这个配置项来做.
CONFIG_EXAMPLES_OSTEST=y
CONFIG_EXAMPLES_OSTEST_LOOPS=100
CONFIG_EXAMPLES_OSTEST_STACKSIZE=4096
CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS=8
CONFIG_EXAMPLES_OSTEST_RR_RANGE=10000
CONFIG_EXAMPLES_OSTEST_RR_RUNS=10
他会编译Z:\home\xa00010\nuttx7.3\apps\examples\ostest 的app 程序进来,run。
ostest測試的流程
2. 這個 ostest 測試的流程應該沒有用到RR schedule,像是FIFO
3. 目前跑到 user_main測試memory heap 有問題。
當在init task 要結束的時候(又是syscall ...)
在ostest 裡加了2 個task,所以總共有4 個task:init、user_main、mytest1、mytest2。
除了init 執行完會離開之外,其餘3 個都是while (1)
4.增加自己的命令程序方便验证问题
First addsupport to BUILT-IN applications on configs/freedom-kl25z/nsh/defconfig :
CONFIG_BUILTIN=y
CONFIG_NSH_BUILTIN_APPS=y
Also make sureCONFIG_BINFMT_DISABLE is not defined or is defined as NOT :
CONFIG_BINFMT_DISABLE=n
To make ourlife easy just use original “hello” example as base:
$ cd ..
$ cp -a apps/examples/hello apps/examples/myapp
$ cd apps/examples/myapp
$ mv hello_main.c myapp.c
Edit Kconfigfile changing it to reflect your application name:
config EXAMPLES_MYAPP
bool"My First NuttX Application"
default n
---help---
Enable the \"MyAPP\" example
if EXAMPLES_MYAPP
endif
Edit Makefilereplacing APPNAME and CSRCS to reflect our application name:
APPNAME =myapp
CSRCS =myapp.c
Also rememberto edit your myapp.c replacing hello_main by myapp_main.
Editapps/examples/Kconfig and add:
source "$APPSDIR/examples/myapp/Kconfig"
Editapps/examples/Make.defs and add:
ifeq ($(CONFIG_EXAMPLES_MYAPP),y)
CONFIGURED_APPS += examples/myapp
endif
add CONFIG_EXAMPLES_MYAPP=y to .config
5.使用T32debug
1.硬件接口:(1)
参考电压的Pin14是3.3V
2、 打开软件,板子上电后执行system.up
3、菜单 Load elf 文件, 或者使用命令 data.load.elf
4、 添加source code的路径
如图,设置后如果还是没找到状态栏会提示not find,可以copy code到那个路径.
5、设置断点
6. go