From fbd104fef057f3ce362163de21a93e36ccd0028d Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 17 Feb 2021 11:25:56 +0900 Subject: [PATCH 01/16] halapi: Add macros.hal-api to add new rpm macro for /hal Change-Id: Iae582e0d2b5912837beb1608bc4f0a8eba91595b Signed-off-by: Chanwoo Choi --- packaging/hal-api-common.spec | 3 +++ packaging/macros.hal-api | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 packaging/macros.hal-api diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 87a46cd..b381841 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -13,6 +13,7 @@ Source0: %{name}-%{version}.tar.gz Source1: %{name}.manifest Source2: libhal-api.conf Source3: systemd-hal-firmware-generator +Source4: macros.hal-api Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -65,6 +66,7 @@ rm -rf %{buildroot} mkdir -p %{buildroot}/hal install -D -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/ld.so.conf.d/libhal-api.conf install -D -m 0755 %{SOURCE3} %{buildroot}%{_systemdgeneratordir}/systemd-hal-firmware-generator +install -D -m 0644 %{SOURCE4} %{buildroot}%{_sysconfdir}/rpm/macros.hal-api %clean rm -rf %{buildroot} @@ -95,6 +97,7 @@ fi %defattr(-,root,root,-) %{_includedir}/hal/*.h %{_libdir}/pkgconfig/*.pc +%{_sysconfdir}/rpm/macros.hal-api %files -n %{test_name} %{_bindir}/hal/common-haltests diff --git a/packaging/macros.hal-api b/packaging/macros.hal-api new file mode 100644 index 0000000..8d172c2 --- /dev/null +++ b/packaging/macros.hal-api @@ -0,0 +1,9 @@ +# RPM macros for /hal directory + +%_hal_prefix /hal +%_hal_bindir %{_hal_prefix}/bin +%_hal_libdir %{_hal_prefix}/%{_lib} +%_hal_includedir %{_hal_prefix}/include +%_hal_sysconfdir %{_hal_prefix}%{_sysconfdir} +%_hal_datadir %{_hal_prefix}/share +%_hal_licensedir %{_hal_prefix}/share/licenses -- 2.7.4 From 21e5da8a27efb24104cc3a5abc29eac979e61e8e Mon Sep 17 00:00:00 2001 From: Seungha Son Date: Tue, 23 Feb 2021 23:58:19 +0900 Subject: [PATCH 02/16] halapi: Remove circular dependency between packages Change json parsing library from json-glib to json-c because when using json-glib, the circular dependency problem between dependent rpm is occured. By changing the json-parser-lib from json-glib to json-c, the circular dependency was removed and the problem was solved. Change-Id: I694e05649a875ea8a3af8128efc5be7c88282830 Signed-off-by: Seungha Son --- CMakeLists.txt | 2 +- packaging/hal-api-common.spec | 2 +- src/hal-api-conf.c | 105 ++++++++++++++++++------------------------ 3 files changed, 47 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae9fd01..df8d137 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ SET(PKG_MODULES dlog gio-2.0 glib-2.0 - json-glib-1.0 + json-c libtzplatform-config ) diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index b381841..223887f 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -21,7 +21,7 @@ BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(json-glib-1.0) +BuildRequires: pkgconfig(json-c) BuildRequires: pkgconfig(gmock) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(systemd) diff --git a/src/hal-api-conf.c b/src/hal-api-conf.c index 9b8480b..46d1be6 100644 --- a/src/hal-api-conf.c +++ b/src/hal-api-conf.c @@ -18,7 +18,9 @@ #include #include -#include + +#include +#include #include "hal-common.h" #include "hal-common-interface.h" @@ -29,8 +31,7 @@ static enum hal_abi_version _platform_abi_version = HAL_ABI_VERSION_END; -static JsonParser *_parser = NULL; -static JsonObject *_root_object = NULL; +static json_object *_json_file_object = NULL; static GHashTable *_module_hash = NULL; @@ -105,13 +106,22 @@ do { \ } } -static struct __hal_module_info *__create_hal_module_info(enum hal_module module, JsonObject *object) +static const char * __get_json_object_string(json_object *object, const char *key) +{ + json_object *temp_object = NULL; + + json_object_object_get_ex(object, key, &temp_object); + return json_object_get_string(temp_object); +} + +static struct __hal_module_info *__create_hal_module_info(enum hal_module module, json_object *object) { struct __hal_module_info *info; - JsonArray *abi_versions_array = NULL; GList *abi_list = NULL; GList *iter_list = NULL; int list_index = 0; + json_object *abi_versions_array; + json_object *tmp_object; const char *tmp; info = (struct __hal_module_info *)calloc(1, sizeof(struct __hal_module_info)); @@ -123,52 +133,47 @@ static struct __hal_module_info *__create_hal_module_info(enum hal_module module info->module = module; info->module_name = g_strdup(__convert_module_to_string(module)); - tmp = json_object_get_string_member(object, "group"); + tmp = __get_json_object_string(object, "group"); info->group = __convert_group_str_to_enum(tmp); - tmp = json_object_get_string_member(object, "license"); + tmp = __get_json_object_string(object, "license"); info->license = __convert_license_str_to_enum(tmp); - info->library_name = g_strdup(json_object_get_string_member(object, "library_name")); - info->library_name_64bit = g_strdup(json_object_get_string_member(object, "library_name_64bit")); - info->symbol_name = g_strdup(json_object_get_string_member(object, "symbol_name")); + info->library_name = g_strdup(__get_json_object_string(object, "library_name")); + info->library_name_64bit = g_strdup(__get_json_object_string(object, "library_name_64bit")); + info->symbol_name = g_strdup(__get_json_object_string(object, "symbol_name")); if (info->library_name && info->library_name_64bit && info->symbol_name) info->hal_api = true; - abi_versions_array = json_object_get_array_member(object, "abi_versions"); - if (abi_versions_array == NULL) + json_object_object_get_ex(object, "abi_versions", &abi_versions_array); + if (json_object_get_type(abi_versions_array) != json_type_array) return info; - abi_list = json_array_get_elements(abi_versions_array); - info->num_abi_versions = g_list_length(abi_list); + info->num_abi_versions = json_object_array_length(abi_versions_array); if (info->num_abi_versions > 0) { info->abi_versions = (struct hal_abi_version_match*)calloc(info->num_abi_versions, sizeof(struct hal_abi_version_match)); if (info->abi_versions == NULL) { _E("Out of Memory\n"); _destroy_module_info(info); - g_list_free(abi_list); return NULL; } - for (iter_list = abi_list; iter_list != NULL; iter_list = iter_list->next) { - JsonObject *tmp_object = json_node_get_object(iter_list->data); + for (int i = 0; i < info->num_abi_versions; i++) { + json_object *abi_object = json_object_array_get_idx(abi_versions_array, i); - tmp = json_object_get_string_member(tmp_object, "platform_abi_version"); + tmp = __get_json_object_string(abi_object, "platform_abi_version"); info->abi_versions[list_index].platform_abi_version = __convert_abi_version_str_to_enum(tmp); - tmp = json_object_get_string_member(tmp_object, "backend_min_abi_version"); + tmp = __get_json_object_string(abi_object, "backend_min_abi_version"); info->abi_versions[list_index].backend_min_abi_version = __convert_abi_version_str_to_enum(tmp); list_index++; } } - if (abi_list) - g_list_free(abi_list); - return info; } @@ -176,28 +181,26 @@ __attribute__ ((visibility("default"))) struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module) { struct __hal_module_info *info = NULL; - JsonArray *module_array = NULL; - GList *module_list = NULL; - GList *iter_list; + json_object *module_array_object = NULL; const char *group_name = NULL; const char *module_name = NULL; + int i; - if (!_root_object || !_module_hash) + if (!_json_file_object || !_module_hash) return NULL; info = (struct __hal_module_info*)g_hash_table_lookup(_module_hash, GINT_TO_POINTER(module)); if (info != NULL) return info; - module_array = json_object_get_array_member(_root_object, "MODULE_INFO"); - module_list = json_array_get_elements(module_array); + json_object_object_get_ex(_json_file_object, "MODULE_INFO", &module_array_object); module_name = __convert_module_to_string(module); - for (iter_list = module_list; iter_list != NULL; iter_list = iter_list->next) { - JsonObject *tmp_object = json_node_get_object(iter_list->data); - const char *value = json_object_get_string_member(tmp_object, "module"); + for (i = 0; i < json_object_array_length(module_array_object); i++) { + json_object *temp_object = json_object_array_get_idx(module_array_object, i); + const char *value = __get_json_object_string(temp_object, "module"); if (g_strcmp0(value, module_name) == 0) { - info = __create_hal_module_info(module, tmp_object); + info = __create_hal_module_info(module, temp_object); if (info == NULL) _E("Failed to create hal module info\n"); else @@ -206,10 +209,6 @@ struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module) } } -ret: - if (module_list) - g_list_free(module_list); - return info; } @@ -217,14 +216,15 @@ enum hal_abi_version _hal_api_conf_get_platform_abi_version(void) { const char *abi_version = NULL; bool ret_initialized; + json_object *platform_obj = NULL; if (_platform_abi_version != HAL_ABI_VERSION_END) return _platform_abi_version; - if (!_root_object || !_module_hash) + if (!_json_file_object || !_module_hash) return HAL_ABI_VERSION_UNKNOWN; - abi_version = json_object_get_string_member(_root_object, "PLATFORM_ABI_VERSION"); + abi_version = __get_json_object_string(_json_file_object, "PLATFORM_ABI_VERSION"); _platform_abi_version = __convert_abi_version_str_to_enum(abi_version); return _platform_abi_version; @@ -233,27 +233,15 @@ enum hal_abi_version _hal_api_conf_get_platform_abi_version(void) __attribute__ ((visibility("default"))) int _hal_api_conf_init(void) { - JsonNode *root_node = NULL; - GError *error = NULL; - gboolean result; - if (_usage_count++ > 0) return 0; - _parser = json_parser_new(); - result = json_parser_load_from_file(_parser, HAL_CONFIGURATION_PATH, &error); - if (result == FALSE) { - _E("Failed to parsing json configuration file : %s\n", error->message); - goto err; - } - - root_node = json_parser_get_root(_parser); - if (JSON_NODE_HOLDS_OBJECT(root_node) == FALSE) { - _E("There is no object in root node\n"); + _json_file_object = json_object_from_file(HAL_CONFIGURATION_PATH); + if (_json_file_object == NULL) { + _E("Failed to parsing json configuration file : %s\n", json_util_get_last_err()); goto err; } - _root_object = json_node_get_object(root_node); _module_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, _destroy_module_info); return 0; @@ -261,11 +249,6 @@ int _hal_api_conf_init(void) err: _usage_count--; - if (error) - g_error_free(error); - if (_parser) - g_object_unref(_parser); - if (_module_hash) { g_hash_table_remove_all(_module_hash); g_hash_table_unref(_module_hash); @@ -281,8 +264,10 @@ void _hal_api_conf_exit(void) if (_usage_count != 0) return; - if (_parser) - g_object_unref(_parser); + if (_json_file_object) { + json_object_put(_json_file_object); + _json_file_object = NULL; + } if (_module_hash) { g_hash_table_remove_all(_module_hash); -- 2.7.4 From 7827e46be2462a45b7645e89654acd6e541ddf61 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 8 Mar 2021 18:44:47 +0900 Subject: [PATCH 03/16] halapi: Fix unlock issue when failed to parse hal-api.json There is deadlock issue without unlocking the mutex when error happen. So that fix the unlock issue. Change-Id: I4581202808f9b6f9b8b36c452663be1e59c4e7af Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index cf5c3fd..4bf3dc4 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -157,8 +157,10 @@ int hal_common_get_backend(enum hal_module module, void **data) G_LOCK(hal_common_lock); - if (_hal_api_conf_init()) - return TIZEN_ERROR_UNKNOWN; + if (_hal_api_conf_init()) { + ret = TIZEN_ERROR_UNKNOWN; + goto err; + } info = _hal_api_conf_get_module_info(module); if (info == NULL) { -- 2.7.4 From f8c7d65a404d22e0020bb5f05210ef15dcd6ff49 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 9 Mar 2021 16:44:06 +0900 Subject: [PATCH 04/16] halapi: Add more information to improve the readability for dlog In order to improve the readability, add more information with library name and usage_count for multi-thread environment. Change-Id: I71b3f68789556ccdf77275ba1932b39b1e7378f5 Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 4bf3dc4..cc2f926 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -249,11 +249,12 @@ int hal_common_get_backend(enum hal_module module, void **data) goto err_dlclose; } - _I("%s: Get HAL backend: name(%s)/vendor(%s)\n", - info->module_name, backend->name, backend->vendor); - info->usage_count++; + _I("%s: Get HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + info->module_name, backend->name, backend->vendor, + library_name, info->usage_count); + G_UNLOCK(hal_common_lock); return TIZEN_ERROR_NONE; @@ -313,8 +314,9 @@ int hal_common_put_backend(enum hal_module module, void *data) } } - _I("%s: Put HAL backend: name(%s)/vendor(%s)\n", - info->module_name, backend->name, backend->vendor); + _I("%s: Put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + info->module_name, backend->name, backend->vendor, + get_backend_library_name(info), info->usage_count); if (handle) dlclose(handle); -- 2.7.4 From 714866a63f2349895f7ceab173a08df0789ca530 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 9 Mar 2021 14:01:59 +0900 Subject: [PATCH 05/16] halapi: Add new get_backend and put_backend with specific library name Basically, hal_common_get_backend has used the promised libray name for HAL backend like 'libhal-backend-[moodule name].so'. But, there are some requirements that need to select the one HAL backend among the multiple HAL backends on same device according to the role of use. So that add the following two functions with new library_name argument. - int hal_common_get_backend_with_library_name(enum hal_module module, void **data, const char *library_name); - int hal_common_put_backend_with_library_name(enum hal_module module, void *data, const char *library_name); [Constraints of library name] This library_name argument must keep the naming rule as following: - 'libhal-backend-[moodule name]-[extented name].so Change-Id: Ia6c69597a718f5a4ae9de2f879f7c4337874b1ee Signed-off-by: Chanwoo Choi --- include/hal-common.h | 21 +++++++++++ src/common.h | 13 +++++++ src/hal-api-common.c | 76 +++++++++++++++++++++++---------------- src/hal-api-conf.c | 88 ++++++++++++++++++++++++++++++++++++++++++---- src/hal-api-conf.h | 3 +- tests/unittest/test_hal.cc | 8 ++--- 6 files changed, 167 insertions(+), 42 deletions(-) diff --git a/include/hal-common.h b/include/hal-common.h index 7402f05..369a78a 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -201,6 +201,27 @@ int hal_common_get_backend(enum hal_module module, void **data); int hal_common_put_backend(enum hal_module module, void *data); /** + * @brief Get the backend data with the specific library name according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[out] Data pointer where 'hal_backend_[module]_funcs' instance + * should be stored from HAL backend binary. + * @param[in] HAL backend library name which is not default library name + * @return @c 0 on success, otherwise a negative error value + */ +int hal_common_get_backend_with_library_name(enum hal_module module, + void **data, const char *library_name); + +/** + * @brief Put the backend data with the specific library name according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[in] Data pointer where 'hal_backend_[module]_funcs' instance + * @param[in] HAL backend library name which is not default library name + * @return @c 0 on success, otherwise a negative error value + */ +int hal_common_put_backend_with_library_name(enum hal_module module, + void *data, const char *library_name); + +/** * @brief Check HAL ABI version whehter is suppored or not on current platform * @param[in] HAL module id among enum hal_moudle * @param[in] HAL ABI version of backend module among enum hal_abi_version diff --git a/src/common.h b/src/common.h index f19e56c..e3463e2 100644 --- a/src/common.h +++ b/src/common.h @@ -72,8 +72,21 @@ struct __hal_module_info { struct hal_abi_version_match *abi_versions; bool hal_api; + bool hal_backend_extension; }; +static inline const char* get_backend_library_name(struct __hal_module_info *info) +{ + if (!info) + return NULL; + +#if defined(__aarch64__) + return info->library_name_64bit; +#else + return info->library_name; +#endif +} + #ifdef __cplusplus } #endif diff --git a/src/hal-api-common.c b/src/hal-api-common.c index cc2f926..9914c08 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -34,19 +34,6 @@ static enum hal_abi_version g_platform_curr_abi_version; G_LOCK_DEFINE_STATIC(hal_common_lock); - -static const char* get_backend_library_name(struct __hal_module_info *info) -{ - if (!info) - return NULL; - -#if defined(__aarch64__) - return info->library_name_64bit; -#else - return info->library_name; -#endif -} - EXPORT int hal_common_get_backend_library_name(enum hal_module module, char *name, int size) { @@ -64,7 +51,7 @@ int hal_common_get_backend_library_name(enum hal_module module, char *name, int if (_hal_api_conf_init()) return TIZEN_ERROR_UNKNOWN; - info = _hal_api_conf_get_module_info(module); + info = _hal_api_conf_get_module_info(module, NULL); if (info == NULL) { _E("Failed to get HAL module(%d) information\n", module); ret = TIZEN_ERROR_UNKNOWN; @@ -111,7 +98,7 @@ int hal_common_get_backend_symbol_name(enum hal_module module, char *name, int s if (_hal_api_conf_init()) return TIZEN_ERROR_UNKNOWN; - info = _hal_api_conf_get_module_info(module); + info = _hal_api_conf_get_module_info(module, NULL); if (info == NULL) { _E("Failed to get HAL module(%d) information\n", module); ret = TIZEN_ERROR_UNKNOWN; @@ -140,13 +127,13 @@ out: return ret; } -EXPORT -int hal_common_get_backend(enum hal_module module, void **data) +static int __get_backend(enum hal_module module, void **data, const char *library_name) { struct __hal_module_info *info = NULL; void *handle = NULL; hal_backend *backend; - const char *library_name, *symbol_name; + const char *symbol_name; + const char *backend_library_name; int ret = 0; /* Check parameter whether is valid or not */ @@ -162,9 +149,13 @@ int hal_common_get_backend(enum hal_module module, void **data) goto err; } - info = _hal_api_conf_get_module_info(module); + info = _hal_api_conf_get_module_info(module, library_name); if (info == NULL) { - _E("Failed to get HAL module(%d) information\n", module); + if (!library_name) + _E("Failed to get HAL module(%d) information\n", module); + else + _E("Failed to get HAL module(%d) information (%s)\n", + module, library_name); ret = TIZEN_ERROR_UNKNOWN; goto err; } @@ -174,23 +165,23 @@ int hal_common_get_backend(enum hal_module module, void **data) * Load HAL backend library at first loading time * when usage_count is 0. */ - library_name = get_backend_library_name(info); - if (!library_name) { + backend_library_name = get_backend_library_name(info); + if (!backend_library_name) { _E("%s: Failed to get backend library name\n", info->module_name); ret = TIZEN_ERROR_INVALID_PARAMETER; goto err; } - ret = access(library_name, F_OK); + ret = access(backend_library_name, F_OK); if (ret < 0) { _E("%s: Failed to find backend library (%s)\n", - info->module_name, library_name); + info->module_name, backend_library_name); ret = TIZEN_ERROR_INVALID_PARAMETER; goto err; } - handle = dlopen(library_name, RTLD_LAZY); + handle = dlopen(backend_library_name, RTLD_LAZY); if (!handle) { _E("%s: Failed to load backend library (%s)\n", info->module_name, dlerror()); @@ -253,7 +244,7 @@ int hal_common_get_backend(enum hal_module module, void **data) _I("%s: Get HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", info->module_name, backend->name, backend->vendor, - library_name, info->usage_count); + backend_library_name, info->usage_count); G_UNLOCK(hal_common_lock); return TIZEN_ERROR_NONE; @@ -266,8 +257,7 @@ err: return ret; } -EXPORT -int hal_common_put_backend(enum hal_module module, void *data) +static int __put_backend(enum hal_module module, void *data, const char *library_name) { struct __hal_module_info *info = NULL; hal_backend *backend = NULL; @@ -282,7 +272,7 @@ int hal_common_put_backend(enum hal_module module, void *data) G_LOCK(hal_common_lock); - info = _hal_api_conf_get_module_info(module); + info = _hal_api_conf_get_module_info(module, library_name); if (info == NULL) { _E("Failed to get HAL module(%d) information\n", module); ret = TIZEN_ERROR_UNKNOWN; @@ -334,6 +324,32 @@ out: } EXPORT +int hal_common_get_backend(enum hal_module module, void **data) +{ + return __get_backend(module, data, NULL); +} + +EXPORT +int hal_common_put_backend(enum hal_module module, void *data) +{ + return __put_backend(module, data, NULL); +} + +EXPORT +int hal_common_get_backend_with_library_name(enum hal_module module, + void **data, const char *library_name) +{ + return __get_backend(module, data, library_name); +} + +EXPORT +int hal_common_put_backend_with_library_name(enum hal_module module, + void *data, const char *library_name) +{ + return __put_backend(module, data, library_name); +} + +EXPORT int hal_common_check_backend_abi_version(enum hal_module module, enum hal_abi_version abi_version) { @@ -357,7 +373,7 @@ int hal_common_check_backend_abi_version(enum hal_module module, if (_hal_api_conf_init()) return TIZEN_ERROR_UNKNOWN; - info = _hal_api_conf_get_module_info(module); + info = _hal_api_conf_get_module_info(module, NULL); if (info == NULL) { _E("Failed to get HAL module(%d) information\n", module); ret = TIZEN_ERROR_UNKNOWN; diff --git a/src/hal-api-conf.c b/src/hal-api-conf.c index 46d1be6..87b4c0c 100644 --- a/src/hal-api-conf.c +++ b/src/hal-api-conf.c @@ -90,13 +90,8 @@ do { \ } while (0); struct __hal_module_info *info = (struct __hal_module_info *)data; - gboolean is_contained = false; if (info) { - is_contained = g_hash_table_contains(_module_hash, GINT_TO_POINTER(info->module)); - if (is_contained) - g_hash_table_steal(_module_hash, GINT_TO_POINTER(info->module)); - SAFE_FREE_AND_NULL(info->module_name); SAFE_FREE_AND_NULL(info->library_name); SAFE_FREE_AND_NULL(info->library_name_64bit); @@ -177,8 +172,7 @@ static struct __hal_module_info *__create_hal_module_info(enum hal_module module return info; } -__attribute__ ((visibility("default"))) -struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module) +static struct __hal_module_info* _get_module_info(enum hal_module module) { struct __hal_module_info *info = NULL; json_object *module_array_object = NULL; @@ -212,6 +206,86 @@ struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module) return info; } +static struct __hal_module_info* _get_module_info_with_library_name(enum hal_module module, + const char *library_name) +{ + struct __hal_module_info *info = NULL, *new_info = NULL; + json_object *module_array_object = NULL; + const char *group_name = NULL; + const char *module_name = NULL; + int ret; + + if (!_json_file_object || !_module_hash | !library_name) + return NULL; + + if (!g_str_has_prefix(library_name, "libhal-backend-")) { + _E("Invalid library name(%s) of HAL module(%d)\n", + library_name, module); + return NULL; + } + + /* Find module info with the passed library name */ + info = (struct __hal_module_info*)g_hash_table_lookup(_module_hash, + (gpointer)library_name); + if (info) + return info; + + /* Create new module info with the passed library name */ + info = _get_module_info(module); + if (info == NULL) { + _E("Failed to get HAL module(%d) information\n", module); + return NULL; + } + + new_info = (struct __hal_module_info *)calloc(1, + sizeof(struct __hal_module_info)); + if (new_info == NULL) { + _E("Failed to allocate the memory\n"); + return NULL; + } + + new_info->usage_count = 0; + new_info->group = info->group; + new_info->module = info->module; + new_info->license = info->license; + new_info->module_name = g_strdup(info->module_name); +#if defined(__aarch64__) + new_info->library_name_64bit = g_strdup_printf("/hal/lib64/%s", library_name); +#else + new_info->library_name = g_strdup_printf("/hal/lib/%s", library_name); +#endif + new_info->symbol_name = g_strdup(info->symbol_name); + new_info->num_abi_versions = info->num_abi_versions; + new_info->abi_versions = info->abi_versions; + new_info->hal_api = info->hal_api; + new_info->hal_backend_extension = true; + + g_hash_table_insert(_module_hash, (gpointer)library_name, new_info); + + return new_info; +} + +__attribute__ ((visibility("default"))) +struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module, + const char *library_name) +{ + struct __hal_module_info *info = NULL; + json_object *module_array_object = NULL; + const char *group_name = NULL; + const char *module_name = NULL; + const char *key = NULL; + int i; + + if (!_json_file_object || !_module_hash) + return NULL; + + if (!library_name) + return _get_module_info(module); + else + return _get_module_info_with_library_name(module, library_name); +} + + enum hal_abi_version _hal_api_conf_get_platform_abi_version(void) { const char *abi_version = NULL; diff --git a/src/hal-api-conf.h b/src/hal-api-conf.h index f0d0cfd..c1e7eb9 100644 --- a/src/hal-api-conf.h +++ b/src/hal-api-conf.h @@ -33,7 +33,8 @@ extern "C" { int _hal_api_conf_init(void); void _hal_api_conf_exit(void); -struct __hal_module_info *_hal_api_conf_get_module_info(enum hal_module module); +struct __hal_module_info *_hal_api_conf_get_module_info(enum hal_module module, + const char *library_name); enum hal_abi_version _hal_api_conf_get_platform_abi_version(void); diff --git a/tests/unittest/test_hal.cc b/tests/unittest/test_hal.cc index dc3c851..1700b6a 100644 --- a/tests/unittest/test_hal.cc +++ b/tests/unittest/test_hal.cc @@ -391,7 +391,7 @@ TEST_P(HalInfoMatchedTest, test_group_module_matching) { auto result_info = GetParam(); _hal_api_conf_init(); - info = _hal_api_conf_get_module_info(result_info.module_); + info = _hal_api_conf_get_module_info(result_info.module_, NULL); ASSERT_TRUE(info != nullptr) << "module name is " << result_info.module_name_; EXPECT_EQ(info->group, result_info.group_) << "module name is " << result_info.module_name_; _hal_api_conf_exit(); @@ -403,7 +403,7 @@ TEST_P(HalInfoMatchedTest, test_license_module_matching) { auto result_info = GetParam(); _hal_api_conf_init(); - info = _hal_api_conf_get_module_info(result_info.module_); + info = _hal_api_conf_get_module_info(result_info.module_, NULL); ASSERT_TRUE(info != nullptr) << "module name is " << result_info.module_name_; EXPECT_EQ(info->license, result_info.license_) << "module name is " << result_info.module_name_; _hal_api_conf_exit(); @@ -415,7 +415,7 @@ TEST_P(HalInfoMatchedTest, test_module_name_matching) { auto result_info = GetParam(); _hal_api_conf_init(); - info = _hal_api_conf_get_module_info(result_info.module_); + info = _hal_api_conf_get_module_info(result_info.module_, NULL); ASSERT_TRUE(info != nullptr) << "module name is " << result_info.module_name_; EXPECT_STREQ(info->module_name, result_info.module_name_) << "module name is " << result_info.module_name_; _hal_api_conf_exit(); @@ -426,7 +426,7 @@ TEST_P(HalInfoMatchedTest, test_check_backend_abi_version) { auto result_info = GetParam(); _hal_api_conf_init(); - info = _hal_api_conf_get_module_info(result_info.module_); + info = _hal_api_conf_get_module_info(result_info.module_, NULL); ASSERT_TRUE(info != nullptr); vector versions = result_info.versions_; -- 2.7.4 From dd82d44aed96afd79b673029957cc45165643d79 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 15 Mar 2021 15:02:54 +0900 Subject: [PATCH 06/16] halapi: Replace hal-api.json with hal-api-list.h When using hal-api.json, the segmentation falut happen when trying to use json-c library because of some library including json-c statically. In order to fix this issue rapily, use the 'hal-api-list.h' temporarily instead of 'hal-api.json'. After fixing this issue, revert this patch for using 'hal-api.json'. Change-Id: I22ba800b536e974879cbfa758f9160b896813c63 Signed-off-by: Chanwoo Choi --- include/hal-common.h | 2 + src/hal-api-conf.c | 83 ++++-- src/hal-api-list.h | 706 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 764 insertions(+), 27 deletions(-) create mode 100644 src/hal-api-list.h diff --git a/include/hal-common.h b/include/hal-common.h index 369a78a..45c4a10 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -112,6 +112,7 @@ enum hal_module { HAL_MODULE_END, }; +#ifdef HAL_API_CONF_JSON static const char *const hal_module_string[] = { [HAL_MODULE_UNKNOWN] = "HAL_MODULE_UNKNOWN", @@ -164,6 +165,7 @@ static const char *const hal_module_string[] = { [HAL_MODULE_END] = "HAL_MODULE_END", }; +#endif /** * @brief Get the backend library name according to the type of HAL module diff --git a/src/hal-api-conf.c b/src/hal-api-conf.c index 87b4c0c..4465fe6 100644 --- a/src/hal-api-conf.c +++ b/src/hal-api-conf.c @@ -25,18 +25,44 @@ #include "hal-common.h" #include "hal-common-interface.h" -#include "hal-api-conf.h" - #include "common.h" +#include "hal-api-conf.h" +#include "hal-api-list.h" +#ifdef HAL_API_CONF_JSON static enum hal_abi_version _platform_abi_version = HAL_ABI_VERSION_END; static json_object *_json_file_object = NULL; +#endif static GHashTable *_module_hash = NULL; static int _usage_count = 0; +__attribute__ ((visibility("default"))) +void _destroy_module_info(gpointer data) +{ +#define SAFE_FREE_AND_NULL(x) \ +do { \ + if (x) { \ + free(x); \ + x = NULL; \ + } \ +} while (0); + + struct __hal_module_info *info = (struct __hal_module_info *)data; + + if (info) { + SAFE_FREE_AND_NULL(info->module_name); + SAFE_FREE_AND_NULL(info->library_name); + SAFE_FREE_AND_NULL(info->library_name_64bit); + SAFE_FREE_AND_NULL(info->symbol_name); + SAFE_FREE_AND_NULL(info->abi_versions); + SAFE_FREE_AND_NULL(info); + } +} + +#ifdef HAL_API_CONF_JSON static enum hal_abi_version __convert_abi_version_str_to_enum(const char *abi_version) { int version; for (version = HAL_ABI_VERSION_UNKNOWN + 1; version < HAL_ABI_VERSION_END; version++){ @@ -78,29 +104,6 @@ static enum hal_license __convert_license_str_to_enum(const char *license) return HAL_LICENSE_UNKNOWN; } -__attribute__ ((visibility("default"))) -void _destroy_module_info(gpointer data) -{ -#define SAFE_FREE_AND_NULL(x) \ -do { \ - if (x) { \ - free(x); \ - x = NULL; \ - } \ -} while (0); - - struct __hal_module_info *info = (struct __hal_module_info *)data; - - if (info) { - SAFE_FREE_AND_NULL(info->module_name); - SAFE_FREE_AND_NULL(info->library_name); - SAFE_FREE_AND_NULL(info->library_name_64bit); - SAFE_FREE_AND_NULL(info->symbol_name); - SAFE_FREE_AND_NULL(info->abi_versions); - SAFE_FREE_AND_NULL(info); - } -} - static const char * __get_json_object_string(json_object *object, const char *key) { json_object *temp_object = NULL; @@ -205,6 +208,12 @@ static struct __hal_module_info* _get_module_info(enum hal_module module) return info; } +#else +static struct __hal_module_info* _get_module_info(enum hal_module module) +{ + return &g_hal_module_info[module]; +} +#endif static struct __hal_module_info* _get_module_info_with_library_name(enum hal_module module, const char *library_name) @@ -215,7 +224,12 @@ static struct __hal_module_info* _get_module_info_with_library_name(enum hal_mod const char *module_name = NULL; int ret; - if (!_json_file_object || !_module_hash | !library_name) +#ifdef HAL_API_CONF_JSON + if (!_json_file_object) + return NULL; +#endif + + if (!_module_hash | !library_name) return NULL; if (!g_str_has_prefix(library_name, "libhal-backend-")) { @@ -276,7 +290,12 @@ struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module, const char *key = NULL; int i; - if (!_json_file_object || !_module_hash) +#ifdef HAL_API_CONF_JSON + if (!_json_file_object) + return NULL; +#endif + + if (!_module_hash) return NULL; if (!library_name) @@ -288,6 +307,7 @@ struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module, enum hal_abi_version _hal_api_conf_get_platform_abi_version(void) { +#ifdef HAL_API_CONF_JSON const char *abi_version = NULL; bool ret_initialized; json_object *platform_obj = NULL; @@ -302,6 +322,9 @@ enum hal_abi_version _hal_api_conf_get_platform_abi_version(void) _platform_abi_version = __convert_abi_version_str_to_enum(abi_version); return _platform_abi_version; +#else + return g_platform_curr_abi_version; +#endif } __attribute__ ((visibility("default"))) @@ -310,16 +333,19 @@ int _hal_api_conf_init(void) if (_usage_count++ > 0) return 0; +#ifdef HAL_API_CONF_JSON _json_file_object = json_object_from_file(HAL_CONFIGURATION_PATH); if (_json_file_object == NULL) { _E("Failed to parsing json configuration file : %s\n", json_util_get_last_err()); goto err; } +#endif _module_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, _destroy_module_info); return 0; +#ifdef HAL_API_CONF_JSON err: _usage_count--; @@ -329,6 +355,7 @@ err: } return -EINVAL; +#endif } __attribute__ ((visibility("default"))) @@ -338,10 +365,12 @@ void _hal_api_conf_exit(void) if (_usage_count != 0) return; +#ifdef HAL_API_CONF_JSON if (_json_file_object) { json_object_put(_json_file_object); _json_file_object = NULL; } +#endif if (_module_hash) { g_hash_table_remove_all(_module_hash); diff --git a/src/hal-api-list.h b/src/hal-api-list.h new file mode 100644 index 0000000..a7e0ece --- /dev/null +++ b/src/hal-api-list.h @@ -0,0 +1,706 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __HAL_API_LIST_H__ +#define __HAL_API_LIST_H__ + +#include "hal-common.h" + +#include "common.h" + +#define HAL_ABI_VERSION_MAX 10 + +enum hal_abi_version g_platform_curr_abi_version = HAL_ABI_VERSION_TIZEN_6_5; + +static struct hal_abi_version_match abi_version_match_data[HAL_MODULE_END][HAL_ABI_VERSION_MAX] = { + /* HAL_GROUP_GRAPHICS */ + [HAL_MODULE_TBM] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_TDM] = { + /* FIXME: Need to be filled from configuration file. */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_COREGL] = { + /** + * Don't need to add abi verion for this module. + * because this module don't support HAL API. + */ + }, + [HAL_MODULE_INPUT] = { + /** + * Don't need to add abi verion for this module. + * because this module don't support HAL API. + */ + }, + + /* HAL_GROUP_MULTIMEDIA */ + [HAL_MODULE_AUDIO] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_CAMERA] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_RADIO] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_CODEC] = { + /** + * Don't need to add abi verion for this module. + * because this module don't support HAL API. + */ + }, + [HAL_MODULE_USB_AUDIO] = { + /** + * Don't need to add abi verion for this module. + * because this module don't support HAL API. + */ + }, + [HAL_MODULE_ALSAUCM] = { + /** + * Don't need to add abi verion for this module. + * because this module don't support HAL API. + */ + }, + + /* HAL_GROUP_CONNECTIVITY */ + [HAL_MODULE_BLUETOOTH] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_WIFI] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_NAN] = { + }, + [HAL_MODULE_NFC] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_ZIGBEE] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_UWB] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_MTP] = { + /** + * Don't need to add abi verion for this module. + * because this module don't support HAL API. + */ + }, + + /* HAL_GROUP_TELEPHONY */ + [HAL_MODULE_TELEPHONY] = { + /* FIXME: Need to be determined whehter support HAL API or not. */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + + /* HAL_GROUP_LOCATION */ + [HAL_MODULE_LOCATION] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + + /* HAL_GROUP_SYSTEM */ + [HAL_MODULE_COMMON] = { + }, + [HAL_MODULE_POWER] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_SENSOR] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_PERIPHERAL] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + + [HAL_MODULE_DEVICE_BATTERY] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_BEZEL] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_DISPLAY] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_IR] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_TOUCHSCREEN] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_LED] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_BOARD] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_EXTERNAL_CONNECTION] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_THERMAL] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_USB_GADGET] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_HAPTIC] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, + [HAL_MODULE_DEVICE_MEMORY] = { + /* FIXME: Need to be initialized by configuration file like xml */ + [0] = { + .platform_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .backend_min_abi_version = HAL_ABI_VERSION_TIZEN_6_5, + }, + }, +}; + +static struct __hal_module_info g_hal_module_info[] = { + /* HAL_GROUP_GRAPHICS */ + [HAL_MODULE_TBM] = { + .group = HAL_GROUP_GRAPHICS, + .module = HAL_MODULE_TBM, + .license = HAL_LICENSE_MIT, + .module_name = "HAL_MODULE_TBM", + .library_name = "/hal/lib/libhal-backend-tbm.so", + .library_name_64bit = "/hal/lib64/libhal-backend-tbm.so", + .symbol_name = "hal_backend_tbm_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_TBM]), + .abi_versions = abi_version_match_data[HAL_MODULE_TBM], + .hal_api = true, + }, + [HAL_MODULE_TDM] = { + .group = HAL_GROUP_GRAPHICS, + .module = HAL_MODULE_TDM, + .license = HAL_LICENSE_MIT, + .module_name = "HAL_MODULE_TDM", + .library_name = "/hal/lib/libhal-backend-tdm.so", + .library_name_64bit = "/hal/lib64/libhal-backend-tdm.so", + .symbol_name = "hal_backend_tdm_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_TDM]), + .abi_versions = abi_version_match_data[HAL_MODULE_TDM], + .hal_api = true, + }, + [HAL_MODULE_COREGL] = { + .group = HAL_GROUP_GRAPHICS, + .module = HAL_MODULE_COREGL, + .license = HAL_LICENSE_UNKNOWN, + .module_name = "HAL_MODULE_COREGL", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = false, + }, + [HAL_MODULE_INPUT] = { + .group = HAL_GROUP_GRAPHICS, + .module = HAL_MODULE_INPUT, + .license = HAL_LICENSE_MIT, + .module_name = "HAL_MODULE_INPUT", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = false, + }, + + /* HAL_GROUP_MULTIMEDIA */ + [HAL_MODULE_AUDIO] = { + .group = HAL_GROUP_MULTIMEDIA, + .module = HAL_MODULE_AUDIO, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_AUDIO", + .library_name = "/hal/lib/libhal-backend-audio.so", + .library_name_64bit = "/hal/lib64/libhal-backend-audio.so", + .symbol_name = "hal_backend_audio_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_AUDIO]), + .abi_versions = abi_version_match_data[HAL_MODULE_AUDIO], + .hal_api = true, + }, + [HAL_MODULE_CAMERA] = { + .group = HAL_GROUP_MULTIMEDIA, + .module = HAL_MODULE_CAMERA, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_CAMERA", + .library_name = "/hal/lib/libhal-backend-camera.so", + .library_name_64bit = "/hal/lib64/libhal-backend-camera.so", + .symbol_name = "hal_backend_camera_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_CAMERA]), + .abi_versions = abi_version_match_data[HAL_MODULE_CAMERA], + .hal_api = true, + }, + [HAL_MODULE_RADIO] = { + .group = HAL_GROUP_MULTIMEDIA, + .module = HAL_MODULE_RADIO, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_RADIO", + .library_name = "/hal/lib/libhal-backend-radio.so", + .library_name_64bit = "/hal/lib64/libhal-backend-radio.so", + .symbol_name = "hal_backend_radio_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_RADIO]), + .abi_versions = abi_version_match_data[HAL_MODULE_RADIO], + .hal_api = true, + }, + [HAL_MODULE_CODEC] = { + .group = HAL_GROUP_MULTIMEDIA, + .module = HAL_MODULE_CODEC, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_CODEC", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = false, + }, + [HAL_MODULE_USB_AUDIO] = { + .group = HAL_GROUP_MULTIMEDIA, + .module = HAL_MODULE_USB_AUDIO, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_USB_AUDIO", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = false, + }, + [HAL_MODULE_ALSAUCM] = { + .group = HAL_GROUP_MULTIMEDIA, + .module = HAL_MODULE_ALSAUCM, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_ALSAUCM", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = false, + }, + + /* HAL_GROUP_CONNECTIVITY */ + [HAL_MODULE_BLUETOOTH] = { + .group = HAL_GROUP_CONNECTIVITY, + .module = HAL_MODULE_BLUETOOTH, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_BLUETOOTH", + .library_name = "/hal/lib/libhal-backend-bluetooth.so", + .library_name_64bit = "/hal/lib64/libhal-backend-bluetooth.so", + .symbol_name = "hal_backend_bluetooth_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_BLUETOOTH]), + .abi_versions = abi_version_match_data[HAL_MODULE_BLUETOOTH], + .hal_api = true, + }, + [HAL_MODULE_WIFI] = { + .group = HAL_GROUP_CONNECTIVITY, + .module = HAL_MODULE_WIFI, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_WIFI", + .library_name = "/hal/lib/libhal-backend-wifi.so", + .library_name_64bit = "/hal/lib64/libhal-backend-wifi.so", + .symbol_name = "hal_backend_wifi_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_WIFI]), + .abi_versions = abi_version_match_data[HAL_MODULE_WIFI], + .hal_api = true, + }, + [HAL_MODULE_NAN] = { + .group = HAL_GROUP_CONNECTIVITY, + .module = HAL_MODULE_NAN, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_NAN", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = false, + }, + [HAL_MODULE_NFC] = { + .group = HAL_GROUP_CONNECTIVITY, + .module = HAL_MODULE_NFC, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_NFC", + .library_name = "/hal/lib/libhal-backend-nfc.so", + .library_name_64bit = "/hal/lib64/libhal-backend-nfc.so", + .symbol_name = "hal_backend_nfc_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_NFC]), + .abi_versions = abi_version_match_data[HAL_MODULE_NFC], + .hal_api = true, + }, + [HAL_MODULE_ZIGBEE] = { + .group = HAL_GROUP_CONNECTIVITY, + .module = HAL_MODULE_ZIGBEE, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_ZIGBEE", + .library_name = "/hal/lib/libhal-backend-zigbee.so", + .library_name_64bit = "/hal/lib64/libhal-backend-zigbee.so", + .symbol_name = "hal_backend_zigbee_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_ZIGBEE]), + .abi_versions = abi_version_match_data[HAL_MODULE_ZIGBEE], + .hal_api = true, + }, + [HAL_MODULE_UWB] = { + .group = HAL_GROUP_CONNECTIVITY, + .module = HAL_MODULE_UWB, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_UWB", + .library_name = "/hal/lib/libhal-backend-uwb.so", + .library_name_64bit = "/hal/lib64/libhal-backend-uwb.so", + .symbol_name = "hal_backend_uwb_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_UWB]), + .abi_versions = abi_version_match_data[HAL_MODULE_UWB], + .hal_api = true, + }, + [HAL_MODULE_MTP] = { + .group = HAL_GROUP_CONNECTIVITY, + .module = HAL_MODULE_MTP, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_MTP", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = false, + }, + + /* HAL_GROUP_TELEPHONY */ + [HAL_MODULE_TELEPHONY] = { + .group = HAL_GROUP_TELEPHONY, + .module = HAL_MODULE_TELEPHONY, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_TELEPHONY", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = false, + }, + + /* HAL_GROUP_LOCATION */ + [HAL_MODULE_LOCATION] = { + .group = HAL_GROUP_LOCATION, + .module = HAL_MODULE_LOCATION, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_LOCATION", + .library_name = "/hal/lib/libhal-backend-location.so", + .library_name_64bit = "/hal/lib64/libhal-backend-location.so", + .symbol_name = "hal_backend_location_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_LOCATION]), + .abi_versions = abi_version_match_data[HAL_MODULE_LOCATION], + .hal_api = true, + }, + + /* HAL_GROUP_SYSTEM */ + [HAL_MODULE_COMMON] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_COMMON, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_COMMON", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = true, + }, + [HAL_MODULE_POWER] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_POWER, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_POWER", + .library_name = "/hal/lib/libhal-backend-power.so", + .library_name_64bit = "/hal/lib64/libhal-backend-power.so", + .symbol_name = "hal_backend_power_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_POWER]), + .abi_versions = abi_version_match_data[HAL_MODULE_POWER], + .hal_api = true, + }, + [HAL_MODULE_SENSOR] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_SENSOR, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_SENSOR", + .library_name = "/hal/lib/libhal-backend-sensor.so", + .library_name_64bit = "/hal/lib64/libhal-backend-sensor.so", + .symbol_name = "hal_backend_sensor_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_SENSOR]), + .abi_versions = abi_version_match_data[HAL_MODULE_SENSOR], + .hal_api = true, + }, + [HAL_MODULE_PERIPHERAL] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_PERIPHERAL, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_PERIPHERAL", + .library_name = NULL, + .library_name_64bit = NULL, + .symbol_name = NULL, + .num_abi_versions = 0, + .abi_versions = NULL, + .hal_api = false, + }, + [HAL_MODULE_DEVICE_BATTERY] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_BATTERY, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_BATTERY", + .library_name = "/hal/lib/libhal-backend-device-battery.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-battery.so", + .symbol_name = "hal_backend_device_battery_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_BATTERY]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_BATTERY], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_BEZEL] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_BEZEL, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_BEZEL", + .library_name = "/hal/lib/libhal-backend-device-bezel.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-bezel.so", + .symbol_name = "hal_backend_device_bezel_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_BEZEL]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_BEZEL], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_DISPLAY] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_DISPLAY, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_DISPLAY", + .library_name = "/hal/lib/libhal-backend-device-display.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-display.so", + .symbol_name = "hal_backend_device_display_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_DISPLAY]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_DISPLAY], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_IR] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_IR, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_IR", + .library_name = "/hal/lib/libhal-backend-device-ir.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-ir.so", + .symbol_name = "hal_backend_device_ir_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_IR]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_IR], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_TOUCHSCREEN] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_TOUCHSCREEN, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_TOUCHSCREEN", + .library_name = "/hal/lib/libhal-backend-device-touchscreen.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-touchscreen.so", + .symbol_name = "hal_backend_device_touchscreen_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_TOUCHSCREEN]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_TOUCHSCREEN], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_LED] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_LED, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_LED", + .library_name = "/hal/lib/libhal-backend-device-led.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-led.so", + .symbol_name = "hal_backend_device_led_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_LED]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_LED], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_BOARD] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_BOARD, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_BOARD", + .library_name = "/hal/lib/libhal-backend-device-board.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-board.so", + .symbol_name = "hal_backend_device_board_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_BOARD]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_BOARD], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_EXTERNAL_CONNECTION] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_EXTERNAL_CONNECTION, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_EXTERNAL_CONNECTION", + .library_name = "/hal/lib/libhal-backend-device-external-connection.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-external-connection.so", + .symbol_name = "hal_backend_device_external_connection_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_EXTERNAL_CONNECTION]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_EXTERNAL_CONNECTION], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_THERMAL] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_THERMAL, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_THERMAL", + .library_name = "/hal/lib/libhal-backend-device-thermal.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-thermal.so", + .symbol_name = "hal_backend_device_thermal_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_THERMAL]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_THERMAL], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_USB_GADGET] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_USB_GADGET, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_USB_GADGET", + .library_name = "/hal/lib/libhal-backend-device-usb-gadget.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-usb-gadget.so", + .symbol_name = "hal_backend_device_usb_gadget_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_USB_GADGET]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_USB_GADGET], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_HAPTIC] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_HAPTIC, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_HAPTIC", + .library_name = "/hal/lib/libhal-backend-device-haptic.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-haptic.so", + .symbol_name = "hal_backend_device_haptic_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_HAPTIC]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_HAPTIC], + .hal_api = true, + }, + [HAL_MODULE_DEVICE_MEMORY] = { + .group = HAL_GROUP_SYSTEM, + .module = HAL_MODULE_DEVICE_MEMORY, + .license = HAL_LICENSE_APACHE_2_0, + .module_name = "HAL_MODULE_DEVICE_MEMORY", + .library_name = "/hal/lib/libhal-backend-device-memory.so", + .library_name_64bit = "/hal/lib64/libhal-backend-device-memory.so", + .symbol_name = "hal_backend_device_memory_data", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[HAL_MODULE_DEVICE_MEMORY]), + .abi_versions = abi_version_match_data[HAL_MODULE_DEVICE_MEMORY], + .hal_api = true, + }, +}; + +#endif /* __HAL_API_LIST_H__ */ -- 2.7.4 From 21ab7fc3a3afeadffb618d45e3475e45b96da9c2 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 16 Mar 2021 09:33:10 +0900 Subject: [PATCH 07/16] halapi: Remove unneeded function definition from header file _destroy_module_info() function is not used on outside of hal-api-conf.c. So that remove the unneeded function defintion. Change-Id: I13b17dcc8592d0a0a1c0d392eda9a9c13dd76155 Signed-off-by: Chanwoo Choi --- src/hal-api-conf.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hal-api-conf.h b/src/hal-api-conf.h index c1e7eb9..23d1e72 100644 --- a/src/hal-api-conf.h +++ b/src/hal-api-conf.h @@ -38,8 +38,6 @@ struct __hal_module_info *_hal_api_conf_get_module_info(enum hal_module module, enum hal_abi_version _hal_api_conf_get_platform_abi_version(void); -void _destroy_module_info(gpointer data); - #ifdef __cplusplus } #endif -- 2.7.4 From 456f76db005fed6a0beba8b53d0f6cf598697a8b Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 22 Mar 2021 16:54:53 +0900 Subject: [PATCH 08/16] halapi: Fix svace warning issue Change-Id: I29f2405f1412a99066ae248c1a98f14cf6b30af9 Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 9914c08..e66446d 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -132,8 +132,8 @@ static int __get_backend(enum hal_module module, void **data, const char *librar struct __hal_module_info *info = NULL; void *handle = NULL; hal_backend *backend; - const char *symbol_name; - const char *backend_library_name; + const char *symbol_name = NULL; + const char *backend_library_name = NULL; int ret = 0; /* Check parameter whether is valid or not */ -- 2.7.4 From 0bd8f286c05544f4646b41b14bb118f9c8634ba3 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 23 Mar 2021 17:25:16 +0900 Subject: [PATCH 09/16] haltest: Add haltest.target to support HAL TEST mode In order to support HAL TEST Mode, add haltest.target which requires the least running processes for only haltest such as sdbd service. So that haltest.target is based on getty.target to support the console and then add deviced.service/ac.service for supporting sdbd service. And reboot-haltest/reboot-normal scripts are for switching between normal mode and HALTEST mode. [Essential service list in haltest.target] - dbus.service for /usr/bin/dbus-daemon - serial-getty@.service for console - dlog_logger.service for /usr/bin/dlog_logger - systemd-udevd.service for /usr/lib/sytemd/sytemd-udevd - systemd-journald.service for /usr/bin/systemd/systemd-journald - ac.service for /usr/bin/amd is requied for deviced.service - deviced.service for /usr/bin/deviced is required for sdbd.service - sdbd.service for /usr/sbin/sdbd [Script commands to switch between Normal and HALTEST mode] - reboot-haltest switches from Normal to HALTEST mode. - reboot-normal switches from HALTEST to Normal mode. Change-Id: If8fdd240003cf3509cec5f83bf8aacb3bc1a5ec6 Signed-off-by: Chanwoo Choi --- packaging/hal-api-common.spec | 9 +++++++++ packaging/haltest.target | 6 ++++++ packaging/reboot-haltest | 41 +++++++++++++++++++++++++++++++++++++++++ packaging/reboot-normal | 26 ++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 packaging/haltest.target create mode 100644 packaging/reboot-haltest create mode 100644 packaging/reboot-normal diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 223887f..1844696 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -14,6 +14,9 @@ Source1: %{name}.manifest Source2: libhal-api.conf Source3: systemd-hal-firmware-generator Source4: macros.hal-api +Source5: haltest.target +Source6: reboot-haltest +Source7: reboot-normal Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -67,6 +70,9 @@ mkdir -p %{buildroot}/hal install -D -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/ld.so.conf.d/libhal-api.conf install -D -m 0755 %{SOURCE3} %{buildroot}%{_systemdgeneratordir}/systemd-hal-firmware-generator install -D -m 0644 %{SOURCE4} %{buildroot}%{_sysconfdir}/rpm/macros.hal-api +install -D -m 0644 %{SOURCE5} %{buildroot}%{_unitdir}/haltest.target +install -D -m 0755 %{SOURCE6} %{buildroot}%{_bindir}/reboot-haltest +install -D -m 0755 %{SOURCE7} %{buildroot}%{_bindir}/reboot-normal %clean rm -rf %{buildroot} @@ -101,3 +107,6 @@ fi %files -n %{test_name} %{_bindir}/hal/common-haltests +%{_unitdir}/haltest.target +%{_bindir}/reboot-haltest +%{_bindir}/reboot-normal diff --git a/packaging/haltest.target b/packaging/haltest.target new file mode 100644 index 0000000..0b35a53 --- /dev/null +++ b/packaging/haltest.target @@ -0,0 +1,6 @@ +[Unit] +Description=HALTEST Mode +Requires=basic.target ac.service deviced.service getty.target +Conflicts=rescue.service rescue.target +After=basic.target rescue.service rescue.target ac.service deviced.service getty.target +AllowIsolate=yes diff --git a/packaging/reboot-haltest b/packaging/reboot-haltest new file mode 100644 index 0000000..622939c --- /dev/null +++ b/packaging/reboot-haltest @@ -0,0 +1,41 @@ +#!/bin/bash +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +user=`whoami` +default=`systemctl get-default` +dmverity_path="/usr/bin/verityctl" +dmverity_cmd=`verityctl get-mode root` +dmverity_log="dm-verity is disabled (Normal boot)" + +if ! [ "$user" = "root" ] +then + echo "HALTEST: Need 'root' permission for switching mode" + exit +fi + +if [ -f $dmverity_path ] +then + if ! [ "$dmverity_cmd" = "$dmverity_log" ] + then + echo "HALTEST: Need to disable DM-VERITY to use HALTEST Mode " + echo "HALTEST: Disable DM-VERITY and reboot target " + echo "HALTEST: After rebooting, need to execure reboot-haltest again " + verityctl disable + echo "HALTEST: Rebooting ..." + reboot -f + fi +fi + +if ! [ "$default" = "haltest.target" ] +then + echo "HALTEST: Switch to HALTEST Mode from Normal Mode" + echo "HALTEST: Change default.target from $default to haltest.target" + mount -o remount,rw / + systemctl set-default haltest.target + sync + echo "HALTEST: Rebooting ..." + reboot -f +else + echo "HALTEST: HALTEST Mode is already enabled (default: $default)" +fi + diff --git a/packaging/reboot-normal b/packaging/reboot-normal new file mode 100644 index 0000000..09fafa9 --- /dev/null +++ b/packaging/reboot-normal @@ -0,0 +1,26 @@ +#!/bin/bash + +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +user=`whoami` +default=`systemctl get-default` + +if ! [ "$user" = "root" ] +then + echo "HALTEST: Need 'root' permission for switching mode" + exit +fi + +if ! [ "$default" = "graphical.target" ] +then + echo "HALTEST: Switch to Normal Mode from HALTEST Mode" + echo "HALTEST: Change default.target from $default to graphical.target" + mount -o remount,rw / + systemctl set-default graphical.target + sync + echo "HALTEST: Rebooting ..." + reboot -f +else + echo "HALTEST: Normal Mode is already enabled (default: $default)" +fi + -- 2.7.4 From bb5b8f7b9af9d50888eb80e03fdf8587af855a81 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 22 Apr 2021 14:19:35 +0900 Subject: [PATCH 10/16] halapi: Replace fPIE gcc option with fPIC The fPIE option is for the executable binary. It is not proper for shared library files. So that correct the wrong use-case by using fPIC. Change-Id: Id27d4a31080477415d9bc2bbaa0210039ff27233 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df8d137..062835b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIE") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-pie") -- 2.7.4 From a82677839e8a5b6ada81eea39c9a3710d1af283c Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 21 Apr 2021 20:48:59 +0900 Subject: [PATCH 11/16] halapi: Get backend library name always regardless of usage_count The backend_library_name value is necessary to show the backend library name always. So that get backend library name always regardless of usage_count and then print 'close' message when close the fd of backend library. Change-Id: I338bf22ac678bc80ceab020c7fd0c1ca1662254b Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index e66446d..769da13 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -160,19 +160,19 @@ static int __get_backend(enum hal_module module, void **data, const char *librar goto err; } + backend_library_name = get_backend_library_name(info); + if (!backend_library_name) { + _E("%s: Failed to get backend library name\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + if (info->usage_count == 0) { /* * Load HAL backend library at first loading time * when usage_count is 0. */ - backend_library_name = get_backend_library_name(info); - if (!backend_library_name) { - _E("%s: Failed to get backend library name\n", - info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err; - } - ret = access(backend_library_name, F_OK); if (ret < 0) { _E("%s: Failed to find backend library (%s)\n", @@ -205,6 +205,10 @@ static int __get_backend(enum hal_module module, void **data, const char *librar goto err_dlclose; } + _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + info->module_name, backend->name, backend->vendor, + backend_library_name, info->usage_count); + info->library_backend = backend; info->library_handle = handle; } else { @@ -288,12 +292,6 @@ static int __put_backend(enum hal_module module, void *data, const char *library goto out; } - info->usage_count--; - if (info->usage_count > 0) { - ret = TIZEN_ERROR_NONE; - goto out; - } - if (backend->exit) { ret = backend->exit(data); if (ret < 0) { @@ -304,10 +302,21 @@ static int __put_backend(enum hal_module module, void *data, const char *library } } + info->usage_count--; + _I("%s: Put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", info->module_name, backend->name, backend->vendor, get_backend_library_name(info), info->usage_count); + if (info->usage_count > 0) { + ret = TIZEN_ERROR_NONE; + goto out; + } + + _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + info->module_name, backend->name, backend->vendor, + get_backend_library_name(info), info->usage_count); + if (handle) dlclose(handle); -- 2.7.4 From 337405b7eddade611c70a9d4afcb4b255e42159f Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 21 Apr 2021 21:02:43 +0900 Subject: [PATCH 12/16] halapi: Encapsulate unused variables by external user The following variables are only used in hal-api-common without exposing for external user. So that move them into internal header files for encapsulation. - enum hal_license - enum hal_group - char *const hal_group_string[] - char *const hal_module_string[] Change-Id: I18643fdbbabcabee7b6aefadff1ba36c8dc3a0fa Signed-off-by: Chanwoo Choi --- include/hal-common.h | 29 ----------------------------- src/common.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/hal-common.h b/include/hal-common.h index 45c4a10..67dc4b1 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -25,35 +25,6 @@ extern "C" { #endif -enum hal_license { - HAL_LICENSE_UNKNOWN = 0, - HAL_LICENSE_APACHE_2_0, - HAL_LICENSE_FLORA, - HAL_LICENSE_MIT, - HAL_LICENSE_END, -}; - -enum hal_group { - HAL_GROUP_UNKNOWN = 0, - HAL_GROUP_GRAPHICS, - HAL_GROUP_MULTIMEDIA, - HAL_GROUP_CONNECTIVITY, - HAL_GROUP_TELEPHONY, - HAL_GROUP_LOCATION, - HAL_GROUP_SYSTEM, - HAL_GROUP_END, -}; - -static const char *const hal_group_string[] = { - [HAL_GROUP_UNKNOWN] = "HAL_GROUP_UNKNOWN", - [HAL_GROUP_GRAPHICS] = "HAL_GROUP_GRAPHICS", - [HAL_GROUP_MULTIMEDIA] = "HAL_GROUP_MULTIMEDIA", - [HAL_GROUP_CONNECTIVITY] = "HAL_GROUP_CONNECTIVITY", - [HAL_GROUP_TELEPHONY] = "HAL_GROUP_TELEPHONY", - [HAL_GROUP_LOCATION] = "HAL_GROUP_LOCATION", - [HAL_GROUP_SYSTEM] = "HAL_GROUP_SYSTEM", -}; - enum hal_module { HAL_MODULE_UNKNOWN = 0, diff --git a/src/common.h b/src/common.h index e3463e2..c641610 100644 --- a/src/common.h +++ b/src/common.h @@ -33,6 +33,35 @@ extern "C" { #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) +enum hal_license { + HAL_LICENSE_UNKNOWN = 0, + HAL_LICENSE_APACHE_2_0, + HAL_LICENSE_FLORA, + HAL_LICENSE_MIT, + HAL_LICENSE_END, +}; + +enum hal_group { + HAL_GROUP_UNKNOWN = 0, + HAL_GROUP_GRAPHICS, + HAL_GROUP_MULTIMEDIA, + HAL_GROUP_CONNECTIVITY, + HAL_GROUP_TELEPHONY, + HAL_GROUP_LOCATION, + HAL_GROUP_SYSTEM, + HAL_GROUP_END, +}; + +static const char *const hal_group_string[] = { + [HAL_GROUP_UNKNOWN] = "HAL_GROUP_UNKNOWN", + [HAL_GROUP_GRAPHICS] = "HAL_GROUP_GRAPHICS", + [HAL_GROUP_MULTIMEDIA] = "HAL_GROUP_MULTIMEDIA", + [HAL_GROUP_CONNECTIVITY] = "HAL_GROUP_CONNECTIVITY", + [HAL_GROUP_TELEPHONY] = "HAL_GROUP_TELEPHONY", + [HAL_GROUP_LOCATION] = "HAL_GROUP_LOCATION", + [HAL_GROUP_SYSTEM] = "HAL_GROUP_SYSTEM", +}; + /** * hal-api-common (/platform/hal/api/common) provides the HAL ABI * (Application Binary Interface) version check feature which is used to check -- 2.7.4 From 0bde68b13a4809ae6772ce46677bfd1867b5f174 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 22 Apr 2021 18:33:36 +0900 Subject: [PATCH 13/16] halapi: conf: Remove unused local variables Change-Id: Iab9597b3bd4d2bbfc258d62ca1302f8ba64169a4 Signed-off-by: Chanwoo Choi --- src/hal-api-conf.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/hal-api-conf.c b/src/hal-api-conf.c index 4465fe6..65e67f4 100644 --- a/src/hal-api-conf.c +++ b/src/hal-api-conf.c @@ -283,13 +283,6 @@ __attribute__ ((visibility("default"))) struct __hal_module_info* _hal_api_conf_get_module_info(enum hal_module module, const char *library_name) { - struct __hal_module_info *info = NULL; - json_object *module_array_object = NULL; - const char *group_name = NULL; - const char *module_name = NULL; - const char *key = NULL; - int i; - #ifdef HAL_API_CONF_JSON if (!_json_file_object) return NULL; -- 2.7.4 From 9c3b2bc76bb5cbfd35322fa2a1c37735ad6b585c Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 23 Apr 2021 16:02:45 +0900 Subject: [PATCH 14/16] halapi: Show process name when using hal-api library The hal-api library are used by the various process. In order to support the easy debugging, show the process name who get/put the hal-api library. Example log with process name, HAL_MODULE_TBM: Get HAL backend: name(vc4)/vendor(Samsung)/library(/hal/lib64/libhal-backend-tbm.so)/count(1) by /usr/bin/enlightenment HAL_MODULE_TBM: Get HAL backend: name(vc4)/vendor(Samsung)/library(/hal/lib64/libhal-backend-tbm.so)/count(1) by /usr/bin/boot-animation Change-Id: I7befe874d17585cfffc79e05e32f90f1edcb284d Signed-off-by: Chanwoo Choi --- src/hal-api-common.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 769da13..530d18c 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -22,11 +22,16 @@ #include #include +#define _GNU_SOURCE +#include + #include #include "common.h" #include "hal-api-conf.h" +extern char *program_invocation_name; + #ifndef EXPORT #define EXPORT __attribute__ ((visibility("default"))) #endif @@ -205,9 +210,10 @@ static int __get_backend(enum hal_module module, void **data, const char *librar goto err_dlclose; } - _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, backend->name, backend->vendor, - backend_library_name, info->usage_count); + get_backend_library_name(info), info->usage_count, + program_invocation_name); info->library_backend = backend; info->library_handle = handle; @@ -246,9 +252,10 @@ static int __get_backend(enum hal_module module, void **data, const char *librar info->usage_count++; - _I("%s: Get HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + _I("%s: Get HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, backend->name, backend->vendor, - backend_library_name, info->usage_count); + backend_library_name, info->usage_count, + program_invocation_name); G_UNLOCK(hal_common_lock); return TIZEN_ERROR_NONE; @@ -304,18 +311,20 @@ static int __put_backend(enum hal_module module, void *data, const char *library info->usage_count--; - _I("%s: Put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + _I("%s: Put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, backend->name, backend->vendor, - get_backend_library_name(info), info->usage_count); + get_backend_library_name(info), info->usage_count, + program_invocation_name); if (info->usage_count > 0) { ret = TIZEN_ERROR_NONE; goto out; } - _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d)\n", + _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, backend->name, backend->vendor, - get_backend_library_name(info), info->usage_count); + get_backend_library_name(info), info->usage_count, + program_invocation_name); if (handle) dlclose(handle); -- 2.7.4 From cffb4836e9887964dc595b6e63a271e0ce216c0d Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 22 Apr 2021 19:12:04 +0900 Subject: [PATCH 15/16] halapi: Split the internal functions finely to get flexibility New functions will use only __open_backend() without __close_backend() in order to get the data of hal_backend structure. But this code have been tightly coupled implemented in __get_backend and __put_backend. In order to make the code more flexibility, split __get_backend/__put_backend finley to two steps such as open/close and init/exit. [Simple description for functions] - __open_backend() : Open backend library and get backend symbol - __close_backend() : Close backend library - __init_backend() : After getting backend, initialize HAL backend driver - __exit_backend() : After getting backend, exit HAL backend driver - __get_backend() __open_backend() __init_backend() Increase usage_count - __put_backend() __exit_backen() __close_backend() Decrease usage_count [Change variable name in struct __hal_module_info] - library_backend -> backend - library_handle -> handle Change-Id: I358e3f4db1991d26c8cf0498b3f37ec543da3e38 Signed-off-by: Chanwoo Choi --- src/common.h | 4 +- src/hal-api-common.c | 279 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 169 insertions(+), 114 deletions(-) diff --git a/src/common.h b/src/common.h index c641610..69d7c13 100644 --- a/src/common.h +++ b/src/common.h @@ -93,8 +93,8 @@ struct __hal_module_info { char *library_name; char *library_name_64bit; - void *library_handle; - hal_backend *library_backend; + void *handle; + hal_backend *backend; char *symbol_name; unsigned int num_abi_versions; diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 530d18c..18eab76 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -132,23 +132,157 @@ out: return ret; } -static int __get_backend(enum hal_module module, void **data, const char *library_name) +static int __open_backend(struct __hal_module_info *info) { - struct __hal_module_info *info = NULL; - void *handle = NULL; - hal_backend *backend; - const char *symbol_name = NULL; const char *backend_library_name = NULL; - int ret = 0; + int ret; + + if (info->backend && info->handle) + return 0; + + backend_library_name = get_backend_library_name(info); + if (!backend_library_name) { + _E("%s: Failed to get backend library name\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + + if (!info->symbol_name) { + _E("%s: Failed to get backend symbol name\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + + ret = access(backend_library_name, F_OK); + if (ret < 0) { + _E("%s: Failed to find backend library (%s)\n", + info->module_name, backend_library_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + + info->handle = dlopen(backend_library_name, RTLD_LAZY); + if (!info->handle) { + _E("%s: Failed to load backend library (%s)\n", + info->module_name, dlerror()); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err; + } + + info->backend = dlsym(info->handle, info->symbol_name); + if (!info->backend) { + _E("%s: Failed to find backend data (%s)\n", + info->module_name, dlerror()); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_dlclose; + } + + _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", + info->module_name, info->backend->name, info->backend->vendor, + backend_library_name, info->usage_count, + program_invocation_name); + + return 0; + +err_dlclose: + dlclose(info->handle); +err: + info->backend = NULL; + info->handle = NULL; + + return ret; +} + +static void __close_backend(struct __hal_module_info *info) +{ + if (!info->backend || !info->handle) + return; + + _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", + info->module_name, info->backend->name, info->backend->vendor, + get_backend_library_name(info), info->usage_count, + program_invocation_name); + + if (info->handle) + dlclose(info->handle); + + info->backend = NULL; + info->handle = NULL; +} + +static int __init_backend(struct __hal_module_info *info, void **data, + const char *library_name) +{ + int ret; + + if (!info->handle || !info->backend) { + _I("%s: Has not yet dlopend backend\n", info->module_name); + return TIZEN_ERROR_NONE; + } + + if (!info->backend->init) { + _E("%s: hal_backend->init() is NULL\n", info->module_name); + return TIZEN_ERROR_INVALID_PARAMETER; + } + + /* Check HAL ABI Version */ + ret = hal_common_check_backend_abi_version(info->module, + info->backend->abi_version); + if (ret < 0) { + _E("%s: Failed to check ABI version\n", info->module_name); + return TIZEN_ERROR_INVALID_PARAMETER; + } + + /* Initialize backend */ + ret = info->backend->init(data); + if (ret < 0) { + _E("%s: Failed to initialize backend: name(%s)/vendor(%s)\n", + info->module_name, info->backend->name, + info->backend->vendor); + return TIZEN_ERROR_INVALID_PARAMETER; + } + + return TIZEN_ERROR_NONE; +} + +static int __exit_backend(struct __hal_module_info *info, void *data, + const char *library_name) +{ + int ret; + + if (!info->handle || !info->backend) { + _I("%s: Has not yet dlopend backend\n", info->module_name); + return TIZEN_ERROR_NONE; + } + + /* Exit backend */ + if (info->backend->exit) { + ret = info->backend->exit(data); + if (ret < 0) { + _E("%s: Failed to exit backend: name(%s)/vendor(%s)\n", + info->module_name, info->backend->name, + info->backend->vendor); + return TIZEN_ERROR_INVALID_PARAMETER; + } + } + + return 0; +} + +static int __get_backend(enum hal_module module, void **data, + const char *library_name) +{ + struct __hal_module_info *info = NULL; + int ret; - /* Check parameter whether is valid or not */ if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { _E("Invalid parameter of HAL module (%d)\n", module); return TIZEN_ERROR_INVALID_PARAMETER; } G_LOCK(hal_common_lock); - if (_hal_api_conf_init()) { ret = TIZEN_ERROR_UNKNOWN; goto err; @@ -165,96 +299,27 @@ static int __get_backend(enum hal_module module, void **data, const char *librar goto err; } - backend_library_name = get_backend_library_name(info); - if (!backend_library_name) { - _E("%s: Failed to get backend library name\n", + ret = __open_backend(info); + if (ret < 0) { + _E("%s: Failed to get the backend library by dlopen\n", info->module_name); ret = TIZEN_ERROR_INVALID_PARAMETER; goto err; } - if (info->usage_count == 0) { - /* - * Load HAL backend library at first loading time - * when usage_count is 0. - */ - ret = access(backend_library_name, F_OK); - if (ret < 0) { - _E("%s: Failed to find backend library (%s)\n", - info->module_name, backend_library_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err; - } - - handle = dlopen(backend_library_name, RTLD_LAZY); - if (!handle) { - _E("%s: Failed to load backend library (%s)\n", - info->module_name, dlerror()); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err; - } - - symbol_name = info->symbol_name; - if (!symbol_name) { - _E("%s: Failed to get backend symbol name\n", - info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err_dlclose; - } - - backend = dlsym(handle, symbol_name); - if (!backend) { - _E("%s: Failed to find backend data (%s)\n", - info->module_name, dlerror()); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err_dlclose; - } - - _I("%s: Open HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", - info->module_name, backend->name, backend->vendor, - get_backend_library_name(info), info->usage_count, - program_invocation_name); - - info->library_backend = backend; - info->library_handle = handle; - } else { - /* - * Re-use the already loaded HAL backend instance - * when usage_count is larger than 0. - */ - backend = info->library_backend; - } - - /* Check HAL ABI Version */ - ret = hal_common_check_backend_abi_version(module, backend->abi_version); + ret = __init_backend(info, data, NULL); if (ret < 0) { - _E("%s: Failed to check ABI version\n", + _E("%s: Failed to initialize the backend library\n", info->module_name); ret = TIZEN_ERROR_INVALID_PARAMETER; goto err_dlclose; } - /* Get the backend module data */ - if (!backend->init) { - _E("%s: hal_backend->init() is NULL\n", - info->module_name); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err_dlclose; - } - - ret = backend->init(data); - if (ret < 0) { - _E("%s: Failed to initialize backend: name(%s)/vendor(%s)\n", - info->module_name, backend->name, backend->vendor); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto err_dlclose; - } - info->usage_count++; _I("%s: Get HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", - info->module_name, backend->name, backend->vendor, - backend_library_name, info->usage_count, + info->module_name, info->backend->name, info->backend->vendor, + get_backend_library_name(info), info->usage_count, program_invocation_name); G_UNLOCK(hal_common_lock); @@ -262,17 +327,16 @@ static int __get_backend(enum hal_module module, void **data, const char *librar err_dlclose: _hal_api_conf_exit(); - dlclose(handle); + __close_backend(info); err: G_UNLOCK(hal_common_lock); return ret; } -static int __put_backend(enum hal_module module, void *data, const char *library_name) +static int __put_backend(enum hal_module module, void *data, + const char *library_name) { struct __hal_module_info *info = NULL; - hal_backend *backend = NULL; - void *handle = NULL; int ret; /* Check parameter whether is valid or not */ @@ -290,29 +354,30 @@ static int __put_backend(enum hal_module module, void *data, const char *library goto out; } - backend = info->library_backend; - handle = info->library_handle; + if (!info->handle || !info->backend) { + _I("%s: Has not yet dlopend backend\n", info->module_name); + ret = TIZEN_ERROR_NONE; + goto out; + } - if (!backend || info->usage_count == 0) { + if (!info->usage_count) { _I("%s: Already fully put for HAL module\n", info->module_name); - ret = TIZEN_ERROR_NONE; + ret = TIZEN_ERROR_NONE; goto out; } - if (backend->exit) { - ret = backend->exit(data); - if (ret < 0) { - _E("%s: Failed to exit backend: name(%s)/vendor(%s)\n", - info->module_name, backend->name, backend->vendor); - ret = TIZEN_ERROR_INVALID_PARAMETER; - goto out; - } + ret = __exit_backend(info, data, NULL); + if (ret < 0) { + _E("%s: Failed to exit the backend library\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto out; } info->usage_count--; _I("%s: Put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", - info->module_name, backend->name, backend->vendor, + info->module_name, info->backend->name, info->backend->vendor, get_backend_library_name(info), info->usage_count, program_invocation_name); @@ -321,17 +386,7 @@ static int __put_backend(enum hal_module module, void *data, const char *library goto out; } - _I("%s: Close HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", - info->module_name, backend->name, backend->vendor, - get_backend_library_name(info), info->usage_count, - program_invocation_name); - - if (handle) - dlclose(handle); - - info->library_backend = NULL; - info->library_handle = NULL; - + __close_backend(info); _hal_api_conf_exit(); ret = TIZEN_ERROR_NONE; -- 2.7.4 From bc5a305b030bd67f8bbd1fbd49bc9eeb1c67985b Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 26 Apr 2021 19:06:56 +0900 Subject: [PATCH 16/16] halapi: Add new functions to get information of hal_backend structure The hal-api-common defines the common hal_backend structure for all hal backend driver. Add new functions to provide the information of hal_backend structure because of user request. Add the detailed function roles as following: [Newly added functions] - hal_common_get_backend_abi_version(enum hal_module module); : Get the backend HAL ABI version according to the type of HAL module - hal_common_get_backend_name(enum hal_module module, char *name, int size); : Get the backend name according to the type of HAL module - hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size); : Get the backend vendor description according to the type of HAL module Change-Id: I2060e9047b60c029e161dc18f3981185a0f724a1 Signed-off-by: Chanwoo Choi --- include/hal-common.h | 25 +++++++++++++ src/hal-api-common.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/include/hal-common.h b/include/hal-common.h index 67dc4b1..7ec6c1f 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -203,6 +203,31 @@ int hal_common_put_backend_with_library_name(enum hal_module module, int hal_common_check_backend_abi_version(enum hal_module module, enum hal_abi_version abi_version); +/** + * @brief Get the backend HAL ABI version according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @return @c positive integer value on success, otherwise a zero error value + */ +unsigned int hal_common_get_backend_abi_version(enum hal_module module); + +/** + * @brief Get the backend name according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[out] Backend name of HAL module + * @param[in] Arrary size of name[] + * @return @c positive integer value on success, otherwise a zero error value + */ +int hal_common_get_backend_name(enum hal_module module, char *name, int size); + +/** + * @brief Get the backend vendor description according to the type of HAL module + * @param[in] HAL module id among enum hal_moudle + * @param[out] Backend vendor description of HAL module + * @param[in] Arrary size of vendor[] + * @return @c positive integer value on success, otherwise a zero error value + */ +int hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size); + #ifdef __cplusplus } #endif diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 18eab76..7a98878 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -396,6 +396,82 @@ out: return ret; } +static int __get_backend_data(enum hal_module module, unsigned int *abi_version, + char *name, int name_size, char *vendor, int vendor_size) +{ + struct __hal_module_info *info = NULL; + int ret, len; + + if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) { + _E("Invalid parameter of HAL module (%d)\n", module); + return 0; + } + + G_LOCK(hal_common_lock); + + if (_hal_api_conf_init()) { + ret = HAL_ABI_VERSION_UNKNOWN; + goto err_unlock; + } + + info = _hal_api_conf_get_module_info(module, NULL); + if (info == NULL) { + _E("Failed to get HAL module(%d) information\n", module); + ret = HAL_ABI_VERSION_UNKNOWN; + goto err_conf_exit; + } + + ret = __open_backend(info); + if (ret < 0) { + _E("%s: Failed to get the backend library by dlopen\n", + info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + + /* Return abi_verion of hal_backend structure */ + if (!name_size && !vendor_size) { + *abi_version = info->backend->abi_version; + + /* Return name of hal_backend structure */ + } else if (info->backend->name && name_size && !vendor_size) { + len = strlen(info->backend->name); + + if (!info->backend->name || (len + 1 > name_size)) { + _E("%s: Invalid size of name[] array\n", info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + + strncpy(name, info->backend->name, len); + name[len] = '\0'; + + /* Return vendor of hal_backend structure */ + } else if (info->backend->vendor && !name_size && vendor_size) { + len = strlen(info->backend->vendor); + + if (!info->backend->vendor || (len + 1 > vendor_size)) { + _E("%s: Invalid size of vendor[] array\n", info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + + strncpy(vendor, info->backend->vendor, len); + vendor[len] = '\0'; + } else { + _E("%s: Failed to get backend data\n", info->module_name); + ret = TIZEN_ERROR_INVALID_PARAMETER; + goto err_conf_exit; + } + ret = TIZEN_ERROR_NONE; + +err_conf_exit: + _hal_api_conf_exit(); +err_unlock: + G_UNLOCK(hal_common_lock); + return ret; +} + EXPORT int hal_common_get_backend(enum hal_module module, void **data) { @@ -505,3 +581,28 @@ out: _hal_api_conf_exit(); return ret; } + +EXPORT +unsigned int hal_common_get_backend_abi_version(enum hal_module module) +{ + unsigned int abi_version; + int ret; + + ret = __get_backend_data(module, &abi_version, NULL, 0, NULL, 0); + if (ret < 0) + return HAL_ABI_VERSION_UNKNOWN; + + return abi_version; +} + +EXPORT +int hal_common_get_backend_name(enum hal_module module, char *name, int size) +{ + return __get_backend_data(module, NULL, name, size, NULL, 0); +} + +EXPORT +int hal_common_get_backend_vendor(enum hal_module module, char *vendor, int size) +{ + return __get_backend_data(module, NULL, NULL, 0, vendor, size); +} -- 2.7.4