diff --git a/src/systemcmds/kparam/CMakeLists.txt b/src/systemcmds/kparam/CMakeLists.txt new file mode 100644 index 0000000000..1d14f57594 --- /dev/null +++ b/src/systemcmds/kparam/CMakeLists.txt @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (c) 2021 Technology Innovation Institute. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +px4_add_module( + MODULE systemcmds__kparam + MAIN kparam + COMPILE_FLAGS + -Wno-array-bounds + SRCS + ../param/param.cpp + DEPENDS + ) diff --git a/src/systemcmds/param/CMakeLists.txt b/src/systemcmds/param/CMakeLists.txt index 0a27cf9589..0ce007376e 100644 --- a/src/systemcmds/param/CMakeLists.txt +++ b/src/systemcmds/param/CMakeLists.txt @@ -39,3 +39,7 @@ px4_add_module( param.cpp DEPENDS ) + +if(${PX4_PLATFORM} STREQUAL "nuttx" AND NOT CONFIG_BUILD_FLAT) +target_link_libraries(systemcmds__param PRIVATE systemcmds__launch_kmod) +endif() diff --git a/src/systemcmds/param/param.cpp b/src/systemcmds/param/param.cpp index 68d204a174..6884b0e45d 100644 --- a/src/systemcmds/param/param.cpp +++ b/src/systemcmds/param/param.cpp @@ -64,6 +64,11 @@ __BEGIN_DECLS __EXPORT int param_main(int argc, char *argv[]); __END_DECLS +#if defined (__PX4_NUTTX) && !defined (CONFIG_BUILD_FLAT) && !defined(__KERNEL__) +static const char kparam_main_fn[] = "kparam"; +extern "C" int launch_kmod_main(int argc, char *argv[]); +#endif + enum class COMPARE_OPERATOR { EQUAL = 0, GREATER = 1, @@ -185,7 +190,7 @@ $ reboot PRINT_MODULE_USAGE_ARG("", "param name", false); } -int +extern "C" int param_main(int argc, char *argv[]) { if (argc >= 2) { @@ -216,12 +221,21 @@ param_main(int argc, char *argv[]) } if (!strcmp(argv[1], "import")) { + int ret; if (argc >= 3) { - return do_import(argv[2]); + ret = do_import(argv[2]); } else { - return do_import(); + ret = do_import(); } + +#if defined (__PX4_NUTTX) && !defined (CONFIG_BUILD_FLAT) && !defined(__KERNEL__) + if (ret == 0) { + argv[0] = (char *)kparam_main_fn; + ret = launch_kmod_main(argc, argv); + } +#endif + return ret; } if (!strcmp(argv[1], "select")) { @@ -237,8 +251,12 @@ param_main(int argc, char *argv[]) if (default_file) { PX4_INFO("selected parameter default file %s", default_file); } - +#if defined (__PX4_NUTTX) && !defined (CONFIG_BUILD_FLAT) && !defined(__KERNEL__) + argv[0] = (char *)kparam_main_fn; + return launch_kmod_main(argc, argv); +#else return 0; +#endif } if (!strcmp(argv[1], "show")) { @@ -423,6 +441,14 @@ do_save(const char *param_file_name) return 0; } +#if defined(__PX4_NUTTX) && !defined(CONFIG_BUILD_FLAT) +extern "C" int +kparam_main(int argc, char *argv[]) +{ + return param_main(argc, argv); +} +#endif + static int do_load(const char *param_file_name) {