Skip to content

Commit

Permalink
Decouple filepaths from rcS/MTD
Browse files Browse the repository at this point in the history
  • Loading branch information
PetervdPerk-NXP committed Feb 13, 2024
1 parent cb09dde commit e1274b9
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 24 deletions.
12 changes: 12 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ menu "Serial ports"
string "EXT2 tty port"
endmenu

menu "File paths"

config BOARD_LOG_DIR
string "Logging directory"
depends on MODULES_LOGGER
default "/fs/microsd"

config BOARD_PARAM_FILE
string "Parameter file"
default "/fs/mtd_params"
endmenu

menu "drivers"
source "src/drivers/Kconfig"
endmenu
Expand Down
6 changes: 6 additions & 0 deletions ROMFS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ add_custom_command(
${romfs_gen_root_dir}/init.d/rc.serial
${romfs_gen_root_dir}/init.d/rc.autostart
${romfs_gen_root_dir}/init.d/rc.autostart.post
${romfs_gen_root_dir}/init.d/rc.filepaths
${romfs_copy_stamp}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${romfs_gen_root_dir}/*
COMMAND ${CMAKE_COMMAND} -E tar xf ${romfs_tar_file}
Expand All @@ -131,6 +132,10 @@ add_custom_command(
--rc-dir ${romfs_gen_root_dir}/init.d
--serial-ports ${board_serial_ports} ${added_arguments}
--config-files ${module_config_files} #--verbose
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/filepaths/generate_config.py
--rc-dir ${romfs_gen_root_dir}/init.d
--log-dir ${CONFIG_BOARD_LOG_DIR}
--params-file ${CONFIG_BOARD_PARAM_FILE}
COMMAND ${CMAKE_COMMAND} -E touch ${romfs_copy_stamp}
WORKING_DIRECTORY ${romfs_gen_root_dir}
DEPENDS ${romfs_tar_file}
Expand Down Expand Up @@ -320,6 +325,7 @@ add_custom_target(romfs_gen_files_target
DEPENDS
${romfs_copy_stamp}
${romfs_gen_root_dir}/init.d/rc.serial
${romfs_gen_root_dir}/init.d/rc.filepaths
romfs_extras.stamp
)

Expand Down
17 changes: 3 additions & 14 deletions ROMFS/cannode/init.d/rcS
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,14 @@ set R /
#
ver all

if mft query -q -k MTD -s MTD_PARAMETERS -v /fs/mtd_params
then
set PARAM_FILE /fs/mtd_params
fi

if mft query -q -k MTD -s MTD_PARAMETERS -v /dev/eeeprom0
then
set PARAM_FILE /dev/eeeprom0
fi

if mft query -q -k MTD -s MTD_PARAMETERS -v /mnt/qspi/params
then
set PARAM_FILE /mnt/qspi/params
fi
# Load param file location from kconfig
. ${R}etc/init.d/rc.filepaths

#
# Load parameters.
#
param select $PARAM_FILE

if ! param load
then
param reset_all
Expand Down
10 changes: 2 additions & 8 deletions ROMFS/px4fmu_common/init.d/rcS
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,8 @@ then
. $FRC
else

#
# Set the parameter file the board supports params on
# MTD device.
#
if mft query -q -k MTD -s MTD_PARAMETERS -v /fs/mtd_params
then
set PARAM_FILE /fs/mtd_params
fi
# Load param file location from kconfig
. ${R}etc/init.d/rc.filepaths

#
# Load parameters.
Expand Down
63 changes: 63 additions & 0 deletions Tools/filepaths/generate_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
""" Script to generate Serial rc.filepaths for the ROMFS startup script """

import argparse
import os
import sys

try:
from jinja2 import Environment, FileSystemLoader
except ImportError as e:
print("Failed to import jinja2: " + str(e))
print("")
print("You may need to install it using:")
print(" pip3 install --user jinja2")
print("")
sys.exit(1)

try:
import yaml
except ImportError as e:
print("Failed to import yaml: " + str(e))
print("")
print("You may need to install it using:")
print(" pip3 install --user pyyaml")
print("")
sys.exit(1)

parser = argparse.ArgumentParser(description='Generate PX4 ROMFS filepaths')

parser.add_argument('--config-files', type=str, nargs='*', default=[],
help='YAML module config file(s)')
parser.add_argument('--constrained-flash', action='store_true',
help='Reduce verbosity in ROMFS scripts to reduce flash size')
parser.add_argument('--rc-dir', type=str, action='store',
help='ROMFS output directory', default=None)
parser.add_argument('--params-file', type=str, action='store',
help='Parameter output file', default=None)
parser.add_argument('--log-dir', type=str, action='store',
help='PX4 dir where flights logs are stored', default=None)
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help='Verbose Output')

args = parser.parse_args()

verbose = args.verbose
constrained_flash = args.constrained_flash
rc_filepaths_output_dir = args.rc_dir
rc_filepaths_template = 'rc.filepaths.jinja'


jinja_env = Environment(loader=FileSystemLoader(
os.path.dirname(os.path.realpath(__file__))))

# generate the ROMFS script using a jinja template
if rc_filepaths_output_dir is not None:
rc_filepath_output_file = os.path.join(rc_filepaths_output_dir, "rc.filepaths")

if verbose: print("Generating {:}".format(rc_filepath_output_file))
template = jinja_env.get_template(rc_filepaths_template)
with open(rc_filepath_output_file, 'w') as fid:
fid.write(template.render(constrained_flash=constrained_flash, params_file=args.params_file, log_dir=args.log_dir))
else:
raise Exception("--rc-dir needs to be specified")
6 changes: 6 additions & 0 deletions Tools/filepaths/rc.filepaths.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{# jinja template to generate the serial autostart script. #}

# serial autostart script generated with generate_serial_config.py


set PARAM_FILE {{ params_file }}
1 change: 1 addition & 0 deletions boards/nxp/mr-canhubk3/default.px4board
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CONFIG_BOARD_TOOLCHAIN="arm-none-eabi"
CONFIG_BOARD_ARCHITECTURE="cortex-m7"
CONFIG_BOARD_ROMFSROOT="cannode"
CONFIG_BOARD_ETHERNET=y
CONFIG_BOARD_PARAM_FILE="/mnt/qspi/params"
CONFIG_DRIVERS_BAROMETER_BMP388=y
CONFIG_DRIVERS_IMU_INVENSENSE_ICM20649=y
CONFIG_DRIVERS_IMU_INVENSENSE_ICM42688P=y
Expand Down
1 change: 1 addition & 0 deletions boards/nxp/ucans32k146/default.px4board
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CONFIG_BOARD_ARCHITECTURE="cortex-m4"
CONFIG_BOARD_ROMFSROOT="cannode"
CONFIG_BOARD_CONSTRAINED_MEMORY=y
CONFIG_BOARD_SERIAL_GPS1="/dev/ttyS1"
CONFIG_BOARD_PARAM_FILE="/dev/eeeprom0"
CONFIG_DRIVERS_BOOTLOADERS=y
CONFIG_COMMON_DISTANCE_SENSOR=y
CONFIG_DRIVERS_GPS=y
Expand Down
4 changes: 2 additions & 2 deletions src/modules/logger/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ class Logger : public ModuleBase<Logger>, public ModuleParams
static constexpr int MAX_MISSION_TOPICS_NUM = 5; /**< Maximum number of mission topics */
static constexpr unsigned MAX_NO_LOGFILE = 999; /**< Maximum number of log files */
static constexpr const char *LOG_ROOT[(int)LogType::Count] = {
PX4_STORAGEDIR "/log",
PX4_STORAGEDIR "/mission_log"
CONFIG_BOARD_LOG_DIR "/log",
CONFIG_BOARD_LOG_DIR "/mission_log"
};

struct LogFileName {
Expand Down

0 comments on commit e1274b9

Please sign in to comment.