rcS: fine-grained storage settings

This commit is contained in:
alexcekay 2026-03-13 16:50:10 +01:00 committed by Alexander Lerach
parent 0954e43708
commit 20cad48707
4 changed files with 123 additions and 51 deletions

View File

@ -193,6 +193,7 @@ endif()
# board custom init files # board custom init files
set(OPTIONAL_BOARD_RC) set(OPTIONAL_BOARD_RC)
list(APPEND OPTIONAL_BOARD_RC list(APPEND OPTIONAL_BOARD_RC
rc.board_early
rc.board_defaults rc.board_defaults
rc.board_sensors rc.board_sensors
rc.board_extras rc.board_extras

View File

@ -31,11 +31,20 @@ set PARAM_FILE ""
set PARAM_BACKUP_FILE "" set PARAM_BACKUP_FILE ""
set RC_INPUT_ARGS "" set RC_INPUT_ARGS ""
set STORAGE_AVAILABLE no set STORAGE_AVAILABLE no
set STORAGE_CHECK yes
set SDCARD_EXT_PATH /fs/microsd/ext_autostart set SDCARD_EXT_PATH /fs/microsd/ext_autostart
set SDCARD_FORMAT no set SDCARD_FORMAT no
set STARTUP_TUNE 1 set STARTUP_TUNE 1
set VEHICLE_TYPE none set VEHICLE_TYPE none
# Fine-grained feature gates.
set USE_HARDFAULT_LOG no
set USE_EXTERNAL_AIRFRAMES no
set USE_PARAM_BACKUPS no
set USE_PARAM_IMPORT_DEBUG no
set USE_TASK_WATCHDOG no
set USE_ALT_UPDATE_DIRS no
# Airframe parameter versioning # Airframe parameter versioning
# Value set to 1 by default but can optionally be overridden in the airframe configuration startup script. # Value set to 1 by default but can optionally be overridden in the airframe configuration startup script.
# Airframe maintainers can ensure a reset to the airframe defaults during an update by increasing by one. # Airframe maintainers can ensure a reset to the airframe defaults during an update by increasing by one.
@ -48,10 +57,26 @@ set PARAM_DEFAULTS_VER 1
ver all ver all
# #
# Try to mount the microSD card. # Optional early board init: rc.board_early
# Can be used for setting env vars for rcS.
# #
if [ -b "/dev/mmcsd0" ] set BOARD_RC_EARLY ${R}etc/init.d/rc.board_early
if [ -f $BOARD_RC_EARLY ]
then then
. $BOARD_RC_EARLY
fi
unset BOARD_RC_EARLY
#
# Try to mount/check storage (rc.board_early can disable this).
#
if [ $STORAGE_CHECK = yes ]
then
#
# Try to mount the microSD card.
#
if [ -b "/dev/mmcsd0" ]
then
if mount -t vfat /dev/mmcsd0 /fs/microsd if mount -t vfat /dev/mmcsd0 /fs/microsd
then then
if [ -f "/fs/microsd/.format" ] if [ -f "/fs/microsd/.format" ]
@ -86,15 +111,27 @@ then
echo "ERROR [init] format failed" echo "ERROR [init] format failed"
fi fi
fi fi
else else
# Is there a device mounted for storage # Is there a device mounted for storage
if mft query -q -k MTD -s MTD_PARAMETERS -v /mnt/microsd if mft query -q -k MTD -s MTD_PARAMETERS -v /mnt/microsd
then then
set STORAGE_AVAILABLE yes set STORAGE_AVAILABLE yes
fi fi
fi
fi fi
if [ $STORAGE_AVAILABLE = yes ] if [ $STORAGE_AVAILABLE = yes ]
then
set USE_HARDFAULT_LOG yes
set USE_EXTERNAL_AIRFRAMES yes
set USE_PARAM_BACKUPS yes
set USE_PARAM_IMPORT_DEBUG yes
set USE_ALT_UPDATE_DIRS yes
set PARAM_FILE /fs/microsd/params
set PARAM_BACKUP_FILE "/fs/microsd/parameters_backup.bson"
fi
if [ $USE_HARDFAULT_LOG = yes ]
then then
if hardfault_log check if hardfault_log check
then then
@ -104,7 +141,15 @@ then
hardfault_log reset hardfault_log reset
fi fi
fi fi
fi
if [ $USE_TASK_WATCHDOG = yes ]
then
task_watchdog start
fi
if [ $USE_ALT_UPDATE_DIRS = yes ]
then
# Check for an update of the ext_autostart folder, and replace the old one with it # Check for an update of the ext_autostart folder, and replace the old one with it
if [ -e /fs/microsd/ext_autostart_new ] if [ -e /fs/microsd/ext_autostart_new ]
then then
@ -112,9 +157,6 @@ then
rm -r $SDCARD_EXT_PATH rm -r $SDCARD_EXT_PATH
mv /fs/microsd/ext_autostart_new $SDCARD_EXT_PATH mv /fs/microsd/ext_autostart_new $SDCARD_EXT_PATH
fi fi
set PARAM_FILE /fs/microsd/params
set PARAM_BACKUP_FILE "/fs/microsd/parameters_backup.bson"
fi fi
# #
@ -155,8 +197,11 @@ else
if [ -d "/fs/microsd" ] if [ -d "/fs/microsd" ]
then then
# try to make a backup copy if [ $USE_PARAM_IMPORT_DEBUG = yes ]
then
# save copy of the failed param file for debugging
cp $PARAM_FILE /fs/microsd/param_import_fail.bson cp $PARAM_FILE /fs/microsd/param_import_fail.bson
fi
# try importing from backup file # try importing from backup file
if [ -f $PARAM_BACKUP_FILE ] if [ -f $PARAM_BACKUP_FILE ]
@ -174,11 +219,14 @@ else
param status param status
if [ $USE_PARAM_IMPORT_DEBUG = yes ]
then
dmesg >> /fs/microsd/param_import_fail.txt & dmesg >> /fs/microsd/param_import_fail.txt &
fi fi
fi fi
fi
if [ $STORAGE_AVAILABLE = yes ] if [ $USE_PARAM_BACKUPS = yes ]
then then
param select-backup $PARAM_BACKUP_FILE param select-backup $PARAM_BACKUP_FILE
fi fi
@ -234,12 +282,12 @@ else
if [ ${VEHICLE_TYPE} = none ] if [ ${VEHICLE_TYPE} = none ]
then then
# Run external airframe script on SD card # Run external airframe script on SD card or EEPROM-backed storage
if [ $STORAGE_AVAILABLE = yes ] if [ $USE_EXTERNAL_AIRFRAMES = yes ]
then then
. ${R}etc/init.d/rc.autostart_ext . ${R}etc/init.d/rc.autostart_ext
else else
echo "ERROR [init] SD not mounted, skipping external airframe" echo "ERROR [init] no external airframe storage, skipping"
fi fi
fi fi
@ -679,9 +727,16 @@ unset PARAM_BACKUP_FILE
unset PARAM_DEFAULTS_VER unset PARAM_DEFAULTS_VER
unset RC_INPUT_ARGS unset RC_INPUT_ARGS
unset STORAGE_AVAILABLE unset STORAGE_AVAILABLE
unset STORAGE_CHECK
unset SDCARD_EXT_PATH unset SDCARD_EXT_PATH
unset SDCARD_FORMAT unset SDCARD_FORMAT
unset STARTUP_TUNE unset STARTUP_TUNE
unset USE_HARDFAULT_LOG
unset USE_EXTERNAL_AIRFRAMES
unset USE_PARAM_BACKUPS
unset USE_PARAM_IMPORT_DEBUG
unset USE_TASK_WATCHDOG
unset USE_ALT_UPDATE_DIRS
unset VEHICLE_TYPE unset VEHICLE_TYPE
# #

View File

@ -34,8 +34,5 @@ nshterm /dev/ttyS3 &
# Start the time_persistor to cyclically store the RTC in FRAM # Start the time_persistor to cyclically store the RTC in FRAM
time_persistor start time_persistor start
# Start the task_watchdog as we do not have the logger watchdog
task_watchdog start
# Start the ESC telemetry # Start the ESC telemetry
dshot telemetry -d /dev/ttyS5 -x dshot telemetry -d /dev/ttyS5 -x

View File

@ -0,0 +1,19 @@
#!/bin/sh
#
# Board early init.
#
# On FRAM boards STORAGE_AVAILABLE=yes will set the USE_* flags. Additional
# enable required for task watchdog as this is not a generally used feature.
# On EEPROM boards: Only airframes and params are needed.
#
if mft query -q -k MTD -s MTD_PARAMETERS -v /mnt/microsd
then
# Start the task_watchdog as we do not have the logger watchdog
set USE_TASK_WATCHDOG yes
else
set PARAM_FILE /fs/microsd/params
set STORAGE_CHECK no
set USE_EXTERNAL_AIRFRAMES yes
set USE_ALT_UPDATE_DIRS yes
fi