summaryrefslogtreecommitdiff
path: root/include/libsharedobjs.h
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2015-05-29 13:25:38 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-17 03:17:57 +0000
commit214e8cacab495149fa7bdc1bf459c4615119336b (patch)
tree98d7d662705583f97e1e5c0067089aea4adfad49 /include/libsharedobjs.h
parentce063e08297b6578abf6f301f7046302625a781c (diff)
downloadchrome-ec-214e8cacab495149fa7bdc1bf459c4615119336b.tar.gz
libsharedobjs: Add libsharedobjs.h.
This commit introduces the macros needed for the shared objects library. To enable the creation of the shared objects library for a particular board, simply define it in board.h. #define CONFIG_SHAREDLIB In order to actually add objects to the shared library, one must utilize the SHAREDLIB() macro around the definition of the object. All of the objects in the shared library will be placed into a separate binary which the RO and RW images link against. The SHAREDLIB() macro simply adds this attribute and prevents the RO and RW images from compiling them in. This library will reside at a fixed location in memory (currently following the RO image) and the size of the library can be defined on a board by board basis. For example, in board.h: #undef CONFIG_SHAREDLIB_SIZE #define CONFIG_SHAREDLIB_SIZE 0x800 For example, # In foo/build.mk foo-$(CONFIG_BAR)+=bar_sharedlib.o # In foo/bar_sharedlib.c #include "libsharedobjs.h" SHAREDLIB(const uint8_t shared_var = 0x43); # In include/bar_sharedlib.h extern const uint8_t shared_var; BUG=none BRANCH=none TEST=make -j buildall tests TEST=Enabled config option and saw the sharedlib being created. TEST=Enabled config option on unsupported board and saw build fail. CQ-DEPEND=CL:274079 Change-Id: I2abeb1be248ab161fa81c897d2f5793f5a599456 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/275344 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'include/libsharedobjs.h')
-rw-r--r--include/libsharedobjs.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/libsharedobjs.h b/include/libsharedobjs.h
new file mode 100644
index 0000000000..3801ccaca0
--- /dev/null
+++ b/include/libsharedobjs.h
@@ -0,0 +1,44 @@
+/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Helper macros for shared objects library.
+ */
+#ifndef __CROS_EC_LIBSHAREDOBJS_H
+#define __CROS_EC_LIBSHAREDOBJS_H
+
+#include "common.h"
+
+#ifdef CONFIG_SHAREDLIB
+/*
+ * The shared library currently only works with those platforms in which both
+ * the RO and RW images are loaded simultaneously in some executable memory.
+ *
+ * NOTE: I know that this doesn't cover all possible cases, but it will catch
+ * an obvious case.
+ */
+#if (CONFIG_RO_MEM_OFF == CONFIG_RW_MEM_OFF)
+#error "The shared library is NOT compatible with this EC."
+#endif
+
+/*
+ * All of the objects in the shared library will be placed into the '.roshared'
+ * section. The SHAREDLIB() macro simply adds this attribute and prevents the
+ * RW image from compiling them in.
+ */
+#undef SHAREDLIB
+#ifdef SHAREDLIB_IMAGE
+#define SHAREDLIB(...) __attribute__ ((section(".roshared"))) __VA_ARGS__
+#else /* !defined(SHAREDLIB_IMAGE) */
+#define SHAREDLIB(...)
+#endif /* defined(SHAREDLIB_IMAGE) */
+#define SHAREDLIB_FUNC(...) \
+ extern __VA_ARGS__ __attribute__ ((section(".roshared.text")))
+
+#else /* !defined(CONFIG_SHAREDLIB) */
+
+/* By default, the SHAREDLIB() macro maps to its contents. */
+#define SHAREDLIB(...) __VA_ARGS__
+#define SHAREDLIB_FUNC(...) __VA_ARGS__
+#endif /* defined(CONFIG_SHAREDLIB) */
+#endif /* __CROS_EC_LIBSHAREDOBJS_H */