mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
config: add dynamic init file
* config: add dynamic init file * added review feedback * added docs
This commit is contained in:
parent
785ea1a137
commit
138427b3a8
5
Kconfig
5
Kconfig
@ -73,6 +73,11 @@ menu "Toolchain"
|
||||
help
|
||||
relative path to the ROMFS root directory
|
||||
|
||||
config BOARD_ADDITIONAL_INIT
|
||||
string "Additional init file"
|
||||
help
|
||||
additional configurable init file to include in the ROMFS
|
||||
|
||||
config BOARD_IO
|
||||
string "IO board name"
|
||||
default "px4_io-v2_default"
|
||||
|
||||
@ -202,6 +202,31 @@ foreach(board_rc_file ${OPTIONAL_BOARD_RC})
|
||||
|
||||
endforeach()
|
||||
|
||||
if(config_additional_init)
|
||||
if(EXISTS "${PX4_BOARD_DIR}/init/${config_additional_init}")
|
||||
file(RELATIVE_PATH rc_file_relative ${PX4_SOURCE_DIR} ${PX4_BOARD_DIR}/init/${config_additional_init})
|
||||
message(STATUS "ROMFS: Adding ${rc_file_relative} -> /etc/init.d/rc.additional_init")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${romfs_gen_root_dir}/init.d/rc.additional_init
|
||||
${config_additional_init}.stamp
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PX4_BOARD_DIR}/init/${config_additional_init} ${romfs_gen_root_dir}/init.d/rc.additional_init
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${config_additional_init}.stamp
|
||||
DEPENDS
|
||||
${PX4_BOARD_DIR}/init/${config_additional_init}
|
||||
romfs_copy.stamp
|
||||
COMMENT "ROMFS: copying ${config_additional_init}"
|
||||
)
|
||||
|
||||
list(APPEND extras_dependencies
|
||||
${config_additional_init}.stamp
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR "BOARD_ADDITIONAL_INIT file not found at: ${PX4_BOARD_DIR}/init/${config_additional_init}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# board extras
|
||||
set(OPTIONAL_BOARD_EXTRAS)
|
||||
|
||||
@ -56,6 +56,17 @@ then
|
||||
fi
|
||||
unset BOARD_RC_DEFAULTS
|
||||
|
||||
#
|
||||
# Optional additional init file: rc.additional_init
|
||||
#
|
||||
set BOARD_RC_ADDITIONAL_INIT ${R}etc/init.d/rc.additional_init
|
||||
if [ -f $BOARD_RC_ADDITIONAL_INIT ]
|
||||
then
|
||||
echo "Board additional init: ${BOARD_RC_ADDITIONAL_INIT}"
|
||||
. $BOARD_RC_ADDITIONAL_INIT
|
||||
fi
|
||||
unset BOARD_RC_ADDITIONAL_INIT
|
||||
|
||||
#
|
||||
# Start system state indicator.
|
||||
#
|
||||
|
||||
@ -217,6 +217,17 @@ else
|
||||
fi
|
||||
unset BOARD_RC_DEFAULTS
|
||||
|
||||
#
|
||||
# Optional additional init file: rc.additional_init
|
||||
#
|
||||
set BOARD_RC_ADDITIONAL_INIT ${R}etc/init.d/rc.additional_init
|
||||
if [ -f $BOARD_RC_ADDITIONAL_INIT ]
|
||||
then
|
||||
echo "Board additional init: ${BOARD_RC_ADDITIONAL_INIT}"
|
||||
. $BOARD_RC_ADDITIONAL_INIT
|
||||
fi
|
||||
unset BOARD_RC_ADDITIONAL_INIT
|
||||
|
||||
# Load airframe configuration based on SYS_AUTOSTART parameter
|
||||
if ! param compare SYS_AUTOSTART 0
|
||||
then
|
||||
|
||||
@ -339,6 +339,11 @@ if(EXISTS ${BOARD_DEFCONFIG})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ADDITIONAL INIT
|
||||
if(ADDITIONAL_INIT)
|
||||
set(config_additional_init ${ADDITIONAL_INIT} CACHE INTERNAL "additional init" FORCE)
|
||||
endif()
|
||||
|
||||
if(UAVCAN_INTERFACES)
|
||||
set(config_uavcan_num_ifaces ${UAVCAN_INTERFACES} CACHE INTERNAL "UAVCAN interfaces" FORCE)
|
||||
endif()
|
||||
|
||||
@ -90,6 +90,8 @@ This is documented below.
|
||||
The best way to customize the system startup is to introduce a [new frame configuration](../dev_airframes/adding_a_new_frame.md).
|
||||
The frame configuration file can be included in the firmware or on an SD Card.
|
||||
|
||||
#### Dynamic customization
|
||||
|
||||
If you only need to "tweak" the existing configuration, such as starting one more application or setting the value of a few parameters, you can specify these by creating two files in the `/etc/` directory of the SD Card:
|
||||
|
||||
- [/etc/config.txt](#customizing-the-configuration-config-txt): modify parameter values
|
||||
@ -106,7 +108,7 @@ If editing on Windows use a suitable editor.
|
||||
These files are referenced in PX4 code as `/fs/microsd/etc/config.txt` and `/fs/microsd/etc/extras.txt`, where the root folder of the microsd card is identified by the path `/fs/microsd`.
|
||||
:::
|
||||
|
||||
#### Customizing the Configuration (config.txt)
|
||||
##### Customizing the Configuration (config.txt)
|
||||
|
||||
The `config.txt` file can be used to modify parameters.
|
||||
It is loaded after the main system has been configured and _before_ it is booted.
|
||||
@ -118,7 +120,7 @@ param set-default PWM_MAIN_DIS3 1000
|
||||
param set-default PWM_MAIN_MIN3 1120
|
||||
```
|
||||
|
||||
#### Starting Additional Applications (extras.txt)
|
||||
##### Starting Additional Applications (extras.txt)
|
||||
|
||||
The `extras.txt` can be used to start additional applications after the main system boot.
|
||||
Typically these would be payload controllers or similar optional custom components.
|
||||
@ -145,3 +147,28 @@ The following example shows how to start custom applications:
|
||||
|
||||
mandatory_app start # Will abort boot if mandatory_app is unknown or fails
|
||||
```
|
||||
|
||||
#### Additional customization
|
||||
|
||||
In rare cases where the desired setup cannot be achieved through frame configuration or dynamic customization,
|
||||
you can add a script that will be contained in the binary.
|
||||
|
||||
**Note**: In almost all cases, you should use a frame configuration. This method should only be used for
|
||||
edge-cases such as customizing `cannode` based boards.
|
||||
|
||||
- Add a new init script in `boards/<vendor>/<board>/init` that will run during board startup. For example:
|
||||
```sh
|
||||
# File: boards/<vendor>/<board>/init/rc.additional
|
||||
param set-default <param> <value>
|
||||
```
|
||||
|
||||
- Add a new board variant in `boards/<vendor>/<board>/<variant>.px4board` that includes the additional script. For example:
|
||||
```sh
|
||||
# File: boards/<vendor>/<board>/var.px4board
|
||||
CONFIG_BOARD_ADDITIONAL_INIT="rc.additional"
|
||||
```
|
||||
|
||||
- Compile the firmware with your new variant by appending the variant name to the compile target. For example:
|
||||
```sh
|
||||
make <target>_var
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user