Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple filepaths from rcS/MTD using Kconfig rootpath #23003

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
11 changes: 11 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ menu "Serial ports"
string "EXT2 tty port"
endmenu

menu "File paths"

config BOARD_ROOT_PATH
string "PX4 Root file path"
default "/fs/microsd"

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

menu "drivers"
source "src/drivers/Kconfig"
endmenu
Expand Down
5 changes: 5 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,9 @@ 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
--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 +324,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
61 changes: 61 additions & 0 deletions Tools/filepaths/generate_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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('-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))
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 }}
2 changes: 2 additions & 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 All @@ -16,6 +17,7 @@ CONFIG_SYSTEMCMDS_I2CDETECT=y
CONFIG_SYSTEMCMDS_LED_CONTROL=y
CONFIG_SYSTEMCMDS_MFT=y
CONFIG_SYSTEMCMDS_MTD=y
CONFIG_SYSTEMCMDS_NETMAN=y
CONFIG_SYSTEMCMDS_PARAM=y
CONFIG_SYSTEMCMDS_REBOOT=y
CONFIG_SYSTEMCMDS_SD_BENCH=y
Expand Down
1 change: 0 additions & 1 deletion boards/nxp/mr-canhubk3/fmu.px4board
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_HARDFAULT_LOG=y
CONFIG_SYSTEMCMDS_NETMAN=y
CONFIG_SYSTEMCMDS_NSHTERM=y
CONFIG_SYSTEMCMDS_PERF=y
CONFIG_SYSTEMCMDS_REFLECT=y
Expand Down
6 changes: 6 additions & 0 deletions boards/nxp/mr-canhubk3/init/rc.board_defaults
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ then
safety_button start
fi

if [ -f "/mnt/qspi/mtd_net" ]
then
else
netman update -i eth0
fi

if param greater -s UAVCAN_ENABLE 0
then
ifup can0
Expand Down
1 change: 0 additions & 1 deletion boards/nxp/mr-canhubk3/sysview.px4board
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_HARDFAULT_LOG=y
CONFIG_SYSTEMCMDS_NETMAN=y
CONFIG_SYSTEMCMDS_NSHTERM=y
CONFIG_SYSTEMCMDS_PERF=y
CONFIG_SYSTEMCMDS_REFLECT=y
Expand Down
1 change: 0 additions & 1 deletion boards/nxp/mr-canhubk3/zenoh.px4board
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_HARDFAULT_LOG=y
CONFIG_SYSTEMCMDS_NETMAN=y
CONFIG_SYSTEMCMDS_NSHTERM=y
CONFIG_SYSTEMCMDS_PERF=y
CONFIG_SYSTEMCMDS_REFLECT=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
1 change: 1 addition & 0 deletions boards/px4/sitl/default.px4board
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CONFIG_PLATFORM_POSIX=y
CONFIG_BOARD_TESTING=y
CONFIG_BOARD_ETHERNET=y
CONFIG_BOARD_ROOT_PATH="./"
CONFIG_DRIVERS_CAMERA_TRIGGER=y
CONFIG_DRIVERS_GPS=y
CONFIG_DRIVERS_OSD_MSP_OSD=y
Expand Down
1 change: 0 additions & 1 deletion boards/px4/sitl/zenoh.px4board
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
CONFIG_MODULES_UXRCE_DDS_CLIENT=n
CONFIG_MODULES_ZENOH=y
CONFIG_ZENOH_CONFIG_PATH="./zenoh"
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
# else
/* Use PX4IO FW search paths defaults based on version */
# if BOARD_USES_PX4IO_VERSION == 2
# define PX4IO_FW_SEARCH_PATHS {"/etc/extras/px4_io-v2_default.bin","/fs/microsd/px4_io-v2_default.bin", "/fs/microsd/px4io2.bin", nullptr }
# define PX4IO_FW_SEARCH_PATHS {"/etc/extras/px4_io-v2_default.bin",CONFIG_BOARD_ROOT_PATH "/px4_io-v2_default.bin", CONFIG_BOARD_ROOT_PATH "/px4io2.bin", nullptr }
# endif
# endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion platforms/common/include/px4_platform_common/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static inline constexpr bool PX4_ISFINITE(double x) { return __builtin_isfinite(
****************************************************************************/

