编译部分暂时放放,先看px4如何工作的。
px4是有rootfs的,rootfs的启动在rsS上,即px4如何启动/工作可以从rcS上看出来,所以先看rcS。
显示版本
ver all
51 /* string constants for version commands */
52 static const char sz_ver_hw_str[] = "hw";
53 static const char sz_ver_hwcmp_str[] = "hwcmp";
54 static const char sz_ver_hwtypecmp_str[] = "hwtypecmp";
55 static const char sz_ver_git_str[] = "git";
56 static const char sz_ver_bdate_str[] = "bdate";
57 static const char sz_ver_buri_str[] = "uri";
58 static const char sz_ver_gcc_str[] = "gcc";
59 static const char sz_ver_all_str[] = "all";
60 static const char mcu_ver_str[] = "mcu";
61 static const char px4_guid_str[] = "px4guid";
这个没啥说的
sdcard的处理
45 # Try to mount the microSD card.
46 #
47 if [ -b "/dev/mmcsd0" ]
48 then
49 if mount -t vfat /dev/mmcsd0 /fs/microsd
50 then
51 if [ -f "/fs/microsd/.format" ]
52 then
53 echo "INFO [init] format /dev/mmcsd0 requested (/fs/microsd/.format)"
54 set SDCARD_FORMAT yes
55 rm /fs/microsd/.format
56 umount /fs/microsd
57
58 else
59 set SDCARD_AVAILABLE yes
60 fi
61 fi
62
63 if [ $SDCARD_AVAILABLE = no -o $SDCARD_FORMAT = yes ]
64 then
65 echo "INFO [init] formatting /dev/mmcsd0"
66 set STARTUP_TUNE 15 # tune 15 = SD_ERROR (overridden to SD_INIT if format + mount succeeds)
67
68 if mkfatfs -F 32 /dev/mmcsd0
69 then
70 echo "INFO [init] card formatted"
71
72 if mount -t vfat /dev/mmcsd0 /fs/microsd
73 then
74 set SDCARD_AVAILABLE yes
75 set STARTUP_TUNE 14 # tune 14 = SD_INIT
76 else
77 echo "ERROR [init] card mount failed"
78 fi
79 else
80 echo "ERROR [init] format failed"
81 fi
82 fi
83
84 if [ $SDCARD_AVAILABLE = yes ]
85 then
86 if hardfault_log check
87 then
88 set STARTUP_TUNE 2 # tune 2 = ERROR_TUNE
89 if hardfault_log commit
90 then
91 hardfault_log reset
92 fi
93 fi
94 fi
95
96 set PARAM_FILE /fs/microsd/params
97 set PARAM_BACKUP_FILE "/fs/microsd/parameters_backup.bson"
98 fi
- 检查
块设备
/dev/mmcsd0。 - 尝试挂载/dev/mmcsd0到/fs/microsd。
- 尝试检查/fs/microsd/.format。没找到的话设置
SDCARD_AVAILABLE
为yes
(默认为no
)。否则设置SDCARD_FORMAT
为yes
(默认为no
)。 - 根据
SDCARD_AVAILABLE
和SDCARD_FORMAT
的值做后续处理。
最终需要SDCARD_AVAILABLE
为yes
才行。
在SDCARD处理的最后,SDCARD_AVAILABLE
为yes
时,会有hardfault相关处理(具体作用目前不明)。
最最后,设置变量 PARAM_FILE PARAM_BACKUP_FILE
。
启动 启动脚本
sdcard上的启动脚本
104 if [ -f $FRC ]
105 then
106 . $FRC
set FRC /fs/microsd/etc/rc.txt
不使用sdcard上的启动脚本
小工具
mft
参数检查工具,支持的参数有:
- -q slient
- -k type 带查询的参数的分类——推测。
- -s 参数名称
- -v 参数值
例如mft query -q -k MTD -s MTD_CALDATA -v /fs/mtd_caldata
,意思是检查MTD
类型的参数MTD_CALDATA
是否为/fs/mtd_caldata
。
param
参数工具——通过shell或脚本访问和操作参数。
支持的参数有:
- load: Load params from a file (overwrite all);
A. "<file>", "File name (use default if not given)" - import:Import params from a file
A. "<file>", "File name (use default if not given)" - save:Save params to a file
A. "<file>", "File name (use default if not given)" - dump:Dump params from a file
"<file>", "File name (use default if not given)" - select:Select default file
"<file>", "File name" - select-backup:Select default file
"<file>", "File name" - show:Show parameter values
'a', "Show all parameters (not just used)"
'c', "Show only changed params (unused too)"
'q', "quiet mode, print only param value (name needs to be exact)"
"<filter>", "Filter by param name (wildcard at end allowed, eg. sys_*)" - show-for-airframe:Show changed params for airframe config
- status:Print status of parameter system
- set:Set parameter to a value
"<param_name> <value>", "Parameter name and value to set"
"fail", "If provided, let the command fail if param is not found" - set-default:Set parameter default to a value
's', "If provided, silent errors if parameter doesn't exists"
"<param_name> <value>", "Parameter name and value to set"
"fail", "If provided, let the command fail if param is not found" - compare:Compare a param with a value. Command will succeed if equal
's', "If provided, silent errors if parameter doesn't exists"
"<param_name> <value>", "Parameter name and value to compare" - greater:"Compare a param with a value. Command will succeed if param is greater than the value"
's', "If provided, silent errors if parameter doesn't exists"
"<param_name> <value>", "Parameter name and value to compare"
"<param_name> <value>", "Parameter name and value to compare" - touch:Mark a parameter as used
"<param_name1> [<param_name2>]", "Parameter name (one or more)" - reset:Reset only specified params to default
"<param1> [<param2>]", "Parameter names to reset (wildcard at end allowed)" - reset_all:Reset all params to default
"<exclude1> [<exclude2>]", "Do not reset matching params (wildcard at end allowed)" - index:Show param for a given index
"<index>", "Index: an integer >= 0" - index_used:Show used param for a given index
"<index>", "Index: an integer >= 0" - find:Show index of a param
"<param>", "param name"
ver
Tool to print various version information
- hw:Hardware architecture
- mcu:MCU info
- git:git version information
- bdate:Build date and time
- gcc:Compiler info
- bdate:Build date and time
- px4guid:PX4 GUID
- uri:Build URI
- hwcmp:Compare hardware version (returns 0 on match)
"<hw> [<hw2>]","Hardware to compare against (eg. PX4_FMU_V4). An OR comparison is used if multiple are specified" - hwtypecmp:Compare hardware type (returns 0 on match)
"<hwtype> [<hwtype2>]","Hardware type to compare against (eg. V2). An OR comparison is used if multiple are specified"
netman
- show:Display the current persistent network settings to the console.
- update:Check SD card for net.cfg and update network persistent network settings.
'i', "eth0","Set the interface name" - save:Save the current network parameters to the SD card.
开始启动
109 #
110 # Set the parameter file the board supports params on
111 # MTD device.
112 #
113 if mft query -q -k MTD -s MTD_PARAMETERS -v /fs/mtd_params
114 then
115 set PARAM_FILE /fs/mtd_params
116 fi
如果MTD_PARAMETERS
等于/fs/mtd_params
,则修改PARAM_FILE
为/fs/mtd_params
(该变量在SDCARD初始化后为/fs/microsd/params
,即参数文件原先默认是在SDCARD上,这里改为从mtd设备上取参数文件)。
118 #
119 # Load parameters.
120 #
121 # if the board has a storage for (factory) calibration data
122 if mft query -q -k MTD -s MTD_CALDATA -v /fs/mtd_caldata
123 then
124 param load /fs/mtd_caldata
125 fi
检查是否有板载校验数据,有的话载入。
127 param select $PARAM_FILE
128 if ! param import
129 then
130 +--- 28 行: echo "ERROR [init] param import failed"-------------------------------------------------------------------------------------------------------------------------------------------------------------
158 fi
select
参数文件,失败的情况不看。
160 if [ $SDCARD_AVAILABLE = yes ]
161 then
162 param select-backup $PARAM_BACKUP_FILE
163 fi
如果SDCARD有效的话,选中备份文件。
165 if ver hwcmp PX4_FMU_V5X PX4_FMU_V6X
166 then
167 netman update -i eth0
168 fi
如果硬件版本是V5X或者V6X
则设置网卡名称eth0
。
170 #
171 # If the airframe has been previously reset SYS_AUTCONFIG will have been set to 1 and other params will be reset on the next boot.
172 #
173 if param greater SYS_AUTOCONFIG 0
174 then
175 # Reset params except Airframe, RC calibration, sensor calibration, flight modes, total flight time, and next flight UUID.
176 param reset_all SYS_AUTOSTART RC* CAL_* COM_FLTMODE* LND_FLIGHT* TC_* COM_FLIGHT*
177 fi
如果参数 SYS_AUTOCONFIG大于 0,则重置SYS_AUTOSTART RC* CAL_* COM_FLTMODE* LND_FLIGHT* TC_* COM_FLIGHT*
这些参数(*是通配符)
179 #
180 # Optional board architecture defaults: rc.board_arch_defaults
181 #
182 set BOARD_ARCH_RC_DEFAULTS ${R}etc/init.d/rc.board_arch_defaults
183 if [ -f $BOARD_ARCH_RC_DEFAULTS ]
184 then
185 echo "Board architecture defaults: ${BOARD_ARCH_RC_DEFAULTS}"
186 . $BOARD_ARCH_RC_DEFAULTS
187 fi
188 unset BOARD_ARCH_RC_DEFAULTS
如果有${R}etc/init.d/rc.board_arch_defaults
则source一下。
190 #
191 # Optional board defaults: rc.board_defaults
192 #
193 set BOARD_RC_DEFAULTS ${R}etc/init.d/rc.board_defaults
194 if [ -f $BOARD_RC_DEFAULTS ]
195 then
196 echo "Board defaults: ${BOARD_RC_DEFAULTS}"
197 . $BOARD_RC_DEFAULTS
198 fi
199 unset BOARD_RC_DEFAULTS
如果${R}etc/init.d/rc.board_defaults
存在,则source一下。
201 #
202 # Set parameters and env variables for selected SYS_AUTOSTART.
203 #
204 set AUTOSTART_PATH etc/init.d/rc.autostart
205 if ! param compare SYS_AUTOSTART 0
206 then
207 if param greater SYS_AUTOSTART 1000000
208 then
209 # Use external startup file
210 if [ $SDCARD_AVAILABLE = yes ]
211 then
212 set AUTOSTART_PATH etc/init.d/rc.autostart_ext
213 else
214 echo "ERROR [init] SD card not mounted - trying to load airframe from ROMFS"
215 fi
216 fi
217 . ${R}$AUTOSTART_PATH
218 fi
219 unset AUTOSTART_PATH
如果参数SYS_AUTOSTART
不等于0,并且大于1000000则尝试加载自动启动脚本。
222 # Start the tone_alarm driver.
223 # Needs to be started after the parameters are loaded (for CBRK_BUZZER).
224 #
225 tone_alarm start
不知道是啥,估计跟警报有关。
227 #
228 # Waypoint storage.
229 # REBOOTWORK this needs to start in parallel.
230 #
231 if param compare -s SYS_DM_BACKEND 1
232 then
233 dataman start -r
234 else
235 if param compare SYS_DM_BACKEND 0
236 then
237 # dataman start default
238 dataman start
239 fi
240 fi
dataman启动。下面是dataman的描述。
Description
Module to provide persistent storage for the rest of the system in form of a simple database through a C API.
Multiple backends are supported:
- a file (eg. on the SD card)
- RAM (this is obviously not persistent)
It is used to store structured data of different types: mission waypoints, mission state and geofence polygons.
Each type has a specific type and a fixed maximum amount of storage items, so that fast random access is possible.
242 #
243 # Start the socket communication send_event handler.
244 #
245 send_event start
启动send_event,下面是描述。
Description
Background process running periodically on the LP work queue to perform housekeeping tasks.
It is currently only responsible for tone alarm on RC Loss.
The tasks can be started via CLI or uORB topics (vehicle_command from MAVLink, etc.).
247 #
248 # Start the resource load monitor.
249 #
250 load_mon start
启动load_mon,描述如下:
Description
Background process running periodically on the low priority work queue to calculate the CPU load and RAM
usage and publish thecpuload
topic.
On NuttX it also checks the stack usage of each process and if it falls below 300 bytes, a warning is output,
which will also appear in the log file.
252 #
253 # Start system state indicator.
254 #
255 rgbled start -X -q
256 rgbled_ncp5623c start -X -q
启动3色led,指示系统状态。led初步看是I2C设备。
258 #
259 # Override parameters from user configuration file.
260 #
261 if [ -f $FCONFIG ]
262 then
263 echo "Custom: ${FCONFIG}"
264 . $FCONFIG
265 fi
set FCONFIG /fs/microsd/etc/config.txt
如果卡上有配置文件,就source一下。
267 #
268 # Check if UAVCAN is enabled, default to it for ESCs.
269 #
270 if param greater -s UAVCAN_ENABLE 0
271 then
272 # Start core UAVCAN module.
273 if ! uavcan start
274 then
275 tune_control play error
276 fi
277 else
278 if param greater -s CYPHAL_ENABLE 0
279 then
280 cyphal start
281 fi
282 fi
检查参数UAVCAN_ENABLE CYPHAL_ENABLE,优先启动uavcan,否则启动cyphal。
tune_control用于发送警告或者通知
uavcan作用未知
cyphal作用未知
这部分作用估计是控制电调 —— ESC。