From c2ba1f517b69f3a283a7c51fd85a3a6c79b34ab2 Mon Sep 17 00:00:00 2001 From: corvus Date: Mon, 31 Jan 2011 20:37:11 +0000 Subject: [PATCH] Fix to make stacs auto-loading of UAVObjects downwards compatible, since its not working on all architectures On architectures supporting automatic initializing, flight/UAVObjects/uavobjectsinit_linker.c is used On architectures NOT supporting automatic initializing, an uavobjectgenerated file build/uavobject-synthetics/flight/init/uavobjectsinit.c is used build/uavobjects-synthetics/flight/uavobjectsinit.c went away, so that a wildcard include in the Makefile will not include the (wrong) initialisation code in either version git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2640 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/CopterControl/Makefile | 2 +- flight/OpenPilot/Makefile | 1 + flight/OpenPilot/Makefile.posix | 1 + flight/PiOS.posix/inc/pios_initcall.h | 29 +++--------- flight/UAVObjects/uavobjectsinit_linker.c | 45 +++++++++++++++++++ flight/UAVObjects/uavobjectsinittemplate.c | 9 +--- .../flight/uavobjectgeneratorflight.cpp | 4 +- .../flight/uavobjectgeneratorflight.h | 1 + 8 files changed, 60 insertions(+), 32 deletions(-) create mode 100644 flight/UAVObjects/uavobjectsinit_linker.c diff --git a/flight/CopterControl/Makefile b/flight/CopterControl/Makefile index 6bca066dc..33511ec19 100644 --- a/flight/CopterControl/Makefile +++ b/flight/CopterControl/Makefile @@ -151,6 +151,7 @@ SRC += $(OPSYSTEM)/taskmonitor.c SRC += $(OPUAVTALK)/uavtalk.c SRC += $(OPUAVOBJ)/uavobjectmanager.c SRC += $(OPUAVOBJ)/eventdispatcher.c +SRC += $(OPUAVOBJ)/uavobjectsinit_linker.c else ## TESTCODE SRC += $(OPTESTS)/test_common.c @@ -184,7 +185,6 @@ SRC += $(OPUAVSYNTHDIR)/manualcontrolsettings.c SRC += $(OPUAVSYNTHDIR)/mixersettings.c SRC += $(OPUAVSYNTHDIR)/mixerstatus.c SRC += $(OPUAVSYNTHDIR)/ahrssettings.c -SRC += $(OPUAVSYNTHDIR)/uavobjectsinit.c #${wildcard ${OBJ}/$(shell echo $(VAR) | tr A-Z a-z)/*.c} #SRC += ${foreach OBJ, ${UAVOBJECTS}, $(UAVOBJECTS)/$(OBJ).c} # Cant use until i can automatically generate list of UAVObjects diff --git a/flight/OpenPilot/Makefile b/flight/OpenPilot/Makefile index 26af9ff01..6c0976f40 100644 --- a/flight/OpenPilot/Makefile +++ b/flight/OpenPilot/Makefile @@ -159,6 +159,7 @@ SRC += $(OPSYSTEM)/taskmonitor.c SRC += $(OPUAVTALK)/uavtalk.c SRC += $(OPUAVOBJ)/uavobjectmanager.c SRC += $(OPUAVOBJ)/eventdispatcher.c +SRC += $(OPUAVOBJ)/uavobjectsinit_linker.c else ## TESTCODE SRC += $(OPTESTS)/test_common.c diff --git a/flight/OpenPilot/Makefile.posix b/flight/OpenPilot/Makefile.posix index 5e9e9fa3f..8ed365e9c 100644 --- a/flight/OpenPilot/Makefile.posix +++ b/flight/OpenPilot/Makefile.posix @@ -143,6 +143,7 @@ SRC += $(OPSYSTEM)/taskmonitor.c SRC += $(OPUAVTALK)/uavtalk.c SRC += $(OPUAVOBJ)/uavobjectmanager.c SRC += $(OPUAVOBJ)/eventdispatcher.c +SRC += $(OPUAVSYNTHDIR)/init/uavobjectsinit.c else ## TESTCODE SRC += $(OPTESTS)/test_common.c diff --git a/flight/PiOS.posix/inc/pios_initcall.h b/flight/PiOS.posix/inc/pios_initcall.h index 7edad6283..c80cd47a8 100644 --- a/flight/PiOS.posix/inc/pios_initcall.h +++ b/flight/PiOS.posix/inc/pios_initcall.h @@ -31,31 +31,14 @@ #ifndef PIOS_INITCALL_H #define PIOS_INITCALL_H -/* - * This implementation is heavily based on the Linux Kernel initcall - * infrastructure: - * http://lxr.linux.no/#linux/include/linux/init.h - * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=include/linux/init.h +/** + * Just a stub define to make things compile. + * Automatically link based initialization currently doesn't work + * since posix really runs on a multitude of architectures + * and we cannot define a linker script for each of them atm */ -/* - * Used for initialization calls.. - */ -typedef int32_t (*initcall_t)(void); - -/* initcalls are now grouped by functionality into separate - * subsections. Ordering inside the subsections is determined - * by link order. - * - * The `id' arg to __define_initcall() is needed so that multiple initcalls - * can point at the same handler without causing duplicate-symbol build errors. - */ - -#define __define_initcall(level,fn,id) \ - static initcall_t __initcall_##fn##id __attribute__((__used__)) \ - __attribute__((__section__(".initcall" level ".init"))) = fn - -#define uavobj_initcall(fn) __define_initcall("uavobj",fn,1) +#define uavobj_initcall(fn) #endif /* PIOS_INITCALL_H */ diff --git a/flight/UAVObjects/uavobjectsinit_linker.c b/flight/UAVObjects/uavobjectsinit_linker.c new file mode 100644 index 000000000..3d4abd7eb --- /dev/null +++ b/flight/UAVObjects/uavobjectsinit_linker.c @@ -0,0 +1,45 @@ +/** + ****************************************************************************** + * + * @file uavobjectsinit.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Initialize all objects. + * Automatically generated by the UAVObjectGenerator. + * + * @note This is an automatically generated file. + * DO NOT modify manually. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "openpilot.h" + +/** + * Function used to initialize the first instance of each object. + * This file is automatically updated by the UAVObjectGenerator. + */ +extern initcall_t __uavobj_initcall_start[], __uavobj_initcall_end[]; + +void UAVObjectsInitializeAll() +{ + initcall_t *fn; + int32_t ret; + + for (fn = __uavobj_initcall_start; fn < __uavobj_initcall_end; fn++) + ret = (*fn)(); +} diff --git a/flight/UAVObjects/uavobjectsinittemplate.c b/flight/UAVObjects/uavobjectsinittemplate.c index 3d4abd7eb..75a104d18 100644 --- a/flight/UAVObjects/uavobjectsinittemplate.c +++ b/flight/UAVObjects/uavobjectsinittemplate.c @@ -28,18 +28,13 @@ */ #include "openpilot.h" +$(OBJINC) /** * Function used to initialize the first instance of each object. * This file is automatically updated by the UAVObjectGenerator. */ -extern initcall_t __uavobj_initcall_start[], __uavobj_initcall_end[]; - void UAVObjectsInitializeAll() { - initcall_t *fn; - int32_t ret; - - for (fn = __uavobj_initcall_start; fn < __uavobj_initcall_end; fn++) - ret = (*fn)(); +$(OBJINIT) } diff --git a/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp b/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp index 2723a905e..c789c6744 100644 --- a/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp +++ b/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp @@ -37,6 +37,8 @@ bool UAVObjectGeneratorFlight::generate(UAVObjectParser* parser,QString template flightCodePath = QDir( templatepath + QString("flight/UAVObjects")); flightOutputPath = QDir( outputpath + QString("flight") ); flightOutputPath.mkpath(flightOutputPath.absolutePath()); + flightInitOutputPath = QDir( outputpath + QString("flight/init") ); + flightInitOutputPath.mkpath(flightInitOutputPath.absolutePath()); flightCodeTemplate = readFile( flightCodePath.absoluteFilePath("uavobjecttemplate.c") ); flightIncludeTemplate = readFile( flightCodePath.absoluteFilePath("inc/uavobjecttemplate.h") ); @@ -57,7 +59,7 @@ bool UAVObjectGeneratorFlight::generate(UAVObjectParser* parser,QString template // Write the flight object inialization files flightInitTemplate.replace( QString("$(OBJINC)"), objInc); flightInitTemplate.replace( QString("$(OBJINIT)"), flightObjInit); - bool res = writeFileIfDiffrent( flightOutputPath.absolutePath() + "/uavobjectsinit.c", + bool res = writeFileIfDiffrent( flightInitOutputPath.absolutePath() + "/uavobjectsinit.c", flightInitTemplate ); if (!res) { cout << "Error: Could not write flight object init files" << endl; diff --git a/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.h b/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.h index 31c377509..f93b15a2f 100644 --- a/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.h +++ b/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.h @@ -37,6 +37,7 @@ public: QString flightCodeTemplate, flightIncludeTemplate, flightInitTemplate; QDir flightCodePath; QDir flightOutputPath; + QDir flightInitOutputPath; private: bool process_object(ObjectInfo* info);