#define PX4_ROOTFSDIR ""
#define PX4_STORAGEDIR PX4_ROOTFSDIR "/fs/microsd"
#define PX4_STORAGEDIR PX4_ROOTFSDIR CONFIG_BOARD_ROOT_PATH
#define _PX4_IOC(x,y) _IOC(x,y)

// mode for open with O_CREAT
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/tap_esc/tap_esc_uploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <stdbool.h>
#include <systemlib/mavlink_log.h>

#define TAP_ESC_FW_SEARCH_PATHS {"/etc/extras/tap_esc.bin", "/fs/microsd/tap_esc.bin", nullptr }
#define TAP_ESC_FW_SEARCH_PATHS {"/etc/extras/tap_esc.bin", CONFIG_BOARD_ROOT_PATH "/tap_esc.bin", nullptr }
#define PROTO_SUPPORT_BL_REV 5 /**< supported bootloader protocol revision */
#define SYNC_RETRY_TIMES 5 /**< (uint8) esc sync failed allow retry times*/
#define UPLOADER_RETRY_TIMES 2 /**< esc uploader failed allow retry times*/
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/uavcan/uavcan_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

// firmware paths
#define UAVCAN_MAX_PATH_LENGTH (128 + 40)
#define UAVCAN_SD_ROOT_PATH "/fs/microsd/"
#define UAVCAN_SD_ROOT_PATH CONFIG_BOARD_ROOT_PATH "/"
#define UAVCAN_FIRMWARE_PATH UAVCAN_SD_ROOT_PATH"ufw"
#define UAVCAN_ROMFS_FW_PATH "/etc/uavcan/fw"
#define UAVCAN_ROMFS_FW_PREFIX "_"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/rc/rc_tests/RCTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#if defined(CONFIG_ARCH_BOARD_PX4_SITL)
#define TEST_DATA_PATH "./test_data/"
#else
#define TEST_DATA_PATH "/fs/microsd"
#define TEST_DATA_PATH CONFIG_BOARD_ROOT_PATH
#endif

extern "C" __EXPORT int rc_tests_main(int argc, char *argv[]);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/systemlib/hardfault_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ typedef struct ssarc_s dump_s;
* Specifier to the xxxx_NUM definei.e %Y is YYYY so add 2 and %s is -2
* Also xxxxTIME_FMT need to match in size. See CCASERT in hardfault_log.c
*/
#define LOG_PATH_BASE "/fs/microsd/"
#define LOG_PATH_BASE CONFIG_BOARD_ROOT_PATH "/"
#define LOG_PATH_BASE_LEN ((arraySize(LOG_PATH_BASE))-1)

#define LOG_NAME_FMT "fault_%s.log"
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_ROOT_PATH "/log",
CONFIG_BOARD_ROOT_PATH "/mission_log"
};

