From e1274b9c6a4059dd8929361b6aac6fc780b8630b Mon Sep 17 00:00:00 2001 From: Peter van der Perk Date: Wed, 26 Jul 2023 18:55:38 +0200 Subject: [PATCH] Decouple filepaths from rcS/MTD --- Kconfig | 12 +++++ ROMFS/CMakeLists.txt | 6 +++ ROMFS/cannode/init.d/rcS | 17 ++----- ROMFS/px4fmu_common/init.d/rcS | 10 +--- Tools/filepaths/generate_config.py | 63 +++++++++++++++++++++++++ Tools/filepaths/rc.filepaths.jinja | 6 +++ boards/nxp/mr-canhubk3/default.px4board | 1 + boards/nxp/ucans32k146/default.px4board | 1 + src/modules/logger/logger.h | 4 +- 9 files changed, 96 insertions(+), 24 deletions(-) create mode 100755 Tools/filepaths/generate_config.py create mode 100644 Tools/filepaths/rc.filepaths.jinja diff --git a/Kconfig b/Kconfig index 6427534f91f8..08d23c22028f 100644 --- a/Kconfig +++ b/Kconfig @@ -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 diff --git a/ROMFS/CMakeLists.txt b/ROMFS/CMakeLists.txt index 532b659b05e0..97a15d61be7b 100644 --- a/ROMFS/CMakeLists.txt +++ b/ROMFS/CMakeLists.txt @@ -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} @@ -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} @@ -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 ) diff --git a/ROMFS/cannode/init.d/rcS b/ROMFS/cannode/init.d/rcS index 0d9da3a10afc..96edd27ead1b 100644 --- a/ROMFS/cannode/init.d/rcS +++ b/ROMFS/cannode/init.d/rcS @@ -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 diff --git a/ROMFS/px4fmu_common/init.d/rcS b/ROMFS/px4fmu_common/init.d/rcS index 49b062909d06..1381b63d9e85 100644 --- a/ROMFS/px4fmu_common/init.d/rcS +++ b/ROMFS/px4fmu_common/init.d/rcS @@ -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. diff --git a/Tools/filepaths/generate_config.py b/Tools/filepaths/generate_config.py new file mode 100755 index 000000000000..c246c723d5a2 --- /dev/null +++ b/Tools/filepaths/generate_config.py @@ -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") diff --git a/Tools/filepaths/rc.filepaths.jinja b/Tools/filepaths/rc.filepaths.jinja new file mode 100644 index 000000000000..30a2c2cce643 --- /dev/null +++ b/Tools/filepaths/rc.filepaths.jinja @@ -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 }} diff --git a/boards/nxp/mr-canhubk3/default.px4board b/boards/nxp/mr-canhubk3/default.px4board index 277c62de7889..4f551cbec644 100644 --- a/boards/nxp/mr-canhubk3/default.px4board +++ b/boards/nxp/mr-canhubk3/default.px4board @@ -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 diff --git a/boards/nxp/ucans32k146/default.px4board b/boards/nxp/ucans32k146/default.px4board index f9530438758b..45430b9c51b9 100644 --- a/boards/nxp/ucans32k146/default.px4board +++ b/boards/nxp/ucans32k146/default.px4board @@ -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 diff --git a/src/modules/logger/logger.h b/src/modules/logger/logger.h index 9b468010997f..b43cadf97d82 100644 --- a/src/modules/logger/logger.h +++ b/src/modules/logger/logger.h @@ -158,8 +158,8 @@ class Logger : public ModuleBase, 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 {