From b9ef1ee6ed944ec4a06cee3266cedb761f03bcab Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Fri, 11 Sep 2015 02:33:42 -0700 Subject: [PATCH] param: Build param without linker script Changed to enable the posix_sitl_simple target to build and run param show * without using a linker script Signed-off-by: Mark Charlebois --- CMakeLists.txt | 2 +- Tools/px_generate_params.py | 53 +++++++++++++++++++++++++++++ cmake/common/px4_base.cmake | 14 ++++++++ src/firmware/posix/CMakeLists.txt | 10 +++--- src/modules/systemlib/param/param.c | 8 +++-- src/modules/systemlib/param/param.h | 27 ++------------- 6 files changed, 80 insertions(+), 34 deletions(-) create mode 100755 Tools/px_generate_params.py diff --git a/CMakeLists.txt b/CMakeLists.txt index a01d50509c..04efb3c89c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,7 +226,7 @@ link_directories(${link_dirs}) add_definitions(${definitions}) #============================================================================= -# source code generation} +# source code generation # file(GLOB_RECURSE msg_files msg/*.msg) px4_generate_messages(TARGET msg_gen diff --git a/Tools/px_generate_params.py b/Tools/px_generate_params.py new file mode 100755 index 0000000000..08808bc559 --- /dev/null +++ b/Tools/px_generate_params.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +import xml.etree.ElementTree as ET +import os + +if len(os.sys.argv) != 3: + print "Error in %s" % os.sys.argv[0] + print "Usage: %s " + raise SystemExit + +fp = open(os.sys.argv[2], "w") + +tree = ET.parse(os.sys.argv[1]) +root = tree.getroot() +body = """ +#include +#include + +// DO NOT EDIT +// This file is autogenerated from paramaters.xml + +""" + +start_name = "" +end_name = "" + +for group in root: + if group.tag == "group": + body += "// %s\n" % group.attrib["name"] + for param in group: + if not start_name: + start_name = param.attrib["name"] + end_name = param.attrib["name"] + body += """ +static const +__attribute__((used, section("__param"))) +struct param_info_s __param__%s = { + "%s", + PARAM_TYPE_%s, + .val.f = %s +}; +""" % (param.attrib["name"], param.attrib["name"], param.attrib["type"], param.attrib["default"]) +body += """ +extern const +__attribute__((alias("__param__%s"))) +struct param_info_s __param_start; + +extern const +__attribute__((alias("__param__%s"))) +struct param_info_s __param_end; +""" % (start_name, end_name) + +fp.write(body) + diff --git a/cmake/common/px4_base.cmake b/cmake/common/px4_base.cmake index 9238bd05ad..c836223258 100644 --- a/cmake/common/px4_base.cmake +++ b/cmake/common/px4_base.cmake @@ -672,4 +672,18 @@ function(px4_create_git_hash_header) configure_file(${CMAKE_SOURCE_DIR}/cmake/templates/build_git_version.h.in ${HEADER} @ONLY) endfunction() +#============================================================================= +# parameter file generation +# +function(px4_generate_parameters) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Tools/px_process_params.py -s ${CMAKE_SOURCE_DIR}/src --board ${BOARD} --xml + ) + + execute_process( + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Tools/px_generate_params.py ${CMAKE_BINARY_DIR}/parameters.xml ${CMAKE_BINARY_DIR}/parameters.c + ) +endfunction() + + # vim: set noet fenc=utf-8 ff=unix nowrap: diff --git a/src/firmware/posix/CMakeLists.txt b/src/firmware/posix/CMakeLists.txt index 4dbd94a3df..657d8d45ad 100644 --- a/src/firmware/posix/CMakeLists.txt +++ b/src/firmware/posix/CMakeLists.txt @@ -1,20 +1,18 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) + px4_posix_generate_builtin_commands( OUT apps.h MODULE_LIST ${module_libraries}) +px4_generate_parameters() + add_executable(mainapp ${CMAKE_SOURCE_DIR}/src/platforms/posix/main.cpp + ${CMAKE_BINARY_DIR}/parameters.c apps.h ) -set(main_link_flags - "-T${CMAKE_SOURCE_DIR}/cmake/posix/ld.script" - ) -px4_join(OUT main_link_flags LIST ${main_link_flags} GLUE " ") -set_target_properties(mainapp PROPERTIES LINK_FLAGS ${main_link_flags}) - target_link_libraries(mainapp -Wl,--start-group ${module_libraries} diff --git a/src/modules/systemlib/param/param.c b/src/modules/systemlib/param/param.c index c85e8dbda8..7af26cd30b 100644 --- a/src/modules/systemlib/param/param.c +++ b/src/modules/systemlib/param/param.c @@ -86,9 +86,11 @@ extern struct param_info_s param_array[]; extern struct param_info_s *param_info_base; extern struct param_info_s *param_info_limit; #else -extern char __param_start, __param_end; -static const struct param_info_s *param_info_base = (struct param_info_s *) &__param_start; -static const struct param_info_s *param_info_limit = (struct param_info_s *) &__param_end; +extern const struct param_info_s __param_start, __param_end; + +// FIXME - start and end are reversed +static const struct param_info_s *param_info_base = &__param_end; +static const struct param_info_s *param_info_limit = &__param_start; #endif #define param_info_count ((unsigned)(param_info_limit - param_info_base)) diff --git a/src/modules/systemlib/param/param.h b/src/modules/systemlib/param/param.h index caa0635dce..d7cf666a71 100644 --- a/src/modules/systemlib/param/param.h +++ b/src/modules/systemlib/param/param.h @@ -346,34 +346,13 @@ __EXPORT int param_load_default(void); */ /** define an int32 parameter */ -#define PARAM_DEFINE_INT32(_name, _default) \ - static const \ - __attribute__((used, section("__param"))) \ - struct param_info_s __param__##_name = { \ - #_name, \ - PARAM_TYPE_INT32, \ - .val.i = _default \ - } +#define PARAM_DEFINE_INT32(_name, _default) /** define a float parameter */ -#define PARAM_DEFINE_FLOAT(_name, _default) \ - static const \ - __attribute__((used, section("__param"))) \ - struct param_info_s __param__##_name = { \ - #_name, \ - PARAM_TYPE_FLOAT, \ - .val.f = _default \ - } +#define PARAM_DEFINE_FLOAT(_name, _default) /** define a parameter that points to a structure */ -#define PARAM_DEFINE_STRUCT(_name, _default) \ - static const \ - __attribute__((used, section("__param"))) \ - struct param_info_s __param__##_name = { \ - #_name, \ - PARAM_TYPE_STRUCT + sizeof(_default), \ - .val.p = &_default \ - } +#define PARAM_DEFINE_STRUCT(_name, _default) /** * Parameter value union.