struct LogFileName {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mavlink/mavlink_ftp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ bool MavlinkFTP::_validatePathIsWritable(const char *path)
// Don't allow writes to system paths as they are in RAM
// Ideally we'd canonicalize the path (with 'realpath'), but it might not exist, so realpath() would fail.
// The next simpler thing is to check there's no reference to a parent dir.
if (strncmp(path, "/fs/microsd/", 12) != 0 || strstr(path, "/../") != nullptr) {
if (strncmp(path, CONFIG_BOARD_ROOT_PATH "/", 12) != 0 || strstr(path, "/../") != nullptr) {
PX4_ERR("Disallowing write to %s", path);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mavlink/mavlink_tests/mavlink_ftp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "../mavlink_ftp.h"

#ifdef __PX4_NUTTX
#define PX4_MAVLINK_TEST_DATA_DIR "/fs/microsd/ftp_unit_test_data"
#define PX4_MAVLINK_TEST_DATA_DIR CONFIG_BOARD_ROOT_PATH "/ftp_unit_test_data"
#else
#define PX4_MAVLINK_TEST_DATA_DIR "ftp_unit_test_data"
#endif
Expand Down
6 changes: 0 additions & 6 deletions src/modules/zenoh/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ menuconfig MODULES_ZENOH
Enable support for Zenoh

if MODULES_ZENOH
config ZENOH_CONFIG_PATH
string "Config path"
default "/fs/microsd/zenoh"
help
Path to store network, publishers and subscribers configuration

config ZENOH_DEBUG
int "Zenoh debug level"
default 0
Expand Down
6 changes: 3 additions & 3 deletions src/modules/zenoh/zenoh_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const char *default_sub_config = ""; //TODO maybe use YAML
Zenoh_Config::Zenoh_Config()
{
bool correct_config = true;
DIR *dir = opendir(ZENOH_SD_ROOT_PATH);
DIR *dir = opendir(ZENOH_ROOT_PATH);
fp_mapping = NULL;

if (dir) {
Expand Down Expand Up @@ -342,14 +342,14 @@ void Zenoh_Config::generate_clean_config()
printf("Generate clean\n");
FILE *fp;

DIR *dir = opendir(ZENOH_SD_ROOT_PATH);
DIR *dir = opendir(ZENOH_ROOT_PATH);

if (dir) {
printf("Zenoh directory exists\n");

} else {
/* Create zenoh dir. */
if (mkdir(ZENOH_SD_ROOT_PATH, 0700) < 0) {
if (mkdir(ZENOH_ROOT_PATH, 0700) < 0) {
printf("Failed to create Zenoh directory\n");
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/modules/zenoh/zenoh_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
#include <zenoh-pico.h>

#define ZENOH_MAX_PATH_LENGTH (128 + 40)
#define ZENOH_SD_ROOT_PATH CONFIG_ZENOH_CONFIG_PATH
#define ZENOH_PUB_CONFIG_PATH ZENOH_SD_ROOT_PATH"/pub.csv"
#define ZENOH_SUB_CONFIG_PATH ZENOH_SD_ROOT_PATH"/sub.csv"
#define ZENOH_NET_CONFIG_PATH ZENOH_SD_ROOT_PATH"/net.txt"
#define ZENOH_ROOT_PATH CONFIG_BOARD_ROOT_PATH"/zenoh"
#define ZENOH_PUB_CONFIG_PATH ZENOH_ROOT_PATH"/pub.csv"
#define ZENOH_SUB_CONFIG_PATH ZENOH_ROOT_PATH"/sub.csv"
#define ZENOH_NET_CONFIG_PATH ZENOH_ROOT_PATH"/net.txt"

#define NET_MODE_SIZE sizeof("client")
#define NET_LOCATOR_SIZE 64
Expand Down
2 changes: 1 addition & 1 deletion src/systemcmds/hardfault_log/hardfault_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ static void print_usage(void)
PRINT_MODULE_USAGE_ARG("0|1", "Hardfault type: 0=divide by 0, 1=Assertion (default=0)", true);

PRINT_MODULE_USAGE_COMMAND_DESCR("commit",
"Write uncommitted hardfault to /fs/microsd/fault_%i.txt (and rearm, but don't reset)");
"Write uncommitted hardfault to " CONFIG_BOARD_ROOT_PATH "/fault_%i.txt (and rearm, but don't reset)");
PRINT_MODULE_USAGE_COMMAND_DESCR("count",
"Read the reboot counter, counts the number of reboots of an uncommitted hardfault (returned as the exit code of the program)");
PRINT_MODULE_USAGE_COMMAND_DESCR("reset", "Reset the reboot counter");
Expand Down
2 changes: 1 addition & 1 deletion src/systemcmds/netman/netman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include <arpa/inet.h>
#include <px4_platform_common/shutdown.h>

constexpr char DEFAULT_NETMAN_CONFIG[] = "/fs/microsd/net.cfg";
constexpr char DEFAULT_NETMAN_CONFIG[] = CONFIG_BOARD_ROOT_PATH "/net.cfg";
#if defined(CONFIG_NETINIT_DHCPC)
# define DEFAULT_PROTO IPv4PROTO_FALLBACK
# define DEFAULT_IP CONFIG_NETMAN_FALLBACK_IPADDR
Expand Down
2 changes: 1 addition & 1 deletion src/systemcmds/tests/test_mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int test_mount(int argc, char *argv[])
const unsigned iterations = 2000;
const unsigned alignments = 10;

const char *cmd_filename = "/fs/microsd/mount_test_cmds.txt";
const char *cmd_filename = CONFIG_BOARD_ROOT_PATH "/mount_test_cmds.txt";


/* check if microSD card is mounted */
Expand Down